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';
|
|
|
|
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';
|
2023-11-05 15:56:48 +08:00
|
|
|
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-08 20:48:48 +08:00
|
|
|
static const String appVersion = "2.9.12 Beta";
|
|
|
|
static const int appVersionCode = 27;
|
2023-11-03 23:08:58 +08:00
|
|
|
static const String appVersionDate = "2023-11-03";
|
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;
|
|
|
|
|
2023-11-06 22:23:06 +08:00
|
|
|
static bool isRunningAdmin = false;
|
|
|
|
|
2023-10-09 09:32:07 +08:00
|
|
|
static late final WindowsDeviceInfo windowsDeviceInfo;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-11-05 15:56:48 +08:00
|
|
|
/// 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-06 22:23:06 +08:00
|
|
|
isRunningAdmin = await globalUIModel.checkAdmin();
|
2023-11-05 15:56:48 +08:00
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> _checkUpdate() async {
|
|
|
|
// 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();
|
|
|
|
dPrint(
|
2023-10-28 20:09:26 +08:00
|
|
|
"lastVersion=${networkVersionData?.lastVersion} ${networkVersionData?.lastVersionCode}");
|
2023-10-09 09:32:07 +08:00
|
|
|
} catch (e) {
|
|
|
|
dPrint("_checkUpdate Error:$e");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|