Skip to content

Launch Cleanmeter after Quit with a Windows hotkey - #88

Open
apyfz wants to merge 3 commits into
mainfrom
feat/launch-overlay-hotkey
Open

apyfz wants to merge 3 commits into
mainfrom
feat/launch-overlay-hotkey

Conversation

@apyfz

@apyfz apyfz commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

The overlay shortcut currently works only while Cleanmeter is running. Add an optional Settings > Shortcuts > Launch when closed checkbox so the same Show/hide overlay shortcut can also open Cleanmeter after Quit. Existing installations keep this disabled.

Windows Explorer owns a per-user Start Menu shortcut that invokes a dedicated on-demand scheduled task. The already-elevated app installs the task; it has no logon trigger and does not enable startup with Windows. Subsequent presses launch or toggle without another UAC prompt. No additional resident helper is needed. Launch mode supports Ctrl+Alt, optionally Shift, with letters, numbers, Space, or F1–F11; unsupported choices show validation feedback.

Cold launches keep Settings hidden. Subsequent launches toggle the existing overlay, including requests received while the UI and sensors are initializing. Disabling or clearing the shortcut removes the link and task and restores normal in-app hotkey registration. Shortcut controls are disabled while configuration is being saved. Reset and uninstall also include cleanup; uninstall can request administrator approval to remove the elevated task.

Validation:

  • 48 Rust library tests passed, including Windows COM shortcut round-trip, on-demand task XML, argument routing, legacy defaults, and queued toggles.
  • 25 frontend shortcut/reset tests passed; production frontend build passed.
  • Local Windows app testing: enable through Settings, fully exit the process, launch with global keyboard input, keep Settings hidden, repeatedly show/hide the existing overlay, disable and verify link/task deletion, restore native hotkey, clear and rebind to Space, and reset through the Help dialog with link/task cleanup verified.
  • Non-admin task activation verified without an elevation prompt. Test build used a local WebView2 automation connection; this instrumentation is not part of the PR.
  • NSIS uninstall hook syntax compiled. Full installer uninstall and sign-out/sign-in testing remain pending.
  • Full TypeScript checking has existing errors in unchanged code/configuration.

@apyfz
apyfz marked this pull request as ready for review October 19, 2026 18:33
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Walkthrough

The app adds a Windows launch-hotkey setting backed by a Task Scheduler task and Start Menu Shell Link. Launch arguments now request an overlay toggle during startup or when the app is already running.

Changes: Overlay launch hotkey

Layer / File(s) Summary
Settings contract and Shell Link
tauri-app/src-tauri/src/types.rs, tauri-app/src/lib/types.ts, tauri-app/src-tauri/src/launch_hotkey.rs, tauri-app/src-tauri/Cargo.toml, tauri-app/src-tauri/tauri.conf.json, tauri-app/src-tauri/windows/installer-hooks.nsh
Overlay settings gain a disabled-by-default launch-hotkey field. Windows shortcut encoding, Task Scheduler registration, and Shell Link synchronization are added. The installer removes the scheduled task and shortcut on uninstall.
Configure and apply the launch shortcut
tauri-app/src-tauri/src/commands.rs, tauri-app/src-tauri/src/shortcuts.rs, tauri-app/src/lib/tauri.ts, tauri-app/src/stores/settings-store.ts, tauri-app/src/stores/settings-store.reset.test.ts, tauri-app/src/components/settings/settings/SettingsTab.tsx
The settings command validates and saves launch-hotkey changes. The shortcut registry applies the Explorer shortcut. The settings UI and store handle configuration, errors, pending saves, and reset behavior.
Route overlay launch requests
tauri-app/src-tauri/src/lib.rs, tauri-app/src-tauri/src/commands.rs, tauri-app/src-tauri/src/shortcuts.rs, tauri-app/src/hooks/useHotkey.ts
The app preserves the overlay-launch argument during elevation and startup. It queues second-instance toggle requests until startup is ready, then consumes a pending request when the hotkey listener and sensor are ready.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 42da9

Enabling "Launch when closed" registers a scheduled task that starts Cleanmeter with administrator rights from a folder the user can modify. Other software running as that user could swap the executable and gain elevated rights without a UAC prompt. On shared machines, users can also overwrite or remove each other's task. Uninstall can leave the elevated task behind if the shortcut was deleted. The earlier problem of a UAC prompt on every show/hide is fixed. The elevation exposure should be addressed before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 36 functions across 11 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the optional Windows launch hotkey, its behavior, cleanup, validation, and remaining test coverage.
Title check Passed The title clearly and concisely summarizes the main change: launching Cleanmeter after quitting through a Windows hotkey.
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: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 36 functions across 11 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: 167e6361-55b1-4d4b-a650-4416eabda3f8
📥 Commits

