app/lib/common/conf.dart

141 lines
4.5 KiB
Dart
Raw Normal View History

2023-10-09 09:32:07 +08:00
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart';
2023-11-11 01:18:30 +08:00
import 'package:hexcolor/hexcolor.dart';
2023-10-09 09:32:07 +08:00
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
2023-10-30 20:39:31 +08:00
import 'package:starcitizen_doctor/api/analytics.dart';
2023-10-09 09:32:07 +08:00
import 'package:starcitizen_doctor/api/api.dart';
2023-11-07 22:35:25 +08:00
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
import 'package:starcitizen_doctor/common/rust/ffi.dart';
2023-10-09 09:32:07 +08:00
import 'package:starcitizen_doctor/data/app_version_data.dart';
2023-11-06 22:23:06 +08:00
import 'package:starcitizen_doctor/global_ui_model.dart';
2023-10-30 20:39:31 +08:00
import 'package:uuid/uuid.dart';
2023-10-09 09:32:07 +08:00
import 'package:window_manager/window_manager.dart';
import '../base/ui.dart';
class AppConf {
2023-11-16 20:42:16 +08:00
static const String appVersion = "2.9.9 Beta";
static const int appVersionCode = 26;
2023-11-11 01:44:15 +08:00
static const String appVersionDate = "2023-11-11";
2023-10-09 09:32:07 +08:00
static const String gitlabHomeUrl =
"https://jihulab.com/StarCitizenCN_Community/StarCitizenDoctor";
static const String gitlabLocalizationUrl =
"https://jihulab.com/StarCitizenCN_Community/LocalizationData";
static const String apiRepoPath =
"https://jihulab.com/StarCitizenCN_Community/api/-/raw/main/";
static const String gitlabApiPath = "https://jihulab.com/api/v4/";
2023-10-28 19:58:26 +08:00
2023-10-28 20:09:26 +08:00
static const String webTranslateHomeUrl =
2023-10-29 18:25:31 +08:00
"https://jihulab.com/StarCitizenCN_Community/scweb_chinese_translate/-/raw/main/json/locales";
2023-10-09 09:32:07 +08:00
2023-10-30 20:39:31 +08:00
static const String xkeycApiUrl = "https://sctoolbox.xkeyc.com";
2023-10-09 09:32:07 +08:00
static late final String applicationSupportDir;
static AppVersionData? networkVersionData;
static bool offlineMode = false;
static late final WindowsDeviceInfo windowsDeviceInfo;
2023-11-11 01:18:30 +08:00
static Color? colorBackground;
static Color? colorMenu;
static Color? colorMica;
2023-10-31 00:27:46 +08:00
static const isMSE =
2023-11-07 22:53:24 +08:00
String.fromEnvironment("MSE", defaultValue: "false") == "true";
2023-10-31 00:27:46 +08:00
2023-11-06 22:23:06 +08:00
static init(List<String> args) async {
dPrint("launch args == $args");
2023-10-09 09:32:07 +08:00
WidgetsFlutterBinding.ensureInitialized();
/// init device info
2023-10-28 19:15:13 +08:00
try {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
windowsDeviceInfo = await deviceInfo.windowsInfo;
2023-10-28 20:09:26 +08:00
} catch (_) {}
2023-10-09 09:32:07 +08:00
/// init Data
applicationSupportDir =
(await getApplicationSupportDirectory()).absolute.path;
dPrint("applicationSupportDir == $applicationSupportDir");
try {
Hive.init("$applicationSupportDir/db");
2023-10-30 20:39:31 +08:00
final box = await Hive.openBox("app_conf");
if (box.get("install_id", defaultValue: "") == "") {
await box.put("install_id", const Uuid().v4());
AnalyticsApi.touch("firstLaunch");
}
2023-10-09 09:32:07 +08:00
} catch (e) {
exit(1);
}
/// check Rust bridge
if (await rustFii.ping() != "PONG") {
dPrint("Rust bridge Error");
exit(1);
}
dPrint("---- rust bridge inited -----");
2023-11-10 21:58:29 +08:00
await SystemHelper.initPowershellPath();
2023-11-11 01:18:30 +08:00
/// init defaultColor
colorBackground = HexColor("#132431").withOpacity(.75);
colorMenu = HexColor("#132431").withOpacity(.95);
colorMica = HexColor("#0A3142");
2023-10-09 09:32:07 +08:00
/// init windows
await windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setSize(const Size(1280, 820));
await windowManager.setMinimumSize(const Size(1280, 820));
await windowManager.center(animate: true);
await windowManager.setSkipTaskbar(false);
await windowManager.setTitleBarStyle(
TitleBarStyle.hidden,
windowButtonVisibility: false,
);
await windowManager.show();
await Window.initialize();
2023-11-06 23:38:55 +08:00
await Window.hideWindowControls();
2023-10-09 09:32:07 +08:00
if (windowsDeviceInfo.productName.contains("Windows 11")) {
await Window.setEffect(
effect: WindowEffect.acrylic,
);
}
});
2023-11-11 01:18:30 +08:00
await checkUpdate();
2023-10-30 20:39:31 +08:00
AnalyticsApi.touch("launch");
2023-10-09 09:32:07 +08:00
}
static String getUpgradePath() {
return "${AppConf.applicationSupportDir}/._upgrade";
}
2023-11-11 01:18:30 +08:00
static Future<void> checkUpdate() async {
2023-10-09 09:32:07 +08:00
// clean path
2023-10-31 00:27:46 +08:00
if (!isMSE) {
final dir = Directory(getUpgradePath());
if (await dir.exists()) {
dir.delete(recursive: true);
}
2023-10-09 09:32:07 +08:00
}
try {
networkVersionData = await Api.getAppVersion();
2023-11-11 01:18:30 +08:00
globalUIModel.checkActivityThemeColor();
2023-11-11 01:41:06 +08:00
if (isMSE) {
dPrint(
"lastVersion=${networkVersionData?.mSELastVersion} ${networkVersionData?.mSELastVersionCode}");
} else {
dPrint(
"lastVersion=${networkVersionData?.lastVersion} ${networkVersionData?.lastVersionCode}");
}
2023-10-09 09:32:07 +08:00
} catch (e) {
dPrint("_checkUpdate Error:$e");
}
}
}