Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frame to macOS native window bar #209

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/features/core/settings/index.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Would be nice to have a shared type for the theme 'dark' | 'light' | 'system' since it's now being used in 3 places.

nativeTheme.themeSource = theme;
});
8 changes: 6 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 Down Expand Up @@ -194,8 +195,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 +415,9 @@ const createWindow = async () => {
// eslint-disable-next-line
new AppUpdater();
}

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

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

Choose a reason for hiding this comment

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

Unneeded console log

localSettings.themeSet(
theme === AppTheme.DEFAULT_DARK ? 'dark' : 'light',
);
}
}}
/>
),
Expand Down
Loading