asab_webui_shell 27.2.2 → 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.
|
@@ -41,6 +41,8 @@ class AttentionRequiredService extends _asab_webui_components.Service {
|
|
|
41
41
|
this.beaconWebSocket.onopen = () => {
|
|
42
42
|
this.connectionStatus('online');
|
|
43
43
|
console.log('Beacon WebSocket connection established.');
|
|
44
|
+
// Reset reconnection interval on successful connection
|
|
45
|
+
this.reconnectInterval = 5000;
|
|
44
46
|
};
|
|
45
47
|
this.beaconWebSocket.onmessage = message => {
|
|
46
48
|
try {
|
|
@@ -54,10 +56,10 @@ class AttentionRequiredService extends _asab_webui_components.Service {
|
|
|
54
56
|
};
|
|
55
57
|
this.beaconWebSocket.onerror = error => {
|
|
56
58
|
console.error("Beacon WebSocket error:", error);
|
|
57
|
-
console.error("Beacon WebSocket
|
|
59
|
+
console.error("Beacon WebSocket will attempt to reconnect...");
|
|
58
60
|
this.connectionStatus('offline');
|
|
59
61
|
this.distributeData({});
|
|
60
|
-
|
|
62
|
+
// onerror is always followed by onclose, so there is no need to reconnect here, since the reconnection happens in onclose
|
|
61
63
|
};
|
|
62
64
|
this.beaconWebSocket.onclose = () => {
|
|
63
65
|
this.connectionStatus('offline');
|
|
@@ -66,25 +68,16 @@ class AttentionRequiredService extends _asab_webui_components.Service {
|
|
|
66
68
|
leaves the application (not the screen).
|
|
67
69
|
*/
|
|
68
70
|
if (this.beaconWebSocket) {
|
|
69
|
-
// Close the WebSocket connection
|
|
70
|
-
this.beaconWebSocket.close();
|
|
71
|
-
|
|
72
|
-
// Clean up event listeners
|
|
73
71
|
this.beaconWebSocket.onopen = null;
|
|
74
72
|
this.beaconWebSocket.onmessage = null;
|
|
75
73
|
this.beaconWebSocket.onerror = null;
|
|
76
74
|
this.beaconWebSocket.onclose = null;
|
|
77
|
-
|
|
78
|
-
// Set WebSocket reference to null to free up memory
|
|
79
75
|
this.beaconWebSocket = null;
|
|
80
76
|
}
|
|
81
77
|
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.reconnectTimeout = null;
|
|
86
|
-
}
|
|
87
|
-
console.log("Beacon WebSocket connection closed.");
|
|
78
|
+
// Service should maintain connection throughout the application lifecycle.
|
|
79
|
+
console.log("Beacon WebSocket connection closed. Attempting to reconnect...");
|
|
80
|
+
this.reconnectBeaconWebSocket();
|
|
88
81
|
};
|
|
89
82
|
}
|
|
90
83
|
|
|
@@ -37,6 +37,8 @@ export default class AttentionRequiredService extends Service {
|
|
|
37
37
|
this.beaconWebSocket.onopen = () => {
|
|
38
38
|
this.connectionStatus('online');
|
|
39
39
|
console.log('Beacon WebSocket connection established.');
|
|
40
|
+
// Reset reconnection interval on successful connection
|
|
41
|
+
this.reconnectInterval = 5000;
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
this.beaconWebSocket.onmessage = (message) => {
|
|
@@ -52,10 +54,10 @@ export default class AttentionRequiredService extends Service {
|
|
|
52
54
|
|
|
53
55
|
this.beaconWebSocket.onerror = (error) => {
|
|
54
56
|
console.error("Beacon WebSocket error:", error);
|
|
55
|
-
console.error("Beacon WebSocket
|
|
57
|
+
console.error("Beacon WebSocket will attempt to reconnect...");
|
|
56
58
|
this.connectionStatus('offline');
|
|
57
59
|
this.distributeData({});
|
|
58
|
-
|
|
60
|
+
// onerror is always followed by onclose, so there is no need to reconnect here, since the reconnection happens in onclose
|
|
59
61
|
};
|
|
60
62
|
|
|
61
63
|
this.beaconWebSocket.onclose = () => {
|
|
@@ -65,26 +67,17 @@ export default class AttentionRequiredService extends Service {
|
|
|
65
67
|
leaves the application (not the screen).
|
|
66
68
|
*/
|
|
67
69
|
if (this.beaconWebSocket) {
|
|
68
|
-
// Close the WebSocket connection
|
|
69
|
-
this.beaconWebSocket.close();
|
|
70
|
-
|
|
71
|
-
// Clean up event listeners
|
|
72
70
|
this.beaconWebSocket.onopen = null;
|
|
73
71
|
this.beaconWebSocket.onmessage = null;
|
|
74
72
|
this.beaconWebSocket.onerror = null;
|
|
75
73
|
this.beaconWebSocket.onclose = null;
|
|
76
|
-
|
|
77
|
-
// Set WebSocket reference to null to free up memory
|
|
78
74
|
this.beaconWebSocket = null;
|
|
79
75
|
}
|
|
80
76
|
|
|
81
|
-
// Clear the reconnect timeout if it exists
|
|
82
|
-
if (this.reconnectTimeout) {
|
|
83
|
-
clearTimeout(this.reconnectTimeout);
|
|
84
|
-
this.reconnectTimeout = null;
|
|
85
|
-
}
|
|
86
77
|
|
|
87
|
-
|
|
78
|
+
// Service should maintain connection throughout the application lifecycle.
|
|
79
|
+
console.log("Beacon WebSocket connection closed. Attempting to reconnect...");
|
|
80
|
+
this.reconnectBeaconWebSocket();
|
|
88
81
|
};
|
|
89
82
|
}
|
|
90
83
|
|
|
@@ -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
|