[bugfix]: defer restore queue until mpv exists
This commit is contained in:
parent
960427fce8
commit
c5e08b643d
3 changed files with 18 additions and 16 deletions
|
@ -438,7 +438,10 @@ const DEFAULT_MPV_PARAMETERS = (extraParameters?: string[]) => {
|
||||||
|
|
||||||
let mpvInstance: MpvAPI | null = null;
|
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 { extraParameters, properties } = data;
|
||||||
|
|
||||||
const params = uniq([...DEFAULT_MPV_PARAMETERS(extraParameters), ...(extraParameters || [])]);
|
const params = uniq([...DEFAULT_MPV_PARAMETERS(extraParameters), ...(extraParameters || [])]);
|
||||||
|
@ -457,15 +460,14 @@ const createMpv = (data: { extraParameters?: string[]; properties?: Record<strin
|
||||||
params,
|
params,
|
||||||
);
|
);
|
||||||
|
|
||||||
// eslint-disable-next-line promise/catch-or-return
|
try {
|
||||||
mpv.start()
|
await mpv.start();
|
||||||
.catch((error) => {
|
} catch (error) {
|
||||||
console.log('MPV failed to start', error);
|
console.log('MPV failed to start', error);
|
||||||
})
|
} finally {
|
||||||
.finally(() => {
|
console.log('Setting MPV properties: ', properties);
|
||||||
console.log('Setting MPV properties: ', properties);
|
await mpv.setMultipleProperties(properties || {});
|
||||||
mpv.setMultipleProperties(properties || {});
|
}
|
||||||
});
|
|
||||||
|
|
||||||
mpv.on('status', (status, ...rest) => {
|
mpv.on('status', (status, ...rest) => {
|
||||||
console.log('MPV Event: status', status.property, status.value, rest);
|
console.log('MPV Event: status', status.property, status.value, rest);
|
||||||
|
@ -530,15 +532,15 @@ ipcMain.on(
|
||||||
'player-restart',
|
'player-restart',
|
||||||
async (_event, data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
async (_event, data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||||
mpvInstance?.quit();
|
mpvInstance?.quit();
|
||||||
mpvInstance = createMpv(data);
|
mpvInstance = await createMpv(data);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcMain.on(
|
ipcMain.handle(
|
||||||
'player-initialize',
|
'player-initialize',
|
||||||
async (_event, data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
async (_event, data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||||
console.log('Initializing MPV with data: ', data);
|
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';
|
import { PlayerData, PlayerState } from '/@/renderer/store';
|
||||||
|
|
||||||
const initialize = (data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
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> }) => {
|
const restart = (data: { extraParameters?: string[]; properties?: Record<string, any> }) => {
|
||||||
ipcRenderer.send('player-restart', data);
|
return ipcRenderer.invoke('player-restart', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isRunning = () => {
|
const isRunning = () => {
|
||||||
|
|
|
@ -108,7 +108,7 @@ export const App = () => {
|
||||||
...getMpvProperties(useSettingsStore.getState().playback.mpvProperties),
|
...getMpvProperties(useSettingsStore.getState().playback.mpvProperties),
|
||||||
};
|
};
|
||||||
|
|
||||||
mpvPlayer?.initialize({
|
await mpvPlayer?.initialize({
|
||||||
extraParameters,
|
extraParameters,
|
||||||
properties,
|
properties,
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue