Skip to content

Refactor FXIOS-12796 [Swift 6 Migration] Notification Center addObserver closure fixes #28062

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ih-codes
Copy link
Collaborator

📜 Tickets

Jira ticket
Github issue

💡 Description

We can be safer about our .main queue closure execution blocks and make sure we're in a main actor isolated context, fixing warnings.

Example warning:
push notif setup

@Cramsden, I just repeated the same pattern we discussed elsewhere on a previous PR.

Note: Because Notification can never be Sendable, I opted to remove the utility method in SensitiveViewController.

Conformance of 'Notification' to 'Sendable' has been explicitly marked unavailable here (Foundation.Notification)

There are still a few warnings related to non-Sendable types in these closures that should be tackled in a separate PR (some of the changes were starting to spiral so I backed off).

cc @Cramsden @lmarceau

📝 Checklist

  • I filled in the ticket numbers and a description of my work
  • I updated the PR name to follow our PR naming guidelines
  • I ensured unit tests pass and wrote tests for new code
  • If working on UI, I checked and implemented accessibility (Dynamic Text and VoiceOver)
  • If adding telemetry, I read the data stewardship requirements and will request a data review
  • If needed, I updated documentation and added comments to complex code
  • If needed, I added a backport comment (example @Mergifyio backport release/v120)

@ih-codes ih-codes requested a review from Cramsden July 18, 2025 16:59
@ih-codes ih-codes requested a review from a team as a code owner July 18, 2025 16:59
@ih-codes ih-codes force-pushed the ih/FXIOS-12796-addObserver-fixes-1 branch from 0384b04 to db989f4 Compare July 18, 2025 18:53
@mobiletest-ci-bot
Copy link

Messages
📖 Project coverage: 35.59%
📖 Edited 10 files
📖 Created 0 files

Client.app: Coverage: 35.23

File Coverage
AppDelegate+PushNotifications.swift 0.0% ⚠️
ExperimentsViewController.swift 29.47% ⚠️
TabEventHandler.swift 88.61%
SensitiveViewController.swift 0.84% ⚠️
SyncContentSettingsViewController.swift 52.25%
DevicePickerViewController.swift 7.37% ⚠️
TabToolbarHelper.swift 60.27%

ShareTo.appex: Coverage: 27.28

File Coverage
DevicePickerViewController.swift 7.37% ⚠️

libStorage.a: Coverage: 54.2

File Coverage
PageMetadata.swift 33.33% ⚠️

Generated by 🚫 Danger Swift against ec0703f

) { notification in
if let newState = notification.userInfo?["newState"] as? ConstellationState {
guard Thread.isMainThread else {
assertionFailure("This must be called main thread")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe I should add a fatal log here too for Sentry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And maybe fallback implementation. I can't decide. This is so messy!

Copy link
Contributor

Choose a reason for hiding this comment

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

We can have a fatal log, but if we're very sure this is main thread only, I don't think fallback is necessary? We can monitor the beta closely for fatal logs in the next release, and we'll get quickly warned if any of those fatal logs is getting spammed/called

Comment on lines +124 to +127
// private func observe(_ notification: Notification.Name,
// with closure: @escaping ((Notification) -> Void)) -> NSObjectProtocol? {
// return NotificationCenter.default.addObserver(forName: notification, object: nil, queue: .main, using: closure)
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this if it's commented?

forName: Notification.Name.constellationStateUpdate,
object: nil,
queue: .main
) { [weak self ] _ in
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
) { [weak self ] _ in
) { [weak self] _ in

) { notification in
if let newState = notification.userInfo?["newState"] as? ConstellationState {
guard Thread.isMainThread else {
assertionFailure("This must be called main thread")
Copy link
Contributor

Choose a reason for hiding this comment

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

We can have a fatal log, but if we're very sure this is main thread only, I don't think fallback is necessary? We can monitor the beta closely for fatal logs in the next release, and we'll get quickly warned if any of those fatal logs is getting spammed/called

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