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.
// The Clipboard and Notifications pages (Mac, Windows, Linux; one-to-one and Multi-device), laid out as Drop:
// at the top, two switches in a line, Share (this device's to the others) and Receive (the others' here),
// each with Edit in Multi-device: a picker as the Share-folder one, All devices by default (one pool,
// devices added later too), or the devices ticked; More settings and the gear open the rest:
// Devices (the two pickers and the grid of the whole mesh) and Settings (the page's own cards).
// Below, what came and went, as Drop's bubbles: grouped by device in Multi-device.
//
// const f = UI.feedPage(body, { kind: 'clip' | 'notifs', feature, flat(s) → {out, in}, setFlat(dir, on),
// shareLabel, receiveLabel, grid: {el, render(s)} | null, settings: [cards], devices?: [cards] })
// f.render(s)
// The pickers' choice is kept on this computer (localStorage); each device's own switch is consent
// (setConsent), the same the grid shows.
'use strict';
(function () {
const t = (k, v) => I18n.t(k, v);
const el = (...a) => UI.el(...a);
const OSNAME = { mac: 'Mac', win: 'Windows', linux: 'Linux', android: 'Android', ios: 'iPhone', ipados: 'iPad' };
const ICON = {
gear: 'M16.02 8.14 L18.04 8.37 L18.04 11.63 L16.02 11.86 L15.57 12.94 L16.83 14.53 L14.53 16.83 L12.94 15.57 L11.86 16.02 L11.63 18.04 L8.37 18.04 L8.14 16.02 L7.06 15.57 L5.47 16.83 L3.17 14.53 L4.43 12.94 L3.98 11.86 L1.96 11.63 L1.96 8.37 L3.98 8.14 L4.43 7.06 L3.17 5.47 L5.47 3.17 L7.06 4.43 L8.14 3.98 L8.37 1.96 L11.63 1.96 L11.86 3.98 L12.94 4.43 L14.53 3.17 L16.83 5.47 L15.57 7.06Z M12.5 10a2.5 2.5 0 1 1-5 0a2.5 2.5 0 1 1 5 0z',
copy: 'M7 7h9.5v9.5H7z M13 7V3.5H3.5V13H7',
open: 'M11 3.5h5.5V9 M16.5 3.5 9 11 M14 12v4.5H3.5V6H8',
};
const svg = (name) => {
const s = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
s.setAttribute('viewBox', '0 0 20 20');
const p = document.createElementNS('http://www.w3.org/2000/svg', 'path');
p.setAttribute('d', ICON[name]);
s.append(p);
return s;
};
const act = (icon, label, fn) => {
const b = el('button', { class: 'drop-act', title: label, attrs: { 'aria-label': label } }, [svg(icon)]);
b.onclick = (e) => { e.stopPropagation(); fn(); };
return b;
};
// Multi-device: the mesh window (its MESH pill), whatever the grid knows yet.
const mesh = () => !!document.querySelector('.app-name .mesh-pill:not(.portable-pill)');
// The mesh's other devices with this computer's side of the feature for each (state.matrix, cells' `ours`).
function devicesOf(s, feature, flat) {
const m = s.matrix;
const peers0 = (s.peers || []).filter((p) => p && p.id);
// Before the grid knows the mesh: the devices this window lists, each as the flat switches say.
const flatOnly = () => peers0.map((p) => ({ id: p.id, name: p.name || p.id.slice(0, 8), os: p.os, connected: !!p.connected || p.state === 'via', out: !!(flat && flat.out), in: !!(flat && flat.in) }));
if (!m || !m.devices || !(m.features || []).includes(feature)) return flatOnly();
const self = m.devices.find((d) => d.self);
if (!self) return flatOnly();
const cells = m.cells[feature] || [];
const cell = (from, to) => cells.find((c) => c.from === from && c.to === to) || {};
const peers = new Map((s.peers || []).map((p) => [p.id, p]));
return m.devices.filter((d) => !d.self).map((d) => {
const p = peers.get(d.id) || {};
return { id: d.id, name: d.name, os: d.os, connected: !!p.connected || p.state === 'via', out: cell(self.id, d.id).ours === true, in: cell(d.id, self.id).ours === true };
});
}
// The picker: All devices (includes those added later) or the ones ticked. Centred, Cancel and Save.
function pick({ title, devs, sel, onSave }) {
const box = (on, change, label) => {
const c = el('input', { type: 'checkbox', attrs: { 'aria-label': label } });
c.checked = on;
c.onchange = () => change(c.checked);
return c;
};
const list = el('div', { class: 'sf-devs' });
const allRow = el('label', { class: 'sf-all' }, [
box(sel === 'all', (v) => { sel = v ? 'all' : devs.map((d) => d.id); draw(); }, t('All devices')),
el('span', {}, [el('b', { text: t('All devices') }), el('small', { text: t('Includes devices added later') })]),
]);
const save = UI.button(t('Save'), () => { close(); onSave(sel); }, 'primary');
function draw() {
allRow.querySelector('input').checked = sel === 'all';
list.replaceChildren(...devs.map((d) => el('label', { class: 'sf-dev' }, [
box(sel === 'all' || sel.includes(d.id), (v) => {
const now = sel === 'all' ? devs.map((x) => x.id) : sel;
sel = v ? [...new Set([...now, d.id])] : now.filter((x) => x !== d.id);
draw();
}, d.name),
el('span', { class: 'sf-dev-name', text: d.name }),
el('span', { class: 'sf-dev-os', text: d.connected ? (OSNAME[d.os] || '') : t('Not connected') }),
])));
if (!devs.length) list.append(el('div', { class: 'sf-empty', text: t('No other device yet') }));
save.disabled = sel !== 'all' && !sel.length;
}
draw();
const sheet = el('div', { class: 'sf-sheet', attrs: { role: 'dialog', 'aria-modal': 'true' } }, [
el('div', { class: 'sf-editor', attrs: { 'data-literal': '' } }, [el('h2', { text: title }), allRow, list,
el('div', { class: 'sf-foot' }, [el('span', { class: 'sf-grow' }), UI.button(t('Cancel'), () => close()), save])]),
]);
const dlg = el('dialog', { class: 'sf-dialog' }, [sheet]);
const close = () => { try { dlg.close(); } catch (_) { /* gone */ } dlg.remove(); };
dlg.addEventListener('cancel', (e) => { e.preventDefault(); close(); });
document.body.append(dlg);
dlg.showModal();
}
UI.pickDevices = pick; // the picker on its own (File Sharing's Send to)
// Finder › Send with TwinDesk (Multi-device, mac/finder.js): which devices get what was picked there.
setTimeout(() => {
if (!UI.api || !UI.api.onSendPick) return;
UI.api.onSendPick((paths) => {
const s = UI.state;
if (!s || !Array.isArray(paths) || !paths.length) return;
const devs = devicesOf(s, 'files', null);
const sel = (s.peers || []).filter((p) => p.selected).map((p) => p.id);
const name = paths.length === 1 ? paths[0].split('/').pop() : t('{count} items', { count: paths.length });
pick({
title: t('Send “{name}” to', { name }), devs, sel: sel.length ? sel : 'all',
onSave: (picked) => UI.api.sendFiles(paths, picked === 'all' ? devs.filter((d) => d.connected).map((d) => d.id) : picked),
});
});
}, 0);
UI.meshDevices = devicesOf;
// Share and Receive, each a switch with Edit (Multi-device: which devices), as one line of two.
// const p = UI.dirPickers({ feature, flat(s), setFlat(dir, on), shareLabel, receiveLabel, shareWith?, receiveFrom? })
// card.append(...p.items); p.render(s); p.edit(dir); p.summary(dir)
UI.dirPickers = (o) => {
const { api } = UI;
const KEY = (dir) => `td.pick.${o.feature}.${dir}`;
const chosen = (dir) => { try { const v = JSON.parse(localStorage.getItem(KEY(dir)) || '"all"'); return v === 'all' || Array.isArray(v) ? v : 'all'; } catch (_) { return 'all'; } };
const keep = (dir, v) => { try { localStorage.setItem(KEY(dir), JSON.stringify(v)); } catch (_) { /* this window only */ } };
let last = null;
// Apply a direction: on/off with the choice kept (All devices: every device, the flat switch too).
function apply(dir, on, sel = chosen(dir)) {
if (!last) return;
if (!mesh(last)) return o.setFlat(dir, on);
if (sel === 'all' || !on) o.setFlat(dir, on); // the flat switch: the selected device and those added later
for (const d of devicesOf(last, o.feature, o.flat(last))) {
const want = on && (sel === 'all' || sel.includes(d.id));
if (d[dir] !== want) api.setConsent(d.id, o.feature, dir, want);
}
}
const edit = (dir) => {
if (!last) return;
const devs = devicesOf(last, o.feature, o.flat(last));
pick({
title: dir === 'out' ? o.shareWith || t('Share with') : o.receiveFrom || t('Receive from'),
devs, sel: chosen(dir),
onSave: (sel) => { keep(dir, sel); apply(dir, true, sel); },
});
};
// Multi-device: All devices, the one device picked by name, or how many were picked.
const summary = (dir) => {
const sel = chosen(dir);
if (sel === 'all') return t('All devices');
if (sel.length === 1 && last) { const d = devicesOf(last, o.feature, o.flat(last)).find((x) => x.id === sel[0]); if (d) return d.name; }
return t('{count} selected devices', { count: sel.length });
};
// ---- the top: two switches in a line, Edit beside each, More settings ----
const shareSw = UI.switch((v) => apply('out', v), { label: o.shareLabel });
const recvSw = UI.switch((v) => apply('in', v), { label: o.receiveLabel });
const shareEdit = UI.button(t('Edit'), () => edit('out'), 'small');
const recvEdit = UI.button(t('Edit'), () => edit('in'), 'small');
const shareSub = el('small', { class: 'feed-sub' });
const recvSub = el('small', { class: 'feed-sub' });
const item = (sw, label, sub, btn) => el('div', { class: 'feed-ctl' }, [sw.el || sw, el('span', { class: 'feed-ctl-text' }, [el('b', { text: label }), sub]), btn]);
return {
items: [item(shareSw, o.shareLabel, shareSub, shareEdit), item(recvSw, o.receiveLabel, recvSub, recvEdit)],
edit, summary,
render(s) {
last = s;
const f = o.flat(s) || {};
const m = mesh(s);
const devs = m ? devicesOf(s, o.feature, o.flat(s)) : [];
// On: the flat switch, or (Multi-device) any device it goes to.
shareSw.set(!!f.out || devs.some((d) => d.out));
recvSw.set(!!f.in || devs.some((d) => d.in));
shareEdit.hidden = recvEdit.hidden = !m;
shareSub.textContent = m ? summary('out') : t('With the other device');
recvSub.textContent = m ? summary('in') : t('From the other device');
},
};
};
// One picker as a row: its label, what's chosen under it (All devices, or how many), and Edit.
// const r = UI.pickRow({ key, label, title, devices(s) → [{id, name, os, connected}], get(s) → 'all' | ids, save(sel, s) })
// card.append(r.el); r.render(s)
UI.pickRow = (o) => {
let last = null;
const btn = UI.button(t('Edit'), () => last && pick({ title: o.title, devs: o.devices(last), sel: o.get(last), onSave: (sel) => o.save(sel, last) }), 'small');
const row = UI.row(o.label, '', [btn]);
return {
el: row,
render(s) {
last = s;
row.hidden = !mesh();
const sel = o.get(s);
row.setHint(sel === 'all' ? t('All devices') : t(sel.length === 1 ? '1 device' : '{count} devices', { count: sel.length }));
},
};
};
UI.inMesh = mesh;
UI.feedPage = (body, o) => {
const { api } = UI;
let last = null;
const pk = UI.dirPickers(o);
const { edit, summary } = pk;
const more = UI.gearButton(() => show(true)); // the settings, as a gear at the end of the line
const top = el('div', { class: 'card feed-top' }, [...pk.items, more]);
// ---- the feed: Drop's bubbles ----
const bubbles = el('div', { class: 'hub-bubbles' });
const empty = el('div', { class: 'hub-conv-empty hint', text: o.kind === 'clip' ? t('Nothing copied yet. What you copy here and on the other devices shows up here.') : t('No notifications yet. Notifications from the other devices show up here.') });
const scroll = el('div', { class: 'hub-conv-scroll' }, [empty, bubbles]);
const clear = UI.button(t('Clear'), () => (o.kind === 'clip' ? api.clearHistory && api.clearHistory() : api.clearNotifHistory && api.clearNotifHistory()), 'small');
const conv = el('div', { class: 'hub-conv' }, [el('div', { class: 'hub-conv-head web-conv-head' }, [el('div', { class: 'hub-conv-name', text: t('Recent') }), clear]), scroll]);
const feed = el('div', { class: 'card web-drop drop-room feed-room' }, [conv]);
// ---- More settings: Devices and Settings, with Back ----
const shareRow = UI.row(o.shareWith || t('Share with'), '', [UI.button(t('Edit'), () => edit('out'), 'small')]);
const recvRow = UI.row(o.receiveFrom || t('Receive from'), '', [UI.button(t('Edit'), () => edit('in'), 'small')]);
const pickCard = UI.card(t('Devices'), [shareRow, recvRow], { cls: 'keep-on' });
const gridCard = o.grid ? (o.grid.el.classList.contains('card-wrap') ? o.grid.el : UI.card(t('Across the mesh'), [o.grid.el], { cls: 'keep-on' })) : null;
// One column, no tabs: the device pickers and the grid (Multi-device), then the settings.
const tabs = el('div', { class: 'feed-stack' }, [pickCard, gridCard, ...(o.devices || []), ...o.settings].filter(Boolean));
const back = UI.button(t('Back'), () => show(false), 'small');
const settingsView = el('div', { class: 'feed-settings', hidden: true }, [el('div', { class: 'feed-back' }, [back]), tabs]);
const mainView = el('div', { class: 'feed-main' }, [top, feed]);
body.append(mainView, settingsView);
function show(on) {
settingsView.hidden = !on;
mainView.hidden = on;
}
// The feed fills the window below the top, as Drop's does.
const fit = () => {
const tp = feed.getBoundingClientRect().top;
if (!feed.offsetParent || tp <= 0) return;
feed.style.setProperty('--drop-h', `${Math.max(300, Math.floor(window.innerHeight - tp - 20))}px`);
};
window.addEventListener('resize', fit);
const time = (at) => new Date(at).toLocaleTimeString(I18n.locale || undefined, { hour: 'numeric', minute: '2-digit' });
const clock = (at) => (UI.clock ? UI.clock(at) : new Date(at).toLocaleDateString());
function clipBubble(h, i, s) {
const out = h.dir === 'out';
const kids = [el('div', { class: 'hub-from', text: out ? (mesh(s) ? t('Copied here') : t('To {name}', { name: UI.peer(s).name })) : (h.from || UI.peer(s).name) })];
if (h.image && h.image.thumb) kids.push(el('img', { class: 'hub-pic', src: h.image.thumb, alt: '' }));
kids.push(el('div', { class: 'hub-text' + (h.image ? ' hint' : ''), text: h.image ? `${t(h.image.shot ? 'Screenshot' : 'Picture')}, ${h.image.w} × ${h.image.h}` : (h.text || '').trim() || t('(whitespace)') }));
const acts = el('div', { class: 'drop-acts' }, [el('span', { class: 'drop-time', text: time(h.at), title: new Date(h.at).toLocaleString() })]);
const a = !h.image && api.openClip && window.ClipAct && ClipAct.of(h.text);
if (a) acts.append(act('open', t({ link: 'Open', mail: 'Email', call: 'Call' }[a.kind]), () => api.openClip(i)));
if (!h.image || h.image.copy) acts.append(act('copy', t('Copy'), () => api.copyHistory(i)));
kids.push(acts);
return el('div', { class: `hub-bubble ${out ? 'out' : 'in'}` }, kids);
}
function notifBubble(x, s) {
const icons = (s.notifs && s.notifs.historyIcons) || {};
const head = el('div', { class: 'hub-from' }, [
...(icons[x.app] ? [el('img', { class: 'notif-ico', src: icons[x.app], alt: '' })] : []),
el('span', { text: [x.on || UI.peer(s).name, x.appName || x.app].filter(Boolean).join(', ') }),
]);
const kids = [head];
if (x.title) kids.push(el('div', { class: 'hub-text feed-title', text: x.title }));
const sub = [x.subtitle, x.body].filter(Boolean).join(' — ');
if (sub) kids.push(el('div', { class: 'hub-text', text: sub }));
const acts = el('div', { class: 'drop-acts' }, [el('span', { class: 'drop-time', text: time(x.at), title: new Date(x.at).toLocaleString() })]);
if (x.text || sub) acts.append(act('copy', t('Copy'), () => (api.copyText ? api.copyText(sub) : navigator.clipboard.writeText(sub).catch(() => {}))));
if (o.open) { const b = o.open(x, s); if (b) acts.append(b); }
kids.push(acts);
return el('div', { class: 'hub-bubble in' }, kids);
}
let feedKey = '';
function paint(s) {
const items = o.kind === 'clip' ? ((s.clipboard && s.clipboard.history) || []) : ((s.notifs && s.notifs.history) || []);
const key = JSON.stringify([items.map((x) => [x.at, x.id, x.dir, x.from, x.on]), mesh(s)]);
if (key === feedKey) return;
feedKey = key;
const atEnd = scroll.scrollHeight - scroll.scrollTop - scroll.clientHeight < 80;
empty.hidden = items.length > 0;
clear.disabled = !items.length;
// Oldest at the top, as a conversation; a day line between days.
const list = items.map((x, i) => [x, i]).slice(0, 100).reverse();
const nodes = [];
let day = '';
for (const [x, i] of list) {
const d = new Date(x.at).toDateString();
if (d !== day) { day = d; nodes.push(el('div', { class: 'hub-day', text: clock(x.at) })); }
nodes.push(o.kind === 'clip' ? clipBubble(x, i, s) : notifBubble(x, s));
}
bubbles.replaceChildren(...nodes);
if (atEnd || paint.first) scroll.scrollTop = scroll.scrollHeight;
paint.first = false;
}
paint.first = true;
return {
show,
render(s) {
last = s;
requestAnimationFrame(fit);
const m = mesh(s);
pk.render(s);
shareRow.setHint(summary('out'));
recvRow.setHint(summary('in'));
pickCard.hidden = !m;
if (gridCard) gridCard.hidden = !m;
if (o.grid) o.grid.render(s);
paint(s);
},
};
};
})();