diff --git a/ivette/src/dome/main/dome.ts b/ivette/src/dome/main/dome.ts index 8296d357d9760c98ee9f4320b13aed3535ebfd39..5930229d41cc37d222793a6adfece9965236419f 100644 --- a/ivette/src/dome/main/dome.ts +++ b/ivette/src/dome/main/dome.ts @@ -621,8 +621,12 @@ ipcMain.handle( // -------------------------------------------------------------------------- -ipcMain.handle('theme-color:switch', (_evt, theme: 'dark' | 'light') => { - // const theme = nativeTheme.shouldUseDarkColors ? 'light' : 'dark'; +type themes = 'dark' | 'light' | 'system'; + +ipcMain.handle('theme-color:switch', (_evt, theme: themes) => { nativeTheme.themeSource = theme; - // return nativeTheme.shouldUseDarkColors; +}); + +ipcMain.handle('theme-color:which-system', () => { + return nativeTheme.shouldUseDarkColors ? 'dark' : 'light'; }); diff --git a/ivette/src/frama-c/plugins/eva/style.css b/ivette/src/frama-c/plugins/eva/style.css index cf8dbf70ee0f55dffed717d127863b38810c1464..3dd5be0b82191f7e234969da8d661bffaa387a1b 100644 --- a/ivette/src/frama-c/plugins/eva/style.css +++ b/ivette/src/frama-c/plugins/eva/style.css @@ -242,6 +242,7 @@ .eva-probes .eva-transient { background: var(--eva-probes-transient); + align-items: center; } .eva-probes .eva-transient.eva-focused { diff --git a/ivette/src/ivette/prefs.tsx b/ivette/src/ivette/prefs.tsx index a4a6919aceef4bdbff46cdf6e465662caf5c70ae..0e9b3dece18684ce6984ec4dc65b8c46f0e00679 100644 --- a/ivette/src/ivette/prefs.tsx +++ b/ivette/src/ivette/prefs.tsx @@ -33,30 +33,27 @@ import React from 'react'; -// import { popupMenu } from 'dome'; +import { usePromise } from 'dome/dome'; import * as Settings from 'dome/data/settings'; import { IconButton } from 'dome/controls/buttons'; import 'codemirror/mode/clike/clike'; import '../colors/dark-code.css'; +import { ipcRenderer } from 'electron'; export const THEMES = [ - { id: 'default', label: 'Default' }, - { id: 'ambiance', label: 'Ambiance' }, - { id: 'solarized light', label: 'Solarized Light' }, - { id: 'solarized dark', label: 'Solarized Dark' }, + { id: 'light', label: 'Light' }, + { id: 'dark', label: 'Dark' }, + { id: 'system', label: 'System' }, ]; // -------------------------------------------------------------------------- // --- AST View Preferences // -------------------------------------------------------------------------- -export const ColorTheme = new Settings.GString('color-theme', 'light'); -export const AstTheme = new Settings.GString('ASTview.theme', 'default'); +export const ColorTheme = new Settings.GString('color-theme', 'system'); export const AstFontSize = new Settings.GNumber('ASTview.fontSize', 12); 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 SourceWrapText = new Settings.GFalse('SourceCode.wrapText'); @@ -78,14 +75,24 @@ export interface ThemeControls { wrapText: boolean; } +export function forceThemeUpdate(theme: string) { + ipcRenderer.invoke('theme-color:switch', theme); +} + +ipcRenderer.on('dome.ipc.settings.defaults', () => { + forceThemeUpdate('system'); +}); + export function useThemeColors() { 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'; } 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 [wrapText, setWrapText] = Settings.useGlobalSettings(props.wrapText); const zoomIn = () => fontSize < 48 && setFontSize(fontSize + 2); @@ -111,12 +118,6 @@ export function useThemeButtons(props: ThemeProps): ThemeControls { disabled={disabled} title="Increase font size" />, - // <IconButton - // key="theme" - // icon="PAINTBRUSH" - // onClick={themePopup} - // title="Choose theme" - // />, <IconButton key="wrap" icon="WRAPTEXT" diff --git a/ivette/src/renderer/Application.tsx b/ivette/src/renderer/Application.tsx index 598b24836db0bc96997a15037e678a660b6f9efc..e08c9536932c367e89fd9cb1c9c20cd2436c3710 100644 --- a/ivette/src/renderer/Application.tsx +++ b/ivette/src/renderer/Application.tsx @@ -35,7 +35,6 @@ import * as Sidebar from 'dome/frame/sidebars'; import * as Controller from './Controller'; import * as Extensions from './Extensions'; import * as Laboratory from './Laboratory'; -import { ipcRenderer } from 'electron'; import * as Settings from 'dome/data/settings'; import './loader'; import * as Preferences from 'ivette/prefs'; @@ -55,7 +54,7 @@ export default function Application(): JSX.Element { }; 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)); const other = th === 'dark' ? 'light' : 'dark'; const themeTitle = 'Switch to ' + other + ' theme'; diff --git a/ivette/src/renderer/Controller.tsx b/ivette/src/renderer/Controller.tsx index 7cfdc5bf4e51e32b0f2d4cd3235fe995c108113a..b7236c770d5fb4debd3ae8086ae298ad4f03c392 100644 --- a/ivette/src/renderer/Controller.tsx +++ b/ivette/src/renderer/Controller.tsx @@ -77,7 +77,7 @@ function buildServerConfig(argv: string[], cwd?: string) { let command; let sockaddr; 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]; switch (v) { case '--cwd': diff --git a/ivette/src/renderer/Preferences.tsx b/ivette/src/renderer/Preferences.tsx index 6a2e8777fa98dd97b0595d13bfd8f53f70c8f16b..bff3987eec58793b02f98418e6e79385b3152cd8 100644 --- a/ivette/src/renderer/Preferences.tsx +++ b/ivette/src/renderer/Preferences.tsx @@ -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 // -------------------------------------------------------------------------- @@ -93,6 +109,9 @@ function EditorCommandFields(props: P.EditorCommandProps) { export default function Preferences() { return ( <Forms.Page> + <Forms.Section label="Theme" unfold> + <ColorThemeFields/> + </Forms.Section> <Forms.Section label="AST View" unfold> <ThemeFields target="Internal AST"