Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix]: defer restore queue until mpv exists #435

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,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 || [])]);
Expand All @@ -457,15 +460,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);
Expand Down Expand Up @@ -530,15 +532,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);
},
);

Expand Down
4 changes: 2 additions & 2 deletions src/main/preload/mpv-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const App = () => {
...getMpvProperties(useSettingsStore.getState().playback.mpvProperties),
};

mpvPlayer?.initialize({
await mpvPlayer?.initialize({
extraParameters,
properties,
});
Expand Down
Loading