tamga-vdesktop 1.1.7 → 1.2.0

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
@@ -5,7 +5,7 @@ import fs9 from "node:fs";
5
5
  import os6 from "node:os";
6
6
  import path9 from "node:path";
7
7
  import readline from "node:readline";
8
- import { execSync as execSync4, spawnSync } from "node:child_process";
8
+ import { execSync as execSync4, spawnSync as spawnSync2 } from "node:child_process";
9
9
 
10
10
  // server/config.ts
11
11
  import fs from "node:fs";
@@ -448,1573 +448,1792 @@ apt-get update -y && apt-get install -y ${cleanPkg}`;
448
448
  }
449
449
  };
450
450
 
451
- // server/index.ts
452
- import express from "express";
453
- import cors from "cors";
454
- import http2 from "node:http";
455
- import os5 from "node:os";
456
- import path8 from "node:path";
457
- import fs8 from "node:fs";
458
- import { fileURLToPath as fileURLToPath2 } from "node:url";
459
- import multer from "multer";
460
- import { WebSocketServer, WebSocket } from "ws";
461
-
462
- // server/vfsManager.ts
451
+ // server/chromiumManager.ts
463
452
  import fs3 from "node:fs";
453
+ import os3 from "node:os";
464
454
  import path3 from "node:path";
465
- import AdmZip from "adm-zip";
466
- var STORAGE_ROOT = path3.resolve(process.cwd(), "storage");
467
- var DESKTOPS_ROOT = path3.join(STORAGE_ROOT, "desktops");
468
- var REGISTRY_FILE = path3.join(DESKTOPS_ROOT, "registry.json");
469
- function setStorageRoot(dir) {
470
- STORAGE_ROOT = path3.resolve(dir);
471
- DESKTOPS_ROOT = path3.join(STORAGE_ROOT, "desktops");
472
- REGISTRY_FILE = path3.join(DESKTOPS_ROOT, "registry.json");
473
- fs3.mkdirSync(DESKTOPS_ROOT, { recursive: true });
474
- }
475
- var SYSTEM_DIRS = ["/Desktop", "/Documents", "/Downloads", "/Projects", "/.trash"];
476
- function sanitizeDesktopId(raw) {
477
- const cleaned = (raw || "main").toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 40);
478
- return cleaned || "main";
479
- }
480
- function extractExtension(name, isDir) {
481
- if (isDir) return "";
482
- const lower = name.toLowerCase();
483
- if (lower.endsWith(".tar.gz")) return "tar.gz";
484
- if (lower.startsWith(".") && !lower.slice(1).includes(".")) {
485
- return lower.slice(1);
455
+ import { spawn as spawn2, spawnSync } from "node:child_process";
456
+ import { createRequire } from "node:module";
457
+ var require2 = createRequire(import.meta.url);
458
+ async function loadPlaywrightChromium() {
459
+ try {
460
+ const pw = await import("playwright-core");
461
+ return pw.chromium;
462
+ } catch {
463
+ throw new Error("Yerle\u015Fik Playwright Chromium y\xFCkl\xFC de\u011Fil.");
486
464
  }
487
- const idx = lower.lastIndexOf(".");
488
- if (idx <= 0 || idx === lower.length - 1) return "";
489
- return lower.slice(idx + 1);
490
465
  }
491
- var DesktopRegistry = class {
492
- desktops = [];
493
- constructor() {
494
- fs3.mkdirSync(DESKTOPS_ROOT, { recursive: true });
495
- this.migrateLegacyIfPresent();
496
- this.load();
497
- }
498
- migrateLegacyIfPresent() {
499
- const legacyVfs = path3.join(STORAGE_ROOT, "vfs");
500
- const mainDir = path3.join(DESKTOPS_ROOT, "main");
501
- if (fs3.existsSync(legacyVfs) && !fs3.existsSync(mainDir)) {
502
- fs3.mkdirSync(mainDir, { recursive: true });
503
- fs3.cpSync(legacyVfs, path3.join(mainDir, "vfs"), { recursive: true });
504
- const legacyMeta = path3.join(STORAGE_ROOT, "meta.json");
505
- if (fs3.existsSync(legacyMeta)) {
506
- fs3.cpSync(legacyMeta, path3.join(mainDir, "meta.json"));
507
- }
508
- fs3.writeFileSync(path3.join(mainDir, ".seeded"), (/* @__PURE__ */ new Date()).toISOString(), "utf-8");
466
+ var PACKET_VIDEO_JPEG = 1;
467
+ var PACKET_AUDIO_PCM = 2;
468
+ function collectPlaywrightRoots() {
469
+ const home = os3.homedir();
470
+ return Array.from(
471
+ new Set(
472
+ [
473
+ process.env.PLAYWRIGHT_BROWSERS_PATH || "",
474
+ path3.join(home, "Library", "Caches", "ms-playwright"),
475
+ path3.join(home, ".cache", "ms-playwright"),
476
+ "/root/.cache/ms-playwright",
477
+ "/var/cache/tamga-playwright",
478
+ process.env.LOCALAPPDATA ? path3.join(process.env.LOCALAPPDATA, "ms-playwright") : ""
479
+ ].filter(Boolean)
480
+ )
481
+ );
482
+ }
483
+ function findChromiumExecutable(chromiumRef) {
484
+ try {
485
+ const defaultPath = chromiumRef?.executablePath();
486
+ if (defaultPath && fs3.existsSync(defaultPath)) {
487
+ return defaultPath;
509
488
  }
489
+ } catch {
510
490
  }
511
- load() {
512
- if (fs3.existsSync(REGISTRY_FILE)) {
513
- try {
514
- const parsed = JSON.parse(fs3.readFileSync(REGISTRY_FILE, "utf-8"));
515
- if (Array.isArray(parsed) && parsed.length > 0) {
516
- this.desktops = parsed;
517
- return;
518
- }
519
- } catch {
491
+ for (const root of collectPlaywrightRoots()) {
492
+ if (!fs3.existsSync(root)) continue;
493
+ let entries = [];
494
+ try {
495
+ entries = fs3.readdirSync(root);
496
+ } catch {
497
+ continue;
498
+ }
499
+ const shellDirs = entries.filter((d) => d.startsWith("chromium_headless_shell-")).sort().reverse();
500
+ for (const dir of shellDirs) {
501
+ const shellCandidates = [
502
+ path3.join(root, dir, "chrome-headless-shell-linux64", "chrome-headless-shell"),
503
+ path3.join(root, dir, "chrome-linux", "headless_shell"),
504
+ path3.join(root, dir, "chrome-headless-shell-mac-arm64", "chrome-headless-shell"),
505
+ path3.join(root, dir, "chrome-headless-shell-mac-x64", "chrome-headless-shell"),
506
+ path3.join(root, dir, "chrome-mac", "headless_shell"),
507
+ path3.join(root, dir, "chrome-mac-arm64", "headless_shell"),
508
+ path3.join(root, dir, "chrome-headless-shell-win64", "chrome-headless-shell.exe"),
509
+ path3.join(root, dir, "chrome-win", "headless_shell.exe")
510
+ ];
511
+ for (const candidate of shellCandidates) {
512
+ if (fs3.existsSync(candidate)) return candidate;
520
513
  }
521
514
  }
522
- this.desktops = [
523
- {
524
- id: "main",
525
- name: "Masa\xFCst\xFC 1",
526
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
515
+ const fullDirs = entries.filter((d) => d.startsWith("chromium-")).sort().reverse();
516
+ for (const dir of fullDirs) {
517
+ const fullCandidates = [
518
+ path3.join(root, dir, "chrome-mac-arm64", "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
519
+ path3.join(root, dir, "chrome-mac", "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
520
+ path3.join(root, dir, "chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium"),
521
+ path3.join(root, dir, "chrome-mac-arm64", "Chromium.app", "Contents", "MacOS", "Chromium"),
522
+ path3.join(root, dir, "chrome-linux", "chrome"),
523
+ path3.join(root, dir, "chrome-linux64", "chrome"),
524
+ path3.join(root, dir, "chrome-win", "chrome.exe")
525
+ ];
526
+ for (const candidate of fullCandidates) {
527
+ if (fs3.existsSync(candidate)) return candidate;
527
528
  }
528
- ];
529
- this.save();
530
- }
531
- save() {
532
- fs3.mkdirSync(DESKTOPS_ROOT, { recursive: true });
533
- fs3.writeFileSync(REGISTRY_FILE, JSON.stringify(this.desktops, null, 2), "utf-8");
529
+ }
534
530
  }
535
- list() {
536
- return [...this.desktops];
531
+ const systemCandidates = [
532
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
533
+ "/Applications/Chromium.app/Contents/MacOS/Chromium",
534
+ "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
535
+ "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
536
+ "/usr/bin/chromium",
537
+ "/usr/bin/chromium-browser",
538
+ "/usr/bin/google-chrome-stable",
539
+ "/usr/bin/google-chrome"
540
+ ];
541
+ for (const candidate of systemCandidates) {
542
+ if (fs3.existsSync(candidate)) return candidate;
537
543
  }
538
- ensureDesktop(rawId, desiredName) {
539
- const id = sanitizeDesktopId(rawId);
540
- const existing = this.desktops.find((d) => d.id === id);
541
- if (existing) return existing;
542
- const info = {
543
- id,
544
- name: desiredName?.trim() || `Masa\xFCst\xFC ${this.desktops.length + 1}`,
545
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
546
- };
547
- this.desktops.push(info);
548
- this.save();
549
- return info;
544
+ return void 0;
545
+ }
546
+ function findPlaywrightManagedBrowser(chromiumRef) {
547
+ try {
548
+ const defaultPath = chromiumRef?.executablePath();
549
+ if (defaultPath && fs3.existsSync(defaultPath)) return defaultPath;
550
+ } catch {
550
551
  }
551
- createNewDesktop(name) {
552
- const nextNum = this.desktops.length + 1;
553
- const cleanTitle = name?.trim() || `Masa\xFCst\xFC ${nextNum}`;
554
- const baseSlug = sanitizeDesktopId(
555
- cleanTitle.replace(/ğ/gi, "g").replace(/ü/gi, "u").replace(/ş/gi, "s").replace(/ı/gi, "i").replace(/ö/gi, "o").replace(/ç/gi, "c")
556
- );
557
- let candidate = baseSlug || `masaustu-${nextNum}`;
558
- let counter = 2;
559
- while (this.desktops.some((d) => d.id === candidate)) {
560
- candidate = `${baseSlug}-${counter++}`;
552
+ for (const root of collectPlaywrightRoots()) {
553
+ if (!fs3.existsSync(root)) continue;
554
+ let entries = [];
555
+ try {
556
+ entries = fs3.readdirSync(root);
557
+ } catch {
558
+ continue;
559
+ }
560
+ for (const dir of entries.filter((d) => d.startsWith("chromium_headless_shell-") || d.startsWith("chromium-")).sort().reverse()) {
561
+ const cands = [
562
+ path3.join(root, dir, "chrome-headless-shell-linux64", "chrome-headless-shell"),
563
+ path3.join(root, dir, "chrome-linux", "headless_shell"),
564
+ path3.join(root, dir, "chrome-linux", "chrome"),
565
+ path3.join(root, dir, "chrome-linux64", "chrome"),
566
+ path3.join(root, dir, "chrome-headless-shell-mac-arm64", "chrome-headless-shell"),
567
+ path3.join(root, dir, "chrome-headless-shell-mac-x64", "chrome-headless-shell"),
568
+ path3.join(root, dir, "chrome-mac", "headless_shell"),
569
+ path3.join(root, dir, "chrome-mac-arm64", "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
570
+ path3.join(root, dir, "chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium")
571
+ ];
572
+ for (const c of cands) {
573
+ if (fs3.existsSync(c)) return c;
574
+ }
561
575
  }
562
- const info = {
563
- id: candidate,
564
- name: cleanTitle,
565
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
566
- };
567
- this.desktops.push(info);
568
- this.save();
569
- return info;
570
- }
571
- renameDesktop(rawId, newName) {
572
- const id = sanitizeDesktopId(rawId);
573
- const item = this.desktops.find((d) => d.id === id);
574
- if (!item) throw new Error("Masa\xFCst\xFC bulunamad\u0131.");
575
- const trimmed = newName.trim();
576
- if (!trimmed) throw new Error("Masa\xFCst\xFC ad\u0131 bo\u015F olamaz.");
577
- item.name = trimmed;
578
- this.save();
579
- return item;
580
576
  }
581
- deleteDesktop(rawId) {
582
- const id = sanitizeDesktopId(rawId);
583
- if (this.desktops.length <= 1) {
584
- throw new Error("En az bir sanal masa\xFCst\xFC aktif kalmal\u0131d\u0131r.");
585
- }
586
- const idx = this.desktops.findIndex((d) => d.id === id);
587
- if (idx === -1) return this.list();
588
- this.desktops.splice(idx, 1);
589
- this.save();
590
- const dir = path3.join(DESKTOPS_ROOT, id);
591
- if (fs3.existsSync(dir)) {
592
- fs3.rmSync(dir, { recursive: true, force: true });
593
- }
594
- return this.list();
577
+ return void 0;
578
+ }
579
+ function resolvePlaywrightCliPath() {
580
+ try {
581
+ return require2.resolve("playwright-core/cli.js");
582
+ } catch {
583
+ return null;
595
584
  }
596
- };
597
- var VFSManager = class {
598
- desktopId;
599
- instanceRoot;
600
- vfsRoot;
601
- metaFile;
602
- meta;
603
- changeListeners = /* @__PURE__ */ new Set();
604
- constructor(desktopId, hostRootOverride) {
605
- this.desktopId = sanitizeDesktopId(desktopId);
606
- this.instanceRoot = path3.join(DESKTOPS_ROOT, this.desktopId);
607
- this.vfsRoot = hostRootOverride ? path3.resolve(hostRootOverride) : path3.join(this.instanceRoot, "vfs");
608
- this.metaFile = path3.join(this.instanceRoot, "meta.json");
609
- fs3.mkdirSync(this.instanceRoot, { recursive: true });
610
- fs3.mkdirSync(this.vfsRoot, { recursive: true });
611
- this.meta = this.loadMeta();
612
- if (!hostRootOverride) {
613
- this.ensureSeedWorkspace();
614
- } else {
615
- for (const dir of SYSTEM_DIRS) {
616
- fs3.mkdirSync(this.resolveDiskPath(dir), { recursive: true });
617
- }
585
+ }
586
+ function installPlaywrightBrowserSync(opts) {
587
+ const existing = findPlaywrightManagedBrowser();
588
+ if (existing) return true;
589
+ const cliPath = resolvePlaywrightCliPath();
590
+ if (!cliPath) {
591
+ if (!opts?.quiet) {
592
+ console.error("[TamgaVDesktop] playwright-core/cli.js bulunamad\u0131.");
618
593
  }
594
+ return false;
619
595
  }
620
- getInstanceRoot() {
621
- return this.instanceRoot;
596
+ const args = [cliPath, "install", "chromium-headless-shell"];
597
+ if (opts?.withDeps && process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0) {
598
+ args.push("--with-deps");
622
599
  }
623
- getVfsRoot() {
624
- return this.vfsRoot;
600
+ if (opts?.quiet) {
601
+ args.push("--no-progress");
625
602
  }
626
- onChange(cb) {
627
- this.changeListeners.add(cb);
628
- return () => this.changeListeners.delete(cb);
603
+ if (!opts?.quiet) {
604
+ console.log("[TamgaVDesktop] Yerle\u015Fik Playwright Chromium taray\u0131c\u0131s\u0131 kuruluyor...");
629
605
  }
630
- notifyChange() {
631
- for (const cb of this.changeListeners) {
632
- try {
633
- cb();
634
- } catch {
635
- }
606
+ const res = spawnSync(process.execPath, args, {
607
+ stdio: opts?.quiet ? "ignore" : "inherit",
608
+ env: {
609
+ ...process.env,
610
+ PLAYWRIGHT_SKIP_BROWSER_GC: "1"
636
611
  }
612
+ });
613
+ if (res.status === 0 && findPlaywrightManagedBrowser()) {
614
+ return true;
637
615
  }
638
- loadMeta() {
639
- if (fs3.existsSync(this.metaFile)) {
640
- try {
641
- const parsed = JSON.parse(fs3.readFileSync(this.metaFile, "utf-8"));
642
- const wp = parsed.preferences?.wallpaper === "nebula-compute" ? "mono-peaks" : parsed.preferences?.wallpaper || "mono-peaks";
643
- return {
644
- positions: parsed.positions || {},
645
- trashOrigins: parsed.trashOrigins || {},
646
- preferences: {
647
- wallpaper: wp,
648
- customWallpaper: parsed.preferences?.customWallpaper,
649
- theme: parsed.preferences?.theme === "light" ? "light" : "dark",
650
- iconSize: parsed.preferences?.iconSize || "md",
651
- autoArrange: parsed.preferences?.autoArrange ?? false,
652
- sortBy: parsed.preferences?.sortBy || "name"
653
- }
654
- };
655
- } catch {
656
- }
657
- }
658
- return {
659
- positions: {},
660
- trashOrigins: {},
661
- preferences: {
662
- wallpaper: "mono-peaks",
663
- theme: "dark",
664
- iconSize: "md",
665
- autoArrange: false,
666
- sortBy: "name"
667
- }
668
- };
616
+ const fallbackArgs = [cliPath, "install", "--only-shell", "chromium"];
617
+ if (opts?.quiet) fallbackArgs.push("--no-progress");
618
+ const res2 = spawnSync(process.execPath, fallbackArgs, {
619
+ stdio: opts?.quiet ? "ignore" : "inherit"
620
+ });
621
+ return res2.status === 0 && Boolean(findPlaywrightManagedBrowser());
622
+ }
623
+ async function installPlaywrightBrowserAsync() {
624
+ if (findPlaywrightManagedBrowser()) return;
625
+ const cliPath = resolvePlaywrightCliPath();
626
+ if (!cliPath) return;
627
+ await new Promise((resolve) => {
628
+ const child = spawn2(
629
+ process.execPath,
630
+ [cliPath, "install", "chromium-headless-shell", "--no-progress"],
631
+ { stdio: "ignore" }
632
+ );
633
+ child.on("exit", () => resolve());
634
+ child.on("error", () => resolve());
635
+ });
636
+ }
637
+ function normalizeUserUrl(rawInput) {
638
+ const trimmed = rawInput.trim();
639
+ if (!trimmed || trimmed === "compute://newtab" || trimmed === "about:blank") {
640
+ return { mode: "newtab", url: "compute://newtab" };
669
641
  }
670
- saveMeta() {
671
- fs3.mkdirSync(this.instanceRoot, { recursive: true });
672
- fs3.writeFileSync(this.metaFile, JSON.stringify(this.meta, null, 2), "utf-8");
642
+ if (trimmed.startsWith("file://")) {
643
+ const rawPath = decodeURIComponent(trimmed.replace(/^file:\/\/\/?/, "/"));
644
+ const normPath = ("/" + rawPath).replace(/\/+/g, "/");
645
+ return { mode: "file", url: `file://${normPath}`, filePath: normPath };
673
646
  }
