mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-15 07:54:18 +02:00
Add local settings
This commit is contained in:
@@ -3,11 +3,24 @@ import MpvAPI from 'node-mpv';
|
|||||||
import { PlayerData } from '../../../../renderer/store';
|
import { PlayerData } from '../../../../renderer/store';
|
||||||
import { getMainWindow } from '../../../main';
|
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(
|
const mpv = new MpvAPI(
|
||||||
{
|
{
|
||||||
audio_only: true,
|
audio_only: true,
|
||||||
auto_restart: true,
|
auto_restart: true,
|
||||||
binary: 'C:/ProgramData/chocolatey/lib/mpv.install/tools/mpv.exe',
|
binary: 'C:/ProgramData/chocolatey/lib/mpv.install/tools/mpv.exe',
|
||||||
|
// binary: BINARY_PATH,
|
||||||
|
|
||||||
time_update: 1,
|
time_update: 1,
|
||||||
},
|
},
|
||||||
['--gapless-audio=yes', '--prefetch-playlist']
|
['--gapless-audio=yes', '--prefetch-playlist']
|
||||||
@@ -68,14 +81,14 @@ ipcMain.on('player-stop', async () => {
|
|||||||
await mpv.stop();
|
await mpv.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stops the player
|
// Goes to the next track in the playlist
|
||||||
ipcMain.on('player-next', async () => {
|
ipcMain.on('player-next', async () => {
|
||||||
await mpv.next();
|
await mpv.next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stops the player
|
// Goes to the previous track in the playlist
|
||||||
ipcMain.on('player-previous', async () => {
|
ipcMain.on('player-previous', async () => {
|
||||||
await mpv.previous();
|
await mpv.prev();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Seeks forward or backward by the given amount of seconds
|
// Seeks forward or backward by the given amount of seconds
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
declare module 'node-mpv';
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -61,6 +61,12 @@ contextBridge.exposeInMainWorld('electron', {
|
|||||||
RENDERER_PLAYER_STOP(cb: (event: IpcRendererEvent, data: any) => void) {
|
RENDERER_PLAYER_STOP(cb: (event: IpcRendererEvent, data: any) => void) {
|
||||||
ipcRenderer.on('renderer-player-stop', cb);
|
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() {
|
windowClose() {
|
||||||
ipcRenderer.send('window-close');
|
ipcRenderer.send('window-close');
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1 +1,16 @@
|
|||||||
|
import isElectron from 'is-electron';
|
||||||
|
|
||||||
export * from './hooks/useDefaultSettings';
|
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,
|
||||||
|
};
|
||||||
|
|||||||
Vendored
+2
@@ -33,6 +33,8 @@ declare global {
|
|||||||
RENDERER_PLAYER_STOP(
|
RENDERER_PLAYER_STOP(
|
||||||
cb: (event: IpcRendererEvent, data: any) => void
|
cb: (event: IpcRendererEvent, data: any) => void
|
||||||
): void;
|
): void;
|
||||||
|
SETTINGS_GET(data: { property: string }): any;
|
||||||
|
SETTINGS_SET(data: { property: string; value: any }): void;
|
||||||
windowClose(): void;
|
windowClose(): void;
|
||||||
windowMaximize(): void;
|
windowMaximize(): void;
|
||||||
windowMinimize(): void;
|
windowMinimize(): void;
|
||||||
|
|||||||
Reference in New Issue
Block a user