fix:参考金值,研听,研值工程通用通用工程公共能力,重点对比网络请求、登录认证、状态管理、本地存储、WebView、推送、版本更新、一键登录、主题/UI 等模块,确定后续统一整改方案
This commit is contained in:
1 parent
6997a65c96
commit
d364c6d908
46 files changed
+2060
-395
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:app_links/app_links.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
@@ -15,6 +17,10 @@ import '../common/theme/theme_controller.dart';
|
||||
import '../features/ads/application/ad_config_foreground_refresher.dart';
|
||||
import '../features/settings/application/update_foreground_service.dart';
|
||||
import '../features/web/application/mall_web_host_controller.dart';
|
||||
import '../features/auth/application/auth_controller.dart';
|
||||
import '../features/auth/application/auth_session_coordinator.dart';
|
||||
import '../features/auth/data/auth_models.dart';
|
||||
import '../features/assets/application/asset_portfolio_controller.dart';
|
||||
import '../common/router/deep_link_service.dart';
|
||||
import '../common/services/device_header_service.dart';
|
||||
|
||||
@@ -28,14 +34,43 @@ class JinzhiApp extends ConsumerStatefulWidget {
|
||||
class _JinzhiAppState extends ConsumerState<JinzhiApp>
|
||||
with WidgetsBindingObserver {
|
||||
late final DevicePushRegistrar _pushRegistrar;
|
||||
ProviderSubscription<AsyncValue<AuthState>>? _authSubscription;
|
||||
StreamSubscription<Uri>? _appLinkSubscription;
|
||||
late final SessionEndListener _sessionEndListener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_pushRegistrar = DevicePushRegistrar(ref.read)..start();
|
||||
_sessionEndListener = (reason) {
|
||||
if (reason == SessionEndReason.accountDeleted) {
|
||||
ref.read(assetPortfolioControllerProvider.notifier).clearHoldings();
|
||||
}
|
||||
};
|
||||
ref.read(authSessionCoordinatorProvider).addListener(_sessionEndListener);
|
||||
_authSubscription = ref.listenManual<AsyncValue<AuthState>>(authProvider, (
|
||||
previous,
|
||||
next,
|
||||
) {
|
||||
final oldUser = previous?.valueOrNull is LoggedInAuthState
|
||||
? (previous!.valueOrNull! as LoggedInAuthState).user.id
|
||||
: null;
|
||||
final newUser = next.valueOrNull is LoggedInAuthState
|
||||
? (next.valueOrNull! as LoggedInAuthState).user.id
|
||||
: null;
|
||||
if (oldUser != newUser) _pushRegistrar.forceRegisterCurrentToken();
|
||||
DeepLinkService.notifyAuthChanged();
|
||||
});
|
||||
UmengPushService.configureNotificationOpen(DeepLinkService.handle);
|
||||
unawaited(_startAppLinks());
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
DeepLinkService.attachRouter((location) {
|
||||
final context = rootNavigatorKey.currentContext;
|
||||
if (context == null) return false;
|
||||
context.go(location);
|
||||
return true;
|
||||
}, authGuard: (_) => !ref.read(authProvider).isLoading);
|
||||
// 首次 iOS 启动在欢迎页点击进入后才注册 APNs,确保系统弹窗不被启动页
|
||||
// 或其他 Overlay 吞掉;后续启动和 Android 保持原有自动初始化。
|
||||
if (!DeviceHeaderService.to.iosStartupRequired) {
|
||||
@@ -44,9 +79,29 @@ class _JinzhiAppState extends ConsumerState<JinzhiApp>
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _startAppLinks() async {
|
||||
try {
|
||||
final appLinks = AppLinks();
|
||||
final initial = await appLinks.getInitialLink();
|
||||
if (initial != null) DeepLinkService.handleUri(initial);
|
||||
_appLinkSubscription = appLinks.uriLinkStream.listen(
|
||||
DeepLinkService.handleUri,
|
||||
onError: (_) {},
|
||||
);
|
||||
} catch (_) {
|
||||
// Desktop tests and unsupported platforms may not register the plugin.
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
unawaited(_pushRegistrar.stop());
|
||||
_authSubscription?.close();
|
||||
ref
|
||||
.read(authSessionCoordinatorProvider)
|
||||
.removeListener(_sessionEndListener);
|
||||
unawaited(_appLinkSubscription?.cancel());
|
||||
DeepLinkService.detachRouter();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:flutter/widgets.dart';
|
||||
import '../common/services/device_header_service.dart';
|
||||
import '../common/config/shorebird_service.dart';
|
||||
import '../common/config/umeng_config.dart';
|
||||
import '../common/storage/secure_identity_storage.dart';
|
||||
import '../common/storage/storage_service.dart';
|
||||
import '../common/widgets/easy_refresh_localization.dart';
|
||||
import 'app.dart';
|
||||
@@ -17,9 +16,6 @@ Future<Widget> bootstrap() async {
|
||||
configureEasyRefreshChineseLocalization();
|
||||
await UmengConfig.load();
|
||||
await StorageService.instance;
|
||||
await SecureIdentityStorage(
|
||||
StorageService.to.preferences,
|
||||
).restoreAccessToken();
|
||||
if (!kIsWeb) {
|
||||
if (Platform.isAndroid) {
|
||||
// Before consent this only initializes app version and channel. The
|
||||
|
||||
Reference in new issue
Block a user