mirror of
https://github.com/jeffvli/feishin.git
synced 2024-11-20 06:27:09 +01:00
Merge pull request #435 from kgarner7/fix-init-timing
[bugfix]: defer restore queue until mpv exists
This commit is contained in:
commit
3bca85b3a8
@ -443,7 +443,10 @@ const DEFAULT_MPV_PARAMETERS = (extraParameters?: string[]) => {
|
||||
|
||||
let mpvInstance: MpvAPI | null = null;
|
||||
|
||||
const createMpv = (data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||
const createMpv = async (data: {
|
||||
extraParameters?: string[];
|
||||
properties?: Record<string, any>;
|
||||
}): Promise<MpvAPI> => {
|
||||
const { extraParameters, properties } = data;
|
||||
|
||||
const params = uniq([...DEFAULT_MPV_PARAMETERS(extraParameters), ...(extraParameters || [])]);
|
||||
@ -462,15 +465,14 @@ const createMpv = (data: { extraParameters?: string[]; properties?: Record<strin
|
||||
params,
|
||||
);
|
||||
|
||||
// eslint-disable-next-line promise/catch-or-return
|
||||
mpv.start()
|
||||
.catch((error) => {
|
||||
console.log('MPV failed to start', error);
|
||||
})
|
||||
.finally(() => {
|
||||
console.log('Setting MPV properties: ', properties);
|
||||
mpv.setMultipleProperties(properties || {});
|
||||
});
|
||||
try {
|
||||
await mpv.start();
|
||||
} catch (error) {
|
||||
console.log('MPV failed to start', error);
|
||||
} finally {
|
||||
console.log('Setting MPV properties: ', properties);
|
||||
await mpv.setMultipleProperties(properties || {});
|
||||
}
|
||||
|
||||
mpv.on('status', (status, ...rest) => {
|
||||
console.log('MPV Event: status', status.property, status.value, rest);
|
||||
@ -535,15 +537,15 @@ ipcMain.on(
|
||||
'player-restart',
|
||||
async (_event, data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||
mpvInstance?.quit();
|
||||
mpvInstance = createMpv(data);
|
||||
mpvInstance = await createMpv(data);
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.on(
|
||||
ipcMain.handle(
|
||||
'player-initialize',
|
||||
async (_event, data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||
console.log('Initializing MPV with data: ', data);
|
||||
mpvInstance = createMpv(data);
|
||||
mpvInstance = await createMpv(data);
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -2,11 +2,11 @@ import { ipcRenderer, IpcRendererEvent } from 'electron';
|
||||
import { PlayerData, PlayerState } from '/@/renderer/store';
|
||||
|
||||
const initialize = (data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||
ipcRenderer.send('player-initialize', data);
|
||||
return ipcRenderer.invoke('player-initialize', data);
|
||||
};
|
||||
|
||||
const restart = (data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||
ipcRenderer.send('player-restart', data);
|
||||
return ipcRenderer.invoke('player-restart', data);
|
||||
};
|
||||
|
||||
const isRunning = () => {
|
||||
|
@ -108,7 +108,7 @@ export const App = () => {
|
||||
...getMpvProperties(useSettingsStore.getState().playback.mpvProperties),
|
||||
};
|
||||
|
||||
mpvPlayer?.initialize({
|
||||
await mpvPlayer?.initialize({
|
||||
extraParameters,
|
||||
properties,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user