app/lib/common/conf.dart

99 lines
3.1 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';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
import 'package:starcitizen_doctor/api/api.dart';
import 'package:starcitizen_doctor/data/app_version_data.dart';
import 'package:window_manager/window_manager.dart';
import '../base/ui.dart';
class AppConf {
2023-10-29 18:10:00 +08:00
static const String appVersion = "2.9.6+1 Beta";
static const int appVersionCode = 22;
static const String appVersionDate = "2023-10-29";
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
static late final String applicationSupportDir;
static AppVersionData? networkVersionData;
static bool offlineMode = false;
static late final WindowsDeviceInfo windowsDeviceInfo;
static init() async {
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");
await Hive.openBox("app_conf");
} catch (e) {
exit(1);
}
/// 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();
if (windowsDeviceInfo.productName.contains("Windows 11")) {
await Window.setEffect(
effect: WindowEffect.acrylic,
);
}
await Window.hideWindowControls();
});
await _checkUpdate();
}
static String getUpgradePath() {
return "${AppConf.applicationSupportDir}/._upgrade";
}
static Future<void> _checkUpdate() async {
// clean path
final dir = Directory(getUpgradePath());
if (await dir.exists()) {
dir.delete(recursive: true);
}
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");
}
}
}