Skip to content

Commit 7c2ca95

Browse files
committed
fix: implement conditional platform bootstrapping for Web compatibility and add build hook null-checks
1 parent 38d8193 commit 7c2ca95

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

hook/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:native_assets_cli/code_assets.dart';
55
void main(List<String> args) async {
66
await build(args, (input, output) async {
77
// Check if code assets are supported/requested
8-
// Note: hook/build.dart is only called if the package has native assets.
8+
if (input.config.code == null) return;
99

1010
final targetOS = input.config.code.targetOS;
1111
if (targetOS != OS.linux) return;

lib/main.dart

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:ffi';
2-
import 'dart:io';
31
import 'package:flutter/foundation.dart';
42
import 'package:flutter/material.dart';
53
import 'package:get/get.dart';
@@ -9,41 +7,15 @@ import 'package:taskwarrior/app/utils/debug_logger/log_databse_helper.dart';
97
import 'package:taskwarrior/app/utils/themes/dark_theme.dart';
108
import 'package:taskwarrior/app/utils/themes/light_theme.dart';
119
import 'package:taskwarrior/rust_bridge/frb_generated.dart';
12-
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
13-
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
10+
import 'package:taskwarrior/platform_bootstrap.dart';
1411

1512
import 'app/routes/app_pages.dart';
1613

1714
LogDatabaseHelper _logDatabaseHelper = LogDatabaseHelper();
1815

19-
DynamicLibrary loadNativeLibrary() {
20-
if (kIsWeb) {
21-
throw UnsupportedError("Native libraries are not supported on Web");
22-
}
23-
24-
if (Platform.isIOS) {
25-
return DynamicLibrary.open('Frameworks/tc_helper.framework/tc_helper');
26-
} else if (Platform.isAndroid) {
27-
return DynamicLibrary.open('libtc_helper.so');
28-
} else if (Platform.isMacOS) {
29-
return DynamicLibrary.open('tc_helper.framework/tc_helper');
30-
} else if (Platform.isLinux) {
31-
return DynamicLibrary.open('libtc_helper.so');
32-
} else if (Platform.isWindows) {
33-
return DynamicLibrary.open('tc_helper.dll');
34-
}
35-
throw UnsupportedError(
36-
'Platform ${Platform.operatingSystem} is not supported');
37-
}
38-
3916
void main() async {
40-
// Initialize SQLite for Desktop platforms
41-
if (!kIsWeb && (Platform.isLinux || Platform.isWindows || Platform.isMacOS)) {
42-
sqfliteFfiInit();
43-
databaseFactory = databaseFactoryFfi;
44-
}
45-
4617
WidgetsFlutterBinding.ensureInitialized();
18+
initPlatform();
4719

4820
// Redirect debug prints to the local database logger
4921
debugPrint = (String? message, {int? wrapWidth}) {

lib/platform_bootstrap.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export 'platform_bootstrap_stub.dart'
2+
if (dart.library.io) 'platform_bootstrap_io.dart';

lib/platform_bootstrap_io.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'dart:ffi';
2+
import 'dart:io';
3+
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
4+
void initPlatform() {
5+
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
6+
sqfliteFfiInit();
7+
databaseFactory = databaseFactoryFfi;
8+
}
9+
}
10+
DynamicLibrary loadNativeLibrary() {
11+
if (Platform.isMacOS) {
12+
return DynamicLibrary.open('tc_helper.framework/tc_helper');
13+
} else if (Platform.isLinux) {
14+
return DynamicLibrary.open('libtc_helper.so');
15+
} else if (Platform.isWindows) {
16+
return DynamicLibrary.open('tc_helper.dll');
17+
}
18+
throw UnsupportedError('Platform not supported');
19+
}

lib/platform_bootstrap_stub.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// lib/platform_bootstrap_stub.dart
2+
class DynamicLibrary {
3+
static void open(String path) => throw UnsupportedError("Stub");
4+
}
5+
6+
void initPlatform() {
7+
// No-op for Web
8+
}
9+
10+
Object? loadNativeLibrary() {
11+
return null;
12+
}

0 commit comments

Comments
 (0)