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.

20.8 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// General tab, in sections: Startup (start with Windows, received files), Appearance (the switching
// popup, the phone's wallpaper, media controls), Overview (what it shows), Network and Bluetooth,
// Permissions (firewall self-check + Fix, Bluetooth, Location) and This computer (its name, the
// helper, the virtual display driver for Extend).
'use strict';

UI.tab({
  id: 'general',
  order: 100,
  title: I18n.t('General'),
  color: 'linear-gradient(#aeaeb2, #636366)',
  desc: '',
  bottom: true,
  badge: (s) => (s.firewall && s.firewall.ok === false && !s.firewall.checking ? 'warn' : ''),
  build(body) {
    const { el, api } = UI;
    const t = (...args) => I18n.t(...args);
    const language = UI.select([
      { value: 'en', label: '🇬🇧 English' }, { value: 'zh-CN', label: '🇨🇳 简体中文' }, { value: 'ru', label: '🇷🇺 Русский' }, { value: 'tr', label: '🇹🇷 Türkçe' }, { value: 'pt-BR', label: '🇧🇷 Português (Brasil)' }, { value: 'de', label: '🇩🇪 Deutsch' }, { value: 'es', label: '🇪🇸 Español' },
    ], (v) => api.setLanguage(v));
    language.set(I18n.locale);
    const startup = UI.switch((v) => api.setStartup(v), { label: t('Start with Windows') });
    // Received files (shared/received.js): where files sent here and saved from a phone go.
    const recvChange = UI.button(t('Change…'), () => api.chooseReceivedFolder(), 'small');
    const recvReset = UI.button(t('Downloads'), () => api.resetReceivedFolder(), 'small');
    const recvOpen = UI.button(t('Open'), () => api.openReceivedFolder(), 'small');
    const recvRow = UI.row(t('Received files'), '', [recvOpen, recvReset, recvChange], { literal: true });
    const hudSw = UI.switch((v) => api.setApp({ hud: v }), { label: t('Show a popup when switching') });
    // Off, While connected, or Always: connected or not, for a computer on its own (settings.app.keepAwake, keepAwakeAlways)
    const awakeSeg = UI.segmented([
      { value: 'off', label: t('Off') }, { value: 'connected', label: t('While connected') }, { value: 'always', label: t('Always') },
    ], (v) => api.setApp({ keepAwake: v !== 'off', keepAwakeAlways: v === 'always' })); // #240, shared/keepawake.js
    const proximityLabel = t('Lock this computer when the phone disconnects');
    const proximitySw = UI.switch((v) => api.setProximityLock(v), { label: proximityLabel, disabled: true });
    const proximityHint = t('If the last paired phone disconnects unexpectedly, you have 15 seconds to cancel.');
    const proximityRow = UI.row(proximityLabel, proximityHint, [proximitySw]);
    const lockSw = UI.switch((v) => api.setApp({ lockTogether: v }), { label: t('Lock together') }); // #322, shared/locksync.js
    const fwPill = el('span', { class: 'pill' });
    const fwCheck = UI.button(t('Check again'), () => api.checkFirewall(), 'small');
    const fwFix = UI.button(t('Fix'), () => api.fixFirewall(), 'small primary');
    const fwRow = UI.row(t('Firewall'), '', [fwPill, fwCheck, fwFix], { literal: true });
    // (as the Mac): wake is a switch; Send to sends files from Explorer.
    const wakeSw = UI.switch((v) => api.setWake(v), { label: t('Wake from the network') });
    const wakeRow = UI.row(t('Let the other computer wake {me}'), '', [wakeSw]);
    const sendToRow = UI.row(t('TwinDesk in Send to'), '', [], { literal: true });
    const helperPill = el('span', { class: 'pill' });
    const helperRow = UI.row(t('Mouse and keyboard helper'), '', [helperPill]);
    const vddPill = el('span', { class: 'pill' });
    const vddInstall = UI.button(t('Install'), () => api.installVdd(), 'small primary');
    const vddRow = UI.row(t('Virtual display driver'), '', [vddPill, vddInstall]); // Share screen › Extend (vdd.js)
    // Bluetooth when not on the same network: with phones (on unless switched off), with computers (off unless switched on).
    const bleSw = UI.switch((v) => api.setNet({ ble: v }), { label: t('Bluetooth with phones') });
    const bleRow = UI.row(t('Bluetooth with phones'), '', [bleSw]);
    const blePcSw = UI.switch((v) => api.setNet({ blePc: v }), { label: t('Bluetooth with computers') });
    const blePcRow = UI.row(t('Bluetooth with computers'), '', [blePcSw]);
    // Bluetooth off altogether while the session is on the same Wi-Fi (blepolicy.js wifiQuiet).
    // Tailscale (#161, shared/tailnet.js): reaching a paired device away from its network.
    const relayCard = UI.relayCard ? UI.relayCard() : null; // General › Your own relay
    const tailSw = UI.switch((v) => api.setNet({ tailscale: v }), { label: t('Connect through Tailscale') });
    const tailRow = UI.row(t('Connect through Tailscale'), '', [tailSw]);
    const tailHere = UI.row(t('This computer on Tailscale'), '', []);
    const tailHow = UI.row(t('How to set it up'), t('To connect away from home, also from a phone on mobile data: install Tailscale on both devices and sign in to the same account. Pair them once on the same network, or with Connect by address and the other one’s Tailscale address (100.x.y.z). Afterwards, while Tailscale is on, TwinDesk reconnects through it when the other device isn’t on this network.'), []);
    // Network fallback (shared/netlink.js, off by default; one-to-one): a Wi-Fi link when the network drops.
    const fallbackSw = UI.switch((v) => api.setNet({ fallback: v }), { label: t('Network fallback') });
    const fallbackRow = UI.row(t('Network fallback'), '', [fallbackSw]);
    const bleWifiSw = UI.switch((v) => api.setNet({ bleWifiOff: v }), { label: t('Turn off Bluetooth on Wi-Fi connections') });
    const bleWifiRow = UI.row(t('Turn off Bluetooth on Wi-Fi connections'), '', [bleWifiSw]);
    // What Windows has to allow, in one place (each is also asked for where a feature needs it).
    const btPill = el('span', { class: 'pill' });
    const btRow = UI.row(t('Bluetooth'), t('For a phone or computer that isn’t on this network'), [btPill, UI.button(t('Open'), () => api.openBluetoothSettings(), 'small')]);
    const locRow = UI.row(t('Location'), t('To join a phone’s or computer’s Wi-Fi Direct (Windows shows Wi-Fi networks only with it)'), [UI.button(t('Open'), () => api.netLocation(), 'small')]);
    const media = UI.mediaControlsRow(); // a phone's media controls on the Phone page (shared/ui-nowplaying.js)
    const deviceName = el('span', { class: 'value', attrs: { 'data-literal': '' } });
    const deviceRow = UI.row(t('Computer name'), t('How other computers see this one'), [deviceName]);

    // Appearance: the phone's wallpaper behind it here (settings.phone.wallpaper, was on the Phone page).
    const wallSw = UI.switch((v) => api.setPhone({ wallpaper: v }), { label: t('Show the phone’s wallpaper') });
    const wallRow = UI.row(t('Show the phone’s wallpaper'), t('On its tile and Overview. TwinDesk on the phone reads it once wireless debugging is set up'), [wallSw]);
    // Overview: what it shows (settings.ui.overview).
    const parts = [['media', t('Now playing'), t('What plays on the phone, with its controls')], ['qs', t('Quick actions'), t('Wi-Fi, Bluetooth, torch, Do not disturb and more, with volume and ringer')],
      ['notifs', t('Latest notifications'), t('The newest few, with Copy for one-time codes')], ['apps', t('Most used apps'), t('The phone’s most used apps this week')],
      ['clipboard', t('Clipboard'), t('Its recent items, while Clipboard is on')], ['files', t('Send files'), t('A drop zone that sends files to the device')]];
    const partSw = {};
    const partRows = parts.map(([k, label, hint]) => {
      partSw[k] = UI.switch((v) => api.setOverview && api.setOverview({ [k]: v }), { label });
      return UI.row(label, hint, [partSw[k]]);
    });

    // Theme and accent colour (shared/look.js, shared/ui-look.js).
    const styleRow = UI.styleRow((v) => api.setLook({ style: v })); // Glass or Simple (shared/ui-glass.css)
    const themeRow = UI.themeRow((v) => api.setLook({ theme: v }));
    const accentRow = UI.accentRow((v) => api.setLook({ accent: v }));
    // One page that scrolls, its sections listed beside it; Permissions first.
    // Advanced: how input travels (shared/inputlane.js). UDP (tdv2, the default): moves on their own
    // lane beside the session. TCP (tdv1): everything on the session. Read at startup, so Restart shows.
    let protoStart = null; // the protocol this run started with
    const protoRestart = UI.button(t('Restart'), () => api.relaunch(), 'small');
    protoRestart.hidden = true;
    const protoSel = UI.select([
      { value: 'udp', label: t('UDP (tdv2)') }, { value: 'tcp', label: t('TCP (tdv1)') },
    ], (v) => { api.setApp({ inputProtocol: v }); protoRestart.hidden = v === protoStart; });
    const protoRow = UI.row(t('Input protocol'), t('UDP moves the pointer faster. TCP works on networks that block UDP. Applies after a restart'), [protoSel, protoRestart]);
    // Hardware encoder (windows/encoder.js, #133): the GPU's, or OpenH264 in software. Read at startup too.
    const encRestart = UI.button(t('Restart'), () => api.relaunch(), 'small');
    encRestart.hidden = true;
    const encSw = UI.switch((v) => api.setEncoder(v), { label: t('Hardware encoder') });
    const encRow = UI.row(t('Hardware encoder'), t('Shares the screen and app windows with the graphics card. Off: in software (OpenH264), for a picture that stalls or goes black. Applies after a restart'), [encSw, encRestart]);
    // Prioritize performance over battery life (settings.app.keepPinging, shared/quiet.js, #143): off, a
    // session nothing uses stops pinging every second so a phone or laptop can sleep; on, as before.
    const pingSw = UI.switch((v) => api.setApp({ keepPinging: v }), { label: t('Prioritize performance over battery life') });
    const pingRow = UI.row(t('Prioritize performance over battery life'), t('Checks the connection every second, even when nothing is in use. Off: an idle connection is checked every few minutes, and at once when something starts, so phones and laptops can sleep'), [pingSw]);
    // Local API (shared/localapi.js): the person's own scripts on this computer.
    const apiSw = UI.switch((v) => api.setApp({ localApi: v }), { label: t('Local API') });
    const apiRow = UI.row(t('Local API'), '', [apiSw], { literalHint: true });
    // Task alerts: twindesk-notify (bin/ in TwinDesk's folder) runs a command and tells the phone when it ends (shared/task-alerts.js)
    let notifyCmd = '';
    const notifyRow = UI.row(t('Task alerts'), '', [UI.button(t('Copy'), () => notifyCmd && api.copyText(notifyCmd), 'small')], { literalHint: true });
    notifyRow.hidden = true;
    const engines = UI.enginesRows(); // Engines in use, while connected (shared/ui-engines.js)
    const modules = UI.modulesCard ? UI.modulesCard() : { card: null, update() {} }; // General › Modules (shared/ui-modules.js; not in Multi-device)
    const portable = UI.portableCard ? UI.portableCard() : { card: null, update() {} }; // TwinDesk Portable (shared/ui-portable.js)
    // Debug (shared/ui-debug.js, Multi-device): its page opens from here instead of the sidebar.
    const debugBtn = UI.button(t('Open'), () => UI.go('debug'), 'small');
    const debugPill = el('span', { class: 'pill good', text: t('On') });
    debugPill.hidden = true;
    const debugCard = UI.card(t('Debug'), [UI.row(t('Debug'), t('Status, logs, screenshots and diagnostics of any device'), [debugPill, debugBtn])]);
    debugCard.hidden = true;
    const sections = UI.sections([
      ...(portable.card ? [portable.card] : []),
      UI.card(t('Permissions'), [fwRow, btRow, locRow]),
      UI.card(t('Startup'), [
        UI.row(t('Start with Windows'), t('TwinDesk waits in the tray'), [startup]),
        recvRow,
        UI.row(t('Keep the display awake'), '', [awakeSeg.el]),
        UI.row(t('Lock together'), t('This computer locks when another connected computer locks, and the other way round. On each computer'), [lockSw]),
      ]),
      UI.card(t('Security'), [proximityRow]),
      UI.card(t('Appearance'), [
        styleRow,
        themeRow,
        accentRow,
        UI.arrangeRow ? UI.arrangeRow() : null,
        UI.row(t('Show a popup when switching'), t('When the mouse and keyboard move between devices'), [hudSw]),
        wallRow,
        media.el,
      ]),
      UI.card(t('Language'), [
        UI.row(t('Language'), t('Some pages are still in English. Changing the language restarts TwinDesk.'), [language]),
      ]),
      UI.card(t('Tutorial'), [
        UI.row(t('Tour of TwinDesk'), t('How to install TwinDesk on your other device, connect it, and what each page does.'), [UI.button(t('Show the tour'), () => window.Tour && Tour.start(), 'small')]),
        UI.row(t('What’s new'), t('What came in this version.'), [UI.button(t('Show'), () => window.Tour && Tour.news(), 'small')]),
      ]),
      UI.card(t('Overview'), partRows),
      UI.card(t('Network and Bluetooth'), [bleRow, blePcRow, bleWifiRow, fallbackRow, wakeRow, sendToRow]),
      UI.card(t('Tailscale'), [tailRow, tailHere, tailHow]),
      relayCard ? relayCard.el : null, // your own relay (shared/ui-relay.js)
      UI.card(t('This computer'), [deviceRow, helperRow, vddRow]),
      UI.card(t('Connections'), [pingRow, apiRow, notifyRow]),
      ...(modules.card ? [modules.card] : []),
      UI.card(t('Advanced'), [protoRow, ...(api.setEncoder ? [encRow] : []), ...engines.rows]),
      debugCard,
    ]);
    body.append(sections);

    return (s) => {
      debugCard.hidden = !(UI.tabs || []).some((d) => d.id === 'debug'); // the Debug module, in Multi-device
      debugPill.hidden = !(s.debug && s.debug.debuggedBy && s.debug.debuggedBy.length); // someone debugging this computer now
      engines.update(s);
      modules.update(s);
      portable.update(s);
      if (s.app) {
        const proto = s.app.inputProtocol === 'tcp' ? 'tcp' : 'udp';
        if (protoStart === null) protoStart = proto;
        protoSel.set(proto);
        protoRestart.hidden = proto === protoStart;
      }
      if (s.encoder) {
        encSw.set(s.encoder.hw !== false);
        encRestart.hidden = !s.encoder.restart;
        if (s.encoder.auto && !s.encoder.restart) encRow.setHint(t('Turned off by itself: the hardware encoder stopped sending. Software encoding (OpenH264) is in use'));
        else if (s.encoder.auto) encRow.setHint(t('Turned off by itself: the hardware encoder stopped sending. Restart to use the software encoder (OpenH264)'));
        else encRow.setHint(t('Shares the screen and app windows with the graphics card. Off: in software (OpenH264), for a picture that stalls or goes black. Applies after a restart'));
      }
      styleRow.render(s.look && s.look.style);
      themeRow.render(s.look && s.look.theme);
      accentRow.render(s.look);
      sections.spy();
      media.update(s);
      wallSw.set(!s.phone || !s.phone.settings || s.phone.settings.wallpaper !== false);
      const ov = (s.ui && s.ui.overview) || {};
      for (const k of Object.keys(partSw)) partSw[k].set(ov[k] !== false);
      startup.set(s.startup);
      hudSw.set(s.app.hud);
      awakeSeg.set(s.app.keepAwake === false ? 'off' : s.app.keepAwakeAlways === true ? 'always' : 'connected');
      const canLock = s.proximityLockSupported === true;
      proximitySw.disable(!canLock);
      proximitySw.set(canLock && s.app.proximityLock === true);
      proximityRow.setHint(canLock ? proximityHint : t('Automatic screen locking is unavailable on this desktop.'));
      lockSw.set(s.app.lockTogether === true);
      pingSw.set(s.app.keepPinging === true);
      apiRow.hidden = !s.localApi;
      notifyCmd = s.localApi && s.localApi.on && s.localApi.notify ? (/\s/.test(s.localApi.notify) ? `"${s.localApi.notify}"` : s.localApi.notify) : '';
      notifyRow.hidden = !notifyCmd;
      if (notifyCmd) notifyRow.setHint(t('Put {cmd} before a command in a terminal, and the phone tells you when it ends. Turn on Task alerts in the phone’s Notifications', { cmd: notifyCmd }));
      if (s.localApi) {
        apiSw.set(!!s.localApi.on);
        apiRow.setHint(s.localApi.on ? t('For your own scripts here: its address and key are in {file}, and the key changes each time it starts', { file: s.localApi.file }) : t('Lets your own scripts on this computer send files and set the clipboard. Nothing from a browser'));
      }
      const f = s.files || {};
      recvReset.hidden = !f.receivedFolder;
      const receivedDescription = t('Files sent to {me} from another computer or a phone, and what’s saved from a phone’s Files and Photos', { me: s.device.name });
      recvRow.setHint(f.receivedFolder && f.received !== f.receivedFolder
        ? t('{folder} isn’t there now: Downloads meanwhile. {description}', { folder: f.receivedFolder, description: receivedDescription })
        : t('{folder} · {description}', { folder: f.received || t('Downloads'), description: receivedDescription }));
      const fw = s.firewall || {};
      fwPill.textContent = fw.checking ? t('Checking…') : fw.ok ? t('OK') : fw.ok === false ? t('Needs a fix') : '';
      fwPill.className = 'pill ' + (fw.checking ? 'muted' : fw.ok ? 'good' : 'bad');
      fwRow.setHint(fw.ok === false ? UI.firewallHint(fw) : '');
      fwCheck.disabled = !!fw.checking;
      fwFix.hidden = fw.checking || fw.ok !== false || !!fw.error;
      const w = s.wake || {};
      wakeSw.set(w.on === true);
      wakeSw.disable(!w.checked || w.on == null || !!w.busy);
      wakeRow.setHint(w.error ? t(w.error) : w.busy ? t('Changing…') : !w.checked ? t('Checking…')
        : w.on == null ? t('No network adapter here can wake {me}')
          : t('Its network adapter wakes {me} on a magic packet. Asks for administrator rights to change it'));
      sendToRow.setHint(s.peer ? t('Right-click files › Send to › {device} (TwinDesk)', { device: s.peer.name }) : t('Shows up once a computer is paired'));
      const h = s.kvmState.helper;
      helperPill.textContent = h ? (h === 'starting' ? t('Starting…') : t('Not running')) : t('Running');
      helperPill.className = 'pill ' + (h ? (h === 'starting' ? 'muted' : 'bad') : 'good');
      helperRow.setHint(h && h !== 'starting' ? t(h) : '');
      const v = s.pcScreen.vdd;
      vddPill.textContent = !v.checked ? t('Checking…') : v.busy === 'install' ? t('Installing…') : v.busy === 'remove' ? t('Removing…') : v.installed ? t('Installed') : t('Not installed');
      vddPill.className = 'pill ' + (!v.checked || v.busy ? 'muted' : v.installed ? 'good' : 'bad');
      vddInstall.hidden = !v.checked || v.installed;
      vddInstall.disabled = !!v.busy;
      vddRow.setHint(v.message ? t(v.message) : v.installed ? t('Adds the extra screen for Share screen › Extend')
        : t('Needed for Share screen › Extend. Asks for administrator rights once'));
      const n = s.net || {};
      const radio = n.radio === 'off' ? t('Bluetooth is off in Windows settings')
        : n.radio === 'unsupported' ? t('This PC’s Bluetooth can’t do it (needs Bluetooth LE)') : '';
      bleSw.set(n.ble !== false);
      bleRow.setHint(n.ble === false ? t('Only phones on this network or a USB cable connect')
        : radio || t('A phone nearby connects through Bluetooth; files and screens switch to Wi-Fi Direct for a moment'));
      blePcSw.set(n.blePc === true);
      bleWifiSw.set(n.bleWifiOff !== false);
      fallbackRow.hidden = typeof location !== 'undefined' && /\/mesh\//.test(location.pathname); // one-to-one for now
      fallbackSw.set(n.fallback === true);
      fallbackRow.setHint(n.fallback === true ? t('When the Wi-Fi drops, the phone makes a Wi-Fi Direct link and this computer joins it, so screens, sound and files go on. Back on the usual Wi-Fi when the phone sees it again')
        : t('Off: when the Wi-Fi drops, the session goes on through Bluetooth only'));
      tailSw.set(n.tailscale !== false);
      tailRow.setHint(n.tailscale === false ? t('Off: only this network, Bluetooth and the cable') : t('When the other device isn’t on this network, TwinDesk tries its Tailscale address'));
      tailHere.setHint((n.tailnet || []).length ? n.tailnet.join(', ') : t('Not on Tailscale now'));
      if (relayCard) relayCard.update(n.relay);
      bleWifiRow.setHint(n.bleWifiOff === false ? t('Bluetooth stays on beside the Wi-Fi, the way back if it drops')
        : n.bleOff ? t('Off now: the session is on the same Wi-Fi. Bluetooth comes back when it ends')
          : t('On the same Wi-Fi network (not Wi-Fi Direct), Bluetooth goes off until the session ends. With a computer, phones can’t find this one meanwhile'));
      blePcRow.setHint(n.blePc !== true ? t('Only computers on this network connect')
        : radio || t('A computer nearby connects through Bluetooth; files and screens switch to Wi-Fi Direct for a moment'));
      btPill.textContent = n.radio === 'off' ? t('Off') : n.radio === 'unsupported' ? t('Not supported') : n.radio ? t('On') : t('Unknown');
      btPill.className = 'pill ' + (n.radio === 'off' || n.radio === 'unsupported' ? 'bad' : n.radio ? 'good' : 'muted');
      deviceName.textContent = s.device.name;
    };
  },
});