Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Merge main and preserve startup diagnostics with scene lifecycle

laurensprieme09181196b39
diff --cc mobile/apps/photos/ios/Runner/AppDelegate.swift
index 9a9b2287f0,fc4948e080..fe26d62a48
--- a/mobile/apps/photos/ios/Runner/AppDelegate.swift
+++ b/mobile/apps/photos/ios/Runner/AppDelegate.swift
@@@ -7,26 -6,9 +6,25 @@@ import ente_background_manage
import workmanager_apple
@main
- @objc class AppDelegate: FlutterAppDelegate {
+ @objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
private static let workmanagerDebugThreadIdentifier =
"io.ente.frame.workmanager.debug"
+ private let startupTrace: BackgroundStartupTrace = {
+ let trace = BackgroundStartupTrace(scope: "app")
+ trace.event("app.delegate.initializing")
+ return trace
+ }()
- private let foregroundHeartbeat = ForegroundHeartbeat()
+
+ override func application(
+ _ application: UIApplication,
+ willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
+ ) -> Bool {
+ startupTrace.event(
+ "app.willFinishLaunching.begin",
+ detail: "applicationState=\(application.applicationState.rawValue)")
+ defer { startupTrace.event("app.willFinishLaunching.end") }
+ return super.application(application, willFinishLaunchingWithOptions: launchOptions)
+ }
override func application(
_ application: UIApplication,
@@@ -57,47 -31,31 +55,41 @@@
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
}
- startupTrace.measure("app.plugins") {
- GeneratedPluginRegistrant.register(with: self)
- }
- BackgroundManagerPlugin.install(
- isEnabled: { Self.shouldUseNativeBackgroundManager() },
- registrant: { registry in GeneratedPluginRegistrant.register(with: registry) }
- )
+ startupTrace.measure("app.backgroundManager.install") {
+ BackgroundManagerPlugin.install(
+ isEnabled: { Self.shouldUseNativeBackgroundManager() },
+ registrant: { registry in GeneratedPluginRegistrant.register(with: registry) }
+ )
+ }
BackgroundManagerPlugin.registerTask(
identifier: "io.ente.photos.nativeBackgroundRefresh", processing: false)
BackgroundManagerPlugin.registerTask(
identifier: "io.ente.photos.nativeBackgroundProcessing", processing: true)
WorkmanagerPlugin.setPluginRegistrantCallback { registry in
- GeneratedPluginRegistrant.register(with: registry)
+ BackgroundStartupTrace(scope: "workmanager").measure("task.plugins") {
+ GeneratedPluginRegistrant.register(with: registry)
+ }
+ }
+ startupTrace.measure("app.workmanager.register") {
+ let freqInMinutes = 30 * 60
+ WorkmanagerPlugin.registerPeriodicTask(
+ withIdentifier: "io.ente.frame.iOSBackgroundAppRefresh",
+ frequency: NSNumber(value: freqInMinutes))
+ WorkmanagerPlugin.registerBGProcessingTask(
+ withIdentifier: "io.ente.frame.iOSBackgroundProcessing")
}
- var freqInMinutes = 30 * 60
- WorkmanagerPlugin.registerPeriodicTask(
- withIdentifier: "io.ente.frame.iOSBackgroundAppRefresh",
- frequency: NSNumber(value: freqInMinutes))
- WorkmanagerPlugin.registerBGProcessingTask(
- withIdentifier: "io.ente.frame.iOSBackgroundProcessing")
- startupTrace.measure("app.links") {
- if let url = AppLinks.shared.getLink(launchOptions: launchOptions) {
- // only accept non-homewidget urls for AppLinks
- if !url.absoluteString.contains("homeWidget") {
- AppLinks.shared.handleLink(url: url)
- }
- }
- }
-
- return super.application(application, didFinishLaunchingWithOptions: launchOptions)
+ return startupTrace.measure("app.super.didFinishLaunching") {
+ super.application(application, didFinishLaunchingWithOptions: launchOptions)
+ }
}
+ func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
- GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
++ startupTrace.measure("app.plugins") {
++ GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
++ }
+ }
+
private func configureWorkmanagerDebugHandler() {
guard shouldEnableWorkmanagerDebugNotifications() else {
return
diff --cc mobile/apps/photos/ios/Runner/SceneDelegate.swift
index 0000000000,2b4d6c903f..08585d02b8
mode 000000,100644..100644
--- a/mobile/apps/photos/ios/Runner/SceneDelegate.swift
+++ b/mobile/apps/photos/ios/Runner/SceneDelegate.swift
@@@ -1,0 -1,54 +1,70 @@@
+ import Flutter
+ import UIKit
+ import app_links
++import ente_background_manager
+
+ class SceneDelegate: FlutterSceneDelegate {
++ private let startupTrace: BackgroundStartupTrace = {
++ let trace = BackgroundStartupTrace(scope: "scene")
++ trace.event("scene.delegate.initializing")
++ return trace
++ }()
+ private let foregroundHeartbeat = ForegroundHeartbeat()
+
+ override func scene(
+ _ scene: UIScene,
+ willConnectTo session: UISceneSession,
+ options connectionOptions: UIScene.ConnectionOptions
+ ) {
- super.scene(scene, willConnectTo: session, options: connectionOptions)
++ startupTrace.event("scene.willConnect.begin")
++ defer { startupTrace.event("scene.willConnect.end") }
++ startupTrace.measure("scene.super.willConnect") {
++ super.scene(scene, willConnectTo: session, options: connectionOptions)
++ }
+
+ // app_links 6.x does not consume scene connection options. Flutter forwards
+ // warm links and legacy share-intent callbacks through its scene delegate.
- for context in connectionOptions.urlContexts {
- handleInitialLink(context.url)
- }
- for activity in connectionOptions.userActivities {
- if let url = activity.webpageURL {
- handleInitialLink(url)
++ startupTrace.measure("scene.links") {
++ for context in connectionOptions.urlContexts {
++ handleInitialLink(context.url)
++ }
++ for activity in connectionOptions.userActivities {
++ if let url = activity.webpageURL {
++ handleInitialLink(url)
++ }
+ }
+ }
+ }
+
+ override func sceneDidBecomeActive(_ scene: UIScene) {
++ startupTrace.event("scene.didBecomeActive")
+ super.sceneDidBecomeActive(scene)
+ foregroundHeartbeat.start()
+ signal(SIGPIPE, SIG_IGN)
+ }
+
+ override func sceneWillEnterForeground(_ scene: UIScene) {
++ startupTrace.event("scene.willEnterForeground")
+ super.sceneWillEnterForeground(scene)
+ foregroundHeartbeat.start()
+ signal(SIGPIPE, SIG_IGN)
+ }
+
+ override func sceneDidEnterBackground(_ scene: UIScene) {
++ startupTrace.event("scene.didEnterBackground")
+ foregroundHeartbeat.stop()
+ super.sceneDidEnterBackground(scene)
+ }
+
+ override func sceneDidDisconnect(_ scene: UIScene) {
++ startupTrace.event("scene.didDisconnect")
+ foregroundHeartbeat.stop()
+ super.sceneDidDisconnect(scene)
+ }
+
+ private func handleInitialLink(_ url: URL) {
+ if !url.absoluteString.contains("homeWidget") {
+ AppLinks.shared.handleLink(url: url)
+ }
+ }
+ }