titlebar switching

This commit is contained in:
Kendall Garner 2024-01-21 22:47:59 -08:00
parent f0f2f54e5a
commit 33972c2a83
No known key found for this signature in database
GPG key ID: 18D2767419676C87
4 changed files with 37 additions and 2 deletions

View file

@ -1,4 +1,4 @@
import { ipcMain, safeStorage } from 'electron'; import { ipcMain, nativeTheme, safeStorage } from 'electron';
import Store from 'electron-store'; import Store from 'electron-store';
export const store = new Store(); export const store = new Store();
@ -48,3 +48,8 @@ ipcMain.handle('password-set', (_event, password: string, server: string) => {
} }
return false; return false;
}); });
ipcMain.on('theme-set', (_event, theme: 'dark' | 'light' | 'system') => {
store.set('theme', theme);
nativeTheme.themeSource = theme;
});

View file

@ -20,6 +20,7 @@ import {
Tray, Tray,
Menu, Menu,
nativeImage, nativeImage,
nativeTheme,
BrowserWindowConstructorOptions, BrowserWindowConstructorOptions,
protocol, protocol,
net, net,
@ -414,6 +415,11 @@ const createWindow = async () => {
// eslint-disable-next-line // eslint-disable-next-line
new AppUpdater(); new AppUpdater();
} }
const theme = store.get('theme') as 'dark' | 'light' | 'system' | undefined;
if (theme) {
nativeTheme.themeSource = theme;
}
}; };
app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService'); app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService');

View file

@ -43,6 +43,10 @@ const fontError = (cb: (event: IpcRendererEvent, file: string) => void) => {
ipcRenderer.on('custom-font-error', cb); ipcRenderer.on('custom-font-error', cb);
}; };
const themeSet = (theme: 'dark' | 'light' | 'system'): void => {
ipcRenderer.send('theme-set', theme);
};
export const localSettings = { export const localSettings = {
disableMediaKeys, disableMediaKeys,
enableMediaKeys, enableMediaKeys,
@ -54,6 +58,7 @@ export const localSettings = {
restart, restart,
set, set,
setZoomFactor, setZoomFactor,
themeSet,
}; };
export type LocalSettings = typeof localSettings; export type LocalSettings = typeof localSettings;

View file

@ -7,8 +7,11 @@ import {
import { THEME_DATA } from '/@/renderer/hooks'; import { THEME_DATA } from '/@/renderer/hooks';
import { useGeneralSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store'; import { useGeneralSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store';
import { AppTheme } from '/@/renderer/themes/types'; import { AppTheme } from '/@/renderer/themes/types';
import isElectron from 'is-electron';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
const localSettings = isElectron() ? window.electron.localSettings : null;
export const ThemeSettings = () => { export const ThemeSettings = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const settings = useGeneralSettings(); const settings = useGeneralSettings();
@ -26,6 +29,15 @@ export const ThemeSettings = () => {
followSystemTheme: e.currentTarget.checked, followSystemTheme: e.currentTarget.checked,
}, },
}); });
if (localSettings) {
localSettings.themeSet(
e.currentTarget.checked
? 'system'
: settings.theme === AppTheme.DEFAULT_DARK
? 'dark'
: 'light',
);
}
}} }}
/> />
), ),
@ -42,12 +54,19 @@ export const ThemeSettings = () => {
data={THEME_DATA} data={THEME_DATA}
defaultValue={settings.theme} defaultValue={settings.theme}
onChange={(e) => { onChange={(e) => {
const theme = e as AppTheme;
setSettings({ setSettings({
general: { general: {
...settings, ...settings,
theme: e as AppTheme, theme,
}, },
}); });
if (localSettings) {
console.log(theme);
localSettings.themeSet(
theme === AppTheme.DEFAULT_DARK ? 'dark' : 'light',
);
}
}} }}
/> />
), ),