Skip to content

fix: restore paste focus and auto-refresh permissions - #24

Merged
sykuang merged 3 commits into
mainfrom
kenkuang/fix-paste-focus
Jul 23, 2026
Merged

fix: restore paste focus and auto-refresh permissions#24
sykuang merged 3 commits into
mainfrom
kenkuang/fix-paste-focus

Conversation

@sykuang

@sykuang sykuang commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • reactivate the exact previously focused macOS app before sending Cmd+V
  • wait for and verify the target bundle ID to prevent paste focus races
  • automatically recheck permissions when returning from System Settings
  • align Tauri JavaScript packages with the Rust crates
  • update random byte generation for rand 0.10
  • ignore local .worktrees/ directories

Validation

  • npm ci
  • npm test -- --run src/App.test.tsx
  • npm run build
  • cargo check --manifest-path src-tauri/Cargo.toml
  • cargo test --manifest-path src-tauri/Cargo.toml --lib paste_target_bundle_must_be_frontmost_before_pasting
  • npm run tauri -- build --no-bundle

sykuang and others added 2 commits July 23, 2026 16:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 23, 2026 08:29

Copilot AI 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.

Pull request overview

This PR improves macOS paste reliability by restoring focus to the exact previously frontmost app (using bundle IDs and verification) and improves the permissions UX by automatically rechecking permissions when the permissions window regains focus.

Changes:

  • Auto-refresh permissions when the permissions window regains focus (plus a focused unit test).
  • macOS paste now reactivates the previously frontmost app by bundle ID and verifies focus before issuing Cmd+V.
  • Minor UX/docs updates (permissions hint text) and ignore local .worktrees/ directories.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/components/PermissionsModal.tsx Updates hint text to reflect automatic permission rechecks.
src/App.tsx Adds focus-based permission refresh logic for the permissions window.
src/App.test.tsx Adds a test ensuring permissions are rechecked when the window regains focus.
src-tauri/src/platform/macos.rs Restores focus to the last frontmost app by bundle ID and verifies focus before pasting.
.gitignore Ignores local .worktrees/ directories.

Comment on lines 8 to 12
pub fn set_last_frontmost_app_name(name: String) {
let cell = LAST_FRONTMOST_APP_NAME.get_or_init(|| Mutex::new(None));
let cell = LAST_FRONTMOST_APP.get_or_init(|| Mutex::new(None));
let mut guard = cell.lock().unwrap_or_else(|e| e.into_inner());
*guard = Some(name);
*guard = query_frontmost_app_bundle_id().map(|bundle_id| (name, bundle_id));
}
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 23, 2026 09:00

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/App.tsx:734

  • refreshPermissions can still be invoked after the effect cleanup via a queued focus event, which would call setCheckingPermissions(true) even when cancelled is already true (potential setState-after-unmount warning). Add an early cancelled guard before mutating local/state flags.
    const refreshPermissions = async () => {
      if (checking) return;
      checking = true;
      setCheckingPermissions(true);
      try {
        const res = await checkPermissions();
        if (cancelled) return;
        setPermissions(res);

src-tauri/src/platform/macos.rs:12

  • set_last_frontmost_app_name currently overwrites the stored last frontmost app with None when query_frontmost_app_bundle_id() returns None, which can erase a previously valid paste target and cause perform_paste to fail with "no previous app available". Preserve the prior value when the bundle ID can’t be determined.
pub fn set_last_frontmost_app_name(name: String) {
    let cell = LAST_FRONTMOST_APP.get_or_init(|| Mutex::new(None));
    let mut guard = cell.lock().unwrap_or_else(|e| e.into_inner());
    *guard = query_frontmost_app_bundle_id().map(|bundle_id| (name, bundle_id));
}

Comment thread package.json
Comment on lines +30 to +34
"@tauri-apps/api": "2.9.0",
"@tauri-apps/plugin-dialog": "^2",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-process": "^2.3.1",
"@tauri-apps/plugin-updater": "^2.10.1",
"@tauri-apps/plugin-updater": "2.9.0",
@sykuang
sykuang merged commit 24dd5b8 into main Jul 23, 2026
10 checks passed
@sykuang
sykuang deleted the kenkuang/fix-paste-focus branch July 23, 2026 09:27
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