674
- normalizeVirtualPath(vPath) {
675
- const cleaned = ("/" + (vPath || "").replace(/\\/g, "/")).replace(/\/+/g, "/").replace(/\/$/, "");
676
- return cleaned === "" ? "/" : cleaned;
647
+ if (/^https?:\/\//i.test(trimmed)) {
648
+ return { mode: "web", url: trimmed };
677
649
  }
678
- resolveDiskPath(vPath) {
679
- const norm = this.normalizeVirtualPath(vPath);
680
- const resolved = path3.resolve(this.vfsRoot, "." + norm);
681
- if (!resolved.startsWith(this.vfsRoot)) {
682
- throw new Error("Ge\xE7ersiz dosya yolu eri\u015Fimi engellendi.");
683
- }
684
- return resolved;
650
+ if (/^(localhost(:\d+)?|(\d{1,3}\.){3}\d{1,3}(:\d+)?|([a-z0-9-]+\.)+[a-z]{2,})(\/.*)?$/i.test(
651
+ trimmed
652
+ ) && !trimmed.includes(" ")) {
653
+ const proto = trimmed.startsWith("localhost") || /^\d+\.\d+/.test(trimmed) ? "http://" : "https://";
654
+ return { mode: "web", url: proto + trimmed };
685
655
  }
686
- ensureSeedWorkspace() {
687
- const marker = path3.join(this.instanceRoot, ".seeded");
688
- for (const dir of SYSTEM_DIRS) {
689
- fs3.mkdirSync(this.resolveDiskPath(dir), { recursive: true });
690
- }
691
- if (fs3.existsSync(marker)) return;
692
- fs3.mkdirSync(this.resolveDiskPath("/Desktop/Projeler"), { recursive: true });
693
- fs3.writeFileSync(
694
- this.resolveDiskPath("/Desktop/notlar.txt"),
695
- `Sanal Masa\xFCst\xFC (${this.desktopId})
696
- =========================
697
- - Bu masa\xFCst\xFC di\u011Fer sanal masa\xFCstlerinden tamamen ba\u011F\u0131ms\u0131z bir disk ve taray\u0131c\u0131 oturumuna sahiptir.
698
- - Dosyalar\u0131 a\xE7\u0131k klas\xF6r pencerelerinin veya Chromium penceresinin \xFCst\xFCne do\u011Frudan s\xFCr\xFCkleyip b\u0131rakabilirsiniz.
699
- `,
700
- "utf-8"
701
- );
702
- fs3.writeFileSync(
703
- this.resolveDiskPath("/Desktop/baslangic.html"),
704
- `<!DOCTYPE html>
705
- <html lang="tr">
706
- <head>
707
- <meta charset="UTF-8" />
708
- <title>Yerel Web Sayfas\u0131</title>
709
- <style>
710
- body {
711
- margin: 0;
712
- min-height: 100vh;
713
- display: grid;
714
- place-items: center;
715
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
716
- background: #141416;
717
- color: #f5f5f7;
718
- }
719
- .box {
720
- background: #1c1c1e;
721
- border: 1px solid rgba(255,255,255,0.1);
722
- border-radius: 18px;
723
- padding: 36px;
724
- max-width: 460px;
725
- text-align: center;
656
+ return {
657
+ mode: "web",
658
+ url: `https://www.google.com/search?q=${encodeURIComponent(trimmed)}&hl=tr`
659
+ };
660
+ }
661
+ var PAGE_ENHANCEMENT_INIT_SCRIPT = `
662
+ (() => {
663
+ try {
664
+ Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
665
+ } catch {}
666
+
667
+ if (!window.__rcCursorHooked) {
668
+ window.__rcCursorHooked = true;
669
+ let lastCursor = '';
670
+ let lastCheck = 0;
671
+ window.addEventListener('mousemove', (ev) => {
672
+ const now = performance.now();
673
+ if (now - lastCheck < 75) return;
674
+ lastCheck = now;
675
+ try {
676
+ const el = document.elementFromPoint(ev.clientX, ev.clientY);
677
+ const cur = el ? getComputedStyle(el).cursor || 'default' : 'default';
678
+ if (cur !== lastCursor && typeof window.__rcCursorChange === 'function') {
679
+ lastCursor = cur;
680
+ window.__rcCursorChange(cur).catch(() => {});
681
+ }
682
+ } catch {}
683
+ }, { passive: true, capture: true });
684
+ }
685
+
686
+ if (window.__rcAudioHooked) return;
687
+ window.__rcAudioHooked = true;
688
+
689
+ let mixCtx = null;
690
+ let mixGain = null;
691
+ let mixProcessor = null;
692
+ const retainedNodes = [];
693
+ const hookedElements = new WeakSet();
694
+ const hookedContexts = new WeakSet();
695
+
696
+ function sendFloatBufferAsPcm(ch0, ch1) {
697
+ if (typeof window.__rcPushAudioBase64 !== 'function') return;
698
+ const len = ch0.length;
699
+ let peak = 0;
700
+ for (let i = 0; i < len; i += 4) {
701
+ const a = Math.abs(ch0[i]);
702
+ if (a > peak) peak = a;
726
703
  }
727
- h1 { margin: 0 0 10px; font-size: 22px; font-weight: 600; }
728
- p { color: #a1a1a6; line-height: 1.6; font-size: 14px; }
729
- </style>
730
- </head>
731
- <body>
732
- <div class="box">
733
- <h1>Yerel HTML Dosyas\u0131</h1>
734
- <p>Bu sayfa sanal masa\xFCst\xFCn\xFCzdeki <code>/Desktop/baslangic.html</code> dosyas\u0131ndan \xE7al\u0131\u015F\u0131yor. \xDCst \xE7ubuktan kayna\u011F\u0131 d\xFCzenleyip kaydedebilirsiniz.</p>
735
- </div>
736
- </body>
737
- </html>`,
738
- "utf-8"
739
- );
740
- fs3.writeFileSync(
741
- this.resolveDiskPath("/Desktop/Projeler/analiz.py"),
742
- `def hesapla(veriler: list[float]) -> dict:
743
- toplam = sum(veriler)
744
- return {"adet": len(veriler), "ortalama": round(toplam / max(len(veriler), 1), 2)}
704
+ if (peak < 0.00035) return;
745
705
 
746
- if __name__ == "__main__":
747
- print(hesapla([14.2, 19.8, 22.4]))
748
- `,
749
- "utf-8"
750
- );
751
- fs3.writeFileSync(
752
- this.resolveDiskPath("/Desktop/Projeler/ayarlar.json"),
753
- JSON.stringify({ desktop: this.desktopId, browser: "chromium", isolated: true }, null, 2),
754
- "utf-8"
755
- );
756
- const zip = new AdmZip();
757
- zip.addFile("bilgi.txt", Buffer.from("Sa\u011F t\u0131klay\u0131p Buraya Ay\u0131kla se\xE7ene\u011Fiyle \xE7\u0131kartabilirsiniz.\n", "utf-8"));
758
- zip.writeZip(this.resolveDiskPath("/Desktop/arsiv.zip"));
759
- fs3.writeFileSync(marker, (/* @__PURE__ */ new Date()).toISOString(), "utf-8");
706
+ const pcm16 = new Int16Array(len);
707
+ for (let i = 0; i < len; i++) {
708
+ const mono = ch1 ? (ch0[i] + ch1[i]) * 0.5 : ch0[i];
709
+ const clamped = mono < -1 ? -1 : mono > 1 ? 1 : mono;
710
+ pcm16[i] = clamped * 32767;
711
+ }
712
+ const bytes = new Uint8Array(pcm16.buffer);
713
+ let binary = '';
714
+ for (let i = 0; i < bytes.length; i++) {
715
+ binary += String.fromCharCode(bytes[i]);
716
+ }
717
+ window.__rcPushAudioBase64(btoa(binary)).catch(() => {});
760
718
  }
