iOS check in widget

This commit is contained in:
2026-01-03 18:50:54 +08:00
parent 35a9c9ff4b
commit 978b7b32fd
18 changed files with 1142 additions and 54 deletions

View File

@@ -20,6 +20,7 @@ import 'package:island/pods/userinfo.dart';
import 'package:island/pods/websocket.dart';
import 'package:island/route.dart';
import 'package:island/services/notify.dart';
import 'package:island/services/widget_sync_service.dart';
import 'package:island/services/timezone.dart';
import 'package:island/widgets/alert.dart';
import 'package:island/widgets/app_scaffold.dart';
@@ -282,6 +283,11 @@ class IslandApp extends HookConsumerWidget {
ref.listen(websocketStateProvider, (_, state) {
talker.info('[WebSocket] $state');
});
ref.listen(userInfoProvider, (_, user) {
if (user.value != null) {
WidgetSyncService().syncToWidget();
}
});
Future(() {
userNotifier.fetchUser().then((_) {
final user = ref.watch(userInfoProvider);

View File

@@ -0,0 +1,24 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
class WidgetSyncService {
static const _channel = MethodChannel('dev.solsynth.solian/widget');
static final _instance = WidgetSyncService._internal();
factory WidgetSyncService() => _instance;
WidgetSyncService._internal();
bool get _isSupported => !kIsWeb && (Platform.isAndroid || Platform.isIOS);
Future<void> syncToWidget() async {
if (!_isSupported) return;
try {
await _channel.invokeMethod('syncToWidget');
} catch (e) {
debugPrint('Failed to sync to widget: $e');
}
}
}

View File

@@ -272,7 +272,7 @@ class AppWrapper extends HookConsumerWidget {
final router = ref.read(routerProvider);
if (uri.queryParameters.isNotEmpty) {
path = Uri.parse(
path,
path == '/dashboard' ? '/' : path,
).replace(queryParameters: uri.queryParameters).toString();
}
router.push(path);