asab_webui_shell 27.2.3 → 27.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,7 +19,14 @@ var ThemeButton = () => {
|
|
|
19
19
|
} = (0, _asab_webui_components.useAppStore)();
|
|
20
20
|
var theme = (0, _asab_webui_components.useAppSelector)(state => state.theme);
|
|
21
21
|
var changeTheme = () => {
|
|
22
|
-
var newTheme = theme ==
|
|
22
|
+
var newTheme = theme == 'light' ? 'dark' : 'light';
|
|
23
|
+
|
|
24
|
+
// Saving the theme in localStorage only with manual modification
|
|
25
|
+
try {
|
|
26
|
+
localStorage.setItem('asabTheme', newTheme);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn('Failed to save theme to localStorage:', error);
|
|
29
|
+
}
|
|
23
30
|
dispatch({
|
|
24
31
|
type: _actions.CHANGE_THEME,
|
|
25
32
|
theme: newTheme
|
|
@@ -27,7 +34,7 @@ var ThemeButton = () => {
|
|
|
27
34
|
};
|
|
28
35
|
return /*#__PURE__*/_react.default.createElement(_reactstrap.NavLink, {
|
|
29
36
|
onClick: changeTheme,
|
|
30
|
-
title: t(
|
|
37
|
+
title: t('General|Change theme'),
|
|
31
38
|
href: "#"
|
|
32
39
|
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
33
40
|
className: "bi bi-circle-half"
|
|
@@ -11,27 +11,44 @@ var _ThemeButton = _interopRequireDefault(require("./ThemeButton"));
|
|
|
11
11
|
var _actions = require("./actions");
|
|
12
12
|
class ThemeService extends _asab_webui_components.Service {
|
|
13
13
|
constructor(app) {
|
|
14
|
-
var serviceName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
|
14
|
+
var serviceName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ThemeService';
|
|
15
15
|
super(app, serviceName);
|
|
16
|
-
app.ReduxService.addReducer(
|
|
16
|
+
app.ReduxService.addReducer('theme', _ThemeReducer.default);
|
|
17
17
|
}
|
|
18
18
|
initialize() {
|
|
19
19
|
var _this$App, _this$App$dispatch;
|
|
20
|
-
var headerService = this.App.locateService(
|
|
20
|
+
var headerService = this.App.locateService('HeaderService');
|
|
21
21
|
headerService.addComponent({
|
|
22
22
|
component: _ThemeButton.default,
|
|
23
23
|
order: 400,
|
|
24
24
|
fullscreenVisible: true
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
26
|
+
var initialTheme;
|
|
27
|
+
|
|
28
|
+
// Check localStorage (read-only, no saving)
|
|
29
|
+
try {
|
|
30
|
+
var savedTheme = localStorage.getItem('asabTheme');
|
|
31
|
+
if (savedTheme) {
|
|
32
|
+
initialTheme = savedTheme;
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.warn('Failed to read theme from localStorage:', error);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// If there is nothing in localStorage, use the browser preferences.
|
|
39
|
+
if (!initialTheme) {
|
|
40
|
+
/*
|
|
41
|
+
Detect initial theme (based on color-scheme aka user prefered theme)
|
|
42
|
+
Doesn't work in Chromiuim in Ubuntu
|
|
43
|
+
more info https://bugs.chromium.org/p/chromium/issues/detail?id=998903
|
|
44
|
+
*/
|
|
45
|
+
initialTheme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
46
|
+
}
|
|
30
47
|
|
|
31
48
|
// Dispatch theme
|
|
32
49
|
(_this$App = this.App) === null || _this$App === void 0 || (_this$App = _this$App.AppStore) === null || _this$App === void 0 || (_this$App$dispatch = _this$App.dispatch) === null || _this$App$dispatch === void 0 || _this$App$dispatch.call(_this$App, {
|
|
33
50
|
type: _actions.CHANGE_THEME,
|
|
34
|
-
theme:
|
|
51
|
+
theme: initialTheme
|
|
35
52
|
});
|
|
36
53
|
|
|
37
54
|
// TODO: Add listener to the system theme and change light/dark based on that
|