@ohos-ports/slides-grab 1.5.0-beta.2 → 1.5.0-beta.3
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.
- package/package.json +2 -2
- package/src/ohos-browser-bridge.cjs +54 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/slides-grab",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.3",
|
|
4
4
|
"description": "Agent-first presentation framework — plan, design, and visually edit HTML slides with Claude Code or Codex, then export to PDF or experimental/unstable PPTX/Figma formats. HarmonyOS adaptation: Playwright connects to system Haitai browser (Chromium M132) via CDP bridge.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "vkehfdl1",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"optionalDependencies": {
|
|
84
84
|
"@ohos-ports/img-sharp-openharmony-arm64": "0.34.5-beta.0",
|
|
85
|
-
"@ohos-ports/img-sharp-libvips-openharmony-arm64": "1.2.4-beta.
|
|
85
|
+
"@ohos-ports/img-sharp-libvips-openharmony-arm64": "1.2.4-beta.1"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/node": "^25.5.0",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* 4. chromium.connectOverCDP(wsEndpoint)
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const { execFileSync } = require('child_process');
|
|
15
14
|
const http = require('http');
|
|
16
15
|
|
|
17
16
|
// ─── Browser registry ────────────────────────────────────────────────────
|
|
@@ -72,6 +71,8 @@ const DISABLED_FEATURES = [
|
|
|
72
71
|
const OHOS_AA_PATH = '/system/bin/cli_tool/executable/ohos-aa';
|
|
73
72
|
const OHOS_BM_PATH = '/system/bin/cli_tool/executable/ohos-bm';
|
|
74
73
|
|
|
74
|
+
const { execFileSync, execSync } = require('child_process');
|
|
75
|
+
|
|
75
76
|
function execOhosAa(args, timeout = 30000) {
|
|
76
77
|
return execFileSync(OHOS_AA_PATH, args, { timeout, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
77
78
|
}
|
|
@@ -80,6 +81,55 @@ function execOhosBm(args, timeout = 30000) {
|
|
|
80
81
|
return execFileSync(OHOS_BM_PATH, args, { timeout, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
// ─── Process management ─────────────────────────────────────────────────
|
|
85
|
+
/**
|
|
86
|
+
* Kill a browser process by bundle name.
|
|
87
|
+
* ohos-aa force-stop can silently fail (returns status=failed without error).
|
|
88
|
+
* This function tries force-stop first, then falls back to killall.
|
|
89
|
+
*/
|
|
90
|
+
function killBrowserProcess(pkg) {
|
|
91
|
+
// 1. Try ohos-aa force-stop
|
|
92
|
+
try {
|
|
93
|
+
const result = execOhosAa(['force-stop', '--bundlename', pkg]);
|
|
94
|
+
let parsed;
|
|
95
|
+
try { parsed = JSON.parse(result); } catch { parsed = null; }
|
|
96
|
+
if (parsed && parsed.status === 'success') return; // force-stop worked
|
|
97
|
+
} catch {}
|
|
98
|
+
|
|
99
|
+
// 2. Check if process is still alive
|
|
100
|
+
let stillAlive = false;
|
|
101
|
+
try {
|
|
102
|
+
const out = execSync(`ps -ef 2>/dev/null | grep "${pkg}" | grep -v grep`, {
|
|
103
|
+
encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'ignore']
|
|
104
|
+
});
|
|
105
|
+
stillAlive = out.trim().length > 0;
|
|
106
|
+
} catch {
|
|
107
|
+
// grep returns non-zero when no match — process is dead
|
|
108
|
+
stillAlive = false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!stillAlive) return; // process already gone
|
|
112
|
+
|
|
113
|
+
// 3. Fallback: killall
|
|
114
|
+
try {
|
|
115
|
+
execSync(`killall ${pkg} 2>/dev/null`, { encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'ignore'] });
|
|
116
|
+
} catch {}
|
|
117
|
+
|
|
118
|
+
// 4. Wait for process to die (poll up to 5s)
|
|
119
|
+
const deadline = Date.now() + 5000;
|
|
120
|
+
while (Date.now() < deadline) {
|
|
121
|
+
try {
|
|
122
|
+
const out = execSync(`ps -ef 2>/dev/null | grep "${pkg}" | grep -v grep`, {
|
|
123
|
+
encoding: 'utf-8', timeout: 3000, stdio: ['pipe', 'pipe', 'ignore']
|
|
124
|
+
});
|
|
125
|
+
if (out.trim().length === 0) return; // dead
|
|
126
|
+
} catch {
|
|
127
|
+
return; // grep no match = dead
|
|
128
|
+
}
|
|
129
|
+
execSync('sleep 0.5', { timeout: 2000 });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
83
133
|
// ─── CDP ────────────────────────────────────────────────────────────────
|
|
84
134
|
function buildCmdArgs(port, options = {}) {
|
|
85
135
|
const args = [
|
|
@@ -151,8 +201,8 @@ async function launchBrowserViaCdp(options = {}) {
|
|
|
151
201
|
}
|
|
152
202
|
|
|
153
203
|
// 2. Stop stale browser process
|
|
154
|
-
|
|
155
|
-
await new Promise(r => setTimeout(r,
|
|
204
|
+
killBrowserProcess(pkg);
|
|
205
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
156
206
|
|
|
157
207
|
// 3. Launch browser with CDP port
|
|
158
208
|
const cmdArgs = buildCmdArgs(port, options);
|
|
@@ -174,7 +224,7 @@ async function launchBrowserViaCdp(options = {}) {
|
|
|
174
224
|
|
|
175
225
|
// Real cleanup on process exit
|
|
176
226
|
process.on('exit', () => {
|
|
177
|
-
try {
|
|
227
|
+
try { killBrowserProcess(pkg); } catch {}
|
|
178
228
|
});
|
|
179
229
|
|
|
180
230
|
return browser;
|