761
- statNode(vPath) {
762
- const norm = this.normalizeVirtualPath(vPath);
763
- const diskPath = this.resolveDiskPath(norm);
764
- const stat = fs3.statSync(diskPath);
765
- const isDir = stat.isDirectory();
766
- const name = norm === "/" ? "Disk" : path3.posix.basename(norm);
767
- const parentPath = norm === "/" ? "" : path3.posix.dirname(norm);
768
- let childCount = 0;
769
- let size = stat.size;
770
- if (isDir) {
771
- const entries = fs3.readdirSync(diskPath).filter((e) => e !== ".DS_Store");
772
- childCount = entries.length;
773
- size = this.computeDirSize(diskPath);
719
+
720
+ function ensurePipeline() {
721
+ if (mixCtx) {
722
+ if (mixCtx.state === 'suspended') mixCtx.resume().catch(() => {});
723
+ return;
774
724
  }
775
- return {
776
- name,
777
- path: norm,
778
- parentPath,
779
- isDir,
780
- extension: extractExtension(name, isDir),
781
- size,
782
- childCount,
783
- createdAt: stat.birthtime.toISOString(),
784
- modifiedAt: stat.mtime.toISOString(),
785
- originalPath: this.meta.trashOrigins[norm]
786
- };
725
+ const AC = window.AudioContext || window.webkitAudioContext;
726
+ if (!AC) return;
727
+ try {
728
+ mixCtx = new AC({ sampleRate: 24000 });
729
+ hookedContexts.add(mixCtx);
730
+ mixGain = mixCtx.createGain();
731
+ mixProcessor = mixCtx.createScriptProcessor(2048, 2, 2);
732
+ mixGain.connect(mixProcessor);
733
+ mixProcessor.connect(mixCtx.destination);
734
+
735
+ mixProcessor.onaudioprocess = (ev) => {
736
+ const ch0 = ev.inputBuffer.getChannelData(0);
737
+ const ch1 = ev.inputBuffer.numberOfChannels > 1 ? ev.inputBuffer.getChannelData(1) : null;
738
+ sendFloatBufferAsPcm(ch0, ch1);
739
+ };
740
+ } catch {}
787
741
  }
788
- computeDirSize(diskDir) {
789
- let total = 0;
742
+
743
+ function attachMediaElement(el) {
744
+ if (!el || hookedElements.has(el)) return;
745
+ ensurePipeline();
746
+ if (!mixCtx || !mixGain) return;
747
+ if (mixCtx.state === 'suspended') mixCtx.resume().catch(() => {});
748
+
790
749
  try {
791
- const entries = fs3.readdirSync(diskDir, { withFileTypes: true });
792
- for (const entry of entries) {
793
- if (entry.name === ".DS_Store") continue;
794
- const full = path3.join(diskDir, entry.name);
795
- if (entry.isDirectory()) {
796
- total += this.computeDirSize(full);
797
- } else {
798
- total += fs3.statSync(full).size;
799
- }
750
+ const src = mixCtx.createMediaElementSource(el);
751
+ const volGain = mixCtx.createGain();
752
+ const syncVol = () => {
753
+ volGain.gain.value = el.muted ? 0 : el.volume;
754
+ };
755
+ syncVol();
756
+ el.addEventListener('volumechange', syncVol);
757
+ src.connect(volGain);
758
+ volGain.connect(mixGain);
759
+ retainedNodes.push(src, volGain);
760
+ hookedElements.add(el);
761
+ } catch {}
762
+ }
763
+
764
+ const origConnect = AudioNode.prototype.connect;
765
+ AudioNode.prototype.connect = function (dest, ...rest) {
766
+ const result = origConnect.call(this, dest, ...rest);
767
+ try {
768
+ if (
769
+ dest &&
770
+ this.context &&
771
+ dest === this.context.destination &&
772
+ !hookedContexts.has(this.context)
773
+ ) {
774
+ hookedContexts.add(this.context);
775
+ const ctx = this.context;
776
+ const tap = ctx.createScriptProcessor(2048, 2, 2);
777
+ origConnect.call(this, tap);
778
+ origConnect.call(tap, ctx.destination);
779
+ const ratio = ctx.sampleRate / 24000;
780
+ tap.onaudioprocess = (ev) => {
781
+ const in0 = ev.inputBuffer.getChannelData(0);
782
+ const outLen = Math.floor(in0.length / ratio);
783
+ const resampled = new Float32Array(outLen);
784
+ for (let i = 0; i < outLen; i++) {
785
+ resampled[i] = in0[Math.min(in0.length - 1, Math.round(i * ratio))];
786
+ }
787
+ sendFloatBufferAsPcm(resampled, null);
788
+ };
789
+ }
790
+ } catch {}
791
+ return result;
792
+ };
793
+
794
+ const origPlay = HTMLMediaElement.prototype.play;
795
+ HTMLMediaElement.prototype.play = function (...args) {
796
+ attachMediaElement(this);
797
+ return origPlay.apply(this, args);
798
+ };
799
+
800
+ setInterval(() => {
801
+ const els = document.querySelectorAll('video, audio');
802
+ for (let i = 0; i < els.length; i++) {
803
+ const el = els[i];
804
+ if (!el.paused && !el.muted) {
805
+ attachMediaElement(el);
800
806
  }
801
- } catch {
802
807
  }
803
- return total;
804
- }
805
- getSnapshot() {
806
- const nodes = [];
807
- const walk = (vDir) => {
808
- const diskDir = this.resolveDiskPath(vDir);
809
- if (!fs3.existsSync(diskDir)) return;
810
- if (vDir !== "/") {
811
- nodes.push(this.statNode(vDir));
808
+ }, 600);
809
+ })();
810
+ `;
811
+ var ChromiumCluster = class {
812
+ browser = null;
813
+ launching = null;
814
+ sessions = /* @__PURE__ */ new Map();
815
+ executableUsed = "Chromium";
816
+ async getBrowser() {
817
+ if (this.browser && this.browser.isConnected()) {
818
+ return this.browser;
819
+ }
820
+ if (this.launching) {
821
+ return this.launching;
822
+ }
823
+ this.launching = (async () => {
824
+ const chromiumApi = await loadPlaywrightChromium();
825
+ let executablePath = findPlaywrightManagedBrowser(chromiumApi);
826
+ if (!executablePath) {
827
+ await installPlaywrightBrowserAsync();
828
+ executablePath = findChromiumExecutable(chromiumApi);
812
829
  }
813
- const entries = fs3.readdirSync(diskDir).filter((e) => e !== ".DS_Store");
814
- for (const entry of entries) {
815
- const childVPath = vDir === "/" ? `/${entry}` : `${vDir}/${entry}`;
816
- const childDisk = this.resolveDiskPath(childVPath);
817
- const st = fs3.statSync(childDisk);
818
- if (st.isDirectory()) {
819
- walk(childVPath);
820
- } else {
821
- nodes.push(this.statNode(childVPath));
822
- }
830
+ if (!executablePath) {
831
+ throw new Error(
832
+ "Playwright Chromium ikilisi bulunamad\u0131. Sunucuda 'tamga-vdesktop install-browser' \xE7al\u0131\u015Ft\u0131r\u0131n."
833
+ );
823
834
  }
835
+ this.executableUsed = executablePath;
836
+ const launched = await chromiumApi.launch({
837
+ executablePath,
838
+ headless: true,
839
+ args: [
840
+ "--no-sandbox",
841
+ "--disable-setuid-sandbox",
842
+ "--disable-dev-shm-usage",
843
+ "--disable-blink-features=AutomationControlled",
844
+ "--autoplay-policy=no-user-gesture-required",
845
+ "--font-render-hinting=medium",
846
+ "--enable-font-antialiasing",
847
+ "--force-color-profile=srgb",
848
+ "--use-gl=angle",
849
+ "--use-angle=swiftshader-webgl",
850
+ "--enable-webgl",
851
+ "--ignore-gpu-blocklist"
852
+ ]
853
+ });
854
+ this.browser = launched;
855
+ return launched;
856
+ })();
857
+ try {
858
+ return await this.launching;
859
+ } finally {
860
+ this.launching = null;
861
+ }
862
+ }
863
+ getOrCreateSession(desktopId, vfs) {
864
+ let session = this.sessions.get(desktopId);
865
+ if (!session) {
866
+ session = new ChromiumDesktopSession(desktopId, vfs, this);
867
+ this.sessions.set(desktopId, session);
868
+ }
869
+ return session;
870
+ }
871
+ async destroySession(desktopId) {
872
+ const session = this.sessions.get(desktopId);
873
+ if (!session) return;
874
+ this.sessions.delete(desktopId);
875
+ await session.dispose();
876
+ }
877
+ getClusterInfo() {
878
+ let totalTabs = 0;
879
+ let totalWebPages = 0;
880
+ for (const s of this.sessions.values()) {
881
+ const info = s.getSessionStats();
882
+ totalTabs += info.activeTabs;
883
+ totalWebPages += info.webPagesCount;
884
+ }
885
+ return {
886
+ ready: Boolean(this.browser?.isConnected()),
887
+ installed: Boolean(findChromiumExecutable()),
888
+ executable: path3.basename(this.executableUsed),
889
+ isolatedDesktopsLoaded: this.sessions.size,
890
+ totalTabs,
891
+ totalWebPages
892
+ };
893
+ }
894
+ };
895
+ var ChromiumDesktopSession = class {
896
+ desktopId;
897
+ vfs;
898
+ cluster;
899
+ context = null;
900
+ contextCreating = null;
901
+ tabs = /* @__PURE__ */ new Map();
902
+ tabOrder = [];
903
+ activeTabId = null;
904
+ viewport = { width: 1160, height: 700 };
905
+ dpr = 1;
906
+ jsonListeners = /* @__PURE__ */ new Set();
907
+ binaryListeners = /* @__PURE__ */ new Set();
908
+ internalPageCreating = 0;
909
+ frameCounter = 0;
910
+ lastFpsCheck = Date.now();
911
+ currentFps = 0;
912
+ constructor(desktopId, vfs, cluster) {
913
+ this.desktopId = desktopId;
914
+ this.vfs = vfs;
915
+ this.cluster = cluster;
916
+ this.createTabInternal("compute://newtab", true);
917
+ }
918
+ getSessionStats() {
919
+ return {
920
+ activeTabs: this.tabs.size,
921
+ webPagesCount: Array.from(this.tabs.values()).filter((t) => Boolean(t.page)).length,
922
+ fps: this.currentFps
824
923
  };
825
- walk("/");
826
- return { nodes, meta: this.meta };
827
924
  }
828
- getUniquePath(parentPath, desiredName) {
829
- const cleanName = desiredName.replace(/[\\/]/g, "").trim() || "Ads\u0131z";
830
- const normParent = this.normalizeVirtualPath(parentPath);
831
- let candidate = normParent === "/" ? `/${cleanName}` : `${normParent}/${cleanName}`;
832
- if (!fs3.existsSync(this.resolveDiskPath(candidate))) {
833
- return candidate;
925
+ subscribe(onJson, onBinary) {
926
+ this.jsonListeners.add(onJson);
927
+ this.binaryListeners.add(onBinary);
928
+ onJson({
929
+ type: "tabs_state",
930
+ tabs: this.getTabsSummary(),
931
+ activeTabId: this.activeTabId
932
+ });
933
+ const active = this.activeTabId ? this.tabs.get(this.activeTabId) : void 0;
934
+ if (active?.mode === "web" && active.lastFrameBuffer) {
935
+ onBinary(active.lastFrameBuffer);
834
936
  }
835
- const extIdx = cleanName.lastIndexOf(".");
836
- const hasExt = extIdx > 0 && extIdx < cleanName.length - 1;
837
- const stem = hasExt ? cleanName.slice(0, extIdx) : cleanName;
838
- const ext = hasExt ? cleanName.slice(extIdx) : "";
839
- let counter = 2;
840
- while (true) {
841
- const nextName = `${stem} (${counter})${ext}`;
842
- candidate = normParent === "/" ? `/${nextName}` : `${normParent}/${nextName}`;
843
- if (!fs3.existsSync(this.resolveDiskPath(candidate))) {
844
- return candidate;
937
+ return () => {
938
+ this.jsonListeners.delete(onJson);
939
+ this.binaryListeners.delete(onBinary);
940
+ };
941
+ }
942
+ broadcastJson(msg) {
943
+ for (const cb of this.jsonListeners) {
944
+ try {
945
+ cb(msg);
946
+ } catch {
845
947
  }
846
- counter++;
847
948
  }
848
949
  }
849
- createFolder(parentPath, name, pos) {
850
- const targetVPath = this.getUniquePath(parentPath, name || "Yeni Klas\xF6r");
851
- fs3.mkdirSync(this.resolveDiskPath(targetVPath), { recursive: true });
852
- if (pos) {
853
- this.meta.positions[targetVPath] = pos;
854
- this.saveMeta();
950
+ broadcastBinary(packet) {
951
+ for (const cb of this.binaryListeners) {
952
+ try {
953
+ cb(packet);
954
+ } catch {
955
+ }
855
956
  }
856
- this.notifyChange();
857
- return this.statNode(targetVPath);
858
957
  }
859
- createFile(parentPath, name, content, pos) {
860
- const targetVPath = this.getUniquePath(parentPath, name || "yeni-dosya.txt");
861
- const diskPath = this.resolveDiskPath(targetVPath);
862
- fs3.mkdirSync(path3.dirname(diskPath), { recursive: true });
863
- const finalContent = content !== void 0 ? content : this.getDefaultTemplate(targetVPath);
864
- fs3.writeFileSync(diskPath, finalContent, "utf-8");
865
- if (pos) {
866
- this.meta.positions[targetVPath] = pos;
867
- this.saveMeta();
868
- }
869
- this.notifyChange();
870
- return this.statNode(targetVPath);
958
+ broadcastTabs() {
959
+ this.broadcastJson({
960
+ type: "tabs_state",
961
+ tabs: this.getTabsSummary(),
962
+ activeTabId: this.activeTabId
963
+ });
871
964
  }
872
- getDefaultTemplate(vPath) {
873
- const ext = extractExtension(path3.posix.basename(vPath), false);
874
- switch (ext) {
875
- case "html":
876
- case "htm":
877
- return `<!DOCTYPE html>
878
- <html lang="tr">
879
- <head>
880
- <meta charset="UTF-8" />
881
- <title>Sayfa</title>
882
- </head>
883
- <body style="font-family:-apple-system,sans-serif;padding:2rem;background:#141416;color:#f5f5f7;">
884
- <h1>Merhaba</h1>
885
- <p>Yeni HTML belgesi haz\u0131r.</p>
886
- </body>
887
- </html>
888
- `;
889
- case "json":
890
- return `{
891
- "ad": "kayit",
892
- "aktif": true
893
- }
894
- `;
895
- case "md":
896
- return `# Ba\u015Fl\u0131k
897
-
898
- Notlar\u0131n\u0131z\u0131 buraya yazabilirsiniz.
899
- `;
900
- case "py":
901
- return `def main():
902
- print("Merhaba!")
903
-
904
- if __name__ == "__main__":
905
- main()
906
- `;
907
- case "js":
908
- case "ts":
909
- return `console.log("Haz\u0131r");
910
- `;
911
- case "css":
912
- return `body {
913
- margin: 0;
914
- background: #141416;
915
- color: #f5f5f7;
916
- }
917
- `;
918
- case "csv":
919
- return `id,baslik,deger
920
- 1,Kalem A,100
921
- 2,Kalem B,250
922
- `;
923
- case "sql":
924
- return `SELECT * FROM kayitlar LIMIT 10;
925
- `;
926
- case "svg":
927
- return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
928
- <rect width="200" height="200" rx="24" fill="#1c1c1e"/>
929
- <circle cx="100" cy="100" r="52" fill="#e5e5ea"/>
930
- </svg>
931
- `;
932
- default:
933
- return "";
934
- }
965
+ getTabsSummary() {
966
+ const now = Date.now();
967
+ return this.tabOrder.map((id) => this.tabs.get(id)).filter((t) => Boolean(t)).map((t) => ({
968
+ id: t.id,
969
+ url: t.url,
970
+ title: t.title,
971
+ favicon: t.favicon,
972
+ isLoading: t.isLoading,
973
+ canGoBack: t.canGoBack,
974
+ canGoForward: t.canGoForward,
975
+ isSecure: t.url.startsWith("https://") || t.url.startsWith("compute://") || t.url.startsWith("file://"),
976
+ isPlayingAudio: now - t.lastAudioAt < 1500,
977
+ mode: t.mode,
978
+ filePath: t.filePath
979
+ }));
935
980
  }
936
- renameNode(vPath, newName) {
937
- const norm = this.normalizeVirtualPath(vPath);
938
- if (SYSTEM_DIRS.includes(norm) || norm === "/") {
939
- throw new Error("Sistem ana dizinleri yeniden adland\u0131r\u0131lamaz.");
940
- }
941
- const cleanName = newName.replace(/[\\/]/g, "").trim();
942
- if (!cleanName) {
943
- throw new Error("Dosya veya klas\xF6r ad\u0131 bo\u015F olamaz.");
944
- }
945
- const parent = path3.posix.dirname(norm);
946
- const nextVPath = parent === "/" ? `/${cleanName}` : `${parent}/${cleanName}`;
947
- if (nextVPath === norm) {
948
- return this.statNode(norm);
949
- }
950
- if (fs3.existsSync(this.resolveDiskPath(nextVPath))) {
951
- throw new Error(`"${cleanName}" ad\u0131nda bir \xF6\u011Fe zaten mevcut.`);
952
- }
953
- fs3.renameSync(this.resolveDiskPath(norm), this.resolveDiskPath(nextVPath));
954
- const updatedPositions = {};
955
- for (const [k, v] of Object.entries(this.meta.positions)) {
956
- if (k === norm) updatedPositions[nextVPath] = v;
957
- else if (k.startsWith(norm + "/")) updatedPositions[nextVPath + k.slice(norm.length)] = v;
958
- else updatedPositions[k] = v;
981
+ async ensureContext() {
982
+ if (this.context) return this.context;
983
+ if (this.contextCreating) return this.contextCreating;
984
+ this.contextCreating = (async () => {
985
+ const browser = await this.cluster.getBrowser();
986
+ const majorVer = browser.version().split(".")[0] || "134";
987
+ const ctx = await browser.newContext({
988
+ viewport: this.viewport,
989
+ deviceScaleFactor: this.dpr,
990
+ locale: "tr-TR",
991
+ userAgent: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${majorVer}.0.0.0 Safari/537.36`,
992
+ acceptDownloads: true
993
+ });
994
+ await ctx.exposeBinding("__rcPushAudioBase64", (source, b64) => {
995
+ if (this.binaryListeners.size === 0 || !b64) return;
996
+ const matchingTab = Array.from(this.tabs.values()).find((t) => t.page === source.page);
997
+ if (!matchingTab) return;
998
+ matchingTab.lastAudioAt = Date.now();
999
+ if (matchingTab.id !== this.activeTabId || matchingTab.mode !== "web") return;
1000
+ const pcmBuf = Buffer.from(b64, "base64");
1001
+ const packet = Buffer.allocUnsafe(1 + pcmBuf.length);
1002
+ packet[0] = PACKET_AUDIO_PCM;
1003
+ pcmBuf.copy(packet, 1);
1004
+ this.broadcastBinary(packet);
1005
+ });
1006
+ await ctx.exposeBinding("__rcCursorChange", (source, cursor) => {
1007
+ const matchingTab = Array.from(this.tabs.values()).find((t) => t.page === source.page);
1008
+ if (!matchingTab || matchingTab.id !== this.activeTabId || matchingTab.mode !== "web") return;
1009
+ this.broadcastJson({ type: "browser_cursor", cursor: String(cursor || "default") });
1010
+ });
1011
+ await ctx.addInitScript(PAGE_ENHANCEMENT_INIT_SCRIPT);
1012
+ ctx.on("page", async (newPage) => {
1013
+ if (this.internalPageCreating > 0) return;
1014
+ const alreadyTracked = Array.from(this.tabs.values()).some((t) => t.page === newPage);
1015
+ if (alreadyTracked) return;
1016
+ const id = `tab-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
1017
+ const tab = {
1018
+ id,
1019
+ mode: "web",
1020
+ url: newPage.url() || "about:blank",
1021
+ title: "Yeni Sekme...",
1022
+ favicon: "",
1023
+ isLoading: true,
1024
+ canGoBack: false,
1025
+ canGoForward: false,
1026
+ lastAudioAt: 0,
1027
+ page: newPage,
1028
+ streaming: false
1029
+ };
1030
+ this.tabs.set(id, tab);
1031
+ this.tabOrder.push(id);
1032
+ await this.attachPageHandlers(tab, newPage);
1033
+ await this.activateTab(id);
1034
+ });
1035
+ this.context = ctx;
1036
+ return ctx;
1037
+ })();
1038
+ try {
1039
+ return await this.contextCreating;
1040
+ } finally {
1041
+ this.contextCreating = null;
959
1042
  }
960
- this.meta.positions = updatedPositions;
961
- this.saveMeta();
962
- this.notifyChange();
963
- return this.statNode(nextVPath);
964
1043
  }
965
- moveNodes(paths, targetDir) {
966
- const normTarget = this.normalizeVirtualPath(targetDir);
967
- const targetDisk = this.resolveDiskPath(normTarget);
968
- if (!fs3.existsSync(targetDisk) || !fs3.statSync(targetDisk).isDirectory()) {
969
- throw new Error("Hedef klas\xF6r bulunamad\u0131.");
970
- }
971
- const moved = [];
972
- for (const rawPath of paths) {
973
- const src = this.normalizeVirtualPath(rawPath);
974
- if (SYSTEM_DIRS.includes(src) || src === "/" || src === normTarget) continue;
975
- if (normTarget.startsWith(src + "/")) {
976
- throw new Error("Bir klas\xF6r kendi alt klas\xF6r\xFCn\xFCn i\xE7ine ta\u015F\u0131namaz.");
977
- }
978
- const base = path3.posix.basename(src);
979
- const dest = path3.posix.dirname(src) === normTarget ? src : this.getUniquePath(normTarget, base);
980
- if (dest !== src) {
981
- fs3.renameSync(this.resolveDiskPath(src), this.resolveDiskPath(dest));
982
- delete this.meta.positions[src];
983
- }
984
- moved.push(this.statNode(dest));
1044
+ createTabInternal(initialInput = "compute://newtab", makeActive = true) {
1045
+ const parsed = normalizeUserUrl(initialInput);
1046
+ const id = `tab-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
1047
+ const tab = {
1048
+ id,
1049
+ mode: parsed.mode,
1050
+ filePath: parsed.filePath,
1051
+ url: parsed.url,
1052
+ title: parsed.mode === "newtab" ? "Yeni Sekme" : parsed.mode === "file" ? path3.posix.basename(parsed.filePath || "Dosya") : parsed.url,
1053
+ favicon: "",
1054
+ isLoading: false,
1055
+ canGoBack: false,
1056
+ canGoForward: false,
1057
+ lastAudioAt: 0,
1058
+ streaming: false
1059
+ };
1060
+ this.tabs.set(id, tab);
1061
+ this.tabOrder.push(id);
1062
+ if (makeActive) this.activeTabId = id;
1063
+ return tab;
1064
+ }
1065
+ async createTab(initialUrl = "compute://newtab") {
1066
+ const tab = this.createTabInternal(initialUrl, false);
1067
+ await this.activateTab(tab.id);
1068
+ if (tab.mode === "web") {
1069
+ await this.navigate(tab.id, tab.url);
985
1070
  }
986
- this.saveMeta();
987
- this.notifyChange();
988
- return moved;
1071
+ this.broadcastTabs();
1072
+ return tab.id;
989
1073
  }
990
- copyNodes(paths, targetDir) {
991
- const normTarget = this.normalizeVirtualPath(targetDir);
992
- const copied = [];
993
- for (const rawPath of paths) {
994
- const src = this.normalizeVirtualPath(rawPath);
995
- if (src === "/") continue;
996
- if (normTarget.startsWith(src + "/")) {
997
- throw new Error("Bir klas\xF6r kendi alt klas\xF6r\xFCn\xFCn i\xE7ine kopyalanamaz.");
1074
+ async applyTabMetrics(tab) {
1075
+ if (!tab.page || tab.page.isClosed()) return;
1076
+ try {
1077
+ await tab.page.setViewportSize(this.viewport);
1078
+ } catch {
1079
+ }
1080
+ if (tab.cdp) {
1081
+ try {
1082
+ await tab.cdp.send("Emulation.setDeviceMetricsOverride", {
1083
+ width: this.viewport.width,
1084
+ height: this.viewport.height,
1085
+ deviceScaleFactor: this.dpr,
1086
+ mobile: false
1087
+ });
1088
+ } catch {
998
1089
  }
999
- const base = path3.posix.basename(src);
1000
- const desired = path3.posix.dirname(src) === normTarget ? this.makeCopyName(base) : base;
1001
- const dest = this.getUniquePath(normTarget, desired);
1002
- fs3.cpSync(this.resolveDiskPath(src), this.resolveDiskPath(dest), { recursive: true });
1003
- copied.push(this.statNode(dest));
1004
1090
  }
1005
- this.notifyChange();
1006
- return copied;
1007
1091
  }
1008
- makeCopyName(name) {
1009
- const idx = name.lastIndexOf(".");
1010
- if (idx > 0 && idx < name.length - 1) {
1011
- return `${name.slice(0, idx)} kopyas\u0131${name.slice(idx)}`;
1092
+ async activateTab(tabId) {
1093
+ const next = this.tabs.get(tabId);
1094
+ if (!next) return;
1095
+ if (this.activeTabId && this.activeTabId !== tabId) {
1096
+ const prev = this.tabs.get(this.activeTabId);
1097
+ if (prev) await this.stopScreencast(prev);
1012
1098
  }
1013
- return `${name} kopyas\u0131`;
1014
- }
1015
- trashNodes(paths) {
1016
- for (const rawPath of paths) {
1017
- const src = this.normalizeVirtualPath(rawPath);
1018
- if (SYSTEM_DIRS.includes(src) || src === "/") continue;
1019
- if (src.startsWith("/.trash/")) {
1020
- fs3.rmSync(this.resolveDiskPath(src), { recursive: true, force: true });
1021
- delete this.meta.trashOrigins[src];
1022
- continue;
1099
+ this.activeTabId = tabId;
1100
+ this.broadcastTabs();
1101
+ if (next.mode === "web" && next.page) {
1102
+ await this.applyTabMetrics(next);
1103
+ if (next.lastFrameBuffer) {
1104
+ this.broadcastBinary(next.lastFrameBuffer);
1023
1105
  }
1024
- const dest = this.getUniquePath("/.trash", path3.posix.basename(src));
1025
- fs3.renameSync(this.resolveDiskPath(src), this.resolveDiskPath(dest));
1026
- this.meta.trashOrigins[dest] = src;
1027
- delete this.meta.positions[src];
1106
+ await this.startScreencast(next);
1107
+ await this.captureImmediateFrame(next);
1028
1108
  }
1029
- this.saveMeta();
1030
- this.notifyChange();
1031
1109
  }
1032
- restoreNodes(trashPaths) {
1033
- const restored = [];
1034
- for (const rawPath of trashPaths) {
1035
- const src = this.normalizeVirtualPath(rawPath);
1036
- if (!src.startsWith("/.trash/")) continue;
1037
- const origin = this.meta.trashOrigins[src] || `/Desktop/${path3.posix.basename(src)}`;
1038
- const originParent = path3.posix.dirname(origin);
1039
- fs3.mkdirSync(this.resolveDiskPath(originParent), { recursive: true });
1040
- const finalDest = this.getUniquePath(originParent, path3.posix.basename(origin));
1041
- fs3.renameSync(this.resolveDiskPath(src), this.resolveDiskPath(finalDest));
1042
- delete this.meta.trashOrigins[src];
1043
- restored.push(this.statNode(finalDest));
1110
+ async closeTab(tabId) {
1111
+ const tab = this.tabs.get(tabId);
1112
+ if (!tab) return;
1113
+ await this.cleanupTabPage(tab);
1114
+ this.tabs.delete(tabId);
1115
+ const idx = this.tabOrder.indexOf(tabId);
1116
+ if (idx !== -1) this.tabOrder.splice(idx, 1);
1117
+ if (this.tabOrder.length === 0) {
1118
+ const fresh = this.createTabInternal("compute://newtab", true);
1119
+ this.activeTabId = fresh.id;
1120
+ this.broadcastTabs();
1121
+ return;
1044
1122
  }
1045
- this.saveMeta();
1046
- this.notifyChange();
1047
- return restored;
1048
- }
1049
- deletePermanently(paths) {
1050
- for (const rawPath of paths) {
1051
- const src = this.normalizeVirtualPath(rawPath);
1052
- if (SYSTEM_DIRS.includes(src) || src === "/") continue;
1053
- fs3.rmSync(this.resolveDiskPath(src), { recursive: true, force: true });
1054
- delete this.meta.trashOrigins[src];
1055
- delete this.meta.positions[src];
1123
+ if (this.activeTabId === tabId) {
1124
+ const nextIdx = Math.min(idx, this.tabOrder.length - 1);
1125
+ await this.activateTab(this.tabOrder[nextIdx]);
1126
+ } else {
1127
+ this.broadcastTabs();
1056
1128
  }
1057
- this.saveMeta();
1058
- this.notifyChange();
1059
1129
  }
1060
- emptyTrash() {
1061
- const trashDisk = this.resolveDiskPath("/.trash");
1062
- if (fs3.existsSync(trashDisk)) {
1063
- for (const item of fs3.readdirSync(trashDisk)) {
1064
- fs3.rmSync(path3.join(trashDisk, item), { recursive: true, force: true });
1130
+ async cleanupTabPage(tab) {
1131
+ if (tab.settleTimer) {
1132
+ clearTimeout(tab.settleTimer);
1133
+ tab.settleTimer = void 0;
1134
+ }
1135
+ await this.stopScreencast(tab);
1136
+ if (tab.cdp) {
1137
+ try {
1138
+ await tab.cdp.detach();
1139
+ } catch {
1065
1140
  }
1141
+ tab.cdp = void 0;
1066
1142
  }
1067
- this.meta.trashOrigins = {};
1068
- this.saveMeta();
1069
- this.notifyChange();
1070
- }
1071
- compressToZip(paths, targetDir, zipName) {
1072
- if (!paths.length) throw new Error("Ar\u015Fivlenecek \xF6\u011Fe se\xE7ilmedi.");
1073
- const zip = new AdmZip();
1074
- for (const rawPath of paths) {
1075
- const src = this.normalizeVirtualPath(rawPath);
1076
- const diskSrc = this.resolveDiskPath(src);
1077
- if (!fs3.existsSync(diskSrc)) continue;
1078
- const st = fs3.statSync(diskSrc);
1079
- if (st.isDirectory()) {
1080
- zip.addLocalFolder(diskSrc, path3.posix.basename(src));
1081
- } else {
1082
- zip.addLocalFile(diskSrc);
1143
+ if (tab.page && !tab.page.isClosed()) {
1144
+ try {
1145
+ await tab.page.close();
1146
+ } catch {
1083
1147
  }
1084
1148
  }
1085
- const baseName = zipName || (paths.length === 1 ? `${path3.posix.basename(paths[0]).replace(/\.[^.]+$/, "")}.zip` : "arsiv.zip");
1086
- const finalName = baseName.toLowerCase().endsWith(".zip") ? baseName : `${baseName}.zip`;
1087
- const destVPath = this.getUniquePath(targetDir, finalName);
1088
- zip.writeZip(this.resolveDiskPath(destVPath));
1089
- this.notifyChange();
1090
- return this.statNode(destVPath);
1091
- }
1092
- extractZip(zipVPath, targetDir) {
1093
- const normZip = this.normalizeVirtualPath(zipVPath);
1094
- const diskZip = this.resolveDiskPath(normZip);
1095
- if (!fs3.existsSync(diskZip)) throw new Error("Ar\u015Fiv dosyas\u0131 bulunamad\u0131.");
1096
- const parent = targetDir ? this.normalizeVirtualPath(targetDir) : path3.posix.dirname(normZip);
1097
- const folderBase = path3.posix.basename(normZip).replace(/\.zip$/i, "") || "ayiklanan";
1098
- const destFolderVPath = this.getUniquePath(parent, folderBase);
1099
- const destDisk = this.resolveDiskPath(destFolderVPath);
1100
- fs3.mkdirSync(destDisk, { recursive: true });
1101
- const zip = new AdmZip(diskZip);
1102
- zip.extractAllTo(destDisk, true);
1103
- this.notifyChange();
1104
- return this.statNode(destFolderVPath);
1149
+ tab.page = void 0;
1105
1150
  }
1106
- readTextFile(vPath) {
1107
- const norm = this.normalizeVirtualPath(vPath);
1108
- const disk = this.resolveDiskPath(norm);
1109
- if (!fs3.existsSync(disk) || fs3.statSync(disk).isDirectory()) {
1110
- throw new Error("Dosya okunamad\u0131.");
1111
- }
1112
- const buf = fs3.readFileSync(disk);
1113
- return {
1114
- content: buf.toString("utf-8"),
1115
- node: this.statNode(norm)
1151
+ async attachPageHandlers(tab, page) {
1152
+ const cdp = await page.context().newCDPSession(page);
1153
+ tab.cdp = cdp;
1154
+ await this.applyTabMetrics(tab);
1155
+ cdp.on("Page.screencastFrame", (payload) => {
1156
+ cdp.send("Page.screencastFrameAck", { sessionId: payload.sessionId }).catch(() => {
1157
+ });
1158
+ const jpegBuf = Buffer.from(payload.data, "base64");
1159
+ const packet = Buffer.allocUnsafe(1 + jpegBuf.length);
1160
+ packet[0] = PACKET_VIDEO_JPEG;
1161
+ jpegBuf.copy(packet, 1);
1162
+ tab.lastFrameBuffer = packet;
1163
+ this.recordFrameTick();
1164
+ if (this.activeTabId === tab.id && tab.mode === "web") {
1165
+ this.broadcastBinary(packet);
1166
+ if (Date.now() > (tab.suppressSettleUntil || 0)) {
1167
+ if (tab.settleTimer) clearTimeout(tab.settleTimer);
1168
+ tab.settleTimer = setTimeout(() => {
1169
+ if (this.activeTabId === tab.id && tab.mode === "web") {
1170
+ this.captureImmediateFrame(tab).catch(() => {
1171
+ });
1172
+ }
1173
+ }, 220);
1174
+ }
1175
+ }
1176
+ });
1177
+ const syncPageMeta = async () => {
1178
+ if (page.isClosed() || tab.mode !== "web") return;
1179
+ try {
1180
+ const currentUrl = page.url();
1181
+ if (currentUrl && currentUrl !== "about:blank") tab.url = currentUrl;
1182
+ const title = await page.title().catch(() => "");
1183
+ if (title) {
1184
+ tab.title = title;
1185
+ } else {
1186
+ try {
1187
+ tab.title = new URL(tab.url).hostname || tab.url;
1188
+ } catch {
1189
+ tab.title = tab.url;
1190
+ }
1191
+ }
1192
+ try {
1193
+ const u = new URL(tab.url);
1194
+ tab.favicon = `https://www.google.com/s2/favicons?domain=${u.hostname}&sz=64`;
1195
+ } catch {
1196
+ tab.favicon = "";
1197
+ }
1198
+ if (tab.cdp) {
1199
+ const hist = await tab.cdp.send("Page.getNavigationHistory").catch(() => null);
1200
+ if (hist) {
1201
+ tab.canGoBack = hist.currentIndex > 0;
1202
+ tab.canGoForward = hist.currentIndex < hist.entries.length - 1;
1203
+ }
1204
+ }
1205
+ } catch {
1206
+ }
1207
+ this.broadcastTabs();
1116
1208
  };
1117
- }
1118
- writeTextFile(vPath, content) {
1119
- const norm = this.normalizeVirtualPath(vPath);
1120
- const disk = this.resolveDiskPath(norm);
1121
- fs3.mkdirSync(path3.dirname(disk), { recursive: true });
1122
- fs3.writeFileSync(disk, content, "utf-8");
1123
- this.notifyChange();
1124
- return this.statNode(norm);
1125
- }
1126
- saveUploadedBuffer(parentPath, originalName, buffer) {
1127
- const destVPath = this.getUniquePath(parentPath, originalName);
1128
- const disk = this.resolveDiskPath(destVPath);
1129
- fs3.mkdirSync(path3.dirname(disk), { recursive: true });
1130
- fs3.writeFileSync(disk, buffer);
1131
- this.notifyChange();
1132
- return this.statNode(destVPath);
1133
- }
1134
- updateMeta(partial) {
1135
- if (partial.positions) {
1136
- this.meta.positions = { ...this.meta.positions, ...partial.positions };
1137
- }
1138
- if (partial.preferences) {
1139
- this.meta.preferences = { ...this.meta.preferences, ...partial.preferences };
1140
- if (!this.meta.preferences.customWallpaper) {
1141
- delete this.meta.preferences.customWallpaper;
1209
+ page.on("framenavigated", (frame) => {
1210
+ if (frame === page.mainFrame()) syncPageMeta();
1211
+ });
1212
+ page.on("domcontentloaded", () => {
1213
+ tab.isLoading = false;
1214
+ syncPageMeta();
1215
+ this.captureImmediateFrame(tab).catch(() => {
1216
+ });
1217
+ });
1218
+ page.on("load", () => {
1219
+ tab.isLoading = false;
1220
+ syncPageMeta();
1221
+ this.captureImmediateFrame(tab).catch(() => {
1222
+ });
1223
+ });
1224
+ page.on("download", async (download) => {
1225
+ try {
1226
+ const suggested = download.suggestedFilename() || `indirilen-${Date.now()}`;
1227
+ const downloadsDir = this.vfs.resolveDiskPath("/Downloads");
1228
+ fs3.mkdirSync(downloadsDir, { recursive: true });
1229
+ let finalName = suggested;
1230
+ let counter = 2;
1231
+ while (fs3.existsSync(path3.join(downloadsDir, finalName))) {
1232
+ const extIdx = suggested.lastIndexOf(".");
1233
+ finalName = extIdx > 0 ? `${suggested.slice(0, extIdx)} (${counter})${suggested.slice(extIdx)}` : `${suggested} (${counter})`;
1234
+ counter++;
1235
+ }
1236
+ await download.saveAs(path3.join(downloadsDir, finalName));
1237
+ this.vfs.notifyChange();
1238
+ this.broadcastJson({
1239
+ type: "download_complete",
1240
+ fileName: finalName,
1241
+ virtualPath: `/Downloads/${finalName}`
1242
+ });
1243
+ } catch (err) {
1244
+ this.broadcastJson({
1245
+ type: "browser_error",
1246
+ message: `\u0130ndirme ba\u015Far\u0131s\u0131z oldu: ${err.message}`
1247
+ });
1142
1248
  }
1143
- }
1144
- this.saveMeta();
1145
- return this.meta;
1146
- }
1147
- saveCustomWallpaper(originalName, buffer) {
1148
- const wpDir = path3.join(this.instanceRoot, "wallpapers");
1149
- fs3.mkdirSync(wpDir, { recursive: true });
1150
- const rawExt = path3.extname(originalName || "").toLowerCase().replace(/[^.a-z0-9]/g, "") || ".png";
1151
- const fileName = `wp-${Date.now()}${rawExt}`;
1152
- fs3.writeFileSync(path3.join(wpDir, fileName), buffer);
1153
- this.meta.preferences.wallpaper = "custom";
1154
- this.meta.preferences.customWallpaper = fileName;
1155
- this.saveMeta();
1156
- return this.meta;
1249
+ });
1157
1250
  }
1158
- setWallpaperFromVfs(vPath) {
1159
- const disk = this.resolveDiskPath(vPath);
1160
- if (!fs3.existsSync(disk) || fs3.statSync(disk).isDirectory()) {
1161
- throw new Error("Resim dosyas\u0131 bulunamad\u0131.");
1251
+ recordFrameTick() {
1252
+ this.frameCounter++;
1253
+ const now = Date.now();
1254
+ const elapsed = now - this.lastFpsCheck;
1255
+ if (elapsed >= 1e3) {
1256
+ this.currentFps = Math.round(this.frameCounter * 1e3 / elapsed);
1257
+ this.frameCounter = 0;
1258
+ this.lastFpsCheck = now;
1162
1259
  }
1163
- const buf = fs3.readFileSync(disk);
1164
- return this.saveCustomWallpaper(path3.basename(disk), buf);
1165
1260
  }
1166
- resolveWallpaperPath(fileName) {
1167
- const safeName = path3.basename(fileName || "");
1168
- const wpDir = path3.join(this.instanceRoot, "wallpapers");
1169
- const resolved = path3.resolve(wpDir, safeName);
1170
- if (!resolved.startsWith(wpDir)) {
1171
- throw new Error("Ge\xE7ersiz arka plan yolu.");
1261
+ async startScreencast(tab) {
1262
+ if (!tab.cdp || tab.streaming || tab.mode !== "web") return;
1263
+ try {
1264
+ await tab.cdp.send("Page.startScreencast", {
1265
+ format: "jpeg",
1266
+ quality: 92,
1267
+ maxWidth: Math.round(this.viewport.width * this.dpr),
1268
+ maxHeight: Math.round(this.viewport.height * this.dpr),
1269
+ everyNthFrame: 1
1270
+ });
1271
+ tab.streaming = true;
1272
+ } catch {
1273
+ tab.streaming = false;
1172
1274
  }
1173
- return resolved;
1174
- }
1175
- clearPositions() {
1176
- this.meta.positions = {};
1177
- this.saveMeta();
1178
- return this.meta;
1179
- }
1180
- };
1181
-
1182
- // server/chromiumManager.ts
1183
- import fs4 from "node:fs";
1184
- import os3 from "node:os";
1185
- import path4 from "node:path";
1186
- async function loadPlaywrightChromium() {
1187
- try {
1188
- const pw = await import("playwright-core");
1189
- return pw.chromium;
1190
- } catch {
1191
- throw new Error("Yerle\u015Fik Playwright Chromium y\xFCkl\xFC de\u011Fil. Linux sunucuda Firefox veya di\u011Fer yerel uygulamalar\u0131 kullan\u0131n.");
1192
1275
  }
1193
- }
1194
- var PACKET_VIDEO_JPEG = 1;
1195
- var PACKET_AUDIO_PCM = 2;
1196
- function findChromiumExecutable(chromiumRef) {
1197
- try {
1198
- const defaultPath = chromiumRef?.executablePath();
1199
- if (defaultPath && fs4.existsSync(defaultPath)) {
1200
- return defaultPath;
1276
+ async stopScreencast(tab) {
1277
+ if (tab.settleTimer) {
1278
+ clearTimeout(tab.settleTimer);
1279
+ tab.settleTimer = void 0;
1201
1280
  }
1202
- } catch {
1281
+ if (!tab.cdp || !tab.streaming) return;
1282
+ try {
1283
+ await tab.cdp.send("Page.stopScreencast");
1284
+ } catch {
1285
+ }
1286
+ tab.streaming = false;
1203
1287
  }
1204
- const home = os3.homedir();
1205
- const cacheRoots = [
1206
- path4.join(home, "Library", "Caches", "ms-playwright"),
1207
- path4.join(home, ".cache", "ms-playwright"),
1208
- process.env.LOCALAPPDATA ? path4.join(process.env.LOCALAPPDATA, "ms-playwright") : ""
1209
- ].filter(Boolean);
1210
- for (const root of cacheRoots) {
1211
- if (!fs4.existsSync(root)) continue;
1212
- const dirs = fs4.readdirSync(root).filter((d) => d.startsWith("chromium-")).sort().reverse();
1213
- for (const dir of dirs) {
1214
- const candidates = [
1215
- path4.join(root, dir, "chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium"),
1216
- path4.join(root, dir, "chrome-mac-arm64", "Chromium.app", "Contents", "MacOS", "Chromium"),
1217
- path4.join(root, dir, "chrome-linux", "chrome"),
1218
- path4.join(root, dir, "chrome-win", "chrome.exe")
1219
- ];
1220
- for (const candidate of candidates) {
1221
- if (fs4.existsSync(candidate)) return candidate;
1288
+ async captureImmediateFrame(tab) {
1289
+ if (!tab.page || tab.page.isClosed() || tab.mode !== "web") return;
1290
+ try {
1291
+ tab.suppressSettleUntil = Date.now() + 380;
1292
+ const pngBuf = await tab.page.screenshot({ type: "png" });
1293
+ const packet = Buffer.allocUnsafe(1 + pngBuf.length);
1294
+ packet[0] = PACKET_VIDEO_JPEG;
1295
+ pngBuf.copy(packet, 1);
1296
+ if (tab.lastFrameBuffer && tab.lastFrameBuffer.length === packet.length && tab.lastFrameBuffer.equals(packet)) {
1297
+ return;
1298
+ }
1299
+ tab.lastFrameBuffer = packet;
1300
+ if (this.activeTabId === tab.id) {
1301
+ this.broadcastBinary(packet);
1222
1302
  }
1303
+ } catch {
1223
1304
  }
1224
1305
  }
1225
- const systemCandidates = [
1226
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
1227
- "/Applications/Chromium.app/Contents/MacOS/Chromium",
1228
- "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
1229
- "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
1230
- "/usr/bin/chromium",
1231
- "/usr/bin/chromium-browser",
1232
- "/usr/bin/google-chrome"
1233
- ];
1234
- for (const candidate of systemCandidates) {
1235
- if (fs4.existsSync(candidate)) return candidate;
1236
- }
1237
- return void 0;
1238
- }
1239
- function normalizeUserUrl(rawInput) {
1240
- const trimmed = rawInput.trim();
1241
- if (!trimmed || trimmed === "compute://newtab" || trimmed === "about:blank") {
1242
- return { mode: "newtab", url: "compute://newtab" };
1243
- }
1244
- if (trimmed.startsWith("file://")) {
1245
- const rawPath = decodeURIComponent(trimmed.replace(/^file:\/\/\/?/, "/"));
1246
- const normPath = ("/" + rawPath).replace(/\/+/g, "/");
1247
- return { mode: "file", url: `file://${normPath}`, filePath: normPath };
1306
+ async navigate(tabId, rawInput) {
1307
+ const tab = this.tabs.get(tabId);
1308
+ if (!tab) return;
1309
+ const parsed = normalizeUserUrl(rawInput);
1310
+ tab.mode = parsed.mode;
1311
+ tab.filePath = parsed.filePath;
1312
+ tab.url = parsed.url;
1313
+ if (parsed.mode === "newtab") {
1314
+ await this.stopScreencast(tab);
1315
+ tab.title = "Yeni Sekme";
1316
+ tab.favicon = "";
1317
+ tab.isLoading = false;
1318
+ this.broadcastTabs();
1319
+ return;
1320
+ }
1321
+ if (parsed.mode === "file") {
1322
+ await this.stopScreencast(tab);
1323
+ tab.title = path3.posix.basename(parsed.filePath || "Dosya");
1324
+ tab.favicon = "";
1325
+ tab.isLoading = false;
1326
+ this.broadcastTabs();
1327
+ return;
1328
+ }
1329
+ tab.isLoading = true;
1330
+ try {
1331
+ tab.title = new URL(parsed.url).hostname || parsed.url;
1332
+ } catch {
1333
+ tab.title = parsed.url;
1334
+ }
1335
+ this.broadcastTabs();
1336
+ try {
1337
+ const ctx = await this.ensureContext();
1338
+ if (!tab.page || tab.page.isClosed()) {
1339
+ this.internalPageCreating++;
1340
+ try {
1341
+ const page = await ctx.newPage();
1342
+ tab.page = page;
1343
+ await this.attachPageHandlers(tab, page);
1344
+ } finally {
1345
+ this.internalPageCreating--;
1346
+ }
1347
+ }
1348
+ if (this.activeTabId === tab.id) {
1349
+ await this.startScreencast(tab);
1350
+ }
1351
+ await tab.page.goto(parsed.url, {
1352
+ waitUntil: "domcontentloaded",
1353
+ timeout: 25e3
1354
+ });
1355
+ tab.isLoading = false;
1356
+ this.broadcastTabs();
1357
+ await this.captureImmediateFrame(tab);
1358
+ } catch (err) {
1359
+ tab.isLoading = false;
1360
+ this.broadcastTabs();
1361
+ this.broadcastJson({
1362
+ type: "browser_error",
1363
+ tabId: tab.id,
1364
+ message: `Sayfa y\xFCklenemedi: ${err.message}`
1365
+ });
1366
+ }
1248
1367
  }
1249
- if (/^https?:\/\//i.test(trimmed)) {
1250
- return { mode: "web", url: trimmed };
1368
+ async goBack(tabId) {
1369
+ const tab = this.tabs.get(tabId);
1370
+ if (!tab?.page || tab.mode !== "web") return;
1371
+ tab.isLoading = true;
1372
+ this.broadcastTabs();
1373
+ await tab.page.goBack({ waitUntil: "domcontentloaded" }).catch(() => {
1374
+ });
1375
+ tab.isLoading = false;
1376
+ this.broadcastTabs();
1377
+ await this.captureImmediateFrame(tab);
1251
1378
  }
1252
- if (/^(localhost(:\d+)?|(\d{1,3}\.){3}\d{1,3}(:\d+)?|([a-z0-9-]+\.)+[a-z]{2,})(\/.*)?$/i.test(
1253
- trimmed
1254
- ) && !trimmed.includes(" ")) {
1255
- const proto = trimmed.startsWith("localhost") || /^\d+\.\d+/.test(trimmed) ? "http://" : "https://";
1256
- return { mode: "web", url: proto + trimmed };
1379
+ async goForward(tabId) {
1380
+ const tab = this.tabs.get(tabId);
1381
+ if (!tab?.page || tab.mode !== "web") return;
1382
+ tab.isLoading = true;
1383
+ this.broadcastTabs();
1384
+ await tab.page.goForward({ waitUntil: "domcontentloaded" }).catch(() => {
1385
+ });
1386
+ tab.isLoading = false;
1387
+ this.broadcastTabs();
1388
+ await this.captureImmediateFrame(tab);
1257
1389
  }
1258
- return {
1259
- mode: "web",
1260
- url: `https://www.google.com/search?q=${encodeURIComponent(trimmed)}&hl=tr`
1261
- };
1262
- }
1263
- var AUDIO_CAPTURE_INIT_SCRIPT = `
1264
- (() => {
1265
- if (window.__rcAudioHooked) return;
1266
- window.__rcAudioHooked = true;
1267
-
1268
- let mixCtx = null;
1269
- let mixGain = null;
1270
- let mixProcessor = null;
1271
- const retainedNodes = [];
1272
- const hookedElements = new WeakSet();
1273
- const hookedContexts = new WeakSet();
1274
-
1275
- function sendFloatBufferAsPcm(ch0, ch1) {
1276
- if (typeof window.__rcPushAudioBase64 !== 'function') return;
1277
- const len = ch0.length;
1278
- let peak = 0;
1279
- for (let i = 0; i < len; i += 4) {
1280
- const a = Math.abs(ch0[i]);
1281
- if (a > peak) peak = a;
1282
- }
1283
- if (peak < 0.00035) return;
1284
-
1285
- const pcm16 = new Int16Array(len);
1286
- for (let i = 0; i < len; i++) {
1287
- const mono = ch1 ? (ch0[i] + ch1[i]) * 0.5 : ch0[i];
1288
- const clamped = mono < -1 ? -1 : mono > 1 ? 1 : mono;
1289
- pcm16[i] = clamped * 32767;
1390
+ async reload(tabId) {
1391
+ const tab = this.tabs.get(tabId);
1392
+ if (!tab) return;
1393
+ if (tab.mode === "web" && tab.page) {
1394
+ tab.isLoading = true;
1395
+ this.broadcastTabs();
1396
+ await tab.page.reload({ waitUntil: "domcontentloaded" }).catch(() => {
1397
+ });
1398
+ tab.isLoading = false;
1399
+ this.broadcastTabs();
1400
+ await this.captureImmediateFrame(tab);
1401
+ } else {
1402
+ this.broadcastTabs();
1290
1403
  }
1291
- const bytes = new Uint8Array(pcm16.buffer);
1292
- let binary = '';
1293
- for (let i = 0; i < bytes.length; i++) {
1294
- binary += String.fromCharCode(bytes[i]);
1404
+ }
1405
+ async setViewport(width, height, dpr) {
1406
+ const w = Math.max(360, Math.min(1920, Math.round(width)));
1407
+ const h = Math.max(260, Math.min(1200, Math.round(height)));
1408
+ const nextDpr = dpr && Number.isFinite(dpr) ? Math.max(1, Math.min(2, Number(dpr))) : this.dpr;
1409
+ const sizeChanged = Math.abs(this.viewport.width - w) >= 4 || Math.abs(this.viewport.height - h) >= 4;
1410
+ const dprChanged = Math.abs(this.dpr - nextDpr) >= 0.05;
1411
+ if (!sizeChanged && !dprChanged) return;
1412
+ this.viewport = { width: w, height: h };
1413
+ this.dpr = nextDpr;
1414
+ const active = this.activeTabId ? this.tabs.get(this.activeTabId) : void 0;
1415
+ if (active?.mode === "web" && active.page && !active.page.isClosed()) {
1416
+ try {
1417
+ await this.stopScreencast(active);
1418
+ await this.applyTabMetrics(active);
1419
+ await this.startScreencast(active);
1420
+ await this.captureImmediateFrame(active);
1421
+ } catch {
1422
+ }
1295
1423
  }
1296
- window.__rcPushAudioBase64(btoa(binary)).catch(() => {});
1297
1424
  }
1298
-
1299
- function ensurePipeline() {
1300
- if (mixCtx) {
1301
- if (mixCtx.state === 'suspended') mixCtx.resume().catch(() => {});
1425
+ handleInput(payload) {
1426
+ const tabId = payload.tabId || this.activeTabId;
1427
+ if (!tabId) return;
1428
+ const tab = this.tabs.get(tabId);
1429
+ if (!tab || tab.mode !== "web" || !tab.page || !tab.cdp || tab.page.isClosed()) return;
1430
+ const kind = payload.kind;
1431
+ if (kind === "mouse") {
1432
+ const eventType = payload.eventType;
1433
+ tab.cdp.send("Input.dispatchMouseEvent", {
1434
+ type: eventType,
1435
+ x: Number(payload.x) || 0,
1436
+ y: Number(payload.y) || 0,
1437
+ button: payload.button || "none",
1438
+ clickCount: Number(payload.clickCount) || 1,
1439
+ modifiers: Number(payload.modifiers) || 0,
1440
+ deltaX: Number(payload.deltaX) || 0,
1441
+ deltaY: Number(payload.deltaY) || 0
1442
+ }).catch(() => {
1443
+ });
1302
1444
  return;
1303
1445
  }
1304
- const AC = window.AudioContext || window.webkitAudioContext;
1305
- if (!AC) return;
1306
- try {
1307
- mixCtx = new AC({ sampleRate: 24000 });
1308
- hookedContexts.add(mixCtx);
1309
- mixGain = mixCtx.createGain();
1310
- mixProcessor = mixCtx.createScriptProcessor(2048, 2, 2);
1311
- mixGain.connect(mixProcessor);
1312
- mixProcessor.connect(mixCtx.destination);
1313
-
1314
- mixProcessor.onaudioprocess = (ev) => {
1315
- const ch0 = ev.inputBuffer.getChannelData(0);
1316
- const ch1 = ev.inputBuffer.numberOfChannels > 1 ? ev.inputBuffer.getChannelData(1) : null;
1317
- sendFloatBufferAsPcm(ch0, ch1);
1318
- };
1319
- } catch {}
1320
- }
1321
-
1322
- function attachMediaElement(el) {
1323
- if (!el || hookedElements.has(el)) return;
1324
- ensurePipeline();
1325
- if (!mixCtx || !mixGain) return;
1326
- if (mixCtx.state === 'suspended') mixCtx.resume().catch(() => {});
1327
-
1328
- try {
1329
- const src = mixCtx.createMediaElementSource(el);
1330
- const volGain = mixCtx.createGain();
1331
- const syncVol = () => {
1332
- volGain.gain.value = el.muted ? 0 : el.volume;
1333
- };
1334
- syncVol();
1335
- el.addEventListener('volumechange', syncVol);
1336
- src.connect(volGain);
1337
- volGain.connect(mixGain);
1338
- retainedNodes.push(src, volGain);
1339
- hookedElements.add(el);
1340
- } catch {}
1341
- }
1342
-
1343
- // Also capture WebAudio API sounds (synths, games, web apps) connected to ctx.destination
1344
- const origConnect = AudioNode.prototype.connect;
1345
- AudioNode.prototype.connect = function (dest, ...rest) {
1346
- const result = origConnect.call(this, dest, ...rest);
1347
- try {
1348
- if (
1349
- dest &&
1350
- this.context &&
1351
- dest === this.context.destination &&
1352
- !hookedContexts.has(this.context)
1353
- ) {
1354
- hookedContexts.add(this.context);
1355
- const ctx = this.context;
1356
- const tap = ctx.createScriptProcessor(2048, 2, 2);
1357
- origConnect.call(this, tap);
1358
- origConnect.call(tap, ctx.destination);
1359
- const ratio = ctx.sampleRate / 24000;
1360
- tap.onaudioprocess = (ev) => {
1361
- const in0 = ev.inputBuffer.getChannelData(0);
1362
- const outLen = Math.floor(in0.length / ratio);
1363
- const resampled = new Float32Array(outLen);
1364
- for (let i = 0; i < outLen; i++) {
1365
- resampled[i] = in0[Math.min(in0.length - 1, Math.round(i * ratio))];
1366
- }
1367
- sendFloatBufferAsPcm(resampled, null);
1368
- };
1446
+ if (kind === "key") {
1447
+ const key = String(payload.key || "");
1448
+ const ctrlOrMeta = Boolean(payload.ctrlKey || payload.metaKey);
1449
+ const shiftKey = Boolean(payload.shiftKey);
1450
+ const altKey = Boolean(payload.altKey);
1451
+ const modPrefix = process.platform === "darwin" ? "Meta" : "Control";
1452
+ if (ctrlOrMeta && key.length === 1) {
1453
+ const lower = key.toLowerCase();
1454
+ if (["a", "c", "x", "z", "y", "f"].includes(lower)) {
1455
+ tab.page.keyboard.press(`${modPrefix}+${shiftKey ? "Shift+" : ""}${lower}`).catch(() => {
1456
+ });
1457
+ return;
1458
+ }
1369
1459
  }
1370
- } catch {}
1371
- return result;
1372
- };
1373
-
1374
- const origPlay = HTMLMediaElement.prototype.play;
1375
- HTMLMediaElement.prototype.play = function (...args) {
1376
- attachMediaElement(this);
1377
- return origPlay.apply(this, args);
1378
- };
1379
-
1380
- setInterval(() => {
1381
- const els = document.querySelectorAll('video, audio');
1382
- for (let i = 0; i < els.length; i++) {
1383
- const el = els[i];
1384
- if (!el.paused && !el.muted) {
1385
- attachMediaElement(el);
1460
+ const specialKeys = /* @__PURE__ */ new Set([
1461
+ "Enter",
1462
+ "Backspace",
1463
+ "Tab",
1464
+ "Escape",
1465
+ "Delete",
1466
+ "ArrowLeft",
1467
+ "ArrowRight",
1468
+ "ArrowUp",
1469
+ "ArrowDown",
1470
+ "Home",
1471
+ "End",
1472
+ "PageUp",
1473
+ "PageDown",
1474
+ "F5"
1475
+ ]);
1476
+ if (specialKeys.has(key)) {
1477
+ const mods = [];
1478
+ if (ctrlOrMeta) mods.push(modPrefix);
1479
+ if (altKey) mods.push("Alt");
1480
+ if (shiftKey) mods.push("Shift");
1481
+ tab.page.keyboard.press([...mods, key].join("+")).catch(() => {
1482
+ });
1483
+ } else if (key.length === 1 && !ctrlOrMeta) {
1484
+ tab.page.keyboard.insertText(key).catch(() => {
1485
+ });
1386
1486
  }
1487
+ return;
1387
1488
  }
1388
- }, 600);
1389
- })();
1390
- `;
1391
- var ChromiumCluster = class {
1392
- browser = null;
1393
- launching = null;
1394
- sessions = /* @__PURE__ */ new Map();
1395
- executableUsed = "Chromium";
1396
- async getBrowser() {
1397
- if (this.browser && this.browser.isConnected()) {
1398
- return this.browser;
1399
- }
1400
- if (this.launching) {
1401
- return this.launching;
1402
- }
1403
- this.launching = (async () => {
1404
- const chromiumApi = await loadPlaywrightChromium();
1405
- const executablePath = findChromiumExecutable(chromiumApi);
1406
- if (executablePath) this.executableUsed = executablePath;
1407
- const launched = await chromiumApi.launch({
1408
- executablePath,
1409
- headless: true,
1410
- args: [
1411
- "--no-sandbox",
1412
- "--disable-setuid-sandbox",
1413
- "--disable-dev-shm-usage",
1414
- "--disable-blink-features=AutomationControlled",
1415
- "--autoplay-policy=no-user-gesture-required",
1416
- "--font-render-hinting=none"
1417
- ]
1489
+ if (kind === "paste") {
1490
+ const text = String(payload.text || "");
1491
+ if (text) tab.page.keyboard.insertText(text).catch(() => {
1418
1492
  });
1419
- this.browser = launched;
1420
- return launched;
1421
- })();
1422
- try {
1423
- return await this.launching;
1424
- } finally {
1425
- this.launching = null;
1426
1493
  }
1427
1494
  }
1428
- getOrCreateSession(desktopId, vfs) {
1429
- let session = this.sessions.get(desktopId);
1430
- if (!session) {
1431
- session = new ChromiumDesktopSession(desktopId, vfs, this);
1432
- this.sessions.set(desktopId, session);
1495
+ async dispose() {
1496
+ for (const tab of this.tabs.values()) {
1497
+ await this.cleanupTabPage(tab);
1433
1498
  }
1434
- return session;
1435
- }
1436
- async destroySession(desktopId) {
1437
- const session = this.sessions.get(desktopId);
1438
- if (!session) return;
1439
- this.sessions.delete(desktopId);
1440
- await session.dispose();
1441
- }
1442
- getClusterInfo() {
1443
- let totalTabs = 0;
1444
- let totalWebPages = 0;
1445
- for (const s of this.sessions.values()) {
1446
- const info = s.getSessionStats();
1447
- totalTabs += info.activeTabs;
1448
- totalWebPages += info.webPagesCount;
1499
+ this.tabs.clear();
1500
+ this.tabOrder = [];
1501
+ if (this.context) {
1502
+ await this.context.close().catch(() => {
1503
+ });
1504
+ this.context = null;
1449
1505
  }
1450
- return {
1451
- ready: Boolean(this.browser?.isConnected()),
1452
- executable: path4.basename(this.executableUsed),
1453
- isolatedDesktopsLoaded: this.sessions.size,
1454
- totalTabs,
1455
- totalWebPages
1456
- };
1457
1506
  }
1458
1507
  };
1459
- var ChromiumDesktopSession = class {
1460
- desktopId;
1461
- vfs;
1462
- cluster;
1463
- context = null;
1464
- contextCreating = null;
1465
- tabs = /* @__PURE__ */ new Map();
1466
- tabOrder = [];
1467
- activeTabId = null;
1468
- viewport = { width: 1160, height: 700 };
1469
- jsonListeners = /* @__PURE__ */ new Set();
1470
- binaryListeners = /* @__PURE__ */ new Set();
1471
- internalPageCreating = 0;
1472
- frameCounter = 0;
1473
- lastFpsCheck = Date.now();
1474
- currentFps = 0;
1475
- constructor(desktopId, vfs, cluster) {
1476
- this.desktopId = desktopId;
1477
- this.vfs = vfs;
1478
- this.cluster = cluster;
1479
- this.createTabInternal("compute://newtab", true);
1480
- }
1481
- getSessionStats() {
1482
- return {
1483
- activeTabs: this.tabs.size,
1484
- webPagesCount: Array.from(this.tabs.values()).filter((t) => Boolean(t.page)).length,
1485
- fps: this.currentFps
1486
- };
1508
+
1509
+ // server/index.ts
1510
+ import express from "express";
1511
+ import cors from "cors";
1512
+ import http2 from "node:http";
1513
+ import os5 from "node:os";
1514
+ import path8 from "node:path";
1515
+ import fs8 from "node:fs";
1516
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
1517
+ import multer from "multer";
1518
+ import { WebSocketServer, WebSocket } from "ws";
1519
+
1520
+ // server/vfsManager.ts
1521
+ import fs4 from "node:fs";
1522
+ import path4 from "node:path";
1523
+ import AdmZip from "adm-zip";
1524
+ var STORAGE_ROOT = path4.resolve(process.cwd(), "storage");
1525
+ var DESKTOPS_ROOT = path4.join(STORAGE_ROOT, "desktops");
1526
+ var REGISTRY_FILE = path4.join(DESKTOPS_ROOT, "registry.json");
1527
+ function setStorageRoot(dir) {
1528
+ STORAGE_ROOT = path4.resolve(dir);
1529
+ DESKTOPS_ROOT = path4.join(STORAGE_ROOT, "desktops");
1530
+ REGISTRY_FILE = path4.join(DESKTOPS_ROOT, "registry.json");
1531
+ fs4.mkdirSync(DESKTOPS_ROOT, { recursive: true });
1532
+ }
1533
+ var SYSTEM_DIRS = ["/Desktop", "/Documents", "/Downloads", "/Projects", "/.trash"];
1534
+ function sanitizeDesktopId(raw) {
1535
+ const cleaned = (raw || "main").toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 40);
1536
+ return cleaned || "main";
1537
+ }
1538
+ function extractExtension(name, isDir) {
1539
+ if (isDir) return "";
1540
+ const lower = name.toLowerCase();
1541
+ if (lower.endsWith(".tar.gz")) return "tar.gz";
1542
+ if (lower.startsWith(".") && !lower.slice(1).includes(".")) {
1543
+ return lower.slice(1);
1487
1544
  }
1488
- subscribe(onJson, onBinary) {
1489
- this.jsonListeners.add(onJson);
1490
- this.binaryListeners.add(onBinary);
1491
- onJson({
1492
- type: "tabs_state",
1493
- tabs: this.getTabsSummary(),
1494
- activeTabId: this.activeTabId
1495
- });
1496
- const active = this.activeTabId ? this.tabs.get(this.activeTabId) : void 0;
1497
- if (active?.mode === "web" && active.lastFrameBuffer) {
1498
- onBinary(active.lastFrameBuffer);
1499
- }
1500
- return () => {
1501
- this.jsonListeners.delete(onJson);
1502
- this.binaryListeners.delete(onBinary);
1503
- };
1545
+ const idx = lower.lastIndexOf(".");
1546
+ if (idx <= 0 || idx === lower.length - 1) return "";
1547
+ return lower.slice(idx + 1);
1548
+ }
1549
+ var DesktopRegistry = class {
1550
+ desktops = [];
1551
+ constructor() {
1552
+ fs4.mkdirSync(DESKTOPS_ROOT, { recursive: true });
1553
+ this.migrateLegacyIfPresent();
1554
+ this.load();
1504
1555
  }
1505
- broadcastJson(msg) {
1506
- for (const cb of this.jsonListeners) {
1507
- try {
1508
- cb(msg);
1509
- } catch {
1556
+ migrateLegacyIfPresent() {
1557
+ const legacyVfs = path4.join(STORAGE_ROOT, "vfs");
1558
+ const mainDir = path4.join(DESKTOPS_ROOT, "main");
1559
+ if (fs4.existsSync(legacyVfs) && !fs4.existsSync(mainDir)) {
1560
+ fs4.mkdirSync(mainDir, { recursive: true });
1561
+ fs4.cpSync(legacyVfs, path4.join(mainDir, "vfs"), { recursive: true });
1562
+ const legacyMeta = path4.join(STORAGE_ROOT, "meta.json");
1563
+ if (fs4.existsSync(legacyMeta)) {
1564
+ fs4.cpSync(legacyMeta, path4.join(mainDir, "meta.json"));
1510
1565
  }
1566
+ fs4.writeFileSync(path4.join(mainDir, ".seeded"), (/* @__PURE__ */ new Date()).toISOString(), "utf-8");
1511
1567
  }
1512
1568
  }
1513
- broadcastBinary(packet) {
1514
- for (const cb of this.binaryListeners) {
1569
+ load() {
1570
+ if (fs4.existsSync(REGISTRY_FILE)) {
1515
1571
  try {
1516
- cb(packet);
1572
+ const parsed = JSON.parse(fs4.readFileSync(REGISTRY_FILE, "utf-8"));
1573
+ if (Array.isArray(parsed) && parsed.length > 0) {
1574
+ this.desktops = parsed;
1575
+ return;
1576
+ }
1517
1577
  } catch {
1518
1578
  }
1519
1579
  }
1580
+ this.desktops = [
1581
+ {
1582
+ id: "main",
1583
+ name: "Masa\xFCst\xFC 1",
1584
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
1585
+ }
1586
+ ];
1587
+ this.save();
1520
1588
  }
1521
- broadcastTabs() {
1522
- this.broadcastJson({
1523
- type: "tabs_state",
1524
- tabs: this.getTabsSummary(),
1525
- activeTabId: this.activeTabId
1526
- });
1527
- }
1528
- getTabsSummary() {
1529
- const now = Date.now();
1530
- return this.tabOrder.map((id) => this.tabs.get(id)).filter((t) => Boolean(t)).map((t) => ({
1531
- id: t.id,
1532
- url: t.url,
1533
- title: t.title,
1534
- favicon: t.favicon,
1535
- isLoading: t.isLoading,
1536
- canGoBack: t.canGoBack,
1537
- canGoForward: t.canGoForward,
1538
- isSecure: t.url.startsWith("https://") || t.url.startsWith("compute://") || t.url.startsWith("file://"),
1539
- isPlayingAudio: now - t.lastAudioAt < 1500,
1540
- mode: t.mode,
1541
- filePath: t.filePath
1542
- }));
1589
+ save() {
1590
+ fs4.mkdirSync(DESKTOPS_ROOT, { recursive: true });
1591
+ fs4.writeFileSync(REGISTRY_FILE, JSON.stringify(this.desktops, null, 2), "utf-8");
1543
1592
  }
1544
- async ensureContext() {
1545
- if (this.context) return this.context;
1546
- if (this.contextCreating) return this.contextCreating;
1547
- this.contextCreating = (async () => {
1548
- const browser = await this.cluster.getBrowser();
1549
- const ctx = await browser.newContext({
1550
- viewport: this.viewport,
1551
- deviceScaleFactor: 1,
1552
- locale: "tr-TR",
1553
- userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
1554
- acceptDownloads: true
1555
- });
1556
- await ctx.exposeBinding("__rcPushAudioBase64", (source, b64) => {
1557
- if (this.binaryListeners.size === 0 || !b64) return;
1558
- const matchingTab = Array.from(this.tabs.values()).find((t) => t.page === source.page);
1559
- if (!matchingTab) return;
1560
- matchingTab.lastAudioAt = Date.now();
1561
- if (matchingTab.id !== this.activeTabId || matchingTab.mode !== "web") return;
1562
- const pcmBuf = Buffer.from(b64, "base64");
1563
- const packet = Buffer.allocUnsafe(1 + pcmBuf.length);
1564
- packet[0] = PACKET_AUDIO_PCM;
1565
- pcmBuf.copy(packet, 1);
1566
- this.broadcastBinary(packet);
1567
- });
1568
- await ctx.addInitScript(AUDIO_CAPTURE_INIT_SCRIPT);
1569
- ctx.on("page", async (newPage) => {
1570
- if (this.internalPageCreating > 0) return;
1571
- const alreadyTracked = Array.from(this.tabs.values()).some((t) => t.page === newPage);
1572
- if (alreadyTracked) return;
1573
- const id = `tab-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
1574
- const tab = {
1575
- id,
1576
- mode: "web",
1577
- url: newPage.url() || "about:blank",
1578
- title: "Yeni Sekme...",
1579
- favicon: "",
1580
- isLoading: true,
1581
- canGoBack: false,
1582
- canGoForward: false,
1583
- lastAudioAt: 0,
1584
- page: newPage,
1585
- streaming: false
1586
- };
1587
- this.tabs.set(id, tab);
1588
- this.tabOrder.push(id);
1589
- await this.attachPageHandlers(tab, newPage);
1590
- await this.activateTab(id);
1591
- });
1592
- this.context = ctx;
1593
- return ctx;
1594
- })();
1595
- try {
1596
- return await this.contextCreating;
1597
- } finally {
1598
- this.contextCreating = null;
1599
- }
1593
+ list() {
1594
+ return [...this.desktops];
1600
1595
  }
1601
- createTabInternal(initialInput = "compute://newtab", makeActive = true) {
1602
- const parsed = normalizeUserUrl(initialInput);
1603
- const id = `tab-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
1604
- const tab = {
1596
+ ensureDesktop(rawId, desiredName) {
1597
+ const id = sanitizeDesktopId(rawId);
1598
+ const existing = this.desktops.find((d) => d.id === id);
1599
+ if (existing) return existing;
1600
+ const info = {
1605
1601
  id,
1606
- mode: parsed.mode,
1607
- filePath: parsed.filePath,
1608
- url: parsed.url,
1609
- title: parsed.mode === "newtab" ? "Yeni Sekme" : parsed.mode === "file" ? path4.posix.basename(parsed.filePath || "Dosya") : parsed.url,
1610
- favicon: "",
1611
- isLoading: false,
1612
- canGoBack: false,
1613
- canGoForward: false,
1614
- lastAudioAt: 0,
1615
- streaming: false
1602
+ name: desiredName?.trim() || `Masa\xFCst\xFC ${this.desktops.length + 1}`,
1603
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
1616
1604
  };
1617
- this.tabs.set(id, tab);
1618
- this.tabOrder.push(id);
1619
- if (makeActive) this.activeTabId = id;
1620
- return tab;
1605
+ this.desktops.push(info);
1606
+ this.save();
1607
+ return info;
1621
1608
  }
1622
- async createTab(initialUrl = "compute://newtab") {
1623
- const tab = this.createTabInternal(initialUrl, false);
1624
- await this.activateTab(tab.id);
1625
- if (tab.mode === "web") {
1626
- await this.navigate(tab.id, tab.url);
1609
+ createNewDesktop(name) {
1610
+ const nextNum = this.desktops.length + 1;
1611
+ const cleanTitle = name?.trim() || `Masa\xFCst\xFC ${nextNum}`;
1612
+ const baseSlug = sanitizeDesktopId(
1613
+ cleanTitle.replace(/ğ/gi, "g").replace(/ü/gi, "u").replace(/ş/gi, "s").replace(/ı/gi, "i").replace(/ö/gi, "o").replace(/ç/gi, "c")
1614
+ );
1615
+ let candidate = baseSlug || `masaustu-${nextNum}`;
1616
+ let counter = 2;
1617
+ while (this.desktops.some((d) => d.id === candidate)) {
1618
+ candidate = `${baseSlug}-${counter++}`;
1627
1619
  }
1628
- this.broadcastTabs();
1629
- return tab.id;
1620
+ const info = {
1621
+ id: candidate,
1622
+ name: cleanTitle,
1623
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
1624
+ };
1625
+ this.desktops.push(info);
1626
+ this.save();
1627
+ return info;
1630
1628
  }
1631
- async activateTab(tabId) {
1632
- const next = this.tabs.get(tabId);
1633
- if (!next) return;
1634
- if (this.activeTabId && this.activeTabId !== tabId) {
1635
- const prev = this.tabs.get(this.activeTabId);
1636
- if (prev) await this.stopScreencast(prev);
1629
+ renameDesktop(rawId, newName) {
1630
+ const id = sanitizeDesktopId(rawId);
1631
+ const item = this.desktops.find((d) => d.id === id);
1632
+ if (!item) throw new Error("Masa\xFCst\xFC bulunamad\u0131.");
1633
+ const trimmed = newName.trim();
1634
+ if (!trimmed) throw new Error("Masa\xFCst\xFC ad\u0131 bo\u015F olamaz.");
1635
+ item.name = trimmed;
1636
+ this.save();
1637
+ return item;
1638
+ }
1639
+ deleteDesktop(rawId) {
1640
+ const id = sanitizeDesktopId(rawId);
1641
+ if (this.desktops.length <= 1) {
1642
+ throw new Error("En az bir sanal masa\xFCst\xFC aktif kalmal\u0131d\u0131r.");
1637
1643
  }
1638
- this.activeTabId = tabId;
1639
- this.broadcastTabs();
1640
- if (next.mode === "web" && next.page) {
1641
- try {
1642
- await next.page.setViewportSize(this.viewport);
1643
- } catch {
1644
- }
1645
- if (next.lastFrameBuffer) {
1646
- this.broadcastBinary(next.lastFrameBuffer);
1647
- }
1648
- await this.startScreencast(next);
1644
+ const idx = this.desktops.findIndex((d) => d.id === id);
1645
+ if (idx === -1) return this.list();
1646
+ this.desktops.splice(idx, 1);
1647
+ this.save();
1648
+ const dir = path4.join(DESKTOPS_ROOT, id);
1649
+ if (fs4.existsSync(dir)) {
1650
+ fs4.rmSync(dir, { recursive: true, force: true });
1649
1651
  }
1652
+ return this.list();
1650
1653
  }
1651
- async closeTab(tabId) {
1652
- const tab = this.tabs.get(tabId);
1653
- if (!tab) return;
1654
- await this.cleanupTabPage(tab);
1655
- this.tabs.delete(tabId);
1656
- const idx = this.tabOrder.indexOf(tabId);
1657
- if (idx !== -1) this.tabOrder.splice(idx, 1);
1658
- if (this.tabOrder.length === 0) {
1659
- const fresh = this.createTabInternal("compute://newtab", true);
1660
- this.activeTabId = fresh.id;
1661
- this.broadcastTabs();
1662
- return;
1663
- }
1664
- if (this.activeTabId === tabId) {
1665
- const nextIdx = Math.min(idx, this.tabOrder.length - 1);
1666
- await this.activateTab(this.tabOrder[nextIdx]);
1654
+ };
1655
+ var VFSManager = class {
1656
+ desktopId;
1657
+ instanceRoot;
1658
+ vfsRoot;
1659
+ metaFile;
1660
+ meta;
1661
+ changeListeners = /* @__PURE__ */ new Set();
1662
+ constructor(desktopId, hostRootOverride) {
1663
+ this.desktopId = sanitizeDesktopId(desktopId);
1664
+ this.instanceRoot = path4.join(DESKTOPS_ROOT, this.desktopId);
1665
+ this.vfsRoot = hostRootOverride ? path4.resolve(hostRootOverride) : path4.join(this.instanceRoot, "vfs");
1666
+ this.metaFile = path4.join(this.instanceRoot, "meta.json");
1667
+ fs4.mkdirSync(this.instanceRoot, { recursive: true });
1668
+ fs4.mkdirSync(this.vfsRoot, { recursive: true });
1669
+ this.meta = this.loadMeta();
1670
+ if (!hostRootOverride) {
1671
+ this.ensureSeedWorkspace();
1667
1672
  } else {
1668
- this.broadcastTabs();
1673
+ for (const dir of SYSTEM_DIRS) {
1674
+ fs4.mkdirSync(this.resolveDiskPath(dir), { recursive: true });
1675
+ }
1669
1676
  }
1670
1677
  }
1671
- async cleanupTabPage(tab) {
1672
- await this.stopScreencast(tab);
1673
- if (tab.cdp) {
1678
+ getInstanceRoot() {
1679
+ return this.instanceRoot;
1680
+ }
1681
+ getVfsRoot() {
1682
+ return this.vfsRoot;
1683
+ }
1684
+ onChange(cb) {
1685
+ this.changeListeners.add(cb);
1686
+ return () => this.changeListeners.delete(cb);
1687
+ }
1688
+ notifyChange() {
1689
+ for (const cb of this.changeListeners) {
1674
1690
  try {
1675
- await tab.cdp.detach();
1691
+ cb();
1676
1692
  } catch {
1677
1693
  }
1678
- tab.cdp = void 0;
1679
1694
  }
1680
- if (tab.page && !tab.page.isClosed()) {
1695
+ }
1696
+ loadMeta() {
1697
+ if (fs4.existsSync(this.metaFile)) {
1681
1698
  try {
1682
- await tab.page.close();
1699
+ const parsed = JSON.parse(fs4.readFileSync(this.metaFile, "utf-8"));
1700
+ const wp = parsed.preferences?.wallpaper === "nebula-compute" ? "mono-peaks" : parsed.preferences?.wallpaper || "mono-peaks";
1701
+ return {
1702
+ positions: parsed.positions || {},
1703
+ trashOrigins: parsed.trashOrigins || {},
1704
+ preferences: {
1705
+ wallpaper: wp,
1706
+ customWallpaper: parsed.preferences?.customWallpaper,
1707
+ theme: parsed.preferences?.theme === "light" ? "light" : "dark",
1708
+ iconSize: parsed.preferences?.iconSize || "md",
1709
+ autoArrange: parsed.preferences?.autoArrange ?? false,
1710
+ sortBy: parsed.preferences?.sortBy || "name"
1711
+ }
1712
+ };
1683
1713
  } catch {
1684
1714
  }
1685
1715
  }
1686
- tab.page = void 0;
1687
- }
1688
- async attachPageHandlers(tab, page) {
1689
- await page.setViewportSize(this.viewport);
1690
- const cdp = await page.context().newCDPSession(page);
1691
- tab.cdp = cdp;
1692
- cdp.on("Page.screencastFrame", (payload) => {
1693
- cdp.send("Page.screencastFrameAck", { sessionId: payload.sessionId }).catch(() => {
1694
- });
1695
- const jpegBuf = Buffer.from(payload.data, "base64");
1696
- const packet = Buffer.allocUnsafe(1 + jpegBuf.length);
1697
- packet[0] = PACKET_VIDEO_JPEG;
1698
- jpegBuf.copy(packet, 1);
1699
- tab.lastFrameBuffer = packet;
1700
- this.recordFrameTick();
1701
- if (this.activeTabId === tab.id && tab.mode === "web") {
1702
- this.broadcastBinary(packet);
1716
+ return {
1717
+ positions: {},
1718
+ trashOrigins: {},
1719
+ preferences: {
1720
+ wallpaper: "mono-peaks",
1721
+ theme: "dark",
1722
+ iconSize: "md",
1723
+ autoArrange: false,
1724
+ sortBy: "name"
1703
1725
  }
1704
- });
1705
- const syncPageMeta = async () => {
1706
- if (page.isClosed() || tab.mode !== "web") return;
1707
- try {
1708
- const currentUrl = page.url();
1709
- if (currentUrl && currentUrl !== "about:blank") tab.url = currentUrl;
1710
- const title = await page.title().catch(() => "");
1711
- if (title) {
1712
- tab.title = title;
1726
+ };
1727
+ }
1728
+ saveMeta() {
1729
+ fs4.mkdirSync(this.instanceRoot, { recursive: true });
1730
+ fs4.writeFileSync(this.metaFile, JSON.stringify(this.meta, null, 2), "utf-8");
1731
+ }
1732
+ normalizeVirtualPath(vPath) {
1733
+ const cleaned = ("/" + (vPath || "").replace(/\\/g, "/")).replace(/\/+/g, "/").replace(/\/$/, "");
1734
+ return cleaned === "" ? "/" : cleaned;
1735
+ }
1736
+ resolveDiskPath(vPath) {
1737
+ const norm = this.normalizeVirtualPath(vPath);
1738
+ const resolved = path4.resolve(this.vfsRoot, "." + norm);
1739
+ if (!resolved.startsWith(this.vfsRoot)) {
1740
+ throw new Error("Ge\xE7ersiz dosya yolu eri\u015Fimi engellendi.");
1741
+ }
1742
+ return resolved;
1743
+ }
1744
+ ensureSeedWorkspace() {
1745
+ const marker = path4.join(this.instanceRoot, ".seeded");
1746
+ for (const dir of SYSTEM_DIRS) {
1747
+ fs4.mkdirSync(this.resolveDiskPath(dir), { recursive: true });
1748
+ }
1749
+ if (fs4.existsSync(marker)) return;
1750
+ fs4.mkdirSync(this.resolveDiskPath("/Desktop/Projeler"), { recursive: true });
1751
+ fs4.writeFileSync(
1752
+ this.resolveDiskPath("/Desktop/notlar.txt"),
1753
+ `Sanal Masa\xFCst\xFC (${this.desktopId})
1754
+ =========================
1755
+ - Bu masa\xFCst\xFC di\u011Fer sanal masa\xFCstlerinden tamamen ba\u011F\u0131ms\u0131z bir disk ve taray\u0131c\u0131 oturumuna sahiptir.
1756
+ - Dosyalar\u0131 a\xE7\u0131k klas\xF6r pencerelerinin veya Chromium penceresinin \xFCst\xFCne do\u011Frudan s\xFCr\xFCkleyip b\u0131rakabilirsiniz.
1757
+ `,
1758
+ "utf-8"
1759
+ );
1760
+ fs4.writeFileSync(
1761
+ this.resolveDiskPath("/Desktop/baslangic.html"),
1762
+ `<!DOCTYPE html>
1763
+ <html lang="tr">
1764
+ <head>
1765
+ <meta charset="UTF-8" />
1766
+ <title>Yerel Web Sayfas\u0131</title>
1767
+ <style>
1768
+ body {
1769
+ margin: 0;
1770
+ min-height: 100vh;
1771
+ display: grid;
1772
+ place-items: center;
1773
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
1774
+ background: #141416;
1775
+ color: #f5f5f7;
1776
+ }
1777
+ .box {
1778
+ background: #1c1c1e;
1779
+ border: 1px solid rgba(255,255,255,0.1);
1780
+ border-radius: 18px;
1781
+ padding: 36px;
1782
+ max-width: 460px;
1783
+ text-align: center;
1784
+ }
1785
+ h1 { margin: 0 0 10px; font-size: 22px; font-weight: 600; }
1786
+ p { color: #a1a1a6; line-height: 1.6; font-size: 14px; }
1787
+ </style>
1788
+ </head>
1789
+ <body>
1790
+ <div class="box">
1791
+ <h1>Yerel HTML Dosyas\u0131</h1>
1792
+ <p>Bu sayfa sanal masa\xFCst\xFCn\xFCzdeki <code>/Desktop/baslangic.html</code> dosyas\u0131ndan \xE7al\u0131\u015F\u0131yor. \xDCst \xE7ubuktan kayna\u011F\u0131 d\xFCzenleyip kaydedebilirsiniz.</p>
1793
+ </div>
1794
+ </body>
1795
+ </html>`,
1796
+ "utf-8"
1797
+ );
1798
+ fs4.writeFileSync(
1799
+ this.resolveDiskPath("/Desktop/Projeler/analiz.py"),
1800
+ `def hesapla(veriler: list[float]) -> dict:
1801
+ toplam = sum(veriler)
1802
+ return {"adet": len(veriler), "ortalama": round(toplam / max(len(veriler), 1), 2)}
1803
+
1804
+ if __name__ == "__main__":
1805
+ print(hesapla([14.2, 19.8, 22.4]))
1806
+ `,
1807
+ "utf-8"
1808
+ );
1809
+ fs4.writeFileSync(
1810
+ this.resolveDiskPath("/Desktop/Projeler/ayarlar.json"),
1811
+ JSON.stringify({ desktop: this.desktopId, browser: "chromium", isolated: true }, null, 2),
1812
+ "utf-8"
1813
+ );
1814
+ const zip = new AdmZip();
1815
+ zip.addFile("bilgi.txt", Buffer.from("Sa\u011F t\u0131klay\u0131p Buraya Ay\u0131kla se\xE7ene\u011Fiyle \xE7\u0131kartabilirsiniz.\n", "utf-8"));
1816
+ zip.writeZip(this.resolveDiskPath("/Desktop/arsiv.zip"));
1817
+ fs4.writeFileSync(marker, (/* @__PURE__ */ new Date()).toISOString(), "utf-8");
1818
+ }
1819
+ statNode(vPath) {
1820
+ const norm = this.normalizeVirtualPath(vPath);
1821
+ const diskPath = this.resolveDiskPath(norm);
1822
+ const stat = fs4.statSync(diskPath);
1823
+ const isDir = stat.isDirectory();
1824
+ const name = norm === "/" ? "Disk" : path4.posix.basename(norm);
1825
+ const parentPath = norm === "/" ? "" : path4.posix.dirname(norm);
1826
+ let childCount = 0;
1827
+ let size = stat.size;
1828
+ if (isDir) {
1829
+ const entries = fs4.readdirSync(diskPath).filter((e) => e !== ".DS_Store");
1830
+ childCount = entries.length;
1831
+ size = this.computeDirSize(diskPath);
1832
+ }
1833
+ return {
1834
+ name,
1835
+ path: norm,
1836
+ parentPath,
1837
+ isDir,
1838
+ extension: extractExtension(name, isDir),
1839
+ size,
1840
+ childCount,
1841
+ createdAt: stat.birthtime.toISOString(),
1842
+ modifiedAt: stat.mtime.toISOString(),
1843
+ originalPath: this.meta.trashOrigins[norm]
1844
+ };
1845
+ }
1846
+ computeDirSize(diskDir) {
1847
+ let total = 0;
1848
+ try {
1849
+ const entries = fs4.readdirSync(diskDir, { withFileTypes: true });
1850
+ for (const entry of entries) {
1851
+ if (entry.name === ".DS_Store") continue;
1852
+ const full = path4.join(diskDir, entry.name);
1853
+ if (entry.isDirectory()) {
1854
+ total += this.computeDirSize(full);
1713
1855
  } else {
1714
- try {
1715
- tab.title = new URL(tab.url).hostname || tab.url;
1716
- } catch {
1717
- tab.title = tab.url;
1718
- }
1719
- }
1720
- try {
1721
- const u = new URL(tab.url);
1722
- tab.favicon = `https://www.google.com/s2/favicons?domain=${u.hostname}&sz=64`;
1723
- } catch {
1724
- tab.favicon = "";
1725
- }
1726
- if (tab.cdp) {
1727
- const hist = await tab.cdp.send("Page.getNavigationHistory").catch(() => null);
1728
- if (hist) {
1729
- tab.canGoBack = hist.currentIndex > 0;
1730
- tab.canGoForward = hist.currentIndex < hist.entries.length - 1;
1731
- }
1856
+ total += fs4.statSync(full).size;
1732
1857
  }
1733
- } catch {
1734
1858
  }
1735
- this.broadcastTabs();
1736
- };
1737
- page.on("framenavigated", (frame) => {
1738
- if (frame === page.mainFrame()) syncPageMeta();
1739
- });
1740
- page.on("domcontentloaded", () => {
1741
- tab.isLoading = false;
1742
- syncPageMeta();
1743
- });
1744
- page.on("load", () => {
1745
- tab.isLoading = false;
1746
- syncPageMeta();
1747
- });
1748
- page.on("download", async (download) => {
1749
- try {
1750
- const suggested = download.suggestedFilename() || `indirilen-${Date.now()}`;
1751
- const downloadsDir = this.vfs.resolveDiskPath("/Downloads");
1752
- fs4.mkdirSync(downloadsDir, { recursive: true });
1753
- let finalName = suggested;
1754
- let counter = 2;
1755
- while (fs4.existsSync(path4.join(downloadsDir, finalName))) {
1756
- const extIdx = suggested.lastIndexOf(".");
1757
- finalName = extIdx > 0 ? `${suggested.slice(0, extIdx)} (${counter})${suggested.slice(extIdx)}` : `${suggested} (${counter})`;
1758
- counter++;
1859
+ } catch {
1860
+ }
1861
+ return total;
1862
+ }
1863
+ getSnapshot() {
1864
+ const nodes = [];
1865
+ const walk = (vDir) => {
1866
+ const diskDir = this.resolveDiskPath(vDir);
1867
+ if (!fs4.existsSync(diskDir)) return;
1868
+ if (vDir !== "/") {
1869
+ nodes.push(this.statNode(vDir));
1870
+ }
1871
+ const entries = fs4.readdirSync(diskDir).filter((e) => e !== ".DS_Store");
1872
+ for (const entry of entries) {
1873
+ const childVPath = vDir === "/" ? `/${entry}` : `${vDir}/${entry}`;
1874
+ const childDisk = this.resolveDiskPath(childVPath);
1875
+ const st = fs4.statSync(childDisk);
1876
+ if (st.isDirectory()) {
1877
+ walk(childVPath);
1878
+ } else {
1879
+ nodes.push(this.statNode(childVPath));
1759
1880
  }
1760
- await download.saveAs(path4.join(downloadsDir, finalName));
1761
- this.vfs.notifyChange();
1762
- this.broadcastJson({
1763
- type: "download_complete",
1764
- fileName: finalName,
1765
- virtualPath: `/Downloads/${finalName}`
1766
- });
1767
- } catch (err) {
1768
- this.broadcastJson({
1769
- type: "browser_error",
1770
- message: `\u0130ndirme ba\u015Far\u0131s\u0131z oldu: ${err.message}`
1771
- });
1772
1881
  }
1773
- });
1882
+ };
1883
+ walk("/");
1884
+ return { nodes, meta: this.meta };
1774
1885
  }
1775
- recordFrameTick() {
1776
- this.frameCounter++;
1777
- const now = Date.now();
1778
- const elapsed = now - this.lastFpsCheck;
1779
- if (elapsed >= 1e3) {
1780
- this.currentFps = Math.round(this.frameCounter * 1e3 / elapsed);
1781
- this.frameCounter = 0;
1782
- this.lastFpsCheck = now;
1886
+ getUniquePath(parentPath, desiredName) {
1887
+ const cleanName = desiredName.replace(/[\\/]/g, "").trim() || "Ads\u0131z";
1888
+ const normParent = this.normalizeVirtualPath(parentPath);
1889
+ let candidate = normParent === "/" ? `/${cleanName}` : `${normParent}/${cleanName}`;
1890
+ if (!fs4.existsSync(this.resolveDiskPath(candidate))) {
1891
+ return candidate;
1892
+ }
1893
+ const extIdx = cleanName.lastIndexOf(".");
1894
+ const hasExt = extIdx > 0 && extIdx < cleanName.length - 1;
1895
+ const stem = hasExt ? cleanName.slice(0, extIdx) : cleanName;
1896
+ const ext = hasExt ? cleanName.slice(extIdx) : "";
1897
+ let counter = 2;
1898
+ while (true) {
1899
+ const nextName = `${stem} (${counter})${ext}`;
1900
+ candidate = normParent === "/" ? `/${nextName}` : `${normParent}/${nextName}`;
1901
+ if (!fs4.existsSync(this.resolveDiskPath(candidate))) {
1902
+ return candidate;
1903
+ }
1904
+ counter++;
1783
1905
  }
1784
1906
  }
1785
- async startScreencast(tab) {
1786
- if (!tab.cdp || tab.streaming || tab.mode !== "web") return;
1787
- try {
1788
- await tab.cdp.send("Page.startScreencast", {
1789
- format: "jpeg",
1790
- quality: 76,
1791
- maxWidth: this.viewport.width,
1792
- maxHeight: this.viewport.height,
1793
- everyNthFrame: 1
1794
- });
1795
- tab.streaming = true;
1796
- } catch {
1797
- tab.streaming = false;
1907
+ createFolder(parentPath, name, pos) {
1908
+ const targetVPath = this.getUniquePath(parentPath, name || "Yeni Klas\xF6r");
1909
+ fs4.mkdirSync(this.resolveDiskPath(targetVPath), { recursive: true });
1910
+ if (pos) {
1911
+ this.meta.positions[targetVPath] = pos;
1912
+ this.saveMeta();
1798
1913
  }
1914
+ this.notifyChange();
1915
+ return this.statNode(targetVPath);
1799
1916
  }
1800
- async stopScreencast(tab) {
1801
- if (!tab.cdp || !tab.streaming) return;
1802
- try {
1803
- await tab.cdp.send("Page.stopScreencast");
1804
- } catch {
1917
+ createFile(parentPath, name, content, pos) {
1918
+ const targetVPath = this.getUniquePath(parentPath, name || "yeni-dosya.txt");
1919
+ const diskPath = this.resolveDiskPath(targetVPath);
1920
+ fs4.mkdirSync(path4.dirname(diskPath), { recursive: true });
1921
+ const finalContent = content !== void 0 ? content : this.getDefaultTemplate(targetVPath);
1922
+ fs4.writeFileSync(diskPath, finalContent, "utf-8");
1923
+ if (pos) {
1924
+ this.meta.positions[targetVPath] = pos;
1925
+ this.saveMeta();
1805
1926
  }
1806
- tab.streaming = false;
1927
+ this.notifyChange();
1928
+ return this.statNode(targetVPath);
1807
1929
  }
1808
- async captureImmediateFrame(tab) {
1809
- if (!tab.page || tab.page.isClosed() || tab.mode !== "web") return;
1810
- try {
1811
- const jpegBuf = await tab.page.screenshot({ type: "jpeg", quality: 78 });
1812
- const packet = Buffer.allocUnsafe(1 + jpegBuf.length);
1813
- packet[0] = PACKET_VIDEO_JPEG;
1814
- jpegBuf.copy(packet, 1);
1815
- tab.lastFrameBuffer = packet;
1816
- if (this.activeTabId === tab.id) {
1817
- this.broadcastBinary(packet);
1818
- }
1819
- } catch {
1930
+ getDefaultTemplate(vPath) {
1931
+ const ext = extractExtension(path4.posix.basename(vPath), false);
1932
+ switch (ext) {
1933
+ case "html":
1934
+ case "htm":
1935
+ return `<!DOCTYPE html>
1936
+ <html lang="tr">
1937
+ <head>
1938
+ <meta charset="UTF-8" />
1939
+ <title>Sayfa</title>
1940
+ </head>
1941
+ <body style="font-family:-apple-system,sans-serif;padding:2rem;background:#141416;color:#f5f5f7;">
1942
+ <h1>Merhaba</h1>
1943
+ <p>Yeni HTML belgesi haz\u0131r.</p>
1944
+ </body>
1945
+ </html>
1946
+ `;
1947
+ case "json":
1948
+ return `{
1949
+ "ad": "kayit",
1950
+ "aktif": true
1951
+ }
1952
+ `;
1953
+ case "md":
1954
+ return `# Ba\u015Fl\u0131k
1955
+
1956
+ Notlar\u0131n\u0131z\u0131 buraya yazabilirsiniz.
1957
+ `;
1958
+ case "py":
1959
+ return `def main():
1960
+ print("Merhaba!")
1961
+
1962
+ if __name__ == "__main__":
1963
+ main()
1964
+ `;
1965
+ case "js":
1966
+ case "ts":
1967
+ return `console.log("Haz\u0131r");
1968
+ `;
1969
+ case "css":
1970
+ return `body {
1971
+ margin: 0;
1972
+ background: #141416;
1973
+ color: #f5f5f7;
1974
+ }
1975
+ `;
1976
+ case "csv":
1977
+ return `id,baslik,deger
1978
+ 1,Kalem A,100
1979
+ 2,Kalem B,250
1980
+ `;
1981
+ case "sql":
1982
+ return `SELECT * FROM kayitlar LIMIT 10;
1983
+ `;
1984
+ case "svg":
1985
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
1986
+ <rect width="200" height="200" rx="24" fill="#1c1c1e"/>
1987
+ <circle cx="100" cy="100" r="52" fill="#e5e5ea"/>
1988
+ </svg>
1989
+ `;
1990
+ default:
1991
+ return "";
1820
1992
  }
1821
1993
  }
1822
- async navigate(tabId, rawInput) {
1823
- const tab = this.tabs.get(tabId);
1824
- if (!tab) return;
1825
- const parsed = normalizeUserUrl(rawInput);
1826
- tab.mode = parsed.mode;
1827
- tab.filePath = parsed.filePath;
1828
- tab.url = parsed.url;
1829
- if (parsed.mode === "newtab") {
1830
- await this.stopScreencast(tab);
1831
- tab.title = "Yeni Sekme";
1832
- tab.favicon = "";
1833
- tab.isLoading = false;
1834
- this.broadcastTabs();
1835
- return;
1994
+ renameNode(vPath, newName) {
1995
+ const norm = this.normalizeVirtualPath(vPath);
1996
+ if (SYSTEM_DIRS.includes(norm) || norm === "/") {
1997
+ throw new Error("Sistem ana dizinleri yeniden adland\u0131r\u0131lamaz.");
1836
1998
  }
1837
- if (parsed.mode === "file") {
1838
- await this.stopScreencast(tab);
1839
- tab.title = path4.posix.basename(parsed.filePath || "Dosya");
1840
- tab.favicon = "";
1841
- tab.isLoading = false;
1842
- this.broadcastTabs();
1843
- return;
1999
+ const cleanName = newName.replace(/[\\/]/g, "").trim();
2000
+ if (!cleanName) {
2001
+ throw new Error("Dosya veya klas\xF6r ad\u0131 bo\u015F olamaz.");
1844
2002
  }
1845
- tab.isLoading = true;
1846
- try {
1847
- tab.title = new URL(parsed.url).hostname || parsed.url;
1848
- } catch {
1849
- tab.title = parsed.url;
2003
+ const parent = path4.posix.dirname(norm);
2004
+ const nextVPath = parent === "/" ? `/${cleanName}` : `${parent}/${cleanName}`;
2005
+ if (nextVPath === norm) {
2006
+ return this.statNode(norm);
1850
2007
  }
1851
- this.broadcastTabs();
1852
- try {
1853
- const ctx = await this.ensureContext();
1854
- if (!tab.page || tab.page.isClosed()) {
1855
- this.internalPageCreating++;
1856
- try {
1857
- const page = await ctx.newPage();
1858
- tab.page = page;
1859
- await this.attachPageHandlers(tab, page);
1860
- } finally {
1861
- this.internalPageCreating--;
1862
- }
2008
+ if (fs4.existsSync(this.resolveDiskPath(nextVPath))) {
2009
+ throw new Error(`"${cleanName}" ad\u0131nda bir \xF6\u011Fe zaten mevcut.`);
2010
+ }
2011
+ fs4.renameSync(this.resolveDiskPath(norm), this.resolveDiskPath(nextVPath));
2012
+ const updatedPositions = {};
2013
+ for (const [k, v] of Object.entries(this.meta.positions)) {
2014
+ if (k === norm) updatedPositions[nextVPath] = v;
2015
+ else if (k.startsWith(norm + "/")) updatedPositions[nextVPath + k.slice(norm.length)] = v;
2016
+ else updatedPositions[k] = v;
2017
+ }
2018
+ this.meta.positions = updatedPositions;
2019
+ this.saveMeta();
2020
+ this.notifyChange();
2021
+ return this.statNode(nextVPath);
2022
+ }
2023
+ moveNodes(paths, targetDir) {
2024
+ const normTarget = this.normalizeVirtualPath(targetDir);
2025
+ const targetDisk = this.resolveDiskPath(normTarget);
2026
+ if (!fs4.existsSync(targetDisk) || !fs4.statSync(targetDisk).isDirectory()) {
2027
+ throw new Error("Hedef klas\xF6r bulunamad\u0131.");
2028
+ }
2029
+ const moved = [];
2030
+ for (const rawPath of paths) {
2031
+ const src = this.normalizeVirtualPath(rawPath);
2032
+ if (SYSTEM_DIRS.includes(src) || src === "/" || src === normTarget) continue;
2033
+ if (normTarget.startsWith(src + "/")) {
2034
+ throw new Error("Bir klas\xF6r kendi alt klas\xF6r\xFCn\xFCn i\xE7ine ta\u015F\u0131namaz.");
1863
2035
  }
1864
- if (this.activeTabId === tab.id) {
1865
- await this.startScreencast(tab);
2036
+ const base = path4.posix.basename(src);
2037
+ const dest = path4.posix.dirname(src) === normTarget ? src : this.getUniquePath(normTarget, base);
2038
+ if (dest !== src) {
2039
+ fs4.renameSync(this.resolveDiskPath(src), this.resolveDiskPath(dest));
2040
+ delete this.meta.positions[src];
1866
2041
  }
1867
- await tab.page.goto(parsed.url, {
1868
- waitUntil: "domcontentloaded",
1869
- timeout: 25e3
1870
- });
1871
- tab.isLoading = false;
1872
- this.broadcastTabs();
1873
- await this.captureImmediateFrame(tab);
1874
- } catch (err) {
1875
- tab.isLoading = false;
1876
- this.broadcastTabs();
1877
- this.broadcastJson({
1878
- type: "browser_error",
1879
- tabId: tab.id,
1880
- message: `Sayfa y\xFCklenemedi: ${err.message}`
1881
- });
2042
+ moved.push(this.statNode(dest));
2043
+ }
2044
+ this.saveMeta();
2045
+ this.notifyChange();
2046
+ return moved;
2047
+ }
2048
+ copyNodes(paths, targetDir) {
2049
+ const normTarget = this.normalizeVirtualPath(targetDir);
2050
+ const copied = [];
2051
+ for (const rawPath of paths) {
2052
+ const src = this.normalizeVirtualPath(rawPath);
2053
+ if (src === "/") continue;
2054
+ if (normTarget.startsWith(src + "/")) {
2055
+ throw new Error("Bir klas\xF6r kendi alt klas\xF6r\xFCn\xFCn i\xE7ine kopyalanamaz.");
2056
+ }
2057
+ const base = path4.posix.basename(src);
2058
+ const desired = path4.posix.dirname(src) === normTarget ? this.makeCopyName(base) : base;
2059
+ const dest = this.getUniquePath(normTarget, desired);
2060
+ fs4.cpSync(this.resolveDiskPath(src), this.resolveDiskPath(dest), { recursive: true });
2061
+ copied.push(this.statNode(dest));
2062
+ }
2063
+ this.notifyChange();
2064
+ return copied;
2065
+ }
2066
+ makeCopyName(name) {
2067
+ const idx = name.lastIndexOf(".");
2068
+ if (idx > 0 && idx < name.length - 1) {
2069
+ return `${name.slice(0, idx)} kopyas\u0131${name.slice(idx)}`;
2070
+ }
2071
+ return `${name} kopyas\u0131`;
2072
+ }
2073
+ trashNodes(paths) {
2074
+ for (const rawPath of paths) {
2075
+ const src = this.normalizeVirtualPath(rawPath);
2076
+ if (SYSTEM_DIRS.includes(src) || src === "/") continue;
2077
+ if (src.startsWith("/.trash/")) {
2078
+ fs4.rmSync(this.resolveDiskPath(src), { recursive: true, force: true });
2079
+ delete this.meta.trashOrigins[src];
2080
+ continue;
2081
+ }
2082
+ const dest = this.getUniquePath("/.trash", path4.posix.basename(src));
2083
+ fs4.renameSync(this.resolveDiskPath(src), this.resolveDiskPath(dest));
2084
+ this.meta.trashOrigins[dest] = src;
2085
+ delete this.meta.positions[src];
1882
2086
  }
2087
+ this.saveMeta();
2088
+ this.notifyChange();
1883
2089
  }
1884
- async goBack(tabId) {
1885
- const tab = this.tabs.get(tabId);
1886
- if (!tab?.page || tab.mode !== "web") return;
1887
- tab.isLoading = true;
1888
- this.broadcastTabs();
1889
- await tab.page.goBack({ waitUntil: "domcontentloaded" }).catch(() => {
1890
- });
1891
- tab.isLoading = false;
1892
- this.broadcastTabs();
1893
- await this.captureImmediateFrame(tab);
2090
+ restoreNodes(trashPaths) {
2091
+ const restored = [];
2092
+ for (const rawPath of trashPaths) {
2093
+ const src = this.normalizeVirtualPath(rawPath);
2094
+ if (!src.startsWith("/.trash/")) continue;
2095
+ const origin = this.meta.trashOrigins[src] || `/Desktop/${path4.posix.basename(src)}`;
2096
+ const originParent = path4.posix.dirname(origin);
2097
+ fs4.mkdirSync(this.resolveDiskPath(originParent), { recursive: true });
2098
+ const finalDest = this.getUniquePath(originParent, path4.posix.basename(origin));
2099
+ fs4.renameSync(this.resolveDiskPath(src), this.resolveDiskPath(finalDest));
2100
+ delete this.meta.trashOrigins[src];
2101
+ restored.push(this.statNode(finalDest));
2102
+ }
2103
+ this.saveMeta();
2104
+ this.notifyChange();
2105
+ return restored;
1894
2106
  }
1895
- async goForward(tabId) {
1896
- const tab = this.tabs.get(tabId);
1897
- if (!tab?.page || tab.mode !== "web") return;
1898
- tab.isLoading = true;
1899
- this.broadcastTabs();
1900
- await tab.page.goForward({ waitUntil: "domcontentloaded" }).catch(() => {
1901
- });
1902
- tab.isLoading = false;
1903
- this.broadcastTabs();
1904
- await this.captureImmediateFrame(tab);
2107
+ deletePermanently(paths) {
2108
+ for (const rawPath of paths) {
2109
+ const src = this.normalizeVirtualPath(rawPath);
2110
+ if (SYSTEM_DIRS.includes(src) || src === "/") continue;
2111
+ fs4.rmSync(this.resolveDiskPath(src), { recursive: true, force: true });
2112
+ delete this.meta.trashOrigins[src];
2113
+ delete this.meta.positions[src];
2114
+ }
2115
+ this.saveMeta();
2116
+ this.notifyChange();
1905
2117
  }
1906
- async reload(tabId) {
1907
- const tab = this.tabs.get(tabId);
1908
- if (!tab) return;
1909
- if (tab.mode === "web" && tab.page) {
1910
- tab.isLoading = true;
1911
- this.broadcastTabs();
1912
- await tab.page.reload({ waitUntil: "domcontentloaded" }).catch(() => {
1913
- });
1914
- tab.isLoading = false;
1915
- this.broadcastTabs();
1916
- await this.captureImmediateFrame(tab);
1917
- } else {
1918
- this.broadcastTabs();
2118
+ emptyTrash() {
2119
+ const trashDisk = this.resolveDiskPath("/.trash");
2120
+ if (fs4.existsSync(trashDisk)) {
2121
+ for (const item of fs4.readdirSync(trashDisk)) {
2122
+ fs4.rmSync(path4.join(trashDisk, item), { recursive: true, force: true });
2123
+ }
1919
2124
  }
2125
+ this.meta.trashOrigins = {};
2126
+ this.saveMeta();
2127
+ this.notifyChange();
1920
2128
  }
1921
- async setViewport(width, height) {
1922
- const w = Math.max(360, Math.min(1920, Math.round(width)));
1923
- const h = Math.max(260, Math.min(1200, Math.round(height)));
1924
- if (Math.abs(this.viewport.width - w) < 4 && Math.abs(this.viewport.height - h) < 4) return;
1925
- this.viewport = { width: w, height: h };
1926
- const active = this.activeTabId ? this.tabs.get(this.activeTabId) : void 0;
1927
- if (active?.mode === "web" && active.page && !active.page.isClosed()) {
1928
- try {
1929
- await this.stopScreencast(active);
1930
- await active.page.setViewportSize(this.viewport);
1931
- await this.startScreencast(active);
1932
- await this.captureImmediateFrame(active);
1933
- } catch {
2129
+ compressToZip(paths, targetDir, zipName) {
2130
+ if (!paths.length) throw new Error("Ar\u015Fivlenecek \xF6\u011Fe se\xE7ilmedi.");
2131
+ const zip = new AdmZip();
2132
+ for (const rawPath of paths) {
2133
+ const src = this.normalizeVirtualPath(rawPath);
2134
+ const diskSrc = this.resolveDiskPath(src);
2135
+ if (!fs4.existsSync(diskSrc)) continue;
2136
+ const st = fs4.statSync(diskSrc);
2137
+ if (st.isDirectory()) {
2138
+ zip.addLocalFolder(diskSrc, path4.posix.basename(src));
2139
+ } else {
2140
+ zip.addLocalFile(diskSrc);
1934
2141
  }
1935
2142
  }
2143
+ const baseName = zipName || (paths.length === 1 ? `${path4.posix.basename(paths[0]).replace(/\.[^.]+$/, "")}.zip` : "arsiv.zip");
2144
+ const finalName = baseName.toLowerCase().endsWith(".zip") ? baseName : `${baseName}.zip`;
2145
+ const destVPath = this.getUniquePath(targetDir, finalName);
2146
+ zip.writeZip(this.resolveDiskPath(destVPath));
2147
+ this.notifyChange();
2148
+ return this.statNode(destVPath);
1936
2149
  }
1937
- handleInput(payload) {
1938
- const tabId = payload.tabId || this.activeTabId;
1939
- if (!tabId) return;
1940
- const tab = this.tabs.get(tabId);
1941
- if (!tab || tab.mode !== "web" || !tab.page || !tab.cdp || tab.page.isClosed()) return;
1942
- const kind = payload.kind;
1943
- if (kind === "mouse") {
1944
- const eventType = payload.eventType;
1945
- tab.cdp.send("Input.dispatchMouseEvent", {
1946
- type: eventType,
1947
- x: Number(payload.x) || 0,
1948
- y: Number(payload.y) || 0,
1949
- button: payload.button || "none",
1950
- clickCount: Number(payload.clickCount) || 1,
1951
- modifiers: Number(payload.modifiers) || 0,
1952
- deltaX: Number(payload.deltaX) || 0,
1953
- deltaY: Number(payload.deltaY) || 0
1954
- }).catch(() => {
1955
- });
1956
- return;
2150
+ extractZip(zipVPath, targetDir) {
2151
+ const normZip = this.normalizeVirtualPath(zipVPath);
2152
+ const diskZip = this.resolveDiskPath(normZip);
2153
+ if (!fs4.existsSync(diskZip)) throw new Error("Ar\u015Fiv dosyas\u0131 bulunamad\u0131.");
2154
+ const parent = targetDir ? this.normalizeVirtualPath(targetDir) : path4.posix.dirname(normZip);
2155
+ const folderBase = path4.posix.basename(normZip).replace(/\.zip$/i, "") || "ayiklanan";
2156
+ const destFolderVPath = this.getUniquePath(parent, folderBase);
2157
+ const destDisk = this.resolveDiskPath(destFolderVPath);
2158
+ fs4.mkdirSync(destDisk, { recursive: true });
2159
+ const zip = new AdmZip(diskZip);
2160
+ zip.extractAllTo(destDisk, true);
2161
+ this.notifyChange();
2162
+ return this.statNode(destFolderVPath);
2163
+ }
2164
+ readTextFile(vPath) {
2165
+ const norm = this.normalizeVirtualPath(vPath);
2166
+ const disk = this.resolveDiskPath(norm);
2167
+ if (!fs4.existsSync(disk) || fs4.statSync(disk).isDirectory()) {
2168
+ throw new Error("Dosya okunamad\u0131.");
1957
2169
  }
1958
- if (kind === "key") {
1959
- const key = String(payload.key || "");
1960
- const ctrlOrMeta = Boolean(payload.ctrlKey || payload.metaKey);
1961
- const shiftKey = Boolean(payload.shiftKey);
1962
- const altKey = Boolean(payload.altKey);
1963
- const modPrefix = process.platform === "darwin" ? "Meta" : "Control";
1964
- if (ctrlOrMeta && key.length === 1) {
1965
- const lower = key.toLowerCase();
1966
- if (["a", "c", "x", "z", "y", "f"].includes(lower)) {
1967
- tab.page.keyboard.press(`${modPrefix}+${shiftKey ? "Shift+" : ""}${lower}`).catch(() => {
1968
- });
1969
- return;
1970
- }
1971
- }
1972
- const specialKeys = /* @__PURE__ */ new Set([
1973
- "Enter",
1974
- "Backspace",
1975
- "Tab",
1976
- "Escape",
1977
- "Delete",
1978
- "ArrowLeft",
1979
- "ArrowRight",
1980
- "ArrowUp",
1981
- "ArrowDown",
1982
- "Home",
1983
- "End",
1984
- "PageUp",
1985
- "PageDown",
1986
- "F5"
1987
- ]);
1988
- if (specialKeys.has(key)) {
1989
- const mods = [];
1990
- if (ctrlOrMeta) mods.push(modPrefix);
1991
- if (altKey) mods.push("Alt");
1992
- if (shiftKey) mods.push("Shift");
1993
- tab.page.keyboard.press([...mods, key].join("+")).catch(() => {
1994
- });
1995
- } else if (key.length === 1 && !ctrlOrMeta) {
1996
- tab.page.keyboard.insertText(key).catch(() => {
1997
- });
1998
- }
1999
- return;
2170
+ const buf = fs4.readFileSync(disk);
2171
+ return {
2172
+ content: buf.toString("utf-8"),
2173
+ node: this.statNode(norm)
2174
+ };
2175
+ }
2176
+ writeTextFile(vPath, content) {
2177
+ const norm = this.normalizeVirtualPath(vPath);
2178
+ const disk = this.resolveDiskPath(norm);
2179
+ fs4.mkdirSync(path4.dirname(disk), { recursive: true });
2180
+ fs4.writeFileSync(disk, content, "utf-8");
2181
+ this.notifyChange();
2182
+ return this.statNode(norm);
2183
+ }
2184
+ saveUploadedBuffer(parentPath, originalName, buffer) {
2185
+ const destVPath = this.getUniquePath(parentPath, originalName);
2186
+ const disk = this.resolveDiskPath(destVPath);
2187
+ fs4.mkdirSync(path4.dirname(disk), { recursive: true });
2188
+ fs4.writeFileSync(disk, buffer);
2189
+ this.notifyChange();
2190
+ return this.statNode(destVPath);
2191
+ }
2192
+ updateMeta(partial) {
2193
+ if (partial.positions) {
2194
+ this.meta.positions = { ...this.meta.positions, ...partial.positions };
2000
2195
  }
2001
- if (kind === "paste") {
2002
- const text = String(payload.text || "");
2003
- if (text) tab.page.keyboard.insertText(text).catch(() => {
2004
- });
2196
+ if (partial.preferences) {
2197
+ this.meta.preferences = { ...this.meta.preferences, ...partial.preferences };
2198
+ if (!this.meta.preferences.customWallpaper) {
2199
+ delete this.meta.preferences.customWallpaper;
2200
+ }
2005
2201
  }
2202
+ this.saveMeta();
2203
+ return this.meta;
2006
2204
  }
2007
- async dispose() {
2008
- for (const tab of this.tabs.values()) {
2009
- await this.cleanupTabPage(tab);
2205
+ saveCustomWallpaper(originalName, buffer) {
2206
+ const wpDir = path4.join(this.instanceRoot, "wallpapers");
2207
+ fs4.mkdirSync(wpDir, { recursive: true });
2208
+ const rawExt = path4.extname(originalName || "").toLowerCase().replace(/[^.a-z0-9]/g, "") || ".png";
2209
+ const fileName = `wp-${Date.now()}${rawExt}`;
2210
+ fs4.writeFileSync(path4.join(wpDir, fileName), buffer);
2211
+ this.meta.preferences.wallpaper = "custom";
2212
+ this.meta.preferences.customWallpaper = fileName;
2213
+ this.saveMeta();
2214
+ return this.meta;
2215
+ }
2216
+ setWallpaperFromVfs(vPath) {
2217
+ const disk = this.resolveDiskPath(vPath);
2218
+ if (!fs4.existsSync(disk) || fs4.statSync(disk).isDirectory()) {
2219
+ throw new Error("Resim dosyas\u0131 bulunamad\u0131.");
2010
2220
  }
2011
- this.tabs.clear();
2012
- this.tabOrder = [];
2013
- if (this.context) {
2014
- await this.context.close().catch(() => {
2015
- });
2016
- this.context = null;
2221
+ const buf = fs4.readFileSync(disk);
2222
+ return this.saveCustomWallpaper(path4.basename(disk), buf);
2223
+ }
2224
+ resolveWallpaperPath(fileName) {
2225
+ const safeName = path4.basename(fileName || "");
2226
+ const wpDir = path4.join(this.instanceRoot, "wallpapers");
2227
+ const resolved = path4.resolve(wpDir, safeName);
2228
+ if (!resolved.startsWith(wpDir)) {
2229
+ throw new Error("Ge\xE7ersiz arka plan yolu.");
2017
2230
  }
2231
+ return resolved;
2232
+ }
2233
+ clearPositions() {
2234
+ this.meta.positions = {};
2235
+ this.saveMeta();
2236
+ return this.meta;
2018
2237
  }
2019
2238
  };
2020
2239
 
@@ -2142,7 +2361,7 @@ var AuthManager = class {
2142
2361
  import fs5 from "node:fs";
2143
2362
  import path5 from "node:path";
2144
2363
  import { fileURLToPath } from "node:url";
2145
- import { spawn as spawn2 } from "node:child_process";
2364
+ import { spawn as spawn3 } from "node:child_process";
2146
2365
  function resolveHelperPath(helperName) {
2147
2366
  const here = path5.dirname(fileURLToPath(import.meta.url));
2148
2367
  const candidates = [
@@ -2164,7 +2383,7 @@ var TerminalManager = class {
2164
2383
  if (existing) return existing;
2165
2384
  const scriptPath = resolveHelperPath("pty_bridge.py");
2166
2385
  const safeCwd = fs5.existsSync(cwd) ? cwd : process.cwd();
2167
- const proc = spawn2("python3", ["-u", scriptPath, safeCwd, String(cols), String(rows)], {
2386
+ const proc = spawn3("python3", ["-u", scriptPath, safeCwd, String(cols), String(rows)], {
2168
2387
  cwd: safeCwd,
2169
2388
  env: {
2170
2389
  ...process.env,
@@ -2200,13 +2419,18 @@ var TerminalManager = class {
2200
2419
  const txt = chunk.toString("utf-8");
2201
2420
  for (const fn of listeners) fn({ type: "output", data: txt });
2202
2421
  });
2422
+ proc.stdin.on("error", () => {
2423
+ });
2203
2424
  proc.on("exit", (code) => {
2204
2425
  for (const fn of listeners) fn({ type: "exit", code: code ?? 0 });
2205
2426
  this.sessions.delete(sessionId);
2206
2427
  });
2207
2428
  const sendCmd = (payload) => {
2208
- if (proc.stdin.writable) {
2209
- proc.stdin.write(JSON.stringify(payload) + "\n");
2429
+ if (!proc.killed && proc.stdin.writable) {
2430
+ try {
2431
+ proc.stdin.write(JSON.stringify(payload) + "\n");
2432
+ } catch {
2433
+ }
2210
2434
  }
2211
2435
  };
2212
2436
  const session = {
@@ -2255,7 +2479,7 @@ var TerminalManager = class {
2255
2479
  import fs6 from "node:fs";
2256
2480
  import os4 from "node:os";
2257
2481
  import path6 from "node:path";
2258
- import { execSync as execSync2, spawn as spawn3 } from "node:child_process";
2482
+ import { execSync as execSync2, spawn as spawn4 } from "node:child_process";
2259
2483
  var DEFAULT_SCREEN_W = 1440;
2260
2484
  var DEFAULT_SCREEN_H = 840;
2261
2485
  var PROFILE_LOCKED_APPS = /* @__PURE__ */ new Set([
@@ -2399,7 +2623,7 @@ var LinuxAppSession = class {
2399
2623
  fs6.mkdirSync(this.tempDir, { recursive: true });
2400
2624
  const obRcPath = path6.join(this.tempDir, "rc.xml");
2401
2625
  fs6.writeFileSync(obRcPath, buildOpenboxRcXml(), "utf-8");
2402
- this.xvfbProc = spawn3(
2626
+ this.xvfbProc = spawn4(
2403
2627
  "Xvfb",
2404
2628
  [
2405
2629
  this.displayStr,
@@ -2438,7 +2662,7 @@ var LinuxAppSession = class {
2438
2662
  };
2439
2663
  delete baseEnv.DBUS_SESSION_BUS_ADDRESS;
2440
2664
  this.baseEnv = baseEnv;
2441
- this.openboxProc = spawn3("openbox", ["--config-file", obRcPath], {
2665
+ this.openboxProc = spawn4("openbox", ["--config-file", obRcPath], {
2442
2666
  env: baseEnv,
2443
2667
  stdio: "ignore"
2444
2668
  });
@@ -2455,7 +2679,7 @@ var LinuxAppSession = class {
2455
2679
  try {
2456
2680
  execSync2("pactl info", { stdio: "ignore", timeout: 1200 });
2457
2681
  } catch {
2458
- spawn3(
2682
+ spawn4(
2459
2683
  "pulseaudio",
2460
2684
  ["--daemonize=yes", "--exit-idle-time=-1", "--disallow-module-loading=0", "--no-cpu-limit"],
2461
2685
  { stdio: "ignore" }
@@ -2477,7 +2701,7 @@ var LinuxAppSession = class {
2477
2701
  }
2478
2702
  startAudioCapture(sinkName) {
2479
2703
  try {
2480
- const parec = spawn3(
2704
+ const parec = spawn4(
2481
2705
  "parec",
2482
2706
  ["-d", `${sinkName}.monitor`, "--rate=24000", "--channels=1", "--format=s16le", "--latency-msec=45"],
2483
2707
  { stdio: ["ignore", "pipe", "ignore"] }
@@ -2519,7 +2743,7 @@ var LinuxAppSession = class {
2519
2743
  }
2520
2744
  startX11Bridge(baseEnv) {
2521
2745
  const scriptPath = resolveHelperPath("x11_bridge.py");
2522
- const proc = spawn3(
2746
+ const proc = spawn4(
2523
2747
  "python3",
2524
2748
  ["-u", scriptPath, this.displayStr, String(this.screenWidth), String(this.screenHeight)],
2525
2749
  {
@@ -2528,6 +2752,8 @@ var LinuxAppSession = class {
2528
2752
  }
2529
2753
  );
2530
2754
  this.x11BridgeProc = proc;
2755
+ proc.stdin?.on("error", () => {
2756
+ });
2531
2757
  proc.stderr?.on("data", (err) => {
2532
2758
  const msg = err.toString("utf-8").trim();
2533
2759
  if (msg) console.error(`[x11_bridge ${this.displayStr}]`, msg);
@@ -2792,7 +3018,7 @@ var LinuxAppSession = class {
2792
3018
  }
2793
3019
  launchTargetApp(baseEnv) {
2794
3020
  const { cmd, cwd } = this.buildLaunchCommand(false);
2795
- this.appProc = spawn3("/bin/bash", ["-c", `exec ${cmd}`], {
3021
+ this.appProc = spawn4("/bin/bash", ["-c", `exec ${cmd}`], {
2796
3022
  cwd,
2797
3023
  env: {
2798
3024
  ...baseEnv,
@@ -2832,7 +3058,7 @@ var LinuxAppSession = class {
2832
3058
  spawnExtraWindow(customCommand) {
2833
3059
  if (this.closed) return;
2834
3060
  const { cmd, cwd } = customCommand ? { cmd: customCommand, cwd: path6.join(this.desktopDataRoot, "vfs", "Desktop") } : this.buildLaunchCommand(true);
2835
- const child = spawn3("/bin/bash", ["-c", cmd], {
3061
+ const child = spawn4("/bin/bash", ["-c", cmd], {
2836
3062
  cwd,
2837
3063
  detached: true,
2838
3064
  env: {
@@ -2856,7 +3082,7 @@ var LinuxAppSession = class {
2856
3082
  const scriptPath = resolveHelperPath("x11_streamer.py");
2857
3083
  const jpegQual = Math.max(60, Math.min(88, 92 - this.quality * 4));
2858
3084
  const initTargetWid = view.targetMode === "pixmap" ? String(view.targetWid || 0) : "0";
2859
- const proc = spawn3(
3085
+ const proc = spawn4(
2860
3086
  "python3",
2861
3087
  [
2862
3088
  "-u",
@@ -2876,6 +3102,8 @@ var LinuxAppSession = class {
2876
3102
  }
2877
3103
  );
2878
3104
  view.streamerProc = proc;
3105
+ proc.stdin?.on("error", () => {
3106
+ });
2879
3107
  proc.stderr?.on("data", (err) => {
2880
3108
  const msg = err.toString("utf-8").trim();
2881
3109
  if (msg) console.error(`[x11_streamer ${this.displayStr}/${view.viewId}]`, msg);
@@ -2896,12 +3124,22 @@ var LinuxAppSession = class {
2896
3124
  const frame = Buffer.from(acc.subarray(4, 4 + frameLen));
2897
3125
  acc = acc.subarray(4 + frameLen);
2898
3126
  if (!view.hasGeometry) {
2899
- if (proc.stdin?.writable) proc.stdin.write("a\n");
3127
+ if (proc.stdin?.writable) {
3128
+ try {
3129
+ proc.stdin.write("a\n");
3130
+ } catch {
3131
+ }
3132
+ }
2900
3133
  continue;
2901
3134
  }
2902
3135
  view.lastFrame = frame;
2903
3136
  if (view.subscribers.size === 0) {
2904
- if (proc.stdin?.writable) proc.stdin.write("a\n");
3137
+ if (proc.stdin?.writable) {
3138
+ try {
3139
+ proc.stdin.write("a\n");
3140
+ } catch {
3141
+ }
3142
+ }
2905
3143
  continue;
2906
3144
  }
2907
3145
  let ackSent = false;
@@ -2909,7 +3147,10 @@ var LinuxAppSession = class {
2909
3147
  if (!ackSent) {
2910
3148
  ackSent = true;
2911
3149
  if (!this.closed && proc.stdin?.writable) {
2912
- proc.stdin.write("a\n");
3150
+ try {
3151
+ proc.stdin.write("a\n");
3152
+ } catch {
3153
+ }
2913
3154
  }
2914
3155
  }
2915
3156
  };
@@ -2962,7 +3203,7 @@ var LinuxAppSession = class {
2962
3203
  String(this.quality + 1),
2963
3204
  "-"
2964
3205
  ];
2965
- const ff = spawn3("ffmpeg", args, { stdio: ["ignore", "pipe", "ignore"] });
3206
+ const ff = spawn4("ffmpeg", args, { stdio: ["ignore", "pipe", "ignore"] });
2966
3207
  view.streamerProc = ff;
2967
3208
  let acc = Buffer.alloc(0);
2968
3209
  const SOI = Buffer.from([255, 216]);
@@ -2999,9 +3240,12 @@ var LinuxAppSession = class {
2999
3240
  }
3000
3241
  resizeViewCapture(view, evenW, evenH) {
3001
3242
  if (view.streamerMode === "xdamage" && view.streamerProc?.stdin?.writable) {
3002
- view.streamerProc.stdin.write(
3003
- JSON.stringify({ type: "resize", width: evenW, height: evenH }) + "\n"
3004
- );
3243
+ try {
3244
+ view.streamerProc.stdin.write(
3245
+ JSON.stringify({ type: "resize", width: evenW, height: evenH }) + "\n"
3246
+ );
3247
+ } catch {
3248
+ }
3005
3249
  return;
3006
3250
  }
3007
3251
  if (view.resizeTimer) clearTimeout(view.resizeTimer);
@@ -3039,13 +3283,16 @@ var LinuxAppSession = class {
3039
3283
  type: "view_geometry",
3040
3284
  width: view.width,
3041
3285
  height: view.height,
3042
- initial: true
3286
+ initial: view.viewId === "main"
3043
3287
  });
3044
3288
  }
3045
3289
  if (view.lastFrame && view.hasGeometry) {
3046
3290
  sub.onVideoFrame(view.lastFrame);
3047
3291
  } else if (view.streamerMode === "xdamage" && view.streamerProc?.stdin?.writable) {
3048
- view.streamerProc.stdin.write(JSON.stringify({ type: "refresh" }) + "\n");
3292
+ try {
3293
+ view.streamerProc.stdin.write(JSON.stringify({ type: "refresh" }) + "\n");
3294
+ } catch {
3295
+ }
3049
3296
  }
3050
3297
  return () => {
3051
3298
  view.subscribers.delete(sub);
@@ -3053,7 +3300,10 @@ var LinuxAppSession = class {
3053
3300
  }
3054
3301
  sendInput(msg, viewId = "main") {
3055
3302
  if (this.closed || !this.x11BridgeProc?.stdin?.writable) return;
3056
- this.x11BridgeProc.stdin.write(JSON.stringify({ ...msg, view: msg.view || viewId }) + "\n");
3303
+ try {
3304
+ this.x11BridgeProc.stdin.write(JSON.stringify({ ...msg, view: msg.view || viewId }) + "\n");
3305
+ } catch {
3306
+ }
3057
3307
  }
3058
3308
  resizeView(viewId, width, height) {
3059
3309
  if (this.closed) return;
@@ -3205,7 +3455,7 @@ import http from "node:http";
3205
3455
  import net from "node:net";
3206
3456
  import path7 from "node:path";
3207
3457
  import zlib from "node:zlib";
3208
- import { execSync as execSync3, spawn as spawn4 } from "node:child_process";
3458
+ import { execSync as execSync3, spawn as spawn5 } from "node:child_process";
3209
3459
  function resolveCodeServeBinary() {
3210
3460
  if (fs7.existsSync("/usr/share/code/bin/code-tunnel")) {
3211
3461
  return "/usr/share/code/bin/code-tunnel";
@@ -3275,7 +3525,7 @@ var VSCodeServerManager = class {
3275
3525
  }
3276
3526
  this.ready = false;
3277
3527
  this.statusMessage = "VS Code Web motoru ba\u015Flat\u0131l\u0131yor (ilk a\xE7\u0131l\u0131\u015Fta bile\u015Fenler indirilebilir)...";
3278
- const proc = spawn4(
3528
+ const proc = spawn5(
3279
3529
  bin,
3280
3530
  [
3281
3531
  "serve-web",
@@ -3489,7 +3739,7 @@ var VSCodeServerManager = class {
3489
3739
  };
3490
3740
 
3491
3741
  // server/index.ts
3492
- var TAMGA_VERSION = "1.1.7";
3742
+ var TAMGA_VERSION = "1.2.0";
3493
3743
  var MIME_MAP = {
3494
3744
  html: "text/html; charset=utf-8",
3495
3745
  htm: "text/html; charset=utf-8",
@@ -4157,6 +4407,7 @@ async function startTamgaServer(opts = {}) {
4157
4407
  case "browser_new_tab":
4158
4408
  await browserSession.createTab(msg.url);
4159
4409
  break;
4410
+ case "browser_activate_tab":
4160
4411
  case "browser_switch_tab":
4161
4412
  await browserSession.activateTab(msg.tabId);
4162
4413
  break;
@@ -4176,7 +4427,11 @@ async function startTamgaServer(opts = {}) {
4176
4427
  await browserSession.reload(msg.tabId);
4177
4428
  break;
4178
4429
  case "browser_viewport":
4179
- await browserSession.setViewport(Number(msg.width), Number(msg.height));
4430
+ await browserSession.setViewport(
4431
+ Number(msg.width),
4432
+ Number(msg.height),
4433
+ typeof msg.devicePixelRatio === "number" ? msg.devicePixelRatio : void 0
4434
+ );
4180
4435
  break;
4181
4436
  case "browser_input":
4182
4437
  browserSession.handleInput(msg);
@@ -4359,7 +4614,8 @@ TamgaVDesktop v${TAMGA_VERSION} \u2014 Linux Sanal Masa\xFCst\xFC Platformu
4359
4614
  Kullan\u0131m:
4360
4615
  tamga-vdesktop start [se\xE7enekler] Sunucuyu ba\u015Flat\u0131r
4361
4616
  tamga-vdesktop init [se\xE7enekler] Yap\u0131land\u0131rma dosyas\u0131n\u0131 olu\u015Fturur
4362
- tamga-vdesktop setup-linux [se\xE7enekler] Linux GUI ba\u011F\u0131ml\u0131l\u0131klar\u0131n\u0131 kurar (Ubuntu/Debian)
4617
+ tamga-vdesktop install-browser Yerle\u015Fik Playwright Chromium taray\u0131c\u0131s\u0131n\u0131 kurar
4618
+ tamga-vdesktop setup-linux [se\xE7enekler] Linux GUI + Playwright Chromium ortam\u0131n\u0131 kurar
4363
4619
  tamga-vdesktop service <komut> systemd servisini y\xF6netir (install|start|stop|restart|status|logs|uninstall)
4364
4620
  tamga-vdesktop passwd <yeni-parola> Y\xF6netici parolas\u0131n\u0131 g\xFCnceller
4365
4621
  tamga-vdesktop doctor Sistem ve ba\u011F\u0131ml\u0131l\u0131k te\u015Fhisi yapar
@@ -4427,6 +4683,19 @@ Ba\u015Flatmak i\xE7in: tamga-vdesktop start --config "${configPath}"`);
4427
4683
  console.log(`7/24 servis i\xE7in: tamga-vdesktop service install --config "${configPath}"
4428
4684
  `);
4429
4685
  }
4686
+ function cmdInstallBrowser(flags) {
4687
+ const quiet = Boolean(flags.quiet);
4688
+ const withDeps = Boolean(flags["with-deps"]);
4689
+ const ok = installPlaywrightBrowserSync({ quiet, withDeps });
4690
+ if (!ok && !quiet) {
4691
+ console.error("\u2717 Playwright Chromium kurulumu tamamlanamad\u0131.");
4692
+ process.exit(1);
4693
+ }
4694
+ if (ok && !quiet) {
4695
+ const p = findPlaywrightManagedBrowser();
4696
+ console.log(`\u2713 Yerle\u015Fik Playwright Chromium haz\u0131r -> ${p || "ms-playwright"}`);
4697
+ }
4698
+ }
4430
4699
  function cmdSetupLinux(flags) {
4431
4700
  if (process.platform !== "linux") {
4432
4701
  console.error("setup-linux komutu yaln\u0131zca Ubuntu/Debian Linux sunucularda \xE7al\u0131\u015F\u0131r.");
@@ -4438,7 +4707,7 @@ function cmdSetupLinux(flags) {
4438
4707
  "set -e",
4439
4708
  "export DEBIAN_FRONTEND=noninteractive",
4440
4709
  "apt-get update -y",
4441
- "apt-get install -y --no-install-recommends xvfb openbox ffmpeg libturbojpeg libxdamage1 libxtst6 libx11-6 libxfixes3 libxext6 xclip xdotool wmctrl dbus-x11 x11-utils dmz-cursor-theme pulseaudio pulseaudio-utils fonts-dejavu-core fonts-liberation fonts-noto-color-emoji desktop-file-utils hicolor-icon-theme wget gnupg ca-certificates curl"
4710
+ "apt-get install -y --no-install-recommends xvfb openbox ffmpeg libturbojpeg libxdamage1 libxtst6 libx11-6 libxfixes3 libxext6 libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxrandr2 libgbm1 libasound2t64 xclip xdotool wmctrl dbus-x11 x11-utils dmz-cursor-theme pulseaudio pulseaudio-utils fonts-noto-core fonts-dejavu-core fonts-liberation fonts-noto-color-emoji desktop-file-utils hicolor-icon-theme wget gnupg ca-certificates curl || apt-get install -y --no-install-recommends xvfb openbox ffmpeg libturbojpeg libxdamage1 libxtst6 libx11-6 libxfixes3 libxext6 xclip xdotool wmctrl dbus-x11 x11-utils dmz-cursor-theme pulseaudio pulseaudio-utils fonts-dejavu-core fonts-liberation fonts-noto-color-emoji desktop-file-utils hicolor-icon-theme wget gnupg ca-certificates curl"
4442
4711
  ];
4443
4712
  if (withFirefox) {
4444
4713
  parts.push(`
@@ -4459,12 +4728,14 @@ if ! command -v code >/dev/null 2>&1; then
4459
4728
  apt-get update -y && apt-get install -y code
4460
4729
  fi`);
4461
4730
  }
4462
- console.log("TamgaVDesktop Linux GUI \xE7al\u0131\u015Fma ortam\u0131 kuruluyor...");
4463
- const res = spawnSync("/bin/bash", ["-c", parts.join("\n")], { stdio: "inherit" });
4731
+ parts.push("apt-get clean");
4732
+ console.log("TamgaVDesktop Linux GUI \xE7al\u0131\u015Fma ortam\u0131 ve Playwright Chromium kuruluyor...");
4733
+ const res = spawnSync2("/bin/bash", ["-c", parts.join("\n")], { stdio: "inherit" });
4464
4734
  if (res.status !== 0) {
4465
4735
  process.exit(res.status || 1);
4466
4736
  }
4467
- console.log("\n\u2713 Linux GUI \xE7al\u0131\u015Fma ortam\u0131 haz\u0131r!");
4737
+ installPlaywrightBrowserSync({ quiet: false, withDeps: true });
4738
+ console.log("\n\u2713 Linux GUI \xE7al\u0131\u015Fma ortam\u0131 ve yerle\u015Fik Chromium haz\u0131r!");
4468
4739
  }
4469
4740
  function cmdService(subCmd, flags) {
4470
4741
  if (process.platform !== "linux") {
@@ -4520,10 +4791,10 @@ WantedBy=multi-user.target
4520
4791
  execSync4(`systemctl ${subCmd} ${unitName}`, { stdio: "inherit" });
4521
4792
  break;
4522
4793
  case "status":
4523
- spawnSync("systemctl", ["status", unitName, "--no-pager"], { stdio: "inherit" });
4794
+ spawnSync2("systemctl", ["status", unitName, "--no-pager"], { stdio: "inherit" });
4524
4795
  break;
4525
4796
  case "logs":
4526
- spawnSync("journalctl", ["-u", unitName, "-n", "80", "--no-pager"], { stdio: "inherit" });
4797
+ spawnSync2("journalctl", ["-u", unitName, "-n", "80", "--no-pager"], { stdio: "inherit" });
4527
4798
  break;
4528
4799
  case "uninstall":
4529
4800
  try {
@@ -4555,6 +4826,7 @@ function cmdDoctor(flags) {
4555
4826
  const appMgr = new LinuxAppManager();
4556
4827
  const status = appMgr.getRuntimeStatus();
4557
4828
  const apps = appMgr.listApps().filter((a) => a.installed);
4829
+ const pwPath = findPlaywrightManagedBrowser() || findChromiumExecutable();
4558
4830
  console.log(`
4559
4831
  TamgaVDesktop v${TAMGA_VERSION} \u2014 Sistem Te\u015Fhisi`);
4560
4832
  console.log(`\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
@@ -4564,6 +4836,7 @@ TamgaVDesktop v${TAMGA_VERSION} \u2014 Sistem Te\u015Fhisi`);
4564
4836
  console.log(`Dinleme Adresi : ${config.host}:${config.port}`);
4565
4837
  console.log(`Veri Dizini : ${config.dataDir}`);
4566
4838
  console.log(`Giri\u015F Korumas\u0131 : ${config.auth.enabled ? `Aktif (${config.auth.username})` : "Kapal\u0131"}`);
4839
+ console.log(`Yerle\u015Fik Chromium: ${pwPath ? `HAZIR (${pwPath})` : "Eksik ('tamga-vdesktop install-browser' \xE7al\u0131\u015Ft\u0131r\u0131n)"}`);
4567
4840
  console.log(`Linux GUI Motor : ${status.guiReady ? "HAZIR (Xvfb + Openbox + FFmpeg + X11)" : `Eksik: ${status.missingDeps.join(", ")}`}`);
4568
4841
  console.log(`Linux Ses Motor : ${status.hasAudio ? "HAZIR (PulseAudio)" : "Devre D\u0131\u015F\u0131"}`);
4569
4842
  console.log(`Kurulu Uygulama : ${apps.length > 0 ? apps.map((a) => a.name).join(", ") : "Yok"}`);
@@ -4594,6 +4867,9 @@ async function main() {
4594
4867
  case "setup-linux":
4595
4868
  cmdSetupLinux(flags);
4596
4869
  break;
4870
+ case "install-browser":
4871
+ cmdInstallBrowser(flags);
4872
+ break;
4597
4873
  case "service":
4598
4874
  cmdService(positional[1], flags);
4599
4875
  break;