mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 12:30:12 +02:00
Set MPV path from local settings file
This commit is contained in:
@@ -1 +1,2 @@
|
||||
import './player';
|
||||
import './settings';
|
||||
|
||||
@@ -2,25 +2,17 @@ import { ipcMain } from 'electron';
|
||||
import MpvAPI from 'node-mpv';
|
||||
import { PlayerData } from '../../../../renderer/store';
|
||||
import { getMainWindow } from '../../../main';
|
||||
import { store } from '../settings/index';
|
||||
|
||||
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 BINARY_PATH = store.get('mpv_path') as string;
|
||||
|
||||
const mpv = new MpvAPI(
|
||||
{
|
||||
audio_only: true,
|
||||
auto_restart: true,
|
||||
binary: 'C:/ProgramData/chocolatey/lib/mpv.install/tools/mpv.exe',
|
||||
// binary: BINARY_PATH,
|
||||
|
||||
binary: BINARY_PATH || '',
|
||||
time_update: 1,
|
||||
},
|
||||
['--gapless-audio=yes', '--prefetch-playlist']
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import settings from 'electron-settings';
|
||||
import Store from 'electron-store';
|
||||
|
||||
ipcMain.on('settings-get', async (__event, data: { property: string }) => {
|
||||
return settings.getSync(data.property);
|
||||
export const store = new Store();
|
||||
|
||||
ipcMain.handle('settings-get', (_event, data: { property: string }) => {
|
||||
return store.get(`${data.property}`);
|
||||
});
|
||||
|
||||
ipcMain.on(
|
||||
'settings-set',
|
||||
async (__event, data: { property: string; value: any }) => {
|
||||
return settings.setSync(data.property, data.value);
|
||||
(__event, data: { property: string; value: any }) => {
|
||||
store.set(`${data.property}`, data.value);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -100,6 +100,11 @@ const createWindow = async () => {
|
||||
mainWindow?.close();
|
||||
});
|
||||
|
||||
ipcMain.on('app-restart', () => {
|
||||
app.relaunch();
|
||||
app.exit(0);
|
||||
});
|
||||
|
||||
mainWindow.loadURL(resolveHtmlPath('index.html'));
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
|
||||
+4
-1
@@ -3,6 +3,9 @@ import { PlayerData } from '../renderer/store';
|
||||
|
||||
contextBridge.exposeInMainWorld('electron', {
|
||||
ipcRenderer: {
|
||||
APP_RESTART() {
|
||||
ipcRenderer.send('app-restart');
|
||||
},
|
||||
PLAYER_AUTO_NEXT(data: PlayerData) {
|
||||
ipcRenderer.send('player-auto-next', data);
|
||||
},
|
||||
@@ -62,7 +65,7 @@ contextBridge.exposeInMainWorld('electron', {
|
||||
ipcRenderer.on('renderer-player-stop', cb);
|
||||
},
|
||||
SETTINGS_GET(data: { property: string }) {
|
||||
ipcRenderer.send('settings-get', data);
|
||||
return ipcRenderer.invoke('settings-get', data);
|
||||
},
|
||||
SETTINGS_SET(data: { property: string; value: any }) {
|
||||
ipcRenderer.send('settings-set', data);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import isElectron from 'is-electron';
|
||||
|
||||
export * from './hooks/useDefaultSettings';
|
||||
export * from './hooks/use-default-settings';
|
||||
|
||||
const ipc = isElectron() ? window.electron.ipcRenderer : null;
|
||||
|
||||
@@ -10,7 +10,12 @@ const set = (property: string, value: any) => {
|
||||
ipc?.SETTINGS_SET({ property, value });
|
||||
};
|
||||
|
||||
const restart = () => {
|
||||
ipc?.APP_RESTART();
|
||||
};
|
||||
|
||||
export const settings = {
|
||||
get,
|
||||
restart,
|
||||
set,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user