mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
remove preexisting save/restore playqueue handlers
This commit is contained in:
+3
-74
@@ -19,9 +19,8 @@ import {
|
|||||||
import electronLocalShortcut from 'electron-localshortcut';
|
import electronLocalShortcut from 'electron-localshortcut';
|
||||||
import log from 'electron-log/main';
|
import log from 'electron-log/main';
|
||||||
import { autoUpdater } from 'electron-updater';
|
import { autoUpdater } from 'electron-updater';
|
||||||
import { access, constants, readFile, writeFile } from 'fs';
|
import { access, constants } from 'fs';
|
||||||
import path, { join } from 'path';
|
import path, { join } from 'path';
|
||||||
import { deflate, inflate } from 'zlib';
|
|
||||||
|
|
||||||
import packageJson from '../../package.json';
|
import packageJson from '../../package.json';
|
||||||
import { disableMediaKeys, enableMediaKeys } from './features/core/player/media-keys';
|
import { disableMediaKeys, enableMediaKeys } from './features/core/player/media-keys';
|
||||||
@@ -372,36 +371,6 @@ async function createWindow(first = true): Promise<void> {
|
|||||||
disableMediaKeys();
|
disableMediaKeys();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('player-restore-queue', () => {
|
|
||||||
if (store.get('resume')) {
|
|
||||||
const queueLocation = join(app.getPath('userData'), 'queue');
|
|
||||||
|
|
||||||
access(queueLocation, constants.F_OK, (accessError) => {
|
|
||||||
if (accessError) {
|
|
||||||
console.error('unable to access saved queue: ', accessError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
readFile(queueLocation, (readError, buffer) => {
|
|
||||||
if (readError) {
|
|
||||||
console.error('failed to read saved queue: ', readError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
inflate(buffer, (decompressError, data) => {
|
|
||||||
if (decompressError) {
|
|
||||||
console.error('failed to decompress queue: ', decompressError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue = JSON.parse(data.toString());
|
|
||||||
getMainWindow()?.webContents.send('renderer-restore-queue', queue);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on('download-url', (_event, url: string) => {
|
ipcMain.on('download-url', (_event, url: string) => {
|
||||||
mainWindow?.webContents.downloadURL(url);
|
mainWindow?.webContents.downloadURL(url);
|
||||||
});
|
});
|
||||||
@@ -442,8 +411,6 @@ async function createWindow(first = true): Promise<void> {
|
|||||||
mainWindow = null;
|
mainWindow = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
let saved = false;
|
|
||||||
|
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', (event) => {
|
||||||
store.set('bounds', mainWindow?.getNormalBounds());
|
store.set('bounds', mainWindow?.getNormalBounds());
|
||||||
store.set('maximized', mainWindow?.isMaximized());
|
store.set('maximized', mainWindow?.isMaximized());
|
||||||
@@ -454,46 +421,8 @@ async function createWindow(first = true): Promise<void> {
|
|||||||
mainWindow?.hide();
|
mainWindow?.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!saved && store.get('resume')) {
|
if (forceQuit) {
|
||||||
event.preventDefault();
|
app.exit();
|
||||||
saved = true;
|
|
||||||
|
|
||||||
ipcMain.once('player-save-queue', async (_event, data: Record<string, any>) => {
|
|
||||||
const queueLocation = join(app.getPath('userData'), 'queue');
|
|
||||||
const serialized = JSON.stringify(data);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
|
||||||
deflate(serialized, { level: 1 }, (error, deflated) => {
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
writeFile(queueLocation, deflated, (writeError) => {
|
|
||||||
if (writeError) {
|
|
||||||
reject(writeError);
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('error saving queue state: ', error);
|
|
||||||
} finally {
|
|
||||||
if (!isMacOS()) {
|
|
||||||
mainWindow?.close();
|
|
||||||
}
|
|
||||||
if (forceQuit) {
|
|
||||||
app.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
getMainWindow()?.webContents.send('renderer-save-queue');
|
|
||||||
} else {
|
|
||||||
if (forceQuit) {
|
|
||||||
app.exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,26 +2,10 @@ import { ipcRenderer, IpcRendererEvent } from 'electron';
|
|||||||
|
|
||||||
import { isLinux, isMacOS, isWindows } from '../main/utils';
|
import { isLinux, isMacOS, isWindows } from '../main/utils';
|
||||||
|
|
||||||
const saveQueue = (data: Record<string, any>) => {
|
|
||||||
ipcRenderer.send('player-save-queue', data);
|
|
||||||
};
|
|
||||||
|
|
||||||
const restoreQueue = () => {
|
|
||||||
ipcRenderer.send('player-restore-queue');
|
|
||||||
};
|
|
||||||
|
|
||||||
const openItem = async (path: string) => {
|
const openItem = async (path: string) => {
|
||||||
return ipcRenderer.invoke('open-item', path);
|
return ipcRenderer.invoke('open-item', path);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSaveQueue = (cb: (event: IpcRendererEvent) => void) => {
|
|
||||||
ipcRenderer.on('renderer-save-queue', cb);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onRestoreQueue = (cb: (event: IpcRendererEvent, data: Partial<any>) => void) => {
|
|
||||||
ipcRenderer.on('renderer-restore-queue', cb);
|
|
||||||
};
|
|
||||||
|
|
||||||
const playerErrorListener = (cb: (event: IpcRendererEvent, data: { code: number }) => void) => {
|
const playerErrorListener = (cb: (event: IpcRendererEvent, data: { code: number }) => void) => {
|
||||||
ipcRenderer.on('player-error-listener', cb);
|
ipcRenderer.on('player-error-listener', cb);
|
||||||
};
|
};
|
||||||
@@ -58,12 +42,8 @@ export const utils = {
|
|||||||
isWindows,
|
isWindows,
|
||||||
logger,
|
logger,
|
||||||
mainMessageListener,
|
mainMessageListener,
|
||||||
onRestoreQueue,
|
|
||||||
onSaveQueue,
|
|
||||||
openItem,
|
openItem,
|
||||||
playerErrorListener,
|
playerErrorListener,
|
||||||
restoreQueue,
|
|
||||||
saveQueue,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Utils = typeof utils;
|
export type Utils = typeof utils;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ interface MpvPlayerEngineProps {
|
|||||||
const mpvPlayer = isElectron() ? window.api.mpvPlayer : null;
|
const mpvPlayer = isElectron() ? window.api.mpvPlayer : null;
|
||||||
const mpvPlayerListener = isElectron() ? window.api.mpvPlayerListener : null;
|
const mpvPlayerListener = isElectron() ? window.api.mpvPlayerListener : null;
|
||||||
const ipc = isElectron() ? window.api.ipc : null;
|
const ipc = isElectron() ? window.api.ipc : null;
|
||||||
const utils = isElectron() ? window.api.utils : null;
|
|
||||||
|
|
||||||
const PROGRESS_UPDATE_INTERVAL = 250;
|
const PROGRESS_UPDATE_INTERVAL = 250;
|
||||||
const TRANSITION_PROGRESS_INTERVAL = 10;
|
const TRANSITION_PROGRESS_INTERVAL = 10;
|
||||||
@@ -74,8 +73,6 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
|||||||
|
|
||||||
mpvPlayer?.volume(properties.volume);
|
mpvPlayer?.volume(properties.volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils?.restoreQueue();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
initializeMpv();
|
initializeMpv();
|
||||||
|
|||||||
Reference in New Issue
Block a user