From a8c4988790a1545c2bee829ad68b507d360f0afc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 7 Oct 2025 03:05:53 +0800 Subject: [PATCH] :bug: Fix bugs --- lib/database/database.web.dart | 17 +++++++++++------ lib/pods/activity/activity_rpc.dart | 2 +- lib/services/notify.dart | 15 ++++++++++++++- web/index.html | 2 ++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/database/database.web.dart b/lib/database/database.web.dart index e87ba7d7..b6b6ea54 100644 --- a/lib/database/database.web.dart +++ b/lib/database/database.web.dart @@ -9,12 +9,17 @@ AppDatabase constructDb() { DatabaseConnection connectOnWeb() { return DatabaseConnection.delayed( Future(() async { - final result = await WasmDatabase.open( - databaseName: 'solar_network_data', - sqlite3Uri: Uri.parse('sqlite3.wasm'), - driftWorkerUri: Uri.parse('drift_worker.dart.js'), - ); - return result.resolvedExecutor; + try { + final result = await WasmDatabase.open( + databaseName: 'solar_network_data', + sqlite3Uri: Uri.parse('sqlite3.wasm'), + driftWorkerUri: Uri.parse('drift_worker.dart.js'), + ); + return result.resolvedExecutor; + } catch (e) { + print('Failed to open WASM database: $e'); + rethrow; + } }), ); } diff --git a/lib/pods/activity/activity_rpc.dart b/lib/pods/activity/activity_rpc.dart index b64b1293..9cfb6ec5 100644 --- a/lib/pods/activity/activity_rpc.dart +++ b/lib/pods/activity/activity_rpc.dart @@ -312,7 +312,7 @@ class ServerStateNotifier extends StateNotifier { : super(ServerState(status: 'Server not started')); Future start() async { - if (!Platform.isAndroid && !Platform.isIOS && !kIsWeb) { + if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) { try { await server.start(); state = state.copyWith(status: 'Server running'); diff --git a/lib/services/notify.dart b/lib/services/notify.dart index ad594662..053567c4 100644 --- a/lib/services/notify.dart +++ b/lib/services/notify.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -11,6 +12,10 @@ import 'notify.universal.dart' as universal_notify; // Platform-specific delegation Future initializeLocalNotifications() async { + if (kIsWeb) { + // No local notifications on web + return; + } if (Platform.isWindows) { return windows_notify.initializeLocalNotifications(); } else { @@ -18,10 +23,14 @@ Future initializeLocalNotifications() async { } } -StreamSubscription setupNotificationListener( +StreamSubscription? setupNotificationListener( BuildContext context, WidgetRef ref, ) { + if (kIsWeb) { + // No notification listener on web + return null; + } if (Platform.isWindows) { return windows_notify.setupNotificationListener(context, ref); } else { @@ -33,6 +42,10 @@ Future subscribePushNotification( Dio apiClient, { bool detailedErrors = false, }) async { + if (kIsWeb) { + // No push notification subscription on web + return; + } if (Platform.isWindows) { return windows_notify.subscribePushNotification( apiClient, diff --git a/web/index.html b/web/index.html index 51e26bec..40b519e6 100644 --- a/web/index.html +++ b/web/index.html @@ -248,6 +248,8 @@ src="https://unpkg.com/sweetalert@2.1.2/dist/sweetalert.min.js" async="" > + +