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

Refactor app startup code - extracting services #3859

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

Conversation

jaceklyp
Copy link
Contributor

Task/Issue URL: TBD

Description:
TBD

Steps to test this PR:
1.
2.

@jaceklyp jaceklyp requested a review from dus7 January 23, 2025 19:06
Copy link
Contributor

@dus7 dus7 left a comment

Choose a reason for hiding this comment

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

Great effort 💪 ! I'm not approving yet because I haven't smoke tested it and there are several features to test thoroughly, but overall I have no major concerns. I left a few suggestions though.

I think you can also consider *LifecycleController naming instead of *Service for those newly created objects. In fact they're controlling the encapsulated logic based on the app events, similarly to how ViewController controls view based on UI events.

NotificationCenter.default.addObserver(forName: AppUserDefaults.Notifications.autofillEnabledChange,
object: nil,
queue: nil) { _ in
self.autofillPixelReporter.updateAutofillEnabledStatus(AppDependencyProvider.shared.appSettings.autofillCredentialsEnabled)
Copy link
Contributor

Choose a reason for hiding this comment

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

Closure is prolonging the life of AutofillService. Is it expected?

override init() {
super.init()
NotificationCenter.default.addObserver(forName: .databaseDidEncounterInsufficientDiskSpace, object: nil, queue: .main) { _ in
self.application(UIApplication.shared, willTerminateWithReason: .insufficientDiskSpace)
Copy link
Contributor

Choose a reason for hiding this comment

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

AppDelegate is retained here. It should be present throughout app lifecycle regardless but I'd probably advise to not keep it strongly via closure.

uiService = UIService(window: window)

// Task handler registration needs to happen before the end of `didFinishLaunching`, otherwise submitting a task can throw an exception.
// Having both in `didBecomeActive` can sometimes cause the exception when running on a physical device, so registration happens here.
AppConfigurationFetch.registerBackgroundRefreshTaskHandler()

UNUserNotificationCenter.current().delegate = unService
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it's the best solution to encapsulate UserNotificationCenter inside VPN. Given VPNService conforms to UNUserNotificationCenterDelegate there can be NotificationService which holds an array of conforming instances, where one of those will be VPNService. This way those two are decoupled from each other and we're ready for easier handling of other cases outside of the VPN purpose. It's only a suggestion, since it may increase already quite big scope of the project.

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.

2 participants