@aivin-labs/cli 1.0.40 → 1.0.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.
@@ -310,6 +310,96 @@ export function printChromeLaunchHelp(port = CHROME_DEBUG_PORT, preferredId) {
310
310
  console.log(chalk.gray(' ...or pass --remote for a server-side browser instead (no local browser needed).'));
311
311
  }
312
312
 
313
+ export function buildHideTaskbarPowerShellScript(profileDir = AIVIN_BROWSER_PROFILE_DIR) {
314
+ const escapedDir = String(profileDir || '').replace(/'/g, "''");
315
+ return `
316
+ $ErrorActionPreference = 'SilentlyContinue'
317
+ $targetDir = '${escapedDir}'.Replace('/', '\\').TrimEnd('\\').ToLowerInvariant()
318
+ if (-not $targetDir) { exit 0 }
319
+
320
+ Add-Type -TypeDefinition @'
321
+ using System;
322
+ using System.Collections.Generic;
323
+ using System.Runtime.InteropServices;
324
+
325
+ public static class AivinTaskbarHider {
326
+ public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
327
+ [DllImport("user32.dll")] public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
328
+ [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
329
+ [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd);
330
+ [DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
331
+ [DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
332
+ [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
333
+ [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
334
+
335
+ public static void HideForPids(uint[] pids) {
336
+ if (pids == null || pids.Length == 0) return;
337
+ var set = new HashSet<uint>(pids);
338
+ EnumWindows((hWnd, lParam) => {
339
+ if (!IsWindowVisible(hWnd)) return true;
340
+ uint pid;
341
+ GetWindowThreadProcessId(hWnd, out pid);
342
+ if (!set.Contains(pid)) return true;
343
+ int ex = GetWindowLong(hWnd, -20);
344
+ int next = (ex | 0x00000080) & ~0x00040000;
345
+ if (next != ex) {
346
+ ShowWindow(hWnd, 0);
347
+ SetWindowLong(hWnd, -20, next);
348
+ ShowWindow(hWnd, 4);
349
+ }
350
+ SetWindowPos(hWnd, IntPtr.Zero, 10000, 10000, 0, 0, 0x0035);
351
+ return true;
352
+ }, IntPtr.Zero);
353
+ }
354
+ }
355
+ '@
356
+
357
+ for ($attempt = 0; $attempt -lt 3; $attempt++) {
358
+ $procs = Get-CimInstance Win32_Process -Filter "Name='msedge.exe' OR Name='chrome.exe' OR Name='brave.exe'"
359
+ $pids = @()
360
+ foreach ($p in $procs) {
361
+ $cmd = [string]$p.CommandLine
362
+ if ($cmd -match '--user-data-dir=(?:"([^"]+)"|''([^'']+)''|(\\S+))') {
363
+ $raw = if ($matches[1]) { $matches[1] } elseif ($matches[2]) { $matches[2] } else { $matches[3] }
364
+ $norm = $raw.Replace('/', '\\').TrimEnd('\\').ToLowerInvariant()
365
+ if ($norm -eq $targetDir) {
366
+ $pids += [uint32]$p.ProcessId
367
+ }
368
+ }
369
+ }
370
+ if ($pids.Count -gt 0) {
371
+ [AivinTaskbarHider]::HideForPids($pids)
372
+ }
373
+ if ($attempt -lt 2) { Start-Sleep -Milliseconds 350 }
374
+ }
375
+ `.trim();
376
+ }
377
+
378
+ /**
379
+ * Ẩn cửa sổ trình duyệt riêng của Aivin (`AIVIN_BROWSER_PROFILE_DIR`) khỏi thanh tác vụ Windows và Alt+Tab
380
+ * bằng cờ Win32 `WS_EX_TOOLWINDOW` (bỏ `WS_EX_APPWINDOW`) + giữ cửa sổ ở `(10000, 10000)` trạng thái hiển thị
381
+ * (`SW_SHOWNOACTIVATE`) để Chromium vẫn vẽ khung hình bình thường cho WebRTC `tabCapture` và CDP screencast.
382
+ * Không đụng vào trình duyệt hằng ngày của người dùng.
383
+ */
384
+ export function hideAivinBrowserFromTaskbar(profileDir = AIVIN_BROWSER_PROFILE_DIR, { platform = process.platform, force = false } = {}) {
385
+ if (platform !== 'win32') return false;
386
+ if (!force && process.env.NODE_TEST_CONTEXT) return false;
387
+ try {
388
+ const script = buildHideTaskbarPowerShellScript(profileDir);
389
+ const encoded = Buffer.from(script, 'utf16le').toString('base64');
390
+ const child = spawn(
391
+ 'powershell.exe',
392
+ ['-NoProfile', '-NonInteractive', '-WindowStyle', 'Hidden', '-EncodedCommand', encoded],
393
+ { detached: true, stdio: 'ignore', windowsHide: true },
394
+ );
395
+ child.on('error', () => {});
396
+ child.unref();
397
+ return true;
398
+ } catch {
399
+ return false;
400
+ }
401
+ }
402
+
313
403
  /** Launches a browser window dedicated to `aivin browser`, on ITS OWN profile
314
404
  * (AIVIN_BROWSER_PROFILE_DIR) - never the user's real daily-driver one. This is what makes local
315
405
  * mode zero-friction after the first run: because it's a separate profile, it never collides with
@@ -373,7 +463,10 @@ export async function launchLocalChromeWithDebugging(port = CHROME_DEBUG_PORT, p
373
463
  : `Could not start ${browser.name}: ${spawnError.message}`);
374
464
  }
375
465
  const { wsUrl, conflict } = await probeLocalChromeDebugger(port);
376
- if (wsUrl) return wsUrl;
466
+ if (wsUrl) {
467
+ hideAivinBrowserFromTaskbar(AIVIN_BROWSER_PROFILE_DIR);
468
+ return wsUrl;
469
+ }
377
470
  if (conflict) {
378
471
  throw new Error(
379
472
  `Port ${port} is already in use by something else (reported itself as "${conflict}", not Chrome/Edge) - ` +
@@ -3,7 +3,7 @@ import os from 'os';
3
3
  import path from 'path';
4
4
  import WSClient from 'ws';
5
5
  import {
6
- AIVIN_BROWSER_PROFILE_DIR, DEBUG_PORTS, LOCAL_BROWSERS, detectDefaultBrowserId, launchLocalChromeWithDebugging, probeLocalChromeDebugger,
6
+ AIVIN_BROWSER_PROFILE_DIR, DEBUG_PORTS, LOCAL_BROWSERS, detectDefaultBrowserId, hideAivinBrowserFromTaskbar, launchLocalChromeWithDebugging, probeLocalChromeDebugger,
7
7
  resolveBrowserInstall,
8
8
  } from '../localBrowser.mjs';
9
9
  import { DeviceErrorCode } from './constants.mjs';
@@ -65,12 +65,12 @@ export function detectLocalBrowser() {
65
65
  */
66
66
  export async function ensureAivinBrowser(preferredId, { ports = DEBUG_PORTS, launch = true, log } = {}) {
67
67
  const running = await activeBrowserEndpoint(AIVIN_BROWSER_PROFILE_DIR);
68
- if (running) return { wsUrl: running.wsUrl, browserId: (await probeLocalChromeDebugger(running.port)).browserId || preferredId, port: running.port };
68
+ if (running) { hideAivinBrowserFromTaskbar(AIVIN_BROWSER_PROFILE_DIR); return { wsUrl: running.wsUrl, browserId: (await probeLocalChromeDebugger(running.port)).browserId || preferredId, port: running.port }; }
69
69
  // Cửa sổ Aivin đang mở mà không ghi DevToolsActivePort (Edge với cổng cố định) → dùng lại theo dòng lệnh tiến trình, không mở thêm.
70
70
  const processPort = await browserPortFromProcesses(AIVIN_BROWSER_PROFILE_DIR);
71
71
  if (processPort) {
72
72
  const { wsUrl, browserId } = await probeLocalChromeDebugger(processPort);
73
- if (wsUrl) return { wsUrl, browserId: browserId || preferredId, port: processPort };
73
+ if (wsUrl) { hideAivinBrowserFromTaskbar(AIVIN_BROWSER_PROFILE_DIR); return { wsUrl, browserId: browserId || preferredId, port: processPort }; }
74
74
  }
75
75
  if (!launch) throw new DeviceToolError(DeviceErrorCode.BROWSER_NOT_FOUND, 'The Aivin browser window is no longer running');
76
76
  const conflicts = [];
@@ -240,6 +240,8 @@ namespace AivinDesktop {
240
240
  }
241
241
  }
242
242
 
243
+ protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) { }
244
+
243
245
  protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) {
244
246
  if (e.Item.Selected && e.Item.Enabled) {
245
247
  int width = Math.Min(e.Item.Width, e.ToolStrip.ClientSize.Width - e.Item.Bounds.Left);
@@ -424,7 +426,12 @@ namespace AivinDesktop {
424
426
  serverCloud = Item(cfg.T("serverCloud"), delegate { ChangeServer("https://api.aivin.cloud"); });
425
427
  serverVn = Item(cfg.T("serverVn"), delegate { ChangeServer("https://api.aivin.vn"); });
426
428
  serverLocal = Item(cfg.T("serverLocal"), delegate { ChangeServer("http://localhost:3001"); });
427
- serverMenu.DropDownItems.AddRange(new ToolStripItem[] { serverCloud, serverVn, serverLocal });
429
+ serverMenu.DropDownItems.AddRange(new ToolStripItem[] { serverCloud, serverVn, serverLocal });
430
+ ToolStripDropDownMenu serverDrop = serverMenu.DropDown as ToolStripDropDownMenu; if (serverDrop != null) { serverDrop.ShowImageMargin = false; }
431
+ if (serverDrop != null) { serverDrop.ShowCheckMargin = false; }
432
+ serverMenu.DropDown.BackColor = Color.White;
433
+ serverMenu.DropDown.Font = new Font("Segoe UI", 9.5f, FontStyle.Regular);
434
+ serverMenu.DropDown.Padding = new Padding(2, 6, 2, 6);
428
435
  startup = Item(cfg.T("startup"), delegate { SetStartup(!StartupEnabled()); Refresh(); });
429
436
  updateItem = Item("", delegate { CheckOrApplyUpdate(); });
430
437
 
@@ -750,9 +757,12 @@ namespace AivinDesktop {
750
757
  }
751
758
  string selectedServer = CurrentServerUrl();
752
759
  serverMenu.Text = cfg.T("server") + ": " + ServerName(selectedServer);
753
- serverCloud.Checked = selectedServer == "https://api.aivin.cloud";
754
- serverVn.Checked = selectedServer == "https://api.aivin.vn";
755
- serverLocal.Checked = selectedServer == "http://localhost:3001";
760
+ bool isCloud = selectedServer == "https://api.aivin.cloud";
761
+ bool isVn = selectedServer == "https://api.aivin.vn";
762
+ bool isLocal = selectedServer == "http://localhost:3001";
763
+ serverCloud.Text = (isCloud ? "✓ " : " ") + cfg.T("serverCloud");
764
+ serverVn.Text = (isVn ? "✓ " : " ") + cfg.T("serverVn");
765
+ serverLocal.Text = (isLocal ? "✓ " : " ") + cfg.T("serverLocal");
756
766
  open.Text = cfg.T(paired ? "open" : "connect");
757
767
  connectCodeItem.Visible = !paired;
758
768
  connectCodeItem.Enabled = !browserConnectInProgress;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aivin-labs/cli",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "aivin CLI - scaffold, run, and deploy Aivin plugins built on @aivin-labs/sdk",
5
5
  "type": "module",
6
6
  "bin": {