[bugfix]: handle unclean MPV exit with existing content

This commit is contained in:
Kendall Garner 2024-04-10 21:18:47 -07:00
parent f5e047c7f5
commit 9339c08777
No known key found for this signature in database
GPG key ID: 18D2767419676C87

View file

@ -180,7 +180,11 @@ ipcMain.handle(
// Clean up previous mpv instance
getMpvInstance()?.stop();
getMpvInstance()?.quit();
getMpvInstance()
?.quit()
.catch((error) => {
mpvLog({ action: 'Failed to quit existing MPV' }, error);
});
mpvInstance = null;
mpvInstance = await createMpv(data);
@ -211,11 +215,12 @@ ipcMain.handle(
ipcMain.on('player-quit', async () => {
try {
getMpvInstance()?.stop();
getMpvInstance()?.quit();
mpvInstance = null;
await getMpvInstance()?.stop();
await getMpvInstance()?.quit();
} catch (err: NodeMpvError | any) {
mpvLog({ action: 'Failed to quit mpv' }, err);
} finally {
mpvInstance = null;
}
});
@ -407,11 +412,19 @@ ipcMain.handle('player-get-time', async (): Promise<number | undefined> => {
}
});
app.on('before-quit', () => {
getMpvInstance()?.stop();
getMpvInstance()?.quit();
app.on('before-quit', async () => {
try {
await getMpvInstance()?.stop();
await getMpvInstance()?.quit();
} catch (err: NodeMpvError | any) {
mpvLog({ action: `Failed to cleanly before-quit` }, err);
}
});
app.on('window-all-closed', () => {
getMpvInstance()?.quit();
app.on('window-all-closed', async () => {
try {
await getMpvInstance()?.quit();
} catch (err: NodeMpvError | any) {
mpvLog({ action: `Failed to cleanly exit` }, err);
}
});