@aivin-labs/cli 1.0.11 → 1.0.21
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/README.md +325 -288
- package/bin/cli.mjs +163 -17
- package/bin/lib/localPreview.mjs +437 -0
- package/bin/lib/openFile.mjs +235 -0
- package/bin/lib/previewCache.mjs +71 -0
- package/bin/lib/remote/atomicFile.mjs +32 -0
- package/bin/lib/remote/autoStart.mjs +2 -1
- package/bin/lib/remote/autoUpdate.mjs +12 -0
- package/bin/lib/remote/browserTunnel.mjs +47 -8
- package/bin/lib/remote/callLedger.mjs +94 -14
- package/bin/lib/remote/cdpPolicy.mjs +14 -2
- package/bin/lib/remote/client.mjs +1024 -808
- package/bin/lib/remote/cloudFiles.mjs +53 -0
- package/bin/lib/remote/codingAgents.mjs +2 -2
- package/bin/lib/remote/constants.mjs +261 -234
- package/bin/lib/remote/credentials.mjs +81 -4
- package/bin/lib/remote/daemonLock.mjs +57 -17
- package/bin/lib/remote/dailyBrowser.mjs +8 -2
- package/bin/lib/remote/desktop/castInput.mjs +98 -0
- package/bin/lib/remote/desktop/desktopCast.mjs +334 -0
- package/bin/lib/remote/desktop/desktopCastCaptureSource.mjs +598 -0
- package/bin/lib/remote/desktop/desktopCastSource.mjs +798 -0
- package/bin/lib/remote/desktop/desktopWebRtc.mjs +242 -0
- package/bin/lib/remote/desktop/fileAssociation.mjs +108 -0
- package/bin/lib/remote/desktop/index.mjs +58 -7
- package/bin/lib/remote/desktop/linux.mjs +1 -1
- package/bin/lib/remote/desktop/linuxTraySource.mjs +427 -427
- package/bin/lib/remote/desktop/mac.mjs +2 -2
- package/bin/lib/remote/desktop/macTraySource.mjs +293 -292
- package/bin/lib/remote/desktop/strings.mjs +28 -2
- package/bin/lib/remote/desktop/traySource.mjs +905 -527
- package/bin/lib/remote/desktop/webrtcRuntime.mjs +137 -0
- package/bin/lib/remote/desktop/webrtcWorker.mjs +181 -0
- package/bin/lib/remote/deviceProfile.mjs +1 -0
- package/bin/lib/remote/docText.mjs +85 -0
- package/bin/lib/remote/fileIndexer.mjs +773 -399
- package/bin/lib/remote/folderRules.mjs +143 -0
- package/bin/lib/remote/gitSafe.mjs +31 -0
- package/bin/lib/remote/gui/index.mjs +170 -19
- package/bin/lib/remote/gui/officeHostSource.mjs +635 -393
- package/bin/lib/remote/gui/windowsHost.mjs +12 -3
- package/bin/lib/remote/gui/windowsHostSource.mjs +461 -87
- package/bin/lib/remote/httpTransfer.mjs +64 -3
- package/bin/lib/remote/idempotency.mjs +49 -20
- package/bin/lib/remote/localPolicy.mjs +81 -9
- package/bin/lib/remote/mascot/ask.mjs +207 -42
- package/bin/lib/remote/mascot/askBlocksSource.mjs +286 -0
- package/bin/lib/remote/mascot/askHostSource.mjs +658 -512
- package/bin/lib/remote/mascot/blocks.mjs +201 -0
- package/bin/lib/remote/mascot/bot.mjs +54 -5
- package/bin/lib/remote/mascot/chartLayout.mjs +382 -0
- package/bin/lib/remote/mascot/diagramRender.mjs +154 -0
- package/bin/lib/remote/mascot/emojiSource.mjs +273 -0
- package/bin/lib/remote/mascot/fileChips.mjs +62 -0
- package/bin/lib/remote/mascot/hostSource.mjs +331 -52
- package/bin/lib/remote/mascot/hotkey.mjs +31 -7
- package/bin/lib/remote/mascot/images.mjs +111 -0
- package/bin/lib/remote/mascot/index.mjs +663 -493
- package/bin/lib/remote/mascot/lucideIcons.mjs +32 -0
- package/bin/lib/remote/mascot/mermaidBundle.mjs +28 -0
- package/bin/lib/remote/mascot/mood.mjs +57 -0
- package/bin/lib/remote/mascot/rigSource.mjs +648 -609
- package/bin/lib/remote/mascot/safeUrl.mjs +29 -0
- package/bin/lib/remote/mascot/strings.mjs +456 -375
- package/bin/lib/remote/mascot/ui.mjs +27 -7
- package/bin/lib/remote/multiUser.mjs +7 -2
- package/bin/lib/remote/notify.mjs +4 -1
- package/bin/lib/remote/office/index.mjs +12 -6
- package/bin/lib/remote/osSearch.mjs +107 -0
- package/bin/lib/remote/processes.mjs +5 -2
- package/bin/lib/remote/sandbox.mjs +26 -0
- package/bin/lib/remote/secretPaths.mjs +21 -0
- package/bin/lib/remote/sqliteDb.mjs +51 -0
- package/bin/lib/remote/tokenRotation.mjs +28 -0
- package/bin/lib/remote/toolHandlers.mjs +852 -741
- package/bin/lib/remote/watchBatcher.mjs +56 -0
- package/bin/lib/remoteControl.mjs +26 -26
- package/bin/lib/selfUpdate.mjs +12 -2
- package/bin/lib/update/binarySwap.mjs +15 -1
- package/bin/lib/update/state.mjs +10 -0
- package/docs/AIVIN_MASCOT.md +14 -0
- package/docs/CLI.md +1545 -1484
- package/docs/media/aivin-ecosystem.jpg +0 -0
- package/docs/media/aivin-mascot-live.gif +0 -0
- package/docs/media/aivin-mascot-live.png +0 -0
- package/docs/media/aivin-remote-architecture.svg +102 -0
- package/package.json +75 -71
- package/docs/media/aivin-mascot-states.mp4 +0 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tính hình của biểu đồ cho ô hỏi linh vật (03/11/2026): khối `chart` → danh sách hình (chữ nhật, nét, chấm, chữ) theo toạ độ; cửa sổ chỉ vẽ lại đúng danh sách đó
|
|
3
|
+
* (askChartSource.mjs). Tính ở daemon để PowerShell không phải chạy vòng lặp toán, và test được không cần cửa sổ. Đủ 12 kiểu như `ChartComponent.txt`.
|
|
4
|
+
* Hình: `{ k: 'r', x, y, w, h, f, rx? }`, `{ k: 'p', d, s?, f?, sw?, dash? }`, `{ k: 'c', x, y, r, f, s? }`, `{ k: 't', x, y, w, t, a?, c?, z?, b? }`.
|
|
5
|
+
*/
|
|
6
|
+
const WIDTH = 288;
|
|
7
|
+
const CHART_HEIGHT = 150;
|
|
8
|
+
const ROUND_HEIGHT = 150;
|
|
9
|
+
const RADAR_HEIGHT = 180;
|
|
10
|
+
/** Nền cột nhạt, nét đường đậm cùng tông: giống bảng màu biểu đồ trên web. */
|
|
11
|
+
const FILLS = ['#93C5FD', '#6EE7B7', '#FCD34D', '#FCA5A5', '#C4B5FD', '#67E8F9'];
|
|
12
|
+
const INKS = ['#2563EB', '#059669', '#D97706', '#DC2626', '#7C3AED', '#0891B2'];
|
|
13
|
+
const POSITIVE = '#34D399';
|
|
14
|
+
const NEGATIVE = '#F87171';
|
|
15
|
+
const POSITIVE_INK = '#059669';
|
|
16
|
+
const NEGATIVE_INK = '#DC2626';
|
|
17
|
+
const GRID = '#EEF0F4';
|
|
18
|
+
const TICK_INK = '#86909C';
|
|
19
|
+
const TEXT_INK = '#4E5969';
|
|
20
|
+
const TICK_SIZE = 10.5;
|
|
21
|
+
const CHAR_PX = 5.6;
|
|
22
|
+
/** Chữ số rộng hơn chữ thường một chút: nhãn trục mà tính thiếu thì bị cắt mất số. */
|
|
23
|
+
const TICK_CHAR_PX = 6.4;
|
|
24
|
+
const LABEL_GAP = 4;
|
|
25
|
+
|
|
26
|
+
const BAR_KINDS = new Set(['bar', 'stackedBar']);
|
|
27
|
+
const HORIZONTAL_KINDS = new Set(['horizontalBar', 'stackedHorizontalBar']);
|
|
28
|
+
const STACKED_KINDS = new Set(['stackedBar', 'stackedHorizontalBar']);
|
|
29
|
+
|
|
30
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|
|
31
|
+
const fix = (v) => Math.round(v * 100) / 100;
|
|
32
|
+
const point = (x, y) => `${fix(x)} ${fix(y)}`;
|
|
33
|
+
|
|
34
|
+
function formatter(lang) {
|
|
35
|
+
try {
|
|
36
|
+
return new Intl.NumberFormat(lang || 'en', { notation: 'compact', maximumFractionDigits: 1 });
|
|
37
|
+
} catch {
|
|
38
|
+
return new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Mốc trục tròn số bao trọn [min, max]. */
|
|
43
|
+
export function niceTicks(min, max, count = 4) {
|
|
44
|
+
if (min === max) { max = min === 0 ? 1 : min + Math.abs(min) / 2; min = min > 0 ? 0 : min - (min < 0 ? Math.abs(min) / 2 : 0); }
|
|
45
|
+
const raw = (max - min) / count;
|
|
46
|
+
const mag = 10 ** Math.floor(Math.log10(raw));
|
|
47
|
+
const norm = raw / mag;
|
|
48
|
+
const step = (norm <= 1 ? 1 : norm <= 2 ? 2 : norm <= 5 ? 5 : 10) * mag;
|
|
49
|
+
const low = Math.floor(min / step) * step;
|
|
50
|
+
const high = Math.ceil(max / step) * step;
|
|
51
|
+
const ticks = [];
|
|
52
|
+
for (let v = low; v <= high + step / 2; v += step) ticks.push(fix(v * 1e6) / 1e6);
|
|
53
|
+
return { min: low, max: high, ticks };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const text = (x, y, w, t, extra = {}) => ({ k: 't', x: fix(x), y: fix(y), w: fix(w), t, ...extra });
|
|
57
|
+
const hline = (x1, x2, y, s = GRID) => ({ k: 'p', d: `M${point(x1, y)}L${point(x2, y)}`, s, sw: 1 });
|
|
58
|
+
const vline = (x, y1, y2, s = GRID) => ({ k: 'p', d: `M${point(x, y1)}L${point(x, y2)}`, s, sw: 1 });
|
|
59
|
+
|
|
60
|
+
const seriesFill = (s, i) => s.color || (s.semantic === 'positive' ? POSITIVE : s.semantic === 'negative' ? NEGATIVE : FILLS[i % FILLS.length]);
|
|
61
|
+
const seriesInk = (s, i) => s.color || (s.semantic === 'positive' ? POSITIVE_INK : s.semantic === 'negative' ? NEGATIVE_INK : INKS[i % INKS.length]);
|
|
62
|
+
|
|
63
|
+
/** Một dãy duy nhất có cả số dương lẫn âm: tăng xanh, giảm đỏ, như web. */
|
|
64
|
+
const mixedSigns = (series) => series.length === 1 && series[0].data.some((v) => num(v) > 0) && series[0].data.some((v) => num(v) < 0);
|
|
65
|
+
|
|
66
|
+
function barColor(series, seriesIndex, value, pointIndex, all) {
|
|
67
|
+
const s = series;
|
|
68
|
+
if (mixedSigns(all) && !s.color) return value < 0 ? NEGATIVE : POSITIVE;
|
|
69
|
+
// Nhấn vài cột: cột thường nhạt đi, cột nhấn dùng màu đậm.
|
|
70
|
+
if (s.highlight?.length) return s.highlight.includes(pointIndex) ? seriesInk(s, seriesIndex) : seriesFill(s, seriesIndex);
|
|
71
|
+
return seriesFill(s, seriesIndex);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function stackedRange(series, n) {
|
|
75
|
+
let low = 0;
|
|
76
|
+
let high = 0;
|
|
77
|
+
for (let p = 0; p < n; p++) {
|
|
78
|
+
let up = 0;
|
|
79
|
+
let down = 0;
|
|
80
|
+
for (const s of series) {
|
|
81
|
+
const v = num(s.data[p]) ?? 0;
|
|
82
|
+
if (v >= 0) up += v; else down += v;
|
|
83
|
+
}
|
|
84
|
+
high = Math.max(high, up);
|
|
85
|
+
low = Math.min(low, down);
|
|
86
|
+
}
|
|
87
|
+
return [low, high];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function plainRange(series, includeZero) {
|
|
91
|
+
const values = series.flatMap((s) => s.data.map(num)).filter((v) => v !== null);
|
|
92
|
+
if (!values.length) return null;
|
|
93
|
+
return [includeZero ? Math.min(0, ...values) : Math.min(...values), includeZero ? Math.max(0, ...values) : Math.max(...values)];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Nhãn danh mục dọc trục ngang: nhãn dày thì cách quãng để không đè nhau. */
|
|
97
|
+
function categoryLabels(shapes, labels, n, left, slot, y) {
|
|
98
|
+
const every = Math.max(1, Math.ceil((CHAR_PX * 6) / slot));
|
|
99
|
+
for (let i = 0; i < n; i += every) {
|
|
100
|
+
if (!labels[i]) continue;
|
|
101
|
+
const w = slot * every - 2;
|
|
102
|
+
shapes.push(text(left + slot * i + slot / 2 - w / 2, y, w, labels[i], { a: 'c', c: TICK_INK, z: TICK_SIZE }));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function pointCount(chart) {
|
|
107
|
+
return Math.max(chart.labels.length, ...chart.series.map((s) => s.data.length));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Cột dọc gom nhóm / chồng + đường, gồm cả `combo` (đường theo trục phải). */
|
|
111
|
+
function verticalChart(chart, lang) {
|
|
112
|
+
const { series, labels, kind } = chart;
|
|
113
|
+
const n = pointCount(chart);
|
|
114
|
+
const fmt = formatter(lang);
|
|
115
|
+
const isLine = (s) => kind === 'line' || (kind === 'combo' && s.type === 'line');
|
|
116
|
+
const leftSeries = series.filter((s) => s.axis !== 'right');
|
|
117
|
+
const rightSeries = series.filter((s) => s.axis === 'right');
|
|
118
|
+
const stacked = STACKED_KINDS.has(kind);
|
|
119
|
+
const includeZero = kind !== 'line';
|
|
120
|
+
const leftRange = stacked ? stackedRange(leftSeries, n) : plainRange(leftSeries, includeZero);
|
|
121
|
+
if (!leftRange) return null;
|
|
122
|
+
const left = niceTicks(leftRange[0], leftRange[1]);
|
|
123
|
+
const rightRange = rightSeries.length ? plainRange(rightSeries, false) : null;
|
|
124
|
+
const right = rightRange ? niceTicks(rightRange[0], rightRange[1]) : null;
|
|
125
|
+
const tickWidth = (ticks) => Math.max(...ticks.map((v) => fmt.format(v).length)) * TICK_CHAR_PX + LABEL_GAP;
|
|
126
|
+
const x0 = tickWidth(left.ticks);
|
|
127
|
+
const x1 = WIDTH - (right ? tickWidth(right.ticks) + LABEL_GAP : 4);
|
|
128
|
+
const y0 = 6;
|
|
129
|
+
const y1 = CHART_HEIGHT - 20;
|
|
130
|
+
const yOf = (scale, v) => y1 - ((v - scale.min) / (scale.max - scale.min || 1)) * (y1 - y0);
|
|
131
|
+
const shapes = [];
|
|
132
|
+
for (const v of left.ticks) {
|
|
133
|
+
const y = yOf(left, v);
|
|
134
|
+
shapes.push(hline(x0, x1, y, v === 0 ? '#C9CDD4' : GRID));
|
|
135
|
+
shapes.push(text(0, y - 7, x0 - LABEL_GAP, fmt.format(v), { a: 'r', c: TICK_INK, z: TICK_SIZE }));
|
|
136
|
+
}
|
|
137
|
+
if (right) {
|
|
138
|
+
for (const v of right.ticks) shapes.push(text(x1 + LABEL_GAP, yOf(right, v) - 7, WIDTH - x1 - LABEL_GAP, fmt.format(v), { a: 'l', c: TICK_INK, z: TICK_SIZE }));
|
|
139
|
+
}
|
|
140
|
+
const slot = (x1 - x0) / Math.max(n, 1);
|
|
141
|
+
const barSeries = series.filter((s) => !isLine(s));
|
|
142
|
+
const groupWidth = slot * 0.72;
|
|
143
|
+
const barWidth = stacked ? Math.min(groupWidth, 32) : Math.min(groupWidth / Math.max(barSeries.length, 1), 24);
|
|
144
|
+
for (let p = 0; p < n; p++) {
|
|
145
|
+
let up = 0;
|
|
146
|
+
let down = 0;
|
|
147
|
+
let at = 0;
|
|
148
|
+
const groupStart = x0 + slot * p + slot / 2 - (stacked ? barWidth : barWidth * barSeries.length) / 2;
|
|
149
|
+
series.forEach((s, si) => {
|
|
150
|
+
if (isLine(s)) return;
|
|
151
|
+
const v = num(s.data[p]);
|
|
152
|
+
const index = at++;
|
|
153
|
+
if (v === null) return;
|
|
154
|
+
const scale = s.axis === 'right' && right ? right : left;
|
|
155
|
+
let from = 0;
|
|
156
|
+
if (stacked) { from = v >= 0 ? up : down; if (v >= 0) up += v; else down += v; }
|
|
157
|
+
const a = yOf(scale, from);
|
|
158
|
+
const b = yOf(scale, from + v);
|
|
159
|
+
shapes.push({
|
|
160
|
+
k: 'r', x: fix(stacked ? groupStart : groupStart + index * barWidth + 0.5), y: fix(Math.min(a, b)), w: fix(Math.max(1, barWidth - (stacked ? 0 : 1))), h: fix(Math.max(1, Math.abs(a - b))),
|
|
161
|
+
f: barColor(s, si, v, p, series), rx: stacked ? 0 : 2,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
series.forEach((s, si) => {
|
|
166
|
+
if (!isLine(s)) return;
|
|
167
|
+
const scale = s.axis === 'right' && right ? right : left;
|
|
168
|
+
const ink = seriesInk(s, si);
|
|
169
|
+
let d = '';
|
|
170
|
+
let pen = false;
|
|
171
|
+
for (let p = 0; p < n; p++) {
|
|
172
|
+
const v = num(s.data[p]);
|
|
173
|
+
if (v === null) { pen = false; continue; }
|
|
174
|
+
d += `${pen ? 'L' : 'M'}${point(x0 + slot * p + slot / 2, yOf(scale, v))}`;
|
|
175
|
+
pen = true;
|
|
176
|
+
}
|
|
177
|
+
if (d) shapes.push({ k: 'p', d, s: ink, sw: 2 });
|
|
178
|
+
if (n <= 16) {
|
|
179
|
+
for (let p = 0; p < n; p++) {
|
|
180
|
+
const v = num(s.data[p]);
|
|
181
|
+
if (v !== null) shapes.push({ k: 'c', x: fix(x0 + slot * p + slot / 2), y: fix(yOf(scale, v)), r: 2.5, f: '#FFFFFF', s: ink });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
categoryLabels(shapes, labels, n, x0, slot, y1 + 4);
|
|
186
|
+
return { w: WIDTH, h: CHART_HEIGHT, shapes };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function horizontalChart(chart, lang) {
|
|
190
|
+
const { series, labels, kind } = chart;
|
|
191
|
+
const n = pointCount(chart);
|
|
192
|
+
const fmt = formatter(lang);
|
|
193
|
+
const stacked = STACKED_KINDS.has(kind);
|
|
194
|
+
const range = stacked ? stackedRange(series, n) : plainRange(series, true);
|
|
195
|
+
if (!range) return null;
|
|
196
|
+
const scale = niceTicks(range[0], range[1], 3);
|
|
197
|
+
const labelWidth = Math.min(96, Math.max(24, Math.max(0, ...labels.map((l) => (l || '').length)) * CHAR_PX + LABEL_GAP));
|
|
198
|
+
const x0 = labelWidth + LABEL_GAP;
|
|
199
|
+
const x1 = WIDTH - 8;
|
|
200
|
+
const groupHeight = stacked ? 16 : Math.max(10, Math.min(8 * series.length + 4, 24));
|
|
201
|
+
const rowHeight = groupHeight + 6;
|
|
202
|
+
const h = n * rowHeight + 20;
|
|
203
|
+
const xOf = (v) => x0 + ((v - scale.min) / (scale.max - scale.min || 1)) * (x1 - x0);
|
|
204
|
+
const shapes = [];
|
|
205
|
+
for (const v of scale.ticks) {
|
|
206
|
+
const x = xOf(v);
|
|
207
|
+
shapes.push(vline(x, 2, h - 18, v === 0 ? '#C9CDD4' : GRID));
|
|
208
|
+
shapes.push(text(x - 24, h - 15, 48, fmt.format(v), { a: 'c', c: TICK_INK, z: TICK_SIZE }));
|
|
209
|
+
}
|
|
210
|
+
for (let p = 0; p < n; p++) {
|
|
211
|
+
const top = 3 + p * rowHeight;
|
|
212
|
+
if (labels[p]) shapes.push(text(0, top + groupHeight / 2 - 7, labelWidth, labels[p], { a: 'r', c: TEXT_INK, z: TICK_SIZE }));
|
|
213
|
+
let up = 0;
|
|
214
|
+
let down = 0;
|
|
215
|
+
series.forEach((s, si) => {
|
|
216
|
+
const v = num(s.data[p]);
|
|
217
|
+
if (v === null) return;
|
|
218
|
+
let from = 0;
|
|
219
|
+
if (stacked) { from = v >= 0 ? up : down; if (v >= 0) up += v; else down += v; }
|
|
220
|
+
const a = xOf(from);
|
|
221
|
+
const b = xOf(from + v);
|
|
222
|
+
const barHeight = stacked ? groupHeight : groupHeight / series.length;
|
|
223
|
+
shapes.push({
|
|
224
|
+
k: 'r', x: fix(Math.min(a, b)), y: fix(stacked ? top : top + si * barHeight), w: fix(Math.max(1, Math.abs(a - b))), h: fix(Math.max(1, barHeight - (stacked ? 0 : 1))),
|
|
225
|
+
f: barColor(s, si, v, p, series), rx: stacked ? 0 : 2,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return { w: WIDTH, h, shapes };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function sector(cx, cy, r, inner, start, end) {
|
|
233
|
+
const sweep = end - start;
|
|
234
|
+
// Một lát trọn vòng: vẽ hai nửa, cung trùng điểm đầu cuối thì không ra hình.
|
|
235
|
+
if (sweep >= Math.PI * 2 - 1e-4) return `${sector(cx, cy, r, inner, start, start + Math.PI)}${sector(cx, cy, r, inner, start + Math.PI, start + Math.PI * 2)}`;
|
|
236
|
+
const at = (radius, angle) => point(cx + radius * Math.cos(angle), cy + radius * Math.sin(angle));
|
|
237
|
+
const large = sweep > Math.PI ? 1 : 0;
|
|
238
|
+
if (!inner) return `M${point(cx, cy)}L${at(r, start)}A${fix(r)} ${fix(r)} 0 ${large} 1 ${at(r, end)}Z`;
|
|
239
|
+
return `M${at(r, start)}A${fix(r)} ${fix(r)} 0 ${large} 1 ${at(r, end)}L${at(inner, end)}A${fix(inner)} ${fix(inner)} 0 ${large} 0 ${at(inner, start)}Z`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function pieChart(chart) {
|
|
243
|
+
const values = chart.series[0].data.map((v) => Math.max(0, num(v) ?? 0));
|
|
244
|
+
const total = values.reduce((a, b) => a + b, 0);
|
|
245
|
+
if (!total) return null;
|
|
246
|
+
const cy = ROUND_HEIGHT / 2;
|
|
247
|
+
const cx = WIDTH / 2;
|
|
248
|
+
const r = cy - 4;
|
|
249
|
+
const inner = chart.kind === 'doughnut' ? r * 0.58 : 0;
|
|
250
|
+
const shapes = [];
|
|
251
|
+
const legend = [];
|
|
252
|
+
let angle = -Math.PI / 2;
|
|
253
|
+
values.forEach((v, i) => {
|
|
254
|
+
const color = chart.series[0].highlight?.includes(i) ? INKS[i % INKS.length] : FILLS[i % FILLS.length];
|
|
255
|
+
const pct = Math.round((v / total) * 100);
|
|
256
|
+
if (chart.labels[i]) legend.push({ label: `${chart.labels[i]} ${pct}%`, color });
|
|
257
|
+
if (!v) return;
|
|
258
|
+
const end = angle + (v / total) * Math.PI * 2;
|
|
259
|
+
shapes.push({ k: 'p', d: sector(cx, cy, r, inner, angle, end), f: color, s: '#FFFFFF', sw: 1.5 });
|
|
260
|
+
if (pct >= 8) {
|
|
261
|
+
const mid = (angle + end) / 2;
|
|
262
|
+
const rr = inner ? (r + inner) / 2 : r * 0.62;
|
|
263
|
+
shapes.push(text(cx + rr * Math.cos(mid) - 18, cy + rr * Math.sin(mid) - 7, 36, `${pct}%`, { a: 'c', c: TEXT_INK, z: TICK_SIZE, b: true }));
|
|
264
|
+
}
|
|
265
|
+
angle = end;
|
|
266
|
+
});
|
|
267
|
+
return { w: WIDTH, h: ROUND_HEIGHT, shapes, legend };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function polarChart(chart) {
|
|
271
|
+
const values = chart.series[0].data.map((v) => Math.max(0, num(v) ?? 0));
|
|
272
|
+
const max = Math.max(...values);
|
|
273
|
+
if (!max) return null;
|
|
274
|
+
const cy = ROUND_HEIGHT / 2;
|
|
275
|
+
const cx = WIDTH / 2;
|
|
276
|
+
const r = cy - 4;
|
|
277
|
+
const shapes = [];
|
|
278
|
+
const legend = [];
|
|
279
|
+
for (const k of [1, 0.66, 0.33]) shapes.push({ k: 'c', x: cx, y: cy, r: fix(r * k), f: null, s: GRID });
|
|
280
|
+
const slice = (Math.PI * 2) / values.length;
|
|
281
|
+
values.forEach((v, i) => {
|
|
282
|
+
const start = -Math.PI / 2 + i * slice;
|
|
283
|
+
const color = FILLS[i % FILLS.length];
|
|
284
|
+
if (chart.labels[i]) legend.push({ label: chart.labels[i], color });
|
|
285
|
+
if (v) shapes.push({ k: 'p', d: sector(cx, cy, r * (v / max), 0, start, start + slice), f: `#CC${color.slice(1)}`, s: '#FFFFFF', sw: 1 });
|
|
286
|
+
});
|
|
287
|
+
return { w: WIDTH, h: ROUND_HEIGHT, shapes, legend };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function radarChart(chart) {
|
|
291
|
+
const n = pointCount(chart);
|
|
292
|
+
const range = plainRange(chart.series, true);
|
|
293
|
+
if (!range || n < 3) return null;
|
|
294
|
+
const scale = niceTicks(0, Math.max(range[1], 1), 4);
|
|
295
|
+
const cx = WIDTH / 2;
|
|
296
|
+
const cy = RADAR_HEIGHT / 2;
|
|
297
|
+
const r = cy - 20;
|
|
298
|
+
const at = (i, k) => {
|
|
299
|
+
const a = -Math.PI / 2 + (i / n) * Math.PI * 2;
|
|
300
|
+
return [cx + r * k * Math.cos(a), cy + r * k * Math.sin(a)];
|
|
301
|
+
};
|
|
302
|
+
const shapes = [];
|
|
303
|
+
for (const v of scale.ticks.slice(1)) {
|
|
304
|
+
const k = v / scale.max;
|
|
305
|
+
shapes.push({ k: 'p', d: `${Array.from({ length: n }, (_, i) => `${i ? 'L' : 'M'}${point(...at(i, k))}`).join('')}Z`, s: GRID, sw: 1 });
|
|
306
|
+
}
|
|
307
|
+
for (let i = 0; i < n; i++) {
|
|
308
|
+
const [x, y] = at(i, 1);
|
|
309
|
+
shapes.push({ k: 'p', d: `M${point(cx, cy)}L${point(x, y)}`, s: GRID, sw: 1 });
|
|
310
|
+
if (chart.labels[i]) {
|
|
311
|
+
const [lx, ly] = at(i, 1.1);
|
|
312
|
+
const onLeft = lx < cx - 4;
|
|
313
|
+
const onRight = lx > cx + 4;
|
|
314
|
+
const w = 76;
|
|
315
|
+
shapes.push(text(onLeft ? lx - w : onRight ? lx : lx - w / 2, ly - 7, w, chart.labels[i], { a: onLeft ? 'r' : onRight ? 'l' : 'c', c: TICK_INK, z: TICK_SIZE }));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
chart.series.forEach((s, si) => {
|
|
319
|
+
const ink = seriesInk(s, si);
|
|
320
|
+
const pts = Array.from({ length: n }, (_, i) => at(i, Math.max(0, num(s.data[i]) ?? 0) / scale.max));
|
|
321
|
+
shapes.push({ k: 'p', d: `${pts.map((p, i) => `${i ? 'L' : 'M'}${point(...p)}`).join('')}Z`, s: ink, sw: 1.6, f: `#33${ink.slice(1)}` });
|
|
322
|
+
for (const p of pts) shapes.push({ k: 'c', x: fix(p[0]), y: fix(p[1]), r: 2, f: ink });
|
|
323
|
+
});
|
|
324
|
+
return { w: WIDTH, h: RADAR_HEIGHT, shapes };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function scatterChart(chart, lang) {
|
|
328
|
+
const pts = chart.series.flatMap((s) => s.data).filter((v) => v && typeof v === 'object');
|
|
329
|
+
if (!pts.length) return null;
|
|
330
|
+
const fmt = formatter(lang);
|
|
331
|
+
const xs = niceTicks(Math.min(...pts.map((p) => p.x)), Math.max(...pts.map((p) => p.x)));
|
|
332
|
+
const ys = niceTicks(Math.min(...pts.map((p) => p.y)), Math.max(...pts.map((p) => p.y)));
|
|
333
|
+
const x0 = Math.max(...ys.ticks.map((v) => fmt.format(v).length)) * TICK_CHAR_PX + LABEL_GAP;
|
|
334
|
+
const x1 = WIDTH - 8;
|
|
335
|
+
const y0 = 6;
|
|
336
|
+
const y1 = CHART_HEIGHT - 20;
|
|
337
|
+
const px = (v) => x0 + ((v - xs.min) / (xs.max - xs.min || 1)) * (x1 - x0);
|
|
338
|
+
const py = (v) => y1 - ((v - ys.min) / (ys.max - ys.min || 1)) * (y1 - y0);
|
|
339
|
+
const shapes = [];
|
|
340
|
+
for (const v of ys.ticks) {
|
|
341
|
+
shapes.push(hline(x0, x1, py(v)));
|
|
342
|
+
shapes.push(text(0, py(v) - 7, x0 - LABEL_GAP, fmt.format(v), { a: 'r', c: TICK_INK, z: TICK_SIZE }));
|
|
343
|
+
}
|
|
344
|
+
for (const v of xs.ticks) {
|
|
345
|
+
shapes.push(vline(px(v), y0, y1));
|
|
346
|
+
shapes.push(text(px(v) - 22, y1 + 4, 44, fmt.format(v), { a: 'c', c: TICK_INK, z: TICK_SIZE }));
|
|
347
|
+
}
|
|
348
|
+
const maxR = Math.max(1, ...pts.map((p) => num(p.r) ?? 0));
|
|
349
|
+
chart.series.forEach((s, si) => {
|
|
350
|
+
const ink = seriesInk(s, si);
|
|
351
|
+
for (const p of s.data) {
|
|
352
|
+
if (!p || typeof p !== 'object') continue;
|
|
353
|
+
const r = chart.kind === 'bubble' ? Math.max(3, Math.sqrt((num(p.r) ?? 0) / maxR) * 14) : 3;
|
|
354
|
+
shapes.push({ k: 'c', x: fix(px(p.x)), y: fix(py(p.y)), r: fix(r), f: `#66${ink.slice(1)}`, s: ink });
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
return { w: WIDTH, h: CHART_HEIGHT, shapes };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function seriesLegend(chart) {
|
|
361
|
+
if (chart.series.length < 2 && !chart.series[0]?.label) return [];
|
|
362
|
+
return chart.series.filter((s) => s.label).map((s) => {
|
|
363
|
+
const si = chart.series.indexOf(s);
|
|
364
|
+
const line = chart.kind === 'line' || chart.kind === 'radar' || chart.kind === 'scatter' || chart.kind === 'bubble' || (chart.kind === 'combo' && s.type === 'line');
|
|
365
|
+
return { label: s.label, color: line ? seriesInk(s, si) : seriesFill(s, si) };
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Khối biểu đồ → `{ w, h, shapes, legend }`; không có số để vẽ → null (nơi gọi đổi thành nhãn + nút xem trên web). */
|
|
370
|
+
export function chartLayout(chart, lang) {
|
|
371
|
+
if (!chart?.series?.length) return null;
|
|
372
|
+
const { kind } = chart;
|
|
373
|
+
let out = null;
|
|
374
|
+
if (kind === 'pie' || kind === 'doughnut') out = pieChart(chart);
|
|
375
|
+
else if (kind === 'polarArea') out = polarChart(chart);
|
|
376
|
+
else if (kind === 'radar') out = radarChart(chart);
|
|
377
|
+
else if (kind === 'scatter' || kind === 'bubble') out = scatterChart(chart, lang);
|
|
378
|
+
else if (HORIZONTAL_KINDS.has(kind)) out = horizontalChart(chart, lang);
|
|
379
|
+
else if (BAR_KINDS.has(kind) || kind === 'line' || kind === 'combo') out = verticalChart(chart, lang);
|
|
380
|
+
if (!out) return null;
|
|
381
|
+
return { ...out, legend: out.legend || seriesLegend(chart) };
|
|
382
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { gunzipSync } from 'zlib';
|
|
6
|
+
import { REMOTE_CONFIG_DIR } from '../constants.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Dựng sơ đồ và mở công cụ tương tác cho linh vật (03/11/2026). WPF không chạy được JavaScript hiện đại nên dùng trình duyệt có sẵn trên máy (Edge luôn có trên
|
|
10
|
+
* Windows 10/11, không có thì Chrome):
|
|
11
|
+
* - Sơ đồ: Mermaid (cùng thư viện với web, đóng gói trong CLI) chạy trong trình duyệt không giao diện, chặn hẳn mạng (`--host-resolver-rules`), hồ sơ riêng,
|
|
12
|
+
* `securityLevel: strict`; đo cỡ rồi chụp thành PNG. Không dựng được → null, nơi gọi đổi thành nút mở trên web.
|
|
13
|
+
* - Công cụ tương tác: cửa sổ ứng dụng riêng (`--app`), HTML của AI nằm trong iframe `sandbox="allow-scripts allow-modals"` — cùng cờ với web: origin riêng, không
|
|
14
|
+
* đọc được tệp trên máy, không điều hướng được trang ngoài, không mở cửa sổ khác. Chỉ mở khi chủ máy bấm.
|
|
15
|
+
*/
|
|
16
|
+
export const MASCOT_RENDER_DIR = path.join(REMOTE_CONFIG_DIR, 'mascot-render');
|
|
17
|
+
const RENDER_TIMEOUT_MS = 20000;
|
|
18
|
+
const KEEP_IMAGES = 40;
|
|
19
|
+
const DIAGRAM_PADDING = 16;
|
|
20
|
+
const MAX_SIDE = 4000;
|
|
21
|
+
const BROWSER_PATHS = [
|
|
22
|
+
['ProgramFiles(x86)', 'Microsoft\\Edge\\Application\\msedge.exe'],
|
|
23
|
+
['ProgramFiles', 'Microsoft\\Edge\\Application\\msedge.exe'],
|
|
24
|
+
['LOCALAPPDATA', 'Microsoft\\Edge\\Application\\msedge.exe'],
|
|
25
|
+
['ProgramFiles', 'Google\\Chrome\\Application\\chrome.exe'],
|
|
26
|
+
['ProgramFiles(x86)', 'Google\\Chrome\\Application\\chrome.exe'],
|
|
27
|
+
['LOCALAPPDATA', 'Google\\Chrome\\Application\\chrome.exe'],
|
|
28
|
+
];
|
|
29
|
+
const SIZE_MARK = /<title>OK (\d+) (\d+)<\/title>/;
|
|
30
|
+
|
|
31
|
+
export function findBrowser(env = process.env, exists = fs.existsSync) {
|
|
32
|
+
for (const [base, rel] of BROWSER_PATHS) {
|
|
33
|
+
const file = env[base] ? path.win32.join(env[base], rel) : null;
|
|
34
|
+
if (file && exists(file)) return file;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const fileUrl = (file) => `file:///${path.resolve(file).replace(/\\/g, '/').split('/').map(encodeURIComponent).join('/').replace(/^([A-Za-z])%3A/, '$1:')}`;
|
|
40
|
+
|
|
41
|
+
/** Chạy trình duyệt không giao diện, trả stdout; quá giờ / lỗi → ném. */
|
|
42
|
+
function runHeadless(browser, args, { spawnImpl, timeoutMs }) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const child = spawnImpl(browser, args, { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
45
|
+
let out = '';
|
|
46
|
+
const timer = setTimeout(() => { child.kill(); reject(new Error('timeout')); }, timeoutMs);
|
|
47
|
+
timer.unref?.();
|
|
48
|
+
child.stdout?.on('data', (d) => { out += d; });
|
|
49
|
+
child.on('error', (e) => { clearTimeout(timer); reject(e); });
|
|
50
|
+
child.on('close', () => { clearTimeout(timer); resolve(out); });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Chuỗi JSON đặt được trong thẻ script: `</script>` trong sơ đồ không thoát ra ngoài. */
|
|
55
|
+
const scriptSafeJson = (value) => JSON.stringify(value).replace(/</g, '\\u003c');
|
|
56
|
+
|
|
57
|
+
function diagramPage(source, mermaidFile, size) {
|
|
58
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>WAIT</title><style>html,body{margin:0;background:#fff}#d{display:inline-block;padding:${DIAGRAM_PADDING / 2}px}</style></head><body><div id="d"></div>
|
|
59
|
+
<script src="${path.basename(mermaidFile)}"></script>
|
|
60
|
+
<script>
|
|
61
|
+
var source = ${scriptSafeJson(source)};
|
|
62
|
+
mermaid.initialize({ startOnLoad: false, securityLevel: 'strict', theme: 'base', fontFamily: 'Segoe UI, sans-serif',
|
|
63
|
+
themeVariables: { fontFamily: 'Segoe UI, sans-serif', fontSize: '14px', primaryColor: '#EFF6FF', primaryBorderColor: '#93C5FD', primaryTextColor: '#1D2129', lineColor: '#86909C', secondaryColor: '#F5F3FF', tertiaryColor: '#F7F8FA' } });
|
|
64
|
+
mermaid.render('g', source).then(function (r) {
|
|
65
|
+
var d = document.getElementById('d'); d.innerHTML = r.svg;
|
|
66
|
+
var svg = d.querySelector('svg'); var box = svg.viewBox.baseVal; var w = Math.ceil(box.width || svg.getBoundingClientRect().width); var h = Math.ceil(box.height || svg.getBoundingClientRect().height);
|
|
67
|
+
svg.style.maxWidth = 'none'; svg.setAttribute('width', w); svg.setAttribute('height', h);
|
|
68
|
+
document.title = 'OK ' + w + ' ' + h;
|
|
69
|
+
}).catch(function (e) { document.title = 'FAIL'; });
|
|
70
|
+
</script>${size ? '' : ''}</body></html>`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Tệp mermaid.min.js trong thư mục dựng: giải nén một lần theo phiên bản, chỉ khi gặp sơ đồ đầu tiên (bộ nén nặng ~1 MB, không nạp lúc daemon khởi động). */
|
|
74
|
+
async function ensureMermaid(dir) {
|
|
75
|
+
const { MERMAID_GZ_BASE64, MERMAID_VERSION } = await import('./mermaidBundle.mjs');
|
|
76
|
+
const file = path.join(dir, `mermaid-${MERMAID_VERSION}.min.js`);
|
|
77
|
+
if (!fs.existsSync(file)) {
|
|
78
|
+
const tmp = `${file}.tmp${process.pid}`;
|
|
79
|
+
fs.writeFileSync(tmp, gunzipSync(Buffer.from(MERMAID_GZ_BASE64, 'base64')));
|
|
80
|
+
fs.renameSync(tmp, file);
|
|
81
|
+
}
|
|
82
|
+
return file;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function pruneImages(dir) {
|
|
86
|
+
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.png')).map((name) => {
|
|
87
|
+
const file = path.join(dir, name);
|
|
88
|
+
return { file, at: fs.statSync(file).mtimeMs };
|
|
89
|
+
}).sort((a, b) => b.at - a.at);
|
|
90
|
+
for (const { file } of files.slice(KEEP_IMAGES)) fs.rmSync(file, { force: true });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Mỗi lúc một sơ đồ: mỗi lần dựng mở một tiến trình trình duyệt. */
|
|
94
|
+
let queue = Promise.resolve();
|
|
95
|
+
|
|
96
|
+
/** Mã Mermaid → đường dẫn PNG (dùng lại nếu đã dựng), không dựng được → null. Không ném lỗi. */
|
|
97
|
+
export function renderDiagram(source, { dir = MASCOT_RENDER_DIR, browser = findBrowser(), spawnImpl = spawn, timeoutMs = RENDER_TIMEOUT_MS } = {}) {
|
|
98
|
+
const run = async () => {
|
|
99
|
+
if (!browser) return null;
|
|
100
|
+
const name = createHash('sha256').update(String(source)).digest('hex').slice(0, 32);
|
|
101
|
+
const png = path.join(dir, `${name}.png`);
|
|
102
|
+
const page = path.join(dir, `${name}.html`);
|
|
103
|
+
try {
|
|
104
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
105
|
+
if (fs.existsSync(png)) return png;
|
|
106
|
+
const mermaidFile = await ensureMermaid(dir);
|
|
107
|
+
fs.writeFileSync(page, diagramPage(String(source), mermaidFile));
|
|
108
|
+
const base = [
|
|
109
|
+
'--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check', '--disable-extensions', '--disable-sync', '--disable-background-networking',
|
|
110
|
+
'--disable-component-update', '--host-resolver-rules=MAP * ~NOTFOUND', `--user-data-dir=${path.join(dir, 'profile')}`, '--virtual-time-budget=8000',
|
|
111
|
+
];
|
|
112
|
+
// Lượt đầu đo cỡ sơ đồ, lượt sau chụp đúng cỡ đó, độ phân giải gấp đôi để thu nhỏ trong ô hỏi vẫn nét.
|
|
113
|
+
const dom = await runHeadless(browser, [...base, '--dump-dom', fileUrl(page)], { spawnImpl, timeoutMs });
|
|
114
|
+
const size = String(dom).match(SIZE_MARK);
|
|
115
|
+
if (!size) return null;
|
|
116
|
+
const w = Math.min(MAX_SIDE, Number(size[1]) + DIAGRAM_PADDING);
|
|
117
|
+
const h = Math.min(MAX_SIDE, Number(size[2]) + DIAGRAM_PADDING);
|
|
118
|
+
await runHeadless(browser, [...base, '--force-device-scale-factor=2', '--hide-scrollbars', `--window-size=${w},${h}`, `--screenshot=${png}`, fileUrl(page)], { spawnImpl, timeoutMs });
|
|
119
|
+
if (!fs.existsSync(png)) return null;
|
|
120
|
+
pruneImages(dir);
|
|
121
|
+
return png;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
} finally {
|
|
125
|
+
fs.rmSync(page, { force: true });
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const result = queue.then(run, run);
|
|
129
|
+
queue = result.catch(() => null);
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const escapeAttr = (s) => String(s).replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
134
|
+
|
|
135
|
+
/** Trang bọc công cụ tương tác: bản thân trang không có script, mọi thứ của AI nằm trong iframe sandbox (cùng cờ `WebViewRenderer` trên web). */
|
|
136
|
+
export function webviewPage(html, title) {
|
|
137
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>${escapeAttr(title)}</title><style>html,body{margin:0;height:100%;background:#fff}iframe{border:0;width:100%;height:100%;display:block}</style></head><body><iframe sandbox="allow-scripts allow-modals" referrerpolicy="no-referrer" srcdoc="${escapeAttr(html)}"></iframe></body></html>`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Mở công cụ tương tác trong cửa sổ riêng. Không có trình duyệt → false, nơi gọi mở phiên trên web. */
|
|
141
|
+
export function openWebview(html, title, { dir = MASCOT_RENDER_DIR, browser = findBrowser(), spawnImpl = spawn } = {}) {
|
|
142
|
+
if (!browser) return false;
|
|
143
|
+
try {
|
|
144
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
145
|
+
const file = path.join(dir, `webview-${createHash('sha256').update(html).digest('hex').slice(0, 24)}.html`);
|
|
146
|
+
fs.writeFileSync(file, webviewPage(html, title));
|
|
147
|
+
const child = spawnImpl(browser, [`--app=${fileUrl(file)}`, '--window-size=560,720', '--no-first-run', '--no-default-browser-check'], { stdio: 'ignore', detached: true, windowsHide: false });
|
|
148
|
+
child.on?.('error', () => {});
|
|
149
|
+
child.unref?.();
|
|
150
|
+
return true;
|
|
151
|
+
} catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|