Skip to content

Run Focus filter when the app is in the background - #5656

Open
bgoncal wants to merge 2 commits into
mainfrom
focus-filter-background-reporting
Open

Run Focus filter when the app is in the background#5656
bgoncal wants to merge 2 commits into
mainfrom
focus-filter-background-reporting

Conversation

@bgoncal

@bgoncal bgoncal commented Sep 5, 2026

Copy link
Copy Markdown
Member

AI Policy

Select exactly one option that describes AI usage in this contribution:

  • I have not used AI for this contribution.
  • AI assistance was used for this contribution.
  • AI fully generated the code for this contribution, but I've reviewed and understood it before submitting and will respond without AI during review.

Summary

A plain SetFocusFilterIntent is only reliably performed while the app is in the foreground, and is skipped when iOS would have to launch the app to run it. That means a Focus starting with the app closed never reports its name, and focus_name blanks instead. Conforming the intent to LiveActivityIntent opts it into running in the app's process in the background, which is the known workaround for this (see FB14715113).

That protocol is iOS 17+, so the conformance sits in an availability-gated extension and the filter itself stays available below iOS 17.

Related to #5467.

Screenshots

Not a UI change.

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant# N/A

Any other notes

The other option Apple documents for this is hosting the filter in an App Intents extension so no app launch is needed. That needs a new extension target, a new App ID and a provisioning profile, so it is not in this PR.

A plain SetFocusFilterIntent is only reliably performed while the app is
in the foreground, so a Focus that starts with the app closed never
reports its name. Conforming the intent to LiveActivityIntent opts it
into running in the app's process in the background.

That protocol is iOS 17+, so the filter is now gated to iOS 17.
Copilot AI lite review requested due to automatic review settings September 5, 2026 23:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The current iOS 17 availability gate on the entire intent likely removes the Focus Filter feature on iOS 16.x deployments rather than only enhancing behavior on iOS 17+.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses Focus filter execution reliability by opting the SetFocusFilterIntent into background execution so the app can report the active Focus name even when the Focus starts while the app is closed (related to #5467).

Changes:

  • Added LiveActivityIntent conformance to the Focus filter App Intent to allow it to run in the app process while in the background.
  • Gated the Focus filter intent to iOS 17+ due to LiveActivityIntent availability.
  • Expanded inline documentation explaining why LiveActivityIntent is used here.
File summaries
File Description
Sources/App/Settings/Focus/FocusNameFocusFilterAppIntent.swift Adds LiveActivityIntent conformance (iOS 17+) and documents the background-execution rationale for Focus filter reporting.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +15 to +16
@available(iOS 17.0, *)
struct FocusNameFocusFilterAppIntent: SetFocusFilterIntent, LiveActivityIntent {
Declare the LiveActivityIntent conformance in an availability-gated
extension instead of on the type, so the filter itself is not removed
from the iOS versions that predate the protocol.
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 35.43%. Comparing base (c3d1737) to head (a4c2e99).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5656      +/-   ##
==========================================
+ Coverage   35.29%   35.43%   +0.14%     
==========================================
  Files        1013     1033      +20     
  Lines       73124    73801     +677     
==========================================
+ Hits        25812    26155     +343     
- Misses      47312    47646     +334     
Files with missing lines Coverage Δ
...Settings/Focus/FocusNameFocusFilterAppIntent.swift 0.00% <ø> (ø)

... and 56 files with indirect coverage changes

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants