-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Popup ready signal to service worker (#174)
* Create popup ready message * Add scripts/private to gitignore * Abstract popupReady * Refactor popup ready * [pairing] update types * Refactor isPopupReadyResponse * Fix typo * Refactor popup ready msging * Add comment * Remove usePopupReady arg * Use pathname for throwIfAlreadyOpen * Refactor throwIfAlreadyOpen to use hashPath --------- Co-authored-by: Gabe Rodriguez <[email protected]>
- Loading branch information
1 parent
bc5d8af
commit 2fcb118
Showing
4 changed files
with
63 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,4 @@ packages/*/package | |
|
||
apps/extension/chromium-profile | ||
|
||
scripts/private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
// signals that react is ready (mounted) to service worker | ||
export const usePopupReady = () => { | ||
const sentMessagesRef = useRef(new Set()); | ||
const [searchParams] = useSearchParams(); | ||
const popupId = searchParams.get('popupId'); | ||
|
||
useEffect(() => { | ||
if (popupId && !sentMessagesRef.current.has(popupId)) { | ||
sentMessagesRef.current.add(popupId); | ||
|
||
void chrome.runtime.sendMessage(popupId); | ||
} | ||
}, [popupId]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters