tamga-vdesktop 1.1.2 → 1.1.4

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/dist/cli.js CHANGED
@@ -2248,6 +2248,19 @@ import fs6 from "node:fs";
2248
2248
  import os4 from "node:os";
2249
2249
  import path6 from "node:path";
2250
2250
  import { execSync as execSync2, spawn as spawn3 } from "node:child_process";
2251
+ var SLOT_W = 1920;
2252
+ var SLOT_H = 1080;
2253
+ var SLOT_COLS = 2;
2254
+ var PROFILE_LOCKED_APPS = /* @__PURE__ */ new Set([
2255
+ "firefox",
2256
+ "firefox-esr",
2257
+ "chrome",
2258
+ "google-chrome",
2259
+ "google-chrome-stable",
2260
+ "chromium",
2261
+ "chromium-browser",
2262
+ "antigravity"
2263
+ ]);
2251
2264
  function findFreeDisplay(inUse) {
2252
2265
  for (let d = 100; d < 250; d++) {
2253
2266
  if (inUse.has(d)) continue;
@@ -2258,14 +2271,13 @@ function findFreeDisplay(inUse) {
2258
2271
  return 100 + Math.floor(Math.random() * 100);
2259
2272
  }
2260
2273
  function hasTurboJpegAndXDamage() {
2261
- const candidates = [
2274
+ const tjCandidates = [
2262
2275
  "/lib/x86_64-linux-gnu/libturbojpeg.so.0",
2263
2276
  "/usr/lib/x86_64-linux-gnu/libturbojpeg.so.0",
2264
2277
  "/lib/aarch64-linux-gnu/libturbojpeg.so.0",
2265
2278
  "/usr/lib/aarch64-linux-gnu/libturbojpeg.so.0",
2266
2279
  "/usr/lib/libturbojpeg.so.0"
2267
2280
  ];
2268
- const hasTj = candidates.some((p) => fs6.existsSync(p));
2269
2281
  const dmgCandidates = [
2270
2282
  "/lib/x86_64-linux-gnu/libXdamage.so.1",
2271
2283
  "/usr/lib/x86_64-linux-gnu/libXdamage.so.1",
@@ -2273,17 +2285,17 @@ function hasTurboJpegAndXDamage() {
2273
2285
  "/usr/lib/aarch64-linux-gnu/libXdamage.so.1",
2274
2286
  "/usr/lib/libXdamage.so.1"
2275
2287
  ];
2276
- const hasDmg = dmgCandidates.some((p) => fs6.existsSync(p));
2277
- return hasTj && hasDmg;
2288
+ return tjCandidates.some((p) => fs6.existsSync(p)) && dmgCandidates.some((p) => fs6.existsSync(p));
2278
2289
  }
2279
2290
  function buildOpenboxRcXml() {
2280
2291
  return `<?xml version="1.0" encoding="UTF-8"?>
2281
2292
  <openbox_config xmlns="http://openbox.org/3.4/rc">
2282
2293
  <resistance><strength>0</strength><screen_edge_strength>0</screen_edge_strength></resistance>
2283
2294
  <focus><focusNew>yes</focusNew><followMouse>no</followMouse></focus>
2284
- <placement><policy>Smart</policy><center>yes</center></placement>
2295
+ <placement><policy>Smart</policy><center>no</center></placement>
2285
2296
  <theme><name>Clearlooks</name><titleLayout>NLIMC</titleLayout><keepBorder>no</keepBorder></theme>
2286
2297
  <desktops><number>1</number></desktops>
2298
+ <margins><top>0</top><bottom>0</bottom><left>0</left><right>0</right></margins>
2287
2299
  <applications>
2288
2300
  <application class="*">
2289
2301
  <decor>no</decor>
@@ -2293,6 +2305,14 @@ function buildOpenboxRcXml() {
2293
2305
  </openbox_config>
2294
2306
  `;
2295
2307
  }
2308
+ function clampDim(w, h) {
2309
+ const cw = Math.max(240, Math.min(SLOT_W, Math.round(w || 1100)));
2310
+ const ch = Math.max(180, Math.min(SLOT_H, Math.round(h || 680)));
2311
+ return {
2312
+ width: cw - cw % 2,
2313
+ height: ch - ch % 2
2314
+ };
2315
+ }
2296
2316
  var LinuxAppSession = class {
2297
2317
  sessionId;
2298
2318
  desktopId;
@@ -2312,17 +2332,14 @@ var LinuxAppSession = class {
2312
2332
  command;
2313
2333
  needsNoSandbox;
2314
2334
  tempDir;
2335
+ baseEnv = {};
2315
2336
  xvfbProc = null;
2316
2337
  openboxProc = null;
2317
2338
  appProc = null;
2318
2339
  x11BridgeProc = null;
2319
- streamerProc = null;
2320
- streamerMode = "xdamage";
2321
2340
  parecProc = null;
2322
2341
  pulseSinkName = "";
2323
- subscribers = /* @__PURE__ */ new Set();
2324
- lastFrame = null;
2325
- resizeTimer = null;
2342
+ views = /* @__PURE__ */ new Map();
2326
2343
  hadWindow = false;
2327
2344
  closed = false;
2328
2345
  onCloseCb;
@@ -2337,10 +2354,9 @@ var LinuxAppSession = class {
2337
2354
  this.desktopDataRoot = opts.desktopDataRoot;
2338
2355
  this.displayNum = displayNum;
2339
2356
  this.displayStr = `:${displayNum}`;
2340
- this.width = Math.max(420, Math.min(1920, Math.round(opts.width || 1100)));
2341
- this.height = Math.max(300, Math.min(1080, Math.round(opts.height || 680)));
2342
- this.width = this.width - this.width % 2;
2343
- this.height = this.height - this.height % 2;
2357
+ const dims = clampDim(opts.width || 1100, opts.height || 680);
2358
+ this.width = dims.width;
2359
+ this.height = dims.height;
2344
2360
  this.fps = Math.max(10, Math.min(30, opts.fps || 24));
2345
2361
  this.quality = Math.max(2, Math.min(10, opts.quality || 4));
2346
2362
  this.enableAudio = opts.enableAudio ?? true;
@@ -2349,6 +2365,19 @@ var LinuxAppSession = class {
2349
2365
  `tamga-gui-${this.sessionId.replace(/[^a-z0-9_-]/gi, "")}`
2350
2366
  );
2351
2367
  this.onCloseCb = onCloseCb;
2368
+ this.views.set("main", {
2369
+ viewId: "main",
2370
+ title: this.appName,
2371
+ width: this.width,
2372
+ height: this.height,
2373
+ offsetX: 0,
2374
+ offsetY: 0,
2375
+ lastFrame: null,
2376
+ streamerProc: null,
2377
+ streamerMode: "xdamage",
2378
+ resizeTimer: null,
2379
+ subscribers: /* @__PURE__ */ new Set()
2380
+ });
2352
2381
  }
2353
2382
  async start() {
2354
2383
  fs6.mkdirSync(this.tempDir, { recursive: true });
@@ -2360,7 +2389,7 @@ var LinuxAppSession = class {
2360
2389
  this.displayStr,
2361
2390
  "-screen",
2362
2391
  "0",
2363
- "1920x1080x24",
2392
+ "3840x2160x24",
2364
2393
  "-ac",
2365
2394
  "+extension",
2366
2395
  "RANDR",
@@ -2389,6 +2418,8 @@ var LinuxAppSession = class {
2389
2418
  NO_AT_BRIDGE: "1",
2390
2419
  XCURSOR_THEME: "DMZ-White"
2391
2420
  };
2421
+ delete baseEnv.DBUS_SESSION_BUS_ADDRESS;
2422
+ this.baseEnv = baseEnv;
2392
2423
  this.openboxProc = spawn3("openbox", ["--config-file", obRcPath], {
2393
2424
  env: baseEnv,
2394
2425
  stdio: "ignore"
@@ -2398,11 +2429,8 @@ var LinuxAppSession = class {
2398
2429
  }
2399
2430
  this.startX11Bridge(baseEnv);
2400
2431
  this.launchTargetApp(baseEnv);
2401
- if (hasTurboJpegAndXDamage()) {
2402
- this.startXDamageStreamer(baseEnv);
2403
- } else {
2404
- this.startFfmpegFallbackCapture();
2405
- }
2432
+ const mainView = this.views.get("main");
2433
+ this.startViewStreamer(mainView);
2406
2434
  }
2407
2435
  setupPulseAudio(baseEnv) {
2408
2436
  try {
@@ -2440,7 +2468,9 @@ var LinuxAppSession = class {
2440
2468
  const CHUNK_BYTES = 2048;
2441
2469
  let pcmBuf = Buffer.alloc(0);
2442
2470
  parec.stdout?.on("data", (chunk) => {
2443
- if (this.closed || this.subscribers.size === 0) return;
2471
+ if (this.closed) return;
2472
+ const audioView = this.views.get("main") || this.views.values().next().value;
2473
+ if (!audioView || audioView.subscribers.size === 0) return;
2444
2474
  pcmBuf = Buffer.concat([pcmBuf, chunk]);
2445
2475
  while (pcmBuf.length >= CHUNK_BYTES) {
2446
2476
  const slice = pcmBuf.subarray(0, CHUNK_BYTES);
@@ -2452,7 +2482,7 @@ var LinuxAppSession = class {
2452
2482
  if (peak > 45) break;
2453
2483
  }
2454
2484
  if (peak > 45) {
2455
- for (const sub of this.subscribers) {
2485
+ for (const sub of audioView.subscribers) {
2456
2486
  sub.onAudioChunk(slice);
2457
2487
  }
2458
2488
  }
@@ -2461,6 +2491,14 @@ var LinuxAppSession = class {
2461
2491
  } catch {
2462
2492
  }
2463
2493
  }
2494
+ getEventHostView() {
2495
+ const main2 = this.views.get("main");
2496
+ if (main2 && main2.subscribers.size > 0) return main2;
2497
+ for (const v of this.views.values()) {
2498
+ if (v.subscribers.size > 0) return v;
2499
+ }
2500
+ return main2;
2501
+ }
2464
2502
  startX11Bridge(baseEnv) {
2465
2503
  const scriptPath = resolveHelperPath("x11_bridge.py");
2466
2504
  const proc = spawn3(
@@ -2482,21 +2520,7 @@ var LinuxAppSession = class {
2482
2520
  if (line) {
2483
2521
  try {
2484
2522
  const msg = JSON.parse(line);
2485
- if (msg.type === "title" && typeof msg.title === "string") {
2486
- this.hadWindow = true;
2487
- this.title = msg.title;
2488
- } else if (msg.type === "cursor" && typeof msg.cursor === "string") {
2489
- this.cursor = msg.cursor;
2490
- } else if (msg.type === "all_windows_closed" && !this.closed) {
2491
- for (const sub of this.subscribers) {
2492
- sub.onEvent({ type: "app_exit", code: 0 });
2493
- }
2494
- this.close();
2495
- return;
2496
- }
2497
- for (const sub of this.subscribers) {
2498
- sub.onEvent(msg);
2499
- }
2523
+ this.handleBridgeEvent(msg);
2500
2524
  } catch {
2501
2525
  }
2502
2526
  }
@@ -2504,13 +2528,128 @@ var LinuxAppSession = class {
2504
2528
  }
2505
2529
  });
2506
2530
  }
2507
- launchTargetApp(baseEnv) {
2531
+ handleBridgeEvent(msg) {
2532
+ if (this.closed) return;
2533
+ if (msg.type === "title" && typeof msg.title === "string") {
2534
+ this.hadWindow = true;
2535
+ const vid = typeof msg.view === "string" ? msg.view : "main";
2536
+ const v = this.views.get(vid);
2537
+ if (v) {
2538
+ v.title = msg.title;
2539
+ for (const sub of v.subscribers) {
2540
+ sub.onEvent({ type: "title", title: msg.title });
2541
+ }
2542
+ }
2543
+ if (vid === "main") this.title = msg.title;
2544
+ return;
2545
+ }
2546
+ if (msg.type === "cursor" && typeof msg.cursor === "string") {
2547
+ this.cursor = msg.cursor;
2548
+ for (const v of this.views.values()) {
2549
+ for (const sub of v.subscribers) {
2550
+ sub.onEvent(msg);
2551
+ }
2552
+ }
2553
+ return;
2554
+ }
2555
+ if (msg.type === "window_opened" && typeof msg.view === "string") {
2556
+ this.hadWindow = true;
2557
+ const slot = Math.max(0, Math.min(3, Number(msg.slot) || 1));
2558
+ const dims = clampDim(Number(msg.width) || 900, Number(msg.height) || 640);
2559
+ const offsetX = slot % SLOT_COLS * SLOT_W;
2560
+ const offsetY = Math.floor(slot / SLOT_COLS) * SLOT_H;
2561
+ const title = typeof msg.title === "string" && msg.title ? msg.title : this.appName;
2562
+ if (!this.views.has(msg.view)) {
2563
+ const view = {
2564
+ viewId: msg.view,
2565
+ title,
2566
+ width: dims.width,
2567
+ height: dims.height,
2568
+ offsetX,
2569
+ offsetY,
2570
+ lastFrame: null,
2571
+ streamerProc: null,
2572
+ streamerMode: "xdamage",
2573
+ resizeTimer: null,
2574
+ subscribers: /* @__PURE__ */ new Set()
2575
+ };
2576
+ this.views.set(msg.view, view);
2577
+ this.startViewStreamer(view);
2578
+ }
2579
+ const hostView2 = this.getEventHostView();
2580
+ if (hostView2) {
2581
+ for (const sub of hostView2.subscribers) {
2582
+ sub.onEvent({
2583
+ type: "window_opened",
2584
+ view: msg.view,
2585
+ title,
2586
+ width: dims.width,
2587
+ height: dims.height
2588
+ });
2589
+ }
2590
+ }
2591
+ return;
2592
+ }
2593
+ if (msg.type === "view_geometry" && typeof msg.view === "string") {
2594
+ const v = this.views.get(msg.view);
2595
+ if (!v) return;
2596
+ const dims = clampDim(Number(msg.width) || v.width, Number(msg.height) || v.height);
2597
+ v.width = dims.width;
2598
+ v.height = dims.height;
2599
+ if (v.viewId === "main") {
2600
+ this.width = dims.width;
2601
+ this.height = dims.height;
2602
+ }
2603
+ this.resizeViewCapture(v, dims.width, dims.height);
2604
+ for (const sub of v.subscribers) {
2605
+ sub.onEvent({ type: "view_geometry", width: dims.width, height: dims.height });
2606
+ }
2607
+ return;
2608
+ }
2609
+ if (msg.type === "view_maximize" && typeof msg.view === "string") {
2610
+ const v = this.views.get(msg.view);
2611
+ if (!v) return;
2612
+ for (const sub of v.subscribers) {
2613
+ sub.onEvent({ type: "view_maximize" });
2614
+ }
2615
+ return;
2616
+ }
2617
+ if (msg.type === "view_closed" && typeof msg.view === "string") {
2618
+ const v = this.views.get(msg.view);
2619
+ if (!v) return;
2620
+ for (const sub of v.subscribers) {
2621
+ sub.onEvent({ type: "app_exit", code: 0 });
2622
+ }
2623
+ this.destroyView(v);
2624
+ return;
2625
+ }
2626
+ if (msg.type === "all_windows_closed") {
2627
+ for (const v of this.views.values()) {
2628
+ for (const sub of v.subscribers) {
2629
+ sub.onEvent({ type: "app_exit", code: 0 });
2630
+ }
2631
+ }
2632
+ this.close();
2633
+ return;
2634
+ }
2635
+ const hostView = this.getEventHostView();
2636
+ if (hostView) {
2637
+ for (const sub of hostView.subscribers) {
2638
+ sub.onEvent(msg);
2639
+ }
2640
+ }
2641
+ }
2642
+ getProfileDir() {
2508
2643
  const profileDir = path6.join(
2509
2644
  this.desktopDataRoot,
2510
2645
  "app-profiles",
2511
2646
  this.appId.replace(/[^a-z0-9_-]/gi, "_")
2512
2647
  );
2513
2648
  fs6.mkdirSync(profileDir, { recursive: true });
2649
+ return profileDir;
2650
+ }
2651
+ buildLaunchCommand(extraNewWindow = false) {
2652
+ const profileDir = this.getProfileDir();
2514
2653
  const desktopFilesDir = path6.join(this.desktopDataRoot, "vfs", "Desktop");
2515
2654
  fs6.mkdirSync(desktopFilesDir, { recursive: true });
2516
2655
  const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
@@ -2534,6 +2673,8 @@ var LinuxAppSession = class {
2534
2673
  'user_pref("toolkit.cosmeticAnimations.enabled", false);',
2535
2674
  'user_pref("ui.prefersReducedMotion", 1);',
2536
2675
  'user_pref("dom.ipc.processCount", 2);',
2676
+ 'user_pref("dom.disable_window_move_resize", false);',
2677
+ 'user_pref("browser.link.open_newwindow.restriction", 0);',
2537
2678
  'user_pref("browser.sessionstore.interval", 60000);',
2538
2679
  'user_pref("browser.newtabpage.activity-stream.feeds.topsites", false);',
2539
2680
  'user_pref("browser.newtabpage.activity-stream.feeds.section.topstories", false);',
@@ -2544,7 +2685,7 @@ var LinuxAppSession = class {
2544
2685
  ].join("\n") + "\n",
2545
2686
  "utf-8"
2546
2687
  );
2547
- finalCmd = `${finalCmd} --no-remote -profile "${profileDir}" --width=${this.width} --height=${this.height}`;
2688
+ finalCmd = extraNewWindow ? `${finalCmd} -profile "${profileDir}" --new-window about:home` : `${finalCmd} -profile "${profileDir}" --width=${this.width} --height=${this.height}`;
2548
2689
  } else if (this.needsNoSandbox || ["code", "antigravity", "chromium", "chromium-browser", "google-chrome", "google-chrome-stable"].includes(baseBin)) {
2549
2690
  const extraFlags = [];
2550
2691
  if (isRoot && !finalCmd.includes("--no-sandbox")) {
@@ -2559,10 +2700,19 @@ var LinuxAppSession = class {
2559
2700
  if ((baseBin === "code" || baseBin === "antigravity") && !finalCmd.includes("--verbose")) {
2560
2701
  extraFlags.push("--verbose");
2561
2702
  }
2703
+ if (extraNewWindow && !finalCmd.includes("--new-window")) {
2704
+ extraFlags.push("--new-window");
2705
+ }
2562
2706
  finalCmd = `${finalCmd} ${extraFlags.join(" ")}`;
2707
+ } else if (extraNewWindow && baseBin === "gimp") {
2708
+ finalCmd = `${finalCmd} -n`;
2563
2709
  }
2564
- this.appProc = spawn3("/bin/bash", ["-c", `exec ${finalCmd}`], {
2565
- cwd: desktopFilesDir,
2710
+ return { cmd: finalCmd, cwd: desktopFilesDir };
2711
+ }
2712
+ launchTargetApp(baseEnv) {
2713
+ const { cmd, cwd } = this.buildLaunchCommand(false);
2714
+ this.appProc = spawn3("/bin/bash", ["-c", `exec ${cmd}`], {
2715
+ cwd,
2566
2716
  env: {
2567
2717
  ...baseEnv,
2568
2718
  HOME: baseEnv.HOME || os4.homedir(),
@@ -2576,7 +2726,7 @@ var LinuxAppSession = class {
2576
2726
  setTimeout(() => {
2577
2727
  if (this.closed) return;
2578
2728
  try {
2579
- const out = execSync2(`wmctrl -l`, {
2729
+ const out = execSync2("wmctrl -l", {
2580
2730
  env: { ...process.env, DISPLAY: this.displayStr },
2581
2731
  stdio: ["ignore", "pipe", "ignore"],
2582
2732
  timeout: 1200
@@ -2588,16 +2738,40 @@ var LinuxAppSession = class {
2588
2738
  } catch {
2589
2739
  }
2590
2740
  if (!this.hadWindow || code !== 0) {
2591
- for (const sub of this.subscribers) {
2592
- sub.onEvent({ type: "app_exit", code: code ?? 0 });
2741
+ for (const v of this.views.values()) {
2742
+ for (const sub of v.subscribers) {
2743
+ sub.onEvent({ type: "app_exit", code: code ?? 0 });
2744
+ }
2593
2745
  }
2594
2746
  this.close();
2595
2747
  }
2596
2748
  }, 1500);
2597
2749
  });
2598
2750
  }
2599
- startXDamageStreamer(baseEnv) {
2600
- this.streamerMode = "xdamage";
2751
+ spawnExtraWindow(customCommand) {
2752
+ if (this.closed) return;
2753
+ const { cmd, cwd } = customCommand ? { cmd: customCommand, cwd: path6.join(this.desktopDataRoot, "vfs", "Desktop") } : this.buildLaunchCommand(true);
2754
+ const child = spawn3("/bin/bash", ["-c", cmd], {
2755
+ cwd,
2756
+ detached: true,
2757
+ env: {
2758
+ ...this.baseEnv,
2759
+ HOME: this.baseEnv.HOME || os4.homedir(),
2760
+ DONT_PROMPT_WSL_INSTALL: "1"
2761
+ },
2762
+ stdio: "ignore"
2763
+ });
2764
+ child.unref();
2765
+ }
2766
+ startViewStreamer(view) {
2767
+ if (hasTurboJpegAndXDamage()) {
2768
+ this.startViewXDamageStreamer(view);
2769
+ } else {
2770
+ this.startViewFfmpegCapture(view);
2771
+ }
2772
+ }
2773
+ startViewXDamageStreamer(view) {
2774
+ view.streamerMode = "xdamage";
2601
2775
  const scriptPath = resolveHelperPath("x11_streamer.py");
2602
2776
  const jpegQual = Math.max(60, Math.min(88, 92 - this.quality * 4));
2603
2777
  const proc = spawn3(
@@ -2606,20 +2780,22 @@ var LinuxAppSession = class {
2606
2780
  "-u",
2607
2781
  scriptPath,
2608
2782
  this.displayStr,
2609
- String(this.width),
2610
- String(this.height),
2783
+ String(view.width),
2784
+ String(view.height),
2611
2785
  String(this.fps),
2612
- String(jpegQual)
2786
+ String(jpegQual),
2787
+ String(view.offsetX),
2788
+ String(view.offsetY)
2613
2789
  ],
2614
2790
  {
2615
- env: baseEnv,
2791
+ env: this.baseEnv,
2616
2792
  stdio: ["pipe", "pipe", "ignore"]
2617
2793
  }
2618
2794
  );
2619
- this.streamerProc = proc;
2795
+ view.streamerProc = proc;
2620
2796
  let acc = Buffer.alloc(0);
2621
2797
  proc.stdout?.on("data", (chunk) => {
2622
- if (this.closed) return;
2798
+ if (this.closed || !this.views.has(view.viewId)) return;
2623
2799
  acc = Buffer.concat([acc, chunk]);
2624
2800
  while (acc.length >= 4) {
2625
2801
  const frameLen = acc.readUInt32BE(0);
@@ -2632,8 +2808,8 @@ var LinuxAppSession = class {
2632
2808
  }
2633
2809
  const frame = Buffer.from(acc.subarray(4, 4 + frameLen));
2634
2810
  acc = acc.subarray(4 + frameLen);
2635
- this.lastFrame = frame;
2636
- if (this.subscribers.size === 0) {
2811
+ view.lastFrame = frame;
2812
+ if (view.subscribers.size === 0) {
2637
2813
  if (proc.stdin?.writable) proc.stdin.write("a\n");
2638
2814
  continue;
2639
2815
  }
@@ -2646,27 +2822,27 @@ var LinuxAppSession = class {
2646
2822
  }
2647
2823
  }
2648
2824
  };
2649
- for (const sub of this.subscribers) {
2825
+ for (const sub of view.subscribers) {
2650
2826
  sub.onVideoFrame(frame, sendAckOnce);
2651
2827
  }
2652
2828
  setTimeout(sendAckOnce, 180).unref();
2653
2829
  }
2654
2830
  });
2655
2831
  proc.on("exit", (code) => {
2656
- if (!this.closed && code !== 0) {
2657
- this.startFfmpegFallbackCapture();
2832
+ if (!this.closed && this.views.has(view.viewId) && code !== 0 && view.streamerProc === proc) {
2833
+ this.startViewFfmpegCapture(view);
2658
2834
  }
2659
2835
  });
2660
2836
  }
2661
- startFfmpegFallbackCapture() {
2662
- if (this.closed) return;
2663
- this.streamerMode = "ffmpeg";
2664
- if (this.streamerProc) {
2837
+ startViewFfmpegCapture(view) {
2838
+ if (this.closed || !this.views.has(view.viewId)) return;
2839
+ view.streamerMode = "ffmpeg";
2840
+ if (view.streamerProc) {
2665
2841
  try {
2666
- this.streamerProc.kill("SIGTERM");
2842
+ view.streamerProc.kill("SIGTERM");
2667
2843
  } catch {
2668
2844
  }
2669
- this.streamerProc = null;
2845
+ view.streamerProc = null;
2670
2846
  }
2671
2847
  const args = [
2672
2848
  "-loglevel",
@@ -2680,11 +2856,11 @@ var LinuxAppSession = class {
2680
2856
  "-draw_mouse",
2681
2857
  "0",
2682
2858
  "-video_size",
2683
- `${this.width}x${this.height}`,
2859
+ `${view.width}x${view.height}`,
2684
2860
  "-framerate",
2685
2861
  String(Math.min(15, this.fps)),
2686
2862
  "-i",
2687
- `${this.displayStr}.0+0,0`,
2863
+ `${this.displayStr}.0+${view.offsetX},${view.offsetY}`,
2688
2864
  "-f",
2689
2865
  "image2pipe",
2690
2866
  "-vcodec",
@@ -2696,12 +2872,12 @@ var LinuxAppSession = class {
2696
2872
  "-"
2697
2873
  ];
2698
2874
  const ff = spawn3("ffmpeg", args, { stdio: ["ignore", "pipe", "ignore"] });
2699
- this.streamerProc = ff;
2875
+ view.streamerProc = ff;
2700
2876
  let acc = Buffer.alloc(0);
2701
2877
  const SOI = Buffer.from([255, 216]);
2702
2878
  const EOI = Buffer.from([255, 217]);
2703
2879
  ff.stdout?.on("data", (chunk) => {
2704
- if (this.closed) return;
2880
+ if (this.closed || !this.views.has(view.viewId)) return;
2705
2881
  acc = Buffer.concat([acc, chunk]);
2706
2882
  if (acc.length > 4 * 1024 * 1024) {
2707
2883
  acc = acc.subarray(acc.length - 512 * 1024);
@@ -2719,63 +2895,99 @@ var LinuxAppSession = class {
2719
2895
  }
2720
2896
  const frame = Buffer.from(acc.subarray(start, end + 2));
2721
2897
  acc = acc.subarray(end + 2);
2722
- if (this.lastFrame && this.lastFrame.length === frame.length && this.lastFrame.equals(frame)) {
2898
+ if (view.lastFrame && view.lastFrame.length === frame.length && view.lastFrame.equals(frame)) {
2723
2899
  continue;
2724
2900
  }
2725
- this.lastFrame = frame;
2726
- for (const sub of this.subscribers) {
2901
+ view.lastFrame = frame;
2902
+ for (const sub of view.subscribers) {
2727
2903
  sub.onVideoFrame(frame);
2728
2904
  }
2729
2905
  }
2730
2906
  });
2731
2907
  }
2732
- subscribe(sub) {
2733
- this.subscribers.add(sub);
2734
- sub.onEvent({ type: "title", title: this.title });
2908
+ resizeViewCapture(view, evenW, evenH) {
2909
+ if (view.streamerMode === "xdamage" && view.streamerProc?.stdin?.writable) {
2910
+ view.streamerProc.stdin.write(
2911
+ JSON.stringify({ type: "resize", width: evenW, height: evenH }) + "\n"
2912
+ );
2913
+ return;
2914
+ }
2915
+ if (view.resizeTimer) clearTimeout(view.resizeTimer);
2916
+ view.resizeTimer = setTimeout(() => {
2917
+ if (!this.closed && this.views.has(view.viewId) && view.streamerMode === "ffmpeg") {
2918
+ view.lastFrame = null;
2919
+ this.startViewFfmpegCapture(view);
2920
+ }
2921
+ }, 160);
2922
+ }
2923
+ destroyView(view) {
2924
+ this.views.delete(view.viewId);
2925
+ if (view.resizeTimer) clearTimeout(view.resizeTimer);
2926
+ if (view.streamerProc) {
2927
+ try {
2928
+ view.streamerProc.kill("SIGTERM");
2929
+ } catch {
2930
+ }
2931
+ view.streamerProc = null;
2932
+ }
2933
+ view.subscribers.clear();
2934
+ }
2935
+ subscribeView(viewId, sub) {
2936
+ const view = this.views.get(viewId || "main") || this.views.get("main");
2937
+ if (!view) {
2938
+ sub.onEvent({ type: "app_exit", code: 0 });
2939
+ return () => {
2940
+ };
2941
+ }
2942
+ view.subscribers.add(sub);
2943
+ sub.onEvent({ type: "title", title: view.title });
2735
2944
  sub.onEvent({ type: "cursor", cursor: this.cursor });
2736
- if (this.lastFrame) {
2737
- sub.onVideoFrame(this.lastFrame);
2738
- } else if (this.streamerMode === "xdamage" && this.streamerProc?.stdin?.writable) {
2739
- this.streamerProc.stdin.write(JSON.stringify({ type: "refresh" }) + "\n");
2945
+ if (view.lastFrame) {
2946
+ sub.onVideoFrame(view.lastFrame);
2947
+ } else if (view.streamerMode === "xdamage" && view.streamerProc?.stdin?.writable) {
2948
+ view.streamerProc.stdin.write(JSON.stringify({ type: "refresh" }) + "\n");
2740
2949
  }
2741
2950
  return () => {
2742
- this.subscribers.delete(sub);
2951
+ view.subscribers.delete(sub);
2743
2952
  };
2744
2953
  }
2745
- sendInput(msg) {
2954
+ sendInput(msg, viewId = "main") {
2746
2955
  if (this.closed || !this.x11BridgeProc?.stdin?.writable) return;
2747
- this.x11BridgeProc.stdin.write(JSON.stringify(msg) + "\n");
2956
+ this.x11BridgeProc.stdin.write(JSON.stringify({ ...msg, view: msg.view || viewId }) + "\n");
2748
2957
  }
2749
- resize(width, height) {
2958
+ resizeView(viewId, width, height) {
2750
2959
  if (this.closed) return;
2751
- const w = Math.max(420, Math.min(1920, Math.round(width)));
2752
- const h = Math.max(300, Math.min(1080, Math.round(height)));
2753
- const evenW = w - w % 2;
2754
- const evenH = h - h % 2;
2755
- if (Math.abs(evenW - this.width) < 4 && Math.abs(evenH - this.height) < 4) return;
2756
- this.width = evenW;
2757
- this.height = evenH;
2758
- this.sendInput({ type: "resize", width: evenW, height: evenH });
2759
- if (this.streamerMode === "xdamage" && this.streamerProc?.stdin?.writable) {
2760
- this.streamerProc.stdin.write(
2761
- JSON.stringify({ type: "resize", width: evenW, height: evenH }) + "\n"
2762
- );
2960
+ const view = this.views.get(viewId || "main");
2961
+ if (!view) return;
2962
+ const dims = clampDim(width, height);
2963
+ if (Math.abs(dims.width - view.width) < 4 && Math.abs(dims.height - view.height) < 4) return;
2964
+ view.width = dims.width;
2965
+ view.height = dims.height;
2966
+ if (view.viewId === "main") {
2967
+ this.width = dims.width;
2968
+ this.height = dims.height;
2969
+ }
2970
+ this.sendInput({ type: "resize", width: dims.width, height: dims.height }, view.viewId);
2971
+ this.resizeViewCapture(view, dims.width, dims.height);
2972
+ }
2973
+ focusView(viewId) {
2974
+ this.sendInput({ type: "focus_view" }, viewId || "main");
2975
+ }
2976
+ closeView(viewId) {
2977
+ if (this.closed) return;
2978
+ if (!viewId || this.views.size <= 1) {
2979
+ this.close();
2763
2980
  return;
2764
2981
  }
2765
- if (this.resizeTimer) clearTimeout(this.resizeTimer);
2766
- this.resizeTimer = setTimeout(() => {
2767
- if (!this.closed && this.streamerMode === "ffmpeg") {
2768
- this.lastFrame = null;
2769
- this.startFfmpegFallbackCapture();
2770
- }
2771
- }, 160);
2982
+ this.sendInput({ type: "close_view" }, viewId);
2772
2983
  }
2773
2984
  close() {
2774
2985
  if (this.closed) return;
2775
2986
  this.closed = true;
2776
- if (this.resizeTimer) clearTimeout(this.resizeTimer);
2987
+ for (const v of Array.from(this.views.values())) {
2988
+ this.destroyView(v);
2989
+ }
2777
2990
  const procs = [
2778
- this.streamerProc,
2779
2991
  this.parecProc,
2780
2992
  this.x11BridgeProc,
2781
2993
  this.appProc,
@@ -2813,16 +3025,35 @@ var LinuxAppSession = class {
2813
3025
  } catch {
2814
3026
  }
2815
3027
  }
2816
- this.subscribers.clear();
2817
3028
  this.onCloseCb();
2818
3029
  }
2819
3030
  };
2820
3031
  var LinuxDisplayBridge = class {
2821
3032
  sessions = /* @__PURE__ */ new Map();
2822
3033
  usedDisplays = /* @__PURE__ */ new Set();
3034
+ findActiveProfileSession(desktopId, appId, command) {
3035
+ const baseBin = path6.basename(command.split(/\s+/)[0] || "");
3036
+ const isLocked = PROFILE_LOCKED_APPS.has(appId) || PROFILE_LOCKED_APPS.has(baseBin);
3037
+ if (!isLocked) return void 0;
3038
+ for (const s of this.sessions.values()) {
3039
+ if (s.desktopId === desktopId && (s.appId === appId || path6.basename(s.appId) === baseBin)) {
3040
+ return s;
3041
+ }
3042
+ }
3043
+ return void 0;
3044
+ }
2823
3045
  async launchApp(opts) {
2824
- const existing = this.sessions.get(opts.sessionId);
2825
- if (existing) return existing;
3046
+ const existingById = this.sessions.get(opts.sessionId);
3047
+ if (existingById) return { session: existingById, openedAsExtraWindow: false };
3048
+ const existingProfileSession = this.findActiveProfileSession(
3049
+ opts.desktopId,
3050
+ opts.appId,
3051
+ opts.command
3052
+ );
3053
+ if (existingProfileSession) {
3054
+ existingProfileSession.spawnExtraWindow();
3055
+ return { session: existingProfileSession, openedAsExtraWindow: true };
3056
+ }
2826
3057
  const displayNum = findFreeDisplay(this.usedDisplays);
2827
3058
  this.usedDisplays.add(displayNum);
2828
3059
  const session = new LinuxAppSession(opts, displayNum, () => {
@@ -2831,7 +3062,7 @@ var LinuxDisplayBridge = class {
2831
3062
  });
2832
3063
  this.sessions.set(opts.sessionId, session);
2833
3064
  await session.start();
2834
- return session;
3065
+ return { session, openedAsExtraWindow: false };
2835
3066
  }
2836
3067
  getSession(sessionId) {
2837
3068
  return this.sessions.get(sessionId);
@@ -2847,9 +3078,14 @@ var LinuxDisplayBridge = class {
2847
3078
  height: s.height
2848
3079
  }));
2849
3080
  }
2850
- closeSession(sessionId) {
3081
+ closeSession(sessionId, viewId) {
2851
3082
  const s = this.sessions.get(sessionId);
2852
- if (s) s.close();
3083
+ if (!s) return;
3084
+ if (viewId) {
3085
+ s.closeView(viewId);
3086
+ } else {
3087
+ s.close();
3088
+ }
2853
3089
  }
2854
3090
  destroyDesktopSessions(desktopId) {
2855
3091
  for (const s of Array.from(this.sessions.values())) {
@@ -3018,12 +3254,38 @@ var VSCodeServerManager = class {
3018
3254
  });
3019
3255
  });
3020
3256
  }
3257
+ patchWorkbenchHtml(html, tamgaTheme) {
3258
+ return html.replace(
3259
+ /(<meta\s+id=["']vscode-workbench-web-configuration["']\s+data-settings=["'])([^"']+)(["'])/i,
3260
+ (full, prefix, encoded, suffix) => {
3261
+ try {
3262
+ const decoded = encoded.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
3263
+ const cfg = JSON.parse(decoded);
3264
+ cfg.enableWorkspaceTrust = false;
3265
+ const prevDefaults = typeof cfg.configurationDefaults === "object" && cfg.configurationDefaults ? cfg.configurationDefaults : {};
3266
+ cfg.configurationDefaults = {
3267
+ ...prevDefaults,
3268
+ "security.workspace.trust.enabled": false,
3269
+ "workbench.startupEditor": "none",
3270
+ "window.confirmBeforeClose": "never",
3271
+ "window.autoDetectColorScheme": false,
3272
+ "workbench.colorTheme": tamgaTheme === "light" ? "Default Light Modern" : "Default Dark Modern"
3273
+ };
3274
+ const reEncoded = JSON.stringify(cfg).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
3275
+ return `${prefix}${reEncoded}${suffix}`;
3276
+ } catch {
3277
+ return full;
3278
+ }
3279
+ }
3280
+ );
3281
+ }
3021
3282
  proxyHttp = (req, res) => {
3022
3283
  if (!this.ready) {
3023
3284
  res.status(503).send("VS Code haz\u0131rlan\u0131yor...");
3024
3285
  return;
3025
3286
  }
3026
3287
  const acceptGzip = String(req.headers["accept-encoding"] || "").includes("gzip");
3288
+ const tamgaTheme = String(req.query?.tamgaTheme || "dark");
3027
3289
  const headers = { ...req.headers };
3028
3290
  const upstream = http.request(
3029
3291
  {
@@ -3047,6 +3309,31 @@ var VSCodeServerManager = class {
3047
3309
  );
3048
3310
  }
3049
3311
  const ctype = String(outHeaders["content-type"] || "").toLowerCase();
3312
+ if (req.method !== "HEAD" && ctype.includes("text/html") && !outHeaders["content-encoding"]) {
3313
+ const chunks = [];
3314
+ upRes.on("data", (chunk) => chunks.push(chunk));
3315
+ upRes.on("end", () => {
3316
+ const rawHtml = Buffer.concat(chunks).toString("utf-8");
3317
+ const patched = Buffer.from(this.patchWorkbenchHtml(rawHtml, tamgaTheme), "utf-8");
3318
+ if (acceptGzip) {
3319
+ delete outHeaders["content-length"];
3320
+ outHeaders["content-encoding"] = "gzip";
3321
+ res.writeHead(upRes.statusCode || 200, outHeaders);
3322
+ zlib.gzip(patched, { level: 1 }, (err, gzBuf) => {
3323
+ if (err) res.end(patched);
3324
+ else res.end(gzBuf);
3325
+ });
3326
+ } else {
3327
+ outHeaders["content-length"] = String(patched.length);
3328
+ res.writeHead(upRes.statusCode || 200, outHeaders);
3329
+ res.end(patched);
3330
+ }
3331
+ });
3332
+ upRes.on("error", () => {
3333
+ if (!res.headersSent) res.status(502).end("VS Code yan\u0131t hatas\u0131");
3334
+ });
3335
+ return;
3336
+ }
3050
3337
  const shouldGzip = acceptGzip && req.method !== "HEAD" && !outHeaders["content-encoding"] && /(javascript|css|json|html|svg|wasm|xml|text\/plain)/.test(ctype);
3051
3338
  if (shouldGzip) {
3052
3339
  delete outHeaders["content-length"];
@@ -3102,7 +3389,7 @@ var VSCodeServerManager = class {
3102
3389
  };
3103
3390
 
3104
3391
  // server/index.ts
3105
- var TAMGA_VERSION = "1.1.2";
3392
+ var TAMGA_VERSION = "1.1.4";
3106
3393
  var MIME_MAP = {
3107
3394
  html: "text/html; charset=utf-8",
3108
3395
  htm: "text/html; charset=utf-8",
@@ -3353,7 +3640,7 @@ async function startTamgaServer(opts = {}) {
3353
3640
  return;
3354
3641
  }
3355
3642
  const sessionId = String(req.body?.sessionId || "") || `app-${appId}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
3356
- const session = await linuxDisplayBridge.launchApp({
3643
+ const { session, openedAsExtraWindow } = await linuxDisplayBridge.launchApp({
3357
3644
  sessionId,
3358
3645
  desktopId,
3359
3646
  appId,
@@ -3373,7 +3660,8 @@ async function startTamgaServer(opts = {}) {
3373
3660
  appName: session.appName,
3374
3661
  title: session.title,
3375
3662
  width: session.width,
3376
- height: session.height
3663
+ height: session.height,
3664
+ openedAsExtraWindow
3377
3665
  });
3378
3666
  } catch (e) {
3379
3667
  res.status(400).json({ error: e.message });
@@ -3381,7 +3669,8 @@ async function startTamgaServer(opts = {}) {
3381
3669
  });
3382
3670
  app.post("/api/apps/close", (req, res) => {
3383
3671
  const sessionId = String(req.body?.sessionId || "");
3384
- if (sessionId) linuxDisplayBridge.closeSession(sessionId);
3672
+ const viewId = req.body?.viewId ? String(req.body.viewId) : void 0;
3673
+ if (sessionId) linuxDisplayBridge.closeSession(sessionId, viewId);
3385
3674
  res.json({ ok: true });
3386
3675
  });
3387
3676
  app.post("/api/apps/install", (req, res) => {
@@ -3415,10 +3704,11 @@ async function startTamgaServer(opts = {}) {
3415
3704
  const { vfs } = getDesktopContext(desktopId);
3416
3705
  await vscodeManager.ensureStarted();
3417
3706
  const targetVPath = String(req.body?.folderPath || "/Projects");
3707
+ const theme = req.body?.theme === "light" ? "light" : "dark";
3418
3708
  const diskFolder = vfs.resolveDiskPath(targetVPath);
3419
3709
  fs8.mkdirSync(diskFolder, { recursive: true });
3420
3710
  res.json({
3421
- url: `/vscode-web/?folder=${encodeURIComponent(diskFolder)}`
3711
+ url: `/vscode-web/?folder=${encodeURIComponent(diskFolder)}&tamgaTheme=${theme}`
3422
3712
  });
3423
3713
  } catch (e) {
3424
3714
  res.status(400).json({ error: e.message });
@@ -3832,13 +4122,14 @@ async function startTamgaServer(opts = {}) {
3832
4122
  appWss.on("connection", (ws, req) => {
3833
4123
  const reqUrl = new URL(req.url || "/ws/app", "http://localhost");
3834
4124
  const sessionId = reqUrl.searchParams.get("sessionId") || "";
4125
+ const viewId = reqUrl.searchParams.get("view") || "main";
3835
4126
  const session = linuxDisplayBridge.getSession(sessionId);
3836
4127
  if (!session) {
3837
4128
  sendJson(ws, { type: "error", message: "Uygulama oturumu bulunamad\u0131." });
3838
4129
  ws.close();
3839
4130
  return;
3840
4131
  }
3841
- const unsub = session.subscribe({
4132
+ const unsub = session.subscribeView(viewId, {
3842
4133
  onVideoFrame: (jpeg, done) => {
3843
4134
  const pkt = Buffer.allocUnsafe(1 + jpeg.length);
3844
4135
  pkt[0] = PACKET_VIDEO_JPEG;
@@ -3857,9 +4148,11 @@ async function startTamgaServer(opts = {}) {
3857
4148
  try {
3858
4149
  const msg = JSON.parse(raw.toString("utf-8"));
3859
4150
  if (msg.type === "resize") {
3860
- session.resize(Number(msg.width), Number(msg.height));
4151
+ session.resizeView(viewId, Number(msg.width), Number(msg.height));
4152
+ } else if (msg.type === "focus") {
4153
+ session.focusView(viewId);
3861
4154
  } else {
3862
- session.sendInput(msg);
4155
+ session.sendInput(msg, viewId);
3863
4156
  }
3864
4157
  } catch {
3865
4158
  }