Browse Source

feat(neon): Add neon web platform

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/372/head
jld3103 1 year ago
parent
commit
4272042c6f
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 4
      packages/neon/neon/lib/neon.dart
  2. 3
      packages/neon/neon/lib/src/app.dart
  3. 9
      packages/neon/neon/lib/src/platform/platform.dart
  4. 44
      packages/neon/neon/lib/src/platform/web.dart
  5. 4
      packages/neon/neon/lib/src/utils/request_manager.dart
  6. 1
      packages/neon/neon/pubspec.yaml

4
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<void> runNeon({
@visibleForTesting final bool nextPushDisabled = false,
}) async {
final binding = bindingOverride ?? WidgetsFlutterBinding.ensureInitialized();
if (!kIsWeb) {
FlutterNativeSplash.preserve(widgetsBinding: binding);
}
await NeonPlatform.setup();
await RequestManager.instance.initCache();

3
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<NeonApp> with WidgetsBindingObserver, tray.Tra
builder: (final context, final options, final _) => StreamBuilder<Account?>(
stream: _accountsBloc.activeAccount,
builder: (final context, final activeAccountSnapshot) {
if (!kIsWeb) {
FlutterNativeSplash.remove();
}
return ResultBuilder<core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data?>.behaviorSubject(
subject: activeAccountSnapshot.hasData
? _accountsBloc.getCapabilitiesBlocFor(activeAccountSnapshot.data!).capabilities

9
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<String> get userAccessibleAppDataPath;
FutureOr<String?> get userAccessibleAppDataPath;
FutureOr<void> init();
}

44
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<String>? get userAccessibleAppDataPath => null;
@override
FutureOr<void> init() {
databaseFactory = databaseFactoryFfiWeb;
}
}

4
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))');

1
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

Loading…
Cancel
Save