audio restart fixed
This commit is contained in:
parent
be61d521de
commit
7d23347ce5
4 changed files with 76 additions and 106 deletions
|
|
@ -4,6 +4,7 @@ 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";
|
||||
|
||||
interface WindowSettings {
|
||||
|
|
@ -17,6 +18,22 @@ interface TextMessage {
|
|||
content: string;
|
||||
}
|
||||
|
||||
interface RenderMessage {
|
||||
content: string;
|
||||
context: string;
|
||||
subContext: string;
|
||||
modifiers: string;
|
||||
time: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface IpcRendererPayload {
|
||||
endpoint: string;
|
||||
message: RenderMessage | null;
|
||||
}
|
||||
|
||||
let win: BrowserWindow | null;
|
||||
|
||||
const handleMessage = (_event, arg: TextMessage | Buffer ) => {
|
||||
sendMessage(arg);
|
||||
}
|
||||
|
|
@ -24,11 +41,29 @@ const handleMessage = (_event, arg: TextMessage | Buffer ) => {
|
|||
const windowMount = (): void => {
|
||||
backgroundMitt.emit('window-active', true);
|
||||
ipcMain.on('send-message', handleMessage);
|
||||
ipcMain.on('update-recorder', updateRecorder);
|
||||
}
|
||||
|
||||
export const createWindow = async (options: WindowSettings): Promise<BrowserWindow> => {
|
||||
const windowDismount = (): void => {
|
||||
win = null;
|
||||
backgroundMitt.emit('window-active', false);
|
||||
ipcMain.removeAllListeners('send-message');
|
||||
ipcMain.removeAllListeners('update-recorder');
|
||||
}
|
||||
|
||||
backgroundMitt.on('ipc-renderer', (payload: IpcRendererPayload) => {
|
||||
if (win)
|
||||
win.webContents.send(payload.endpoint, {
|
||||
message: payload.message
|
||||
});
|
||||
});
|
||||
|
||||
export const createWindow = async (options: WindowSettings): Promise<void> => {
|
||||
return new Promise((resolve, _reject) => {
|
||||
const win: BrowserWindow = new BrowserWindow({
|
||||
|
||||
if (win) resolve();
|
||||
|
||||
win= new BrowserWindow({
|
||||
width: options.width,
|
||||
height: options.height,
|
||||
resizable: options.resizable,
|
||||
|
|
@ -50,9 +85,12 @@ export const createWindow = async (options: WindowSettings): Promise<BrowserWind
|
|||
win.loadURL("app://./index.html");
|
||||
}
|
||||
|
||||
// Handle window close.
|
||||
win.on("closed", windowDismount);
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
windowMount();
|
||||
resolve(win);
|
||||
if (win)resolve();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue