remove old message event listeners
This commit is contained in:
parent
e914c0ca14
commit
3cf22d61ac
13 changed files with 142 additions and 219 deletions
|
|
@ -3,7 +3,6 @@
|
|||
import { BrowserWindow, ipcMain } from "electron";
|
||||
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
||||
import { backgroundMitt } from './emitter';
|
||||
import { sendMessage } from './session';
|
||||
import { updateRecorder } from './audio';
|
||||
import * as path from "path";
|
||||
|
||||
|
|
@ -13,46 +12,35 @@ interface WindowSettings {
|
|||
resizable: boolean;
|
||||
}
|
||||
|
||||
interface TextMessage {
|
||||
audio: 0;
|
||||
content: string;
|
||||
}
|
||||
|
||||
interface RenderMessage {
|
||||
content: string;
|
||||
context: string;
|
||||
subContext: string;
|
||||
modifiers: string;
|
||||
time: string;
|
||||
id: string;
|
||||
content: string;
|
||||
context: string;
|
||||
subContext: string;
|
||||
modifiers: string;
|
||||
time: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface IpcRendererPayload {
|
||||
endpoint: string;
|
||||
message: RenderMessage | null;
|
||||
endpoint: string;
|
||||
message: RenderMessage | null;
|
||||
}
|
||||
|
||||
let win: BrowserWindow | null;
|
||||
|
||||
const handleMessage = (_event, arg: TextMessage | Buffer ) => {
|
||||
sendMessage(arg);
|
||||
}
|
||||
|
||||
const windowMount = (): void => {
|
||||
backgroundMitt.emit('window-active', true);
|
||||
ipcMain.on('send-message', handleMessage);
|
||||
ipcMain.on('update-recorder', updateRecorder);
|
||||
}
|
||||
|
||||
const windowDismount = (): void => {
|
||||
win = null;
|
||||
backgroundMitt.emit('window-active', false);
|
||||
ipcMain.removeAllListeners('send-message');
|
||||
ipcMain.removeAllListeners('update-recorder');
|
||||
win = null;
|
||||
backgroundMitt.emit('window-active', false);
|
||||
ipcMain.removeAllListeners('update-recorder');
|
||||
}
|
||||
|
||||
backgroundMitt.on('ipc-renderer', (payload: IpcRendererPayload) => {
|
||||
if (win)
|
||||
if (win)
|
||||
win.webContents.send(payload.endpoint, {
|
||||
message: payload.message
|
||||
});
|
||||
|
|
@ -63,7 +51,7 @@ export const createWindow = async (options: WindowSettings): Promise<void> => {
|
|||
|
||||
if (win) resolve();
|
||||
|
||||
win= new BrowserWindow({
|
||||
win = new BrowserWindow({
|
||||
width: options.width,
|
||||
height: options.height,
|
||||
resizable: options.resizable,
|
||||
|
|
@ -90,7 +78,7 @@ export const createWindow = async (options: WindowSettings): Promise<void> => {
|
|||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
windowMount();
|
||||
if (win)resolve();
|
||||
resolve();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue