Add hotkey settings tab
This commit is contained in:
parent
0d9224bc09
commit
f35152a169
5 changed files with 74 additions and 32 deletions
|
@ -0,0 +1,10 @@
|
||||||
|
import { Stack } from '@mantine/core';
|
||||||
|
import { WindowHotkeySettings } from './window-hotkey-settings';
|
||||||
|
|
||||||
|
export const HotkeysTab = () => {
|
||||||
|
return (
|
||||||
|
<Stack spacing="md">
|
||||||
|
<WindowHotkeySettings />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,44 @@
|
||||||
|
import isElectron from 'is-electron';
|
||||||
|
import { SettingOption, SettingsSection } from '../settings-section';
|
||||||
|
import { Switch } from '/@/renderer/components';
|
||||||
|
import { useHotkeySettings, useSettingsStoreActions } from '/@/renderer/store';
|
||||||
|
|
||||||
|
const localSettings = isElectron() ? window.electron.localSettings : null;
|
||||||
|
|
||||||
|
export const WindowHotkeySettings = () => {
|
||||||
|
const settings = useHotkeySettings();
|
||||||
|
const { setSettings } = useSettingsStoreActions();
|
||||||
|
|
||||||
|
const options: SettingOption[] = [
|
||||||
|
{
|
||||||
|
control: (
|
||||||
|
<Switch
|
||||||
|
aria-label="Toggle global media hotkeys"
|
||||||
|
defaultChecked={settings.globalMediaHotkeys}
|
||||||
|
disabled={!isElectron()}
|
||||||
|
onChange={(e) => {
|
||||||
|
setSettings({
|
||||||
|
hotkeys: {
|
||||||
|
...settings,
|
||||||
|
globalMediaHotkeys: e.currentTarget.checked,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
localSettings.set('global_media_hotkeys', e.currentTarget.checked);
|
||||||
|
|
||||||
|
if (e.currentTarget.checked) {
|
||||||
|
localSettings.enableMediaKeys();
|
||||||
|
} else {
|
||||||
|
localSettings.disableMediaKeys();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
description:
|
||||||
|
'Enable or disable the usage of your system media hotkeys to control the audio player',
|
||||||
|
isHidden: !isElectron(),
|
||||||
|
title: 'Global media hotkeys',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return <SettingsSection options={options} />;
|
||||||
|
};
|
|
@ -1,7 +1,7 @@
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { SelectItem, Stack } from '@mantine/core';
|
import { SelectItem, Stack } from '@mantine/core';
|
||||||
import isElectron from 'is-electron';
|
import isElectron from 'is-electron';
|
||||||
import { Select, FileInput, Slider, Switch, Textarea, Text, toast } from '/@/renderer/components';
|
import { Select, FileInput, Slider, Textarea, Text, toast } from '/@/renderer/components';
|
||||||
import {
|
import {
|
||||||
SettingsSection,
|
SettingsSection,
|
||||||
SettingOption,
|
SettingOption,
|
||||||
|
@ -230,34 +230,6 @@ export const AudioSettings = () => {
|
||||||
note: status === PlayerStatus.PLAYING ? 'Player must be paused' : undefined,
|
note: status === PlayerStatus.PLAYING ? 'Player must be paused' : undefined,
|
||||||
title: 'Crossfade Style',
|
title: 'Crossfade Style',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
control: (
|
|
||||||
<Switch
|
|
||||||
aria-label="Toggle global media hotkeys"
|
|
||||||
defaultChecked={settings.globalMediaHotkeys}
|
|
||||||
disabled={!isElectron()}
|
|
||||||
onChange={(e) => {
|
|
||||||
setSettings({
|
|
||||||
playback: {
|
|
||||||
...settings,
|
|
||||||
globalMediaHotkeys: e.currentTarget.checked,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
localSettings.set('global_media_hotkeys', e.currentTarget.checked);
|
|
||||||
|
|
||||||
if (e.currentTarget.checked) {
|
|
||||||
localSettings.enableMediaKeys();
|
|
||||||
} else {
|
|
||||||
localSettings.disableMediaKeys();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
description:
|
|
||||||
'Enable or disable the usage of your system media hotkeys to control the audio player (desktop only)',
|
|
||||||
isHidden: !isElectron(),
|
|
||||||
title: 'Global media hotkeys',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return <SettingsSection options={audioOptions} />;
|
return <SettingsSection options={audioOptions} />;
|
||||||
|
|
|
@ -22,6 +22,12 @@ const ApplicationTab = lazy(() =>
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const HotkeysTab = lazy(() =>
|
||||||
|
import('/@/renderer/features/settings/components/hotkeys/hotkeys-tab').then((module) => ({
|
||||||
|
default: module.HotkeysTab,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
const TabContainer = styled.div`
|
const TabContainer = styled.div`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
@ -45,6 +51,7 @@ export const SettingsContent = () => {
|
||||||
<Tabs.List>
|
<Tabs.List>
|
||||||
<Tabs.Tab value="general">General</Tabs.Tab>
|
<Tabs.Tab value="general">General</Tabs.Tab>
|
||||||
<Tabs.Tab value="playback">Playback</Tabs.Tab>
|
<Tabs.Tab value="playback">Playback</Tabs.Tab>
|
||||||
|
<Tabs.Tab value="hotkeys">Hotkeys</Tabs.Tab>
|
||||||
{isElectron() && <Tabs.Tab value="window">Window</Tabs.Tab>}
|
{isElectron() && <Tabs.Tab value="window">Window</Tabs.Tab>}
|
||||||
</Tabs.List>
|
</Tabs.List>
|
||||||
<Tabs.Panel value="general">
|
<Tabs.Panel value="general">
|
||||||
|
@ -53,6 +60,9 @@ export const SettingsContent = () => {
|
||||||
<Tabs.Panel value="playback">
|
<Tabs.Panel value="playback">
|
||||||
<PlaybackTab />
|
<PlaybackTab />
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
|
<Tabs.Panel value="hotkeys">
|
||||||
|
<HotkeysTab />
|
||||||
|
</Tabs.Panel>
|
||||||
{isElectron() && (
|
{isElectron() && (
|
||||||
<Tabs.Panel value="window">
|
<Tabs.Panel value="window">
|
||||||
<ApplicationTab />
|
<ApplicationTab />
|
||||||
|
|
|
@ -48,11 +48,13 @@ export interface SettingsState {
|
||||||
themeLight: AppTheme;
|
themeLight: AppTheme;
|
||||||
volumeWheelStep: number;
|
volumeWheelStep: number;
|
||||||
};
|
};
|
||||||
|
hotkeys: {
|
||||||
|
globalMediaHotkeys: boolean;
|
||||||
|
};
|
||||||
playback: {
|
playback: {
|
||||||
audioDeviceId?: string | null;
|
audioDeviceId?: string | null;
|
||||||
crossfadeDuration: number;
|
crossfadeDuration: number;
|
||||||
crossfadeStyle: CrossfadeStyle;
|
crossfadeStyle: CrossfadeStyle;
|
||||||
globalMediaHotkeys: boolean;
|
|
||||||
muted: boolean;
|
muted: boolean;
|
||||||
scrobble: {
|
scrobble: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
@ -63,7 +65,7 @@ export interface SettingsState {
|
||||||
style: PlaybackStyle;
|
style: PlaybackStyle;
|
||||||
type: PlaybackType;
|
type: PlaybackType;
|
||||||
};
|
};
|
||||||
tab: 'general' | 'playback' | 'window' | string;
|
tab: 'general' | 'playback' | 'window' | 'hotkeys' | string;
|
||||||
tables: {
|
tables: {
|
||||||
fullScreen: DataTableProps;
|
fullScreen: DataTableProps;
|
||||||
nowPlaying: DataTableProps;
|
nowPlaying: DataTableProps;
|
||||||
|
@ -103,11 +105,13 @@ const initialState: SettingsState = {
|
||||||
themeLight: AppTheme.DEFAULT_LIGHT,
|
themeLight: AppTheme.DEFAULT_LIGHT,
|
||||||
volumeWheelStep: 5,
|
volumeWheelStep: 5,
|
||||||
},
|
},
|
||||||
|
hotkeys: {
|
||||||
|
globalMediaHotkeys: false,
|
||||||
|
},
|
||||||
playback: {
|
playback: {
|
||||||
audioDeviceId: undefined,
|
audioDeviceId: undefined,
|
||||||
crossfadeDuration: 5,
|
crossfadeDuration: 5,
|
||||||
crossfadeStyle: CrossfadeStyle.EQUALPOWER,
|
crossfadeStyle: CrossfadeStyle.EQUALPOWER,
|
||||||
globalMediaHotkeys: false,
|
|
||||||
muted: false,
|
muted: false,
|
||||||
scrobble: {
|
scrobble: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -298,3 +302,5 @@ export const usePlayButtonBehavior = () =>
|
||||||
useSettingsStore((state) => state.general.playButtonBehavior, shallow);
|
useSettingsStore((state) => state.general.playButtonBehavior, shallow);
|
||||||
|
|
||||||
export const useWindowSettings = () => useSettingsStore((state) => state.window, shallow);
|
export const useWindowSettings = () => useSettingsStore((state) => state.window, shallow);
|
||||||
|
|
||||||
|
export const useHotkeySettings = () => useSettingsStore((state) => state.hotkeys, shallow);
|
||||||
|
|
Reference in a new issue