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.
// File Shelf's window (shared/file-shelf.js): files kept at hand, the Recent view, the share corner.
'use strict';
const api = window.fileShelf;
document.documentElement.dataset.os = api.platform || '';
const $ = (id) => document.getElementById(id);
const list = $('items');
let serial = 0, state = null;
const bytes = size => size < 1024 ? `${size} B` : size < 1048576 ? `${(size / 1024).toFixed(1)} KB` : size < 1073741824 ? `${(size / 1048576).toFixed(1)} MB` : `${(size / 1073741824).toFixed(1)} GB`;
const SVG = 'http://www.w3.org/2000/svg';
const ICONS = {
folder: 'M3 6.5A1.5 1.5 0 0 1 4.5 5h4.6l2 2h8.4A1.5 1.5 0 0 1 21 8.5v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 17.5z',
recent: 'M12 3a9 9 0 1 0 9 9h-2a7 7 0 1 1-2.05-4.95L14 10h7V3l-2.64 2.64A8.97 8.97 0 0 0 12 3zm-1 4v6l5 3 .9-1.5-3.9-2.3V7z',
back: 'M15.5 4.5 8 12l7.5 7.5-1.4 1.4L5.2 12l8.9-8.9z',
close: 'M6.4 5 12 10.6 17.6 5 19 6.4 13.4 12l5.6 5.6-1.4 1.4-5.6-5.6L6.4 19 5 17.6l5.6-5.6L5 6.4z',
down: 'M11 4h2v9.2l3.6-3.6L18 11l-6 6-6-6 1.4-1.4 3.6 3.6zM5 18h14v2H5z',
portal: 'M12 3c5 0 9 4 9 9s-4 9-9 9-9-4-9-9 4-9 9-9zm0 3a6 6 0 1 0 0 12 6 6 0 0 0 0-12zm0 3a3 3 0 1 1 0 6 3 3 0 0 1 0-6z',
share: 'M18 16a3 3 0 0 0-2.4 1.2l-6.7-3.4a3 3 0 0 0 0-1.6l6.7-3.4A3 3 0 1 0 15 7c0 .3 0 .5.1.8L8.4 11.2a3 3 0 1 0 0 3.6l6.7 3.4A3 3 0 1 0 18 16z',
computer: 'M3 5.5A1.5 1.5 0 0 1 4.5 4h15A1.5 1.5 0 0 1 21 5.5v10a1.5 1.5 0 0 1-1.5 1.5H13v2h3v1.5H8V19h3v-2H4.5A1.5 1.5 0 0 1 3 15.5z',
phone: 'M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2zm0 3v13h8V5zm3 14.5h2V21h-2z',
};
function icon(name, size = 18) {
const svg = document.createElementNS(SVG, 'svg');
svg.setAttribute('viewBox', '0 0 24 24');
svg.setAttribute('width', size);
svg.setAttribute('height', size);
svg.setAttribute('aria-hidden', 'true');
const p = document.createElementNS(SVG, 'path');
p.setAttribute('d', ICONS[name]);
p.setAttribute('fill', 'currentColor');
svg.append(p);
return svg;
}
const PHONES = new Set(['android', 'ios']);
function row(item) {
const li = document.createElement('li');
const file = document.createElement('div');
file.className = 'item'; file.draggable = true; file.tabIndex = 0;
file.dataset.id = item.id;
file.setAttribute('aria-label', item.name);
const badge = document.createElement('span'); badge.className = 'icon';
if (item.kind === 'folder') badge.append(icon('folder', 22)); // drawn (a font's ▰ came out as a dash)
else badge.textContent = item.extension || '—';
const label = document.createElement('div'); label.className = 'label';
const name = document.createElement('div'); name.className = 'name'; name.textContent = item.name;
const detail = document.createElement('div'); detail.className = 'detail';
detail.textContent = [item.detail, item.size === null ? '' : bytes(item.size)].filter(Boolean).join(', ');
label.append(name, detail); file.append(badge, label);
file.ondragstart = event => { event.preventDefault(); fromShelf([item.id]); api.drag([item.id]); };
file.oncontextmenu = event => { event.preventDefault(); api.menu(item.id); };
file.ondblclick = () => api.reveal(item.id);
file.onkeydown = event => {
if (event.key === 'Enter') { event.preventDefault(); api.reveal(item.id); }
if ((event.key === 'Delete' || event.key === 'Backspace') && state.view === 'shelf') { event.preventDefault(); api.remove([item.id]); }
};
li.append(file);
return li;
}
function render(next) {
if (!next) return;
state = next;
const s = state.s, recent = state.view === 'recent';
const focused = document.activeElement?.dataset?.id;
$('title').textContent = recent ? s.recent : s.title;
document.title = s.title;
$('hint').textContent = state.items.length ? s.hint : '';
const empty = $('empty');
empty.textContent = recent ? s.emptyRecent : s.empty;
empty.hidden = state.items.length > 0;
empty.classList.toggle('drop', !recent);
const rb = $('recent');
rb.replaceChildren(icon(recent ? 'back' : 'recent'));
rb.title = recent ? s.back : s.recent; rb.setAttribute('aria-label', rb.title);
const cb = $('close');
cb.replaceChildren(icon('close', 16)); cb.title = s.close; cb.setAttribute('aria-label', s.close);
const clear = $('clear');
clear.textContent = s.clear; clear.hidden = recent || !state.items.length;
const all = $('all');
all.hidden = state.items.length < 2;
all.textContent = s.all;
list.replaceChildren(...state.items.map(row));
if (focused) list.querySelector(`[data-id="${CSS.escape(focused)}"]`)?.focus();
$('share-icon').replaceChildren(icon('share', 16));
$('share-label').textContent = s.share;
paintDevices();
}
// The share corner (bottom right): files dragged from the shelf into it open the devices connected.
// Holding on a device opens what it can take: its Downloads (drop) and a Portal (hold: the pointer
// goes there with the files still held, dropped where they're let go).
// A hold starts only once the pointer has moved onto a target after it was drawn: what lands under a
// still pointer when the choices open (Back, where the device was) doesn't fire by itself.
let dragIds = null, dragTimer = 0, dwell = 0, dwellOn = null, opened = null, armed = 0, lastXY = '';
const fromShelf = (ids) => { dragIds = ids; clearTimeout(dragTimer); dragTimer = setTimeout(endShare, 30000); };
function endShare() {
dragIds = null; opened = null;
clearTimeout(dwell);
document.body.classList.remove('sharing');
if (state) paintDevices();
}
const hold = (t, ms, fn) => { clearTimeout(dwell); dwellOn = t; dwell = setTimeout(() => { dwellOn = null; fn(); }, ms); };
const unhold = (t) => { if (dwellOn === t) { clearTimeout(dwell); dwellOn = null; } };
function target(cls, iconName, label, on) {
const t = document.createElement('div');
t.className = 'device ' + cls;
t.append(icon(iconName, 26));
const name = document.createElement('span'); name.textContent = label;
t.append(name);
t.ondragenter = event => { event.preventDefault(); t.classList.add('over'); };
t.ondragover = event => {
event.preventDefault(); event.dataTransfer.dropEffect = 'copy';
t.classList.add('over');
const xy = event.screenX + ',' + event.screenY, moved = xy !== lastXY;
lastXY = xy;
if (on.hold && dwellOn !== t && moved && Date.now() >= armed) hold(t, on.hold[0], () => on.hold[1](t));
};
t.ondragleave = event => { if (t.contains(event.relatedTarget)) return; t.classList.remove('over'); unhold(t); }; // into its own icon or name: still on it
t.ondrop = event => {
event.preventDefault(); event.stopPropagation();
t.classList.remove('over');
clearTimeout(dwell);
if (on.drop) { on.drop(event); t.classList.add('sent'); setTimeout(endShare, 700); } else endShare();
done();
};
return t;
}
function paintDevices() {
const s = state.s;
armed = Date.now() + 250;
clearTimeout(dwell); dwellOn = null;
if (opened) {
const d = state.devices.find(x => x.id === opened);
if (!d) { opened = null; return paintDevices(); }
$('share-hint').textContent = d.name;
const list = [target('choice', 'down', s.downloads, { drop: event => api.send(d.id, dragIds || [], [...event.dataTransfer.files]) })];
if (d.portal) list.push(target('choice', 'portal', s.portal, { hold: [500, () => { const ids = dragIds || []; endShare(); api.portal(d.id, ids); }] }));
list.push(target('choice back', 'back', s.devicesBack, { hold: [450, () => { opened = null; paintDevices(); }] })); // last: Downloads takes the device's place
return $('devices').replaceChildren(...list);
}
$('share-hint').textContent = state.devices.length ? s.shareHint : s.noDevices;
$('devices').replaceChildren(...state.devices.map(d => target('', PHONES.has(d.os) ? 'phone' : 'computer', d.name, {
hold: [650, () => { opened = d.id; paintDevices(); }],
drop: event => api.send(d.id, dragIds || [], [...event.dataTransfer.files]), // let go at once: its Downloads
})));
}
// A drag over the window: the shelf takes the drop (files from elsewhere); the share corner opens
// only for files dragged from the shelf.
// Left the window only when the pointer is outside it: counting enters and leaves went wrong over the
// device tiles (and the tiles redrawn under the pointer never send their leave), closing the panel mid-hold.
const done = () => document.body.classList.remove('dragging');
const outside = (e) => (e.clientX === 0 && e.clientY === 0) || e.clientX < 0 || e.clientY < 0 || e.clientX >= innerWidth || e.clientY >= innerHeight;
document.addEventListener('dragenter', event => { event.preventDefault(); document.body.classList.add('dragging'); });
document.addEventListener('dragleave', event => {
if (!outside(event)) return;
done();
clearTimeout(dwell); dwellOn = null;
if (dragIds && !opened) document.body.classList.remove('sharing');
});
document.addEventListener('dragover', event => { event.preventDefault(); event.dataTransfer.dropEffect = 'copy'; });
document.addEventListener('drop', event => {
event.preventDefault();
done();
const mine = !!dragIds;
endShare();
if (!mine && event.dataTransfer.files.length) api.add([...event.dataTransfer.files]); // its own files stay where they are
});
$('share').addEventListener('dragenter', () => { if (dragIds && state.devices.length) document.body.classList.add('sharing'); });
$('all').ondragstart = event => { event.preventDefault(); fromShelf(state.items.map(i => i.id)); api.drag(dragIds); };
$('recent').onclick = () => api.view(state && state.view === 'recent' ? 'shelf' : 'recent');
$('close').onclick = () => api.close();
$('clear').onclick = () => api.clear();
api.onState(next => { serial++; render(next); });
const initial = serial;
api.read().then(next => { if (serial === initial) render(next); }).catch(() => {});
window.addEventListener('keydown', event => {
if (event.key === 'Escape') api.close();
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'v') { event.preventDefault(); api.paste(); }
});