diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-03 16:20:23 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-03 16:20:28 +0200 |
| commit | 753653b4df62723b82d32799825135822886eac7 (patch) | |
| tree | 14829922bf343e6353093eaceaa84986fe5f84df /packages/meshbay-client/src/main.js | |
| parent | 675beed6ff688733a9598f9d82d41578f48316be (diff) | |
| download | meshbay-753653b4df62723b82d32799825135822886eac7.tar.gz | |
refactor(node): platform abstraction for Windows portability (W1-W2-W5-W6-W7)
Platform directories, signal handling, chmod guards, ffmpeg discovery,
and platform-conditional CLI messages — all testable on Linux.
See docs/WINDOWS-PORT.md §5 for the plan these implement.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-client/src/main.js')
| -rw-r--r-- | packages/meshbay-client/src/main.js | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/packages/meshbay-client/src/main.js b/packages/meshbay-client/src/main.js index e071074..2a97246 100644 --- a/packages/meshbay-client/src/main.js +++ b/packages/meshbay-client/src/main.js @@ -43,6 +43,20 @@ app.commandLine.appendSwitch('class', 'MeshBay'); const UI_DIR = path.join(__dirname, '..', 'ui'); const SCHEME = 'app'; +// ── Platform directories ──────────────────────────────────────────────────── + +function meshbayConfigDir() { + if (process.platform === 'win32') + return path.join(process.env.LOCALAPPDATA || os.homedir(), 'meshbay'); + return path.join(os.homedir(), '.config', 'meshbay'); +} + +function meshbayDataDir() { + if (process.platform === 'win32') + return path.join(process.env.LOCALAPPDATA || os.homedir(), 'meshbay', 'data'); + return path.join(os.homedir(), '.local', 'share', 'meshbay'); +} + // The policy, sent as a header on every response. // // Not a <meta> tag: `frame-ancestors` is ignored there — Chromium says so in @@ -697,13 +711,13 @@ function registerBridge() { let _nodePairingCode = null; function nodeConfigPath() { - return path.join(os.homedir(), '.config', 'meshbay', 'node.toml'); + return path.join(meshbayConfigDir(), 'node.toml'); } function readNodeConfig() { try { const text = fs.readFileSync(nodeConfigPath(), 'utf8'); - let dataDir = path.join(os.homedir(), '.local', 'share', 'meshbay'); + let dataDir = meshbayDataDir(); let uiPort = 18000; const dataMatch = text.match(/^\s*data_dir\s*=\s*"([^"]+)"/m); if (dataMatch) { @@ -750,11 +764,14 @@ function registerBridge() { }); function findNodeBinary() { - const local = path.join(os.homedir(), '.local', 'bin', 'meshbay-node'); - if (fs.existsSync(local)) return local; + if (process.platform !== 'win32') { + const local = path.join(os.homedir(), '.local', 'bin', 'meshbay-node'); + if (fs.existsSync(local)) return local; + } + const cmd = process.platform === 'win32' ? 'where.exe' : 'which'; return new Promise((resolve) => { - execFile('which', ['meshbay-node'], (err, stdout) => { - resolve(err ? null : stdout.trim()); + execFile(cmd, ['meshbay-node'], (err, stdout) => { + resolve(err ? null : stdout.trim().split('\n')[0]); }); }); } @@ -832,8 +849,7 @@ function registerBridge() { async function probeNode() { const nc = readNodeConfig(); - const dataDir = nc ? nc.dataDir - : path.join(os.homedir(), '.local', 'share', 'meshbay'); + const dataDir = nc ? nc.dataDir : meshbayDataDir(); const port = nc ? nc.uiPort : 18000; const token = readNodeToken(dataDir); if (!token) return null; @@ -852,8 +868,8 @@ function registerBridge() { } function provisionNode(hubUrl, username) { - const configDir = path.join(os.homedir(), '.config', 'meshbay'); - const dataDir = path.join(os.homedir(), '.local', 'share', 'meshbay'); + const configDir = meshbayConfigDir(); + const dataDir = meshbayDataDir(); fs.mkdirSync(configDir, { recursive: true }); fs.mkdirSync(dataDir, { recursive: true }); |