Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Fix iOS startup and simulator initialization

ashil-pilotcb4ef67c428f
diff --git a/mobile/apps/photos/changes/ios-startup.md b/mobile/apps/photos/changes/ios-startup.md
new file mode 100644
index 0000000000..69b2e6d94f
--- /dev/null
+++ b/mobile/apps/photos/changes/ios-startup.md
@@ -0,0 +1 @@
+- Fixed an app launch failure on iOS 27.
diff --git a/mobile/apps/photos/integration_test/ios_startup_test.dart b/mobile/apps/photos/integration_test/ios_startup_test.dart
new file mode 100644
index 0000000000..f34e399a06
--- /dev/null
+++ b/mobile/apps/photos/integration_test/ios_startup_test.dart
@@ -0,0 +1,47 @@
+import "dart:io";
+
+import "package:flutter/material.dart";
+import "package:flutter_test/flutter_test.dart";
+import "package:integration_test/integration_test.dart";
+import "package:rive/rive.dart" as rive;
+import "package:shared_preferences/shared_preferences.dart";
+
+void main() {
+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();
+
+ testWidgets("iOS starts Rive and maintains its foreground heartbeat", (
+ tester,
+ ) async {
+ await rive.RiveNative.init();
+ final file = await rive.File.asset(
+ "assets/onboarding.riv",
+ riveFactory: rive.Factory.flutter,
+ );
+ expect(file, isNotNull);
+ final controller = rive.RiveWidgetController(file!);
+ addTearDown(() {
+ controller.dispose();
+ file.dispose();
+ });
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(body: rive.RiveWidget(controller: controller)),
+ ),
+ );
+ await tester.pump(const Duration(seconds: 1));
+ expect(find.byType(rive.RiveWidget), findsOneWidget);
+ expect(tester.takeException(), isNull);
+
+ final preferences = await SharedPreferences.getInstance();
+ await preferences.reload();
+ final firstHeartbeat = preferences.getInt("native_fg_task_hb_time");
+ expect(firstHeartbeat, isNotNull);
+ await Future<void>.delayed(const Duration(seconds: 2));
+ await preferences.reload();
+ expect(
+ preferences.getInt("native_fg_task_hb_time"),
+ greaterThan(firstHeartbeat!),
+ );
+ await tester.pumpWidget(const SizedBox.shrink());
+ }, skip: !Platform.isIOS);
+}
diff --git a/mobile/apps/photos/ios/Podfile b/mobile/apps/photos/ios/Podfile
index f4cc3957d2..17a3461222 100644
--- a/mobile/apps/photos/ios/Podfile
+++ b/mobile/apps/photos/ios/Podfile
@@ -48,12 +48,21 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
+ if target.name == 'rive_native'
+ source = installer.pods_project.main_group.new_file(File.join(__dir__, 'RiveSimulatorArchInfo.c'))
+ target.source_build_phase.add_file_reference(source)
+ end
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
if target.name == 'ente_photos_frb' && config.name == 'Debug'
config.build_settings['ONLY_ACTIVE_ARCH[sdk=iphonesimulator*]'] = 'YES'
end
+
+ if target.name == 'rive_native'
+ config.build_settings['OTHER_LDFLAGS[sdk=iphonesimulator*]'] =
+ '$(inherited) -Wl,-alias,_EnteRiveSimulatorArchInfo,_NXGetLocalArchInfo'
+ end
end
end
diff --git a/mobile/apps/photos/ios/Podfile.lock b/mobile/apps/photos/ios/Podfile.lock
index fc8336f4d8..43f64ef8fd 100644
--- a/mobile/apps/photos/ios/Podfile.lock
+++ b/mobile/apps/photos/ios/Podfile.lock
@@ -516,6 +516,6 @@ SPEC CHECKSUMS:
wakelock_plus: e29112ab3ef0b318e58cfa5c32326458be66b556
workmanager_apple: 904529ae31e97fc5be632cf628507652294a0778
-PODFILE CHECKSUM: 50318c7062bacf98b6cddf7dc37637eb4eabed48
+PODFILE CHECKSUM: a3f986a49675b93a48b8f2861dc5afb5e8d21284
COCOAPODS: 1.17.0
diff --git a/mobile/apps/photos/ios/RiveSimulatorArchInfo.c b/mobile/apps/photos/ios/RiveSimulatorArchInfo.c
new file mode 100644
index 0000000000..67cd9a6174
--- /dev/null
+++ b/mobile/apps/photos/ios/RiveSimulatorArchInfo.c
@@ -0,0 +1,18 @@
+#include <TargetConditionals.h>
+
+#if TARGET_OS_SIMULATOR
+#include <mach-o/arch.h>
+
+// Rive 0.0.16 dereferences NXGetLocalArchInfo(), which returns NULL for newer
+// Mac CPU subtypes. The Podfile redirects only Rive's simulator lookup here.
+// Remove when Rive no longer relies on that deprecated host-CPU lookup.
+const NXArchInfo *EnteRiveSimulatorArchInfo(void) {
+#if defined(__arm64__)
+ return NXGetArchInfoFromCpuType(CPU_TYPE_ARM64, CPU_SUBTYPE_MULTIPLE);
+#elif defined(__x86_64__)
+ return NXGetArchInfoFromCpuType(CPU_TYPE_X86_64, CPU_SUBTYPE_MULTIPLE);
+#else
+#error Unsupported iOS simulator architecture
+#endif
+}
+#endif
diff --git a/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj b/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj
index c57ea907f9..b35b3511d5 100644
--- a/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj
+++ b/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ ABB487F057701138D27F550A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB627F0726BF9EB1E87E584 /* SceneDelegate.swift */; };
0856877A9F80F9E052DBFDB4 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F82DAEEB9A7D9FD00E0FFA1E /* Pods_Runner.framework */; };
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
274DC65125920DD100F526A4 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 274DC65025920DD100F526A4 /* StoreKit.framework */; };
@@ -90,6 +91,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 6DB627F0726BF9EB1E87E584 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
271BD99F270EE74F00D86E6F /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
@@ -314,6 +316,7 @@
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
+ 6DB627F0726BF9EB1E87E584 /* SceneDelegate.swift */,
57EEDBC4E19D917C19BF4545 /* ForegroundHeartbeat.swift */,
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
);
@@ -870,6 +873,7 @@
buildActionMask = 2147483647;
files = (
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
+ ABB487F057701138D27F550A /* SceneDelegate.swift in Sources */,
6DA601B38B4BCCD1C4BB0E25 /* ForegroundHeartbeat.swift in Sources */,
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
);
diff --git a/mobile/apps/photos/ios/Runner/AppDelegate.swift b/mobile/apps/photos/ios/Runner/AppDelegate.swift
index 77d5e4fc60..fc4948e080 100644
--- a/mobile/apps/photos/ios/Runner/AppDelegate.swift
+++ b/mobile/apps/photos/ios/Runner/AppDelegate.swift
@@ -2,15 +2,13 @@ import AVFoundation
import Flutter
import UIKit
import UserNotifications
-import app_links
import ente_background_manager
import workmanager_apple
@main
-@objc class AppDelegate: FlutterAppDelegate {
+@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
private static let workmanagerDebugThreadIdentifier =
"io.ente.frame.workmanager.debug"
- private let foregroundHeartbeat = ForegroundHeartbeat()
override func application(
_ application: UIApplication,
@@ -33,7 +31,6 @@ import workmanager_apple
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
}
- GeneratedPluginRegistrant.register(with: self)
BackgroundManagerPlugin.install(
isEnabled: { Self.shouldUseNativeBackgroundManager() },
registrant: { registry in GeneratedPluginRegistrant.register(with: registry) }
@@ -52,16 +49,13 @@ import workmanager_apple
WorkmanagerPlugin.registerBGProcessingTask(
withIdentifier: "io.ente.frame.iOSBackgroundProcessing")
- 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)
}
+ func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
+ GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
+ }
+
private func configureWorkmanagerDebugHandler() {
guard shouldEnableWorkmanagerDebugNotifications() else {
return
@@ -106,21 +100,6 @@ import workmanager_apple
return json["internalUser"] as? Bool ?? false
}
- override func applicationDidBecomeActive(_ application: UIApplication) {
- foregroundHeartbeat.start()
- signal(SIGPIPE, SIG_IGN)
- }
-
- override func applicationWillEnterForeground(_ application: UIApplication) {
- foregroundHeartbeat.start()
- signal(SIGPIPE, SIG_IGN)
- }
-
- override func applicationDidEnterBackground(_ application: UIApplication) {
- foregroundHeartbeat.stop()
- super.applicationDidEnterBackground(application)
- }
-
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
diff --git a/mobile/apps/photos/ios/Runner/Info.plist b/mobile/apps/photos/ios/Runner/Info.plist
index 6c1fe95679..73deead0b1 100644
--- a/mobile/apps/photos/ios/Runner/Info.plist
+++ b/mobile/apps/photos/ios/Runner/Info.plist
@@ -101,6 +101,27 @@
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
+ <key>UIApplicationSceneManifest</key>
+ <dict>
+ <key>UIApplicationSupportsMultipleScenes</key>
+ <false/>
+ <key>UISceneConfigurations</key>
+ <dict>
+ <key>UIWindowSceneSessionRoleApplication</key>
+ <array>
+ <dict>
+ <key>UISceneClassName</key>
+ <string>UIWindowScene</string>
+ <key>UISceneDelegateClassName</key>
+ <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
+ <key>UISceneConfigurationName</key>
+ <string>flutter</string>
+ <key>UISceneStoryboardFile</key>
+ <string>Main</string>
+ </dict>
+ </array>
+ </dict>
+ </dict>
<!-- Temporary workaround for iPad iOS 26 layout issue. Remove when fixed in Flutter: https://github.com/flutter/flutter/issues/170461 -->
<key>UIDesignRequiresCompatibility</key>
<true/>
diff --git a/mobile/apps/photos/ios/Runner/SceneDelegate.swift b/mobile/apps/photos/ios/Runner/SceneDelegate.swift
new file mode 100644
index 0000000000..2b4d6c903f
--- /dev/null
+++ b/mobile/apps/photos/ios/Runner/SceneDelegate.swift
@@ -0,0 +1,54 @@
+import Flutter
+import UIKit
+import app_links
+
+class SceneDelegate: FlutterSceneDelegate {
+ private let foregroundHeartbeat = ForegroundHeartbeat()
+
+ override func scene(
+ _ scene: UIScene,
+ willConnectTo session: UISceneSession,
+ options connectionOptions: UIScene.ConnectionOptions
+ ) {
+ 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)
+ }
+ }
+ }
+
+ override func sceneDidBecomeActive(_ scene: UIScene) {
+ super.sceneDidBecomeActive(scene)
+ foregroundHeartbeat.start()
+ signal(SIGPIPE, SIG_IGN)
+ }
+
+ override func sceneWillEnterForeground(_ scene: UIScene) {
+ super.sceneWillEnterForeground(scene)
+ foregroundHeartbeat.start()
+ signal(SIGPIPE, SIG_IGN)
+ }
+
+ override func sceneDidEnterBackground(_ scene: UIScene) {
+ foregroundHeartbeat.stop()
+ super.sceneDidEnterBackground(scene)
+ }
+
+ override func sceneDidDisconnect(_ scene: UIScene) {
+ foregroundHeartbeat.stop()
+ super.sceneDidDisconnect(scene)
+ }
+
+ private func handleInitialLink(_ url: URL) {
+ if !url.absoluteString.contains("homeWidget") {
+ AppLinks.shared.handleLink(url: url)
+ }
+ }
+}