Skip to content

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.

2.7 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// A shared folder offered to a computer with Drive off and no folder of its own (shared/drive-wake.js,
// shared/drive-host.js heard): the offer loads the engine, shows on the page to Add, and the engine
// doesn't start until it's added. Found live between a Mac and Linux in Multi-device (2026-11-30).
// Run with: node shared/test/drive-wake.js
'use strict';
const assert = require('assert');
const os = require('os');
const fs = require('fs');
const path = require('path');
const { EventEmitter } = require('events');
const host = require('../drive-host.js');
const { driveWake } = require('../drive-wake.js');

const bus = new EventEmitter();
const mesh = {
  on: (t, fn) => bus.on(t, fn),
  onPeer: () => {},
  send: () => {},
  session: () => null,
  peerName: (id) => (id === 'mac' ? 'Inukas-MBA' : id),
  isComputer: (id) => id !== 'phone',
  connectedIds: () => ['mac'],
  setRequest: () => {},
};
const settings = { drive: { on: false, folders: [] } };
let drive = null, loads = 0, changes = 0;
const load = () => drive || (loads++, drive = host.createMesh({
  settings, save() {}, me: 'linux', meName: 'ubuntu', userData: fs.mkdtempSync(path.join(os.tmpdir(), 'dw-')),
  trash: async () => {}, mesh, onChange: () => { changes++; },
}));
driveWake((t, fn) => bus.on(t, fn), () => drive, load);

// An empty list (the other computer shares nothing with us) loads nothing.
bus.emit('drive.folders', { list: [] }, 'mac');
assert.strictEqual(loads, 0);
// A phone never offers a computer's folder.
bus.emit('drive.folders', { list: [{ f: 'abcdef0123456789', name: 'x' }] }, 'phone');
assert.strictEqual(loads, 1, 'loaded on a non-empty list');
assert.deepStrictEqual(drive.view().offers, [], 'a phone’s list is ignored');

// The Mac's offer: loaded once, shown to Add, nothing started.
bus.emit('drive.folders', { list: [{ f: '3f64a1ab6114f3bf', name: 'share-test' }] }, 'mac');
assert.strictEqual(loads, 1);
assert.deepStrictEqual(drive.view().offers, [{ f: '3f64a1ab6114f3bf', name: 'share-test', from: ['Inukas-MBA'] }]);
assert.ok(changes > 0, 'the page is told');
assert.deepStrictEqual(settings.drive.folders, []);

// Taken back: the offer goes.
bus.emit('drive.folders', { list: [] }, 'mac');
assert.deepStrictEqual(drive.view().offers, []);

// One to one: no fromId, the session's device.
const d2 = host.createMesh({ settings: { drive: { on: false, folders: [] } }, save() {}, me: 'l', meName: 'l', userData: os.tmpdir(), trash: async () => {}, mesh: { ...mesh, on: () => {} }, onChange() {} });
d2.heard({ list: [{ f: '0123456789abcdef', name: 'Docs' }] });
assert.deepStrictEqual(d2.view().offers.map((o) => o.name), ['Docs']);
console.log('drive-wake: ok');