Skip to content

Commit

Permalink
Merge pull request #209 from jeffvli/fix/#202
Browse files Browse the repository at this point in the history
Add frame to macOS native window bar
  • Loading branch information
kgarner7 authored Jan 23, 2024
2 parents c8701d1 + 5e9ef9f commit 61ecd32
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/main/features/core/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ipcMain, safeStorage } from 'electron';
import { ipcMain, nativeTheme, safeStorage } from 'electron';
import Store from 'electron-store';
import type { TitleTheme } from '/@/renderer/types';

export const store = new Store();

Expand Down Expand Up @@ -48,3 +49,8 @@ ipcMain.handle('password-set', (_event, password: string, server: string) => {
}
return false;
});

ipcMain.on('theme-set', (_event, theme: TitleTheme) => {
store.set('theme', theme);
nativeTheme.themeSource = theme;
});
9 changes: 7 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Tray,
Menu,
nativeImage,
nativeTheme,
BrowserWindowConstructorOptions,
protocol,
net,
Expand All @@ -34,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';

Expand Down Expand Up @@ -194,8 +196,8 @@ const createWindow = async () => {
},
macOS: {
autoHideMenuBar: true,
frame: false,
titleBarStyle: 'hidden',
frame: true,
titleBarStyle: 'default',
trafficLightPosition: { x: 10, y: 10 },
},
windows: {
Expand Down Expand Up @@ -414,6 +416,9 @@ const createWindow = async () => {
// eslint-disable-next-line
new AppUpdater();
}

const theme = store.get('theme') as TitleTheme | undefined;
nativeTheme.themeSource = theme || 'dark';
};

app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService');
Expand Down
6 changes: 6 additions & 0 deletions src/main/preload/local-settings.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -43,6 +44,10 @@ const fontError = (cb: (event: IpcRendererEvent, file: string) => void) => {
ipcRenderer.on('custom-font-error', cb);
};

const themeSet = (theme: TitleTheme): void => {
ipcRenderer.send('theme-set', theme);
};

export const localSettings = {
disableMediaKeys,
enableMediaKeys,
Expand All @@ -54,6 +59,7 @@ export const localSettings = {
restart,
set,
setZoomFactor,
themeSet,
};

export type LocalSettings = typeof localSettings;
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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',
);
}
}}
/>
),
Expand All @@ -42,12 +54,18 @@ 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) {
localSettings.themeSet(
theme === AppTheme.DEFAULT_DARK ? 'dark' : 'light',
);
}
}}
/>
),
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,5 @@ export enum FontType {
CUSTOM = 'custom',
SYSTEM = 'system',
}

export type TitleTheme = 'dark' | 'light' | 'system';

1 comment on commit 61ecd32

@vercel
Copy link

@vercel vercel bot commented on 61ecd32 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feishin – ./

feishin-jeffvli.vercel.app
feishin-git-development-jeffvli.vercel.app
feishin.vercel.app

Please sign in to comment.