1- import { useEffect , useState } from "react" ;
2- import "./App.css" ;
3- import { PublicPath } from "wxt/browser" ;
1+ import { storage } from "#imports" ;
42import {
5- postMessage ,
3+ openInfoPage ,
64 playLocalAudio ,
7- stopLocalAudio ,
5+ postMessage ,
86 setLocalVolume ,
9- openInfoPage ,
7+ stopLocalAudio ,
108} from "@/utils" ;
11- import { storage } from "#imports " ;
9+ import { getMySounds , getSounds , login } from "@/utils/api " ;
1210import { CrossFunctions } from "@/utils/constants" ;
13- import { login , getMySounds , getSounds } from "@/utils/api" ;
14- import { storeSound , retrieveSound , isSoundCached } from "@/utils/db.ts" ;
11+ import { isSoundCached , retrieveSound , storeSound } from "@/utils/db.ts" ;
12+ import { useEffect , useState } from "react" ;
13+ import "./App.css" ;
1514
1615import {
1716 BoxIcon ,
@@ -23,12 +22,12 @@ import {
2322 SpeakerLoudIcon ,
2423 UpdateIcon ,
2524} from "@radix-ui/react-icons" ;
26- import { DropdownMenu , Popover , Separator , Slider } from "radix-ui" ;
27- import { MicIcon , MicOffIcon , VideoIcon , VideoOffIcon } from "../../icons" ;
2825import fuzzysort from "fuzzysort" ;
26+ import { DropdownMenu , Separator , Slider , Tooltip } from "radix-ui" ;
27+ import { MicIcon , MicOffIcon , VideoIcon , VideoOffIcon } from "../../icons" ;
2928
3029function App ( ) {
31- const [ currentlyPlaying , setCurrentlyPlaying ] = useState ( - 1 ) ;
30+ const [ currentlyPlaying , setCurrentlyPlaying ] = useState < number | null > ( null ) ;
3231 const [ searchInput , setSearchInput ] = useState ( "" ) ;
3332 const [ isMeet , setIsMeet ] = useState < boolean > ( false ) ;
3433 const [ soundButtons , setSoundButtons ] = useState < any [ ] > ( [ ] ) ;
@@ -81,10 +80,8 @@ function App() {
8180
8281 async function fetchSounds ( ) {
8382 setIsSyncing ( true ) ;
84- console . log ( "Fetching sounds..." ) ;
8583 try {
8684 const response = await getSounds ( ) ;
87- console . log ( "Default Sounds:" , response ) ;
8885 const sounds = await Promise . all (
8986 response . data . map ( async ( sound : any ) => {
9087 const id = sound . id ;
@@ -96,10 +93,8 @@ function App() {
9693 if ( ! isCached ) {
9794 const audioResponse = await fetch ( fullUrl ) ;
9895 const blob = await audioResponse . blob ( ) ;
99- console . log ( "Caching new sound:" , id ) ;
10096 await storeSound ( id , blob ) ;
10197 } else {
102- console . log ( "Sound already cached:" , id ) ;
10398 }
10499
105100 return {
@@ -151,9 +146,7 @@ function App() {
151146 }
152147
153148 async function playSound ( id : number ) {
154- console . log ( "Playing sound with id:" , id ) ;
155149 const blob = await retrieveSound ( id ) ;
156- console . log ( "(app.tsx)Retrieved sound blob:" , blob ) ;
157150 const base64 = await blobToBase64 ( blob ) ;
158151 if ( isMeet ) {
159152 postMessage ( CrossFunctions . INJECT_AUDIO , {
@@ -163,6 +156,10 @@ function App() {
163156 }
164157 const success = await playLocalAudio ( base64 , fxVolume ) ;
165158 if ( success ) {
159+ browser . runtime . sendMessage ( {
160+ type : CrossFunctions . SET_AUDIO_PLAYING ,
161+ audioID : id ,
162+ } ) ;
166163 setCurrentlyPlaying ( id ) ;
167164 }
168165 }
@@ -172,7 +169,7 @@ function App() {
172169 postMessage ( CrossFunctions . STOP_AUDIO ) ;
173170 }
174171 stopLocalAudio ( ) ;
175- setCurrentlyPlaying ( - 1 ) ;
172+ setCurrentlyPlaying ( null ) ;
176173 }
177174
178175 async function handleMicMute ( muteMic : boolean ) {
@@ -219,15 +216,19 @@ function App() {
219216 setFxVolume ( await fxVolumeStorage . getValue ( ) ) ;
220217 setMicMuted ( await micMutedStorage . getValue ( ) ) ;
221218 setSelectedFolder ( await selectedFolderStorage . getValue ( ) ) ;
219+ setCurrentlyPlaying (
220+ await browser . runtime . sendMessage ( {
221+ type : CrossFunctions . GET_AUDIO_PLAYING ,
222+ } )
223+ ) ;
222224 }
223225 loadStates ( ) ;
224226 } , [ ] ) ;
225227
226228 useEffect ( ( ) => {
227- // TODO: Make it check if the audio is still playing on reopen
228229 const listener = ( msg : any ) => {
229230 if ( msg . type === CrossFunctions . AUDIO_ENDED ) {
230- setCurrentlyPlaying ( - 1 ) ;
231+ setCurrentlyPlaying ( null ) ;
231232 }
232233 } ;
233234
@@ -305,13 +306,11 @@ function App() {
305306 try {
306307 const res = await fetch ( "http://localhost:3001/login" , {
307308 method : "POST" ,
308- headers : { "Content-Type" : "application/json" ,
309- "Authorization" : ""
310- } ,
309+ headers : { "Content-Type" : "application/json" , Authorization : "" } ,
311310 body : JSON . stringify ( {
312311 user : { email : loginEmail , password : loginPassword } ,
313312 } ) ,
314- credentials : "omit"
313+ credentials : "omit" ,
315314 } ) ;
316315 const response = await res . json ( ) ;
317316 const authHeader = res . headers . get ( "Authorization" ) ;
@@ -325,13 +324,14 @@ function App() {
325324 } catch ( e ) {
326325 console . error ( "Failed to store JWT in browser storage:" , e ) ;
327326 }
328- await browser . storage . local . get ( "jwt" ) . then ( ( result ) => {
329- } ) ;
327+ await browser . storage . local . get ( "jwt" ) . then ( ( result ) => { } ) ;
330328 setShowLogin ( false ) ;
331329 setLoginEmail ( "" ) ;
332330 setLoginPassword ( "" ) ;
333331 setUsername ( response . status . data . user . username ) ;
334- await browser . storage . local . set ( { username : response . status . data . user . username } ) ;
332+ await browser . storage . local . set ( {
333+ username : response . status . data . user . username ,
334+ } ) ;
335335 alert ( "Logged in!" ) ;
336336 } catch {
337337 setLoginError ( "Login failed" ) ;
@@ -444,7 +444,7 @@ function App() {
444444 < button
445445 className = "iconButton stopButton"
446446 onClick = { stopSound }
447- disabled = { currentlyPlaying === - 1 }
447+ disabled = { currentlyPlaying === null }
448448 >
449449 < BoxIcon className = "buttonIcon stopButtonIcon" />
450450 </ button >
@@ -458,28 +458,34 @@ function App() {
458458 < div className = "controlPanelContainer" >
459459 < h2 className = "voiceLabel" >
460460 Voice{ " " }
461- < Popover . Root >
462- < Popover . Trigger asChild >
463- < button className = "iconButton infoButton" >
464- < InfoCircledIcon className = "infoButtonIcon" />
465- </ button >
466- </ Popover . Trigger >
467- < Popover . Portal >
468- < Popover . Content
469- className = "infoButtonPopover"
470- side = "top"
471- sideOffset = { 2 }
472- collisionPadding = { 8 }
461+ < Tooltip . Provider delayDuration = { 200 } >
462+ < Tooltip . Root >
463+ < Tooltip . Trigger
464+ asChild
465+ onClick = { ( event ) => event . preventDefault ( ) }
473466 >
474- < p >
475- This extension can only inject audio when your Google Meet
476- microphone is unmuted. To play sound effects but mute your
477- microphone, use this button!
478- </ p >
479- < Popover . Arrow className = "infoButtonArrow" />
480- </ Popover . Content >
481- </ Popover . Portal >
482- </ Popover . Root >
467+ < button className = "iconButton infoButton" >
468+ < InfoCircledIcon className = "infoButtonIcon" />
469+ </ button >
470+ </ Tooltip . Trigger >
471+ < Tooltip . Portal >
472+ < Tooltip . Content
473+ className = "infoButtonPopover"
474+ side = "top"
475+ sideOffset = { 2 }
476+ collisionPadding = { 8 }
477+ onClick = { ( event ) => event . preventDefault ( ) }
478+ >
479+ < p >
480+ This extension can only inject audio when your Google
481+ Meet microphone is unmuted. To play sound effects but
482+ mute your microphone, use this button!
483+ </ p >
484+ < Tooltip . Arrow className = "infoButtonArrow" />
485+ </ Tooltip . Content >
486+ </ Tooltip . Portal >
487+ </ Tooltip . Root >
488+ </ Tooltip . Provider >
483489 </ h2 >
484490 < button
485491 className = {
0 commit comments