Skip to content

fix(macos): the sign-in switch follows Allow in the Background - #1993

Open
YusufMntm wants to merge 1 commit into
KnifeLemon:mainfrom
YusufMntm:fix/macos-login-switch-1940
Open

YusufMntm wants to merge 1 commit into
KnifeLemon:mainfrom
YusufMntm:fix/macos-login-switch-1940

Conversation

@YusufMntm

Copy link
Copy Markdown
Contributor

Fixes #1940

What and why

On macOS, "Start Filee when I sign in" writes or deletes ~/Library/LaunchAgents/com.filee.app.plist, and macOS lists
that agent under System Settings > General > Login Items & Extensions > Allow in the Background. Filee never read
the system's side, so after turning Filee off there the switch in Settings > General still showed on (as the issue
says, and as you confirmed: "Filee's switch doesn't read the system's state").

Design

  • IPlatformServices.StartsWithSystem() (default null = can't tell; Windows and Linux are unchanged). On macOS:
    no agent file → null (a first start keeps the default of starting with the system), otherwise
    launchctl print-disabled gui/<uid> decides; a failure or timeout is null.
    MacOSIntegrationFiles.IsDisabled parses its output ("com.filee.app" => disabled/enabled on macOS 13+,
    true/false on older ones, exact label only). The label is one constant now, used by the plist too.
  • SystemIntegrationService.SyncFromSystem runs at startup (before the first Apply) and when the General page opens.
    A known state that differs from the setting wins (the reporter asked for the system setting to be the source). It
    marks the startup entry as applied, so the next Apply neither rewrites nor deletes the agent: deleting it would
    stop "Allow in the Background" from working when the user turns Filee back on there.
  • Turning the switch on in Filee while macOS still blocks the agent: after writing the plist, macOS is asked again
    and StartupEntryNotKeptException is thrown with a new key, general.startup_blocked_background, which says
    where to allow it. The exception got an optional MessageKey (default general.startup_entry_missing, so the
    Windows [Bug]: 无法登陆时启动 #450 message is unchanged), and ApplyOne shows that key. The new line is in all 23 i18n files.
  • getuid is a DllImport from libSystem, like the other P/Invokes in Filee.Platform.MacOS.

Tests

  • MacOSIntegrationTests: IsDisabled with macOS 13+ and older print-disabled output, the label missing, a
    longer label (com.filee.app.helper) that must not count, and empty output.
  • SystemIntegrationTests: system off + setting on → the setting turns off and the next Apply doesn't touch the
    startup entry; system unknown or equal → nothing changes; a separate data directory → nothing; a
    StartupEntryNotKeptException with a custom key shows that key's text.

Ran locally (Windows): Filee.Platform.Tests (MacOSIntegration: 13 pass), Filee.App.Tests (SystemIntegration,
Localization, GeneralPage: 250 pass), dotnet format --verify-no-changes on the changed files.

Not tried: a real Mac. I couldn't check by hand that switching Filee off under Allow in the Background shows up as
disabled in launchctl print-disabled on every macOS version. If it doesn't, StartsWithSystem reports
"enabled" and the switch behaves as it does today. CHANGELOG.md is left alone; the lines are in a comment below.

🤖 Generated with Claude Code

Filee's "Start Filee when I sign in" switch only wrote or deleted its launch
agent and never read the system's state, so turning Filee off under System
Settings > General > Login Items & Extensions > Allow in the Background left
the switch showing on (KnifeLemon#1940).

The platform can now report whether the system will start Filee
(IPlatformServices.StartsWithSystem; macOS reads launchctl print-disabled for
com.filee.app). At startup and when the General page opens, a known state that
differs from the setting wins and the agent file is left in place, so turning
Filee back on in System Settings keeps working. Turning the switch on while
macOS still blocks the agent now says where to allow it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YusufMntm
YusufMntm requested a review from KnifeLemon as a code owner December 2, 2026 15:42
@YusufMntm

Copy link
Copy Markdown
Contributor Author

The CHANGELOG.md lines for this one, for the CHANGELOG PR:

ko: macOS에서 시스템 설정의 "백그라운드에서 허용"에서 Filee를 끄면 Filee의 로그인 시 시작 스위치도 꺼져요
en: On macOS, turning Filee off under Allow in the Background now turns off its sign-in switch too
- **The macOS sign-in switch follows System Settings** (#1940). Turning Filee off under Login Items & Extensions >
  Allow in the Background now shows in Settings > General, and turning the switch on while macOS blocks Filee says
  where to allow it.

@github-actions github-actions Bot added the bug Something isn't working label Dec 2, 2026

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @YusufMntm. The design reads right:

  • the system wins only when it can tell;
  • a missing agent keeps the default;
  • the agent isn't deleted after a sync, so turning Filee back on in System Settings still works;
  • turning the switch on while macOS blocks it says where to fix it.

The parser tests with the exact label are a nice touch.

One thing we can't check from CI is whether Allow in the Background really shows up in launchctl print-disabled gui/<uid> on current macOS (13, 14, 15). It's managed by Background Task Management, so this is worth seeing on a real Mac before merge. @AzrielTheHellrazor, could you try it when you have a moment?

  1. Turn on Start Filee when I sign in in Filee.
  2. Turn Filee off under System Settings > General > Login Items & Extensions > Allow in the Background.
  3. Reopen Settings > General in Filee. The switch should now be off.
  4. Turn the switch on in Filee. It should show the new "turned off under … Allow in the Background" message.
  5. Turn it back on in System Settings, then sign out and in. Filee should start.

If you can, please also run launchctl print-disabled gui/$(id -u) | grep filee after step 2 and paste the line.

A small nit: GeneralPageViewModel now runs launchctl (with a 10 s timeout) in its constructor, on the UI thread. It's normally quick, so it's fine as is. But if it ever hangs, the page would freeze. Moving it off the UI thread would avoid that.

We'll add the CHANGELOG lines after the merge, as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: macOS 登录项中未添加 Filee,但应用内开关开启后仍会自启动

2 participants