Skip to content

Commit ed41b25

Browse files
francescospissuAkos Kitta
and
Akos Kitta
authored
IDE startup theme based on OS theme (#1160)
* add patch for setting IDE startup theme based on OS theme * Patched the default theme behavior. Signed-off-by: Akos Kitta <[email protected]> * add custom themes in register Co-authored-by: Akos Kitta <[email protected]>
1 parent 4f27725 commit ed41b25

File tree

6 files changed

+72
-3
lines changed

6 files changed

+72
-3
lines changed

Diff for: electron/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ working-copy/
66
src-gen/
77
node_modules/
88
build/yarn.lock
9-
webpack.config.js
109
lib/
1110

1211
# The electron-builder output.
File renamed without changes.

Diff for: electron/build/patch/frontend/index.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Patch for the startup theme. Customizes the `ThemeService.get().defaultTheme();` to dispatch the default IDE2 theme based on the OS' theme.
2+
// For all subsequent starts of the IDE the theme applied will be the last one set by the user.
3+
4+
// With the current version of Theia adopted (1.25) it is not possible to extend the `ThemeService`, it will be possible starting from Theia 1.27.
5+
// Once the version of Theia is updated, this patch will be removed and this functionality will be implemented via dependency injection.
6+
// Ideally, we should open a PR in Theia and add support for `light` and `dark` default themes in the app config.
7+
8+
const {
9+
ThemeService,
10+
ThemeServiceSymbol,
11+
BuiltinThemeProvider,
12+
} = require('@theia/core/lib/browser/theming');
13+
const {
14+
ApplicationProps,
15+
} = require('@theia/application-package/lib/application-props');
16+
17+
const lightTheme = 'arduino-theme';
18+
const darkTheme = 'arduino-theme-dark';
19+
const defaultTheme =
20+
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
21+
? darkTheme
22+
: lightTheme;
23+
24+
const arduinoDarkTheme = {
25+
id: 'arduino-theme-dark',
26+
type: 'dark',
27+
label: 'Dark (Arduino)',
28+
editorTheme: 'arduino-theme-dark',
29+
activate() { },
30+
deactivate() { }
31+
};
32+
33+
const arduinoLightTheme = {
34+
id: 'arduino-theme',
35+
type: 'light',
36+
label: 'Light (Arduino)',
37+
editorTheme: 'arduino-theme',
38+
activate() { },
39+
deactivate() { }
40+
};
41+
42+
if (!window[ThemeServiceSymbol]) {
43+
const themeService = new ThemeService();
44+
Object.defineProperty(themeService, 'defaultTheme', {
45+
get: function () {
46+
return (
47+
this.themes[defaultTheme] ||
48+
this.themes[ApplicationProps.DEFAULT.frontend.config.defaultTheme]
49+
);
50+
},
51+
});
52+
themeService.register(...BuiltinThemeProvider.themes, arduinoDarkTheme, arduinoLightTheme);
53+
themeService.startupTheme();
54+
themeService.setCurrentTheme(defaultTheme);
55+
window[ThemeServiceSymbol] = themeService;
56+
}
57+
58+
// Require the original, generated `index.js` for `webpack` as the next entry for the `bundle.js`.
59+
require('../../src-gen/frontend/index');

Diff for: electron/build/template-package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"package": "cross-env DEBUG=* && electron-builder --publish=never",
2424
"package:publish": "cross-env DEBUG=* && electron-builder --publish=always",
2525
"download:plugins": "theia download:plugins",
26-
"patch": "ncp ./patch/main.js ./src-gen/backend/main.js && node ./scripts/patch-theia-preload.js ./lib/index.html"
26+
"patch": "ncp ./patch/backend/main.js ./src-gen/backend/main.js && node ./scripts/patch-theia-preload.js ./lib/index.html"
2727
},
2828
"engines": {
2929
"node": ">=14.0.0 <15"
@@ -157,4 +157,4 @@
157157
"vscode-language-pack-pt-BR": "https://open-vsx.org/api/MS-CEINTL/vscode-language-pack-pt-BR/1.69.0/file/MS-CEINTL.vscode-language-pack-pt-BR-1.69.0.vsix",
158158
"vscode-language-pack-cs": "https://open-vsx.org/api/MS-CEINTL/vscode-language-pack-cs/1.69.0/file/MS-CEINTL.vscode-language-pack-cs-1.69.0.vsix"
159159
}
160-
}
160+
}

Diff for: electron/build/webpack.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
const config = require('./gen-webpack.config.js');
3+
const path = require('path');
4+
5+
// Load the patched `index.js` that sets the desired theme in IDE2 based on the OS' theme.
6+
// The `patch/frontend/index.js` will require the original, generated `index.js`.
7+
// See: https://github.com/arduino/arduino-ide/pull/1160.
8+
config.entry.bundle = path.resolve(__dirname, 'patch/frontend/index.js');
9+
10+
module.exports = config;

Diff for: electron/packager/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
'resources',
5353
'scripts',
5454
'template-package.json',
55+
'webpack.config.js'
5556
];
5657
fs.readdirSync(path('..', 'build'))
5758
.filter((filename) => resourcesToKeep.indexOf(filename) === -1)

0 commit comments

Comments
 (0)