Skip to content

Global keyboard shortcuts do not work until the menu bar popover is opened #199

Closed

Description

@jsattler

What happened?

Global keyboard shortcuts (Toggle Recording, Select Content, Select Area) do nothing until the menu bar popover has been opened at least once after launch.

Root cause

registerKeyboardShortcuts() is called from a .task attached to the MenuBarExtra content in BetterCaptureApp.swift:

MenuBarExtra {
    MenuBarView(viewModel: viewModel)
        .task {
            await viewModel.requestPermissionsOnLaunch()
            registerKeyboardShortcuts()
        }
} label: {
    MenuBarLabel(viewModel: viewModel)
}
.menuBarExtraStyle(.window)

MenuBarExtra content using .menuBarExtraStyle(.window) is instantiated lazily — the view is not built until the user first clicks the menu bar icon. So the .task never runs at launch, and KeyboardShortcuts.onKeyUp(for:) is never registered.

Evidence

Streaming the app's log from a cold launch, without opening the popover:

$ log stream --level debug --predicate 'subsystem == "com.sattlerjoshua.BetterCapture"'
[com.sattlerjoshua.BetterCapture:PermissionService] Permission states - Screen: ... Microphone: ... Camera: ...

$ rg -c "Requesting permissions" applog.txt
NOT FOUND

PermissionService.init() logs, which proves RecorderViewModel is constructed eagerly at launch. requestPermissionsOnLaunch() — the first line of the same .task — never logs, which proves the .task body did not run.

Steps to Reproduce

  1. Quit BetterCapture completely
  2. Launch it (or log in, if it starts at login)
  3. Without clicking the menu bar icon, press the Toggle Recording shortcut

Nothing happens. Click the menu bar icon once, dismiss the popover, press the shortcut again — it now works for the rest of the session.

What did you expect to happen?

Global shortcuts work from launch, without any interaction with the menu bar popover.

Suggested fix

Move registerKeyboardShortcuts() into AppDelegate.applicationDidFinishLaunching(_:), which runs at launch and does not depend on any view being built.

requestPermissionsOnLaunch() sits in the same .task and has the same problem — despite its name it does not run on launch. Moving it is a user-visible change though, since BetterCapture is LSUIElement: the TCC prompts would appear at login with no visible app window behind them. Worth deciding separately.

Related

The AppDelegate referenced above was added while fixing the same class of bug for the bettercapture:// URL scheme, which was dead for the same reason (onOpenURL attached to the lazily-created MenuBarExtra content).

Activity

  1. added
    bug
    on Aug 30, 2026
  2. added a commit that references this issue on Aug 30, 2026
    1e610b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions