mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-02 10:53:33 +00:00
parent
6b91ee4a25
commit
7562c619d2
3 changed files with 35 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import type { TitleTheme } from '/@/shared/types/types';
|
import type { TitleTheme } from '/@/shared/types/types';
|
||||||
|
|
||||||
import { ipcMain, nativeTheme, safeStorage } from 'electron';
|
import { dialog, ipcMain, nativeTheme, OpenDialogOptions, safeStorage } from 'electron';
|
||||||
import Store from 'electron-store';
|
import Store from 'electron-store';
|
||||||
|
|
||||||
export const store = new Store();
|
export const store = new Store();
|
||||||
|
|
@ -55,3 +55,12 @@ ipcMain.on('theme-set', (_event, theme: TitleTheme) => {
|
||||||
store.set('theme', theme);
|
store.set('theme', theme);
|
||||||
nativeTheme.themeSource = theme;
|
nativeTheme.themeSource = theme;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('open-file-selector', async (_event, options: OpenDialogOptions) => {
|
||||||
|
const result = await dialog.showOpenDialog({
|
||||||
|
...options,
|
||||||
|
properties: ['openFile'],
|
||||||
|
});
|
||||||
|
|
||||||
|
return result.filePaths[0] || null;
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { ipcRenderer, IpcRendererEvent, webFrame } from 'electron';
|
import { ipcRenderer, IpcRendererEvent, OpenDialogOptions, webFrame } from 'electron';
|
||||||
import Store from 'electron-store';
|
import Store from 'electron-store';
|
||||||
|
|
||||||
import { TitleTheme } from '/@/shared/types/types';
|
import { TitleTheme } from '/@/shared/types/types';
|
||||||
|
|
@ -57,6 +57,11 @@ const themeSet = (theme: TitleTheme): void => {
|
||||||
ipcRenderer.send('theme-set', theme);
|
ipcRenderer.send('theme-set', theme);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openFileSelector = async (options?: OpenDialogOptions) => {
|
||||||
|
const result = await ipcRenderer.invoke('open-file-selector', options);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export const toServerType = (value?: string): null | string => {
|
export const toServerType = (value?: string): null | string => {
|
||||||
switch (value?.toLowerCase()) {
|
switch (value?.toLowerCase()) {
|
||||||
case 'jellyfin':
|
case 'jellyfin':
|
||||||
|
|
@ -87,6 +92,7 @@ export const localSettings = {
|
||||||
env,
|
env,
|
||||||
fontError,
|
fontError,
|
||||||
get,
|
get,
|
||||||
|
openFileSelector,
|
||||||
passwordGet,
|
passwordGet,
|
||||||
passwordRemove,
|
passwordRemove,
|
||||||
passwordSet,
|
passwordSet,
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import { RiCloseLine, RiRestartLine } from 'react-icons/ri';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
FileInput,
|
|
||||||
NumberInput,
|
NumberInput,
|
||||||
Select,
|
Select,
|
||||||
Switch,
|
Switch,
|
||||||
Text,
|
Text,
|
||||||
Textarea,
|
Textarea,
|
||||||
|
TextInput,
|
||||||
} from '/@/renderer/components';
|
} from '/@/renderer/components';
|
||||||
import {
|
import {
|
||||||
SettingOption,
|
SettingOption,
|
||||||
|
|
@ -81,15 +81,23 @@ export const MpvSettings = () => {
|
||||||
|
|
||||||
const [mpvPath, setMpvPath] = useState('');
|
const [mpvPath, setMpvPath] = useState('');
|
||||||
|
|
||||||
const handleSetMpvPath = (e: File | null) => {
|
const handleSetMpvPath = async (clear?: boolean) => {
|
||||||
if (e === null) {
|
if (clear) {
|
||||||
localSettings?.set('mpv_path', undefined);
|
localSettings?.set('mpv_path', undefined);
|
||||||
setMpvPath('');
|
setMpvPath('');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
localSettings?.set('mpv_path', e.path);
|
const result = await localSettings?.openFileSelector();
|
||||||
setMpvPath(e.path);
|
|
||||||
|
if (result === null) {
|
||||||
|
localSettings?.set('mpv_path', undefined);
|
||||||
|
setMpvPath('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
localSettings?.set('mpv_path', result);
|
||||||
|
setMpvPath(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -160,13 +168,13 @@ export const MpvSettings = () => {
|
||||||
>
|
>
|
||||||
<RiRestartLine />
|
<RiRestartLine />
|
||||||
</Button>
|
</Button>
|
||||||
<FileInput
|
<TextInput
|
||||||
onChange={handleSetMpvPath}
|
onClick={() => handleSetMpvPath()}
|
||||||
rightSection={
|
rightSection={
|
||||||
mpvPath && (
|
mpvPath && (
|
||||||
<Button
|
<Button
|
||||||
compact
|
compact
|
||||||
onClick={() => handleSetMpvPath(null)}
|
onClick={() => handleSetMpvPath(true)}
|
||||||
tooltip={{
|
tooltip={{
|
||||||
label: t('common.clear', { postProcess: 'titleCase' }),
|
label: t('common.clear', { postProcess: 'titleCase' }),
|
||||||
openDelay: 0,
|
openDelay: 0,
|
||||||
|
|
@ -177,6 +185,8 @@ export const MpvSettings = () => {
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
type="button"
|
||||||
|
value={mpvPath}
|
||||||
width={200}
|
width={200}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue