From 3c278d5e178803369938571493fdec5b29b9835d Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 9 Aug 2023 21:07:27 -0700 Subject: [PATCH 1/5] Add frame to macOS native window bar --- src/main/main.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 61adc9e0d..99409cbed 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -11,11 +11,6 @@ import { access, constants, readFile, writeFile } from 'fs'; import path, { join } from 'path'; import { deflate, inflate } from 'zlib'; -import electronLocalShortcut from 'electron-localshortcut'; -import log from 'electron-log'; -import { autoUpdater } from 'electron-updater'; -import uniq from 'lodash/uniq'; -import MpvAPI from 'node-mpv'; import { app, BrowserWindow, @@ -27,6 +22,11 @@ import { nativeImage, BrowserWindowConstructorOptions, } from 'electron'; +import electronLocalShortcut from 'electron-localshortcut'; +import log from 'electron-log'; +import { autoUpdater } from 'electron-updater'; +import uniq from 'lodash/uniq'; +import MpvAPI from 'node-mpv'; import { disableMediaKeys, enableMediaKeys } from './features/core/player/media-keys'; import { store } from './features/core/settings/index'; import MenuBuilder from './menu'; @@ -198,7 +198,7 @@ const createWindow = async () => { }, macOS: { autoHideMenuBar: true, - frame: false, + frame: true, titleBarStyle: 'hidden', trafficLightPosition: { x: 10, y: 10 }, }, From 6f969294b0c430b3a10ae7b2304630c4afff12bd Mon Sep 17 00:00:00 2001 From: jeffvli Date: Thu, 10 Aug 2023 01:54:15 -0700 Subject: [PATCH 2/5] Set macos titlebarstyle to default --- src/main/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/main.ts b/src/main/main.ts index 99409cbed..dca1182fd 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -199,7 +199,7 @@ const createWindow = async () => { macOS: { autoHideMenuBar: true, frame: true, - titleBarStyle: 'hidden', + titleBarStyle: 'default', trafficLightPosition: { x: 10, y: 10 }, }, windows: { From 33972c2a831336e0bd354b711240fedb5c95ca75 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sun, 21 Jan 2024 22:47:59 -0800 Subject: [PATCH 3/5] titlebar switching --- src/main/features/core/settings/index.ts | 7 ++++++- src/main/main.ts | 6 ++++++ src/main/preload/local-settings.ts | 5 +++++ .../components/general/theme-settings.tsx | 21 ++++++++++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/features/core/settings/index.ts b/src/main/features/core/settings/index.ts index f45addea5..4d2a40643 100644 --- a/src/main/features/core/settings/index.ts +++ b/src/main/features/core/settings/index.ts @@ -1,4 +1,4 @@ -import { ipcMain, safeStorage } from 'electron'; +import { ipcMain, nativeTheme, safeStorage } from 'electron'; import Store from 'electron-store'; export const store = new Store(); @@ -48,3 +48,8 @@ ipcMain.handle('password-set', (_event, password: string, server: string) => { } return false; }); + +ipcMain.on('theme-set', (_event, theme: 'dark' | 'light' | 'system') => { + store.set('theme', theme); + nativeTheme.themeSource = theme; +}); diff --git a/src/main/main.ts b/src/main/main.ts index 8f92a810e..388351c0d 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -20,6 +20,7 @@ import { Tray, Menu, nativeImage, + nativeTheme, BrowserWindowConstructorOptions, protocol, net, @@ -414,6 +415,11 @@ const createWindow = async () => { // eslint-disable-next-line new AppUpdater(); } + + const theme = store.get('theme') as 'dark' | 'light' | 'system' | undefined; + if (theme) { + nativeTheme.themeSource = theme; + } }; app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService'); diff --git a/src/main/preload/local-settings.ts b/src/main/preload/local-settings.ts index a57b08c4f..ca8937bb8 100644 --- a/src/main/preload/local-settings.ts +++ b/src/main/preload/local-settings.ts @@ -43,6 +43,10 @@ const fontError = (cb: (event: IpcRendererEvent, file: string) => void) => { ipcRenderer.on('custom-font-error', cb); }; +const themeSet = (theme: 'dark' | 'light' | 'system'): void => { + ipcRenderer.send('theme-set', theme); +}; + export const localSettings = { disableMediaKeys, enableMediaKeys, @@ -54,6 +58,7 @@ export const localSettings = { restart, set, setZoomFactor, + themeSet, }; export type LocalSettings = typeof localSettings; diff --git a/src/renderer/features/settings/components/general/theme-settings.tsx b/src/renderer/features/settings/components/general/theme-settings.tsx index 07b3b8b7d..db82832fe 100644 --- a/src/renderer/features/settings/components/general/theme-settings.tsx +++ b/src/renderer/features/settings/components/general/theme-settings.tsx @@ -7,8 +7,11 @@ import { import { THEME_DATA } from '/@/renderer/hooks'; import { useGeneralSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store'; import { AppTheme } from '/@/renderer/themes/types'; +import isElectron from 'is-electron'; import { useTranslation } from 'react-i18next'; +const localSettings = isElectron() ? window.electron.localSettings : null; + export const ThemeSettings = () => { const { t } = useTranslation(); const settings = useGeneralSettings(); @@ -26,6 +29,15 @@ export const ThemeSettings = () => { 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} defaultValue={settings.theme} onChange={(e) => { + const theme = e as AppTheme; setSettings({ general: { ...settings, - theme: e as AppTheme, + theme, }, }); + if (localSettings) { + console.log(theme); + localSettings.themeSet( + theme === AppTheme.DEFAULT_DARK ? 'dark' : 'light', + ); + } }} /> ), From b3a9e7ccba5c48db65a42ea1d62ba0f60742b0e2 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sun, 21 Jan 2024 22:58:10 -0800 Subject: [PATCH 4/5] default theme dark --- src/main/main.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 388351c0d..501168054 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -417,9 +417,7 @@ const createWindow = async () => { } const theme = store.get('theme') as 'dark' | 'light' | 'system' | undefined; - if (theme) { - nativeTheme.themeSource = theme; - } + nativeTheme.themeSource = theme || 'dark'; }; app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService'); From 5e9ef9f23f53c3efb92d495be05cb5f7aa969cdd Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:52:14 -0800 Subject: [PATCH 5/5] use type, remove console --- src/main/features/core/settings/index.ts | 3 ++- src/main/main.ts | 3 ++- src/main/preload/local-settings.ts | 3 ++- .../features/settings/components/general/theme-settings.tsx | 1 - src/renderer/types.ts | 2 ++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/features/core/settings/index.ts b/src/main/features/core/settings/index.ts index 4d2a40643..f829ea588 100644 --- a/src/main/features/core/settings/index.ts +++ b/src/main/features/core/settings/index.ts @@ -1,5 +1,6 @@ import { ipcMain, nativeTheme, safeStorage } from 'electron'; import Store from 'electron-store'; +import type { TitleTheme } from '/@/renderer/types'; export const store = new Store(); @@ -49,7 +50,7 @@ ipcMain.handle('password-set', (_event, password: string, server: string) => { return false; }); -ipcMain.on('theme-set', (_event, theme: 'dark' | 'light' | 'system') => { +ipcMain.on('theme-set', (_event, theme: TitleTheme) => { store.set('theme', theme); nativeTheme.themeSource = theme; }); diff --git a/src/main/main.ts b/src/main/main.ts index 501168054..6649fa767 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -35,6 +35,7 @@ import { store } from './features/core/settings/index'; import MenuBuilder from './menu'; import { hotkeyToElectronAccelerator, isLinux, isMacOS, isWindows, resolveHtmlPath } from './utils'; import './features'; +import type { TitleTheme } from '/@/renderer/types'; declare module 'node-mpv'; @@ -416,7 +417,7 @@ const createWindow = async () => { new AppUpdater(); } - const theme = store.get('theme') as 'dark' | 'light' | 'system' | undefined; + const theme = store.get('theme') as TitleTheme | undefined; nativeTheme.themeSource = theme || 'dark'; }; diff --git a/src/main/preload/local-settings.ts b/src/main/preload/local-settings.ts index ca8937bb8..7b1b37320 100644 --- a/src/main/preload/local-settings.ts +++ b/src/main/preload/local-settings.ts @@ -1,5 +1,6 @@ import { IpcRendererEvent, ipcRenderer, webFrame } from 'electron'; import Store from 'electron-store'; +import type { TitleTheme } from '/@/renderer/types'; const store = new Store(); @@ -43,7 +44,7 @@ const fontError = (cb: (event: IpcRendererEvent, file: string) => void) => { ipcRenderer.on('custom-font-error', cb); }; -const themeSet = (theme: 'dark' | 'light' | 'system'): void => { +const themeSet = (theme: TitleTheme): void => { ipcRenderer.send('theme-set', theme); }; diff --git a/src/renderer/features/settings/components/general/theme-settings.tsx b/src/renderer/features/settings/components/general/theme-settings.tsx index db82832fe..af9230ca2 100644 --- a/src/renderer/features/settings/components/general/theme-settings.tsx +++ b/src/renderer/features/settings/components/general/theme-settings.tsx @@ -62,7 +62,6 @@ export const ThemeSettings = () => { }, }); if (localSettings) { - console.log(theme); localSettings.themeSet( theme === AppTheme.DEFAULT_DARK ? 'dark' : 'light', ); diff --git a/src/renderer/types.ts b/src/renderer/types.ts index a40018b70..1ede3dea6 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -209,3 +209,5 @@ export enum FontType { CUSTOM = 'custom', SYSTEM = 'system', } + +export type TitleTheme = 'dark' | 'light' | 'system';