Skip to content

Commit 38d8193

Browse files
author
bhola-dev58
committed
refactor: optimize dynamic library loading in lib/main.dart
1 parent 3e25972 commit 38d8193

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

lib/main.dart

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:ffi';
22
import 'dart:io';
3-
import 'package:flutter/foundation.dart' show kIsWeb, debugPrintSynchronously;
3+
import 'package:flutter/foundation.dart';
44
import 'package:flutter/material.dart';
55
import 'package:get/get.dart';
66
import 'package:taskwarrior/app/services/deep_link_service.dart';
@@ -16,58 +16,69 @@ import 'app/routes/app_pages.dart';
1616

1717
LogDatabaseHelper _logDatabaseHelper = LogDatabaseHelper();
1818

19-
ExternalLibrary loadNativeLibrary() {
19+
DynamicLibrary loadNativeLibrary() {
2020
if (kIsWeb) {
2121
throw UnsupportedError("Native libraries are not supported on Web");
2222
}
2323

2424
if (Platform.isIOS) {
25-
return ExternalLibrary.open('Frameworks/tc_helper.framework/tc_helper');
25+
return DynamicLibrary.open('Frameworks/tc_helper.framework/tc_helper');
2626
} else if (Platform.isAndroid) {
27-
return ExternalLibrary.open('libtc_helper.so');
27+
return DynamicLibrary.open('libtc_helper.so');
2828
} else if (Platform.isMacOS) {
29-
return ExternalLibrary.open('tc_helper.framework/tc_helper');
29+
return DynamicLibrary.open('tc_helper.framework/tc_helper');
3030
} else if (Platform.isLinux) {
31-
return ExternalLibrary.open('libtc_helper.so');
32-
} else if (Platform.isWindows) { // Add Windows back in!
33-
return ExternalLibrary.open('tc_helper.dll');
31+
return DynamicLibrary.open('libtc_helper.so');
32+
} else if (Platform.isWindows) {
33+
return DynamicLibrary.open('tc_helper.dll');
3434
}
3535
throw UnsupportedError(
3636
'Platform ${Platform.operatingSystem} is not supported');
3737
}
3838

3939
void main() async {
40-
// 1. Keep your Desktop SQLite fix
40+
// Initialize SQLite for Desktop platforms
4141
if (!kIsWeb && (Platform.isLinux || Platform.isWindows || Platform.isMacOS)) {
4242
sqfliteFfiInit();
4343
databaseFactory = databaseFactoryFfi;
4444
}
45-
// 2. Accept the project's early initialization
45+
4646
WidgetsFlutterBinding.ensureInitialized();
47-
// 3. Keep the shared Logger setup
47+
48+
// Redirect debug prints to the local database logger
4849
debugPrint = (String? message, {int? wrapWidth}) {
4950
if (message != null) {
5051
debugPrintSynchronously(message, wrapWidth: wrapWidth);
5152
_logDatabaseHelper.insertLog(message);
5253
}
5354
};
55+
5456
debugPrint("🚀 BOOT: main() started");
55-
// 4. Keep your Native Library loader
56-
final lib = loadNativeLibrary();
57-
await RustLib.init(externalLibrary: lib);
57+
58+
loadNativeLibrary();
59+
await RustLib.init();
60+
5861
await AppSettings.init();
59-
// 5. Accept the new DeepLink logic from UPSTREAM
62+
63+
// fix: Actually await the service initialization so the OS intent is caught BEFORE runApp.
6064
await Get.putAsync<DeepLinkService>(() async {
6165
final service = DeepLinkService();
6266
await service.init();
6367
return service;
64-
});
68+
}, permanent: true);
6569
runApp(
6670
GetMaterialApp(
6771
darkTheme: darkTheme,
6872
theme: lightTheme,
6973
title: "Application",
7074
initialRoute: AppPages.INITIAL,
75+
unknownRoute: AppPages.routes.firstWhere(
76+
(page) => page.name == AppPages.INITIAL,
77+
orElse: () {
78+
debugPrint("⚠️ Unknown route requested, falling back to default");
79+
return AppPages.routes.first;
80+
},
81+
),
7182
getPages: AppPages.routes,
7283
themeMode: AppSettings.isDarkMode ? ThemeMode.dark : ThemeMode.light,
7384
),

0 commit comments

Comments
 (0)