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 system theme for Windows and Mac Electron builds #2882

Merged
merged 6 commits into from
May 1, 2021
Merged
Changes from all 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
2 changes: 2 additions & 0 deletions desktop/app.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ const {
shell,
Menu,
session,
nativeTheme,
} = require('electron');

const path = require('path');
@@ -102,6 +103,7 @@ module.exports = function main() {
Menu.setApplicationMenu(
Menu.buildFromTemplate(createMenuTemplate(args), mainWindow)
);
nativeTheme.themeSource = settings.theme;
});

ipcMain.on('clearCookies', function () {
27 changes: 17 additions & 10 deletions desktop/menus/view-menu.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,22 @@ const buildViewMenu = (settings, isAuthenticated) => {
settings = settings || {};
isAuthenticated = isAuthenticated || false;

const themeSubMenu = [];
if (!platform.isLinux()) {
themeSubMenu.push({
label: '&System',
id: 'system',
});
}
themeSubMenu.push({
label: '&Light',
id: 'light',
});
themeSubMenu.push({
label: '&Dark',
id: 'dark',
});

const menu = {
label: '&View',
submenu: [
@@ -107,16 +123,7 @@ const buildViewMenu = (settings, isAuthenticated) => {
{
label: 'T&heme',
visible: isAuthenticated,
submenu: [
{
label: '&Light',
id: 'light',
},
{
label: '&Dark',
id: 'dark',
},
].map(
submenu: themeSubMenu.map(
buildRadioGroup({
action: 'activateTheme',
propName: 'theme',
1 change: 1 addition & 0 deletions desktop/preload.js
Original file line number Diff line number Diff line change
@@ -60,4 +60,5 @@ contextBridge.exposeInMainWorld('electron', {
}
},
isMac: process.platform === 'darwin',
isLinux: process.platform === 'linux',
});
6 changes: 2 additions & 4 deletions lib/dialogs/settings/panels/display.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Fragment, FunctionComponent } from 'react';
import { connect } from 'react-redux';

import { isElectron, isMac } from '../../../utils/platform';
import { isElectron, isLinux, isMac } from '../../../utils/platform';
import RadioGroup from '../../radio-settings-group';
import SettingsGroup, { Item } from '../../settings-group';
import ToggleGroup from '../../toggle-settings-group';
@@ -131,9 +131,7 @@ const DisplayPanel: FunctionComponent<Props> = (props) => (
onChange={props.setActiveTheme}
renderer={RadioGroup}
>
{navigator.userAgent.toLowerCase().indexOf(' electron/') === -1 && (
<Item title="System" slug="system" />
)}
{!isLinux && <Item title="System" slug="system" />}
<Item title="Light" slug="light" />
<Item title="Dark" slug="dark" />
</SettingsGroup>
1 change: 1 addition & 0 deletions lib/global.d.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ declare global {
electron: {
confirmLogout(changes: string): 'logout' | 'reconsider' | 'export';
isMac: boolean;
isLinux: boolean;
receive(command: 'appCommand', callback: (event: any) => any);
receive(command: 'editorCommand', callback: (event: any) => any);
receive(command: 'noteImportChannel', callback: (event: any) => any);
4 changes: 4 additions & 0 deletions lib/utils/platform.ts
Original file line number Diff line number Diff line change
@@ -10,3 +10,7 @@ export const CmdOrCtrl = isElectron && isMac ? 'Cmd' : 'Ctrl';
export const isSafari = /^((?!chrome|android).)*safari/i.test(
window.navigator.userAgent
);

export const isLinux = isElectron
? window?.electron?.isLinux
: navigator.appVersion.indexOf('Linux') !== -1;