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.

3.3 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Overview of a TwinDesk TV (android-tv/), Mac, PC and Linux, in Overview's place while one is connected.
// A TV takes only this computer's screen and sound, files both ways and the cursor and keyboard
// (shared/ui-kinds.js TV_PAGES): its picture, link, Share screen, Send files, Disconnect, and those
// pages as tiles.
'use strict';

(function () {
  const D = UI.deviceParts;
  const { t } = D;

  UI.tab({
    id: 'tv-overview',
    variantOf: 'overview',
    for: ['tv'],
    order: 0,
    title: 'Overview',
    heading: 'Overview',
    icon: 'overview',
    color: 'linear-gradient(#8e8e93, #636366)',
    desc: '',
    hidden: (s) => !D.linked(s),
    build(body, page) {
      const { el, api } = UI;
      const { h1, desc } = D.setup(body, page);
      const sharePage = () => (UI.tabs.some((d) => d.id === 'share') ? 'share' : 'pc-mac');

      const shareBtn = D.button(t('Share screen'), 'show', () => UI.go(sharePage()));
      shareBtn.classList.add('primary');
      const sendBtn = D.button(t('Send files'), 'send', () => api.chooseSendFiles());
      const discBtn = D.button(t('Disconnect'), 'disconnect', () => (api.disconnectPhone ? api.disconnectPhone() : api.disconnect()));
      const hero = D.hero([shareBtn, sendBtn, discBtn]);

      // Drop files on it: they go to the TV's Downloads › TwinDesk.
      const zone = el('div', { class: 'dropzone dv-drop' }, [el('div', {}, [el('div', { class: 'big', text: t('Drop files here') }), el('div', { class: 'hint', text: t('They go to Downloads › TwinDesk on the TV.') })])]);
      zone.ondragover = (e) => { e.preventDefault(); zone.classList.add('over'); };
      zone.ondragleave = () => zone.classList.remove('over');
      zone.ondrop = (e) => {
        e.preventDefault();
        zone.classList.remove('over');
        api.sendFiles(api.pathsOf([...e.dataTransfer.files]));
      };
      const dropCard = UI.card(t('Send files'), [zone], { actions: [UI.button(t('Choose…'), () => api.chooseSendFiles(), 'small link')] });
      const shortcuts = D.tilesCard(t('Shortcuts'), { key: 'tv.shortcuts', standard: { rows: 1, items: [{ id: 'p.' + sharePage(), s: 's' }, { id: 'p.audio', s: 's' }, { id: 'p.files', s: 's' }, { id: 'p.cursor', s: 's' }] } });
      body.append(hero.el, shortcuts.el, dropCard);

      return (s) => {
        const ph = s.phone || {};
        const c = ph.connected;
        const info = ph.info || {};
        const p = UI.peer(s);
        const name = c ? c.name : (s.client && s.client.name) || p.name;
        h1.textContent = name;
        hero.name.textContent = name;
        hero.pic.className = 'device big tv';
        desc.textContent = [info.maker && info.model ? `${info.maker} ${info.model}` : info.model, info.release && `Android TV ${info.release}`].filter(Boolean).join(', ');
        const rtt = c && c.rttMs;
        const via = D.viaOf(s);
        hero.sub.textContent = [t('Connected'), via, rtt != null ? t('{value} ms', { value: rtt }) : ''].filter(Boolean).join(', ');
        hero.battery(null);
        const d = info.display;
        hero.setFacts([
          [t('Screen'), d && d.w && d.h ? `${Math.max(d.w, d.h)} × ${Math.min(d.w, d.h)}` : ''],
          [t('Link'), via],
          ['TwinDesk', info.app || ''],
        ]);
        shortcuts.render(D.pageTiles(s));
      };
    },
  });
})();