Merge pull request #209 from jeffvli/fix/#202

Add frame to macOS native window bar
This commit is contained in:
Kendall Garner 2024-01-23 05:07:10 +00:00 committed by GitHub
commit 61ecd3253e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import { ipcMain, safeStorage } from 'electron'; import { ipcMain, nativeTheme, safeStorage } from 'electron';
import Store from 'electron-store'; import Store from 'electron-store';
import type { TitleTheme } from '/@/renderer/types';
export const store = new Store(); export const store = new Store();
@ -48,3 +49,8 @@ ipcMain.handle('password-set', (_event, password: string, server: string) => {
} }
return false; return false;
}); });
ipcMain.on('theme-set', (_event, theme: TitleTheme) => {
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,
@ -34,6 +35,7 @@ import { store } from './features/core/settings/index';
import MenuBuilder from './menu'; import MenuBuilder from './menu';
import { hotkeyToElectronAccelerator, isLinux, isMacOS, isWindows, resolveHtmlPath } from './utils'; import { hotkeyToElectronAccelerator, isLinux, isMacOS, isWindows, resolveHtmlPath } from './utils';
import './features'; import './features';
import type { TitleTheme } from '/@/renderer/types';
declare module 'node-mpv'; declare module 'node-mpv';
@ -194,8 +196,8 @@ const createWindow = async () => {
}, },
macOS: { macOS: {
autoHideMenuBar: true, autoHideMenuBar: true,
frame: false, frame: true,
titleBarStyle: 'hidden', titleBarStyle: 'default',
trafficLightPosition: { x: 10, y: 10 }, trafficLightPosition: { x: 10, y: 10 },
}, },
windows: { windows: {
@ -414,6 +416,9 @@ const createWindow = async () => {
// eslint-disable-next-line // eslint-disable-next-line
new AppUpdater(); new AppUpdater();
} }
const theme = store.get('theme') as TitleTheme | undefined;
nativeTheme.themeSource = theme || 'dark';
}; };
app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService'); app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService');

View file

@ -1,5 +1,6 @@
import { IpcRendererEvent, ipcRenderer, webFrame } from 'electron'; import { IpcRendererEvent, ipcRenderer, webFrame } from 'electron';
import Store from 'electron-store'; import Store from 'electron-store';
import type { TitleTheme } from '/@/renderer/types';
const store = new Store(); const store = new Store();
@ -43,6 +44,10 @@ const fontError = (cb: (event: IpcRendererEvent, file: string) => void) => {
ipcRenderer.on('custom-font-error', cb); ipcRenderer.on('custom-font-error', cb);
}; };
const themeSet = (theme: TitleTheme): void => {
ipcRenderer.send('theme-set', theme);
};
export const localSettings = { export const localSettings = {
disableMediaKeys, disableMediaKeys,
enableMediaKeys, enableMediaKeys,
@ -54,6 +59,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,18 @@ 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) {
localSettings.themeSet(
theme === AppTheme.DEFAULT_DARK ? 'dark' : 'light',
);
}
}} }}
/> />
), ),

View file

@ -209,3 +209,5 @@ export enum FontType {
CUSTOM = 'custom', CUSTOM = 'custom',
SYSTEM = 'system', SYSTEM = 'system',
} }
export type TitleTheme = 'dark' | 'light' | 'system';