diff --git a/main.js b/main.js index 0055d82..ba98a0a 100644 --- a/main.js +++ b/main.js @@ -191,7 +191,8 @@ app.on('ready', () => { clipboard.writeText(text) }); // 退出 - ipcMain.handle('quit', (event) => { + ipcMain.handle('quit', async (event) => { + await mainWindow.webContents.send('quitAndInstall'); quit() }); // 加入房间通知 diff --git a/preload.js b/preload.js index 9a6fe1f..886b87a 100644 --- a/preload.js +++ b/preload.js @@ -37,6 +37,10 @@ window.electron = { onUpdate: (callback) => { ipcRenderer.on('update', callback) }, + // 执行退出房间 + quitAndInstall: (callback) => { + ipcRenderer.on('quitAndInstall', callback) + }, // 通知下载最新的包 onDownload: (type) => { ipcRenderer.invoke('updateDownload', type) diff --git a/src/App.tsx b/src/App.tsx index 669dc26..41022d6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -129,6 +129,15 @@ const App: React.FC = () => { } storage.setItem('setting', JSON.stringify(setting)) }) + window.electron.quitAndInstall(async (_e: any) => { + if (location.hash.indexOf('/meeting') === 1) { + const data = JSON.parse(localStorage.stateInfo); + await onInvoke('levelChannel', { + roomNum: data.channelId + }) + await agora.leaveChannel() + } + }) }, []) useEffect(() => { onInvitation((item: any) => { @@ -171,13 +180,6 @@ const App: React.FC = () => { setIsState(false) window.electron.onQuit(async () => { if (storage.getItem('isTips') === 'true') { - if (location.hash.indexOf('/meeting') !== -1) { - const data = JSON.parse(localStorage.stateInfo); - await onInvoke('levelChannel', { - roomNum: data.channelId - }) - await agora.leaveChannel() - } window.electron.quit() } else { quitTipsRef.current.changeModal() diff --git a/src/render.d.ts b/src/render.d.ts index d37abc9..6e1f479 100644 --- a/src/render.d.ts +++ b/src/render.d.ts @@ -13,6 +13,7 @@ export interface IElectronAPI { getSources: () => any; quit: () => any; downFile: (callBack: Function) => void; + quitAndInstall: (callBack: Function) => void; } declare global {