diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 6bf60d46..3496c867 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart'; import 'package:neon/src/app.dart'; @@ -29,7 +30,10 @@ Future runNeon({ @visibleForTesting final bool nextPushDisabled = false, }) async { final binding = bindingOverride ?? WidgetsFlutterBinding.ensureInitialized(); - FlutterNativeSplash.preserve(widgetsBinding: binding); + + if (!kIsWeb) { + FlutterNativeSplash.preserve(widgetsBinding: binding); + } await NeonPlatform.setup(); await RequestManager.instance.initCache(); diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index 1726389e..820ef50a 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart'; import 'package:meta/meta.dart'; @@ -281,7 +282,9 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra builder: (final context, final options, final _) => StreamBuilder( stream: _accountsBloc.activeAccount, builder: (final context, final activeAccountSnapshot) { - FlutterNativeSplash.remove(); + if (!kIsWeb) { + FlutterNativeSplash.remove(); + } return ResultBuilder.behaviorSubject( subject: activeAccountSnapshot.hasData ? _accountsBloc.getCapabilitiesBlocFor(activeAccountSnapshot.data!).capabilities diff --git a/packages/neon/neon/lib/src/platform/platform.dart b/packages/neon/neon/lib/src/platform/platform.dart index ad96413d..d8a688fb 100644 --- a/packages/neon/neon/lib/src/platform/platform.dart +++ b/packages/neon/neon/lib/src/platform/platform.dart @@ -1,8 +1,9 @@ import 'dart:async'; -import 'package:meta/meta.dart'; +import 'package:flutter/foundation.dart'; import 'package:neon/src/platform/android.dart'; import 'package:neon/src/platform/linux.dart'; +import 'package:neon/src/platform/web.dart'; import 'package:universal_io/io.dart'; /// Implements platform specific functionality and exposes the availability of certain features. @@ -21,7 +22,9 @@ abstract interface class NeonPlatform { return; } - if (Platform.isAndroid) { + if (kIsWeb) { + _platform = const WebNeonPlatform(); + } else if (Platform.isAndroid) { _platform = const AndroidNeonPlatform(); } else if (Platform.isLinux) { _platform = const LinuxNeonPlatform(); @@ -64,7 +67,7 @@ abstract interface class NeonPlatform { /// This is needed to compensate lacking support of `https://pub.dev/packages/file_picker`. abstract final bool shouldUseFileDialog; - FutureOr get userAccessibleAppDataPath; + FutureOr get userAccessibleAppDataPath; FutureOr init(); } diff --git a/packages/neon/neon/lib/src/platform/web.dart b/packages/neon/neon/lib/src/platform/web.dart new file mode 100644 index 00000000..9dc78b6a --- /dev/null +++ b/packages/neon/neon/lib/src/platform/web.dart @@ -0,0 +1,44 @@ +import 'dart:async'; + +import 'package:meta/meta.dart'; +import 'package:neon/src/platform/platform.dart'; +import 'package:sqflite_common_ffi/sqflite_ffi.dart'; +import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart'; + +@immutable +@internal +class WebNeonPlatform implements NeonPlatform { + const WebNeonPlatform(); + + @override + bool get canUseCamera => false; + + @override + bool get canUsePushNotifications => false; + + @override + bool get canUseQuickActions => false; + + @override + bool get canUseSystemTray => false; + + @override + bool get canUseWebView => false; + + @override + bool get canUseWindowManager => false; + + @override + bool get canUseSharing => true; + + @override + bool get shouldUseFileDialog => throw UnimplementedError(); + + @override + FutureOr? get userAccessibleAppDataPath => null; + + @override + FutureOr init() { + databaseFactory = databaseFactoryFfiWeb; + } +} diff --git a/packages/neon/neon/lib/src/utils/request_manager.dart b/packages/neon/neon/lib/src/utils/request_manager.dart index 5222f823..14c8f611 100644 --- a/packages/neon/neon/lib/src/utils/request_manager.dart +++ b/packages/neon/neon/lib/src/utils/request_manager.dart @@ -231,9 +231,9 @@ class Cache { return; } - final cacheDir = await getApplicationCacheDirectory(); + final cacheDir = kIsWeb ? '' : (await getApplicationCacheDirectory()).path; _database = await openDatabase( - p.join(cacheDir.path, 'cache.db'), + p.join(cacheDir, 'cache.db'), version: 1, onCreate: (final db, final version) async { await db.execute('CREATE TABLE cache (id INTEGER PRIMARY KEY, key TEXT, value TEXT, UNIQUE(key))'); diff --git a/packages/neon/neon/pubspec.yaml b/packages/neon/neon/pubspec.yaml index d0c41bba..05916de5 100644 --- a/packages/neon/neon/pubspec.yaml +++ b/packages/neon/neon/pubspec.yaml @@ -48,6 +48,7 @@ dependencies: path: packages/sort_box sqflite: ^2.0.0 sqflite_common_ffi: ^2.2.8-2 + sqflite_common_ffi_web: ^0.4.0 tray_manager: ^0.2.0 unifiedpush: ^5.0.0 unifiedpush_android: ^2.0.0