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.
// Builds the Linux packages (`npm run dist`): the helper, a staging folder with the same
// layout as the repo (linux/, shared/, linux-helper/bin/), then electron-builder → AppImage and
// .deb (x64). Same approach as windows/installer/build.js: the layout is kept so
// '../shared/protocol.js' and the helper path work unchanged; no asar, so the helper is a real file.
// Run it on Linux (or in WSL) with the X11 dev packages installed. For a phone as the peer it also
// carries adb (downloaded, scripts/fetch-adb.js) and the scrcpy server (mac/vendor/scrcpy-server)
// in linux/vendor/.
const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');
const builder = require('electron-builder');
const { fetchAdb } = require('../scripts/fetch-adb');
const LIN = path.join(__dirname, '..');
const ROOT = path.join(LIN, '..');
const STAGE = path.join(LIN, 'dist', 'stage');
const pkg = require(path.join(LIN, 'package.json'));
const electronVersion = require(path.join(LIN, 'node_modules', 'electron', 'package.json')).version;
// This machine's architecture (x64, or arm64 on a Raspberry Pi and other ARM computers, #384 by Spifey).
// Every helper is compiled here, so it comes out the same architecture; only adb isn't (Google ships no
// Linux ARM build): ARM packages use the system's adb (recommended), which linux/adb.js finds on PATH.
const ARCH = process.env.TWINDESK_ARCH || (process.arch === 'arm64' ? 'arm64' : 'x64');
// electron-builder's own fpm (the .deb) is an x86-64 build: on ARM it uses the system's (gem install fpm, #385).
if (ARCH === 'arm64' && !process.env.USE_SYSTEM_FPM) {
try { execFileSync('fpm', ['--version'], { stdio: 'ignore' }); process.env.USE_SYSTEM_FPM = 'true'; } catch {
console.log('note: no fpm on PATH — the ARM .deb needs it (sudo apt install ruby ruby-dev && sudo gem install fpm)');
}
}
// The Full KVM build (docs/full-kvm.md): `TWINDESK_EDITION=full-kvm npm run dist`. Only it carries
// linux/fullkvm and shared/fullkvm (the service); the normal packages have none of it, and the
// hooks in the app (shared/edition.js) stay off without those folders.
const FULL_KVM = process.env.TWINDESK_EDITION === 'full-kvm';
const SKIP = new Set(['node_modules', 'dist', 'installer', 'test', 'package-lock.json', ...(FULL_KVM ? [] : ['fullkvm'])]); // tests (mesh/test) stay out of the package
function copy(from, to, filter = () => true) {
const st = fs.statSync(from);
if (st.isDirectory()) {
fs.mkdirSync(to, { recursive: true });
for (const name of fs.readdirSync(from)) if (filter(name)) copy(path.join(from, name), path.join(to, name));
} else {
fs.mkdirSync(path.dirname(to), { recursive: true });
fs.copyFileSync(from, to);
fs.chmodSync(to, st.mode);
}
}
function copyDeps(names, seen = new Set()) {
for (const name of names) {
if (seen.has(name)) continue;
seen.add(name);
const dir = path.join(LIN, 'node_modules', name);
copy(dir, path.join(STAGE, 'node_modules', name));
copyDeps(Object.keys(require(path.join(dir, 'package.json')).dependencies || {}), seen);
}
}
async function main() {
// CI builds the helpers on an old glibc first (build-linux.yml, issue #149) and sets this: keep those.
if (process.env.TWINDESK_HELPERS_PREBUILT) {
console.log('Using the helpers already in linux-helper/bin');
} else {
console.log('Building the helper…');
execFileSync('sh', [path.join(ROOT, 'linux-helper', 'build.sh')], { stdio: 'inherit' });
// iPhone app signing's helper (ios-signer/): optional, the app leaves the page's work out without it.
try { execFileSync('sh', [path.join(ROOT, 'ios-signer', 'build.sh')], { stdio: 'inherit', env: { ...process.env, TWINDESK_SIGNER_ANY_IPA: '1' } }); } catch { console.log('note: the iOS signing helper didn’t build'); }
// An iPhone's screen and input through the USB cable (ios-control/, shared/iosusb.js): optional too.
try { execFileSync('sh', [path.join(ROOT, 'ios-control', 'build.sh')], { stdio: 'inherit' }); } catch { console.log('note: the iOS control helper didn’t build'); }
}
console.log('Staging…');
fs.rmSync(STAGE, { recursive: true, force: true });
copy(LIN, path.join(STAGE, 'linux'), (name) => !SKIP.has(name));
// Every shared module (a list missed new ones: the app then failed on its first require), and the
// pages' styles and the call window (phonehub.css, callpop.html).
for (const name of fs.readdirSync(path.join(ROOT, 'shared'))) {
if (name === 'lang' || name === 'web' || name === 'airplay' || (FULL_KVM && name === 'fullkvm') || /\.(js|css|html)$/.test(name)) copy(path.join(ROOT, 'shared', name), path.join(STAGE, 'shared', name));
}
// TwinDesk Web (shared/web/webwire.js): its server pieces, the page a browser loads (web/), and the
// phone app's viewer and remote it reuses (android-web/).
copy(path.join(ROOT, 'web'), path.join(STAGE, 'web'), (name) => name !== 'shortcuts-src');
copy(path.join(ROOT, 'android', 'app', 'src', 'main', 'assets', 'web'), path.join(STAGE, 'android-web'));
copy(path.join(ROOT, 'linux-helper', 'bin', 'macshare-linuxhelper'), path.join(STAGE, 'linux-helper', 'bin', 'macshare-linuxhelper'));
if (fs.existsSync(path.join(ROOT, 'ios-signer', 'bin'))) copy(path.join(ROOT, 'ios-signer', 'bin'), path.join(STAGE, 'ios-signer', 'bin'));
else console.log('note: no ios-signer/bin — iPhone app signing is left out (ios-signer/build.sh, with cargo)');
// Its own binary only: Windows' .exe is built in the same folder.
// Only this package's architecture (shared/iosusb.js picks by process.arch; #385 by Spifey).
const iosControl = [ARCH].filter((a) => fs.existsSync(path.join(ROOT, 'ios-control', 'bin', a, 'twindesk-ios-control')));
for (const a of iosControl) copy(path.join(ROOT, 'ios-control', 'bin', a, 'twindesk-ios-control'), path.join(STAGE, 'ios-control', 'bin', a, 'twindesk-ios-control'));
if (!iosControl.length) console.log('note: no ios-control/bin/*/twindesk-ios-control — an iPhone on the cable shows nothing (ios-control/build.sh, with cargo)');
// Multi-device's helper (several watched edges, docs/multi-device.md): the same sources built with -DMULTI.
copy(path.join(ROOT, 'linux-helper', 'bin', 'macshare-linuxhelper-multi'), path.join(STAGE, 'linux-helper', 'bin', 'macshare-linuxhelper-multi'));
copy(path.join(ROOT, 'linux-helper', 'bin', 'twindesk-wifiap'), path.join(STAGE, 'linux-helper', 'bin', 'twindesk-wifiap'));
// Camera › Virtual camera's writer (vcam.js).
copy(path.join(ROOT, 'linux-helper', 'bin', 'twindesk-vcam'), path.join(STAGE, 'linux-helper', 'bin', 'twindesk-vcam'));
// Remote › Real gamepad's writer (gamepad.js).
copy(path.join(ROOT, 'linux-helper', 'bin', 'twindesk-pad'), path.join(STAGE, 'linux-helper', 'bin', 'twindesk-pad'));
// A phone: its screen, apps and input go through adb and scrcpy-server (phone-bridge.js).
if (!fs.existsSync(path.join(LIN, 'vendor', 'scrcpy-server'))) {
copy(path.join(ROOT, 'mac', 'vendor', 'scrcpy-server'), path.join(STAGE, 'linux', 'vendor', 'scrcpy-server'));
}
// Mirroring › Skip adbd: the relay on the phone beside it (native/adb-relay).
if (!fs.existsSync(path.join(LIN, 'vendor', 'twindesk-relay.jar'))) {
copy(path.join(ROOT, 'mac', 'vendor', 'twindesk-relay.jar'), path.join(STAGE, 'linux', 'vendor', 'twindesk-relay.jar'));
}
if (ARCH === 'x64') await fetchAdb(path.join(STAGE, 'linux', 'vendor', 'adb'));
// The Android app with notification access isn't packaged: Install downloads it from the release
// (shared/androidfull.js).
for (const f of ['LICENSE', 'THIRD_PARTY_NOTICES', 'README.md', 'licenses']) {
if (fs.existsSync(path.join(ROOT, f))) copy(path.join(ROOT, f), path.join(STAGE, f));
}
copyDeps(Object.keys(pkg.dependencies || {}));
// Extend on X11 (vdd.js): the connector helper and its polkit action, at their system paths in
// the .deb (fpm's source=destination); the AppImage's Install writes the same files.
const system = path.join(LIN, 'dist', 'system');
fs.rmSync(system, { recursive: true, force: true });
fs.mkdirSync(system, { recursive: true });
const systemFiles = require('../vdd').FILES.map((f) => {
const file = path.join(system, path.basename(f.path));
fs.writeFileSync(file, f.text);
fs.chmodSync(file, f.mode);
return file + '=' + f.path;
});
fs.writeFileSync(path.join(STAGE, 'package.json'), JSON.stringify({
name: 'twindesk', productName: pkg.productName, version: pkg.version, description: pkg.description,
license: pkg.license, author: { name: 'inukaasith', email: '[email protected]' },
homepage: 'https://github.com/InukaAsith/TwinDesk', main: 'linux/main.js', dependencies: pkg.dependencies,
}, null, 2));
console.log('Packaging…');
await builder.build({
targets: builder.Platform.LINUX.createTarget(['AppImage', 'deb'], builder.Arch[ARCH]),
projectDir: LIN,
config: {
appId: 'org.macshare.linux',
productName: 'TwinDesk',
copyright: 'Copyright (C) 2026 inukaasith',
electronVersion,
directories: { app: STAGE, output: path.join(LIN, 'dist') },
asar: false,
npmRebuild: false,
linux: {
icon: path.join(LIN, 'assets', 'icon.png'),
executableName: 'twindesk',
category: 'Utility',
synopsis: 'Share mouse, keyboard, clipboard, files and screens with your other computer',
maintainer: 'inukaasith',
desktop: { entry: { Name: 'TwinDesk', StartupWMClass: 'TwinDesk', Keywords: 'KVM;mouse;keyboard;clipboard;screen;share;' } },
artifactName: (FULL_KVM ? 'TwinDesk-FullKVM-' : 'TwinDesk-') + '${version}-${arch}.${ext}',
},
deb: {
// Electron's own needs plus what TwinDesk calls: openssl (host certificate), pactl (sound),
// dbus-monitor (notifications), pkexec (firewall / input access fixes), GIO (the helper's
// Bluetooth through BlueZ). Bluetooth and the Wi-Fi it moves to (NetworkManager) are for
// devices not on this network: recommended, not needed.
depends: ['libgtk-3-0 | libgtk-3-0t64', 'libnotify4', 'libnss3', 'libxss1', 'libxtst6', 'xdg-utils',
'libatspi2.0-0 | libatspi2.0-0t64', 'libuuid1', 'libsecret-1-0', 'libxi6', 'libxrandr2', 'libxfixes3',
'openssl', 'dbus', 'pulseaudio-utils | pipewire-pulse', 'policykit-1 | pkexec', 'libglib2.0-0 | libglib2.0-0t64'],
recommends: ['bluez', 'network-manager', ...(ARCH === 'x64' ? [] : ['adb'])],
priority: 'optional',
fpm: systemFiles,
},
},
});
console.log('Done: ' + path.join(LIN, 'dist'));
}
main().catch((e) => { console.error(e); process.exit(1); });