Skip to content
Snippets Groups Projects
Commit fba9c5aa authored by Maxime Jacquemin's avatar Maxime Jacquemin Committed by Loïc Correnson
Browse files

[ivette] Default theme to system settings

parent f523414c
No related branches found
No related tags found
No related merge requests found
...@@ -621,8 +621,12 @@ ipcMain.handle( ...@@ -621,8 +621,12 @@ ipcMain.handle(
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
ipcMain.handle('theme-color:switch', (_evt, theme: 'dark' | 'light') => { type themes = 'dark' | 'light' | 'system';
// const theme = nativeTheme.shouldUseDarkColors ? 'light' : 'dark';
ipcMain.handle('theme-color:switch', (_evt, theme: themes) => {
nativeTheme.themeSource = theme; nativeTheme.themeSource = theme;
// return nativeTheme.shouldUseDarkColors; });
ipcMain.handle('theme-color:which-system', () => {
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
}); });
...@@ -242,6 +242,7 @@ ...@@ -242,6 +242,7 @@
.eva-probes .eva-transient { .eva-probes .eva-transient {
background: var(--eva-probes-transient); background: var(--eva-probes-transient);
align-items: center;
} }
.eva-probes .eva-transient.eva-focused { .eva-probes .eva-transient.eva-focused {
......
...@@ -33,30 +33,27 @@ ...@@ -33,30 +33,27 @@
import React from 'react'; import React from 'react';
// import { popupMenu } from 'dome'; import { usePromise } from 'dome/dome';
import * as Settings from 'dome/data/settings'; import * as Settings from 'dome/data/settings';
import { IconButton } from 'dome/controls/buttons'; import { IconButton } from 'dome/controls/buttons';
import 'codemirror/mode/clike/clike'; import 'codemirror/mode/clike/clike';
import '../colors/dark-code.css'; import '../colors/dark-code.css';
import { ipcRenderer } from 'electron';
export const THEMES = [ export const THEMES = [
{ id: 'default', label: 'Default' }, { id: 'light', label: 'Light' },
{ id: 'ambiance', label: 'Ambiance' }, { id: 'dark', label: 'Dark' },
{ id: 'solarized light', label: 'Solarized Light' }, { id: 'system', label: 'System' },
{ id: 'solarized dark', label: 'Solarized Dark' },
]; ];
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- AST View Preferences // --- AST View Preferences
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
export const ColorTheme = new Settings.GString('color-theme', 'light'); export const ColorTheme = new Settings.GString('color-theme', 'system');
export const AstTheme = new Settings.GString('ASTview.theme', 'default');
export const AstFontSize = new Settings.GNumber('ASTview.fontSize', 12); export const AstFontSize = new Settings.GNumber('ASTview.fontSize', 12);
export const AstWrapText = new Settings.GFalse('ASTview.wrapText'); export const AstWrapText = new Settings.GFalse('ASTview.wrapText');
export const SourceTheme = new Settings.GString('SourceCode.theme', 'default');
export const SourceFontSize = new Settings.GNumber('SourceCode.fontSize', 12); export const SourceFontSize = new Settings.GNumber('SourceCode.fontSize', 12);
export const SourceWrapText = new Settings.GFalse('SourceCode.wrapText'); export const SourceWrapText = new Settings.GFalse('SourceCode.wrapText');
...@@ -78,14 +75,24 @@ export interface ThemeControls { ...@@ -78,14 +75,24 @@ export interface ThemeControls {
wrapText: boolean; wrapText: boolean;
} }
export function forceThemeUpdate(theme: string) {
ipcRenderer.invoke('theme-color:switch', theme);
}
ipcRenderer.on('dome.ipc.settings.defaults', () => {
forceThemeUpdate('system');
});
export function useThemeColors() { export function useThemeColors() {
const [themeColors] = Settings.useGlobalSettings(ColorTheme); const [themeColors] = Settings.useGlobalSettings(ColorTheme);
const invoke = () => ipcRenderer.invoke('theme-color:which-system');
const { result } : { result: 'dark' | 'light' } = usePromise(invoke());
if (themeColors === 'system')
return result === 'dark' ? 'dark-code' : 'default';
return themeColors === 'dark' ? 'dark-code' : 'default'; return themeColors === 'dark' ? 'dark-code' : 'default';
} }
export function useThemeButtons(props: ThemeProps): ThemeControls { export function useThemeButtons(props: ThemeProps): ThemeControls {
// const [themeColors] = Settings.useGlobalSettings(ColorTheme);
// const theme = themeColors === 'dark' ? 'dark-code' : 'default';
const [fontSize, setFontSize] = Settings.useGlobalSettings(props.fontSize); const [fontSize, setFontSize] = Settings.useGlobalSettings(props.fontSize);
const [wrapText, setWrapText] = Settings.useGlobalSettings(props.wrapText); const [wrapText, setWrapText] = Settings.useGlobalSettings(props.wrapText);
const zoomIn = () => fontSize < 48 && setFontSize(fontSize + 2); const zoomIn = () => fontSize < 48 && setFontSize(fontSize + 2);
...@@ -111,12 +118,6 @@ export function useThemeButtons(props: ThemeProps): ThemeControls { ...@@ -111,12 +118,6 @@ export function useThemeButtons(props: ThemeProps): ThemeControls {
disabled={disabled} disabled={disabled}
title="Increase font size" title="Increase font size"
/>, />,
// <IconButton
// key="theme"
// icon="PAINTBRUSH"
// onClick={themePopup}
// title="Choose theme"
// />,
<IconButton <IconButton
key="wrap" key="wrap"
icon="WRAPTEXT" icon="WRAPTEXT"
......
...@@ -35,7 +35,6 @@ import * as Sidebar from 'dome/frame/sidebars'; ...@@ -35,7 +35,6 @@ import * as Sidebar from 'dome/frame/sidebars';
import * as Controller from './Controller'; import * as Controller from './Controller';
import * as Extensions from './Extensions'; import * as Extensions from './Extensions';
import * as Laboratory from './Laboratory'; import * as Laboratory from './Laboratory';
import { ipcRenderer } from 'electron';
import * as Settings from 'dome/data/settings'; import * as Settings from 'dome/data/settings';
import './loader'; import './loader';
import * as Preferences from 'ivette/prefs'; import * as Preferences from 'ivette/prefs';
...@@ -55,7 +54,7 @@ export default function Application(): JSX.Element { ...@@ -55,7 +54,7 @@ export default function Application(): JSX.Element {
}; };
const [ th, setTh ] = Settings.useGlobalSettings(Preferences.ColorTheme); const [ th, setTh ] = Settings.useGlobalSettings(Preferences.ColorTheme);
const change = (t: string) => ipcRenderer.invoke('theme-color:switch', t); const change = Preferences.forceThemeUpdate;
React.useState(() => change(th)); React.useState(() => change(th));
const other = th === 'dark' ? 'light' : 'dark'; const other = th === 'dark' ? 'light' : 'dark';
const themeTitle = 'Switch to ' + other + ' theme'; const themeTitle = 'Switch to ' + other + ' theme';
......
...@@ -77,7 +77,7 @@ function buildServerConfig(argv: string[], cwd?: string) { ...@@ -77,7 +77,7 @@ function buildServerConfig(argv: string[], cwd?: string) {
let command; let command;
let sockaddr; let sockaddr;
let cwdir = cwd; let cwdir = cwd;
for (let k = 0; k < argv.length; k++) { for (let k = 0; k < (argv ? argv.length : 0); k++) {
const v = argv[k]; const v = argv[k];
switch (v) { switch (v) {
case '--cwd': case '--cwd':
......
...@@ -72,6 +72,22 @@ function ThemeFields(props: P.ThemeProps) { ...@@ -72,6 +72,22 @@ function ThemeFields(props: P.ThemeProps) {
); );
} }
function ColorThemeFields() {
const [theme, setTheme] = Settings.useGlobalSettings(P.ColorTheme);
const elements = P.THEMES.map(({ id, label }) => {
return <option value={id} key={id}>{label}</option>;
});
const set = (t: string | undefined) => {
if (t) { P.forceThemeUpdate(t); setTheme(t); }
};
return (
<Forms.SelectField label={'Color theme'} state={[theme, undefined, set]}>
{elements}
</Forms.SelectField>
);
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Editor Command Forms // --- Editor Command Forms
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -93,6 +109,9 @@ function EditorCommandFields(props: P.EditorCommandProps) { ...@@ -93,6 +109,9 @@ function EditorCommandFields(props: P.EditorCommandProps) {
export default function Preferences() { export default function Preferences() {
return ( return (
<Forms.Page> <Forms.Page>
<Forms.Section label="Theme" unfold>
<ColorThemeFields/>
</Forms.Section>
<Forms.Section label="AST View" unfold> <Forms.Section label="AST View" unfold>
<ThemeFields <ThemeFields
target="Internal AST" target="Internal AST"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment