Skip to content

Pulse Desktop: run on Linux, macOS path unchanged (#2591) - #2687

Open
drpaulobernardy wants to merge 1 commit into
danielmiessler:mainfrom
drpaulobernardy:pulse-desktop-linux
Open

drpaulobernardy wants to merge 1 commit into
danielmiessler:mainfrom
drpaulobernardy:pulse-desktop-linux

Conversation

@drpaulobernardy

Copy link
Copy Markdown

Note

🤖 Paulino (AI assistant) responding on behalf of Dr. Paulo

Carries #2591, under the conditions you set there: the darwin branch byte-identical, one platform test, and evidence from a Linux run.

What changes

Everything only Linux needs lives in a new linux.ts: Ctrl+Shift shortcuts in place of ⌘, the menu without the macOS-only roles, system tmux, the login shell and wl-copy in the tmux config, Linux font folders, Chrome started detached, Pulse started as a systemd user service, and a ~/.local/share install with a launcher entry.

One platform test. isLinux(platform) in linux.ts. Each app file sets const LINUX=isLinux(process.platform) (or navigator.platform in the renderer) once, and every Linux branch tests LINUX. Nothing branches on "not macOS", so macOS and every other platform run the shipped code.

The darwin side. The diff removes five of your lines. In each one the shipped expression stays, byte for byte, as the non-Linux arm:

Line Now
build.ts const terminalFile=… LINUX ? <Linux font folders> : <your expression>
terminals.ts const tmux=… LINUX ? LINUX_TMUX.find(existsSync) : <your expression>
terminals.ts const env=… LINUX ? linuxShellEnvironment(…) : <your expression>
main.ts Menu.setApplicationMenu(Menu.buildFromTemplate([ and its ])); the template goes through LINUX ? linuxMenu(template) : template

All your other lines are untouched, and the Linux code is inserted before or after them (git diff -U0 upstream/main shows 5 deletions). Where a Linux line overrides a value your line sets (the offline page, the page-button labels, the terminal key hint), your line still runs first and the Linux line follows it.

Linux run evidence

Built and run from this branch on Arch Linux with Hyprland (Wayland), Electron 44.3.0: bun build.ts --package, then the packaged app launched with a debugging port and driven over the DevTools protocol:

platform: linux
menu bar visible in the window: false
Linux labels (class linux-keys): true
kbd labels: Ctrl+Shift+T | Ctrl+Shift+K | Ctrl+H | Ctrl+L
Ctrl+Shift+T: session buttons before 43, after 44
Ctrl+Shift+K: command menu open: true
page button label: Ctrl+Shift+1
terminal key hint: Ctrl+H / Ctrl+L switch

The earlier version of this patch has been in daily use on that machine since 2026-11-03, installed with bun build.ts --install. On it these were also checked live: Ctrl+Shift+T/K/1 and Ctrl+Shift+H, Ctrl+C stopping sleep 300 in the terminal, Ctrl+Shift+C/X/Z/A with no selection never reaching the shell (cat -v), Ctrl+Shift+V pasting once, the edit keys in the command menu and the Pulse pages, the launcher entry starting a stopped Pulse in about a second without restarting a running one, and desktop-file-validate on the entry.

Not verified: a macOS build (I have no Mac); copying to the system clipboard while the window is hidden (Wayland only lets the focused window write to it); brackets on a physical Brazilian ABNT2 keyboard, covered only by the test against xkb/symbols/br.

Tests

LifeOS/install/LIFEOS/PULSE/Desktop/linux.test.ts, 10 tests, all pass. They read the accelerators and labels from your files, so a new menu shortcut with no distinct Linux key, or a glyph label set after start-up without its Linux line, fails the test instead of showing up wrong in use. install-app runs bun test first, so on macOS too a new shortcut that collides on Linux stops the install; say so if you would rather keep that test out of install-app.

The README gets a short Linux section under Build and install.

🤖 Generated with Claude Code

Everything only Linux needs lives in linux.ts. Each app file decides once, with isLinux(process.platform)
or isLinux(navigator.platform), and every Linux branch tests that, so macOS and every other platform run
the shipped code. The author's lines stay as written except five, where the shipped expression is kept
verbatim as the non-Linux arm of a ternary (terminalFile, tmux, env, the menu template wrapper).

linux.test.ts reads the accelerators and labels from the app files, so a new shortcut with no Linux key
fails there instead of silently in use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014YTdW6sTViEVVK8c3DeQVC

@isihussain isihussain left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architectural & Quality Review

Thank you for putting this together @drpaulobernardy. Adding Linux support to Pulse Desktop while keeping the macOS path untouched is a great improvement for cross-platform parity. The isolation of Linux-specific logic into linux.ts with a dedicated test suite (linux.test.ts) makes the boundary very clean.

Here are a few constructive observations and suggested hardening improvements across correctness, defensive error handling, and web standards:


1. Correctness & Web Standards: navigator.platform Deprecation

In workspace.ts (line 15) and linux.ts:

const LINUX = isLinux(navigator.platform);

navigator.platform is officially deprecated in current web standards (MDN reference) and modern Chromium/WebKit browsers are increasingly freezing or masking this string.

Recommendation: For the renderer process, consider checking navigator.userAgentData?.platform first with fallback to navigator.platform and navigator.userAgent:

export function isLinuxRenderer(): boolean {
  if (typeof navigator === "undefined") return false;
  const uaDataPlatform = (navigator as any).userAgentData?.platform;
  if (typeof uaDataPlatform === "string") return /^linux/i.test(uaDataPlatform);
  return /^linux/i.test(navigator.platform || navigator.userAgent || "");
}

2. Defensiveness: Unhandled Exception in linuxChord

In linux.ts:

function linuxChord(shift: boolean, alt: boolean, key: string, source: string): string {
  if (alt) {
    if (key === 'R' && !shift) return 'Ctrl+Shift+F5';
    throw new Error(`No Linux shortcut for ${source}: add it to linux.ts`);
  }
  return shift ? `Ctrl+Shift+Alt+${key}` : `Ctrl+Shift+${key}`;
}

If a future shortcut with alt is added or a user defines a customized binding that enters this code path, throwing an unhandled Error inside linuxChord() will fail palette generation (commandCatalog()) or crash renderer startup.

Recommendation: Rather than throwing at runtime, log a warning in development and fall back defensively to the original label or a best-effort representation:

if (alt) {
  if (key === 'R' && !shift) return 'Ctrl+Shift+F5';
  console.warn(`[PulseDesktop] Unmapped Linux shortcut for ${source}`);
  return source;
}

3. Performance & Cleanliness: Single-Pass Shortcut Rendering in workspace.ts

In workspace.ts:

pages.forEach(p => { ... b.append(..., Object.assign(document.createElement('kbd'), { textContent: p.shortcut || '' })); ... });
if (LINUX) $('pages').querySelectorAll('kbd').forEach(k => { k.textContent = keyLabel(k.textContent || ''); });

Instead of creating elements with the author label and immediately following with a full DOM query $('pages').querySelectorAll('kbd') to re-write their text, applying keyLabel(p.shortcut || '') directly during element construction avoids layout churn and keeps element formatting self-contained:

Object.assign(document.createElement('kbd'), { textContent: p.shortcut ? keyLabel(p.shortcut) : '' })

Overall, the separation of concerns, the XDG directory compliance in linux.ts, and the Wayland/tmux testing make this PR very solid!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants