homebridge-melcloud-control 4.0.0-beta.426 → 4.0.0-beta.428

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/functions.js +54 -18
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.426",
4
+ "version": "4.0.0-beta.428",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/functions.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from 'fs';
2
+ import { exec } from 'child_process';
2
3
  import { promises as fsPromises } from 'fs';
3
4
  import { promisify } from 'util';
4
5
  const execAsync = promisify(exec);
@@ -48,40 +49,75 @@ class Functions {
48
49
  }
49
50
 
50
51
  async ensureChromiumInstalled(logInfo, logWarn, logError) {
52
+ let chromiumPath = '/usr/bin/chromium-browser';
53
+
51
54
  try {
55
+ // --- Detect architecture ---
52
56
  const { stdout: arch } = await execAsync('uname -m');
53
- const { stdout: osRelease } = await execAsync('cat /etc/os-release');
54
57
  logInfo(`Detected architecture: ${arch.trim()}`);
55
- logInfo(`Detected OS: ${osRelease.split('\n')[0]}`);
56
58
 
57
- let chromiumPath = '/usr/bin/chromium-browser';
58
- const { stdout: chromiumCheck } = await execAsync('which chromium || which chromium-browser || true');
59
+ // --- Detect OS safely ---
60
+ let osName = 'unknown';
61
+ try {
62
+ const { stdout: osRelease } = await execAsync('cat /etc/os-release');
63
+ osName = osRelease.split('\n')[0] || 'unknown';
64
+ } catch {
65
+ logWarn('/etc/os-release not found, skipping OS detection.');
66
+ }
67
+ logInfo(`Detected OS: ${osName}`);
59
68
 
69
+ // --- Check existing Chromium ---
70
+ const { stdout: chromiumCheck } = await execAsync('which chromium || which chromium-browser || true');
60
71
  if (chromiumCheck.trim()) {
61
72
  chromiumPath = chromiumCheck.trim();
62
73
  logInfo(`Found system Chromium: ${chromiumPath}`);
63
- } else {
64
- logWarn('Chromium not found. Installing...');
65
- try {
66
- await execAsync('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg');
67
- logInfo('Chromium installed successfully.');
68
- } catch (aptErr) {
69
- logWarn('apt-get failed, trying apk/yum fallback...');
70
- try {
71
- await execAsync('sudo apk add chromium ffmpeg');
72
- } catch {
73
- await execAsync('sudo yum install -y chromium chromium-codecs-ffmpeg');
74
- }
75
- }
74
+ return chromiumPath;
76
75
  }
77
76
 
77
+ logWarn('Chromium not found. Attempting installation...');
78
+
79
+ // --- Try apt-get first ---
80
+ try {
81
+ await execAsync('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg');
82
+ chromiumPath = '/usr/bin/chromium-browser';
83
+ logInfo('Chromium installed successfully via apt-get.');
84
+ return chromiumPath;
85
+ } catch (aptErr) {
86
+ logWarn('apt-get install failed. Trying apk (Alpine) or yum (RHEL/CentOS)...');
87
+ }
88
+
89
+ // --- Try Alpine APK ---
90
+ try {
91
+ await execAsync('sudo apk add --no-cache chromium ffmpeg');
92
+ chromiumPath = '/usr/bin/chromium-browser'; // standardowa ścieżka w Alpine
93
+ logInfo('Chromium installed successfully via apk.');
94
+ return chromiumPath;
95
+ } catch (apkErr) {
96
+ logWarn('apk install failed. Trying yum (RHEL/CentOS)...');
97
+ }
98
+
99
+ // --- Try YUM ---
100
+ try {
101
+ await execAsync('sudo yum install -y chromium chromium-codecs-ffmpeg');
102
+ chromiumPath = '/usr/bin/chromium-browser';
103
+ logInfo('Chromium installed successfully via yum.');
104
+ return chromiumPath;
105
+ } catch (yumErr) {
106
+ logWarn('yum install failed. Falling back to Puppeteer bundled Chromium.');
107
+ }
108
+
109
+ // --- Fallback: Puppeteer Chromium ---
110
+ chromiumPath = puppeteer.executablePath();
111
+ logWarn(`Using bundled Puppeteer Chromium at ${chromiumPath}`);
78
112
  return chromiumPath;
113
+
79
114
  } catch (err) {
80
- logError(`Chromium detection error: ${err.message}`);
115
+ logError(`Chromium detection/install error: ${err.message}`);
81
116
  throw err;
82
117
  }
83
118
  }
84
119
 
120
+
85
121
  async isRunningInDocker() {
86
122
  try {
87
123
  if (fs.existsSync('/.dockerenv')) return true;