@@ -34,43 +34,39 @@ class AppInitializer {
3434 }
3535 }
3636
37- if (PlatformUtils .isDesktop) {
38- await DesktopManager .initialize ();
39- } else if (PlatformUtils .isMobile) {
40- await MobileManager .initialize ();
41- }
42-
4337 final appDir = await getApplicationDocumentsDirectory ();
4438 String path =
4539 '${appDir .path }${Platform .pathSeparator }pure_live${instanceId .isNotEmpty ? "${Platform .pathSeparator }$instanceId " : "" }' ;
4640
47- PrefUtil .prefs = await SharedPreferences .getInstance ();
48- initService ();
49-
5041 try {
42+ await SupaBaseManager .getInstance ().initial ();
43+ PrefUtil .prefs = await SharedPreferences .getInstance ();
5144 await Hive .initFlutter (path);
5245 await HivePrefUtil .init ();
46+ initService ();
5347 } catch (e) {
5448 log ("Hive Init Error: $e " );
5549 }
5650
5751 MediaKit .ensureInitialized ();
58- await SupaBaseManager .getInstance ().initial ();
59-
6052 if (PlatformUtils .isDesktop) {
53+ await DesktopManager .initialize ();
6154 await DesktopManager .postInitialize ();
6255 Future .delayed (const Duration (milliseconds: 800 ), () {
6356 WindowUtils .markCurrentWindow (instanceId);
6457 });
58+ } else if (PlatformUtils .isMobile) {
59+ await MobileManager .initialize ();
6560 }
61+
62+ initRefresh ();
63+
6664 if (PlatformUtils .isDesktopNotMac) {
6765 // 只有主实例(instanceId 为空)才注册自启,避免多个实例互相覆盖注册表
6866 if (instanceId.isEmpty) {
6967 await _setupLaunchAtStartup ();
7068 }
7169 }
72-
73- initRefresh ();
7470 _isInitialized = true ;
7571 }
7672
@@ -84,30 +80,33 @@ class AppInitializer {
8480 return '' ;
8581 }
8682
87- Future <void > _setupLaunchAtStartup () async {
88- PackageInfo packageInfo = await PackageInfo .fromPlatform ();
89- launchAtStartup.setup (
90- appName: packageInfo.appName,
91- appPath: Platform .resolvedExecutable,
92- packageName: 'dev.leanflutter.puretech.pure_live' ,
93- );
94- var settings = Get .find <SettingsService >();
95- if (settings.enableStartUp.value) {
96- bool enabled = await launchAtStartup.isEnabled ();
97- if (! enabled) {
98- await launchAtStartup.enable ();
83+ Future <void > _setupLaunchAtStartup () async {
84+ try {
85+ PackageInfo packageInfo = await PackageInfo .fromPlatform ();
86+ launchAtStartup.setup (
87+ appName: packageInfo.appName,
88+ appPath: Platform .resolvedExecutable,
89+ packageName: 'dev.leanflutter.puretech.pure_live' ,
90+ );
91+ var settings = Get .find <SettingsService >();
92+ if (settings.enableStartUp.value) {
93+ if (! await launchAtStartup.isEnabled ()) {
94+ await launchAtStartup.enable ();
95+ }
9996 }
97+ } catch (e) {
98+ log ("Auto-start error: $e " );
10099 }
101100 }
102101
103102 void initService () {
104- Get .put (SettingsService ());
105- Get .put (AuthController ());
106- Get .put (FavoriteController ());
107- Get .put (BiliBiliAccountService ());
108- Get .put (PopularController ());
109- Get .put (AreasController ());
110- Get .put (GlobalPlayerState ());
103+ Get .put (SettingsService (), permanent : true );
104+ Get .put (AuthController (), permanent : true );
105+ Get .put (FavoriteController (), permanent : true );
106+ Get .put (BiliBiliAccountService (), permanent : true );
107+ Get .put (PopularController (), permanent : true );
108+ Get .put (AreasController (), permanent : true );
109+ Get .put (GlobalPlayerState (), permanent : true );
111110 }
112111
113112 bool get isInitialized => _isInitialized;
0 commit comments