[PR #5266] [MERGED] feat(desktop): cross-platform quit action #5132

Closed
opened 2026-03-17 02:36:32 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5266
Author: @CuriousCorrelation
Created: 7/22/2025
Status: Merged
Merged: 7/23/2025
Merged by: @jamesgeorge007

Base: nextHead: desktop-feat-cross-platform-quit-action


📝 Commits (1)

  • a397415 feat(desktop): cross-platform quit action

📊 Changes

5 files changed (+75 additions, -6 deletions)

View changed files

📝 packages/hoppscotch-common/src/components.d.ts (+6 -5)
📝 packages/hoppscotch-common/src/helpers/actions.ts (+36 -0)
📝 packages/hoppscotch-common/src/helpers/keybindings.ts (+1 -0)
📝 packages/hoppscotch-desktop/src-tauri/src/lib.rs (+21 -1)
📝 packages/hoppscotch-selfhost-web/src/main.ts (+11 -0)

📄 Description

This implements consistent cross-platform quit functionality that
triggers graceful application shutdown through native native commands.

Closes FE-919

The Cmd + Q quit shortcut was previously broken across platforms with
inconsistent behavior, working on Windows 11 but failing on macOS,
AppImage Linux, and Windows 10. The implementation was mixed and
unreliable.

What's changed

This adds explicit cross-platform quit shortcut handling using the
actions system. The implementation adds Ctrl/Cmd + Q detection in
main.ts that maps to the ctrl-q keybinding, creates a new app.quit
action with platform-specific handling, implements a quit_app native
command that calls app.exit(0) for graceful shutdown, and connects the
ctrl-q keybinding to the app.quit action in the keybindings
configuration.

Implementation details

The shortcut handler prevents default browser behavior and triggers the
action system:

if (
  isCtrlOrCmd &&
  !e.shiftKey &&
  !e.altKey &&
  e.key.toLowerCase() === "q"
) {
  e.preventDefault()
  e.stopPropagation()
  e.stopImmediatePropagation()
  shortcutEvent = "ctrl-q"
}

The action handler checks kernel mode and invokes the native command on
desktop:

bindAction("app.quit", async () => {
  if (getKernelMode() === "desktop") {
    try {
      await invoke('quit_app')
    } catch (error) {
      console.error('Failed to quit application:', error)
    }
  }
})

The native quit_app command triggers RunEvent::ExitRequested
followed by RunEvent::Exit for cleanup (internally):

#[tauri::command]
fn quit_app(app: tauri::AppHandle) -> Result<(), String> {
    tracing::info!("Quit command received, shutting down application");
    app.exit(0);
    Ok(())
}

Platform behavior

  • macOS: Cmd + Q triggers native quit command
  • Windows/Linux: Ctrl + Q triggers native quit command
  • Web: Action is a no-op, preserving existing web app behavior

Notes to reviewers

The quit action is set up immediately when the actions module is
imported and doesn't depend on any component lifecycle. Error handling
avoids fallback to window.close() since native command failures
indicate improper context.

Testing should verify that the shortcut consistently quits the
application across macOS, Windows, and Linux without leaving background
processes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5266 **Author:** [@CuriousCorrelation](https://github.com/CuriousCorrelation) **Created:** 7/22/2025 **Status:** ✅ Merged **Merged:** 7/23/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `desktop-feat-cross-platform-quit-action` --- ### 📝 Commits (1) - [`a397415`](https://github.com/hoppscotch/hoppscotch/commit/a397415a1353540ba3d0124fd962bf9b0fc47e78) feat(desktop): cross-platform `quit` action ### 📊 Changes **5 files changed** (+75 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/components.d.ts` (+6 -5) 📝 `packages/hoppscotch-common/src/helpers/actions.ts` (+36 -0) 📝 `packages/hoppscotch-common/src/helpers/keybindings.ts` (+1 -0) 📝 `packages/hoppscotch-desktop/src-tauri/src/lib.rs` (+21 -1) 📝 `packages/hoppscotch-selfhost-web/src/main.ts` (+11 -0) </details> ### 📄 Description This implements consistent cross-platform quit functionality that triggers graceful application shutdown through native native commands. Closes FE-919 The `Cmd + Q` quit shortcut was previously broken across platforms with inconsistent behavior, working on Windows 11 but failing on macOS, AppImage Linux, and Windows 10. The implementation was mixed and unreliable. ### What's changed This adds explicit cross-platform quit shortcut handling using the actions system. The implementation adds `Ctrl/Cmd + Q` detection in `main.ts` that maps to the `ctrl-q` keybinding, creates a new `app.quit` action with platform-specific handling, implements a `quit_app` native command that calls `app.exit(0)` for graceful shutdown, and connects the `ctrl-q` keybinding to the `app.quit` action in the keybindings configuration. ### Implementation details The shortcut handler prevents default browser behavior and triggers the action system: ```typescript if ( isCtrlOrCmd && !e.shiftKey && !e.altKey && e.key.toLowerCase() === "q" ) { e.preventDefault() e.stopPropagation() e.stopImmediatePropagation() shortcutEvent = "ctrl-q" } ``` The action handler checks kernel mode and invokes the native command on desktop: ```typescript bindAction("app.quit", async () => { if (getKernelMode() === "desktop") { try { await invoke('quit_app') } catch (error) { console.error('Failed to quit application:', error) } } }) ``` The native `quit_app` command triggers `RunEvent::ExitRequested` followed by `RunEvent::Exit` for cleanup (internally): ```rust #[tauri::command] fn quit_app(app: tauri::AppHandle) -> Result<(), String> { tracing::info!("Quit command received, shutting down application"); app.exit(0); Ok(()) } ``` ### Platform behavior - **macOS**: `Cmd + Q` triggers native quit command - **Windows/Linux**: `Ctrl + Q` triggers native quit command - **Web**: Action is a no-op, preserving existing web app behavior ### Notes to reviewers The quit action is set up immediately when the actions module is imported and doesn't depend on any component lifecycle. Error handling avoids fallback to `window.close()` since native command failures indicate improper context. Testing should verify that the shortcut consistently quits the application across macOS, Windows, and Linux without leaving background processes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:36:32 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5132
No description provided.