Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FB15943245: Focus Filters (SetFocusFilterIntent) should run on app launch too to set initial state #588

Open
sindresorhus opened this issue Nov 24, 2024 · 0 comments

Comments

@sindresorhus
Copy link
Member

  • Date: 2024-11-24
  • Resolution: Open
  • Area: Intents Framework
  • OS: macOS 15.1
  • Type: Incorrect/Unexpected Behavior

Description

Lets say I have a focus filter like this:

struct FocusFilterIntent: SetFocusFilterIntent {
	static let title: LocalizedStringResource = "Pause Unicorn Mode"

	static let description = IntentDescription("Pause unicorn mode.")

	let displayRepresentation: DisplayRepresentation = "App"

	@Parameter(
		title: "Pause Unicorn Mode",
		default: false
	)
	var isUnicornModePaused: Bool

	@MainActor
	func perform() async throws -> some IntentResult {
		AppState.shared.isUnicornModePaused = isUnicornModePaused
		return .result()
	}
}

// ...

@Observable
final class AppState {
	var isUnicornModePaused = false
}

AppState.shared.isUnicornModePaused will be set when the user has enabled it for a focus and that focus mode is enabled. The problem is that it needs to be set at app launch too, in case the user has the focus mode already enabled.

I think FocusFilterIntent should be run at app launch automatically, so it will set the correct initial state.

I'm aware I could do AppState.shared.isUnicornModePaused = try await FocusFilterIntent.current.isUnicornModePaused at app launch, but I think it would be better if focus filters just worked. This way also does not work if some synchronous initialization state needs to know about isUnicornModePaused as it's initialized asynchronously.

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

No branches or pull requests

1 participant