Reviewing files that changed from the base of the PR and between 0eb9f7c and 26d1bf2.

📒 Files selected for processing: 14
  • tauri-app/src-tauri/Cargo.toml
  • tauri-app/src-tauri/src/commands.rs
  • tauri-app/src-tauri/src/launch_hotkey.rs
  • tauri-app/src-tauri/src/lib.rs
  • tauri-app/src-tauri/src/shortcuts.rs
  • tauri-app/src-tauri/src/types.rs
  • tauri-app/src-tauri/tauri.conf.json
  • tauri-app/src-tauri/windows/installer-hooks.nsh
  • tauri-app/src/components/settings/settings/SettingsTab.tsx
  • tauri-app/src/hooks/useHotkey.ts
  • tauri-app/src/lib/tauri.ts
  • tauri-app/src/lib/types.ts
  • tauri-app/src/stores/settings-store.reset.test.ts
  • tauri-app/src/stores/settings-store.ts

Included review availability: This review used your included allowance. 7 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.

Comment thread tauri-app/src-tauri/src/shortcuts.rs Resolved

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: 8f8f7aba-b354-4450-8ffe-da6f01789e57
📥 Commits

Reviewing files that changed from the base of the PR and between 26d1bf2 and 42da9df.

📒 Files selected for processing: 3
  • tauri-app/src-tauri/src/launch_hotkey.rs
  • tauri-app/src-tauri/windows/installer-hooks.nsh
  • tauri-app/src/components/settings/settings/SettingsTab.tsx

Included review availability: This review used your included allowance. 6 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.

use std::sync::Mutex;

pub const TOGGLE_ARG: &str = "--toggle-overlay";
pub const LAUNCH_TASK: &str = "Cleanmeter Overlay Hotkey";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

The task name is machine-global and different users overwrite each other's task.

LAUNCH_TASK is a fixed name in the root task folder. Suppose user A enables the option and user B enables it later. /Create ... /F then replaces A's task with B's SID principal. A's Start Menu link still runs that task, so A's hotkey runs under B's identity or fails. In the same way, when B disables the option, /Delete /TN ... /F deletes the task that A's link uses.

Fix: put the user SID in the task name, for example Cleanmeter Overlay Hotkey {SID}. Use the same name in register_task, the delete call on Line 231, and write_link arguments. Update the uninstall hook to match.

r#"<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<Triggers />
<Principals><Principal id="User"><UserId>{}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>HighestAvailable</RunLevel></Principal></Principals>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
fd -a tauri.conf.json | xargs -I{} sh -c 'echo "== {}"; jq ".bundle.windows // .tauri.bundle.windows" {}'
rg -n -C3 'installMode|perMachine|currentUser' -g '*.json' -g '*.nsh' -g '*.nsi'

Repository: SupaStellar/Cleanmeter

Length of output: 1084


🏁 Script executed:

#!/bin/bash
set -o pipefail
printf '%s\n' '== launch_hotkey.rs =='
nl -ba tauri-app/src-tauri/src/launch_hotkey.rs | sed -n '1,280p'
printf '%s\n' '== lib.rs elevation and argument routing =='
rg -n -C8 -F -e 'runas' -e 'is_overlay_launch' -e 'toggle-overlay' -e 'std::env::args' -e 'Command::new' tauri-app/src-tauri/src/lib.rs tauri-app/src-tauri/src
printf '%s\n' '== installer hook =='
nl -ba tauri-app/src-tauri/windows/installer-hooks.nsh | sed -n '1,240p'
printf '%s\n' '== tauri config and package metadata =='
nl -ba tauri-app/src-tauri/tauri.conf.json | sed -n '55,82p'
rg -n -C4 -F -e 'productName' -e 'identifier' -e 'currentUser' -e 'ProgramFiles' -e 'LOCALAPPDATA' tauri-app/src-tauri/tauri.conf.json tauri-app/src-tauri/Cargo.toml tauri-app/package.json

Repository: SupaStellar/Cleanmeter

Length of output: 42490


🏁 Script executed:

#!/bin/bash
set -o pipefail
printf '%s\n' '== Tauri versions and installer references =='
rg -n -C3 -F -e 'tauri = ' -e 'tauri-build' -e 'tauri-cli' -e 'installMode' -e 'currentUser' -e 'APPDATA' -e 'LOCALAPPDATA' -e 'ProgramFiles' --glob 'Cargo.toml' --glob 'Cargo.lock' --glob '*.json' --glob '*.nsh' --glob '*.nsi' --glob '*.rs' .
printf '%s\n' '== installer-related files =='
rg --files tauri-app/src-tauri | rg '(^|/)(windows|installer|nsis|tauri).*(nsh|nsi|toml|json)$|tauri.conf'

Repository: SupaStellar/Cleanmeter

