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.

6.8 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Clipboard tab: accept (Mac → PC) and send (PC → Mac) as two direction cards, then
// timing, privacy and the Recent list for both.
'use strict';

UI.tab({
  id: 'clipboard',
  order: 40,
  title: I18n.t('Clipboard'),
  color: 'linear-gradient(#64d2ff, #30b0c7)',
  desc: I18n.t('Copy on one computer, paste on the other.'),
  master: { get: (s) => s.clipboard.enabled, set: (v) => UI.api.setClipboard({ enabled: v }) },
  badge: (s) => (!s.clipboard.enabled ? '' : s.link.state === 'connected' && !s.clipboard.peerAccepts ? 'warn' : 'on'),
  build(body) {
    const { el, api } = UI;
    const set = (partial) => api.setClipboard(partial);

    const peerRow = UI.row('', '', [], { literal: true });
    const skipNote = UI.note('info', '', { literal: true });
    const wlNote = UI.note('warn', '', { literal: true }); // linux/wlclip.js missing()
    const mode = UI.segmented([
      { value: 'instant', label: I18n.t('Instantly') }, // the default
      { value: 'switch', label: I18n.t('When you switch') },
    ], (v) => set({ mode: v }));
    const modeRow = UI.row(I18n.t('Sync'), '', [mode]);
    const concealed = UI.switch((v) => set({ skipConcealed: v }), { label: I18n.t('Skip passwords') });
    const maxKB = UI.select([
      { value: 16, label: '16 KB' }, { value: 64, label: '64 KB' }, { value: 256, label: '256 KB' },
    ], (v) => set({ maxKB: Number(v) }));
    // Pictures (clipimage.js): screenshots put on the clipboard among them. Not in Multi-device yet.
    const pictures = UI.switch((v) => set({ images: v }), { label: I18n.t('Pictures') });
    const picturesRow = UI.row(I18n.t('Pictures'), '', [pictures]);
    // Text only: pictures have their own limit (10 MB).
    const maxKBRow = UI.row(I18n.t('Largest text'), '', [maxKB]);
    const historySize = UI.select([
      { value: 0, label: I18n.t('Off') }, { value: 10, label: I18n.t('10 items') }, { value: 20, label: I18n.t('20 items') },
      { value: 50, label: I18n.t('50 items') }, { value: 100, label: I18n.t('100 items') },
    ], (v) => set({ historySize: Number(v) }));
    const pair = UI.dirCards(
      { on: { get: (s) => s.clipboard.receive, set: (v) => set({ receive: v }) }, label: I18n.t('Copy on {name}, paste on {me}'), rows: [] },
      { on: { get: (s) => s.clipboard.send, set: (v) => set({ send: v }) }, label: I18n.t('Copy on {me}, paste on {name}'), rows: [] },
    );

    // While away (shared/clipqueue.js): copies made with the other device gone go to its Recent
    // when it's back; only live copies change what it pastes, unless Put the latest is on there.
    const queue = UI.switch((v) => set({ queue: v }), { label: I18n.t('Queue copies while away') });
    const queueRow = UI.row(I18n.t('Queue copies while away'), '', [queue]);
    const latest = UI.switch((v) => set({ queueLatest: v }), { label: I18n.t('Put the latest on the clipboard') });
    const latestRow = UI.row(I18n.t('Put the latest on the clipboard'), I18n.t('When queued copies arrive here, the newest one is pasted next'), [latest]);
    const awayCard = UI.card(I18n.t('While away'), [queueRow, latestRow]);

    const recentRow = UI.row(I18n.t('Recent items'), I18n.t('Never saved to disk'), [historySize]);
    const hist = UI.historyCard('clip');

    // Laid out as Drop (shared/ui-feed.js): Share and Receive at the top (Edit: which devices, Multi-device),
    // what was copied below, More settings for the devices, the grid and the options.
    const grid = window.MeshMatrix ? MeshMatrix.create({ feature: 'clipboard', toggle: (id, f, dir, on) => api.setConsent(id, f, dir, on) }) : null;
    const feed = UI.feedPage(body, {
      kind: 'clip', feature: 'clipboard',
      flat: (s) => ({ out: !!(s.clipboard && s.clipboard.send), in: !!(s.clipboard && s.clipboard.receive) }),
      setFlat: (dir, on) => set(dir === 'out' ? { send: on } : { receive: on }),
      shareLabel: I18n.t('Share this device’s clipboard'), receiveLabel: I18n.t('Receive the other devices’ clipboard'),
      shareWith: I18n.t('Share the clipboard with'), receiveFrom: I18n.t('Receive the clipboard from'),
      grid: grid ? { el: grid.el, render: (s) => grid.render(s.matrix) } : null,
      settings: [peerRow, wlNote,
        UI.card('', [modeRow, picturesRow]),
        UI.card(I18n.t('Privacy'), [
          UI.row(I18n.t('Skip passwords'), I18n.t('From password managers'), [concealed]),
          maxKBRow,
          recentRow,
        ]),
        awayCard,
        skipNote, hist.el],
    });


    return (s) => {
      const c = s.clipboard;
      hist.update(s);
      feed.render(s);
      recentRow.setHint(s.history && s.history.save ? I18n.t('Kept encrypted, as History says') : I18n.t('Never saved to disk'));
      pair.update(s);
      mode.set(c.mode);
      modeRow.setHint(c.mode === 'instant' ? I18n.t('As soon as you copy') : I18n.t('When you move to the other computer'));
      wlNote.set(c.enabled && c.needsWlClipboard ? I18n.t('Install wl-clipboard (wl-paste and wl-copy): without it, copies made in other apps aren’t seen here on this Wayland desktop') : '');
      picturesRow.hidden = !c.imageSupport;
      pictures.set(!!c.images);
      picturesRow.setHint(!c.images ? I18n.t('Pictures and screenshots you copy, up to 10 MB, both ways')
        // Multi-device: every connected device without Pictures, not only the selected one
        : c.noPictures && c.noPictures.length ? I18n.t('Turn on Pictures on {device} too (TwinDesk 2.3 or later there)', { device: c.noPictures.join(', ') })
        : !c.noPictures && s.link.state === 'connected' && !c.peerImages ? I18n.t('Turn on Pictures on {device} too (TwinDesk 2.3 or later there)', { device: UI.peer(s).name })
          : I18n.t('Pictures and screenshots you copy, up to 10 MB, both ways. Not over Bluetooth'));
      concealed.set(c.skipConcealed);
      maxKB.set(c.maxKB);
      maxKBRow.setHint(c.imageSupport ? I18n.t('Longer text isn’t sent. Pictures: up to 10 MB') : I18n.t('Longer text isn’t sent'));
      historySize.set(c.historySize);
      awayCard.hidden = c.queued === undefined; // Multi-device: not yet
      queue.set(c.queue !== false);
      latest.set(!!c.queueLatest);
      queueRow.setHint(c.queue === false ? I18n.t('Copies made while {name} is away aren’t kept')
        : c.queued ? I18n.t('{count} waiting for {name}: they go in its Recent, not on its clipboard', { count: c.queued })
          : I18n.t('Copies made while {name} is away go in its Recent when it’s back, not on its clipboard'));
      const refused = s.link.state === 'connected' && !c.peerAccepts;
      peerRow.hidden = !refused;
      peerRow.label.textContent = I18n.t('Turned off on {device}', { device: UI.peer(s).name });
      peerRow.setHint('');
      skipNote.set(c.enabled && c.lastSkip ? I18n.t('Last item not sent: {reason}.', { reason: I18n.t(c.lastSkip, UI.peer(s)) }) : '');

    };
  },
});