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';
|
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';
|
|
|
|
|
2024-01-29 20:44:00 +08:00
|
|
|
import '../../base/ui.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
|
|
|
|
class AppConf {
|
2024-01-07 14:57:49 +08:00
|
|
|
static const String appVersion = "2.11.0 Beta";
|
2023-12-12 20:17:43 +08:00
|
|
|
static const int appVersionCode = 36;
|
2024-01-07 14:57:49 +08:00
|
|
|
static const String appVersionDate = "2024-01-07";
|
2023-10-09 09:32:07 +08:00
|
|
|
|
2023-12-06 22:45:36 +08:00
|
|
|
static const gameChannels = ["LIVE", "PTU", "EPTU"];
|
|
|
|
|
2024-01-13 17:29:41 +08:00
|
|
|
static String deviceUUID = "";
|
|
|
|
|
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");
|
|
|
|
}
|
2024-01-13 17:29:41 +08:00
|
|
|
deviceUUID = box.get("install_id", defaultValue: "");
|
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-05 15:56:48 +08:00
|
|
|
|
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 {
|
2023-12-02 12:35:02 +08:00
|
|
|
await windowManager.setSize(const Size(1280, 810));
|
2023-11-30 20:28:03 +08:00
|
|
|
await windowManager.setMinimumSize(const Size(1280, 810));
|
2023-10-09 09:32:07 +08:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|