Merge pull request #435 from kgarner7/fix-init-timing

[bugfix]: defer restore queue until mpv exists
This commit is contained in:
Kendall Garner 2024-01-23 05:18:20 +00:00 committed by GitHub
commit 3bca85b3a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 16 deletions

View File

@ -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);
},
);

View File

@ -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 = () => {

View File

@ -108,7 +108,7 @@ export const App = () => {
...getMpvProperties(useSettingsStore.getState().playback.mpvProperties),
};
mpvPlayer?.initialize({
await mpvPlayer?.initialize({
extraParameters,
properties,
});