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