Length of output: 3066


🌐 Web query:

official Tauri 2 NSIS installMode currentUser installation path permissions

💡 Result:

In **Tauri 2**, NSIS `installMode: "currentUser"` means a per-user install:

```json
{
  "bundle": {
    "windows": {
      "nsis": {
        "installMode": "currentUser"
      }
    }
  }
}
```

- **Privileges:** The installer does not require Administrator privileges.
- **Default location:** `%LOCALAPPDATA%\<ProductName>`—not `Program Files`. The app is installed for the current Windows user, not system-wide.
- **Registry metadata:** Stored under `HKCU`.
- **Path permissions:** The per-user install location is intended to be writable without admin rights. This is separate from Tauri’s app permissions/capabilities: `installMode` does **not** grant the frontend access to files or other system APIs. Configure those through Tauri capabilities and plugin permissions.
- **Custom paths:** The official docs say relative paths can work for per-user NSIS installs; they do not establish that `installMode` itself provides a setting to change the installer’s default directory. ([v2.tauri.app](https://v2.tauri.app/reference/config/?utm_source=openai))

For comparison, `perMachine` installs to `Program Files` and requires administrator privileges; `both` offers a choice but still requires administrator privileges. ([v2.tauri.app](https://v2.tauri.app/reference/config/?utm_source=openai))

Citations:

- 1: https://v2.tauri.app/reference/config/?utm_source=openai
- 2: https://v2.tauri.app/reference/config/?utm_source=openai

Do not create a HighestAvailable task for the per-user installation.

installMode: "currentUser" installs the application under %LOCALAPPDATA%, which is writable by the user. The task runs current_exe() with RunLevel=HighestAvailable. Therefore, a medium-integrity process running as the registered administrator can replace the executable and invoke schtasks.exe /Run to launch attacker-controlled code without the normal runas consent prompt.

Retain the runas flow for per-user installations. Alternatively, register this task only when the executable and its parent directory are protected from modification by the user.

Comment on lines +2 to +5
IfFileExists "$SMPROGRAMS\Cleanmeter Overlay.lnk" 0 cleanmeter_hotkey_removed
ExecShellWait "runas" "$SYSDIR\schtasks.exe" '/Delete /TN "Cleanmeter Overlay Hotkey" /F' SW_HIDE
Delete "$SMPROGRAMS\Cleanmeter Overlay.lnk"
cleanmeter_hotkey_removed:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -n -C3 'SetShellVarContext|installMode|NSIS_HOOK' -g '*.nsh' -g '*.nsi' -g '*.json'

Repository: SupaStellar/Cleanmeter

Length of output: 1120


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- PR diff ---'
git diff --no-ext-diff --unified=30 0eb9f7c9369202297b697c08ee957f2fab520b74 42da9df02bd496483965195d110887f678171b36 -- tauri-app/src-tauri/windows/installer-hooks.nsh tauri-app/src-tauri tauri-app/src
printf '%s\n' '--- relevant identifiers ---'
rg -n -C4 -F -e 'Cleanmeter Overlay Hotkey' -e 'Cleanmeter Overlay.lnk' -e 'FOLDERID_Programs' -e 'CreateShortcut' -e 'DeleteShortcut' -e 'SetShellVarContext' tauri-app/src-tauri tauri-app/src || test "$?" -eq 1

Repository: SupaStellar/Cleanmeter

Length of output: 42923


Do not gate task cleanup on the shortcut file.

If the user deletes Cleanmeter Overlay.lnk before uninstall, IfFileExists skips the scheduled-task deletion. Delete the task independently of the link.

Suggested fix
-  IfFileExists "$SMPROGRAMS\Cleanmeter Overlay.lnk" 0 cleanmeter_hotkey_removed
  ExecShellWait "runas" "$SYSDIR\schtasks.exe" '/Delete /TN "Cleanmeter Overlay Hotkey" /F' SW_HIDE
  Delete "$SMPROGRAMS\Cleanmeter Overlay.lnk"
-  cleanmeter_hotkey_removed:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
IfFileExists "$SMPROGRAMS\Cleanmeter Overlay.lnk" 0 cleanmeter_hotkey_removed
ExecShellWait "runas" "$SYSDIR\schtasks.exe" '/Delete /TN "Cleanmeter Overlay Hotkey" /F' SW_HIDE
Delete "$SMPROGRAMS\Cleanmeter Overlay.lnk"
cleanmeter_hotkey_removed:
ExecShellWait "runas" "$SYSDIR\schtasks.exe" '/Delete /TN "Cleanmeter Overlay Hotkey" /F' SW_HIDE
Delete "$SMPROGRAMS\Cleanmeter Overlay.lnk"

@saadah7 saadah7 self-assigned this Oct 19, 2026
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