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.8 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// New (Mac, Windows, Linux, one-to-one and Multi-device): a small New pill on what this version adds,
// until it's opened: on its page in the sidebar (gone once the page is shown) and, for a few, on the
// control itself (UI.newPill(id), gone once it's used: UI.newSeen(id)). What was seen is kept in
// this window's storage. No timer: it looks again only when a page is shown or the sidebar changes.
'use strict';

(() => {
  if (typeof UI === 'undefined') return;
  const tr = (text) => (window.I18n ? window.I18n.t(text) : text);
  const KEY = 'td.new.seen';
  // This version's: feature id → its sidebar page. Next version: a new list (old ids are just ignored).
  const FEATURES = {
    'photo-backup': 'media', // Photos › settings › Photo backup
    'file-shelf': 'files', // Files › Recent › File Shelf
    'file-shelf-tab': 'files', // File Sharing › File Shelf (the tab)
    activity: 'activity',
    'controller-share': 'camera', // Camera & Controller › Controller
    'share-map': 'share', // Share screen map
  };
  let seen;
  try { seen = new Set(JSON.parse(localStorage.getItem(KEY) || '[]')); } catch (_) { seen = new Set(); }
  const save = () => { try { localStorage.setItem(KEY, JSON.stringify([...seen])); } catch (_) { /* kept for this window */ } };
  const pill = () => UI.el('span', { class: 'new-pill', text: tr('New') });

  // A page's pill shows while any of its features is unseen; showing the page sees the page itself.
  const pageNew = (page) => !seen.has(`page:${page}`) && Object.entries(FEATURES).some(([id, p]) => p === page && !seen.has(id));

  function paintNav() {
    for (const b of document.querySelectorAll('.nav-item[data-base]')) {
      const want = pageNew(b.dataset.base);
      const has = b.querySelector('.new-pill');
      if (want && !has) b.querySelector('.label')?.after(pill());
      else if (!want && has) has.remove();
    }
  }

  UI.newPill = (id) => (FEATURES[id] && !seen.has(id) ? pill() : null);
  // A button with the pill, seen once it's clicked.
  UI.withNew = (button, id) => {
    const p = UI.newPill(id);
    if (!p) return button;
    button.append(p);
    button.addEventListener('click', () => { p.remove(); UI.newSeen(id); });
    return button;
  };
  UI.newSeen = (id) => {
    if (seen.has(id)) return;
    seen.add(id);
    save();
    paintNav();
  };

  // A page shown (a click, search, the tray, a pop-up): its sidebar pill goes.
  function shown(section) {
    const page = section && section.id && section.id.startsWith('page-') ? section.id.slice(5) : '';
    const btn = page && document.querySelector(`.nav-item[aria-controls="page-${CSS.escape(page)}"]`);
    const base = btn ? btn.dataset.base : page;
    if (!base || !Object.values(FEATURES).includes(base) || seen.has(`page:${base}`)) return;
    seen.add(`page:${base}`);
    save();
    paintNav();
  }

  function start() {
    const content = document.getElementById('content');
    const nav = document.querySelector('.nav-item')?.closest('ul,nav') || document.querySelector('nav');
    paintNav();
    if (content) {
      new MutationObserver((list) => {
        for (const m of list) if (m.target.classList && m.target.classList.contains('page') && !m.target.hidden) shown(m.target);
      }).observe(content, { attributes: true, attributeFilter: ['hidden'], subtree: true });
      const open = content.querySelector('section.page:not([hidden])');
      if (open) shown(open);
    }
    // The sidebar is drawn again (Arrange, a device picked): the pills go back on.
    if (nav) new MutationObserver(() => paintNav()).observe(nav, { childList: true });
  }
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => setTimeout(start, 0));
  else setTimeout(start, 0);
})();