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 AppDelegate (milestone 1) #3727

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

Conversation

jaceklyp
Copy link
Contributor

Task/Issue URL: https://app.asana.com/0/0/1208832732122403/f
Tech Design URL: https://app.asana.com/0/481882893211075/1208859623176995/f
CC: @bwaresiak

Description:

  • Migrate the app’s startup flow into a state machine with clearly defined states, each specifying its dependencies to ensure the necessary resources are available before execution.
  • Keep the flow primarily synchronous as it currently is, with some exceptions for existing async code.
  • Define explicit state dependencies to avoid optional objects, ensuring clarity about what exists in each state.

Steps to test this PR:

  1. Make sure you're assigned to "experimental" state machine group (change appBehavior random value inside AppDelegate)
  2. Please go through all smoke tests. https://app.asana.com/0/1202500774821704/1201879741377823/f
  3. Run the UI tests.
  4. Repeat for old behavior.

Definition of Done (Internal Only):

Device Testing:

  • iPhone 14 Pro
  • iPad

OS Testing:

  • iOS 17

@jaceklyp jaceklyp changed the title Jacek/refactor app delegate m1 Refactor AppDelegate (milestone 1) Dec 13, 2024
@jaceklyp jaceklyp requested a review from dus7 December 13, 2024 16:02
Copy link

github-actions bot commented Dec 13, 2024

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against af9e049

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.

Posting my comments so far. I'll still need to do some smoke testing.

DuckDuckGo/AppDelegate.swift Outdated Show resolved Hide resolved
DuckDuckGo/AppDelegate.swift Show resolved Hide resolved
DuckDuckGo/AppLifecycle/AppStateMachine.swift Show resolved Hide resolved
DuckDuckGo/AppLifecycle/AppStates/Active.swift Outdated Show resolved Hide resolved
DuckDuckGo/AppServices/UIService.swift Show resolved Hide resolved
}

func applicationWillResignActive(_ application: UIApplication) {
appStateMachine.handle(.suspending)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be called during testing? Would it cause inconsistencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed with new Testing state

}

func refreshRemoteMessages() {
// part of debug menu, let's not support it in the first iteration
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be able to easily pass remoteMessagingClient to Settings and Debug view - it's already done for multiple objects.

case .launching(let application, let launchOptions):
return Launched(application: application, launchOptions: launchOptions)
case .launching(let application):
return Launched(stateContext: makeStateContext(application: application))
default:
return handleUnexpectedEvent(event)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a note: make sure to rename the pixel (if you want to avoid using app version param) before actual tests so we can easily see if things are not working as expected.

application = stateContext.application
privacyProDataReporter = PrivacyProDataReporter(fireproofing: fireproofing)
vpnWorkaround = VPNRedditSessionWorkaround(accountManager: accountManager, tunnelController: tunnelController)
crashReportUploaderOnboarding = CrashCollectionOnboarding(appSettings: AppDependencyProvider.shared.appSettings)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is a bit concerning here, is that we change the moment things are instantiated and when data is red from the storage - and it's potentially earlier than it used to be in the old implementation so things may not be ready yet. E.g. some of the code here for VPN workaround was instantiated lazily in Task {} when did finish launching has already returned to the OS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

talked through on 1:1, it shouldn't cause any issues, as there's no work happening in the inits

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