diff --git a/src/App/App.js b/src/App/App.js index b6031be6e..d3a1ce188 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -100,7 +100,7 @@ const App = () => { }; }, []); - // Handle shell window visibility changed event + // Handle shell window visibility changed event React.useEffect(() => { const onWindowVisibilityChanged = (state) => { setWindowHidden(state.visible === false && state.visibility === 0); diff --git a/src/common/useShell.ts b/src/common/useShell.ts index f4700d779..7baab60bc 100644 --- a/src/common/useShell.ts +++ b/src/common/useShell.ts @@ -17,11 +17,17 @@ type ShellEvent = { args: string[]; }; - - const createId = () => Math.floor(Math.random() * 9999) + 1; const useShell = () => { + const on = (name: string, listener: (arg: any) => void) => { + events.on(name, listener); + }; + + const off = (name: string, listener: (arg: any) => void) => { + events.off(name, listener); + }; + const send = (method: string, ...args: (string | number)[]) => { try { transport?.send(JSON.stringify({ @@ -31,19 +37,11 @@ const useShell = () => { method: 'onEvent', args: [method, ...args], })); - } catch(e) { + } catch (e) { console.error('Shell', 'Failed to send event', e); } }; - const on = (name: string, listener: (arg: any) => void) => { - events.on(name, listener); - }; - - const off = (name: string, listener: (arg: any) => void) => { - events.off(name, listener); - }; - useEffect(() => { if (!transport) return; diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 7a50d7432..d1d601d5e 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -17,4 +17,4 @@ declare global { var qt: Qt | undefined; } -export {} \ No newline at end of file +export {};