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 22 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 29564d2

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.

private let appStateMachine: AppStateMachine = AppStateMachine()
private let appBehavior: AppBehavior = {
guard !ProcessInfo().arguments.contains("testing") else { return .existing }
if let appBehavior = AppDependencyProvider.shared.appSettings.appBehavior {
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 afraid we can run into an unexpected behavior here, i.e. not being consistent for a single app instance. AppSettings are user defaults and this can be executed before data is unlocked. We are already observing inconsistencies with UserDefaults (https://app.asana.com/0/414235014887631/1208659072736427/f) so maybe it's a good idea to steer away from using those here?

case stateMachine

}

@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it'll be a bit more work at this point, but did you consider extracting the code into 2 separate types, say ExistingAppDelegate and StateMachineAppDelegate, then use them in this class? It'd have a few advantages for the future:

  • It'd lower the risk of introducing unwanted changes to existing approach, for example by making changes to instance properties.
  • Requirements, dependencies and instance properties for the state machine would be clearly visible and easier to maintain.
  • Reasoning about the approach and overall shape will be easier.
  • Switching the implementation after the migration is complete could be as easy as replacing AppDelegate contents with whatever is inside StateMachineAppDelegate.


}

protocol AppEventHandler {

@MainActor
func handle(_ event: AppEvent)
Copy link
Contributor

Choose a reason for hiding this comment

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

Marking protocol function declaration as MainActor won't enforce it (based on my tests). It's better to mark the method as async here and defer to the implementation to isolate for specific actor.

}

// onApplicationLaunch code
Task { @MainActor [self] in // is capturing self here ok?
Copy link
Contributor

Choose a reason for hiding this comment

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

is capturing self here ok?

self is a value type so you'll be capturing a copy. If self value changes you won't see those changes here.

overlayWindow = UIWindow(frame: window.frame)
overlayWindow?.windowLevel = UIWindow.Level.alert

// TODO: most likely we do not need voiceSearchHelper for BlankSnapshotVC
Copy link
Contributor

Choose a reason for hiding this comment

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

It's used to toggle mic's visibility in the omni bar, so I'm afraid it's here to stay.

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