Add local settings

This commit is contained in:
jeffvli
2022-10-24 22:38:06 -07:00
parent f09abdb4c6
commit 863dce88b7
6 changed files with 52 additions and 4 deletions
+16 -3
View File
@@ -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
-1
View File
@@ -1 +0,0 @@
declare module 'node-mpv';
+13
View File
@@ -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);
}
);
+6
View File
@@ -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');
},
+15
View File
@@ -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,
};
+2
View File
@@ -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;