diff --git a/src/main/features/core/player/index.ts b/src/main/features/core/player/index.ts index fff7df151..52269a543 100644 --- a/src/main/features/core/player/index.ts +++ b/src/main/features/core/player/index.ts @@ -3,11 +3,24 @@ import MpvAPI from 'node-mpv'; import { PlayerData } from '../../../../renderer/store'; import { getMainWindow } from '../../../main'; +declare module 'node-mpv'; + +// const BINARY_PATH = getMainWindow() +// ?.webContents.executeJavaScript('localStorage.getItem("mpv_binary");', true) +// .then((result) => { +// return result; +// }) +// .catch((err) => { +// console.log(err); +// }); + const mpv = new MpvAPI( { audio_only: true, auto_restart: true, binary: 'C:/ProgramData/chocolatey/lib/mpv.install/tools/mpv.exe', + // binary: BINARY_PATH, + time_update: 1, }, ['--gapless-audio=yes', '--prefetch-playlist'] @@ -68,14 +81,14 @@ ipcMain.on('player-stop', async () => { await mpv.stop(); }); -// Stops the player +// Goes to the next track in the playlist ipcMain.on('player-next', async () => { await mpv.next(); }); -// Stops the player +// Goes to the previous track in the playlist ipcMain.on('player-previous', async () => { - await mpv.previous(); + await mpv.prev(); }); // Seeks forward or backward by the given amount of seconds diff --git a/src/main/features/core/player/mpv.ts b/src/main/features/core/player/mpv.ts deleted file mode 100644 index c4c05e4f5..000000000 --- a/src/main/features/core/player/mpv.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'node-mpv'; diff --git a/src/main/features/core/settings/index.ts b/src/main/features/core/settings/index.ts new file mode 100644 index 000000000..f6fda43f0 --- /dev/null +++ b/src/main/features/core/settings/index.ts @@ -0,0 +1,13 @@ +import { ipcMain } from 'electron'; +import settings from 'electron-settings'; + +ipcMain.on('settings-get', async (__event, data: { property: string }) => { + return settings.getSync(data.property); +}); + +ipcMain.on( + 'settings-set', + async (__event, data: { property: string; value: any }) => { + return settings.setSync(data.property, data.value); + } +); diff --git a/src/main/preload.ts b/src/main/preload.ts index 13fbcd190..58e00c1da 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -61,6 +61,12 @@ contextBridge.exposeInMainWorld('electron', { RENDERER_PLAYER_STOP(cb: (event: IpcRendererEvent, data: any) => void) { ipcRenderer.on('renderer-player-stop', cb); }, + SETTINGS_GET(data: { property: string }) { + ipcRenderer.send('settings-get', data); + }, + SETTINGS_SET(data: { property: string; value: any }) { + ipcRenderer.send('settings-set', data); + }, windowClose() { ipcRenderer.send('window-close'); }, diff --git a/src/renderer/features/settings/index.ts b/src/renderer/features/settings/index.ts index 1e62be636..3d1c67e61 100644 --- a/src/renderer/features/settings/index.ts +++ b/src/renderer/features/settings/index.ts @@ -1 +1,16 @@ +import isElectron from 'is-electron'; + export * from './hooks/useDefaultSettings'; + +const ipc = isElectron() ? window.electron.ipcRenderer : null; + +const get = (property: string) => ipc?.SETTINGS_GET({ property }); + +const set = (property: string, value: any) => { + ipc?.SETTINGS_SET({ property, value }); +}; + +export const settings = { + get, + set, +}; diff --git a/src/renderer/preload.d.ts b/src/renderer/preload.d.ts index 8dba1e8d2..6b9ff31c6 100644 --- a/src/renderer/preload.d.ts +++ b/src/renderer/preload.d.ts @@ -33,6 +33,8 @@ declare global { RENDERER_PLAYER_STOP( cb: (event: IpcRendererEvent, data: any) => void ): void; + SETTINGS_GET(data: { property: string }): any; + SETTINGS_SET(data: { property: string; value: any }): void; windowClose(): void; windowMaximize(): void; windowMinimize(): void;