iobroker.mywebui 1.37.41 → 1.37.42

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.
@@ -0,0 +1,81 @@
1
+ /**
2
+ * pre-start.mjs — clears stale alive state before adapter starts.
3
+ *
4
+ * Root cause of ADAPTER_ALREADY_RUNNING:
5
+ * onUnload() in main adapter does not call its callback →
6
+ * ioBroker kills the process via SIGKILL on shutdown →
7
+ * alive state is never cleared →
8
+ * next start sees alive=true → exit code 7 → adapter disabled.
9
+ *
10
+ * Fix: clear system.adapter.mywebui.0.alive before starting main.js.
11
+ */
12
+
13
+ import { createRequire } from 'node:module';
14
+ import { readFileSync } from 'node:fs';
15
+ import { fileURLToPath } from 'node:url';
16
+ import path from 'node:path';
17
+
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+ const require = createRequire(import.meta.url);
21
+
22
+ async function clearAliveState() {
23
+ try {
24
+ // Get ioBroker config file path using js-controller-common (available in parent node_modules)
25
+ let statesHost = '127.0.0.1';
26
+ let statesPort = 9020;
27
+
28
+ try {
29
+ const { tools } = require('@iobroker/js-controller-common');
30
+ const configFile = tools.getConfigFileName();
31
+ const config = JSON.parse(readFileSync(configFile, 'utf8'));
32
+ statesHost = config?.states?.host || '127.0.0.1';
33
+ statesPort = config?.states?.port || 9020;
34
+ } catch {
35
+ // Fallback: try path relative to this file
36
+ try {
37
+ const configPath = path.resolve(__dirname, '../../../../iobroker-data/iobroker.json');
38
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
39
+ statesHost = config?.states?.host || '127.0.0.1';
40
+ statesPort = config?.states?.port || 9020;
41
+ } catch {
42
+ // Use defaults: 127.0.0.1:9020
43
+ }
44
+ }
45
+
46
+ const IORedis = require('ioredis');
47
+ const client = new IORedis({
48
+ host: statesHost,
49
+ port: statesPort,
50
+ lazyConnect: false,
51
+ connectTimeout: 3000,
52
+ enableReadyCheck: false,
53
+ maxRetriesPerRequest: 1,
54
+ });
55
+
56
+ await new Promise((resolve) => {
57
+ client.once('ready', resolve);
58
+ client.once('error', resolve);
59
+ setTimeout(resolve, 3000);
60
+ });
61
+
62
+ const ts = Date.now();
63
+ const stateVal = JSON.stringify({
64
+ val: false,
65
+ ack: true,
66
+ ts,
67
+ lc: ts,
68
+ from: 'system.adapter.mywebui.0',
69
+ });
70
+
71
+ await client.set('io.system.adapter.mywebui.0.alive', stateVal).catch(() => {});
72
+ console.log('[mywebui pre-start] Cleared alive state on', statesHost + ':' + statesPort);
73
+
74
+ await client.quit().catch(() => {});
75
+ } catch (e) {
76
+ console.warn('[mywebui pre-start] Could not clear alive state:', e.message);
77
+ }
78
+ }
79
+
80
+ await clearAliveState();
81
+ await import('./main.js');
package/io-package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "mywebui",
4
- "version": "1.37.41",
4
+ "version": "1.37.42",
5
5
  "titleLang": {
6
6
  "en": "mywebui",
7
7
  "de": "mywebui",
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "iobroker.mywebui",
3
- "version": "1.37.41",
3
+ "version": "1.37.42",
4
4
  "description": "ioBroker mywebui - Custom edited mywebui by gokturk413",
5
5
  "type": "module",
6
- "main": "dist/backend/main.js",
6
+ "main": "dist/backend/pre-start.mjs",
7
7
  "scripts": {
8
8
  "sync": "node sync-package.js",
9
9
  "esbuild": "node esbuild.js",