Skip to content

refactor(renderer): route native calls through a platform service - #2546

Merged
RobbieTheWagner merged 2 commits into
mainfrom
platform-service
Dec 2, 2026
Merged

RobbieTheWagner merged 2 commits into
mainfrom
platform-service

Conversation

@RobbieTheWagner

@RobbieTheWagner RobbieTheWagner commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Why

We plan to move Swach from Electron to Tauri. The renderer called window.electronAPI directly in 10 files, each with its own guard and channel strings. This PR puts every native call behind one typed service, so the Tauri swap changes one renderer file.

What changed

  • New app/services/platform.ts owns the bridge. It types every command and event, and on() returns an unsubscribe function in place of removeAllListeners.
  • Every component, service, controller, and test now uses the service or its isNativeApp and nativeOs exports.
  • Removed dead code: kuler listeners for events the main process never sends, the getPlatform IPC handler, and commented-out tests.

Scope

  • The renderer only. The preload, the IPC channel names, and the main process stay as they are, apart from the removed getPlatform handler.
  • No behavior change for users.

Blast Radius

This touches every renderer path that talks to the main process: picker, clipboard, undo/redo, theme, auto-start, dock icon, import/export, updates, shared palettes. The packaged Electron test run covers the settings and data paths. The picker and tray paths have no automated tests.

Verification

  • pnpm test:electron: 71/71 pass, the same 71 test names as on main.
  • pnpm test:ember: 72/72 pass.
  • eslint and pnpm lint:types are clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Native desktop actions—including color picking, clipboard copying, data import and export, update checks, and app settings—now use consistent platform behavior.
    • Sharing a palette opens its link in the external browser.
    • Undo and redo use native controls in the desktop app and keyboard shortcuts elsewhere.
    • App version and operating-system-specific settings are shown only where supported.
    • Website links open through the platform’s external-link handling.

RobbieTheWagner and others added 2 commits December 2, 2026 13:29
The main process never sends selectKulerColor or updateKulerColor, so
these handlers could never run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Components and services called window.electronAPI directly, each with
its own guard and its own channel strings. The new platform service
owns the bridge, types every command and event, and returns an
unsubscribe function from on(). Swapping Electron for Tauri now
changes one file in the renderer.

The settings menu reads the OS from the preload value instead of
the getPlatform IPC call, so that handler is gone from the main process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds PlatformService as the interface for native-platform status, events, and operations. Components and services use it instead of direct Electron IPC access. Acceptance tests use platform-service exports to select platform-specific cases.

Changes: Platform service integration

Layer / File(s) Summary
Platform service contract
app/services/platform.ts
Adds native-platform status exports, event and picker types, and methods that wrap native IPC operations.
Application native events and operations
app/controllers/application.ts, electron-app/src/ipc-events.ts
ApplicationController subscribes to native events and delegates native operations to PlatformService. The getPlatform IPC handler is removed.
Component platform integration
app/components/about.gts, app/components/contrast-checker.gts, app/components/kuler.gts, app/components/palette-row.gts, app/components/settings-menu.gts, tests/acceptance/settings-test.js
Components use PlatformService for app version, external URLs, contrast pickers, and OS checks. Kuler no longer handles its Electron color events. Settings acceptance tests use platform status and OS values.
Native settings data transfer
app/components/settings-data.gts, tests/acceptance/settings/data-test.ts
SettingsData uses PlatformService for native data export and import. Acceptance tests use native-platform status to select export and import cases.
Color and undo platform behavior
app/services/color-utils.ts, app/services/undo-manager.ts, tests/acceptance/colors-test.js, tests/acceptance/palettes-test.js
ColorUtilsService delegates native clipboard copying to PlatformService. UndoManager selects native undo events or browser keyboard shortcuts and cleans up its listener. Acceptance-test conditions use platform status.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Suggested reviewers: chuckcarpenter

Merge Risk: Minimal · up to 8cae6

This refactor routes renderer-to-native calls through one platform service without intended behavior change. The review found no concrete regression, and the earlier teardown concern was disproved. The remaining uncertainty is the lack of automated tests for the picker and tray paths, which is modest for a pure refactor.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "refactor(renderer): route native calls through a platform service" matches the main change. The PR adds app/services/platform.ts and moves components, services, controllers, and tests from …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "refactor(renderer): route native calls through a platform service" matches the main change. The PR adds app/services/platform.ts and moves components, services, controllers, and tests from direct window.electronAPI/ipcRenderer access to the PlatformService. The title is concise, specific, and follows a conventional commit style. It does not mention the removed kuler listeners or the removed getPlatform IPC handler, but those are secondary details.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9f70b6b-2c7c-49c4-860a-4714020e46f9
Commits

Reviewing files that changed from the base of the PR and between 0431d28 and 8cae6ac.

Files selected for processing: 15

  • app/components/about.gts
  • app/components/contrast-checker.gts
  • app/components/kuler.gts
  • app/components/palette-row.gts
  • app/components/settings-data.gts
  • app/components/settings-menu.gts
  • app/controllers/application.ts
  • app/services/color-utils.ts
  • app/services/platform.ts
  • app/services/undo-manager.ts
  • electron-app/src/ipc-events.ts
  • tests/acceptance/colors-test.js
  • tests/acceptance/palettes-test.js
  • tests/acceptance/settings-test.js
  • tests/acceptance/settings/data-test.ts
Files with no reviewable changes: 2

  • app/components/kuler.gts
  • electron-app/src/ipc-events.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@RobbieTheWagner
RobbieTheWagner merged commit dee849e into main Dec 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant