All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.
JavaScript androidapple-ecosystemconnectelectronfile-sharingintel-unison-alternativeiosios-windowskde-connect-alternativekvmlinuxmacbookmacosmouse-sharingphone-link-alternativeproductivityscreen-sharingsidecar-alternativesynergy-alternativewindows
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Share folder, from the file manager's right-click menu: Explorer (windows/explorer.js, and on Windows 11
// its first-level menu, windows-helper/shellmenu), Finder's Quick Actions (mac/finder.js), and Nautilus,
// Caja, Nemo, Dolphin and Thunar (linux/sendto.js). TwinDesk comes up on "Share <folder> with…"
// (shared/folders-host.js): which devices get it, computers through TwinDesk Shared folders, phones
// through their Files app (shared/foldershare.js).
// Windows, Linux: TwinDesk is started with `--td share <folder>` (a running one gets it as
// second-instance argv).
// Mac: macshare://share-folder?h=<the path's UTF-8 bytes in hex> (open-url), hex so a
// Quick Action's script needs no escaping.
'use strict';
const fs = require('fs');
const path = require('path');
const ARG = '--td';
const MAX_PATH = 1000; // as the settings keep it
const isDir = (p) => { try { return fs.statSync(p).isDirectory(); } catch { return false; } };
// argv with --td share <folder>: the folder ('' when the argument isn't a folder), or null when it isn't ours.
// A running TwinDesk gets a second copy's argv from Chromium with the switches first, so --td can be
// apart from share <folder> (`… --td --allow-file-access-from-files <app> share <folder>`).
function fromArgv(argv) {
const list = Array.isArray(argv) ? argv : [];
const i = list.indexOf(ARG);
const j = i < 0 ? -1 : list.indexOf('share', i + 1);
if (j < 0) return null;
const dir = String(list[j + 1] || '').replace(/"$/, '');
return path.isAbsolute(dir) && dir.length <= MAX_PATH && isDir(dir) ? path.resolve(dir) : '';
}
// macshare://share-folder?h=…: the folder ('' when it isn't one), or null when it isn't ours.
function fromUrl(url) {
let u;
try { u = new URL(String(url)); } catch { return null; }
if (u.host !== 'share-folder' && u.pathname.replace(/^\/+/, '') !== 'share-folder') return null;
const h = u.searchParams.get('h') || '';
if (!/^(?:[0-9a-fA-F]{2}){1,1000}$/.test(h)) return '';
const dir = Buffer.from(h, 'hex').toString('utf8');
return path.isAbsolute(dir) && dir.length <= MAX_PATH && isDir(dir) ? path.resolve(dir) : '';
}
// macshare://send-files?h=… (Finder › Send with TwinDesk): the file or folder ('' when it isn't one), or null.
function sendFromUrl(url) {
let u;
try { u = new URL(String(url)); } catch { return null; }
if (u.host !== 'send-files' && u.pathname.replace(/^\/+/, '') !== 'send-files') return null;
const h = u.searchParams.get('h') || '';
if (!/^(?:[0-9a-fA-F]{2}){1,1000}$/.test(h)) return '';
const p = Buffer.from(h, 'hex').toString('utf8');
let ok = false;
try { fs.statSync(p); ok = true; } catch { /* gone */ }
return path.isAbsolute(p) && p.length <= MAX_PATH && ok ? path.resolve(p) : '';
}
module.exports = { ARG, fromArgv, fromUrl, sendFromUrl };