Skip to content

Commit ac1af50

Browse files
author
liuchuancong
committed
优化项目
1 parent a2bd702 commit ac1af50

5 files changed

Lines changed: 58 additions & 46 deletions

File tree

lib/common/global/initialized.dart

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

lib/common/global/platform/desktop_manager.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:get/get.dart';
55
import 'package:flutter/material.dart';
66
import 'package:pure_live/plugins/utils.dart';
77
import 'package:tray_manager/tray_manager.dart';
8+
import 'package:url_launcher/url_launcher.dart';
89
import 'package:window_manager/window_manager.dart';
910
import 'package:bitsdojo_window/bitsdojo_window.dart';
1011
import 'package:flutter_acrylic/flutter_acrylic.dart';
@@ -265,9 +266,24 @@ class CustomTitleBar extends StatelessWidget {
265266
alignment: Alignment.centerLeft,
266267
child: isFull
267268
? null
268-
: Text(
269-
"Pure Live",
270-
style: TextStyle(fontSize: 13, color: baseIconColor, fontWeight: FontWeight.bold),
269+
: Material(
270+
color: Colors.transparent,
271+
child: InkWell(
272+
onTap: () async {
273+
final url = Uri.parse('https://github.com/liuchuancong/pure_live');
274+
if (await canLaunchUrl(url)) await launchUrl(url);
275+
},
276+
child: Text(
277+
"Pure Live",
278+
style: TextStyle(
279+
fontSize: 13,
280+
color: baseIconColor,
281+
fontWeight: FontWeight.bold,
282+
decoration: TextDecoration.none,
283+
decorationColor: baseIconColor,
284+
),
285+
),
286+
),
271287
),
272288
),
273289
),

lib/main.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import 'package:pure_live/player/switchable_global_player.dart';
1111
import 'package:pure_live/common/global/platform/desktop_manager.dart';
1212
import 'package:pure_live/common/global/platform/background_server.dart';
1313

14-
const kWindowsScheme = 'purelive://signin';
15-
1614
void main(List<String> args) async {
1715
// 初始化
1816
await AppInitializer().initialize(args);

lib/plugins/supabase.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class SupaBaseManager {
2626
SupaBaseManager();
2727
Future initial() async {
2828
var mapString = await rootBundle.loadString("assets/keystore/supabase.json");
29-
3029
supabasePolicy = SupabasePolicy.fromJson(jsonDecode(mapString)); // 获取配置信息
3130
await Supabase.initialize(url: supabasePolicy.supabaseUrl, anonKey: supabasePolicy.supabaseKey);
3231
}

pubspec.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ packages:
277277
dependency: transitive
278278
description:
279279
name: characters
280-
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
280+
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
281281
url: "https://pub.flutter-io.cn"
282282
source: hosted
283-
version: "1.4.0"
283+
version: "1.4.1"
284284
checked_yaml:
285285
dependency: transitive
286286
description:
@@ -1172,18 +1172,18 @@ packages:
11721172
dependency: transitive
11731173
description:
11741174
name: matcher
1175-
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
1175+
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
11761176
url: "https://pub.flutter-io.cn"
11771177
source: hosted
1178-
version: "0.12.17"
1178+
version: "0.12.19"
11791179
material_color_utilities:
11801180
dependency: transitive
11811181
description:
11821182
name: material_color_utilities
1183-
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
1183+
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
11841184
url: "https://pub.flutter-io.cn"
11851185
source: hosted
1186-
version: "0.11.1"
1186+
version: "0.13.0"
11871187
media_kit:
11881188
dependency: "direct main"
11891189
description:
@@ -2005,10 +2005,10 @@ packages:
20052005
dependency: transitive
20062006
description:
20072007
name: test_api
2008-
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
2008+
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
20092009
url: "https://pub.flutter-io.cn"
20102010
source: hosted
2011-
version: "0.7.7"
2011+
version: "0.7.10"
20122012
timezone:
20132013
dependency: "direct main"
20142014
description:

0 commit comments

Comments
 (0)