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.

1.5 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// File Sharing › File Shelf › Shake to open: tells the helper to watch for a shaken file drag
// (mac-helper ShelfShake.swift, windows-helper Capture.cs ShelfStep, linux-helper capture.c
// shelf_step) and opens the shelf under the pointer when it says shelfShake. Made by the app only
// once the setting has been on (main.js pushState): while off, this file isn't even loaded, and the
// helper has no tap (Mac) or skips one flag check (Windows, Linux).
'use strict';

function shelfWatch({ helper, on, open }) {
  let sent = null;
  const h = () => (typeof helper === 'function' ? helper() : helper);
  const send = (want) => {
    const x = h();
    if (!x) return;
    try { x.send('shelfWatch', { on: want }); sent = want; } catch { sent = null; }
  };
  let wired = null;
  const wire = () => {
    const x = h();
    if (!x || wired === x) return;
    wired = x;
    x.on('ready', () => { sent = null; apply(); }); // a restarted helper starts with it off
    x.on('event', (name, msg) => {
      if (name !== 'shelfShake' || !on()) return;
      let at = { x: Number(msg.x) || 0, y: Number(msg.y) || 0 };
      if (process.platform === 'win32') {
        try { at = require('electron').screen.screenToDipPoint(at); } catch { /* as it is */ }
      }
      open({ x: Math.round(at.x), y: Math.round(at.y) });
    });
  };
  function apply() {
    wire();
    const want = !!on();
    if (want !== sent) send(want);
  }
  return { apply };
}

module.exports = { shelfWatch };