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.

5.3 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Notifications tab: the other computer's notifications here as Windows
// toasts from TwinDesk, and this PC's on the other computer (read from Windows' notification
// database by the helper). Two direction cards, then the apps seen sending.
'use strict';

UI.tab({
  id: 'notifications',
  order: 45,
  title: I18n.t('Notifications'),
  icon: 'bell',
  color: 'linear-gradient(#ff6961, #ff3b30)',
  desc: I18n.t('See one computer’s notifications on the other.'),
  // One switch for the whole tab (both directions); each direction is shared with the
  // other computer per pair (pair.sync), so flipping it there flips it here.
  master: { get: (s) => s.notifs.send || s.notifs.receive, set: (v) => UI.api.setNotifs({ send: v, receive: v }) },
  badge: (s) => (s.notifs.send || s.notifs.receive ? 'on' : ''),
  build(body, page) {
    const { el, api } = UI;
    const batteryLabel = I18n.t('Phone battery alerts');
    const batterySw = UI.switch((v) => api.setNotifs({ batteryAlerts: v }), { label: batteryLabel });
    batterySw.el.classList.add('local-setting');
    // Keep the battery switch above the sync introduction, outside the hidden page body.
    page.insertBefore(UI.card('', [
      UI.row(batteryLabel, I18n.t('When the phone’s battery falls to 15% or reaches 100% while charging'), [batterySw]),
    ], { cls: 'keep-on' }), page.querySelector('.feature-art') || body);
    const hideSw = UI.switch((v) => api.setNotifs({ hideText: v }), { label: I18n.t('Hide message text') });
    const hideRow = UI.row(I18n.t('Hide message text'), I18n.t('Only the app and the title'), [hideSw]);
    const note = UI.note('info', '');
    const pair = UI.dirCards(
      { on: { get: (s) => s.notifs.receive, set: (v) => api.setNotifs({ receive: v }) }, label: I18n.t('Show {name}’s notifications on {me}'), rows: [] },
      { on: { get: (s) => s.notifs.send, set: (v) => api.setNotifs({ send: v }) }, label: I18n.t('Show {me}’s notifications on {name}'), rows: [] },
    );
    const recvRow = pair.a.main, sendRow = pair.b.main;
    const apps = el('div');

    const hist = UI.historyCard('notifs');
    const showing = UI.notifShowCard ? UI.notifShowCard() : null; // how they show here (shared/ui-notifrules.js)
    // Multi-device: who shows whose notifications, per app (shared/ui-matrix.js; hidden one-to-one).
    const across = window.MeshMatrix && MeshMatrix.notifs ? MeshMatrix.notifs({
      toggle: (id, dir, on) => api.setConsent(id, 'notifs', dir, on),
      setCell: (from, to, on) => api.setCell && api.setCell(from, to, 'notifs', on),
      setApp: (from, app, name, show) => api.setNotifs({ fromApp: { from, app, name, hide: !show } }),
      showAll: (from) => api.setNotifs({ fromApp: { from, all: true } }),
      takeAll: (on) => api.setNotifs({ takeAll: on }),
    }) : null;
    if (across) across.el.hidden = true;
    // Laid out as Drop (shared/ui-feed.js): Share and Receive at the top (Edit: which devices, Multi-device),
    // the notifications below, More settings for the devices, the grid of the mesh (per app) and the options.
    const feed = UI.feedPage(body, {
      kind: 'notifs', feature: 'notifs',
      flat: (s) => ({ out: !!(s.notifs && s.notifs.send), in: !!(s.notifs && s.notifs.receive) }),
      setFlat: (dir, on) => api.setNotifs(dir === 'out' ? { send: on } : { receive: on }),
      shareLabel: I18n.t('Share this device’s notifications'), receiveLabel: I18n.t('Show the other devices’ notifications'),
      shareWith: I18n.t('Share notifications with'), receiveFrom: I18n.t('Show notifications from'),
      grid: across ? { el: across.el, render: (s) => across.render(s.matrix, s.notifs) } : null,
      settings: [note, UI.card(I18n.t('Options'), [hideRow]), ...(showing ? [showing.el] : []), UI.card(I18n.t('Apps this device sends'), [UI.row(I18n.t('Which apps’ notifications go to other devices'), I18n.t('Only apps on this device. What other devices send is set on them'), []), apps]), hist.el],
    });

    let key = '';
    return (s) => {
      const n = s.notifs;
      batterySw.set(n.batteryAlerts === true);
      if (showing) showing.update(s);
      hist.update(s);
      feed.render(s);
      const p = UI.peer(s);
      const connected = s.link.state === 'connected';
      pair.update(s);
      note.set('');
      hideSw.set(n.hideText);
      recvRow.setHint(n.receive && n.shown ? I18n.t('{count} shown', { count: n.shown }) : I18n.t('As desktop notifications, from TwinDesk'));
      sendRow.setHint(n.readable === false ? I18n.t('Can’t read this desktop’s notifications (dbus-monitor missing)')
        : !n.send ? '' : !connected ? I18n.t('Also switches it on the other computer') : n.sent ? I18n.t('{count} sent', { count: n.sent }) : I18n.t('As native notifications there'));
      const k = JSON.stringify([n.apps.map((a) => a.app), n.muted]);
      if (k === key) return;
      key = k;
      apps.replaceChildren(...(n.apps.length
        ? n.apps.map((a) => {
          const sw = UI.switch((v) => api.muteNotifApp({ app: a.app, muted: !v }), { label: I18n.t('Send {app}', { app: a.appName }) });
          sw.set(!n.muted.includes(a.app));
          return UI.row(a.appName, '', [sw], { literal: true });
        })
        : [UI.row(I18n.t('No notifications yet'), I18n.t('Apps show up here after their first notification while sending is on'))]));
    };
  },
});