feishin/src/renderer/features/settings/components/hotkeys/window-hotkey-settings.tsx

48 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-03-31 07:26:10 -07:00
import isElectron from 'is-electron';
import { useTranslation } from 'react-i18next';
2023-03-31 07:26:10 -07:00
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 { t } = useTranslation();
2023-07-01 19:10:05 -07:00
const settings = useHotkeySettings();
const { setSettings } = useSettingsStoreActions();
2023-03-31 07:26:10 -07:00
2023-07-01 19:10:05 -07:00
const options: SettingOption[] = [
{
control: (
<Switch
defaultChecked={settings.globalMediaHotkeys}
disabled={!isElectron()}
onChange={(e) => {
setSettings({
hotkeys: {
...settings,
globalMediaHotkeys: e.currentTarget.checked,
},
});
localSettings!.set('global_media_hotkeys', e.currentTarget.checked);
2023-03-31 07:26:10 -07:00
2023-07-01 19:10:05 -07:00
if (e.currentTarget.checked) {
localSettings!.enableMediaKeys();
2023-07-01 19:10:05 -07:00
} else {
localSettings!.disableMediaKeys();
2023-07-01 19:10:05 -07:00
}
}}
/>
),
description: t('setting.globalMediaHotkeys', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: !isElectron(),
title: t('setting.globalMediaHotkeys', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
];
2023-03-31 07:26:10 -07:00
2023-07-01 19:10:05 -07:00
return <SettingsSection options={options} />;
2023-03-31 07:26:10 -07:00
};