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.
// One Dock icon per PC or phone app. A tiny generated bundle (the app's name, a per-app bundle id,
// its icon; mac-helper's macshare-dockstub as the executable, ad-hoc signed) runs while that app has
// windows here. Its events: activate / focus <i> / quit. Opened on its own it asks TwinDesk
// (macshare://pc-app/<id>) to open the app.
// Where it lives: an icon only shown while the app has windows (ReZume, phone and PC app windows) is
// built in Application Support/TwinDesk/Dock Apps.noindex, out of Launchpad and Spotlight, and deleted
// when the icon goes unless it was kept in the Dock. Add to Dock builds it in ~/Applications/MacShare Apps,
// where Launchpad and Spotlight list it; a running icon of that app then uses that bundle.
// sweep() at start removes the bundles nothing keeps (#389).
'use strict';
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const { spawn, execFile } = require('child_process');
const { app } = require('electron');
const STUB = path.join(__dirname, '..', 'mac-helper', '.build', 'release', 'macshare-dockstub');
const run = (cmd, args) => new Promise((resolve) => execFile(cmd, args, (err) => resolve(!err)));
const APPS_DIR = path.join(require('os').homedir(), 'Applications', 'MacShare Apps');
const TEMP_DIR = path.join(require('os').homedir(), 'Library', 'Application Support', 'TwinDesk', 'Dock Apps.noindex');
const KEPT = 'macshare-kept'; // in Contents: made by Add to Dock
const live = new Map(); // bundle dir -> running DockStubs using it
const xml = (v) => String(v).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
// The bundle of app `id` in `base` (two apps with one name: the second gets a short suffix).
function bundleDir(base, id, safe, hash) {
const dir = path.join(base, `${safe}.app`);
try {
const plist = fs.readFileSync(path.join(dir, 'Contents', 'Info.plist'), 'utf8');
if (!plist.includes(`<string>${xml(id)}</string>`)) return path.join(base, `${safe} ${hash.slice(0, 4)}.app`);
} catch { /* new */ }
return dir;
}
const has = (dir) => fs.existsSync(path.join(dir, 'Contents', 'Info.plist'));
// Builds (or reuses) the bundle for one app; returns the executable path, or null.
// keep: Add to Dock (~/Applications); otherwise the kept bundle if there is one, else a temporary one.
async function bundle({ id, name, icon }, keep = false) {
if (!fs.existsSync(STUB)) return null;
const hash = crypto.createHash('sha1').update(String(id)).digest('hex').slice(0, 10);
const safe = String(name || 'PC app').replace(/[/:\\]/g, '-').slice(0, 60);
const kept = bundleDir(APPS_DIR, id, safe, hash);
const dir = keep || (has(kept) && fs.existsSync(path.join(kept, 'Contents', KEPT))) ? kept : bundleDir(TEMP_DIR, id, safe, hash);
const exe = path.join(dir, 'Contents', 'MacOS', 'dockstub');
const stamp = crypto.createHash('sha1').update([id, name, icon || '', fs.statSync(STUB).mtimeMs, 'r6'].join('|')).digest('hex');
const stampFile = path.join(dir, 'Contents', 'macshare-stamp');
try {
if (fs.readFileSync(stampFile, 'utf8') === stamp) return exe;
} catch {}
fs.rmSync(path.join(dir, 'Contents'), { recursive: true, force: true }); // keep the .app folder: the Dock points at it
const res = path.join(dir, 'Contents', 'Resources');
fs.mkdirSync(path.dirname(exe), { recursive: true });
fs.mkdirSync(res, { recursive: true });
fs.copyFileSync(STUB, exe);
fs.chmodSync(exe, 0o755);
let iconKey = '';
const m = /^data:image\/png;base64,(.+)$/.exec(icon || '');
if (m) {
const png = path.join(res, 'icon.png');
fs.writeFileSync(png, Buffer.from(m[1], 'base64'));
if (await run('/usr/bin/sips', ['-s', 'format', 'icns', png, '--out', path.join(res, 'icon.icns')])) iconKey = '<key>CFBundleIconFile</key><string>icon</string>';
}
fs.writeFileSync(path.join(dir, 'Contents', 'Info.plist'), `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>CFBundleExecutable</key><string>dockstub</string>
<key>CFBundleIdentifier</key><string>org.macshare.pcapp.${hash}</string>
<key>CFBundleName</key><string>${xml(safe)}</string>
<key>CFBundleDisplayName</key><string>${xml(safe)}</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleVersion</key><string>1</string>
<key>LSMinimumSystemVersion</key><string>13.0</string>
<key>MacSharePcAppId</key><string>${xml(id)}</string>
<key>NSHighResolutionCapable</key><true/>
${iconKey}
</dict></plist>
`);
if (dir === kept) fs.writeFileSync(path.join(dir, 'Contents', KEPT), '');
await run('/usr/bin/codesign', ['--force', '--sign', '-', dir]);
fs.writeFileSync(stampFile, stamp);
return exe;
}
// The bundles the Dock keeps (persistent-apps), as paths.
function dockKept() {
return new Promise((resolve) => execFile('/usr/bin/defaults', ['read', 'com.apple.dock', 'persistent-apps'], (err, out) => {
const set = new Set();
for (const m of String(out || '').matchAll(/"?_CFURLString"?\s*=\s*"([^"]+)"/g)) {
try { set.add(decodeURI(m[1].replace(/^file:\/\//, '')).replace(/\/$/, '')); } catch {}
}
resolve(set);
}));
}
// A temporary bundle goes once nothing runs it and the Dock doesn't keep it.
async function drop(dir) {
if (!dir || !dir.startsWith(TEMP_DIR + path.sep) || live.get(dir)) return;
if ((await dockKept()).has(dir) || live.get(dir)) return;
fs.rmSync(dir, { recursive: true, force: true });
}
// At start: temporary bundles the Dock doesn't keep, and the ones older versions left in
// ~/Applications/MacShare Apps for every app ever shown (not made by Add to Dock, not in the Dock).
async function sweep() {
const docked = await dockKept();
const old = (base, ok) => {
let names = [];
try { names = fs.readdirSync(base); } catch { return 0; }
let n = 0;
for (const f of names) {
const dir = path.join(base, f);
if (!f.endsWith('.app') || live.get(dir) || ok(dir)) continue;
if (docked.has(dir)) { // kept in the Dock by hand: from now on it's the app's kept bundle
if (base === APPS_DIR) try { fs.writeFileSync(path.join(dir, 'Contents', KEPT), ''); } catch {}
continue;
}
fs.rmSync(dir, { recursive: true, force: true });
n++;
}
return n;
};
const n = old(TEMP_DIR, () => false) + old(APPS_DIR, (dir) => fs.existsSync(path.join(dir, 'Contents', KEPT)));
try { if (!fs.readdirSync(APPS_DIR).some((f) => f.endsWith('.app'))) fs.rmSync(APPS_DIR, { recursive: true, force: true }); } catch {}
if (n) console.log(`[dockstub] removed ${n} unused Dock app bundle(s)`);
return n;
}
// One running Dock icon. on(event, arg): 'activate' | 'focus' (index) | 'quit'.
class DockStub {
constructor(appInfo, on) {
this.on = on;
this.proc = null;
this.gone = false;
this.titles = [];
bundle(appInfo).then((exe) => {
if (!exe) return;
this.dir = exe.replace(/\/Contents\/MacOS\/dockstub$/, '');
if (this.gone) { drop(this.dir).catch(() => {}); return; }
live.set(this.dir, (live.get(this.dir) || 0) + 1);
this.proc = spawn(exe, [], { stdio: ['pipe', 'pipe', 'ignore'], env: { ...process.env, MACSHARE_DOCKSTUB: '1' } });
this.proc.on('error', () => {});
this.proc.stdin.on('error', () => {}); // EPIPE: it quit from the Dock as we wrote
this.proc.on('exit', () => {
this.proc = null;
const n = (live.get(this.dir) || 1) - 1;
if (n > 0) live.set(this.dir, n); else live.delete(this.dir);
drop(this.dir).catch(() => {});
});
let buf = '';
this.proc.stdout.on('data', (d) => {
buf += d;
let i;
while ((i = buf.indexOf('\n')) >= 0) {
const line = buf.slice(0, i).trim();
buf = buf.slice(i + 1);
if (line === 'activate' || line === 'quit') this.on(line);
else if (line.startsWith('focus ')) this.on('focus', Number(line.slice(6)));
}
});
this.menu(this.titles);
}).catch((e) => console.log(`[dockstub] ${e.message}`));
}
menu(titles) {
this.titles = titles;
if (this.proc && this.proc.stdin.writable) this.proc.stdin.write(`menu ${JSON.stringify(titles)}\n`);
}
stop() {
this.gone = true;
if (this.proc && this.proc.stdin.writable) this.proc.stdin.end('exit\n');
}
}
// Keep a PC app in the Dock before it ever ran (Apps tab › Add to Dock).
async function addToDock(appInfo) {
const exe = await bundle(appInfo, true);
if (!exe) return false;
const dir = exe.replace(/\/Contents\/MacOS\/dockstub$/, '');
const url = `file://${encodeURI(dir)}/`;
const tile = `<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>${xml(url)}</string><key>_CFURLStringType</key><integer>15</integer></dict></dict></dict>`;
const ok = await run('/usr/bin/defaults', ['write', 'com.apple.dock', 'persistent-apps', '-array-add', tile]);
if (ok) await run('/usr/bin/killall', ['Dock']);
return ok;
}
module.exports = { DockStub, bundle, addToDock, sweep, APPS_DIR, TEMP_DIR };