mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-22 19:53:43 +08:00
feat:riverpod 迁移
This commit is contained in:
parent
c6b69c4e08
commit
8e37ebece5
@ -26,5 +26,9 @@ linter:
|
|||||||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||||
dangling_library_doc_comments: false
|
dangling_library_doc_comments: false
|
||||||
|
|
||||||
|
analyzer:
|
||||||
|
plugins:
|
||||||
|
- custom_lint
|
||||||
|
|
||||||
# Additional information about this file can be found at
|
# Additional information about this file can be found at
|
||||||
# https://dart.dev/guides/language/analysis-options
|
# https://dart.dev/guides/language/analysis-options
|
||||||
|
255
lib/app.dart
Normal file
255
lib/app.dart
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
|
import 'package:flutter_acrylic/flutter_acrylic.dart';
|
||||||
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:hexcolor/hexcolor.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/conf/const_conf.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||||
|
import 'package:starcitizen_doctor/ui/splash_ui.dart';
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
|
import 'api/analytics.dart';
|
||||||
|
import 'api/api.dart';
|
||||||
|
import 'common/helper/system_helper.dart';
|
||||||
|
import 'common/io/rs_http.dart';
|
||||||
|
import 'common/rust/frb_generated.dart';
|
||||||
|
import 'common/utils/base_utils.dart';
|
||||||
|
import 'data/app_version_data.dart';
|
||||||
|
import 'ui/settings/upgrade_dialog.dart';
|
||||||
|
|
||||||
|
part 'app.g.dart';
|
||||||
|
|
||||||
|
part 'app.freezed.dart';
|
||||||
|
|
||||||
|
@riverpod
|
||||||
|
GoRouter router(RouterRef ref) {
|
||||||
|
return GoRouter(
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: '/',
|
||||||
|
builder: (context, state) {
|
||||||
|
return const SplashUI();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@riverpod
|
||||||
|
class AppGlobalModel extends _$AppGlobalModel {
|
||||||
|
@override
|
||||||
|
AppGlobalState build() {
|
||||||
|
return const AppGlobalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _initialized = false;
|
||||||
|
|
||||||
|
Future<void> initApp() async {
|
||||||
|
if (_initialized) return;
|
||||||
|
// init Data
|
||||||
|
final userProfileDir = Platform.environment["USERPROFILE"];
|
||||||
|
final applicationSupportDir =
|
||||||
|
(await getApplicationSupportDirectory()).absolute.path;
|
||||||
|
String? applicationBinaryModuleDir;
|
||||||
|
final logFile = File(
|
||||||
|
"$applicationSupportDir\\logs\\${DateTime.now().millisecondsSinceEpoch}.log");
|
||||||
|
await logFile.create(recursive: true);
|
||||||
|
setDPrintFile(logFile);
|
||||||
|
if (ConstConf.isMSE && userProfileDir != null) {
|
||||||
|
applicationBinaryModuleDir =
|
||||||
|
"$userProfileDir\\AppData\\Local\\Temp\\SCToolbox\\modules";
|
||||||
|
} else {
|
||||||
|
applicationBinaryModuleDir = "$applicationSupportDir\\modules";
|
||||||
|
}
|
||||||
|
dPrint("applicationSupportDir == $applicationSupportDir");
|
||||||
|
dPrint("applicationBinaryModuleDir == $applicationBinaryModuleDir");
|
||||||
|
state = state.copyWith(
|
||||||
|
applicationSupportDir: applicationSupportDir,
|
||||||
|
applicationBinaryModuleDir: applicationBinaryModuleDir,
|
||||||
|
);
|
||||||
|
|
||||||
|
// init Hive
|
||||||
|
try {
|
||||||
|
Hive.init("$applicationSupportDir/db");
|
||||||
|
final box = await Hive.openBox("app_conf");
|
||||||
|
if (box.get("install_id", defaultValue: "") == "") {
|
||||||
|
await box.put("install_id", const Uuid().v4());
|
||||||
|
AnalyticsApi.touch("firstLaunch");
|
||||||
|
}
|
||||||
|
final deviceUUID = box.get("install_id", defaultValue: "");
|
||||||
|
state = state.copyWith(deviceUUID: deviceUUID);
|
||||||
|
} catch (e) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// init Rust bridge
|
||||||
|
await RustLib.init();
|
||||||
|
await RSHttp.init();
|
||||||
|
dPrint("---- rust bridge inited -----");
|
||||||
|
|
||||||
|
// init powershell
|
||||||
|
await SystemHelper.initPowershellPath();
|
||||||
|
|
||||||
|
// get windows info
|
||||||
|
WindowsDeviceInfo? windowsDeviceInfo;
|
||||||
|
try {
|
||||||
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||||
|
windowsDeviceInfo = await deviceInfo.windowsInfo;
|
||||||
|
} catch (e) {
|
||||||
|
dPrint("DeviceInfo.windowsInfo error: $e");
|
||||||
|
}
|
||||||
|
|
||||||
|
// init windows
|
||||||
|
|
||||||
|
windowManager.waitUntilReadyToShow().then((_) async {
|
||||||
|
await windowManager.setSize(const Size(1280, 810));
|
||||||
|
await windowManager.setMinimumSize(const Size(1280, 810));
|
||||||
|
await windowManager.setSkipTaskbar(false);
|
||||||
|
await windowManager.show();
|
||||||
|
await Window.initialize();
|
||||||
|
await Window.hideWindowControls();
|
||||||
|
if (windowsDeviceInfo?.productName.contains("Windows 11") ?? false) {
|
||||||
|
await Window.setEffect(
|
||||||
|
effect: WindowEffect.acrylic,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
_initialized = true;
|
||||||
|
ref.keepAlive();
|
||||||
|
}
|
||||||
|
|
||||||
|
String getUpgradePath() {
|
||||||
|
return "${state.applicationSupportDir}/._upgrade";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore: avoid_build_context_in_providers
|
||||||
|
Future<bool> checkUpdate(BuildContext context) async {
|
||||||
|
if (!ConstConf.isMSE) {
|
||||||
|
final dir = Directory(getUpgradePath());
|
||||||
|
if (await dir.exists()) {
|
||||||
|
dir.delete(recursive: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamic checkUpdateError;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final networkVersionData = await Api.getAppVersion();
|
||||||
|
checkActivityThemeColor(networkVersionData);
|
||||||
|
if (ConstConf.isMSE) {
|
||||||
|
dPrint(
|
||||||
|
"lastVersion=${networkVersionData.mSELastVersion} ${networkVersionData.mSELastVersionCode}");
|
||||||
|
} else {
|
||||||
|
dPrint(
|
||||||
|
"lastVersion=${networkVersionData.lastVersion} ${networkVersionData.lastVersionCode}");
|
||||||
|
}
|
||||||
|
state = state.copyWith(networkVersionData: networkVersionData);
|
||||||
|
} catch (e) {
|
||||||
|
checkUpdateError = e;
|
||||||
|
dPrint("_checkUpdate Error:$e");
|
||||||
|
}
|
||||||
|
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
if (state.networkVersionData == null) {
|
||||||
|
if (!context.mounted) return false;
|
||||||
|
await showToast(context,
|
||||||
|
"网络异常!\n这可能是您的网络环境存在DNS污染,请尝试更换DNS。\n或服务器正在维护或遭受攻击,稍后再试。 \n进入离线模式... \n\n请谨慎在离线模式中使用。 \n当前版本构建日期:${ConstConf.appVersionDate}\n QQ群:940696487 \n错误信息:$checkUpdateError");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final lastVersion = ConstConf.isMSE
|
||||||
|
? state.networkVersionData?.mSELastVersionCode
|
||||||
|
: state.networkVersionData?.lastVersionCode;
|
||||||
|
if ((lastVersion ?? 0) > ConstConf.appVersionCode) {
|
||||||
|
// need update
|
||||||
|
if (!context.mounted) return false;
|
||||||
|
|
||||||
|
final r = await showDialog(
|
||||||
|
dismissWithEsc: false,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => const UpgradeDialogUI());
|
||||||
|
|
||||||
|
if (r != true) {
|
||||||
|
if (!context.mounted) return false;
|
||||||
|
showToast(context, "获取更新信息失败,请稍后重试。");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer? _activityThemeColorTimer;
|
||||||
|
|
||||||
|
checkActivityThemeColor(AppVersionData networkVersionData) {
|
||||||
|
if (_activityThemeColorTimer != null) {
|
||||||
|
_activityThemeColorTimer?.cancel();
|
||||||
|
_activityThemeColorTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final startTime = networkVersionData.activityColors?.startTime;
|
||||||
|
final endTime = networkVersionData.activityColors?.endTime;
|
||||||
|
if (startTime == null || endTime == null) return;
|
||||||
|
final now = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
|
||||||
|
dPrint("now == $now start == $startTime end == $endTime");
|
||||||
|
if (now < startTime) {
|
||||||
|
_activityThemeColorTimer = Timer(Duration(milliseconds: startTime - now),
|
||||||
|
() => checkActivityThemeColor(networkVersionData));
|
||||||
|
dPrint("start Timer ....");
|
||||||
|
} else if (now >= startTime && now <= endTime) {
|
||||||
|
dPrint("update Color ....");
|
||||||
|
// update Color
|
||||||
|
final colorCfg = networkVersionData.activityColors;
|
||||||
|
state = state.copyWith(
|
||||||
|
themeConf: ThemeConf(
|
||||||
|
backgroundColor:
|
||||||
|
HexColor(colorCfg?.background ?? "#132431").withOpacity(.75),
|
||||||
|
menuColor: HexColor(colorCfg?.menu ?? "#132431").withOpacity(.95),
|
||||||
|
micaColor: HexColor(colorCfg?.mica ?? "#0A3142"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// wait for end
|
||||||
|
_activityThemeColorTimer = Timer(Duration(milliseconds: endTime - now),
|
||||||
|
() => checkActivityThemeColor(networkVersionData));
|
||||||
|
} else {
|
||||||
|
dPrint("reset Color ....");
|
||||||
|
state = state.copyWith(
|
||||||
|
themeConf: ThemeConf(
|
||||||
|
backgroundColor: HexColor("#132431").withOpacity(.75),
|
||||||
|
menuColor: HexColor("#132431").withOpacity(.95),
|
||||||
|
micaColor: HexColor("#0A3142"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class AppGlobalState with _$AppGlobalState {
|
||||||
|
const factory AppGlobalState({
|
||||||
|
String? deviceUUID,
|
||||||
|
String? applicationSupportDir,
|
||||||
|
String? applicationBinaryModuleDir,
|
||||||
|
AppVersionData? networkVersionData,
|
||||||
|
@Default(ThemeConf()) ThemeConf themeConf,
|
||||||
|
}) = _AppGlobalState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class ThemeConf with _$ThemeConf {
|
||||||
|
const factory ThemeConf({
|
||||||
|
@Default(Color(0xbf132431)) Color backgroundColor,
|
||||||
|
@Default(Color(0xf2132431)) Color menuColor,
|
||||||
|
@Default(Color(0xff0a3142)) Color micaColor,
|
||||||
|
}) = _ThemeConf;
|
||||||
|
}
|
405
lib/app.freezed.dart
Normal file
405
lib/app.freezed.dart
Normal file
@ -0,0 +1,405 @@
|
|||||||
|
// coverage:ignore-file
|
||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||||
|
|
||||||
|
part of 'app.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// FreezedGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
T _$identity<T>(T value) => value;
|
||||||
|
|
||||||
|
final _privateConstructorUsedError = UnsupportedError(
|
||||||
|
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
mixin _$AppGlobalState {
|
||||||
|
String? get deviceUUID => throw _privateConstructorUsedError;
|
||||||
|
String? get applicationSupportDir => throw _privateConstructorUsedError;
|
||||||
|
String? get applicationBinaryModuleDir => throw _privateConstructorUsedError;
|
||||||
|
AppVersionData? get networkVersionData => throw _privateConstructorUsedError;
|
||||||
|
ThemeConf get themeConf => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
$AppGlobalStateCopyWith<AppGlobalState> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $AppGlobalStateCopyWith<$Res> {
|
||||||
|
factory $AppGlobalStateCopyWith(
|
||||||
|
AppGlobalState value, $Res Function(AppGlobalState) then) =
|
||||||
|
_$AppGlobalStateCopyWithImpl<$Res, AppGlobalState>;
|
||||||
|
@useResult
|
||||||
|
$Res call(
|
||||||
|
{String? deviceUUID,
|
||||||
|
String? applicationSupportDir,
|
||||||
|
String? applicationBinaryModuleDir,
|
||||||
|
AppVersionData? networkVersionData,
|
||||||
|
ThemeConf themeConf});
|
||||||
|
|
||||||
|
$ThemeConfCopyWith<$Res> get themeConf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$AppGlobalStateCopyWithImpl<$Res, $Val extends AppGlobalState>
|
||||||
|
implements $AppGlobalStateCopyWith<$Res> {
|
||||||
|
_$AppGlobalStateCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Val _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function($Val) _then;
|
||||||
|
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? deviceUUID = freezed,
|
||||||
|
Object? applicationSupportDir = freezed,
|
||||||
|
Object? applicationBinaryModuleDir = freezed,
|
||||||
|
Object? networkVersionData = freezed,
|
||||||
|
Object? themeConf = null,
|
||||||
|
}) {
|
||||||
|
return _then(_value.copyWith(
|
||||||
|
deviceUUID: freezed == deviceUUID
|
||||||
|
? _value.deviceUUID
|
||||||
|
: deviceUUID // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
applicationSupportDir: freezed == applicationSupportDir
|
||||||
|
? _value.applicationSupportDir
|
||||||
|
: applicationSupportDir // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
applicationBinaryModuleDir: freezed == applicationBinaryModuleDir
|
||||||
|
? _value.applicationBinaryModuleDir
|
||||||
|
: applicationBinaryModuleDir // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
networkVersionData: freezed == networkVersionData
|
||||||
|
? _value.networkVersionData
|
||||||
|
: networkVersionData // ignore: cast_nullable_to_non_nullable
|
||||||
|
as AppVersionData?,
|
||||||
|
themeConf: null == themeConf
|
||||||
|
? _value.themeConf
|
||||||
|
: themeConf // ignore: cast_nullable_to_non_nullable
|
||||||
|
as ThemeConf,
|
||||||
|
) as $Val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
$ThemeConfCopyWith<$Res> get themeConf {
|
||||||
|
return $ThemeConfCopyWith<$Res>(_value.themeConf, (value) {
|
||||||
|
return _then(_value.copyWith(themeConf: value) as $Val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$$AppGlobalStateImplCopyWith<$Res>
|
||||||
|
implements $AppGlobalStateCopyWith<$Res> {
|
||||||
|
factory _$$AppGlobalStateImplCopyWith(_$AppGlobalStateImpl value,
|
||||||
|
$Res Function(_$AppGlobalStateImpl) then) =
|
||||||
|
__$$AppGlobalStateImplCopyWithImpl<$Res>;
|
||||||
|
@override
|
||||||
|
@useResult
|
||||||
|
$Res call(
|
||||||
|
{String? deviceUUID,
|
||||||
|
String? applicationSupportDir,
|
||||||
|
String? applicationBinaryModuleDir,
|
||||||
|
AppVersionData? networkVersionData,
|
||||||
|
ThemeConf themeConf});
|
||||||
|
|
||||||
|
@override
|
||||||
|
$ThemeConfCopyWith<$Res> get themeConf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$$AppGlobalStateImplCopyWithImpl<$Res>
|
||||||
|
extends _$AppGlobalStateCopyWithImpl<$Res, _$AppGlobalStateImpl>
|
||||||
|
implements _$$AppGlobalStateImplCopyWith<$Res> {
|
||||||
|
__$$AppGlobalStateImplCopyWithImpl(
|
||||||
|
_$AppGlobalStateImpl _value, $Res Function(_$AppGlobalStateImpl) _then)
|
||||||
|
: super(_value, _then);
|
||||||
|
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? deviceUUID = freezed,
|
||||||
|
Object? applicationSupportDir = freezed,
|
||||||
|
Object? applicationBinaryModuleDir = freezed,
|
||||||
|
Object? networkVersionData = freezed,
|
||||||
|
Object? themeConf = null,
|
||||||
|
}) {
|
||||||
|
return _then(_$AppGlobalStateImpl(
|
||||||
|
deviceUUID: freezed == deviceUUID
|
||||||
|
? _value.deviceUUID
|
||||||
|
: deviceUUID // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
applicationSupportDir: freezed == applicationSupportDir
|
||||||
|
? _value.applicationSupportDir
|
||||||
|
: applicationSupportDir // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
applicationBinaryModuleDir: freezed == applicationBinaryModuleDir
|
||||||
|
? _value.applicationBinaryModuleDir
|
||||||
|
: applicationBinaryModuleDir // ignore: cast_nullable_to_non_nullable
|
||||||
|
as String?,
|
||||||
|
networkVersionData: freezed == networkVersionData
|
||||||
|
? _value.networkVersionData
|
||||||
|
: networkVersionData // ignore: cast_nullable_to_non_nullable
|
||||||
|
as AppVersionData?,
|
||||||
|
themeConf: null == themeConf
|
||||||
|
? _value.themeConf
|
||||||
|
: themeConf // ignore: cast_nullable_to_non_nullable
|
||||||
|
as ThemeConf,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$AppGlobalStateImpl implements _AppGlobalState {
|
||||||
|
const _$AppGlobalStateImpl(
|
||||||
|
{this.deviceUUID,
|
||||||
|
this.applicationSupportDir,
|
||||||
|
this.applicationBinaryModuleDir,
|
||||||
|
this.networkVersionData,
|
||||||
|
this.themeConf = const ThemeConf()});
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String? deviceUUID;
|
||||||
|
@override
|
||||||
|
final String? applicationSupportDir;
|
||||||
|
@override
|
||||||
|
final String? applicationBinaryModuleDir;
|
||||||
|
@override
|
||||||
|
final AppVersionData? networkVersionData;
|
||||||
|
@override
|
||||||
|
@JsonKey()
|
||||||
|
final ThemeConf themeConf;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'AppGlobalState(deviceUUID: $deviceUUID, applicationSupportDir: $applicationSupportDir, applicationBinaryModuleDir: $applicationBinaryModuleDir, networkVersionData: $networkVersionData, themeConf: $themeConf)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other.runtimeType == runtimeType &&
|
||||||
|
other is _$AppGlobalStateImpl &&
|
||||||
|
(identical(other.deviceUUID, deviceUUID) ||
|
||||||
|
other.deviceUUID == deviceUUID) &&
|
||||||
|
(identical(other.applicationSupportDir, applicationSupportDir) ||
|
||||||
|
other.applicationSupportDir == applicationSupportDir) &&
|
||||||
|
(identical(other.applicationBinaryModuleDir,
|
||||||
|
applicationBinaryModuleDir) ||
|
||||||
|
other.applicationBinaryModuleDir ==
|
||||||
|
applicationBinaryModuleDir) &&
|
||||||
|
(identical(other.networkVersionData, networkVersionData) ||
|
||||||
|
other.networkVersionData == networkVersionData) &&
|
||||||
|
(identical(other.themeConf, themeConf) ||
|
||||||
|
other.themeConf == themeConf));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(
|
||||||
|
runtimeType,
|
||||||
|
deviceUUID,
|
||||||
|
applicationSupportDir,
|
||||||
|
applicationBinaryModuleDir,
|
||||||
|
networkVersionData,
|
||||||
|
themeConf);
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
@override
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
_$$AppGlobalStateImplCopyWith<_$AppGlobalStateImpl> get copyWith =>
|
||||||
|
__$$AppGlobalStateImplCopyWithImpl<_$AppGlobalStateImpl>(
|
||||||
|
this, _$identity);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _AppGlobalState implements AppGlobalState {
|
||||||
|
const factory _AppGlobalState(
|
||||||
|
{final String? deviceUUID,
|
||||||
|
final String? applicationSupportDir,
|
||||||
|
final String? applicationBinaryModuleDir,
|
||||||
|
final AppVersionData? networkVersionData,
|
||||||
|
final ThemeConf themeConf}) = _$AppGlobalStateImpl;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get deviceUUID;
|
||||||
|
@override
|
||||||
|
String? get applicationSupportDir;
|
||||||
|
@override
|
||||||
|
String? get applicationBinaryModuleDir;
|
||||||
|
@override
|
||||||
|
AppVersionData? get networkVersionData;
|
||||||
|
@override
|
||||||
|
ThemeConf get themeConf;
|
||||||
|
@override
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
_$$AppGlobalStateImplCopyWith<_$AppGlobalStateImpl> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
mixin _$ThemeConf {
|
||||||
|
Color get backgroundColor => throw _privateConstructorUsedError;
|
||||||
|
Color get menuColor => throw _privateConstructorUsedError;
|
||||||
|
Color get micaColor => throw _privateConstructorUsedError;
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
$ThemeConfCopyWith<ThemeConf> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class $ThemeConfCopyWith<$Res> {
|
||||||
|
factory $ThemeConfCopyWith(ThemeConf value, $Res Function(ThemeConf) then) =
|
||||||
|
_$ThemeConfCopyWithImpl<$Res, ThemeConf>;
|
||||||
|
@useResult
|
||||||
|
$Res call({Color backgroundColor, Color menuColor, Color micaColor});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class _$ThemeConfCopyWithImpl<$Res, $Val extends ThemeConf>
|
||||||
|
implements $ThemeConfCopyWith<$Res> {
|
||||||
|
_$ThemeConfCopyWithImpl(this._value, this._then);
|
||||||
|
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Val _value;
|
||||||
|
// ignore: unused_field
|
||||||
|
final $Res Function($Val) _then;
|
||||||
|
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? backgroundColor = null,
|
||||||
|
Object? menuColor = null,
|
||||||
|
Object? micaColor = null,
|
||||||
|
}) {
|
||||||
|
return _then(_value.copyWith(
|
||||||
|
backgroundColor: null == backgroundColor
|
||||||
|
? _value.backgroundColor
|
||||||
|
: backgroundColor // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Color,
|
||||||
|
menuColor: null == menuColor
|
||||||
|
? _value.menuColor
|
||||||
|
: menuColor // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Color,
|
||||||
|
micaColor: null == micaColor
|
||||||
|
? _value.micaColor
|
||||||
|
: micaColor // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Color,
|
||||||
|
) as $Val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
abstract class _$$ThemeConfImplCopyWith<$Res>
|
||||||
|
implements $ThemeConfCopyWith<$Res> {
|
||||||
|
factory _$$ThemeConfImplCopyWith(
|
||||||
|
_$ThemeConfImpl value, $Res Function(_$ThemeConfImpl) then) =
|
||||||
|
__$$ThemeConfImplCopyWithImpl<$Res>;
|
||||||
|
@override
|
||||||
|
@useResult
|
||||||
|
$Res call({Color backgroundColor, Color menuColor, Color micaColor});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
class __$$ThemeConfImplCopyWithImpl<$Res>
|
||||||
|
extends _$ThemeConfCopyWithImpl<$Res, _$ThemeConfImpl>
|
||||||
|
implements _$$ThemeConfImplCopyWith<$Res> {
|
||||||
|
__$$ThemeConfImplCopyWithImpl(
|
||||||
|
_$ThemeConfImpl _value, $Res Function(_$ThemeConfImpl) _then)
|
||||||
|
: super(_value, _then);
|
||||||
|
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
@override
|
||||||
|
$Res call({
|
||||||
|
Object? backgroundColor = null,
|
||||||
|
Object? menuColor = null,
|
||||||
|
Object? micaColor = null,
|
||||||
|
}) {
|
||||||
|
return _then(_$ThemeConfImpl(
|
||||||
|
backgroundColor: null == backgroundColor
|
||||||
|
? _value.backgroundColor
|
||||||
|
: backgroundColor // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Color,
|
||||||
|
menuColor: null == menuColor
|
||||||
|
? _value.menuColor
|
||||||
|
: menuColor // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Color,
|
||||||
|
micaColor: null == micaColor
|
||||||
|
? _value.micaColor
|
||||||
|
: micaColor // ignore: cast_nullable_to_non_nullable
|
||||||
|
as Color,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @nodoc
|
||||||
|
|
||||||
|
class _$ThemeConfImpl implements _ThemeConf {
|
||||||
|
const _$ThemeConfImpl(
|
||||||
|
{this.backgroundColor = const Color(0xbf132431),
|
||||||
|
this.menuColor = const Color(0xf2132431),
|
||||||
|
this.micaColor = const Color(0xff0a3142)});
|
||||||
|
|
||||||
|
@override
|
||||||
|
@JsonKey()
|
||||||
|
final Color backgroundColor;
|
||||||
|
@override
|
||||||
|
@JsonKey()
|
||||||
|
final Color menuColor;
|
||||||
|
@override
|
||||||
|
@JsonKey()
|
||||||
|
final Color micaColor;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ThemeConf(backgroundColor: $backgroundColor, menuColor: $menuColor, micaColor: $micaColor)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
return identical(this, other) ||
|
||||||
|
(other.runtimeType == runtimeType &&
|
||||||
|
other is _$ThemeConfImpl &&
|
||||||
|
(identical(other.backgroundColor, backgroundColor) ||
|
||||||
|
other.backgroundColor == backgroundColor) &&
|
||||||
|
(identical(other.menuColor, menuColor) ||
|
||||||
|
other.menuColor == menuColor) &&
|
||||||
|
(identical(other.micaColor, micaColor) ||
|
||||||
|
other.micaColor == micaColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
Object.hash(runtimeType, backgroundColor, menuColor, micaColor);
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
@override
|
||||||
|
@pragma('vm:prefer-inline')
|
||||||
|
_$$ThemeConfImplCopyWith<_$ThemeConfImpl> get copyWith =>
|
||||||
|
__$$ThemeConfImplCopyWithImpl<_$ThemeConfImpl>(this, _$identity);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _ThemeConf implements ThemeConf {
|
||||||
|
const factory _ThemeConf(
|
||||||
|
{final Color backgroundColor,
|
||||||
|
final Color menuColor,
|
||||||
|
final Color micaColor}) = _$ThemeConfImpl;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Color get backgroundColor;
|
||||||
|
@override
|
||||||
|
Color get menuColor;
|
||||||
|
@override
|
||||||
|
Color get micaColor;
|
||||||
|
@override
|
||||||
|
@JsonKey(ignore: true)
|
||||||
|
_$$ThemeConfImplCopyWith<_$ThemeConfImpl> get copyWith =>
|
||||||
|
throw _privateConstructorUsedError;
|
||||||
|
}
|
40
lib/app.g.dart
Normal file
40
lib/app.g.dart
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'app.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// RiverpodGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
String _$routerHash() => r'df314e6867c385ecf4f18f2cf485c7517bec9154';
|
||||||
|
|
||||||
|
/// See also [router].
|
||||||
|
@ProviderFor(router)
|
||||||
|
final routerProvider = AutoDisposeProvider<GoRouter>.internal(
|
||||||
|
router,
|
||||||
|
name: r'routerProvider',
|
||||||
|
debugGetCreateSourceHash:
|
||||||
|
const bool.fromEnvironment('dart.vm.product') ? null : _$routerHash,
|
||||||
|
dependencies: null,
|
||||||
|
allTransitiveDependencies: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef RouterRef = AutoDisposeProviderRef<GoRouter>;
|
||||||
|
String _$appGlobalModelHash() => r'1b454a5c8a776aa12a4f953b59b9670d8337840f';
|
||||||
|
|
||||||
|
/// See also [AppGlobalModel].
|
||||||
|
@ProviderFor(AppGlobalModel)
|
||||||
|
final appGlobalModelProvider =
|
||||||
|
AutoDisposeNotifierProvider<AppGlobalModel, AppGlobalState>.internal(
|
||||||
|
AppGlobalModel.new,
|
||||||
|
name: r'appGlobalModelProvider',
|
||||||
|
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||||
|
? null
|
||||||
|
: _$appGlobalModelHash,
|
||||||
|
dependencies: null,
|
||||||
|
allTransitiveDependencies: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef _$AppGlobalModel = AutoDisposeNotifier<AppGlobalState>;
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
187
lib/base/ui.dart
187
lib/base/ui.dart
@ -1,187 +0,0 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:starcitizen_doctor/main.dart';
|
|
||||||
import 'package:starcitizen_doctor/widgets/my_page_route.dart';
|
|
||||||
import 'package:window_manager/window_manager.dart';
|
|
||||||
import '../common/utils/log.dart' as log_utils;
|
|
||||||
|
|
||||||
import 'dart:ui' as ui;
|
|
||||||
|
|
||||||
import 'ui_model.dart';
|
|
||||||
|
|
||||||
export '../common/utils/base_utils.dart';
|
|
||||||
export '../widgets/widgets.dart';
|
|
||||||
export 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
|
|
||||||
class BaseUIContainer extends ConsumerStatefulWidget {
|
|
||||||
final ConsumerState<BaseUIContainer> Function() uiCreate;
|
|
||||||
final dynamic Function() modelCreate;
|
|
||||||
|
|
||||||
const BaseUIContainer(
|
|
||||||
{super.key, required this.uiCreate, required this.modelCreate});
|
|
||||||
|
|
||||||
@override
|
|
||||||
// ignore: no_logic_in_create_state
|
|
||||||
ConsumerState<BaseUIContainer> createState() => uiCreate();
|
|
||||||
|
|
||||||
Future push(BuildContext context) {
|
|
||||||
return Navigator.push(context, makeRoute(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Future pushShowModalBottomSheet(BuildContext context) {
|
|
||||||
// return showModalBottomSheet(
|
|
||||||
// context: context,
|
|
||||||
// isScrollControlled: true,
|
|
||||||
// builder: (BuildContext context) {
|
|
||||||
// return this;
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// 获取路由
|
|
||||||
FluentPageRoute makeRoute(BuildContext context) {
|
|
||||||
return MyPageRoute(
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Future pushAndRemoveUntil(BuildContext context) {
|
|
||||||
// return Navigator.pushAndRemoveUntil(context,
|
|
||||||
// MaterialPageRoute(builder: (BuildContext context) {
|
|
||||||
// return this;
|
|
||||||
// }), (_) => false);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class BaseUI<T extends BaseUIModel>
|
|
||||||
extends ConsumerState<BaseUIContainer> {
|
|
||||||
BaseUIModel? _needDisposeModel;
|
|
||||||
late final ChangeNotifierProvider<T> provider = bindUIModel();
|
|
||||||
|
|
||||||
// final GlobalKey<ScaffoldState> scaffoldState = GlobalKey();
|
|
||||||
// RefreshController? refreshController;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
// get model
|
|
||||||
final model = ref.watch(provider);
|
|
||||||
return buildBody(context, model)!;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getUITitle(BuildContext context, T model);
|
|
||||||
|
|
||||||
Widget? buildBody(
|
|
||||||
BuildContext context,
|
|
||||||
T model,
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget? getBottomNavigationBar(BuildContext context, T model) => null;
|
|
||||||
|
|
||||||
Color? getBackgroundColor(BuildContext context, T model) => null;
|
|
||||||
|
|
||||||
Widget? getFloatingActionButton(BuildContext context, T model) => null;
|
|
||||||
|
|
||||||
bool getDrawerEnableOpenDragGesture(BuildContext context, T model) => true;
|
|
||||||
|
|
||||||
Widget? getDrawer(BuildContext context, T model) => null;
|
|
||||||
|
|
||||||
Widget makeDefaultPage(BuildContext context, T model,
|
|
||||||
{Widget? titleRow,
|
|
||||||
List<Widget>? actions,
|
|
||||||
Widget? content,
|
|
||||||
bool automaticallyImplyLeading = true}) {
|
|
||||||
return NavigationView(
|
|
||||||
pane: NavigationPane(
|
|
||||||
size: const NavigationPaneSize(openWidth: 0),
|
|
||||||
),
|
|
||||||
appBar: NavigationAppBar(
|
|
||||||
automaticallyImplyLeading: automaticallyImplyLeading,
|
|
||||||
title: DragToMoveArea(
|
|
||||||
child: titleRow ??
|
|
||||||
Column(children: [Expanded(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Text(getUITitle(context, model)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)],),
|
|
||||||
),
|
|
||||||
actions: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
children: [...?actions, const WindowButtons()],
|
|
||||||
)),
|
|
||||||
paneBodyBuilder: (
|
|
||||||
PaneItem? item,
|
|
||||||
Widget? body,
|
|
||||||
) {
|
|
||||||
return SizedBox(
|
|
||||||
height: MediaQuery.of(context).size.height,
|
|
||||||
child: content ?? makeLoading(context),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@mustCallSuper
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
dPrint("[base] <$runtimeType> UI Init");
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@mustCallSuper
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
dPrint("[base] <$runtimeType> UI Disposed");
|
|
||||||
_needDisposeModel?.dispose();
|
|
||||||
_needDisposeModel = null;
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 关闭键盘
|
|
||||||
dismissKeyBoard() {
|
|
||||||
FocusManager.instance.primaryFocus?.unfocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// void updateStatusBarIconColor(BuildContext context) {
|
|
||||||
// SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
||||||
// statusBarBrightness: Theme.of(context).brightness,
|
|
||||||
// statusBarIconBrightness: getAndroidIconBrightness(context),
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
ChangeNotifierProvider<T> bindUIModel() {
|
|
||||||
final createdModel = widget.modelCreate();
|
|
||||||
if (createdModel is T) {
|
|
||||||
_needDisposeModel = createdModel;
|
|
||||||
return ChangeNotifierProvider<T>((ref) {
|
|
||||||
return createdModel..context = context;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return createdModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Widget pullToRefreshBody(
|
|
||||||
// {required BaseUIModel model, required Widget child}) {
|
|
||||||
// refreshController ??= RefreshController();
|
|
||||||
// return AppSmartRefresher(
|
|
||||||
// enablePullUp: false,
|
|
||||||
// controller: refreshController,
|
|
||||||
// onRefresh: () async {
|
|
||||||
// await model.reloadData();
|
|
||||||
// refreshController?.refreshCompleted();
|
|
||||||
// },
|
|
||||||
// child: child,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
makeSvgColor(Color color, {BlendMode blendMode = BlendMode.color}) {
|
|
||||||
return ui.ColorFilter.mode(color, blendMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
dPrint(src) {
|
|
||||||
log_utils.dPrint("<$runtimeType> $src");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,141 +0,0 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:grpc/grpc.dart';
|
|
||||||
|
|
||||||
import 'ui.dart';
|
|
||||||
import '../common/utils/log.dart' as log_utils;
|
|
||||||
|
|
||||||
export '../common/utils/base_utils.dart';
|
|
||||||
export 'ui.dart';
|
|
||||||
|
|
||||||
class BaseUIModel extends ChangeNotifier {
|
|
||||||
String uiErrorMsg = "";
|
|
||||||
bool _isDisposed = false;
|
|
||||||
|
|
||||||
bool get mounted => !_isDisposed;
|
|
||||||
|
|
||||||
BuildContext? context;
|
|
||||||
|
|
||||||
BaseUIModel() {
|
|
||||||
initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@mustCallSuper
|
|
||||||
void initModel() {
|
|
||||||
dPrint("[base] <$runtimeType> Model Init");
|
|
||||||
loadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@mustCallSuper
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_isDisposed = true;
|
|
||||||
_childUIModels?.forEach((k, value) {
|
|
||||||
(value as BaseUIModel).dispose();
|
|
||||||
_childUIModels?[k] = null;
|
|
||||||
});
|
|
||||||
dPrint("[base] <$runtimeType> Model Disposed");
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future loadData() async {}
|
|
||||||
|
|
||||||
Future reloadData() async {
|
|
||||||
return loadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future onErrorReloadData() async {
|
|
||||||
return loadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void notifyListeners() {
|
|
||||||
if (!mounted) return;
|
|
||||||
super.notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<T?> handleError<T>(Future<T> Function() requestFunc,
|
|
||||||
{bool showFullScreenError = false,
|
|
||||||
String? errorOverride,
|
|
||||||
bool noAlert = false}) async {
|
|
||||||
uiErrorMsg = "";
|
|
||||||
if (mounted) notifyListeners();
|
|
||||||
try {
|
|
||||||
return await requestFunc();
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("$runtimeType.handleError Error:$e");
|
|
||||||
String errorMsg = "Unknown Error";
|
|
||||||
if (e is GrpcError) {
|
|
||||||
errorMsg = "远程服务器消息: ${e.message ?? "Unknown Error"}";
|
|
||||||
} else {
|
|
||||||
errorMsg = e.toString();
|
|
||||||
}
|
|
||||||
if (showFullScreenError) {
|
|
||||||
uiErrorMsg = errorMsg;
|
|
||||||
notifyListeners();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!noAlert) {
|
|
||||||
showToast(context!, errorOverride ?? errorMsg,
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context!).size.width * .6,
|
|
||||||
),
|
|
||||||
title: "出现错误!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<dynamic, dynamic>? _childUIModels;
|
|
||||||
Map<dynamic, dynamic>? _childUIProviders;
|
|
||||||
|
|
||||||
BaseUIModel? onCreateChildUIModel(modelKey) => null;
|
|
||||||
|
|
||||||
dynamic _getChildUIModel(modelKey) {
|
|
||||||
_childUIModels ??= {};
|
|
||||||
final cachedModel = _childUIModels![modelKey];
|
|
||||||
if (cachedModel != null) {
|
|
||||||
return (cachedModel);
|
|
||||||
}
|
|
||||||
final newModel = onCreateChildUIModel(modelKey);
|
|
||||||
_childUIModels![modelKey] = newModel!;
|
|
||||||
return newModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChangeNotifierProvider<M> getChildUIModelProviders<M extends BaseUIModel>(
|
|
||||||
modelKey) {
|
|
||||||
_childUIProviders ??= {};
|
|
||||||
if (_childUIProviders![modelKey] == null) {
|
|
||||||
_childUIProviders![modelKey] = ChangeNotifierProvider<M>((ref) {
|
|
||||||
final c = (_getChildUIModel(modelKey) as M);
|
|
||||||
return c..context = context;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return _childUIProviders![modelKey]!;
|
|
||||||
}
|
|
||||||
|
|
||||||
T? getCreatedChildUIModel<T extends BaseUIModel>(String modelKey,
|
|
||||||
{bool create = false}) {
|
|
||||||
if (create && _childUIModels?[modelKey] == null) {
|
|
||||||
_getChildUIModel(modelKey);
|
|
||||||
}
|
|
||||||
return _childUIModels?[modelKey] as T?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> reloadAllChildModels() async {
|
|
||||||
if (_childUIModels == null) return;
|
|
||||||
final futureList = <Future>[];
|
|
||||||
for (var value in _childUIModels!.entries) {
|
|
||||||
futureList.add(value.value.reloadData());
|
|
||||||
}
|
|
||||||
await Future.wait(futureList);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
dismissKeyBoard() {
|
|
||||||
FocusManager.instance.primaryFocus?.unfocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
dPrint(src) {
|
|
||||||
log_utils.dPrint("<$runtimeType> $src");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,145 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
|
||||||
import 'package:flutter_acrylic/flutter_acrylic.dart';
|
|
||||||
import 'package:hexcolor/hexcolor.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/rust/frb_generated.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/app_version_data.dart';
|
|
||||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:uuid/uuid.dart';
|
|
||||||
import 'package:window_manager/window_manager.dart';
|
|
||||||
|
|
||||||
class AppConf {
|
|
||||||
static const String appVersion = "2.10.7 Beta";
|
|
||||||
static const int appVersionCode = 42;
|
|
||||||
static const String appVersionDate = "2024-03-01";
|
|
||||||
|
|
||||||
static const gameChannels = ["LIVE", "PTU", "EPTU"];
|
|
||||||
|
|
||||||
static String deviceUUID = "";
|
|
||||||
|
|
||||||
static late final String applicationSupportDir;
|
|
||||||
|
|
||||||
static late final String applicationBinaryModuleDir;
|
|
||||||
|
|
||||||
static File? appLogFile;
|
|
||||||
|
|
||||||
static AppVersionData? networkVersionData;
|
|
||||||
|
|
||||||
static bool offlineMode = false;
|
|
||||||
|
|
||||||
static late final WindowsDeviceInfo windowsDeviceInfo;
|
|
||||||
|
|
||||||
static Color? colorBackground;
|
|
||||||
static Color? colorMenu;
|
|
||||||
static Color? colorMica;
|
|
||||||
|
|
||||||
static const isMSE =
|
|
||||||
String.fromEnvironment("MSE", defaultValue: "false") == "true";
|
|
||||||
|
|
||||||
static init(List<String> args) async {
|
|
||||||
dPrint("launch args == $args");
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
|
|
||||||
/// init device info
|
|
||||||
try {
|
|
||||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
||||||
windowsDeviceInfo = await deviceInfo.windowsInfo;
|
|
||||||
} catch (_) {}
|
|
||||||
|
|
||||||
/// init Data
|
|
||||||
final userProfileDir = Platform.environment["USERPROFILE"];
|
|
||||||
applicationSupportDir =
|
|
||||||
(await getApplicationSupportDirectory()).absolute.path;
|
|
||||||
final logFile = File(
|
|
||||||
"$applicationSupportDir\\logs\\${DateTime.now().millisecondsSinceEpoch}.log");
|
|
||||||
await logFile.create(recursive: true);
|
|
||||||
appLogFile = logFile;
|
|
||||||
if (AppConf.isMSE && userProfileDir != null) {
|
|
||||||
applicationBinaryModuleDir =
|
|
||||||
"$userProfileDir\\AppData\\Local\\Temp\\SCToolbox\\modules";
|
|
||||||
} else {
|
|
||||||
applicationBinaryModuleDir = "$applicationSupportDir\\modules";
|
|
||||||
}
|
|
||||||
dPrint("applicationSupportDir == $applicationSupportDir");
|
|
||||||
dPrint("applicationBinaryModuleDir == $applicationBinaryModuleDir");
|
|
||||||
try {
|
|
||||||
Hive.init("$applicationSupportDir/db");
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
if (box.get("install_id", defaultValue: "") == "") {
|
|
||||||
await box.put("install_id", const Uuid().v4());
|
|
||||||
AnalyticsApi.touch("firstLaunch");
|
|
||||||
}
|
|
||||||
deviceUUID = box.get("install_id", defaultValue: "");
|
|
||||||
} catch (e) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// check Rust bridge
|
|
||||||
await RustLib.init();
|
|
||||||
await RSHttp.init();
|
|
||||||
dPrint("---- rust bridge inited -----");
|
|
||||||
await SystemHelper.initPowershellPath();
|
|
||||||
|
|
||||||
/// init defaultColor
|
|
||||||
colorBackground = HexColor("#132431").withOpacity(.75);
|
|
||||||
colorMenu = HexColor("#132431").withOpacity(.95);
|
|
||||||
colorMica = HexColor("#0A3142");
|
|
||||||
|
|
||||||
/// init windows
|
|
||||||
await windowManager.ensureInitialized();
|
|
||||||
windowManager.waitUntilReadyToShow().then((_) async {
|
|
||||||
await windowManager.setSize(const Size(1280, 810));
|
|
||||||
await windowManager.setMinimumSize(const Size(1280, 810));
|
|
||||||
await windowManager.center(animate: true);
|
|
||||||
await windowManager.setSkipTaskbar(false);
|
|
||||||
await windowManager.setTitleBarStyle(
|
|
||||||
TitleBarStyle.hidden,
|
|
||||||
windowButtonVisibility: false,
|
|
||||||
);
|
|
||||||
await windowManager.show();
|
|
||||||
await Window.initialize();
|
|
||||||
await Window.hideWindowControls();
|
|
||||||
if (windowsDeviceInfo.productName.contains("Windows 11")) {
|
|
||||||
await Window.setEffect(
|
|
||||||
effect: WindowEffect.acrylic,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static String getUpgradePath() {
|
|
||||||
return "${AppConf.applicationSupportDir}/._upgrade";
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> checkUpdate() async {
|
|
||||||
// clean path
|
|
||||||
if (!isMSE) {
|
|
||||||
final dir = Directory(getUpgradePath());
|
|
||||||
if (await dir.exists()) {
|
|
||||||
dir.delete(recursive: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
networkVersionData = await Api.getAppVersion();
|
|
||||||
globalUIModel.checkActivityThemeColor();
|
|
||||||
if (isMSE) {
|
|
||||||
dPrint(
|
|
||||||
"lastVersion=${networkVersionData?.mSELastVersion} ${networkVersionData?.mSELastVersionCode}");
|
|
||||||
} else {
|
|
||||||
dPrint(
|
|
||||||
"lastVersion=${networkVersionData?.lastVersion} ${networkVersionData?.lastVersionCode}");
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("_checkUpdate Error:$e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:archive/archive.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
|
||||||
|
|
||||||
class BinaryModuleConf {
|
|
||||||
static const _modules = {
|
|
||||||
"aria2c": "0",
|
|
||||||
};
|
|
||||||
|
|
||||||
static Future extractModule(List<String> modules) async {
|
|
||||||
final workingDir = AppConf.applicationBinaryModuleDir;
|
|
||||||
for (var m in _modules.entries) {
|
|
||||||
if (!modules.contains(m.key)) continue;
|
|
||||||
final name = m.key;
|
|
||||||
final version = m.value;
|
|
||||||
final dir = "$workingDir\\$name";
|
|
||||||
final versionFile = File("$dir\\version");
|
|
||||||
if (await versionFile.exists() &&
|
|
||||||
(await versionFile.readAsString()).trim() == version) {
|
|
||||||
dPrint(
|
|
||||||
"BinaryModuleConf.extractModule skip $name version == $version");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// write model file
|
|
||||||
final zipBuffer = await rootBundle.load("assets/binary/$name.zip");
|
|
||||||
final decoder = ZipDecoder().decodeBytes(zipBuffer.buffer.asUint8List());
|
|
||||||
for (var value in decoder.files) {
|
|
||||||
final filename = value.name;
|
|
||||||
if (value.isFile) {
|
|
||||||
final data = value.content as List<int>;
|
|
||||||
final file = File('$dir\\$filename');
|
|
||||||
await file.create(recursive: true);
|
|
||||||
await file.writeAsBytes(data);
|
|
||||||
} else {
|
|
||||||
await Directory('$dir\\$filename').create(recursive: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// write version file
|
|
||||||
await versionFile.writeAsString(version);
|
|
||||||
dPrint("BinaryModuleConf.extractModule $name $dir");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
8
lib/common/conf/const_conf.dart
Normal file
8
lib/common/conf/const_conf.dart
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class ConstConf {
|
||||||
|
static const String appVersion = "2.10.7 Beta";
|
||||||
|
static const int appVersionCode = 42;
|
||||||
|
static const String appVersionDate = "2024-03-01";
|
||||||
|
static const gameChannels = ["LIVE", "PTU", "EPTU"];
|
||||||
|
static const isMSE =
|
||||||
|
String.fromEnvironment("MSE", defaultValue: "false") == "true";
|
||||||
|
}
|
@ -1,48 +0,0 @@
|
|||||||
import 'package:fixnum/fixnum.dart';
|
|
||||||
import 'package:grpc/grpc.dart';
|
|
||||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pbgrpc.dart';
|
|
||||||
|
|
||||||
class PartyRoomGrpcServer {
|
|
||||||
static const clientVersion = 0;
|
|
||||||
static final _channel = ClientChannel(
|
|
||||||
"127.0.0.1",
|
|
||||||
port: 39399,
|
|
||||||
options: ChannelOptions(
|
|
||||||
credentials: const ChannelCredentials.insecure(),
|
|
||||||
codecRegistry:
|
|
||||||
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
static final _indexService = IndexServiceClient(_channel);
|
|
||||||
|
|
||||||
static Future<PingData> pingServer() async {
|
|
||||||
final r = await _indexService.pingServer(PingData(
|
|
||||||
data: "PING", clientVersion: Int64.parseInt(clientVersion.toString())));
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<RoomTypesData> getRoomTypes() async {
|
|
||||||
final r = await _indexService.getRoomTypes(Empty());
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<RoomListData> getRoomList(RoomListPageReqData req) async {
|
|
||||||
return await _indexService.getRoomList(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<RoomData> createRoom(RoomData roomData) async {
|
|
||||||
return await _indexService.createRoom(roomData);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<RoomData?> touchUserRoom(String userName, String deviceUUID) {
|
|
||||||
return _indexService
|
|
||||||
.touchUser(PreUser(userName: userName, deviceUUID: deviceUUID));
|
|
||||||
}
|
|
||||||
|
|
||||||
static ResponseStream<RoomUpdateMessage> joinRoom(
|
|
||||||
String roomID, String userName, String deviceUUID) {
|
|
||||||
return _indexService.joinRoom(
|
|
||||||
PreUser(roomID: roomID, userName: userName, deviceUUID: deviceUUID));
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,8 +5,6 @@ import 'package:aria2/aria2.dart';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
import 'package:starcitizen_doctor/api/api.dart';
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/binary_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||||
|
|
||||||
import 'package:starcitizen_doctor/common/rust/api/process_api.dart'
|
import 'package:starcitizen_doctor/common/rust/api/process_api.dart'
|
||||||
@ -16,8 +14,8 @@ import 'package:starcitizen_doctor/common/utils/log.dart';
|
|||||||
class Aria2cManager {
|
class Aria2cManager {
|
||||||
static bool _isDaemonRunning = false;
|
static bool _isDaemonRunning = false;
|
||||||
|
|
||||||
static final String _aria2cDir =
|
// static final String _aria2cDir = "${AppConf.applicationBinaryModuleDir}\\aria2c";
|
||||||
"${AppConf.applicationBinaryModuleDir}\\aria2c";
|
static final String _aria2cDir = "\\aria2c";
|
||||||
|
|
||||||
static Aria2c? _aria2c;
|
static Aria2c? _aria2c;
|
||||||
|
|
||||||
@ -43,7 +41,7 @@ class Aria2cManager {
|
|||||||
|
|
||||||
static Future launchDaemon() async {
|
static Future launchDaemon() async {
|
||||||
if (_isDaemonRunning) return;
|
if (_isDaemonRunning) return;
|
||||||
await BinaryModuleConf.extractModule(["aria2c"]);
|
// await BinaryModuleConf.extractModule(["aria2c"]);
|
||||||
|
|
||||||
/// skip for debug hot reload
|
/// skip for debug hot reload
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
import 'package:starcitizen_doctor/common/conf/const_conf.dart';
|
||||||
import 'package:starcitizen_doctor/common/rust/api/http_api.dart' as rust_http;
|
import 'package:starcitizen_doctor/common/rust/api/http_api.dart' as rust_http;
|
||||||
import 'package:starcitizen_doctor/common/rust/api/http_api.dart';
|
import 'package:starcitizen_doctor/common/rust/api/http_api.dart';
|
||||||
import 'package:starcitizen_doctor/common/rust/http_package.dart';
|
import 'package:starcitizen_doctor/common/rust/http_package.dart';
|
||||||
@ -10,7 +10,7 @@ class RSHttp {
|
|||||||
static init() async {
|
static init() async {
|
||||||
await rust_http.setDefaultHeader(headers: {
|
await rust_http.setDefaultHeader(headers: {
|
||||||
"User-Agent":
|
"User-Agent":
|
||||||
"SCToolBox/${AppConf.appVersion} (${AppConf.appVersionCode})${AppConf.isMSE ? "" : " DEV"} RSHttp"
|
"SCToolBox/${ConstConf.appVersion} (${ConstConf.appVersionCode})${ConstConf.isMSE ? "" : " DEV"} RSHttp"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,8 @@ import 'dart:io';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:synchronized/synchronized.dart';
|
import 'package:synchronized/synchronized.dart';
|
||||||
|
|
||||||
import '../conf/app_conf.dart';
|
|
||||||
|
|
||||||
var _logLock = Lock();
|
var _logLock = Lock();
|
||||||
|
File? _logFile;
|
||||||
|
|
||||||
void dPrint(src) async {
|
void dPrint(src) async {
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
@ -13,7 +12,11 @@ void dPrint(src) async {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await _logLock.synchronized(() async {
|
await _logLock.synchronized(() async {
|
||||||
await AppConf.appLogFile?.writeAsString("$src\n", mode: FileMode.append);
|
_logFile?.writeAsString("$src\n", mode: FileMode.append);
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDPrintFile(File file) {
|
||||||
|
_logFile = file;
|
||||||
|
}
|
||||||
|
@ -1,159 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: chat.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
|
|
||||||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
|
||||||
// ignore_for_file: constant_identifier_names, library_prefixes
|
|
||||||
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
|
||||||
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
|
||||||
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
|
|
||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
|
||||||
|
|
||||||
import 'chat.pbenum.dart';
|
|
||||||
|
|
||||||
export 'chat.pbenum.dart';
|
|
||||||
|
|
||||||
class ChatMessage extends $pb.GeneratedMessage {
|
|
||||||
factory ChatMessage({
|
|
||||||
$core.String? senderID,
|
|
||||||
$core.String? receiverID,
|
|
||||||
ReceiverType? receiverType,
|
|
||||||
MessageType? messageType,
|
|
||||||
$core.String? data,
|
|
||||||
}) {
|
|
||||||
final $result = create();
|
|
||||||
if (senderID != null) {
|
|
||||||
$result.senderID = senderID;
|
|
||||||
}
|
|
||||||
if (receiverID != null) {
|
|
||||||
$result.receiverID = receiverID;
|
|
||||||
}
|
|
||||||
if (receiverType != null) {
|
|
||||||
$result.receiverType = receiverType;
|
|
||||||
}
|
|
||||||
if (messageType != null) {
|
|
||||||
$result.messageType = messageType;
|
|
||||||
}
|
|
||||||
if (data != null) {
|
|
||||||
$result.data = data;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
ChatMessage._() : super();
|
|
||||||
factory ChatMessage.fromBuffer($core.List<$core.int> i,
|
|
||||||
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
|
||||||
create()..mergeFromBuffer(i, r);
|
|
||||||
factory ChatMessage.fromJson($core.String i,
|
|
||||||
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
|
|
||||||
create()..mergeFromJson(i, r);
|
|
||||||
|
|
||||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
|
|
||||||
_omitMessageNames ? '' : 'ChatMessage',
|
|
||||||
createEmptyInstance: create)
|
|
||||||
..aOS(1, _omitFieldNames ? '' : 'senderID', protoName: 'senderID')
|
|
||||||
..aOS(2, _omitFieldNames ? '' : 'receiverID', protoName: 'receiverID')
|
|
||||||
..e<ReceiverType>(
|
|
||||||
3, _omitFieldNames ? '' : 'receiverType', $pb.PbFieldType.OE,
|
|
||||||
protoName: 'receiverType',
|
|
||||||
defaultOrMaker: ReceiverType.RoomMsg,
|
|
||||||
valueOf: ReceiverType.valueOf,
|
|
||||||
enumValues: ReceiverType.values)
|
|
||||||
..e<MessageType>(
|
|
||||||
4, _omitFieldNames ? '' : 'messageType', $pb.PbFieldType.OE,
|
|
||||||
protoName: 'messageType',
|
|
||||||
defaultOrMaker: MessageType.System,
|
|
||||||
valueOf: MessageType.valueOf,
|
|
||||||
enumValues: MessageType.values)
|
|
||||||
..aOS(5, _omitFieldNames ? '' : 'data')
|
|
||||||
..hasRequiredFields = false;
|
|
||||||
|
|
||||||
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
|
||||||
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
|
||||||
'Will be removed in next major version')
|
|
||||||
ChatMessage clone() => ChatMessage()..mergeFromMessage(this);
|
|
||||||
@$core.Deprecated('Using this can add significant overhead to your binary. '
|
|
||||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
|
||||||
'Will be removed in next major version')
|
|
||||||
ChatMessage copyWith(void Function(ChatMessage) updates) =>
|
|
||||||
super.copyWith((message) => updates(message as ChatMessage))
|
|
||||||
as ChatMessage;
|
|
||||||
|
|
||||||
$pb.BuilderInfo get info_ => _i;
|
|
||||||
|
|
||||||
@$core.pragma('dart2js:noInline')
|
|
||||||
static ChatMessage create() => ChatMessage._();
|
|
||||||
ChatMessage createEmptyInstance() => create();
|
|
||||||
static $pb.PbList<ChatMessage> createRepeated() => $pb.PbList<ChatMessage>();
|
|
||||||
@$core.pragma('dart2js:noInline')
|
|
||||||
static ChatMessage getDefault() => _defaultInstance ??=
|
|
||||||
$pb.GeneratedMessage.$_defaultFor<ChatMessage>(create);
|
|
||||||
static ChatMessage? _defaultInstance;
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
$core.String get senderID => $_getSZ(0);
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
set senderID($core.String v) {
|
|
||||||
$_setString(0, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
$core.bool hasSenderID() => $_has(0);
|
|
||||||
@$pb.TagNumber(1)
|
|
||||||
void clearSenderID() => clearField(1);
|
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
$core.String get receiverID => $_getSZ(1);
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
set receiverID($core.String v) {
|
|
||||||
$_setString(1, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
$core.bool hasReceiverID() => $_has(1);
|
|
||||||
@$pb.TagNumber(2)
|
|
||||||
void clearReceiverID() => clearField(2);
|
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
ReceiverType get receiverType => $_getN(2);
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
set receiverType(ReceiverType v) {
|
|
||||||
setField(3, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
$core.bool hasReceiverType() => $_has(2);
|
|
||||||
@$pb.TagNumber(3)
|
|
||||||
void clearReceiverType() => clearField(3);
|
|
||||||
|
|
||||||
@$pb.TagNumber(4)
|
|
||||||
MessageType get messageType => $_getN(3);
|
|
||||||
@$pb.TagNumber(4)
|
|
||||||
set messageType(MessageType v) {
|
|
||||||
setField(4, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(4)
|
|
||||||
$core.bool hasMessageType() => $_has(3);
|
|
||||||
@$pb.TagNumber(4)
|
|
||||||
void clearMessageType() => clearField(4);
|
|
||||||
|
|
||||||
@$pb.TagNumber(5)
|
|
||||||
$core.String get data => $_getSZ(4);
|
|
||||||
@$pb.TagNumber(5)
|
|
||||||
set data($core.String v) {
|
|
||||||
$_setString(4, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.TagNumber(5)
|
|
||||||
$core.bool hasData() => $_has(4);
|
|
||||||
@$pb.TagNumber(5)
|
|
||||||
void clearData() => clearField(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names');
|
|
||||||
const _omitMessageNames =
|
|
||||||
$core.bool.fromEnvironment('protobuf.omit_message_names');
|
|
@ -1,58 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: chat.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
|
|
||||||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
|
||||||
// ignore_for_file: constant_identifier_names, library_prefixes
|
|
||||||
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
|
||||||
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
|
||||||
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
|
|
||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
|
||||||
|
|
||||||
class ReceiverType extends $pb.ProtobufEnum {
|
|
||||||
static const ReceiverType RoomMsg =
|
|
||||||
ReceiverType._(0, _omitEnumNames ? '' : 'RoomMsg');
|
|
||||||
static const ReceiverType PrivateMsg =
|
|
||||||
ReceiverType._(1, _omitEnumNames ? '' : 'PrivateMsg');
|
|
||||||
|
|
||||||
static const $core.List<ReceiverType> values = <ReceiverType>[
|
|
||||||
RoomMsg,
|
|
||||||
PrivateMsg,
|
|
||||||
];
|
|
||||||
|
|
||||||
static final $core.Map<$core.int, ReceiverType> _byValue =
|
|
||||||
$pb.ProtobufEnum.initByValue(values);
|
|
||||||
static ReceiverType? valueOf($core.int value) => _byValue[value];
|
|
||||||
|
|
||||||
const ReceiverType._($core.int v, $core.String n) : super(v, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
class MessageType extends $pb.ProtobufEnum {
|
|
||||||
static const MessageType System =
|
|
||||||
MessageType._(0, _omitEnumNames ? '' : 'System');
|
|
||||||
static const MessageType Text =
|
|
||||||
MessageType._(1, _omitEnumNames ? '' : 'Text');
|
|
||||||
static const MessageType Image =
|
|
||||||
MessageType._(2, _omitEnumNames ? '' : 'Image');
|
|
||||||
static const MessageType Markdown =
|
|
||||||
MessageType._(3, _omitEnumNames ? '' : 'Markdown');
|
|
||||||
|
|
||||||
static const $core.List<MessageType> values = <MessageType>[
|
|
||||||
System,
|
|
||||||
Text,
|
|
||||||
Image,
|
|
||||||
Markdown,
|
|
||||||
];
|
|
||||||
|
|
||||||
static final $core.Map<$core.int, MessageType> _byValue =
|
|
||||||
$pb.ProtobufEnum.initByValue(values);
|
|
||||||
static MessageType? valueOf($core.int value) => _byValue[value];
|
|
||||||
|
|
||||||
const MessageType._($core.int v, $core.String n) : super(v, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names');
|
|
@ -1,88 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: chat.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
|
|
||||||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
|
||||||
// ignore_for_file: constant_identifier_names, library_prefixes
|
|
||||||
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
|
||||||
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
|
||||||
|
|
||||||
import 'dart:async' as $async;
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
|
|
||||||
import 'package:grpc/service_api.dart' as $grpc;
|
|
||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
|
||||||
|
|
||||||
import 'chat.pb.dart' as $1;
|
|
||||||
import 'index.pb.dart' as $0;
|
|
||||||
|
|
||||||
export 'chat.pb.dart';
|
|
||||||
|
|
||||||
@$pb.GrpcServiceName('ChatService')
|
|
||||||
class ChatServiceClient extends $grpc.Client {
|
|
||||||
static final _$listenMessage = $grpc.ClientMethod<$0.PreUser, $1.ChatMessage>(
|
|
||||||
'/ChatService/ListenMessage',
|
|
||||||
($0.PreUser value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $1.ChatMessage.fromBuffer(value));
|
|
||||||
static final _$sendMessage =
|
|
||||||
$grpc.ClientMethod<$1.ChatMessage, $0.BaseRespData>(
|
|
||||||
'/ChatService/SendMessage',
|
|
||||||
($1.ChatMessage value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $0.BaseRespData.fromBuffer(value));
|
|
||||||
|
|
||||||
ChatServiceClient($grpc.ClientChannel channel,
|
|
||||||
{$grpc.CallOptions? options,
|
|
||||||
$core.Iterable<$grpc.ClientInterceptor>? interceptors})
|
|
||||||
: super(channel, options: options, interceptors: interceptors);
|
|
||||||
|
|
||||||
$grpc.ResponseStream<$1.ChatMessage> listenMessage($0.PreUser request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createStreamingCall(
|
|
||||||
_$listenMessage, $async.Stream.fromIterable([request]),
|
|
||||||
options: options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grpc.ResponseFuture<$0.BaseRespData> sendMessage($1.ChatMessage request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createUnaryCall(_$sendMessage, request, options: options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.GrpcServiceName('ChatService')
|
|
||||||
abstract class ChatServiceBase extends $grpc.Service {
|
|
||||||
$core.String get $name => 'ChatService';
|
|
||||||
|
|
||||||
ChatServiceBase() {
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.PreUser, $1.ChatMessage>(
|
|
||||||
'ListenMessage',
|
|
||||||
listenMessage_Pre,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
($core.List<$core.int> value) => $0.PreUser.fromBuffer(value),
|
|
||||||
($1.ChatMessage value) => value.writeToBuffer()));
|
|
||||||
$addMethod($grpc.ServiceMethod<$1.ChatMessage, $0.BaseRespData>(
|
|
||||||
'SendMessage',
|
|
||||||
sendMessage_Pre,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
($core.List<$core.int> value) => $1.ChatMessage.fromBuffer(value),
|
|
||||||
($0.BaseRespData value) => value.writeToBuffer()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Stream<$1.ChatMessage> listenMessage_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$0.PreUser> request) async* {
|
|
||||||
yield* listenMessage(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.BaseRespData> sendMessage_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$1.ChatMessage> request) async {
|
|
||||||
return sendMessage(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Stream<$1.ChatMessage> listenMessage(
|
|
||||||
$grpc.ServiceCall call, $0.PreUser request);
|
|
||||||
$async.Future<$0.BaseRespData> sendMessage(
|
|
||||||
$grpc.ServiceCall call, $1.ChatMessage request);
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: chat.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
|
|
||||||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
|
||||||
// ignore_for_file: constant_identifier_names, library_prefixes
|
|
||||||
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
|
||||||
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
|
||||||
|
|
||||||
import 'dart:convert' as $convert;
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
import 'dart:typed_data' as $typed_data;
|
|
||||||
|
|
||||||
@$core.Deprecated('Use receiverTypeDescriptor instead')
|
|
||||||
const ReceiverType$json = {
|
|
||||||
'1': 'ReceiverType',
|
|
||||||
'2': [
|
|
||||||
{'1': 'RoomMsg', '2': 0},
|
|
||||||
{'1': 'PrivateMsg', '2': 1},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `ReceiverType`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
|
||||||
final $typed_data.Uint8List receiverTypeDescriptor = $convert.base64Decode(
|
|
||||||
'CgxSZWNlaXZlclR5cGUSCwoHUm9vbU1zZxAAEg4KClByaXZhdGVNc2cQAQ==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use messageTypeDescriptor instead')
|
|
||||||
const MessageType$json = {
|
|
||||||
'1': 'MessageType',
|
|
||||||
'2': [
|
|
||||||
{'1': 'System', '2': 0},
|
|
||||||
{'1': 'Text', '2': 1},
|
|
||||||
{'1': 'Image', '2': 2},
|
|
||||||
{'1': 'Markdown', '2': 3},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `MessageType`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
|
||||||
final $typed_data.Uint8List messageTypeDescriptor = $convert.base64Decode(
|
|
||||||
'CgtNZXNzYWdlVHlwZRIKCgZTeXN0ZW0QABIICgRUZXh0EAESCQoFSW1hZ2UQAhIMCghNYXJrZG'
|
|
||||||
'93bhAD');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use chatMessageDescriptor instead')
|
|
||||||
const ChatMessage$json = {
|
|
||||||
'1': 'ChatMessage',
|
|
||||||
'2': [
|
|
||||||
{'1': 'senderID', '3': 1, '4': 1, '5': 9, '10': 'senderID'},
|
|
||||||
{'1': 'receiverID', '3': 2, '4': 1, '5': 9, '10': 'receiverID'},
|
|
||||||
{
|
|
||||||
'1': 'receiverType',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 14,
|
|
||||||
'6': '.ReceiverType',
|
|
||||||
'10': 'receiverType'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'messageType',
|
|
||||||
'3': 4,
|
|
||||||
'4': 1,
|
|
||||||
'5': 14,
|
|
||||||
'6': '.MessageType',
|
|
||||||
'10': 'messageType'
|
|
||||||
},
|
|
||||||
{'1': 'data', '3': 5, '4': 1, '5': 9, '10': 'data'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `ChatMessage`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List chatMessageDescriptor = $convert.base64Decode(
|
|
||||||
'CgtDaGF0TWVzc2FnZRIaCghzZW5kZXJJRBgBIAEoCVIIc2VuZGVySUQSHgoKcmVjZWl2ZXJJRB'
|
|
||||||
'gCIAEoCVIKcmVjZWl2ZXJJRBIxCgxyZWNlaXZlclR5cGUYAyABKA4yDS5SZWNlaXZlclR5cGVS'
|
|
||||||
'DHJlY2VpdmVyVHlwZRIuCgttZXNzYWdlVHlwZRgEIAEoDjIMLk1lc3NhZ2VUeXBlUgttZXNzYW'
|
|
||||||
'dlVHlwZRISCgRkYXRhGAUgASgJUgRkYXRh');
|
|
File diff suppressed because it is too large
Load Diff
@ -1,115 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: index.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
|
|
||||||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
|
||||||
// ignore_for_file: constant_identifier_names, library_prefixes
|
|
||||||
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
|
||||||
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
|
||||||
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
|
|
||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
|
||||||
|
|
||||||
class RoomStatus extends $pb.ProtobufEnum {
|
|
||||||
static const RoomStatus All = RoomStatus._(0, _omitEnumNames ? '' : 'All');
|
|
||||||
static const RoomStatus Open = RoomStatus._(1, _omitEnumNames ? '' : 'Open');
|
|
||||||
static const RoomStatus Private =
|
|
||||||
RoomStatus._(2, _omitEnumNames ? '' : 'Private');
|
|
||||||
static const RoomStatus Full = RoomStatus._(3, _omitEnumNames ? '' : 'Full');
|
|
||||||
static const RoomStatus Closed =
|
|
||||||
RoomStatus._(4, _omitEnumNames ? '' : 'Closed');
|
|
||||||
static const RoomStatus WillOffline =
|
|
||||||
RoomStatus._(5, _omitEnumNames ? '' : 'WillOffline');
|
|
||||||
static const RoomStatus Offline =
|
|
||||||
RoomStatus._(6, _omitEnumNames ? '' : 'Offline');
|
|
||||||
|
|
||||||
static const $core.List<RoomStatus> values = <RoomStatus>[
|
|
||||||
All,
|
|
||||||
Open,
|
|
||||||
Private,
|
|
||||||
Full,
|
|
||||||
Closed,
|
|
||||||
WillOffline,
|
|
||||||
Offline,
|
|
||||||
];
|
|
||||||
|
|
||||||
static final $core.Map<$core.int, RoomStatus> _byValue =
|
|
||||||
$pb.ProtobufEnum.initByValue(values);
|
|
||||||
static RoomStatus? valueOf($core.int value) => _byValue[value];
|
|
||||||
|
|
||||||
const RoomStatus._($core.int v, $core.String n) : super(v, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
class RoomSortType extends $pb.ProtobufEnum {
|
|
||||||
static const RoomSortType Default =
|
|
||||||
RoomSortType._(0, _omitEnumNames ? '' : 'Default');
|
|
||||||
static const RoomSortType MostPlayerNumber =
|
|
||||||
RoomSortType._(1, _omitEnumNames ? '' : 'MostPlayerNumber');
|
|
||||||
static const RoomSortType MinimumPlayerNumber =
|
|
||||||
RoomSortType._(2, _omitEnumNames ? '' : 'MinimumPlayerNumber');
|
|
||||||
static const RoomSortType RecentlyCreated =
|
|
||||||
RoomSortType._(3, _omitEnumNames ? '' : 'RecentlyCreated');
|
|
||||||
static const RoomSortType OldestCreated =
|
|
||||||
RoomSortType._(4, _omitEnumNames ? '' : 'OldestCreated');
|
|
||||||
|
|
||||||
static const $core.List<RoomSortType> values = <RoomSortType>[
|
|
||||||
Default,
|
|
||||||
MostPlayerNumber,
|
|
||||||
MinimumPlayerNumber,
|
|
||||||
RecentlyCreated,
|
|
||||||
OldestCreated,
|
|
||||||
];
|
|
||||||
|
|
||||||
static final $core.Map<$core.int, RoomSortType> _byValue =
|
|
||||||
$pb.ProtobufEnum.initByValue(values);
|
|
||||||
static RoomSortType? valueOf($core.int value) => _byValue[value];
|
|
||||||
|
|
||||||
const RoomSortType._($core.int v, $core.String n) : super(v, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
class RoomUserStatus extends $pb.ProtobufEnum {
|
|
||||||
static const RoomUserStatus RoomUserStatusJoin =
|
|
||||||
RoomUserStatus._(0, _omitEnumNames ? '' : 'RoomUserStatusJoin');
|
|
||||||
static const RoomUserStatus RoomUserStatusLostOffline =
|
|
||||||
RoomUserStatus._(1, _omitEnumNames ? '' : 'RoomUserStatusLostOffline');
|
|
||||||
static const RoomUserStatus RoomUserStatusLeave =
|
|
||||||
RoomUserStatus._(2, _omitEnumNames ? '' : 'RoomUserStatusLeave');
|
|
||||||
static const RoomUserStatus RoomUserStatusWaitingConnect =
|
|
||||||
RoomUserStatus._(3, _omitEnumNames ? '' : 'RoomUserStatusWaitingConnect');
|
|
||||||
|
|
||||||
static const $core.List<RoomUserStatus> values = <RoomUserStatus>[
|
|
||||||
RoomUserStatusJoin,
|
|
||||||
RoomUserStatusLostOffline,
|
|
||||||
RoomUserStatusLeave,
|
|
||||||
RoomUserStatusWaitingConnect,
|
|
||||||
];
|
|
||||||
|
|
||||||
static final $core.Map<$core.int, RoomUserStatus> _byValue =
|
|
||||||
$pb.ProtobufEnum.initByValue(values);
|
|
||||||
static RoomUserStatus? valueOf($core.int value) => _byValue[value];
|
|
||||||
|
|
||||||
const RoomUserStatus._($core.int v, $core.String n) : super(v, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
class RoomUpdateType extends $pb.ProtobufEnum {
|
|
||||||
static const RoomUpdateType RoomUpdateData =
|
|
||||||
RoomUpdateType._(0, _omitEnumNames ? '' : 'RoomUpdateData');
|
|
||||||
static const RoomUpdateType RoomClose =
|
|
||||||
RoomUpdateType._(1, _omitEnumNames ? '' : 'RoomClose');
|
|
||||||
|
|
||||||
static const $core.List<RoomUpdateType> values = <RoomUpdateType>[
|
|
||||||
RoomUpdateData,
|
|
||||||
RoomClose,
|
|
||||||
];
|
|
||||||
|
|
||||||
static final $core.Map<$core.int, RoomUpdateType> _byValue =
|
|
||||||
$pb.ProtobufEnum.initByValue(values);
|
|
||||||
static RoomUpdateType? valueOf($core.int value) => _byValue[value];
|
|
||||||
|
|
||||||
const RoomUpdateType._($core.int v, $core.String n) : super(v, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names');
|
|
@ -1,206 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: index.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
|
|
||||||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
|
||||||
// ignore_for_file: constant_identifier_names, library_prefixes
|
|
||||||
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
|
||||||
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
|
||||||
|
|
||||||
import 'dart:async' as $async;
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
|
|
||||||
import 'package:grpc/service_api.dart' as $grpc;
|
|
||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
|
||||||
|
|
||||||
import 'index.pb.dart' as $0;
|
|
||||||
|
|
||||||
export 'index.pb.dart';
|
|
||||||
|
|
||||||
@$pb.GrpcServiceName('IndexService')
|
|
||||||
class IndexServiceClient extends $grpc.Client {
|
|
||||||
static final _$pingServer = $grpc.ClientMethod<$0.PingData, $0.PingData>(
|
|
||||||
'/IndexService/PingServer',
|
|
||||||
($0.PingData value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $0.PingData.fromBuffer(value));
|
|
||||||
static final _$getRoomTypes = $grpc.ClientMethod<$0.Empty, $0.RoomTypesData>(
|
|
||||||
'/IndexService/GetRoomTypes',
|
|
||||||
($0.Empty value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $0.RoomTypesData.fromBuffer(value));
|
|
||||||
static final _$createRoom = $grpc.ClientMethod<$0.RoomData, $0.RoomData>(
|
|
||||||
'/IndexService/CreateRoom',
|
|
||||||
($0.RoomData value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $0.RoomData.fromBuffer(value));
|
|
||||||
static final _$getRoomList =
|
|
||||||
$grpc.ClientMethod<$0.RoomListPageReqData, $0.RoomListData>(
|
|
||||||
'/IndexService/GetRoomList',
|
|
||||||
($0.RoomListPageReqData value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $0.RoomListData.fromBuffer(value));
|
|
||||||
static final _$touchUser = $grpc.ClientMethod<$0.PreUser, $0.RoomData>(
|
|
||||||
'/IndexService/TouchUser',
|
|
||||||
($0.PreUser value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $0.RoomData.fromBuffer(value));
|
|
||||||
static final _$joinRoom =
|
|
||||||
$grpc.ClientMethod<$0.PreUser, $0.RoomUpdateMessage>(
|
|
||||||
'/IndexService/JoinRoom',
|
|
||||||
($0.PreUser value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) =>
|
|
||||||
$0.RoomUpdateMessage.fromBuffer(value));
|
|
||||||
static final _$leaveRoom = $grpc.ClientMethod<$0.PreUser, $0.BaseRespData>(
|
|
||||||
'/IndexService/LeaveRoom',
|
|
||||||
($0.PreUser value) => value.writeToBuffer(),
|
|
||||||
($core.List<$core.int> value) => $0.BaseRespData.fromBuffer(value));
|
|
||||||
|
|
||||||
IndexServiceClient($grpc.ClientChannel channel,
|
|
||||||
{$grpc.CallOptions? options,
|
|
||||||
$core.Iterable<$grpc.ClientInterceptor>? interceptors})
|
|
||||||
: super(channel, options: options, interceptors: interceptors);
|
|
||||||
|
|
||||||
$grpc.ResponseFuture<$0.PingData> pingServer($0.PingData request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createUnaryCall(_$pingServer, request, options: options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grpc.ResponseFuture<$0.RoomTypesData> getRoomTypes($0.Empty request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createUnaryCall(_$getRoomTypes, request, options: options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grpc.ResponseFuture<$0.RoomData> createRoom($0.RoomData request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createUnaryCall(_$createRoom, request, options: options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grpc.ResponseFuture<$0.RoomListData> getRoomList(
|
|
||||||
$0.RoomListPageReqData request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createUnaryCall(_$getRoomList, request, options: options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grpc.ResponseFuture<$0.RoomData> touchUser($0.PreUser request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createUnaryCall(_$touchUser, request, options: options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grpc.ResponseStream<$0.RoomUpdateMessage> joinRoom($0.PreUser request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createStreamingCall(
|
|
||||||
_$joinRoom, $async.Stream.fromIterable([request]),
|
|
||||||
options: options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grpc.ResponseFuture<$0.BaseRespData> leaveRoom($0.PreUser request,
|
|
||||||
{$grpc.CallOptions? options}) {
|
|
||||||
return $createUnaryCall(_$leaveRoom, request, options: options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@$pb.GrpcServiceName('IndexService')
|
|
||||||
abstract class IndexServiceBase extends $grpc.Service {
|
|
||||||
$core.String get $name => 'IndexService';
|
|
||||||
|
|
||||||
IndexServiceBase() {
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.PingData, $0.PingData>(
|
|
||||||
'PingServer',
|
|
||||||
pingServer_Pre,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
($core.List<$core.int> value) => $0.PingData.fromBuffer(value),
|
|
||||||
($0.PingData value) => value.writeToBuffer()));
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.Empty, $0.RoomTypesData>(
|
|
||||||
'GetRoomTypes',
|
|
||||||
getRoomTypes_Pre,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
($core.List<$core.int> value) => $0.Empty.fromBuffer(value),
|
|
||||||
($0.RoomTypesData value) => value.writeToBuffer()));
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.RoomData, $0.RoomData>(
|
|
||||||
'CreateRoom',
|
|
||||||
createRoom_Pre,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
($core.List<$core.int> value) => $0.RoomData.fromBuffer(value),
|
|
||||||
($0.RoomData value) => value.writeToBuffer()));
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.RoomListPageReqData, $0.RoomListData>(
|
|
||||||
'GetRoomList',
|
|
||||||
getRoomList_Pre,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
($core.List<$core.int> value) =>
|
|
||||||
$0.RoomListPageReqData.fromBuffer(value),
|
|
||||||
($0.RoomListData value) => value.writeToBuffer()));
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.PreUser, $0.RoomData>(
|
|
||||||
'TouchUser',
|
|
||||||
touchUser_Pre,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
($core.List<$core.int> value) => $0.PreUser.fromBuffer(value),
|
|
||||||
($0.RoomData value) => value.writeToBuffer()));
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.PreUser, $0.RoomUpdateMessage>(
|
|
||||||
'JoinRoom',
|
|
||||||
joinRoom_Pre,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
($core.List<$core.int> value) => $0.PreUser.fromBuffer(value),
|
|
||||||
($0.RoomUpdateMessage value) => value.writeToBuffer()));
|
|
||||||
$addMethod($grpc.ServiceMethod<$0.PreUser, $0.BaseRespData>(
|
|
||||||
'LeaveRoom',
|
|
||||||
leaveRoom_Pre,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
($core.List<$core.int> value) => $0.PreUser.fromBuffer(value),
|
|
||||||
($0.BaseRespData value) => value.writeToBuffer()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.PingData> pingServer_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$0.PingData> request) async {
|
|
||||||
return pingServer(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.RoomTypesData> getRoomTypes_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$0.Empty> request) async {
|
|
||||||
return getRoomTypes(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.RoomData> createRoom_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$0.RoomData> request) async {
|
|
||||||
return createRoom(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.RoomListData> getRoomList_Pre($grpc.ServiceCall call,
|
|
||||||
$async.Future<$0.RoomListPageReqData> request) async {
|
|
||||||
return getRoomList(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.RoomData> touchUser_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$0.PreUser> request) async {
|
|
||||||
return touchUser(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Stream<$0.RoomUpdateMessage> joinRoom_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$0.PreUser> request) async* {
|
|
||||||
yield* joinRoom(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.BaseRespData> leaveRoom_Pre(
|
|
||||||
$grpc.ServiceCall call, $async.Future<$0.PreUser> request) async {
|
|
||||||
return leaveRoom(call, await request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$async.Future<$0.PingData> pingServer(
|
|
||||||
$grpc.ServiceCall call, $0.PingData request);
|
|
||||||
$async.Future<$0.RoomTypesData> getRoomTypes(
|
|
||||||
$grpc.ServiceCall call, $0.Empty request);
|
|
||||||
$async.Future<$0.RoomData> createRoom(
|
|
||||||
$grpc.ServiceCall call, $0.RoomData request);
|
|
||||||
$async.Future<$0.RoomListData> getRoomList(
|
|
||||||
$grpc.ServiceCall call, $0.RoomListPageReqData request);
|
|
||||||
$async.Future<$0.RoomData> touchUser(
|
|
||||||
$grpc.ServiceCall call, $0.PreUser request);
|
|
||||||
$async.Stream<$0.RoomUpdateMessage> joinRoom(
|
|
||||||
$grpc.ServiceCall call, $0.PreUser request);
|
|
||||||
$async.Future<$0.BaseRespData> leaveRoom(
|
|
||||||
$grpc.ServiceCall call, $0.PreUser request);
|
|
||||||
}
|
|
@ -1,354 +0,0 @@
|
|||||||
//
|
|
||||||
// Generated code. Do not modify.
|
|
||||||
// source: index.proto
|
|
||||||
//
|
|
||||||
// @dart = 2.12
|
|
||||||
|
|
||||||
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
|
||||||
// ignore_for_file: constant_identifier_names, library_prefixes
|
|
||||||
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
|
||||||
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
|
||||||
|
|
||||||
import 'dart:convert' as $convert;
|
|
||||||
import 'dart:core' as $core;
|
|
||||||
import 'dart:typed_data' as $typed_data;
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomStatusDescriptor instead')
|
|
||||||
const RoomStatus$json = {
|
|
||||||
'1': 'RoomStatus',
|
|
||||||
'2': [
|
|
||||||
{'1': 'All', '2': 0},
|
|
||||||
{'1': 'Open', '2': 1},
|
|
||||||
{'1': 'Private', '2': 2},
|
|
||||||
{'1': 'Full', '2': 3},
|
|
||||||
{'1': 'Closed', '2': 4},
|
|
||||||
{'1': 'WillOffline', '2': 5},
|
|
||||||
{'1': 'Offline', '2': 6},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomStatus`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomStatusDescriptor = $convert.base64Decode(
|
|
||||||
'CgpSb29tU3RhdHVzEgcKA0FsbBAAEggKBE9wZW4QARILCgdQcml2YXRlEAISCAoERnVsbBADEg'
|
|
||||||
'oKBkNsb3NlZBAEEg8KC1dpbGxPZmZsaW5lEAUSCwoHT2ZmbGluZRAG');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomSortTypeDescriptor instead')
|
|
||||||
const RoomSortType$json = {
|
|
||||||
'1': 'RoomSortType',
|
|
||||||
'2': [
|
|
||||||
{'1': 'Default', '2': 0},
|
|
||||||
{'1': 'MostPlayerNumber', '2': 1},
|
|
||||||
{'1': 'MinimumPlayerNumber', '2': 2},
|
|
||||||
{'1': 'RecentlyCreated', '2': 3},
|
|
||||||
{'1': 'OldestCreated', '2': 4},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomSortType`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomSortTypeDescriptor = $convert.base64Decode(
|
|
||||||
'CgxSb29tU29ydFR5cGUSCwoHRGVmYXVsdBAAEhQKEE1vc3RQbGF5ZXJOdW1iZXIQARIXChNNaW'
|
|
||||||
'5pbXVtUGxheWVyTnVtYmVyEAISEwoPUmVjZW50bHlDcmVhdGVkEAMSEQoNT2xkZXN0Q3JlYXRl'
|
|
||||||
'ZBAE');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomUserStatusDescriptor instead')
|
|
||||||
const RoomUserStatus$json = {
|
|
||||||
'1': 'RoomUserStatus',
|
|
||||||
'2': [
|
|
||||||
{'1': 'RoomUserStatusJoin', '2': 0},
|
|
||||||
{'1': 'RoomUserStatusLostOffline', '2': 1},
|
|
||||||
{'1': 'RoomUserStatusLeave', '2': 2},
|
|
||||||
{'1': 'RoomUserStatusWaitingConnect', '2': 3},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomUserStatus`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomUserStatusDescriptor = $convert.base64Decode(
|
|
||||||
'Cg5Sb29tVXNlclN0YXR1cxIWChJSb29tVXNlclN0YXR1c0pvaW4QABIdChlSb29tVXNlclN0YX'
|
|
||||||
'R1c0xvc3RPZmZsaW5lEAESFwoTUm9vbVVzZXJTdGF0dXNMZWF2ZRACEiAKHFJvb21Vc2VyU3Rh'
|
|
||||||
'dHVzV2FpdGluZ0Nvbm5lY3QQAw==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomUpdateTypeDescriptor instead')
|
|
||||||
const RoomUpdateType$json = {
|
|
||||||
'1': 'RoomUpdateType',
|
|
||||||
'2': [
|
|
||||||
{'1': 'RoomUpdateData', '2': 0},
|
|
||||||
{'1': 'RoomClose', '2': 1},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomUpdateType`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomUpdateTypeDescriptor = $convert.base64Decode(
|
|
||||||
'Cg5Sb29tVXBkYXRlVHlwZRISCg5Sb29tVXBkYXRlRGF0YRAAEg0KCVJvb21DbG9zZRAB');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use emptyDescriptor instead')
|
|
||||||
const Empty$json = {
|
|
||||||
'1': 'Empty',
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `Empty`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List emptyDescriptor =
|
|
||||||
$convert.base64Decode('CgVFbXB0eQ==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use baseRespDataDescriptor instead')
|
|
||||||
const BaseRespData$json = {
|
|
||||||
'1': 'BaseRespData',
|
|
||||||
'2': [
|
|
||||||
{'1': 'code', '3': 1, '4': 1, '5': 5, '10': 'code'},
|
|
||||||
{'1': 'message', '3': 2, '4': 1, '5': 9, '10': 'message'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `BaseRespData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List baseRespDataDescriptor = $convert.base64Decode(
|
|
||||||
'CgxCYXNlUmVzcERhdGESEgoEY29kZRgBIAEoBVIEY29kZRIYCgdtZXNzYWdlGAIgASgJUgdtZX'
|
|
||||||
'NzYWdl');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use basePageRespDataDescriptor instead')
|
|
||||||
const BasePageRespData$json = {
|
|
||||||
'1': 'BasePageRespData',
|
|
||||||
'2': [
|
|
||||||
{'1': 'code', '3': 1, '4': 1, '5': 5, '10': 'code'},
|
|
||||||
{'1': 'message', '3': 2, '4': 1, '5': 9, '10': 'message'},
|
|
||||||
{'1': 'hasNext', '3': 3, '4': 1, '5': 8, '10': 'hasNext'},
|
|
||||||
{'1': 'curPageNum', '3': 4, '4': 1, '5': 4, '10': 'curPageNum'},
|
|
||||||
{'1': 'pageSize', '3': 5, '4': 1, '5': 3, '10': 'pageSize'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `BasePageRespData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List basePageRespDataDescriptor = $convert.base64Decode(
|
|
||||||
'ChBCYXNlUGFnZVJlc3BEYXRhEhIKBGNvZGUYASABKAVSBGNvZGUSGAoHbWVzc2FnZRgCIAEoCV'
|
|
||||||
'IHbWVzc2FnZRIYCgdoYXNOZXh0GAMgASgIUgdoYXNOZXh0Eh4KCmN1clBhZ2VOdW0YBCABKARS'
|
|
||||||
'CmN1clBhZ2VOdW0SGgoIcGFnZVNpemUYBSABKANSCHBhZ2VTaXpl');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use pingDataDescriptor instead')
|
|
||||||
const PingData$json = {
|
|
||||||
'1': 'PingData',
|
|
||||||
'2': [
|
|
||||||
{'1': 'data', '3': 1, '4': 1, '5': 9, '10': 'data'},
|
|
||||||
{'1': 'clientVersion', '3': 2, '4': 1, '5': 18, '10': 'clientVersion'},
|
|
||||||
{'1': 'serverVersion', '3': 3, '4': 1, '5': 18, '10': 'serverVersion'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `PingData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List pingDataDescriptor = $convert.base64Decode(
|
|
||||||
'CghQaW5nRGF0YRISCgRkYXRhGAEgASgJUgRkYXRhEiQKDWNsaWVudFZlcnNpb24YAiABKBJSDW'
|
|
||||||
'NsaWVudFZlcnNpb24SJAoNc2VydmVyVmVyc2lvbhgDIAEoElINc2VydmVyVmVyc2lvbg==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomTypesDataDescriptor instead')
|
|
||||||
const RoomTypesData$json = {
|
|
||||||
'1': 'RoomTypesData',
|
|
||||||
'2': [
|
|
||||||
{
|
|
||||||
'1': 'roomTypes',
|
|
||||||
'3': 1,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.RoomType',
|
|
||||||
'10': 'roomTypes'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomTypesData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomTypesDataDescriptor = $convert.base64Decode(
|
|
||||||
'Cg1Sb29tVHlwZXNEYXRhEicKCXJvb21UeXBlcxgBIAMoCzIJLlJvb21UeXBlUglyb29tVHlwZX'
|
|
||||||
'M=');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomTypeDescriptor instead')
|
|
||||||
const RoomType$json = {
|
|
||||||
'1': 'RoomType',
|
|
||||||
'2': [
|
|
||||||
{'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
|
|
||||||
{'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
|
|
||||||
{'1': 'icon', '3': 3, '4': 1, '5': 9, '10': 'icon'},
|
|
||||||
{'1': 'desc', '3': 4, '4': 1, '5': 9, '10': 'desc'},
|
|
||||||
{
|
|
||||||
'1': 'subTypes',
|
|
||||||
'3': 5,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.RoomSubtype',
|
|
||||||
'10': 'subTypes'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomType`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomTypeDescriptor = $convert.base64Decode(
|
|
||||||
'CghSb29tVHlwZRIOCgJpZBgBIAEoCVICaWQSEgoEbmFtZRgCIAEoCVIEbmFtZRISCgRpY29uGA'
|
|
||||||
'MgASgJUgRpY29uEhIKBGRlc2MYBCABKAlSBGRlc2MSKAoIc3ViVHlwZXMYBSADKAsyDC5Sb29t'
|
|
||||||
'U3VidHlwZVIIc3ViVHlwZXM=');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomSubtypeDescriptor instead')
|
|
||||||
const RoomSubtype$json = {
|
|
||||||
'1': 'RoomSubtype',
|
|
||||||
'2': [
|
|
||||||
{'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
|
|
||||||
{'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomSubtype`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomSubtypeDescriptor = $convert.base64Decode(
|
|
||||||
'CgtSb29tU3VidHlwZRIOCgJpZBgBIAEoCVICaWQSEgoEbmFtZRgCIAEoCVIEbmFtZQ==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomDataDescriptor instead')
|
|
||||||
const RoomData$json = {
|
|
||||||
'1': 'RoomData',
|
|
||||||
'2': [
|
|
||||||
{'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
|
|
||||||
{'1': 'roomTypeID', '3': 2, '4': 1, '5': 9, '10': 'roomTypeID'},
|
|
||||||
{'1': 'roomSubTypeIds', '3': 3, '4': 3, '5': 9, '10': 'roomSubTypeIds'},
|
|
||||||
{'1': 'owner', '3': 4, '4': 1, '5': 9, '10': 'owner'},
|
|
||||||
{'1': 'maxPlayer', '3': 5, '4': 1, '5': 5, '10': 'maxPlayer'},
|
|
||||||
{'1': 'createTime', '3': 6, '4': 1, '5': 3, '10': 'createTime'},
|
|
||||||
{'1': 'curPlayer', '3': 7, '4': 1, '5': 5, '10': 'curPlayer'},
|
|
||||||
{
|
|
||||||
'1': 'status',
|
|
||||||
'3': 8,
|
|
||||||
'4': 1,
|
|
||||||
'5': 14,
|
|
||||||
'6': '.RoomStatus',
|
|
||||||
'10': 'status'
|
|
||||||
},
|
|
||||||
{'1': 'deviceUUID', '3': 9, '4': 1, '5': 9, '10': 'deviceUUID'},
|
|
||||||
{'1': 'announcement', '3': 10, '4': 1, '5': 9, '10': 'announcement'},
|
|
||||||
{'1': 'avatar', '3': 11, '4': 1, '5': 9, '10': 'avatar'},
|
|
||||||
{'1': 'updateTime', '3': 12, '4': 1, '5': 3, '10': 'updateTime'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomDataDescriptor = $convert.base64Decode(
|
|
||||||
'CghSb29tRGF0YRIOCgJpZBgBIAEoCVICaWQSHgoKcm9vbVR5cGVJRBgCIAEoCVIKcm9vbVR5cG'
|
|
||||||
'VJRBImCg5yb29tU3ViVHlwZUlkcxgDIAMoCVIOcm9vbVN1YlR5cGVJZHMSFAoFb3duZXIYBCAB'
|
|
||||||
'KAlSBW93bmVyEhwKCW1heFBsYXllchgFIAEoBVIJbWF4UGxheWVyEh4KCmNyZWF0ZVRpbWUYBi'
|
|
||||||
'ABKANSCmNyZWF0ZVRpbWUSHAoJY3VyUGxheWVyGAcgASgFUgljdXJQbGF5ZXISIwoGc3RhdHVz'
|
|
||||||
'GAggASgOMgsuUm9vbVN0YXR1c1IGc3RhdHVzEh4KCmRldmljZVVVSUQYCSABKAlSCmRldmljZV'
|
|
||||||
'VVSUQSIgoMYW5ub3VuY2VtZW50GAogASgJUgxhbm5vdW5jZW1lbnQSFgoGYXZhdGFyGAsgASgJ'
|
|
||||||
'UgZhdmF0YXISHgoKdXBkYXRlVGltZRgMIAEoA1IKdXBkYXRlVGltZQ==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomListPageReqDataDescriptor instead')
|
|
||||||
const RoomListPageReqData$json = {
|
|
||||||
'1': 'RoomListPageReqData',
|
|
||||||
'2': [
|
|
||||||
{'1': 'typeID', '3': 1, '4': 1, '5': 9, '10': 'typeID'},
|
|
||||||
{'1': 'subTypeID', '3': 2, '4': 1, '5': 9, '10': 'subTypeID'},
|
|
||||||
{
|
|
||||||
'1': 'status',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 14,
|
|
||||||
'6': '.RoomStatus',
|
|
||||||
'10': 'status'
|
|
||||||
},
|
|
||||||
{'1': 'sort', '3': 4, '4': 1, '5': 14, '6': '.RoomSortType', '10': 'sort'},
|
|
||||||
{'1': 'pageNum', '3': 5, '4': 1, '5': 4, '10': 'pageNum'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomListPageReqData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomListPageReqDataDescriptor = $convert.base64Decode(
|
|
||||||
'ChNSb29tTGlzdFBhZ2VSZXFEYXRhEhYKBnR5cGVJRBgBIAEoCVIGdHlwZUlEEhwKCXN1YlR5cG'
|
|
||||||
'VJRBgCIAEoCVIJc3ViVHlwZUlEEiMKBnN0YXR1cxgDIAEoDjILLlJvb21TdGF0dXNSBnN0YXR1'
|
|
||||||
'cxIhCgRzb3J0GAQgASgOMg0uUm9vbVNvcnRUeXBlUgRzb3J0EhgKB3BhZ2VOdW0YBSABKARSB3'
|
|
||||||
'BhZ2VOdW0=');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomListDataDescriptor instead')
|
|
||||||
const RoomListData$json = {
|
|
||||||
'1': 'RoomListData',
|
|
||||||
'2': [
|
|
||||||
{
|
|
||||||
'1': 'pageData',
|
|
||||||
'3': 1,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.BasePageRespData',
|
|
||||||
'10': 'pageData'
|
|
||||||
},
|
|
||||||
{'1': 'rooms', '3': 2, '4': 3, '5': 11, '6': '.RoomData', '10': 'rooms'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomListData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomListDataDescriptor = $convert.base64Decode(
|
|
||||||
'CgxSb29tTGlzdERhdGESLQoIcGFnZURhdGEYASABKAsyES5CYXNlUGFnZVJlc3BEYXRhUghwYW'
|
|
||||||
'dlRGF0YRIfCgVyb29tcxgCIAMoCzIJLlJvb21EYXRhUgVyb29tcw==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use preUserDescriptor instead')
|
|
||||||
const PreUser$json = {
|
|
||||||
'1': 'PreUser',
|
|
||||||
'2': [
|
|
||||||
{'1': 'userName', '3': 1, '4': 1, '5': 9, '10': 'userName'},
|
|
||||||
{'1': 'deviceUUID', '3': 2, '4': 1, '5': 9, '10': 'deviceUUID'},
|
|
||||||
{'1': 'roomID', '3': 3, '4': 1, '5': 9, '10': 'roomID'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `PreUser`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List preUserDescriptor = $convert.base64Decode(
|
|
||||||
'CgdQcmVVc2VyEhoKCHVzZXJOYW1lGAEgASgJUgh1c2VyTmFtZRIeCgpkZXZpY2VVVUlEGAIgAS'
|
|
||||||
'gJUgpkZXZpY2VVVUlEEhYKBnJvb21JRBgDIAEoCVIGcm9vbUlE');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomUserDataDescriptor instead')
|
|
||||||
const RoomUserData$json = {
|
|
||||||
'1': 'RoomUserData',
|
|
||||||
'2': [
|
|
||||||
{'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
|
|
||||||
{'1': 'playerName', '3': 2, '4': 1, '5': 9, '10': 'playerName'},
|
|
||||||
{'1': 'Avatar', '3': 3, '4': 1, '5': 9, '10': 'Avatar'},
|
|
||||||
{
|
|
||||||
'1': 'status',
|
|
||||||
'3': 4,
|
|
||||||
'4': 1,
|
|
||||||
'5': 14,
|
|
||||||
'6': '.RoomUserStatus',
|
|
||||||
'10': 'status'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomUserData`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomUserDataDescriptor = $convert.base64Decode(
|
|
||||||
'CgxSb29tVXNlckRhdGESDgoCaWQYASABKAlSAmlkEh4KCnBsYXllck5hbWUYAiABKAlSCnBsYX'
|
|
||||||
'llck5hbWUSFgoGQXZhdGFyGAMgASgJUgZBdmF0YXISJwoGc3RhdHVzGAQgASgOMg8uUm9vbVVz'
|
|
||||||
'ZXJTdGF0dXNSBnN0YXR1cw==');
|
|
||||||
|
|
||||||
@$core.Deprecated('Use roomUpdateMessageDescriptor instead')
|
|
||||||
const RoomUpdateMessage$json = {
|
|
||||||
'1': 'RoomUpdateMessage',
|
|
||||||
'2': [
|
|
||||||
{
|
|
||||||
'1': 'roomData',
|
|
||||||
'3': 1,
|
|
||||||
'4': 1,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.RoomData',
|
|
||||||
'10': 'roomData'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'usersData',
|
|
||||||
'3': 2,
|
|
||||||
'4': 3,
|
|
||||||
'5': 11,
|
|
||||||
'6': '.RoomUserData',
|
|
||||||
'10': 'usersData'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'1': 'roomUpdateType',
|
|
||||||
'3': 3,
|
|
||||||
'4': 1,
|
|
||||||
'5': 14,
|
|
||||||
'6': '.RoomUpdateType',
|
|
||||||
'10': 'roomUpdateType'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Descriptor for `RoomUpdateMessage`. Decode as a `google.protobuf.DescriptorProto`.
|
|
||||||
final $typed_data.Uint8List roomUpdateMessageDescriptor = $convert.base64Decode(
|
|
||||||
'ChFSb29tVXBkYXRlTWVzc2FnZRIlCghyb29tRGF0YRgBIAEoCzIJLlJvb21EYXRhUghyb29tRG'
|
|
||||||
'F0YRIrCgl1c2Vyc0RhdGEYAiADKAsyDS5Sb29tVXNlckRhdGFSCXVzZXJzRGF0YRI3Cg5yb29t'
|
|
||||||
'VXBkYXRlVHlwZRgDIAEoDjIPLlJvb21VcGRhdGVUeXBlUg5yb29tVXBkYXRlVHlwZQ==');
|
|
@ -1,101 +0,0 @@
|
|||||||
// ignore_for_file: use_build_context_synchronously
|
|
||||||
|
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:hexcolor/hexcolor.dart';
|
|
||||||
|
|
||||||
import 'base/ui_model.dart';
|
|
||||||
import 'common/conf/app_conf.dart';
|
|
||||||
import 'ui/settings/upgrade_dialog_ui.dart';
|
|
||||||
import 'ui/settings/upgrade_dialog_ui_model.dart';
|
|
||||||
|
|
||||||
final globalUIModel = AppGlobalUIModel();
|
|
||||||
final globalUIModelProvider = ChangeNotifierProvider((ref) => globalUIModel);
|
|
||||||
|
|
||||||
class AppGlobalUIModel extends BaseUIModel {
|
|
||||||
Timer? activityThemeColorTimer;
|
|
||||||
|
|
||||||
Future<String?> getRunningGameUser() async {
|
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
|
|
||||||
///TODO 实现获取运行中用户名
|
|
||||||
return "xkeyC";
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> doCheckUpdate(BuildContext context, {bool init = true}) async {
|
|
||||||
dynamic checkUpdateError;
|
|
||||||
if (!init) {
|
|
||||||
try {
|
|
||||||
await AppConf.checkUpdate();
|
|
||||||
} catch (e) {
|
|
||||||
checkUpdateError = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
|
||||||
if (AppConf.networkVersionData == null) {
|
|
||||||
showToast(context,
|
|
||||||
"网络异常!\n这可能是您的网络环境存在DNS污染,请尝试更换DNS。\n或服务器正在维护或遭受攻击,稍后再试。 \n进入离线模式... \n\n请谨慎在离线模式中使用。 \n当前版本构建日期:${AppConf.appVersionDate}\n QQ群:940696487 \n错误信息:$checkUpdateError");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final lastVersion = AppConf.isMSE
|
|
||||||
? AppConf.networkVersionData?.mSELastVersionCode
|
|
||||||
: AppConf.networkVersionData?.lastVersionCode;
|
|
||||||
if ((lastVersion ?? 0) > AppConf.appVersionCode) {
|
|
||||||
// need update
|
|
||||||
final r = await showDialog(
|
|
||||||
dismissWithEsc: false,
|
|
||||||
context: context,
|
|
||||||
builder: (context) => BaseUIContainer(
|
|
||||||
uiCreate: () => UpgradeDialogUI(),
|
|
||||||
modelCreate: () => UpgradeDialogUIModel()));
|
|
||||||
if (r != true) {
|
|
||||||
showToast(context, "获取更新信息失败,请稍后重试。");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkActivityThemeColor() {
|
|
||||||
if (activityThemeColorTimer != null) {
|
|
||||||
activityThemeColorTimer?.cancel();
|
|
||||||
activityThemeColorTimer = null;
|
|
||||||
}
|
|
||||||
if (AppConf.networkVersionData == null ||
|
|
||||||
AppConf.networkVersionData?.activityColors?.enable != true) return;
|
|
||||||
|
|
||||||
final startTime = AppConf.networkVersionData!.activityColors?.startTime;
|
|
||||||
final endTime = AppConf.networkVersionData!.activityColors?.endTime;
|
|
||||||
if (startTime == null || endTime == null) return;
|
|
||||||
final now = DateTime.now().millisecondsSinceEpoch;
|
|
||||||
|
|
||||||
dPrint("now == $now start == $startTime end == $endTime");
|
|
||||||
if (now < startTime) {
|
|
||||||
activityThemeColorTimer = Timer(
|
|
||||||
Duration(milliseconds: startTime - now), checkActivityThemeColor);
|
|
||||||
dPrint("start Timer ....");
|
|
||||||
} else if (now >= startTime && now <= endTime) {
|
|
||||||
dPrint("update Color ....");
|
|
||||||
// update Color
|
|
||||||
final colorCfg = AppConf.networkVersionData!.activityColors;
|
|
||||||
AppConf.colorBackground =
|
|
||||||
HexColor(colorCfg?.background ?? "#132431").withOpacity(.75);
|
|
||||||
AppConf.colorMenu =
|
|
||||||
HexColor(colorCfg?.menu ?? "#132431").withOpacity(.95);
|
|
||||||
AppConf.colorMica = HexColor(colorCfg?.mica ?? "#0A3142");
|
|
||||||
notifyListeners();
|
|
||||||
// wait for end
|
|
||||||
activityThemeColorTimer =
|
|
||||||
Timer(Duration(milliseconds: endTime - now), checkActivityThemeColor);
|
|
||||||
} else {
|
|
||||||
dPrint("reset Color ....");
|
|
||||||
AppConf.colorBackground = HexColor("#132431").withOpacity(.75);
|
|
||||||
AppConf.colorMenu = HexColor("#132431").withOpacity(.95);
|
|
||||||
AppConf.colorMica = HexColor("#0A3142");
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +1,43 @@
|
|||||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
import 'base/ui_model.dart';
|
import 'app.dart';
|
||||||
import 'common/conf/app_conf.dart';
|
|
||||||
import 'global_ui_model.dart';
|
|
||||||
import 'ui/splash_ui.dart';
|
|
||||||
import 'ui/splash_ui_model.dart';
|
|
||||||
|
|
||||||
void main(List<String> args) async {
|
void main(List<String> args) async {
|
||||||
|
// webview window
|
||||||
if (runWebViewTitleBarWidget(args,
|
if (runWebViewTitleBarWidget(args,
|
||||||
backgroundColor: const Color.fromRGBO(19, 36, 49, 1),
|
backgroundColor: const Color.fromRGBO(19, 36, 49, 1),
|
||||||
builder: _defaultWebviewTitleBar)) {
|
builder: _defaultWebviewTitleBar)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await AppConf.init(args);
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
runApp(ProviderScope(
|
await _initWindow();
|
||||||
child: BaseUIContainer(
|
// run app
|
||||||
uiCreate: () => AppUI(),
|
runApp(const ProviderScope(child: App()));
|
||||||
modelCreate: () => globalUIModelProvider,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppUI extends BaseUI {
|
_initWindow() async {
|
||||||
|
await windowManager.ensureInitialized();
|
||||||
|
await windowManager.setTitleBarStyle(
|
||||||
|
TitleBarStyle.hidden,
|
||||||
|
windowButtonVisibility: false,
|
||||||
|
);
|
||||||
|
await windowManager.hide();
|
||||||
|
await windowManager.center(animate: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
class App extends HookConsumerWidget {
|
||||||
|
const App({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget? buildBody(BuildContext context, BaseUIModel model) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return FluentApp(
|
final router = ref.watch(routerProvider);
|
||||||
title: "StarCitizen Doctor",
|
final appState = ref.watch(appGlobalModelProvider);
|
||||||
restorationScopeId: "Doctor",
|
return FluentApp.router(
|
||||||
|
title: "StarCitizenToolBox",
|
||||||
|
restorationScopeId: "StarCitizenToolBox",
|
||||||
themeMode: ThemeMode.dark,
|
themeMode: ThemeMode.dark,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
@ -41,10 +50,10 @@ class AppUI extends BaseUI {
|
|||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
fontFamily: "SourceHanSansCN-Regular",
|
fontFamily: "SourceHanSansCN-Regular",
|
||||||
navigationPaneTheme: NavigationPaneThemeData(
|
navigationPaneTheme: NavigationPaneThemeData(
|
||||||
backgroundColor: AppConf.colorBackground,
|
backgroundColor: appState.themeConf.backgroundColor,
|
||||||
),
|
),
|
||||||
menuColor: AppConf.colorMenu,
|
menuColor: appState.themeConf.menuColor,
|
||||||
micaBackgroundColor: AppConf.colorMica,
|
micaBackgroundColor: appState.themeConf.micaColor,
|
||||||
buttonTheme: ButtonThemeData(
|
buttonTheme: ButtonThemeData(
|
||||||
defaultButtonStyle: ButtonStyle(
|
defaultButtonStyle: ButtonStyle(
|
||||||
shape: ButtonState.all(RoundedRectangleBorder(
|
shape: ButtonState.all(RoundedRectangleBorder(
|
||||||
@ -52,28 +61,9 @@ class AppUI extends BaseUI {
|
|||||||
side: BorderSide(color: Colors.white.withOpacity(.01)))),
|
side: BorderSide(color: Colors.white.withOpacity(.01)))),
|
||||||
))),
|
))),
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: BaseUIContainer(
|
routeInformationParser: router.routeInformationParser,
|
||||||
uiCreate: () => SplashUI(), modelCreate: () => SplashUIModel()),
|
routerDelegate: router.routerDelegate,
|
||||||
);
|
routeInformationProvider: router.routeInformationProvider,
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, BaseUIModel model) => "";
|
|
||||||
}
|
|
||||||
|
|
||||||
class WindowButtons extends StatelessWidget {
|
|
||||||
const WindowButtons({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final FluentThemeData theme = FluentTheme.of(context);
|
|
||||||
return SizedBox(
|
|
||||||
width: 138,
|
|
||||||
height: 50,
|
|
||||||
child: WindowCaption(
|
|
||||||
brightness: theme.brightness,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,163 +0,0 @@
|
|||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
import 'about_ui_model.dart';
|
|
||||||
|
|
||||||
class AboutUI extends BaseUI<AboutUIModel> {
|
|
||||||
bool isTipTextCn = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, AboutUIModel model) {
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Spacer(),
|
|
||||||
const SizedBox(height: 64),
|
|
||||||
Image.asset("assets/app_logo.png", width: 128, height: 128),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
const Text(
|
|
||||||
"SC汉化盒子 V${AppConf.appVersion} ${AppConf.isMSE ? "" : " +Dev"}",
|
|
||||||
style: TextStyle(fontSize: 18)),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Button(
|
|
||||||
onPressed: model.checkUpdate,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(4),
|
|
||||||
child: Text("检查更新"),
|
|
||||||
)),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
borderRadius: BorderRadius.circular(12)),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24),
|
|
||||||
child: Text(
|
|
||||||
"不仅仅是汉化!\n\nSC汉化盒子是你探索宇宙的好帮手,我们致力于为各位公民解决游戏中的常见问题,并为社区汉化、性能调优、常用网站汉化 等操作提供便利。",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.9)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(FontAwesomeIcons.link),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
"在线反馈",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString(URLConf.feedbackUrl);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
IconButton(
|
|
||||||
icon: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(FontAwesomeIcons.qq),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
"QQ群: 940696487",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString(
|
|
||||||
"https://qm.qq.com/cgi-bin/qm/qr?k=TdyR3QU-x77OeD0NQ5w--F0uiNxPq-Tn&jump_from=webapi&authKey=m8s5GhF/7bRCvm5vI4aNl7RQEx5KOViwkzzIl54K+u9w2hzFpr9N/3avG4W/HaVS");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
IconButton(
|
|
||||||
icon: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(FontAwesomeIcons.envelope),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
"邮箱: scbox@xkeyc.com",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString("mailto:scbox@xkeyc.com");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
IconButton(
|
|
||||||
icon: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(FontAwesomeIcons.github),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
"开源",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString("https://github.com/StarCitizenToolBox/app");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
const Spacer(),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Spacer(),
|
|
||||||
Container(
|
|
||||||
width: MediaQuery.of(context).size.width * .35,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor.withOpacity(.03),
|
|
||||||
borderRadius: BorderRadius.circular(12)),
|
|
||||||
child: IconButton(
|
|
||||||
icon: Padding(
|
|
||||||
padding: const EdgeInsets.all(3),
|
|
||||||
child: Text(
|
|
||||||
isTipTextCn ? tipTextCN : tipTextEN,
|
|
||||||
textAlign: TextAlign.start,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12, color: Colors.white.withOpacity(.9)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
isTipTextCn = !isTipTextCn;
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const tipTextEN =
|
|
||||||
"This is an unofficial Star Citizen fan-made tools, not affiliated with the Cloud Imperium group of companies. All content on this Software not authored by its host or users are property of their respective owners. \nStar Citizen®, Roberts Space Industries® and Cloud Imperium® are registered trademarks of Cloud Imperium Rights LLC.";
|
|
||||||
|
|
||||||
static const tipTextCN =
|
|
||||||
"这是一个非官方的星际公民工具,不隶属于 Cloud Imperium 公司集团。 本软件中非由其主机或用户创作的所有内容均为其各自所有者的财产。 \nStar Citizen®、Roberts Space Industries® 和 Cloud Imperium® 是 Cloud Imperium Rights LLC 的注册商标。";
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, AboutUIModel model) => "";
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
class AboutUIModel extends BaseUIModel {
|
|
||||||
Future<void> checkUpdate() async {
|
|
||||||
if (AppConf.isMSE) {
|
|
||||||
launchUrlString("ms-windows-store://pdp/?productid=9NF3SWFWNKL1");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final hasUpdate = await globalUIModel.doCheckUpdate(context!);
|
|
||||||
if (!hasUpdate) {
|
|
||||||
if (mounted) showToast(context!, "已是最新版本");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/widgets/countdown_time_text.dart';
|
|
||||||
|
|
||||||
import 'countdown_dialog_ui_model.dart';
|
|
||||||
|
|
||||||
class CountdownDialogUI extends BaseUI<CountdownDialogUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, CountdownDialogUIModel model) {
|
|
||||||
return ContentDialog(
|
|
||||||
constraints:
|
|
||||||
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .65),
|
|
||||||
title: Row(
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(
|
|
||||||
FluentIcons.back,
|
|
||||||
size: 22,
|
|
||||||
),
|
|
||||||
onPressed: model.onBack),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Text("节日倒计时"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
content: SingleChildScrollView(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 12, right: 12),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
AlignedGridView.count(
|
|
||||||
crossAxisCount: 3,
|
|
||||||
mainAxisSpacing: 12,
|
|
||||||
crossAxisSpacing: 12,
|
|
||||||
itemCount: model.countdownFestivalListData.length,
|
|
||||||
shrinkWrap: true,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
final item = model.countdownFestivalListData[index];
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
if (item.icon != null && item.icon != "") ...[
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(1000),
|
|
||||||
child: Image.asset(
|
|
||||||
"assets/countdown/${item.icon}",
|
|
||||||
width: 38,
|
|
||||||
height: 38,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
] else
|
|
||||||
const SizedBox(width: 50),
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${item.name}",
|
|
||||||
),
|
|
||||||
CountdownTimeText(
|
|
||||||
targetTime: DateTime.fromMillisecondsSinceEpoch(
|
|
||||||
item.time ?? 0),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
"* 以上节日日期由人工收录、维护,可能存在错误,欢迎反馈!",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13, color: Colors.white.withOpacity(.3)),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, CountdownDialogUIModel model) => "";
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/countdown_festival_item_data.dart';
|
|
||||||
|
|
||||||
class CountdownDialogUIModel extends BaseUIModel {
|
|
||||||
final List<CountdownFestivalItemData> countdownFestivalListData;
|
|
||||||
|
|
||||||
CountdownDialogUIModel(this.countdownFestivalListData);
|
|
||||||
|
|
||||||
onBack() {
|
|
||||||
Navigator.pop(context!);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
import 'package:flutter/material.dart' show Material;
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui_model.dart';
|
|
||||||
|
|
||||||
class MDContentDialogUI extends BaseUI<MDContentDialogUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, MDContentDialogUIModel model) {
|
|
||||||
return Material(
|
|
||||||
child: ContentDialog(
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context).size.width * .6,
|
|
||||||
),
|
|
||||||
title: Text(getUITitle(context, model)),
|
|
||||||
content: model.data == null
|
|
||||||
? makeLoading(context)
|
|
||||||
: SingleChildScrollView(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 12, right: 12),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: makeMarkdownView(model.data ?? ""),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
FilledButton(
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
|
||||||
child: Text("关闭"),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
})
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, MDContentDialogUIModel model) =>
|
|
||||||
model.title;
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
|
||||||
|
|
||||||
class MDContentDialogUIModel extends BaseUIModel {
|
|
||||||
String title;
|
|
||||||
String url;
|
|
||||||
|
|
||||||
MDContentDialogUIModel(this.title, this.url);
|
|
||||||
|
|
||||||
String? data;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future loadData() async {
|
|
||||||
final r = await handleError(() => RSHttp.getText(url));
|
|
||||||
if (r == null) return;
|
|
||||||
data = r;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,247 +0,0 @@
|
|||||||
import 'package:file_sizes/file_sizes.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/aria2c.dart';
|
|
||||||
|
|
||||||
import 'downloader_ui_model.dart';
|
|
||||||
|
|
||||||
class DownloaderUI extends BaseUI<DownloaderUIModel> {
|
|
||||||
final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, DownloaderUIModel model) {
|
|
||||||
return makeDefaultPage(context, model,
|
|
||||||
content: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Spacer(),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
for (final item in <MapEntry<String, IconData>, String>{
|
|
||||||
const MapEntry("settings", FluentIcons.settings): "限速设置",
|
|
||||||
if (model.tasks.isNotEmpty)
|
|
||||||
const MapEntry("pause_all", FluentIcons.pause): "全部暂停",
|
|
||||||
if (model.waitingTasks.isNotEmpty)
|
|
||||||
const MapEntry("resume_all", FluentIcons.download): "恢复全部",
|
|
||||||
if (model.tasks.isNotEmpty || model.waitingTasks.isNotEmpty)
|
|
||||||
const MapEntry("cancel_all", FluentIcons.cancel): "全部取消",
|
|
||||||
}.entries)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 6, right: 6),
|
|
||||||
child: Button(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(item.key.value),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Text(item.value),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () => model.onTapButton(item.key.key)),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (model.getTasksLen() == 0)
|
|
||||||
const Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Text("无下载任务"),
|
|
||||||
))
|
|
||||||
else
|
|
||||||
Expanded(
|
|
||||||
child: ListView.builder(
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
final (task, type, isFirstType) = model.getTaskAndType(index);
|
|
||||||
final nt = DownloaderUIModel.getTaskTypeAndName(task);
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (isFirstType)
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
left: 24,
|
|
||||||
right: 24,
|
|
||||||
top: index == 0 ? 0 : 12,
|
|
||||||
bottom: 12),
|
|
||||||
margin: const EdgeInsets.only(top: 6, bottom: 6),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${model.listHeaderStatusMap[type]}",
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 24,
|
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 12, right: 12, top: 12, bottom: 12),
|
|
||||||
margin: const EdgeInsets.only(
|
|
||||||
left: 12, right: 12, top: 6, bottom: 6),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context)
|
|
||||||
.cardColor
|
|
||||||
.withOpacity(.06),
|
|
||||||
borderRadius: BorderRadius.circular(7),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
nt.value,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"总大小:${FileSize.getSize(task.totalLength ?? 0)}",
|
|
||||||
style: const TextStyle(fontSize: 14),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
if (nt.key == "torrent" &&
|
|
||||||
task.verifiedLength != null &&
|
|
||||||
task.verifiedLength != 0)
|
|
||||||
Text(
|
|
||||||
"校验中...(${FileSize.getSize(task.verifiedLength)})",
|
|
||||||
style: const TextStyle(fontSize: 14),
|
|
||||||
)
|
|
||||||
else if (task.status == "active")
|
|
||||||
Text(
|
|
||||||
"下载中... (${((task.completedLength ?? 0) * 100 / (task.totalLength ?? 1)).toStringAsFixed(4)}%)")
|
|
||||||
else
|
|
||||||
Text(
|
|
||||||
"状态:${model.statusMap[task.status]}",
|
|
||||||
style: const TextStyle(fontSize: 14),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
if (task.status == "active" &&
|
|
||||||
task.verifiedLength == null)
|
|
||||||
Text(
|
|
||||||
"ETA: ${formatter.format(DateTime.now().add(Duration(seconds: model.getETA(task))))}"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"已上传:${FileSize.getSize(task.uploadLength)}"),
|
|
||||||
Text(
|
|
||||||
"已下载:${FileSize.getSize(task.completedLength)}"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(width: 18),
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"↑:${FileSize.getSize(task.uploadSpeed)}/s"),
|
|
||||||
Text(
|
|
||||||
"↓:${FileSize.getSize(task.downloadSpeed)}/s"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(width: 32),
|
|
||||||
if (type != "stopped")
|
|
||||||
DropDownButton(
|
|
||||||
closeAfterClick: false,
|
|
||||||
title: const Padding(
|
|
||||||
padding: EdgeInsets.all(3),
|
|
||||||
child: Text('选项'),
|
|
||||||
),
|
|
||||||
items: [
|
|
||||||
if (task.status == "paused")
|
|
||||||
MenuFlyoutItem(
|
|
||||||
leading:
|
|
||||||
const Icon(FluentIcons.download),
|
|
||||||
text: const Text('继续下载'),
|
|
||||||
onPressed: () =>
|
|
||||||
model.resumeTask(task.gid))
|
|
||||||
else if (task.status == "active")
|
|
||||||
MenuFlyoutItem(
|
|
||||||
leading: const Icon(FluentIcons.pause),
|
|
||||||
text: const Text('暂停下载'),
|
|
||||||
onPressed: () =>
|
|
||||||
model.pauseTask(task.gid)),
|
|
||||||
const MenuFlyoutSeparator(),
|
|
||||||
MenuFlyoutItem(
|
|
||||||
leading: const Icon(
|
|
||||||
FluentIcons.chrome_close,
|
|
||||||
size: 14,
|
|
||||||
),
|
|
||||||
text: const Text('取消下载'),
|
|
||||||
onPressed: () =>
|
|
||||||
model.cancelTask(task.gid)),
|
|
||||||
MenuFlyoutItem(
|
|
||||||
leading: const Icon(
|
|
||||||
FluentIcons.folder_open,
|
|
||||||
size: 14,
|
|
||||||
),
|
|
||||||
text: const Text('打开文件夹'),
|
|
||||||
onPressed: () => model.openFolder(task)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
itemCount: model.getTasksLen(),
|
|
||||||
)),
|
|
||||||
Container(
|
|
||||||
color: FluentTheme.of(context).cardColor.withOpacity(.06),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 12, bottom: 3, top: 3),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
width: 8,
|
|
||||||
height: 8,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Aria2cManager.isAvailable
|
|
||||||
? Colors.green
|
|
||||||
: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(1000),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(
|
|
||||||
"下载: ${FileSize.getSize(model.globalStat?.downloadSpeed ?? 0)}/s 上传:${FileSize.getSize(model.globalStat?.uploadSpeed ?? 0)}/s",
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, DownloaderUIModel model) => "下载管理";
|
|
||||||
}
|
|
@ -1,251 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:aria2/aria2.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/aria2c.dart';
|
|
||||||
|
|
||||||
class DownloaderUIModel extends BaseUIModel {
|
|
||||||
List<Aria2Task> tasks = [];
|
|
||||||
List<Aria2Task> waitingTasks = [];
|
|
||||||
List<Aria2Task> stoppedTasks = [];
|
|
||||||
Aria2GlobalStat? globalStat;
|
|
||||||
|
|
||||||
final statusMap = {
|
|
||||||
"active": "下载中...",
|
|
||||||
"waiting": "等待中",
|
|
||||||
"paused": "已暂停",
|
|
||||||
"error": "下载失败",
|
|
||||||
"complete": "下载完成",
|
|
||||||
"removed": "已删除",
|
|
||||||
};
|
|
||||||
|
|
||||||
final listHeaderStatusMap = {
|
|
||||||
"active": "下载中",
|
|
||||||
"waiting": "等待中",
|
|
||||||
"stopped": "已结束",
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
|
||||||
initModel() {
|
|
||||||
super.initModel();
|
|
||||||
_listenDownloader();
|
|
||||||
}
|
|
||||||
|
|
||||||
onTapButton(String key) async {
|
|
||||||
switch (key) {
|
|
||||||
case "pause_all":
|
|
||||||
if (!Aria2cManager.isAvailable) return;
|
|
||||||
await Aria2cManager.getClient().pauseAll();
|
|
||||||
await Aria2cManager.getClient().saveSession();
|
|
||||||
return;
|
|
||||||
case "resume_all":
|
|
||||||
if (!Aria2cManager.isAvailable) return;
|
|
||||||
await Aria2cManager.getClient().unpauseAll();
|
|
||||||
await Aria2cManager.getClient().saveSession();
|
|
||||||
return;
|
|
||||||
case "cancel_all":
|
|
||||||
final userOK = await showConfirmDialogs(
|
|
||||||
context!, "确认取消全部任务?", const Text("如果文件不再需要,你可能需要手动删除下载文件。"));
|
|
||||||
if (userOK == true) {
|
|
||||||
if (!Aria2cManager.isAvailable) return;
|
|
||||||
try {
|
|
||||||
for (var value in [...tasks, ...waitingTasks]) {
|
|
||||||
await Aria2cManager.getClient().remove(value.gid!);
|
|
||||||
}
|
|
||||||
await Aria2cManager.getClient().saveSession();
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("DownloadsUIModel cancel_all Error: $e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "settings":
|
|
||||||
_showDownloadSpeedSettings();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_listenDownloader() async {
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
if (!mounted) return;
|
|
||||||
if (Aria2cManager.isAvailable) {
|
|
||||||
final aria2c = Aria2cManager.getClient();
|
|
||||||
tasks.clear();
|
|
||||||
tasks = await aria2c.tellActive();
|
|
||||||
waitingTasks = await aria2c.tellWaiting(0, 1000000);
|
|
||||||
stoppedTasks = await aria2c.tellStopped(0, 1000000);
|
|
||||||
globalStat = await aria2c.getGlobalStat();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("[DownloadsUIModel]._listenDownloader Error: $e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int getTasksLen() {
|
|
||||||
return tasks.length + waitingTasks.length + stoppedTasks.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
(Aria2Task, String, bool) getTaskAndType(int index) {
|
|
||||||
final tempList = <Aria2Task>[...tasks, ...waitingTasks, ...stoppedTasks];
|
|
||||||
if (index >= 0 && index < tasks.length) {
|
|
||||||
return (tempList[index], "active", index == 0);
|
|
||||||
}
|
|
||||||
if (index >= tasks.length && index < tasks.length + waitingTasks.length) {
|
|
||||||
return (tempList[index], "waiting", index == tasks.length);
|
|
||||||
}
|
|
||||||
if (index >= tasks.length + waitingTasks.length &&
|
|
||||||
index < tempList.length) {
|
|
||||||
return (
|
|
||||||
tempList[index],
|
|
||||||
"stopped",
|
|
||||||
index == tasks.length + waitingTasks.length
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw Exception("Index out of range or element is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
static MapEntry<String, String> getTaskTypeAndName(Aria2Task task) {
|
|
||||||
if (task.bittorrent == null) {
|
|
||||||
String uri = task.files?[0]['uris'][0]['uri'] as String;
|
|
||||||
return MapEntry("url", uri.split('/').last);
|
|
||||||
} else if (task.bittorrent != null) {
|
|
||||||
if (task.bittorrent!.containsKey('info')) {
|
|
||||||
var btName = task.bittorrent?["info"]["name"];
|
|
||||||
return MapEntry("torrent", btName ?? 'torrent');
|
|
||||||
} else {
|
|
||||||
return MapEntry("magnet", '[METADATA]${task.infoHash}');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return const MapEntry("metaLink", '==========metaLink============');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Aria2File> getFilesFormTask(Aria2Task task) {
|
|
||||||
List<Aria2File> l = [];
|
|
||||||
if (task.files != null) {
|
|
||||||
for (var element in task.files!) {
|
|
||||||
final f = Aria2File.fromJson(element);
|
|
||||||
l.add(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getETA(Aria2Task task) {
|
|
||||||
if (task.downloadSpeed == null || task.downloadSpeed == 0) return 0;
|
|
||||||
final remainingBytes =
|
|
||||||
(task.totalLength ?? 0) - (task.completedLength ?? 0);
|
|
||||||
return remainingBytes ~/ (task.downloadSpeed!);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> resumeTask(String? gid) async {
|
|
||||||
final aria2c = Aria2cManager.getClient();
|
|
||||||
if (gid != null) {
|
|
||||||
await aria2c.unpause(gid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> pauseTask(String? gid) async {
|
|
||||||
final aria2c = Aria2cManager.getClient();
|
|
||||||
|
|
||||||
if (gid != null) {
|
|
||||||
await aria2c.pause(gid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> cancelTask(String? gid) async {
|
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
if (gid != null) {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!, "确认取消下载?", const Text("如果文件不再需要,你可能需要手动删除下载文件。"));
|
|
||||||
if (ok == true) {
|
|
||||||
final aria2c = Aria2cManager.getClient();
|
|
||||||
await aria2c.remove(gid);
|
|
||||||
await Aria2cManager.getClient().saveSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
openFolder(Aria2Task task) {
|
|
||||||
final f = getFilesFormTask(task).firstOrNull;
|
|
||||||
if (f != null) {
|
|
||||||
SystemHelper.openDir(File(f.path!).absolute.path.replaceAll("/", "\\"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _showDownloadSpeedSettings() async {
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
|
|
||||||
final upCtrl = TextEditingController(
|
|
||||||
text: box.get("downloader_up_limit", defaultValue: ""));
|
|
||||||
final downCtrl = TextEditingController(
|
|
||||||
text: box.get("downloader_down_limit", defaultValue: ""));
|
|
||||||
|
|
||||||
final ifr = FilteringTextInputFormatter.allow(RegExp(r'^\d*[km]?$'));
|
|
||||||
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!,
|
|
||||||
"限速设置",
|
|
||||||
Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"SC 汉化盒子使用 p2p 网络来加速文件下载,如果您流量有限,可在此处将上传带宽设置为 1(byte)。",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.white.withOpacity(.6),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
const Text("请输入下载单位,如:1、100k、10m, 0或留空为不限速。"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
const Text("上传限速:"),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
TextFormBox(
|
|
||||||
placeholder: "1、100k、10m、0",
|
|
||||||
controller: upCtrl,
|
|
||||||
placeholderStyle: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
inputFormatters: [ifr],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
const Text("下载限速:"),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
TextFormBox(
|
|
||||||
placeholder: "1、100k、10m、0",
|
|
||||||
controller: downCtrl,
|
|
||||||
placeholderStyle: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
inputFormatters: [ifr],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Text(
|
|
||||||
"* P2P 上传仅在下载文件时进行,下载完成后会关闭 p2p 连接。如您想参与做种,请通过关于页面联系我们。",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Colors.white.withOpacity(.6),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
));
|
|
||||||
if (ok == true) {
|
|
||||||
await handleError(() => Aria2cManager.launchDaemon());
|
|
||||||
final aria2c = Aria2cManager.getClient();
|
|
||||||
final upByte = Aria2cManager.textToByte(upCtrl.text.trim());
|
|
||||||
final downByte = Aria2cManager.textToByte(downCtrl.text.trim());
|
|
||||||
final r = await handleError(() => aria2c.changeGlobalOption(Aria2Option()
|
|
||||||
..maxOverallUploadLimit = upByte
|
|
||||||
..maxOverallDownloadLimit = downByte));
|
|
||||||
if (r != null) {
|
|
||||||
await box.put('downloader_up_limit', upCtrl.text.trim());
|
|
||||||
await box.put('downloader_down_limit', downCtrl.text.trim());
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,255 +0,0 @@
|
|||||||
import 'package:flutter_tilt/flutter_tilt.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
import 'game_doctor_ui_model.dart';
|
|
||||||
|
|
||||||
class GameDoctorUI extends BaseUI<GameDoctorUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, GameDoctorUIModel model) {
|
|
||||||
return makeDefaultPage(context, model,
|
|
||||||
content: Stack(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
for (final item in const {
|
|
||||||
"rsi_log": "RSI启动器log",
|
|
||||||
"game_log": "游戏运行log",
|
|
||||||
}.entries)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 6, right: 6),
|
|
||||||
child: Button(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(FluentIcons.folder_open),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Text(item.value),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () => model.onTapButton(item.key)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (model.isChecking)
|
|
||||||
Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const ProgressRing(),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(model.lastScreenInfo)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))
|
|
||||||
else if (model.checkResult == null ||
|
|
||||||
model.checkResult!.isEmpty) ...[
|
|
||||||
const Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
SizedBox(height: 12),
|
|
||||||
Text("扫描完毕,没有找到问题!", maxLines: 1),
|
|
||||||
SizedBox(height: 64),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))
|
|
||||||
] else
|
|
||||||
...makeResult(context, model),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (model.isFixing)
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black.withAlpha(150),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const ProgressRing(),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(model.isFixingString.isNotEmpty
|
|
||||||
? model.isFixingString
|
|
||||||
: "正在处理..."),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
bottom: 20,
|
|
||||||
right: 20,
|
|
||||||
child: makeRescueBanner(context),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> makeResult(BuildContext context, GameDoctorUIModel model) {
|
|
||||||
return [
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Text(model.lastScreenInfo, maxLines: 1),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
"注意:本工具检测结果仅供参考,若您不理解以下操作,请提供截图给有经验的玩家!",
|
|
||||||
style: TextStyle(color: Colors.red, fontSize: 16),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
ListView.builder(
|
|
||||||
itemCount: model.checkResult!.length,
|
|
||||||
shrinkWrap: true,
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
final item = model.checkResult![index];
|
|
||||||
return makeResultItem(item, model);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 64),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeRescueBanner(BuildContext context) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () async {
|
|
||||||
await showToast(context,
|
|
||||||
"您即将前往由 深空治疗中心(QQ群号:536454632 ) 提供的游戏异常救援服务,主要解决游戏安装失败与频繁闪退,如游戏玩法问题,请勿加群。");
|
|
||||||
launchUrlString(
|
|
||||||
"https://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=-M4wEme_bCXbUGT4LFKLH0bAYTFt70Ad&authKey=vHVr0TNgRmKu%2BHwywoJV6EiLa7La2VX74Vkyixr05KA0H9TqB6qWlCdY%2B9jLQ4Ha&noverify=0&group_code=536454632");
|
|
||||||
},
|
|
||||||
child: Tilt(
|
|
||||||
shadowConfig: const ShadowConfig(maxIntensity: .2),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Image.asset("assets/rescue.png", width: 24, height: 24),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Text("需要帮助? 点击加群寻求免费人工支援!"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeResultItem(
|
|
||||||
MapEntry<String, String> item, GameDoctorUIModel model) {
|
|
||||||
final errorNames = {
|
|
||||||
"unSupport_system":
|
|
||||||
MapEntry("不支持的操作系统,游戏可能无法运行", "请升级您的系统 (${item.value})"),
|
|
||||||
"no_live_path": MapEntry("安装目录缺少LIVE文件夹,可能导致安装失败",
|
|
||||||
"点击修复为您创建 LIVE 文件夹,完成后重试安装。(${item.value})"),
|
|
||||||
"nvme_PhysicalBytes": MapEntry("新型 NVME 设备,与 RSI 启动器暂不兼容,可能导致安装失败",
|
|
||||||
"为注册表项添加 ForcedPhysicalSectorSizeInBytes 值 模拟旧设备。硬盘分区(${item.value})"),
|
|
||||||
"eac_file_miss": const MapEntry("EasyAntiCheat 文件丢失",
|
|
||||||
"未在 LIVE 文件夹找到 EasyAntiCheat 文件 或 文件不完整,请使用 RSI 启动器校验文件"),
|
|
||||||
"eac_not_install": const MapEntry("EasyAntiCheat 未安装 或 未正常退出",
|
|
||||||
"EasyAntiCheat 未安装,请点击修复为您一键安装。(在游戏正常启动并结束前,该问题会一直出现,若您因为其他原因游戏闪退,可忽略此条目)"),
|
|
||||||
"cn_user_name":
|
|
||||||
const MapEntry("中文用户名!", "中文用户名可能会导致游戏启动/安装错误! 点击修复按钮查看修改教程!"),
|
|
||||||
"cn_install_path": MapEntry("中文安装路径!",
|
|
||||||
"中文安装路径!这可能会导致游戏 启动/安装 错误!(${item.value}),请在RSI启动器更换安装路径。"),
|
|
||||||
"low_ram": MapEntry(
|
|
||||||
"物理内存过低", "您至少需要 16GB 的物理内存(Memory)才可运行此游戏。(当前大小:${item.value})"),
|
|
||||||
};
|
|
||||||
bool isCheckedError = errorNames.containsKey(item.key);
|
|
||||||
|
|
||||||
if (isCheckedError) {
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
margin: const EdgeInsets.only(bottom: 12),
|
|
||||||
child: ListTile(
|
|
||||||
title: Text(
|
|
||||||
errorNames[item.key]?.key ?? "",
|
|
||||||
style: const TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
subtitle: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 4, bottom: 4),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
"修复建议: ${errorNames[item.key]?.value ?? "暂无解决方法,请截图反馈"}",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.7)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
trailing: Button(
|
|
||||||
onPressed: (errorNames[item.key]?.value == null || model.isFixing)
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
await model.doFix(item);
|
|
||||||
model.isFixing = false;
|
|
||||||
model.notifyListeners();
|
|
||||||
},
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.only(left: 8, right: 8, top: 4, bottom: 4),
|
|
||||||
child: Text("修复"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final isSubTitleUrl = item.value.startsWith("https://");
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
margin: const EdgeInsets.only(bottom: 12),
|
|
||||||
child: ListTile(
|
|
||||||
title: Text(
|
|
||||||
item.key,
|
|
||||||
style: const TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
subtitle: isSubTitleUrl
|
|
||||||
? null
|
|
||||||
: Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
item.value,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.7)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
trailing: isSubTitleUrl
|
|
||||||
? Button(
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString(item.value);
|
|
||||||
},
|
|
||||||
child: const Padding(
|
|
||||||
padding:
|
|
||||||
EdgeInsets.only(left: 8, right: 8, top: 4, bottom: 4),
|
|
||||||
child: Text("查看解决方案"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, GameDoctorUIModel model) =>
|
|
||||||
"一键诊断 > ${model.scInstalledPath}";
|
|
||||||
}
|
|
@ -1,260 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
class GameDoctorUIModel extends BaseUIModel {
|
|
||||||
String scInstalledPath = "";
|
|
||||||
|
|
||||||
GameDoctorUIModel(this.scInstalledPath);
|
|
||||||
|
|
||||||
String _lastScreenInfo = "";
|
|
||||||
|
|
||||||
String get lastScreenInfo => _lastScreenInfo;
|
|
||||||
|
|
||||||
List<MapEntry<String, String>>? checkResult;
|
|
||||||
|
|
||||||
set lastScreenInfo(String info) {
|
|
||||||
_lastScreenInfo = info;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isChecking = false;
|
|
||||||
|
|
||||||
bool isFixing = false;
|
|
||||||
String isFixingString = "";
|
|
||||||
|
|
||||||
final cnExp = RegExp(r"[^\x00-\xff]");
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initModel() {
|
|
||||||
doCheck()?.call();
|
|
||||||
super.initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidCallback? doCheck() {
|
|
||||||
if (isChecking) return null;
|
|
||||||
return () async {
|
|
||||||
isChecking = true;
|
|
||||||
lastScreenInfo = "正在分析...";
|
|
||||||
await _statCheck();
|
|
||||||
isChecking = false;
|
|
||||||
notifyListeners();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _statCheck() async {
|
|
||||||
checkResult = [];
|
|
||||||
// TODO for debug
|
|
||||||
// checkResult?.add(const MapEntry("unSupport_system", "android"));
|
|
||||||
// checkResult?.add(const MapEntry("nvme_PhysicalBytes", "C"));
|
|
||||||
// checkResult?.add(const MapEntry("no_live_path", ""));
|
|
||||||
|
|
||||||
await _checkPreInstall();
|
|
||||||
await _checkEAC();
|
|
||||||
await _checkGameRunningLog();
|
|
||||||
|
|
||||||
if (checkResult!.isEmpty) {
|
|
||||||
checkResult = null;
|
|
||||||
lastScreenInfo = "分析完毕,没有发现问题";
|
|
||||||
} else {
|
|
||||||
lastScreenInfo = "分析完毕,发现 ${checkResult!.length} 个问题";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scInstalledPath == "not_install" && (checkResult?.isEmpty ?? true)) {
|
|
||||||
showToast(context!, "扫描完毕,没有发现问题,若仍然安装失败,请尝试使用工具箱中的 RSI启动器管理员模式。");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _checkGameRunningLog() async {
|
|
||||||
if (scInstalledPath == "not_install") return;
|
|
||||||
lastScreenInfo = "正在检查:Game.log";
|
|
||||||
final logs = await SCLoggerHelper.getGameRunningLogs(scInstalledPath);
|
|
||||||
if (logs == null) return;
|
|
||||||
final info = SCLoggerHelper.getGameRunningLogInfo(logs);
|
|
||||||
if (info != null) {
|
|
||||||
if (info.key != "_") {
|
|
||||||
checkResult?.add(MapEntry("游戏异常退出:${info.key}", info.value));
|
|
||||||
} else {
|
|
||||||
checkResult
|
|
||||||
?.add(MapEntry("游戏异常退出:未知异常", "info:${info.value},请点击右下角加群反馈。"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _checkEAC() async {
|
|
||||||
if (scInstalledPath == "not_install") return;
|
|
||||||
lastScreenInfo = "正在检查:EAC";
|
|
||||||
final eacPath = "$scInstalledPath\\EasyAntiCheat";
|
|
||||||
final eacJsonPath = "$eacPath\\Settings.json";
|
|
||||||
if (!await Directory(eacPath).exists() ||
|
|
||||||
!await File(eacJsonPath).exists()) {
|
|
||||||
checkResult?.add(const MapEntry("eac_file_miss", ""));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final eacJsonData = await File(eacJsonPath).readAsBytes();
|
|
||||||
final Map eacJson = json.decode(utf8.decode(eacJsonData));
|
|
||||||
final eacID = eacJson["productid"];
|
|
||||||
final eacDeploymentId = eacJson["deploymentid"];
|
|
||||||
if (eacID == null || eacDeploymentId == null) {
|
|
||||||
checkResult?.add(const MapEntry("eac_file_miss", ""));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final eacFilePath =
|
|
||||||
"${Platform.environment["appdata"]}\\EasyAntiCheat\\$eacID\\$eacDeploymentId\\anticheatlauncher.log";
|
|
||||||
if (!await File(eacFilePath).exists()) {
|
|
||||||
checkResult?.add(MapEntry("eac_not_install", eacPath));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _checkPreInstall() async {
|
|
||||||
lastScreenInfo = "正在检查:运行环境";
|
|
||||||
if (!(Platform.operatingSystemVersion.contains("Windows 10") ||
|
|
||||||
Platform.operatingSystemVersion.contains("Windows 11"))) {
|
|
||||||
checkResult
|
|
||||||
?.add(MapEntry("unSupport_system", Platform.operatingSystemVersion));
|
|
||||||
lastScreenInfo = "不支持的操作系统:${Platform.operatingSystemVersion}";
|
|
||||||
await showToast(context!, lastScreenInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cnExp.hasMatch(await SCLoggerHelper.getLogFilePath() ?? "")) {
|
|
||||||
checkResult?.add(const MapEntry("cn_user_name", ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查 RAM
|
|
||||||
final ramSize = await SystemHelper.getSystemMemorySizeGB();
|
|
||||||
if (ramSize < 16) {
|
|
||||||
checkResult?.add(MapEntry("low_ram", "$ramSize"));
|
|
||||||
}
|
|
||||||
|
|
||||||
lastScreenInfo = "正在检查:安装信息";
|
|
||||||
// 检查安装分区
|
|
||||||
try {
|
|
||||||
final listData = await SCLoggerHelper.getGameInstallPath(
|
|
||||||
await SCLoggerHelper.getLauncherLogList() ?? []);
|
|
||||||
final p = [];
|
|
||||||
final checkedPath = [];
|
|
||||||
for (var installPath in listData) {
|
|
||||||
if (!checkedPath.contains(installPath)) {
|
|
||||||
if (cnExp.hasMatch(installPath)) {
|
|
||||||
checkResult?.add(MapEntry("cn_install_path", installPath));
|
|
||||||
}
|
|
||||||
if (scInstalledPath == "not_install") {
|
|
||||||
checkedPath.add(installPath);
|
|
||||||
if (!await Directory(installPath).exists()) {
|
|
||||||
checkResult?.add(MapEntry("no_live_path", installPath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final tp = installPath.split(":")[0];
|
|
||||||
if (!p.contains(tp)) {
|
|
||||||
p.add(tp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// call check
|
|
||||||
for (var element in p) {
|
|
||||||
var result = await Process.run('powershell', [
|
|
||||||
"(fsutil fsinfo sectorinfo $element: | Select-String 'PhysicalBytesPerSectorForPerformance').ToString().Split(':')[1].Trim()"
|
|
||||||
]);
|
|
||||||
dPrint(
|
|
||||||
"fsutil info sector info: ->>> ${result.stdout.toString().trim()}");
|
|
||||||
if (result.stderr == "") {
|
|
||||||
final rs = result.stdout.toString().trim();
|
|
||||||
final physicalBytesPerSectorForPerformance = (int.tryParse(rs) ?? 0);
|
|
||||||
if (physicalBytesPerSectorForPerformance > 4096) {
|
|
||||||
checkResult?.add(MapEntry("nvme_PhysicalBytes", element));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dPrint(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> doFix(MapEntry<String, String> item) async {
|
|
||||||
isFixing = true;
|
|
||||||
notifyListeners();
|
|
||||||
switch (item.key) {
|
|
||||||
case "unSupport_system":
|
|
||||||
showToast(context!, "若您的硬件达标,请尝试安装最新的 Windows 系统。");
|
|
||||||
return;
|
|
||||||
case "no_live_path":
|
|
||||||
try {
|
|
||||||
await Directory(item.value).create(recursive: true);
|
|
||||||
showToast(context!, "创建文件夹成功,请尝试继续下载游戏!");
|
|
||||||
checkResult?.remove(item);
|
|
||||||
notifyListeners();
|
|
||||||
} catch (e) {
|
|
||||||
showToast(context!, "创建文件夹失败,请尝试手动创建。\n目录:${item.value} \n错误:$e");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "nvme_PhysicalBytes":
|
|
||||||
final r = await SystemHelper.addNvmePatch();
|
|
||||||
if (r == "") {
|
|
||||||
showToast(context!,
|
|
||||||
"修复成功,请尝试重启后继续安装游戏! 若注册表修改操作导致其他软件出现兼容问题,请使用 工具 中的 NVME 注册表清理。");
|
|
||||||
checkResult?.remove(item);
|
|
||||||
notifyListeners();
|
|
||||||
} else {
|
|
||||||
showToast(context!, "修复失败,$r");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "eac_file_miss":
|
|
||||||
showToast(
|
|
||||||
context!, "未在 LIVE 文件夹找到 EasyAntiCheat 文件 或 文件不完整,请使用 RSI 启动器校验文件");
|
|
||||||
return;
|
|
||||||
case "eac_not_install":
|
|
||||||
final eacJsonPath = "${item.value}\\Settings.json";
|
|
||||||
final eacJsonData = await File(eacJsonPath).readAsBytes();
|
|
||||||
final Map eacJson = json.decode(utf8.decode(eacJsonData));
|
|
||||||
final eacID = eacJson["productid"];
|
|
||||||
try {
|
|
||||||
var result = await Process.run(
|
|
||||||
"${item.value}\\EasyAntiCheat_EOS_Setup.exe", ["install", eacID]);
|
|
||||||
dPrint("${item.value}\\EasyAntiCheat_EOS_Setup.exe install $eacID");
|
|
||||||
if (result.stderr == "") {
|
|
||||||
showToast(context!, "修复成功,请尝试启动游戏。(若问题无法解决,请使用工具箱的 《重装 EAC》)");
|
|
||||||
checkResult?.remove(item);
|
|
||||||
notifyListeners();
|
|
||||||
} else {
|
|
||||||
showToast(context!, "修复失败,${result.stderr}");
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
showToast(context!, "修复失败,$e");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "cn_user_name":
|
|
||||||
showToast(context!, "即将跳转,教程来自互联网,请谨慎操作...");
|
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
launchUrlString(
|
|
||||||
"https://btfy.eu.org/?q=5L+u5pS5d2luZG93c+eUqOaIt+WQjeS7juS4reaWh+WIsOiLseaWhw==");
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
showToast(context!, "该问题暂不支持自动处理,请提供截图寻求帮助");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onTapButton(String key) async {
|
|
||||||
switch (key) {
|
|
||||||
case "rsi_log":
|
|
||||||
final path = await SCLoggerHelper.getLogFilePath();
|
|
||||||
if (path == null) return;
|
|
||||||
SystemHelper.openDir(path);
|
|
||||||
return;
|
|
||||||
case "game_log":
|
|
||||||
if (scInstalledPath == "not_install") {
|
|
||||||
showToast(context!, "请在首页选择游戏安装目录。");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SystemHelper.openDir("$scInstalledPath\\Game.log");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,727 +0,0 @@
|
|||||||
import 'package:card_swiper/card_swiper.dart';
|
|
||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
|
||||||
import 'package:flutter_tilt/flutter_tilt.dart';
|
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/widgets/cache_image.dart';
|
|
||||||
import 'package:starcitizen_doctor/widgets/countdown_time_text.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
import 'home_ui_model.dart';
|
|
||||||
|
|
||||||
class HomeUI extends BaseUI<HomeUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, HomeUIModel model) {
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
Center(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
if (model.appPlacardData != null) ...[
|
|
||||||
InfoBar(
|
|
||||||
title: Text("${model.appPlacardData?.title}"),
|
|
||||||
content: Text("${model.appPlacardData?.content}"),
|
|
||||||
severity: InfoBarSeverity.info,
|
|
||||||
action: model.appPlacardData?.link == null
|
|
||||||
? null
|
|
||||||
: Button(
|
|
||||||
child: const Text('查看详情'),
|
|
||||||
onPressed: () => model.showPlacard(),
|
|
||||||
),
|
|
||||||
onClose: model.appPlacardData?.alwaysShow == true
|
|
||||||
? null
|
|
||||||
: () => model.closePlacard(),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
],
|
|
||||||
...makeIndex(context, model)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (model.isFixing)
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black.withAlpha(150),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const ProgressRing(),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(model.isFixingString.isNotEmpty
|
|
||||||
? model.isFixingString
|
|
||||||
: "正在处理..."),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> makeIndex(BuildContext context, HomeUIModel model) {
|
|
||||||
const double width = 280;
|
|
||||||
return [
|
|
||||||
Stack(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 64, bottom: 0),
|
|
||||||
child: SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 30),
|
|
||||||
child: Image.asset(
|
|
||||||
"assets/sc_logo.png",
|
|
||||||
fit: BoxFit.fitHeight,
|
|
||||||
height: 260,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
makeGameStatusCard(context, model, 340)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: 0,
|
|
||||||
left: 24,
|
|
||||||
child: makeLeftColumn(context, model, width),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
right: 24,
|
|
||||||
top: 0,
|
|
||||||
child: makeNewsCard(context, model),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 24, right: 24),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Text("安装位置:"),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Expanded(
|
|
||||||
child: ComboBox<String>(
|
|
||||||
value: model.scInstalledPath,
|
|
||||||
items: [
|
|
||||||
const ComboBoxItem(
|
|
||||||
value: "not_install",
|
|
||||||
child: Text("未安装 或 安装失败"),
|
|
||||||
),
|
|
||||||
for (final path in model.scInstallPaths)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: path,
|
|
||||||
child: Text(path),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: (v) {
|
|
||||||
model.scInstalledPath = v!;
|
|
||||||
model.notifyListeners();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
AnimatedSize(
|
|
||||||
duration: const Duration(milliseconds: 130),
|
|
||||||
child: model.isRsiLauncherStarting
|
|
||||||
? const ProgressRing()
|
|
||||||
: Button(
|
|
||||||
onPressed: model.appWebLocalizationVersionsData == null
|
|
||||||
? null
|
|
||||||
: () => model.launchRSI(),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(6),
|
|
||||||
child: Icon(
|
|
||||||
model.isCurGameRunning
|
|
||||||
? FluentIcons.stop_solid
|
|
||||||
: FluentIcons.play,
|
|
||||||
color: model.isCurGameRunning
|
|
||||||
? Colors.red.withOpacity(.8)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.folder_open),
|
|
||||||
),
|
|
||||||
onPressed: () => model.openDir(model.scInstalledPath)),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
onPressed: model.reScanPath,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.refresh),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(model.lastScreenInfo, maxLines: 1),
|
|
||||||
makeIndexActionLists(context, model),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeLeftColumn(BuildContext context, HomeUIModel model, double width) {
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
color: FluentTheme.of(context).cardColor.withOpacity(.03),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
makeWebViewButton(model,
|
|
||||||
icon: SvgPicture.asset(
|
|
||||||
"assets/rsi.svg",
|
|
||||||
colorFilter: makeSvgColor(Colors.white),
|
|
||||||
height: 18,
|
|
||||||
),
|
|
||||||
name: "星际公民官网汉化",
|
|
||||||
webTitle: "星际公民官网汉化",
|
|
||||||
webURL: "https://robertsspaceindustries.com",
|
|
||||||
info: "罗伯茨航天工业公司,万物的起源",
|
|
||||||
useLocalization: true,
|
|
||||||
width: width,
|
|
||||||
touchKey: "webLocalization_rsi"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeWebViewButton(model,
|
|
||||||
icon: Row(
|
|
||||||
children: [
|
|
||||||
SvgPicture.asset(
|
|
||||||
"assets/uex.svg",
|
|
||||||
height: 18,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
name: "UEX 汉化",
|
|
||||||
webTitle: "UEX 汉化",
|
|
||||||
webURL: "https://uexcorp.space/",
|
|
||||||
info: "采矿、精炼、贸易计算器、价格、船信息",
|
|
||||||
useLocalization: true,
|
|
||||||
width: width,
|
|
||||||
touchKey: "webLocalization_uex"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeWebViewButton(model,
|
|
||||||
icon: Row(
|
|
||||||
children: [
|
|
||||||
Image.asset(
|
|
||||||
"assets/dps.png",
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
name: "DPS计算器汉化",
|
|
||||||
webTitle: "DPS计算器汉化",
|
|
||||||
webURL: "https://www.erkul.games/live/calculator",
|
|
||||||
info: "在线改船,查询伤害数值和配件购买地点",
|
|
||||||
useLocalization: true,
|
|
||||||
width: width,
|
|
||||||
touchKey: "webLocalization_dps"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
const Text("外部浏览器拓展:"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Button(
|
|
||||||
child:
|
|
||||||
const FaIcon(FontAwesomeIcons.chrome, size: 18),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString(
|
|
||||||
"https://chrome.google.com/webstore/detail/gocnjckojmledijgmadmacoikibcggja?authuser=0&hl=zh-CN");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
child: const FaIcon(FontAwesomeIcons.edge, size: 18),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString(
|
|
||||||
"https://microsoftedge.microsoft.com/addons/detail/lipbbcckldklpdcpfagicipecaacikgi");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
child: const FaIcon(FontAwesomeIcons.firefoxBrowser,
|
|
||||||
size: 18),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString(
|
|
||||||
"https://addons.mozilla.org/zh-CN/firefox/"
|
|
||||||
"addon/%E6%98%9F%E9%99%85%E5%85%AC%E6%B0%91%E7%9B%92%E5%AD%90%E6%B5%8F%E8%A7%88%E5%99%A8%E6%8B%93%E5%B1%95/");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
child:
|
|
||||||
const FaIcon(FontAwesomeIcons.github, size: 18),
|
|
||||||
onPressed: () {
|
|
||||||
launchUrlString(
|
|
||||||
"https://github.com/StarCitizenToolBox/StarCitizenBoxBrowserEx");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
makeActivityBanner(context, model, width),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (model.appWebLocalizationVersionsData == null)
|
|
||||||
Positioned.fill(
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black.withOpacity(.3),
|
|
||||||
borderRadius: BorderRadius.circular(12)),
|
|
||||||
child: const Center(
|
|
||||||
child: ProgressRing(),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeNewsCard(BuildContext context, HomeUIModel model) {
|
|
||||||
return ScrollConfiguration(
|
|
||||||
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
|
||||||
child: Container(
|
|
||||||
width: 316,
|
|
||||||
height: 386,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white.withOpacity(.1),
|
|
||||||
borderRadius: BorderRadius.circular(12)),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
height: 190,
|
|
||||||
width: 316,
|
|
||||||
child: Tilt(
|
|
||||||
shadowConfig: const ShadowConfig(maxIntensity: .3),
|
|
||||||
borderRadius: const BorderRadius.only(
|
|
||||||
topLeft: Radius.circular(12),
|
|
||||||
topRight: Radius.circular(12),
|
|
||||||
),
|
|
||||||
child: model.rssVideoItems == null
|
|
||||||
? Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white.withOpacity(.1)),
|
|
||||||
child: makeLoading(context),
|
|
||||||
)
|
|
||||||
: Swiper(
|
|
||||||
itemCount: model.rssVideoItems?.length ?? 0,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final item = model.rssVideoItems![index];
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
if (item.link != null) {
|
|
||||||
launchUrlString(item.link!);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: CacheNetImage(
|
|
||||||
url: model.getRssImage(item),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
autoplay: true,
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
const SizedBox(height: 1),
|
|
||||||
if (model.rssTextItems == null)
|
|
||||||
makeLoading(context)
|
|
||||||
else
|
|
||||||
ListView.builder(
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
|
||||||
shrinkWrap: true,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
final item = model.rssTextItems![index];
|
|
||||||
return Tilt(
|
|
||||||
shadowConfig: const ShadowConfig(maxIntensity: .3),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
if (item.link != null) {
|
|
||||||
launchUrlString(item.link!);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 12, right: 12, top: 4, bottom: 4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
getRssIcon(item.link ?? ""),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
"${model.handleTitle(item.title)}",
|
|
||||||
textAlign: TextAlign.start,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: const TextStyle(fontSize: 12.2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Icon(
|
|
||||||
FluentIcons.chevron_right,
|
|
||||||
size: 12,
|
|
||||||
color: Colors.white.withOpacity(.4),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
},
|
|
||||||
itemCount: model.rssTextItems?.length,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget getRssIcon(String url) {
|
|
||||||
if (url.startsWith("https://tieba.baidu.com")) {
|
|
||||||
return SvgPicture.asset("assets/tieba.svg", width: 14, height: 14);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url.startsWith("https://www.bilibili.com")) {
|
|
||||||
return const FaIcon(
|
|
||||||
FontAwesomeIcons.bilibili,
|
|
||||||
size: 14,
|
|
||||||
color: Color.fromRGBO(0, 161, 214, 1),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return const FaIcon(FontAwesomeIcons.rss, size: 14);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeIndexActionLists(BuildContext context, HomeUIModel model) {
|
|
||||||
final items = [
|
|
||||||
_HomeItemData("auto_check", "一键诊断", "一键诊断星际公民常见问题",
|
|
||||||
FluentIcons.auto_deploy_settings),
|
|
||||||
_HomeItemData(
|
|
||||||
"localization", "汉化管理", "快捷安装汉化资源", FluentIcons.locale_language),
|
|
||||||
_HomeItemData("performance", "性能优化", "调整引擎配置文件,优化游戏性能",
|
|
||||||
FluentIcons.process_meta_task),
|
|
||||||
];
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(24),
|
|
||||||
child: AlignedGridView.count(
|
|
||||||
crossAxisCount: 3,
|
|
||||||
mainAxisSpacing: 12,
|
|
||||||
crossAxisSpacing: 12,
|
|
||||||
itemCount: items.length,
|
|
||||||
shrinkWrap: true,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final item = items.elementAt(index);
|
|
||||||
return HoverButton(
|
|
||||||
onPressed: () => model.onMenuTap(item.key),
|
|
||||||
builder: (BuildContext context, Set<ButtonStates> states) {
|
|
||||||
return Container(
|
|
||||||
width: 300,
|
|
||||||
height: 120,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
color: states.isHovering
|
|
||||||
? FluentTheme.of(context).cardColor.withOpacity(.1)
|
|
||||||
: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white.withOpacity(.2),
|
|
||||||
borderRadius: BorderRadius.circular(1000)),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: Icon(
|
|
||||||
item.icon,
|
|
||||||
size: 26,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
item.name,
|
|
||||||
style: const TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(item.infoString),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
if (item.key == "localization" &&
|
|
||||||
model.localizationUpdateInfo != null)
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 3, bottom: 3, left: 8, right: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red,
|
|
||||||
borderRadius: BorderRadius.circular(12)),
|
|
||||||
child:
|
|
||||||
Text(model.localizationUpdateInfo?.key ?? " "),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Icon(
|
|
||||||
FluentIcons.chevron_right,
|
|
||||||
size: 16,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, HomeUIModel model) => "HOME";
|
|
||||||
|
|
||||||
Widget makeWebViewButton(HomeUIModel model,
|
|
||||||
{required Widget icon,
|
|
||||||
required String name,
|
|
||||||
required String webTitle,
|
|
||||||
required String webURL,
|
|
||||||
required bool useLocalization,
|
|
||||||
required double width,
|
|
||||||
String? info,
|
|
||||||
String? touchKey}) {
|
|
||||||
return Tilt(
|
|
||||||
shadowConfig: const ShadowConfig(maxIntensity: .3),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
if (touchKey != null) {
|
|
||||||
AnalyticsApi.touch(touchKey);
|
|
||||||
}
|
|
||||||
model.goWebView(webTitle, webURL, useLocalization: true);
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
width: width,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
icon,
|
|
||||||
Text(
|
|
||||||
name,
|
|
||||||
style: const TextStyle(fontSize: 14),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (info != null)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 4),
|
|
||||||
child: Text(
|
|
||||||
info,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Icon(
|
|
||||||
FluentIcons.chevron_right,
|
|
||||||
size: 14,
|
|
||||||
color: Colors.white.withOpacity(.6),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeGameStatusCard(
|
|
||||||
BuildContext context, HomeUIModel model, double width) {
|
|
||||||
return Tilt(
|
|
||||||
shadowConfig: const ShadowConfig(maxIntensity: .2),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
model.goWebView(
|
|
||||||
"RSI 服务器状态", "https://status.robertsspaceindustries.com/",
|
|
||||||
useLocalization: true);
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
width: width,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Column(children: [
|
|
||||||
if (model.scServerStatus == null)
|
|
||||||
makeLoading(context, width: 20)
|
|
||||||
else
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
const Text("状态:"),
|
|
||||||
for (final item in model.scServerStatus ?? [])
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
height: 14,
|
|
||||||
child: Center(
|
|
||||||
child: Icon(
|
|
||||||
FontAwesomeIcons.solidCircle,
|
|
||||||
color: model.isRSIServerStatusOK(item)
|
|
||||||
? Colors.green
|
|
||||||
: Colors.red,
|
|
||||||
size: 12,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 5),
|
|
||||||
Text(
|
|
||||||
"${model.statusCnName[item["name"]] ?? item["name"]}",
|
|
||||||
style: const TextStyle(fontSize: 13),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Icon(
|
|
||||||
FluentIcons.chevron_right,
|
|
||||||
size: 12,
|
|
||||||
color: Colors.white.withOpacity(.4),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeActivityBanner(
|
|
||||||
BuildContext context, HomeUIModel model, double width) {
|
|
||||||
return Tilt(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
shadowConfig: const ShadowConfig(disable: true),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => model.onTapFestival(),
|
|
||||||
child: Container(
|
|
||||||
width: width + 24,
|
|
||||||
decoration: BoxDecoration(color: FluentTheme.of(context).cardColor),
|
|
||||||
child: Padding(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.only(left: 12, right: 12, top: 8, bottom: 8),
|
|
||||||
child: (model.countdownFestivalListData == null)
|
|
||||||
? SizedBox(
|
|
||||||
width: width,
|
|
||||||
height: 62,
|
|
||||||
child: const Center(
|
|
||||||
child: ProgressRing(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: SizedBox(
|
|
||||||
width: width,
|
|
||||||
height: 62,
|
|
||||||
child: Swiper(
|
|
||||||
itemCount: model.countdownFestivalListData!.length,
|
|
||||||
autoplay: true,
|
|
||||||
autoplayDelay: 5000,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final item = model.countdownFestivalListData![index];
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
|
||||||
if (item.icon != null && item.icon != "") ...[
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(1000),
|
|
||||||
child: Image.asset(
|
|
||||||
"assets/countdown/${item.icon}",
|
|
||||||
width: 48,
|
|
||||||
height: 48,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
item.name ?? "",
|
|
||||||
style: const TextStyle(fontSize: 15),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 3),
|
|
||||||
CountdownTimeText(
|
|
||||||
targetTime:
|
|
||||||
DateTime.fromMillisecondsSinceEpoch(
|
|
||||||
item.time ?? 0),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Icon(
|
|
||||||
FluentIcons.chevron_right,
|
|
||||||
size: 14,
|
|
||||||
color: Colors.white.withOpacity(.6),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomeItemData {
|
|
||||||
String key;
|
|
||||||
|
|
||||||
_HomeItemData(this.key, this.name, this.infoString, this.icon);
|
|
||||||
|
|
||||||
String name;
|
|
||||||
String infoString;
|
|
||||||
IconData icon;
|
|
||||||
}
|
|
@ -1,481 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:dart_rss/dart_rss.dart';
|
|
||||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/rss.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/app_placard_data.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/app_web_localization_versions_data.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/countdown_festival_item_data.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/countdown/countdown_dialog_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/login/login_dialog_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/login/login_dialog_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/performance/performance_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/webview/webview.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/webview/webview_localization_capture_ui_model.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
import 'package:html/parser.dart' as html;
|
|
||||||
import 'package:html/dom.dart' as html_dom;
|
|
||||||
import 'package:windows_ui/windows_ui.dart';
|
|
||||||
|
|
||||||
import 'countdown/countdown_dialog_ui.dart';
|
|
||||||
import 'game_doctor/game_doctor_ui.dart';
|
|
||||||
import 'game_doctor/game_doctor_ui_model.dart';
|
|
||||||
import 'localization/localization_ui.dart';
|
|
||||||
import 'performance/performance_ui.dart';
|
|
||||||
import 'webview/webview_localization_capture_ui.dart';
|
|
||||||
|
|
||||||
class HomeUIModel extends BaseUIModel {
|
|
||||||
var scInstalledPath = "not_install";
|
|
||||||
|
|
||||||
List<String> scInstallPaths = [];
|
|
||||||
|
|
||||||
String lastScreenInfo = "";
|
|
||||||
|
|
||||||
bool isFixing = false;
|
|
||||||
String isFixingString = "";
|
|
||||||
|
|
||||||
final Map<String, bool> _isGameRunning = {};
|
|
||||||
|
|
||||||
bool get isCurGameRunning => _isGameRunning[scInstalledPath] ?? false;
|
|
||||||
|
|
||||||
List<RssItem>? rssVideoItems;
|
|
||||||
List<RssItem>? rssTextItems;
|
|
||||||
|
|
||||||
AppWebLocalizationVersionsData? appWebLocalizationVersionsData;
|
|
||||||
|
|
||||||
List<CountdownFestivalItemData>? countdownFestivalListData;
|
|
||||||
|
|
||||||
MapEntry<String, bool>? localizationUpdateInfo;
|
|
||||||
|
|
||||||
bool _isSendLocalizationUpdateNotification = false;
|
|
||||||
|
|
||||||
AppPlacardData? appPlacardData;
|
|
||||||
|
|
||||||
List? scServerStatus;
|
|
||||||
|
|
||||||
Timer? serverUpdateTimer;
|
|
||||||
Timer? appUpdateTimer;
|
|
||||||
|
|
||||||
final statusCnName = const {
|
|
||||||
"Platform": "平台",
|
|
||||||
"Persistent Universe": "持续宇宙",
|
|
||||||
"Electronic Access": "电子访问",
|
|
||||||
"Arena Commander": "竞技场指挥官"
|
|
||||||
};
|
|
||||||
|
|
||||||
bool isRsiLauncherStarting = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future loadData() async {
|
|
||||||
if (AppConf.networkVersionData == null) return;
|
|
||||||
try {
|
|
||||||
final r = await Api.getAppPlacard();
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
final version = box.get("close_placard", defaultValue: "");
|
|
||||||
if (r.enable == true) {
|
|
||||||
if (r.alwaysShow != true && version == r.version) {
|
|
||||||
} else {
|
|
||||||
appPlacardData = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateSCServerStatus();
|
|
||||||
notifyListeners();
|
|
||||||
appWebLocalizationVersionsData = AppWebLocalizationVersionsData.fromJson(
|
|
||||||
json.decode((await RSHttp.getText(
|
|
||||||
"${URLConf.webTranslateHomeUrl}/versions.json"))));
|
|
||||||
countdownFestivalListData = await Api.getFestivalCountdownList();
|
|
||||||
notifyListeners();
|
|
||||||
_loadRRS();
|
|
||||||
} catch (e) {
|
|
||||||
dPrint(e);
|
|
||||||
}
|
|
||||||
// check Localization update
|
|
||||||
_checkLocalizationUpdate();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initModel() {
|
|
||||||
reScanPath();
|
|
||||||
serverUpdateTimer = Timer.periodic(
|
|
||||||
const Duration(minutes: 10),
|
|
||||||
(timer) {
|
|
||||||
updateSCServerStatus();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
appUpdateTimer = Timer.periodic(const Duration(minutes: 30), (timer) {
|
|
||||||
_checkLocalizationUpdate();
|
|
||||||
});
|
|
||||||
super.initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
serverUpdateTimer?.cancel();
|
|
||||||
serverUpdateTimer = null;
|
|
||||||
appUpdateTimer?.cancel();
|
|
||||||
appUpdateTimer = null;
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> reScanPath() async {
|
|
||||||
scInstallPaths.clear();
|
|
||||||
scInstalledPath = "not_install";
|
|
||||||
lastScreenInfo = "正在扫描 ...";
|
|
||||||
try {
|
|
||||||
final listData = await SCLoggerHelper.getLauncherLogList();
|
|
||||||
if (listData == null) {
|
|
||||||
lastScreenInfo = "获取log失败!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scInstallPaths = await SCLoggerHelper.getGameInstallPath(listData,
|
|
||||||
withVersion: ["LIVE", "PTU", "EPTU"], checkExists: true);
|
|
||||||
if (scInstallPaths.isNotEmpty) {
|
|
||||||
scInstalledPath = scInstallPaths.first;
|
|
||||||
}
|
|
||||||
lastScreenInfo = "扫描完毕,共找到 ${scInstallPaths.length} 个有效安装目录";
|
|
||||||
} catch (e) {
|
|
||||||
lastScreenInfo = "解析 log 文件失败!";
|
|
||||||
AnalyticsApi.touch("error_launchLogs");
|
|
||||||
showToast(context!,
|
|
||||||
"解析 log 文件失败! \n请关闭游戏,退出RSI启动器后重试,若仍有问题,请使用工具箱中的 RSI Launcher log 修复。");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateSCServerStatus() async {
|
|
||||||
try {
|
|
||||||
final s = await Api.getScServerStatus();
|
|
||||||
dPrint("updateSCServerStatus===$s");
|
|
||||||
scServerStatus = s;
|
|
||||||
notifyListeners();
|
|
||||||
} catch (e) {
|
|
||||||
dPrint(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _loadRRS() async {
|
|
||||||
try {
|
|
||||||
final v = await RSSApi.getRssVideo();
|
|
||||||
rssVideoItems = v;
|
|
||||||
notifyListeners();
|
|
||||||
final t = await RSSApi.getRssText();
|
|
||||||
rssTextItems = t;
|
|
||||||
notifyListeners();
|
|
||||||
dPrint("RSS update Success !");
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("_loadRRS Error:$e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
openDir(rsiLauncherInstalledPath) async {
|
|
||||||
await Process.run(SystemHelper.powershellPath,
|
|
||||||
["explorer.exe", "/select,\"$rsiLauncherInstalledPath\""]);
|
|
||||||
}
|
|
||||||
|
|
||||||
onMenuTap(String key) async {
|
|
||||||
const String gameInstallReqInfo =
|
|
||||||
"该功能需要一个有效的安装位置\n\n如果您的游戏未下载完成,请等待下载完毕后使用此功能。\n\n如果您的游戏已下载完毕但未识别,请启动一次游戏后重新打开盒子 或 在设置选项中手动设置安装位置。";
|
|
||||||
switch (key) {
|
|
||||||
case "auto_check":
|
|
||||||
BaseUIContainer(
|
|
||||||
uiCreate: () => GameDoctorUI(),
|
|
||||||
modelCreate: () => GameDoctorUIModel(scInstalledPath))
|
|
||||||
.push(context!);
|
|
||||||
return;
|
|
||||||
case "localization":
|
|
||||||
if (scInstalledPath == "not_install") {
|
|
||||||
showToast(context!, gameInstallReqInfo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await showDialog(
|
|
||||||
context: context!,
|
|
||||||
dismissWithEsc: false,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => LocalizationUI(),
|
|
||||||
modelCreate: () => LocalizationUIModel(scInstalledPath));
|
|
||||||
});
|
|
||||||
_checkLocalizationUpdate();
|
|
||||||
return;
|
|
||||||
case "performance":
|
|
||||||
if (scInstalledPath == "not_install") {
|
|
||||||
showToast(context!, gameInstallReqInfo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AnalyticsApi.touch("performance_launch");
|
|
||||||
BaseUIContainer(
|
|
||||||
uiCreate: () => PerformanceUI(),
|
|
||||||
modelCreate: () => PerformanceUIModel(scInstalledPath))
|
|
||||||
.push(context!);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
showPlacard() {
|
|
||||||
switch (appPlacardData?.linkType) {
|
|
||||||
case "external":
|
|
||||||
launchUrlString(appPlacardData?.link);
|
|
||||||
return;
|
|
||||||
case "doc":
|
|
||||||
showDialog(
|
|
||||||
context: context!,
|
|
||||||
builder: (context) {
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => MDContentDialogUI(),
|
|
||||||
modelCreate: () => MDContentDialogUIModel(
|
|
||||||
appPlacardData?.title ?? "公告详情", appPlacardData?.link));
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closePlacard() async {
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
await box.put("close_placard", appPlacardData?.version);
|
|
||||||
appPlacardData = null;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
goWebView(String title, String url,
|
|
||||||
{bool useLocalization = false,
|
|
||||||
bool loginMode = false,
|
|
||||||
RsiLoginCallback? rsiLoginCallback}) async {
|
|
||||||
if (useLocalization) {
|
|
||||||
const tipVersion = 2;
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
final skip =
|
|
||||||
await box.get("skip_web_localization_tip_version", defaultValue: 0);
|
|
||||||
if (skip != tipVersion) {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!,
|
|
||||||
"星际公民网站汉化",
|
|
||||||
const Text(
|
|
||||||
"本插功能件仅供大致浏览使用,不对任何有关本功能产生的问题负责!在涉及账号操作前请注意确认网站的原本内容!"
|
|
||||||
"\n\n\n使用此功能登录账号时请确保您的 SC汉化盒子 是从可信任的来源下载。",
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context!).size.width * .6));
|
|
||||||
if (!ok) {
|
|
||||||
if (loginMode) {
|
|
||||||
rsiLoginCallback?.call(null, false);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await box.put("skip_web_localization_tip_version", tipVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!await WebviewWindow.isWebviewAvailable()) {
|
|
||||||
showToast(context!, "需要安装 WebView2 Runtime");
|
|
||||||
launchUrlString(
|
|
||||||
"https://developer.microsoft.com/en-us/microsoft-edge/webview2/");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final webViewModel = WebViewModel(context!,
|
|
||||||
loginMode: loginMode, loginCallback: rsiLoginCallback);
|
|
||||||
if (useLocalization) {
|
|
||||||
isFixingString = "正在初始化汉化资源...";
|
|
||||||
isFixing = true;
|
|
||||||
notifyListeners();
|
|
||||||
try {
|
|
||||||
await webViewModel.initLocalization(appWebLocalizationVersionsData!);
|
|
||||||
} catch (e) {
|
|
||||||
showToast(context!, "初始化网页汉化资源失败!$e");
|
|
||||||
}
|
|
||||||
isFixingString = "";
|
|
||||||
isFixing = false;
|
|
||||||
}
|
|
||||||
await webViewModel.initWebView(
|
|
||||||
title: title,
|
|
||||||
);
|
|
||||||
if (await File(
|
|
||||||
"${AppConf.applicationSupportDir}\\webview_data\\enable_webview_localization_capture")
|
|
||||||
.exists()) {
|
|
||||||
webViewModel.enableCapture = true;
|
|
||||||
BaseUIContainer(
|
|
||||||
uiCreate: () => WebviewLocalizationCaptureUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
WebviewLocalizationCaptureUIModel(webViewModel))
|
|
||||||
.push(context!)
|
|
||||||
.then((_) {
|
|
||||||
webViewModel.enableCapture = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
|
||||||
await webViewModel.launch(url);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
launchRSI() async {
|
|
||||||
if (scInstalledPath == "not_install") {
|
|
||||||
showToast(context!, "该功能需要一个有效的安装位置");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AppConf.isMSE) {
|
|
||||||
if (isCurGameRunning) {
|
|
||||||
await Process.run(
|
|
||||||
SystemHelper.powershellPath, ["ps \"StarCitizen\" | kill"]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AnalyticsApi.touch("gameLaunch");
|
|
||||||
showDialog(
|
|
||||||
context: context!,
|
|
||||||
dismissWithEsc: false,
|
|
||||||
builder: (context) {
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => LoginDialog(),
|
|
||||||
modelCreate: () => LoginDialogModel(scInstalledPath, this));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!,
|
|
||||||
"一键启动功能提示",
|
|
||||||
const Text("为确保账户安全,一键启动功能已在开发版中禁用,我们将在微软商店版本中提供此功能。"
|
|
||||||
"\n\n微软商店版由微软提供可靠的分发下载与数字签名,可有效防止软件被恶意篡改。\n\n提示:您无需使用盒子启动游戏也可使用汉化。"),
|
|
||||||
confirm: "安装微软商店版本",
|
|
||||||
cancel: "取消");
|
|
||||||
if (ok == true) {
|
|
||||||
await launchUrlString(
|
|
||||||
"https://apps.microsoft.com/detail/9NF3SWFWNKL1?launch=true");
|
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isRSIServerStatusOK(Map map) {
|
|
||||||
return (map["status"] == "ok" || map["status"] == "operational");
|
|
||||||
}
|
|
||||||
|
|
||||||
doLaunchGame(String launchExe, List<String> args, String installPath,
|
|
||||||
String? processorAffinity) async {
|
|
||||||
_isGameRunning[installPath] = true;
|
|
||||||
notifyListeners();
|
|
||||||
try {
|
|
||||||
late ProcessResult result;
|
|
||||||
if (processorAffinity == null) {
|
|
||||||
result = await Process.run(launchExe, args);
|
|
||||||
} else {
|
|
||||||
dPrint("set Affinity === $processorAffinity launchExe === $launchExe");
|
|
||||||
result = await Process.run("cmd.exe", [
|
|
||||||
'/C',
|
|
||||||
'Start',
|
|
||||||
'"StarCitizen"',
|
|
||||||
'/High',
|
|
||||||
'/Affinity',
|
|
||||||
processorAffinity,
|
|
||||||
launchExe,
|
|
||||||
...args
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
dPrint('Exit code: ${result.exitCode}');
|
|
||||||
dPrint('stdout: ${result.stdout}');
|
|
||||||
dPrint('stderr: ${result.stderr}');
|
|
||||||
|
|
||||||
if (result.exitCode != 0) {
|
|
||||||
final logs = await SCLoggerHelper.getGameRunningLogs(scInstalledPath);
|
|
||||||
MapEntry<String, String>? exitInfo;
|
|
||||||
bool hasUrl = false;
|
|
||||||
if (logs != null) {
|
|
||||||
exitInfo = SCLoggerHelper.getGameRunningLogInfo(logs);
|
|
||||||
if (exitInfo!.value.startsWith("https://")) {
|
|
||||||
hasUrl = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
showToast(context!,
|
|
||||||
"游戏非正常退出\nexitCode=${result.exitCode}\nstdout=${result.stdout ?? ""}\nstderr=${result.stderr ?? ""}\n\n诊断信息:${exitInfo == null ? "未知错误,请通过一键诊断加群反馈。" : exitInfo.key} \n${hasUrl ? "请查看弹出的网页链接获得详细信息。" : exitInfo?.value ?? ""}");
|
|
||||||
if (hasUrl) {
|
|
||||||
await Future.delayed(const Duration(seconds: 3));
|
|
||||||
launchUrlString(exitInfo!.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final launchFile = File("$installPath\\loginData.json");
|
|
||||||
if (await launchFile.exists()) {
|
|
||||||
await launchFile.delete();
|
|
||||||
}
|
|
||||||
} catch (_) {}
|
|
||||||
_isGameRunning[installPath] = false;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
onTapFestival() {
|
|
||||||
if (countdownFestivalListData == null) return;
|
|
||||||
showDialog(
|
|
||||||
context: context!,
|
|
||||||
builder: (context) {
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => CountdownDialogUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
CountdownDialogUIModel(countdownFestivalListData!));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getRssImage(RssItem item) {
|
|
||||||
final h = html.parse(item.description ?? "");
|
|
||||||
if (h.body == null) return "";
|
|
||||||
for (var node in h.body!.nodes) {
|
|
||||||
if (node is html_dom.Element) {
|
|
||||||
if (node.localName == "img") {
|
|
||||||
return node.attributes["src"]?.trim() ?? "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
handleTitle(String? title) {
|
|
||||||
if (title == null) return "";
|
|
||||||
title = title.replaceAll("【", "[ ");
|
|
||||||
title = title.replaceAll("】", " ] ");
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _checkLocalizationUpdate() async {
|
|
||||||
final info = await handleError(
|
|
||||||
() => LocalizationUIModel.checkLocalizationUpdates(scInstallPaths));
|
|
||||||
dPrint("lUpdateInfo === $info");
|
|
||||||
localizationUpdateInfo = info;
|
|
||||||
notifyListeners();
|
|
||||||
|
|
||||||
if (info?.value == true && !_isSendLocalizationUpdateNotification) {
|
|
||||||
final toastNotifier =
|
|
||||||
ToastNotificationManager.createToastNotifierWithId("SC汉化盒子");
|
|
||||||
if (toastNotifier != null) {
|
|
||||||
final toastContent = ToastNotificationManager.getTemplateContent(
|
|
||||||
ToastTemplateType.toastText02);
|
|
||||||
if (toastContent != null) {
|
|
||||||
final xmlNodeList = toastContent.getElementsByTagName('text');
|
|
||||||
const title = '汉化有新版本!';
|
|
||||||
final content = '您在 ${info?.key} 安装的汉化有新版本啦!';
|
|
||||||
xmlNodeList.item(0)?.appendChild(toastContent.createTextNode(title));
|
|
||||||
xmlNodeList
|
|
||||||
.item(1)
|
|
||||||
?.appendChild(toastContent.createTextNode(content));
|
|
||||||
final toastNotification =
|
|
||||||
ToastNotification.createToastNotification(toastContent);
|
|
||||||
toastNotifier.show(toastNotification);
|
|
||||||
_isSendLocalizationUpdateNotification = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,419 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
|
||||||
|
|
||||||
import 'localization_ui_model.dart';
|
|
||||||
|
|
||||||
class LocalizationUI extends BaseUI<LocalizationUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, LocalizationUIModel model) {
|
|
||||||
final curInstallInfo = model.apiLocalizationData?[model.patchStatus?.value];
|
|
||||||
return ContentDialog(
|
|
||||||
title: makeTitle(context, model),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context).size.width * .7,
|
|
||||||
minHeight: MediaQuery.of(context).size.height * .9),
|
|
||||||
content: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 12, right: 12, top: 12),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
AnimatedSize(
|
|
||||||
duration: const Duration(milliseconds: 130),
|
|
||||||
child: model.patchStatus?.key == true &&
|
|
||||||
model.patchStatus?.value == "游戏内置"
|
|
||||||
? Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 12),
|
|
||||||
child: InfoBar(
|
|
||||||
title: const Text("警告"),
|
|
||||||
content: const Text(
|
|
||||||
"您正在使用游戏内置文本,官方文本目前为机器翻译(截至3.21.0),建议您在下方安装社区汉化。"),
|
|
||||||
severity: InfoBarSeverity.info,
|
|
||||||
style: InfoBarThemeData(decoration: (severity) {
|
|
||||||
return const BoxDecoration(
|
|
||||||
color: Color.fromRGBO(155, 7, 7, 1.0));
|
|
||||||
}, iconColor: (severity) {
|
|
||||||
return Colors.white;
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
makeListContainer("汉化状态", [
|
|
||||||
if (model.patchStatus == null)
|
|
||||||
makeLoading(context)
|
|
||||||
else ...[
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
"启用(${LocalizationUIModel.languageSupport[model.selectedLanguage]}):"),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
ToggleSwitch(
|
|
||||||
checked: model.patchStatus?.key == true,
|
|
||||||
onChanged: model.updateLangCfg,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text("已安装版本:${model.patchStatus?.value}"),
|
|
||||||
const Spacer(),
|
|
||||||
if (model.patchStatus?.value != "游戏内置")
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Button(
|
|
||||||
onPressed: model.goFeedback,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(FluentIcons.feedback),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Text("汉化反馈"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Button(
|
|
||||||
onPressed: model.doDelIniFile(),
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(FluentIcons.delete),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Text("卸载汉化"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
AnimatedSize(
|
|
||||||
duration: const Duration(milliseconds: 130),
|
|
||||||
child: (curInstallInfo != null &&
|
|
||||||
curInstallInfo.note != null &&
|
|
||||||
curInstallInfo.note!.isNotEmpty)
|
|
||||||
? Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 12),
|
|
||||||
child: Container(
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
borderRadius: BorderRadius.circular(7)),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
"备注:",
|
|
||||||
style: TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Text(
|
|
||||||
"${curInstallInfo.note}",
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white.withOpacity(.8)),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
makeListContainer("社区汉化", [
|
|
||||||
if (model.apiLocalizationData == null)
|
|
||||||
makeLoading(context)
|
|
||||||
else if (model.apiLocalizationData!.isEmpty)
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
"该语言/版本 暂无可用汉化,敬请期待!",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13, color: Colors.white.withOpacity(.8)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
for (final item in model.apiLocalizationData!.entries)
|
|
||||||
makeRemoteList(context, model, item),
|
|
||||||
]),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
IconButton(
|
|
||||||
icon: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(model.enableCustomize
|
|
||||||
? FluentIcons.chevron_up
|
|
||||||
: FluentIcons.chevron_down),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Text("高级功能"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
model.enableCustomize = !model.enableCustomize;
|
|
||||||
model.notifyListeners();
|
|
||||||
}),
|
|
||||||
AnimatedSize(
|
|
||||||
duration: const Duration(milliseconds: 130),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
model.enableCustomize
|
|
||||||
? makeListContainer("自定义文本", [
|
|
||||||
if (model.customizeList == null)
|
|
||||||
makeLoading(context)
|
|
||||||
else if (model.customizeList!.isEmpty)
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
"暂无自定义文本",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Colors.white.withOpacity(.8)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else ...[
|
|
||||||
for (final file in model.customizeList!)
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
model.getCustomizeFileName(file),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
if (model.workingVersion == file)
|
|
||||||
const Padding(
|
|
||||||
padding: EdgeInsets.only(right: 12),
|
|
||||||
child: ProgressRing(),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Button(
|
|
||||||
onPressed: model.doLocalInstall(file),
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
left: 8,
|
|
||||||
right: 8,
|
|
||||||
top: 4,
|
|
||||||
bottom: 4),
|
|
||||||
child: Text("安装"),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
], actions: [
|
|
||||||
Button(
|
|
||||||
onPressed: () => model.openDir(),
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(FluentIcons.folder_open),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Text("打开文件夹"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
])
|
|
||||||
: SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeRemoteList(BuildContext context, LocalizationUIModel model,
|
|
||||||
MapEntry<String, ScLocalizationData> item) {
|
|
||||||
final isWorking = model.workingVersion.isNotEmpty;
|
|
||||||
final isMineWorking = model.workingVersion == item.key;
|
|
||||||
final isInstalled = model.patchStatus?.value == item.key;
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 12),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${item.value.info}",
|
|
||||||
style: const TextStyle(fontSize: 19),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
"版本号:${item.value.versionName}",
|
|
||||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
"通道:${item.value.gameChannel}",
|
|
||||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
"更新时间:${item.value.updateAt}",
|
|
||||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
if (isMineWorking)
|
|
||||||
const Padding(
|
|
||||||
padding: EdgeInsets.only(right: 12),
|
|
||||||
child: ProgressRing(),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Button(
|
|
||||||
onPressed: ((item.value.enable == true &&
|
|
||||||
!isWorking &&
|
|
||||||
!isInstalled)
|
|
||||||
? model.doRemoteInstall(item.value)
|
|
||||||
: null),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 8, right: 8, top: 4, bottom: 4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(right: 6),
|
|
||||||
child: Icon(isInstalled
|
|
||||||
? FluentIcons.check_mark
|
|
||||||
: (item.value.enable ?? false)
|
|
||||||
? FluentIcons.download
|
|
||||||
: FluentIcons.disable_updates),
|
|
||||||
),
|
|
||||||
Text(isInstalled
|
|
||||||
? "已安装"
|
|
||||||
: ((item.value.enable ?? false) ? "安装" : "不可用")),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Container(
|
|
||||||
color: Colors.white.withOpacity(.05),
|
|
||||||
height: 1,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeListContainer(String title, List<Widget> children,
|
|
||||||
{List<Widget> actions = const []}) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 12),
|
|
||||||
child: AnimatedSize(
|
|
||||||
duration: const Duration(milliseconds: 130),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
borderRadius: BorderRadius.circular(7)),
|
|
||||||
child: Padding(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.only(top: 12, bottom: 12, left: 24, right: 24),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: const TextStyle(fontSize: 22),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
if (actions.isNotEmpty) ...actions,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 6,
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
color: Colors.white.withOpacity(.1),
|
|
||||||
height: 1,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
...children
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeTitle(BuildContext context, LocalizationUIModel model) {
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(
|
|
||||||
FluentIcons.back,
|
|
||||||
size: 22,
|
|
||||||
),
|
|
||||||
onPressed: model.onBack()),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(getUITitle(context, model)),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
Text(
|
|
||||||
model.scInstallPath,
|
|
||||||
style: const TextStyle(fontSize: 13),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
"语言: ",
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
ComboBox<String>(
|
|
||||||
value: model.selectedLanguage,
|
|
||||||
items: [
|
|
||||||
for (final lang
|
|
||||||
in LocalizationUIModel.languageSupport.entries)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: lang.key,
|
|
||||||
child: Text(lang.value),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: model.workingVersion.isNotEmpty
|
|
||||||
? null
|
|
||||||
: (v) {
|
|
||||||
if (v == null) return;
|
|
||||||
model.selectLang(v);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
onPressed: model.doRefresh(),
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.refresh),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, LocalizationUIModel model) => "汉化管理";
|
|
||||||
}
|
|
@ -1,394 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:archive/archive_io.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/utils/log.dart' as log_utils;
|
|
||||||
|
|
||||||
class LocalizationUIModel extends BaseUIModel {
|
|
||||||
final String scInstallPath;
|
|
||||||
|
|
||||||
static const languageSupport = {
|
|
||||||
"chinese_(simplified)": "简体中文",
|
|
||||||
"chinese_(traditional)": "繁體中文",
|
|
||||||
};
|
|
||||||
|
|
||||||
late String selectedLanguage;
|
|
||||||
|
|
||||||
Map<String, ScLocalizationData>? apiLocalizationData;
|
|
||||||
|
|
||||||
LocalizationUIModel(this.scInstallPath);
|
|
||||||
|
|
||||||
String workingVersion = "";
|
|
||||||
|
|
||||||
final downloadDir =
|
|
||||||
Directory("${AppConf.applicationSupportDir}\\Localizations");
|
|
||||||
|
|
||||||
late final customizeDir =
|
|
||||||
Directory("${downloadDir.absolute.path}\\Customize_ini");
|
|
||||||
|
|
||||||
late final scDataDir = Directory("$scInstallPath\\data");
|
|
||||||
|
|
||||||
late final cfgFile = File("${scDataDir.absolute.path}\\system.cfg");
|
|
||||||
|
|
||||||
MapEntry<bool, String>? patchStatus;
|
|
||||||
|
|
||||||
List<String>? customizeList;
|
|
||||||
|
|
||||||
StreamSubscription? customizeDirListenSub;
|
|
||||||
|
|
||||||
bool enableCustomize = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initModel() {
|
|
||||||
selectedLanguage = languageSupport.entries.first.key;
|
|
||||||
if (!customizeDir.existsSync()) {
|
|
||||||
customizeDir.createSync(recursive: true);
|
|
||||||
}
|
|
||||||
customizeDirListenSub = customizeDir.watch().listen((event) {
|
|
||||||
_scanCustomizeDir();
|
|
||||||
});
|
|
||||||
super.initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future loadData() async {
|
|
||||||
await _updateStatus();
|
|
||||||
_checkUserCfg();
|
|
||||||
_scanCustomizeDir();
|
|
||||||
final l =
|
|
||||||
await handleError(() => Api.getScLocalizationData(selectedLanguage));
|
|
||||||
if (l != null) {
|
|
||||||
apiLocalizationData = {};
|
|
||||||
for (var element in l) {
|
|
||||||
final isPTU = !scInstallPath.contains("LIVE");
|
|
||||||
if (isPTU && element.gameChannel == "PTU") {
|
|
||||||
apiLocalizationData![element.versionName ?? ""] = element;
|
|
||||||
} else if (!isPTU && element.gameChannel == "PU") {
|
|
||||||
apiLocalizationData![element.versionName ?? ""] = element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
dispose() {
|
|
||||||
customizeDirListenSub?.cancel();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
_scanCustomizeDir() {
|
|
||||||
final fileList = customizeDir.listSync();
|
|
||||||
customizeList = [];
|
|
||||||
for (var value in fileList) {
|
|
||||||
if (value is File && value.path.endsWith(".ini")) {
|
|
||||||
customizeList?.add(value.absolute.path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
String getCustomizeFileName(String path) {
|
|
||||||
return path.split("\\").last;
|
|
||||||
}
|
|
||||||
|
|
||||||
_updateStatus() async {
|
|
||||||
patchStatus = MapEntry(
|
|
||||||
await getLangCfgEnableLang(lang: selectedLanguage),
|
|
||||||
await getInstalledIniVersion(
|
|
||||||
"${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini"));
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidCallback? onBack() {
|
|
||||||
if (workingVersion.isNotEmpty) return null;
|
|
||||||
return () {
|
|
||||||
Navigator.pop(context!);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void selectLang(String v) {
|
|
||||||
selectedLanguage = v;
|
|
||||||
apiLocalizationData = null;
|
|
||||||
notifyListeners();
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidCallback? doRefresh() {
|
|
||||||
if (workingVersion.isNotEmpty) return null;
|
|
||||||
return () {
|
|
||||||
apiLocalizationData = null;
|
|
||||||
notifyListeners();
|
|
||||||
reloadData();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidCallback? doRemoteInstall(ScLocalizationData value) {
|
|
||||||
return () async {
|
|
||||||
AnalyticsApi.touch("install_localization");
|
|
||||||
final downloadUrl =
|
|
||||||
"${URLConf.gitlabLocalizationUrl}/archive/${value.versionName}.tar.gz";
|
|
||||||
final savePath =
|
|
||||||
File("${downloadDir.absolute.path}\\${value.versionName}.sclang");
|
|
||||||
try {
|
|
||||||
workingVersion = value.versionName!;
|
|
||||||
notifyListeners();
|
|
||||||
if (!await savePath.exists()) {
|
|
||||||
// download
|
|
||||||
dPrint("downloading file to $savePath");
|
|
||||||
final r = await RSHttp.get(downloadUrl);
|
|
||||||
if (r.statusCode == 200 && r.data != null) {
|
|
||||||
await savePath.writeAsBytes(r.data!);
|
|
||||||
} else {
|
|
||||||
throw "statusCode Error : ${r.statusCode}";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dPrint("use cache $savePath");
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
// check file
|
|
||||||
final globalIni = await compute(_readArchive, savePath.absolute.path);
|
|
||||||
if (globalIni.isEmpty) {
|
|
||||||
throw "文件受损,请重新下载";
|
|
||||||
}
|
|
||||||
await _installFormString(globalIni, value.versionName ?? "");
|
|
||||||
} catch (e) {
|
|
||||||
await showToast(context!, "安装出错!\n\n $e");
|
|
||||||
if (await savePath.exists()) await savePath.delete();
|
|
||||||
}
|
|
||||||
workingVersion = "";
|
|
||||||
notifyListeners();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> getLangCfgEnableLang({String lang = ""}) async {
|
|
||||||
if (!await cfgFile.exists()) return false;
|
|
||||||
final str = (await cfgFile.readAsString()).replaceAll(" ", "");
|
|
||||||
return str.contains("sys_languages=$lang") &&
|
|
||||||
str.contains("g_language=$lang") &&
|
|
||||||
str.contains("g_languageAudio=english");
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<String> getInstalledIniVersion(String iniPath) async {
|
|
||||||
final iniFile = File(iniPath);
|
|
||||||
if (!await iniFile.exists()) return "游戏内置";
|
|
||||||
final iniStringSplit = (await iniFile.readAsString()).split("\n");
|
|
||||||
for (var i = iniStringSplit.length - 1; i > 0; i--) {
|
|
||||||
if (iniStringSplit[i]
|
|
||||||
.contains("_starcitizen_doctor_localization_version=")) {
|
|
||||||
final v = iniStringSplit[i]
|
|
||||||
.trim()
|
|
||||||
.split("_starcitizen_doctor_localization_version=")[1];
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "自定义文件";
|
|
||||||
}
|
|
||||||
|
|
||||||
_installFormString(StringBuffer globalIni, String versionName) async {
|
|
||||||
final iniFile = File(
|
|
||||||
"${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini");
|
|
||||||
if (versionName.isNotEmpty) {
|
|
||||||
if (!globalIni.toString().endsWith("\n")) {
|
|
||||||
globalIni.write("\n");
|
|
||||||
}
|
|
||||||
globalIni.write("_starcitizen_doctor_localization_version=$versionName");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// write cfg
|
|
||||||
if (await cfgFile.exists()) {}
|
|
||||||
|
|
||||||
/// write ini
|
|
||||||
if (await iniFile.exists()) {
|
|
||||||
await iniFile.delete();
|
|
||||||
}
|
|
||||||
await iniFile.create(recursive: true);
|
|
||||||
await iniFile.writeAsString("\uFEFF${globalIni.toString().trim()}",
|
|
||||||
flush: true);
|
|
||||||
await updateLangCfg(true);
|
|
||||||
await _updateStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
openDir() async {
|
|
||||||
showToast(context!,
|
|
||||||
"即将打开本地化文件夹,请将自定义的 任意名称.ini 文件放入 Customize_ini 文件夹。\n\n添加新文件后未显示请使用右上角刷新按钮。\n\n安装时请确保选择了正确的语言。");
|
|
||||||
await Process.run(SystemHelper.powershellPath,
|
|
||||||
["explorer.exe", "/select,\"${customizeDir.absolute.path}\"\\"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateLangCfg(bool enable) async {
|
|
||||||
final status = await getLangCfgEnableLang(lang: selectedLanguage);
|
|
||||||
final exists = await cfgFile.exists();
|
|
||||||
if (status == enable) {
|
|
||||||
await _updateStatus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
StringBuffer newStr = StringBuffer();
|
|
||||||
var str = <String>[];
|
|
||||||
if (exists) {
|
|
||||||
str = (await cfgFile.readAsString()).replaceAll(" ", "").split("\n");
|
|
||||||
}
|
|
||||||
if (enable) {
|
|
||||||
if (exists) {
|
|
||||||
for (var value in str) {
|
|
||||||
if (value.contains("sys_languages")) {
|
|
||||||
value = "sys_languages=$selectedLanguage";
|
|
||||||
} else if (value.contains("g_language")) {
|
|
||||||
value = "g_language=$selectedLanguage";
|
|
||||||
} else if (value.contains("g_languageAudio")) {
|
|
||||||
value = "g_language=english";
|
|
||||||
}
|
|
||||||
if (value.trim().isNotEmpty) newStr.writeln(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!newStr.toString().contains("sys_languages=$selectedLanguage")) {
|
|
||||||
newStr.writeln("sys_languages=$selectedLanguage");
|
|
||||||
}
|
|
||||||
if (!newStr.toString().contains("g_language=$selectedLanguage")) {
|
|
||||||
newStr.writeln("g_language=$selectedLanguage");
|
|
||||||
}
|
|
||||||
if (!newStr.toString().contains("g_languageAudio")) {
|
|
||||||
newStr.writeln("g_languageAudio=english");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (exists) {
|
|
||||||
for (var value in str) {
|
|
||||||
if (value.contains("sys_languages=")) {
|
|
||||||
continue;
|
|
||||||
} else if (value.contains("g_language")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
newStr.writeln(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (exists) await cfgFile.delete(recursive: true);
|
|
||||||
await cfgFile.create(recursive: true);
|
|
||||||
await cfgFile.writeAsString(newStr.toString());
|
|
||||||
await _updateStatus();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidCallback? doDelIniFile() {
|
|
||||||
return () async {
|
|
||||||
final iniFile = File(
|
|
||||||
"${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini");
|
|
||||||
if (await iniFile.exists()) await iniFile.delete();
|
|
||||||
await updateLangCfg(false);
|
|
||||||
await _updateStatus();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// read locale active
|
|
||||||
static StringBuffer _readArchive(String savePath) {
|
|
||||||
final inputStream = InputFileStream(savePath);
|
|
||||||
final archive =
|
|
||||||
TarDecoder().decodeBytes(GZipDecoder().decodeBuffer(inputStream));
|
|
||||||
StringBuffer globalIni = StringBuffer("");
|
|
||||||
for (var element in archive.files) {
|
|
||||||
if (element.name.contains("global.ini")) {
|
|
||||||
for (var value
|
|
||||||
in (element.rawContent?.readString() ?? "").split("\n")) {
|
|
||||||
final tv = value.trim();
|
|
||||||
if (tv.isNotEmpty) globalIni.writeln(tv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
archive.clear();
|
|
||||||
return globalIni;
|
|
||||||
}
|
|
||||||
|
|
||||||
VoidCallback? doLocalInstall(String filePath) {
|
|
||||||
if (workingVersion.isNotEmpty) return null;
|
|
||||||
return () async {
|
|
||||||
final f = File(filePath);
|
|
||||||
if (!await f.exists()) return;
|
|
||||||
workingVersion = filePath;
|
|
||||||
notifyListeners();
|
|
||||||
final str = await f.readAsString();
|
|
||||||
await _installFormString(
|
|
||||||
StringBuffer(str), "自定义_${getCustomizeFileName(filePath)}");
|
|
||||||
workingVersion = "";
|
|
||||||
notifyListeners();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void _checkUserCfg() async {
|
|
||||||
final userCfgFile = File("$scInstallPath\\USER.cfg");
|
|
||||||
if (await userCfgFile.exists()) {
|
|
||||||
final cfgString = await userCfgFile.readAsString();
|
|
||||||
if (cfgString.contains("g_language") &&
|
|
||||||
!cfgString.contains("g_language=$selectedLanguage")) {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!,
|
|
||||||
"是否移除不兼容的汉化参数",
|
|
||||||
const Text(
|
|
||||||
"USER.cfg 包含不兼容的汉化参数,这可能是以前的汉化文件的残留信息。\n\n这将可能导致汉化无效或乱码,点击确认为您一键移除(不会影响其他配置)。"),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context!).size.width * .35));
|
|
||||||
if (ok == true) {
|
|
||||||
var finalString = "";
|
|
||||||
for (var item in cfgString.split("\n")) {
|
|
||||||
if (!item.trim().startsWith("g_language")) {
|
|
||||||
finalString = "$finalString$item\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await userCfgFile.delete();
|
|
||||||
await userCfgFile.create();
|
|
||||||
await userCfgFile.writeAsString(finalString, flush: true);
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<MapEntry<String, bool>?> checkLocalizationUpdates(
|
|
||||||
List<String> gameInstallPaths) async {
|
|
||||||
final updateInfo = <String, bool>{};
|
|
||||||
for (var kv in languageSupport.entries) {
|
|
||||||
final l = await Api.getScLocalizationData(kv.key);
|
|
||||||
for (var value in gameInstallPaths) {
|
|
||||||
final iniPath = "$value\\data\\Localization\\${kv.key}\\global.ini";
|
|
||||||
if (!await File(iniPath).exists()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final installed = await getInstalledIniVersion(iniPath);
|
|
||||||
if (installed == "游戏内置" || installed == "自定义文件") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final hasUpdate = l
|
|
||||||
.where((element) => element.versionName == installed)
|
|
||||||
.firstOrNull ==
|
|
||||||
null;
|
|
||||||
updateInfo[value] = hasUpdate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log_utils.dPrint("checkLocalizationUpdates ==== $updateInfo");
|
|
||||||
for (var v in updateInfo.entries) {
|
|
||||||
if (v.value) {
|
|
||||||
for (var element in AppConf.gameChannels) {
|
|
||||||
if (v.key.contains("StarCitizen\\$element")) {
|
|
||||||
return MapEntry(element, true);
|
|
||||||
} else {
|
|
||||||
return const MapEntry("", true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void goFeedback() {
|
|
||||||
launchUrlString(URLConf.feedbackUrl);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,115 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/widgets/cache_image.dart';
|
|
||||||
|
|
||||||
import 'login_dialog_ui_model.dart';
|
|
||||||
|
|
||||||
class LoginDialog extends BaseUI<LoginDialogModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, LoginDialogModel model) {
|
|
||||||
return ContentDialog(
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context).size.width * .56,
|
|
||||||
),
|
|
||||||
title: (model.loginStatus == 2) ? null : const Text("一键启动"),
|
|
||||||
content: AnimatedSize(
|
|
||||||
duration: const Duration(milliseconds: 230),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Row(),
|
|
||||||
if (model.loginStatus == 0) ...[
|
|
||||||
Center(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
const Text("登录中..."),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
const ProgressRing(),
|
|
||||||
if (model.isDeviceSupportWinHello)
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Text(
|
|
||||||
"* 若开启了自动填充,请留意弹出的 Windows Hello 窗口",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13, color: Colors.white.withOpacity(.6)),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
] else if (model.loginStatus == 1) ...[
|
|
||||||
Text("请输入RSI账户 [${model.nickname}] 的邮箱,以保存登录状态(输入错误会导致无法进入游戏!)"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
TextFormBox(
|
|
||||||
// controller: model.emailCtrl,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Text(
|
|
||||||
"*该操作同一账号只需执行一次,输入错误请在盒子设置中清理,切换账号请在汉化浏览器中操作。",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Colors.white.withOpacity(.6),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
] else if (model.loginStatus == 2 || model.loginStatus == 3) ...[
|
|
||||||
Center(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
const Text(
|
|
||||||
"欢迎回来!",
|
|
||||||
style: TextStyle(fontSize: 20),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
if (model.avatarUrl != null)
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(1000),
|
|
||||||
child: CacheNetImage(
|
|
||||||
url: model.avatarUrl!,
|
|
||||||
width: 128,
|
|
||||||
height: 128,
|
|
||||||
fit: BoxFit.fill,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
model.nickname,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 24, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
Text(model.loginStatus == 2
|
|
||||||
? "正在为您启动游戏..."
|
|
||||||
: "正在等待优化CPU参数..."),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
const ProgressRing(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
]
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: const [
|
|
||||||
// if (model.loginStatus == 1) ...[
|
|
||||||
// Button(
|
|
||||||
// child: const Padding(
|
|
||||||
// padding: EdgeInsets.all(4),
|
|
||||||
// child: Text("取消"),
|
|
||||||
// ),
|
|
||||||
// onPressed: () {
|
|
||||||
// Navigator.pop(context);
|
|
||||||
// }),
|
|
||||||
// const SizedBox(width: 80),
|
|
||||||
// FilledButton(
|
|
||||||
// child: const Padding(
|
|
||||||
// padding: EdgeInsets.all(4),
|
|
||||||
// child: Text("保存"),
|
|
||||||
// ),
|
|
||||||
// onPressed: () => model.onSaveEmail()),
|
|
||||||
// ],
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, LoginDialogModel model) => "";
|
|
||||||
}
|
|
@ -1,273 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:cryptography/cryptography.dart';
|
|
||||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:jwt_decode/jwt_decode.dart';
|
|
||||||
import 'package:local_auth/local_auth.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/win32/credentials.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/webview/webview.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
import 'package:uuid/uuid.dart';
|
|
||||||
|
|
||||||
class LoginDialogModel extends BaseUIModel {
|
|
||||||
int loginStatus = 0;
|
|
||||||
|
|
||||||
String nickname = "";
|
|
||||||
String? avatarUrl;
|
|
||||||
String? authToken;
|
|
||||||
String? webToken;
|
|
||||||
Map? releaseInfo;
|
|
||||||
|
|
||||||
final String installPath;
|
|
||||||
|
|
||||||
final HomeUIModel homeUIModel;
|
|
||||||
|
|
||||||
// TextEditingController emailCtrl = TextEditingController();
|
|
||||||
|
|
||||||
LoginDialogModel(this.installPath, this.homeUIModel);
|
|
||||||
|
|
||||||
final LocalAuthentication localAuth = LocalAuthentication();
|
|
||||||
|
|
||||||
var isDeviceSupportWinHello = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initModel() {
|
|
||||||
_launchWebLogin();
|
|
||||||
super.initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _launchWebLogin() async {
|
|
||||||
isDeviceSupportWinHello = await localAuth.isDeviceSupported();
|
|
||||||
notifyListeners();
|
|
||||||
goWebView("登录 RSI 账户", "https://robertsspaceindustries.com/connect",
|
|
||||||
loginMode: true, rsiLoginCallback: (message, ok) async {
|
|
||||||
// dPrint(
|
|
||||||
// "======rsiLoginCallback=== $ok ===== data==\n${json.encode(message)}");
|
|
||||||
if (message == null || !ok) {
|
|
||||||
Navigator.pop(context!);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// final emailBox = await Hive.openBox("quick_login_email");
|
|
||||||
final data = message["data"];
|
|
||||||
authToken = data["authToken"];
|
|
||||||
webToken = data["webToken"];
|
|
||||||
releaseInfo = data["releaseInfo"];
|
|
||||||
avatarUrl = data["avatar"]
|
|
||||||
?.toString()
|
|
||||||
.replaceAll("url(\"", "")
|
|
||||||
.replaceAll("\")", "");
|
|
||||||
Map<String, dynamic> payload = Jwt.parseJwt(authToken!);
|
|
||||||
nickname = payload["nickname"] ?? "";
|
|
||||||
|
|
||||||
final inputEmail = data["inputEmail"];
|
|
||||||
final inputPassword = data["inputPassword"];
|
|
||||||
|
|
||||||
final userBox = await Hive.openBox("rsi_account_data");
|
|
||||||
if (inputEmail != null && inputEmail != "") {
|
|
||||||
await userBox.put("account_email", inputEmail);
|
|
||||||
}
|
|
||||||
if (isDeviceSupportWinHello) {
|
|
||||||
if (await userBox.get("enable", defaultValue: true)) {
|
|
||||||
if (inputEmail != null &&
|
|
||||||
inputEmail != "" &&
|
|
||||||
inputPassword != null &&
|
|
||||||
inputPassword != "") {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!,
|
|
||||||
"是否开启自动密码填充?",
|
|
||||||
const Text(
|
|
||||||
"盒子将使用 PIN 与 Windows 凭据加密保存您的密码,密码只存储在您的设备中。\n\n当下次登录需要输入密码时,您只需授权PIN即可自动填充登录。"));
|
|
||||||
if (ok == true) {
|
|
||||||
if (await localAuth.authenticate(localizedReason: "输入PIN以启用加密") ==
|
|
||||||
true) {
|
|
||||||
await _savePwd(inputEmail, inputPassword);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await userBox.put("enable", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final buildInfoFile = File("$installPath\\build_manifest.id");
|
|
||||||
if (await buildInfoFile.exists()) {
|
|
||||||
final buildInfo =
|
|
||||||
json.decode(await buildInfoFile.readAsString())["Data"];
|
|
||||||
dPrint("buildInfo ======= $buildInfo");
|
|
||||||
|
|
||||||
if (releaseInfo?["versionLabel"] != null &&
|
|
||||||
buildInfo["RequestedP4ChangeNum"] != null) {
|
|
||||||
if (!(releaseInfo!["versionLabel"]!
|
|
||||||
.toString()
|
|
||||||
.endsWith(buildInfo["RequestedP4ChangeNum"]!.toString()))) {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!,
|
|
||||||
"游戏版本过期",
|
|
||||||
Text(
|
|
||||||
"RSI 服务器报告版本号:${releaseInfo?["versionLabel"]} \n\n本地版本号:${buildInfo["RequestedP4ChangeNum"]} \n\n建议使用 RSI Launcher 更新游戏!"),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context!).size.width * .4),
|
|
||||||
cancel: "忽略");
|
|
||||||
if (ok == true) {
|
|
||||||
Navigator.pop(context!);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_readyForLaunch();
|
|
||||||
}, useLocalization: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
goWebView(String title, String url,
|
|
||||||
{bool useLocalization = false,
|
|
||||||
bool loginMode = false,
|
|
||||||
RsiLoginCallback? rsiLoginCallback}) async {
|
|
||||||
if (useLocalization) {
|
|
||||||
const tipVersion = 2;
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
final skip = await box.get("skip_web_login_version", defaultValue: 0);
|
|
||||||
if (skip != tipVersion) {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!,
|
|
||||||
"盒子一键启动",
|
|
||||||
const Text(
|
|
||||||
"本功能可以帮您更加便利的启动游戏。\n\n为确保账户安全 ,本功能使用汉化浏览器保留登录状态,且不会保存您的密码信息(除非你启用了自动填充功能)。"
|
|
||||||
"\n\n使用此功能登录账号时请确保您的 SC汉化盒子 是从可信任的来源下载。",
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context!).size.width * .6));
|
|
||||||
if (!ok) {
|
|
||||||
if (loginMode) {
|
|
||||||
rsiLoginCallback?.call(null, false);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await box.put("skip_web_login_version", tipVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!await WebviewWindow.isWebviewAvailable()) {
|
|
||||||
await showToast(context!, "需要安装 WebView2 Runtime");
|
|
||||||
await launchUrlString(
|
|
||||||
"https://developer.microsoft.com/en-us/microsoft-edge/webview2/");
|
|
||||||
Navigator.pop(context!);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final webViewModel = WebViewModel(context!,
|
|
||||||
loginMode: loginMode,
|
|
||||||
loginCallback: rsiLoginCallback,
|
|
||||||
loginChannel: getChannelID());
|
|
||||||
if (useLocalization) {
|
|
||||||
try {
|
|
||||||
await webViewModel
|
|
||||||
.initLocalization(homeUIModel.appWebLocalizationVersionsData!);
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
|
||||||
await webViewModel.initWebView(
|
|
||||||
title: title,
|
|
||||||
);
|
|
||||||
await webViewModel.launch(url);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
// onSaveEmail() async {
|
|
||||||
// final RegExp emailRegex = RegExp(r'^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$');
|
|
||||||
// if (!emailRegex.hasMatch(emailCtrl.text.trim())) {
|
|
||||||
// showToast(context!, "邮箱输入有误!");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// final emailBox = await Hive.openBox("quick_login_email");
|
|
||||||
// await emailBox.put(nickname, emailCtrl.text.trim());
|
|
||||||
// _readyForLaunch();
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
|
|
||||||
Future<void> _readyForLaunch() async {
|
|
||||||
final userBox = await Hive.openBox("rsi_account_data");
|
|
||||||
loginStatus = 2;
|
|
||||||
notifyListeners();
|
|
||||||
final launchData = {
|
|
||||||
"username": userBox.get("account_email", defaultValue: ""),
|
|
||||||
"token": webToken,
|
|
||||||
"auth_token": authToken,
|
|
||||||
"star_network": {
|
|
||||||
"services_endpoint": releaseInfo?["servicesEndpoint"],
|
|
||||||
"hostname": releaseInfo?["universeHost"],
|
|
||||||
"port": releaseInfo?["universePort"],
|
|
||||||
},
|
|
||||||
"TMid": const Uuid().v4(),
|
|
||||||
};
|
|
||||||
final executable = releaseInfo?["executable"];
|
|
||||||
final launchOptions = releaseInfo?["launchOptions"];
|
|
||||||
dPrint("----------launch data ====== -----------\n$launchData");
|
|
||||||
dPrint(
|
|
||||||
"----------executable data ====== -----------\n$installPath\\$executable $launchOptions");
|
|
||||||
final launchFile = File("$installPath\\loginData.json");
|
|
||||||
if (await launchFile.exists()) {
|
|
||||||
await launchFile.delete();
|
|
||||||
}
|
|
||||||
await launchFile.create();
|
|
||||||
await launchFile.writeAsString(json.encode(launchData));
|
|
||||||
notifyListeners();
|
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
|
||||||
|
|
||||||
await Future.delayed(const Duration(seconds: 3));
|
|
||||||
final processorAffinity = await SystemHelper.getCpuAffinity();
|
|
||||||
|
|
||||||
homeUIModel.doLaunchGame(
|
|
||||||
'$installPath\\$executable',
|
|
||||||
["-no_login_dialog", ...launchOptions.toString().split(" ")],
|
|
||||||
installPath,
|
|
||||||
processorAffinity);
|
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
|
||||||
Navigator.pop(context!);
|
|
||||||
}
|
|
||||||
|
|
||||||
String getChannelID() {
|
|
||||||
if (installPath.endsWith("\\LIVE")) {
|
|
||||||
return "LIVE";
|
|
||||||
} else if (installPath.endsWith("\\PTU")) {
|
|
||||||
return "PTU";
|
|
||||||
} else if (installPath.endsWith("\\EPTU")) {
|
|
||||||
return "EPTU";
|
|
||||||
}
|
|
||||||
return "LIVE";
|
|
||||||
}
|
|
||||||
|
|
||||||
_savePwd(String inputEmail, String inputPassword) async {
|
|
||||||
final algorithm = AesGcm.with256bits();
|
|
||||||
final secretKey = await algorithm.newSecretKey();
|
|
||||||
final nonce = algorithm.newNonce();
|
|
||||||
|
|
||||||
final secretBox = await algorithm.encrypt(utf8.encode(inputPassword),
|
|
||||||
secretKey: secretKey, nonce: nonce);
|
|
||||||
|
|
||||||
await algorithm.decrypt(
|
|
||||||
SecretBox(secretBox.cipherText,
|
|
||||||
nonce: secretBox.nonce, mac: secretBox.mac),
|
|
||||||
secretKey: secretKey);
|
|
||||||
|
|
||||||
final pwdEncrypted = base64.encode(secretBox.cipherText);
|
|
||||||
|
|
||||||
final userBox = await Hive.openBox("rsi_account_data");
|
|
||||||
await userBox.put("account_email", inputEmail);
|
|
||||||
await userBox.put("account_pwd_encrypted", pwdEncrypted);
|
|
||||||
await userBox.put("nonce", base64.encode(secretBox.nonce));
|
|
||||||
await userBox.put("mac", base64.encode(secretBox.mac.bytes));
|
|
||||||
|
|
||||||
final secretKeyStr = base64.encode((await secretKey.extractBytes()));
|
|
||||||
|
|
||||||
Win32Credentials.write(
|
|
||||||
credentialName: "SCToolbox_RSI_Account_secret",
|
|
||||||
userName: inputEmail,
|
|
||||||
password: secretKeyStr);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,268 +0,0 @@
|
|||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/game_performance_data.dart';
|
|
||||||
|
|
||||||
import 'performance_ui_model.dart';
|
|
||||||
|
|
||||||
class PerformanceUI extends BaseUI<PerformanceUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, PerformanceUIModel model) {
|
|
||||||
var content = makeLoading(context);
|
|
||||||
|
|
||||||
if (model.performanceMap != null) {
|
|
||||||
content = Stack(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 12, left: 12, right: 12),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 24, right: 24),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
if (model.showGraphicsPerformanceTip)
|
|
||||||
InfoBar(
|
|
||||||
title: const Text("图形优化提示"),
|
|
||||||
content: const Text(
|
|
||||||
"该功能对优化显卡瓶颈有很大帮助,但对 CPU 瓶颈可能起反效果,如果您显卡性能强劲,可以尝试使用更好的画质来获得更高的显卡利用率。",
|
|
||||||
),
|
|
||||||
onClose: () => model.closeTip(),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"当前状态:${model.enabled ? "已应用" : "未应用"}",
|
|
||||||
style: const TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 32),
|
|
||||||
const Text(
|
|
||||||
"预设:",
|
|
||||||
style: TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
for (final item in const {
|
|
||||||
"low": "低",
|
|
||||||
"medium": "中",
|
|
||||||
"high": "高",
|
|
||||||
"ultra": "超级"
|
|
||||||
}.entries)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 6, right: 6),
|
|
||||||
child: Button(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 2, bottom: 2, left: 4, right: 4),
|
|
||||||
child: Text(item.value),
|
|
||||||
),
|
|
||||||
onPressed: () =>
|
|
||||||
model.onChangePreProfile(item.key)),
|
|
||||||
),
|
|
||||||
const Text("(预设只修改图形设置)"),
|
|
||||||
const Spacer(),
|
|
||||||
Button(
|
|
||||||
onPressed: () => model.refresh(),
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.refresh),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
child: const Text(
|
|
||||||
" 恢复默认 ",
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
onPressed: () => model.clean()),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
Button(
|
|
||||||
child: const Text(
|
|
||||||
"应用",
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
onPressed: () => model.applyProfile(false)),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Button(
|
|
||||||
child: const Text(
|
|
||||||
"应用并清理着色器(推荐)",
|
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
onPressed: () => model.applyProfile(true)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: MasonryGridView.count(
|
|
||||||
crossAxisCount: 2,
|
|
||||||
mainAxisSpacing: 1,
|
|
||||||
crossAxisSpacing: 1,
|
|
||||||
itemCount: model.performanceMap!.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return makeItemGroup(
|
|
||||||
model.performanceMap!.entries.elementAt(index));
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (model.workingString.isNotEmpty)
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black.withAlpha(150),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const ProgressRing(),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(model.workingString),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return makeDefaultPage(context, model, content: content);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeItemGroup(MapEntry<String?, List<GamePerformanceData>> group) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${group.key}",
|
|
||||||
style: const TextStyle(fontSize: 20),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Container(
|
|
||||||
color: FluentTheme.of(context).cardColor.withOpacity(.2),
|
|
||||||
height: 1),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
for (final item in group.value) makeItem(item)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeItem(GamePerformanceData item) {
|
|
||||||
final model = ref.watch(provider);
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${item.name}",
|
|
||||||
style: const TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
if (item.type == "int")
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 72,
|
|
||||||
child: TextFormBox(
|
|
||||||
key: UniqueKey(),
|
|
||||||
initialValue: "${item.value}",
|
|
||||||
onFieldSubmitted: (str) {
|
|
||||||
dPrint(str);
|
|
||||||
if (str.isEmpty) return;
|
|
||||||
final v = int.tryParse(str);
|
|
||||||
if (v != null &&
|
|
||||||
v < (item.max ?? 0) &&
|
|
||||||
v >= (item.min ?? 0)) {
|
|
||||||
item.value = v;
|
|
||||||
}
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
onTapOutside: (e) {
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 32),
|
|
||||||
SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width / 4,
|
|
||||||
child: Slider(
|
|
||||||
value: item.value?.toDouble() ?? 0,
|
|
||||||
min: item.min?.toDouble() ?? 0,
|
|
||||||
max: item.max?.toDouble() ?? 0,
|
|
||||||
onChanged: (double value) {
|
|
||||||
item.value = value.toInt();
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
else if (item.type == "bool")
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
ToggleSwitch(
|
|
||||||
checked: item.value == 1,
|
|
||||||
onChanged: (bool value) {
|
|
||||||
item.value = value ? 1 : 0;
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
else if (item.type == "customize")
|
|
||||||
TextFormBox(
|
|
||||||
maxLines: 10,
|
|
||||||
placeholder:
|
|
||||||
"您可以在这里输入未收录进盒子的自定义参数。配置示例:\n\nr_displayinfo=0\nr_VSync=0",
|
|
||||||
controller: model.customizeCtrl,
|
|
||||||
),
|
|
||||||
if (item.info != null && item.info!.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
"${item.info}",
|
|
||||||
style:
|
|
||||||
TextStyle(fontSize: 14, color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
if (item.type != "customize")
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${item.key} 最小值: ${item.min} / 最大值: ${item.max}",
|
|
||||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Container(
|
|
||||||
color: FluentTheme.of(context).cardColor.withOpacity(.1),
|
|
||||||
height: 1),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, PerformanceUIModel model) =>
|
|
||||||
"性能优化 ${model.scPath}";
|
|
||||||
}
|
|
@ -1,211 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/game_performance_data.dart';
|
|
||||||
|
|
||||||
class PerformanceUIModel extends BaseUIModel {
|
|
||||||
String scPath;
|
|
||||||
|
|
||||||
PerformanceUIModel(this.scPath);
|
|
||||||
|
|
||||||
TextEditingController customizeCtrl = TextEditingController();
|
|
||||||
|
|
||||||
Map<String?, List<GamePerformanceData>>? performanceMap;
|
|
||||||
|
|
||||||
List<String> inAppKeys = [];
|
|
||||||
|
|
||||||
String workingString = "";
|
|
||||||
|
|
||||||
late final confFile = File("$scPath\\USER.cfg");
|
|
||||||
|
|
||||||
bool enabled = false;
|
|
||||||
|
|
||||||
bool showGraphicsPerformanceTip = false;
|
|
||||||
static const _graphicsPerformanceTipVersion = 1;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future loadData() async {
|
|
||||||
customizeCtrl.clear();
|
|
||||||
inAppKeys.clear();
|
|
||||||
final String jsonString =
|
|
||||||
await rootBundle.loadString('assets/performance.json');
|
|
||||||
final list = json.decode(jsonString);
|
|
||||||
|
|
||||||
if (list is List) {
|
|
||||||
performanceMap = {};
|
|
||||||
for (var element in list) {
|
|
||||||
final item = GamePerformanceData.fromJson(element);
|
|
||||||
if (item.key != "customize") {
|
|
||||||
inAppKeys.add(item.key ?? "");
|
|
||||||
}
|
|
||||||
performanceMap?[item.group] ??= [];
|
|
||||||
performanceMap?[item.group]?.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await confFile.exists()) {
|
|
||||||
await _readConf();
|
|
||||||
} else {
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
final v = box.get("close_graphics_performance_tip", defaultValue: -1);
|
|
||||||
showGraphicsPerformanceTip = v != _graphicsPerformanceTipVersion;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
onChangePreProfile(String key) {
|
|
||||||
switch (key) {
|
|
||||||
case "low":
|
|
||||||
performanceMap?.forEach((key, v) {
|
|
||||||
if (key?.contains("图形") ?? false) {
|
|
||||||
for (var element in v) {
|
|
||||||
element.value = element.min;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case "medium":
|
|
||||||
performanceMap?.forEach((key, v) {
|
|
||||||
if (key?.contains("图形") ?? false) {
|
|
||||||
for (var element in v) {
|
|
||||||
element.value = ((element.max ?? 0) ~/ 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case "high":
|
|
||||||
performanceMap?.forEach((key, v) {
|
|
||||||
if (key?.contains("图形") ?? false) {
|
|
||||||
for (var element in v) {
|
|
||||||
element.value = ((element.max ?? 0) / 1.5).ceil();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case "ultra":
|
|
||||||
performanceMap?.forEach((key, v) {
|
|
||||||
if (key?.contains("图形") ?? false) {
|
|
||||||
for (var element in v) {
|
|
||||||
element.value = element.max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
applyProfile(bool cleanShader) async {
|
|
||||||
if (performanceMap == null) return;
|
|
||||||
AnalyticsApi.touch("performance_apply");
|
|
||||||
workingString = "生成配置文件";
|
|
||||||
notifyListeners();
|
|
||||||
String conf = "";
|
|
||||||
for (var v in performanceMap!.entries) {
|
|
||||||
for (var c in v.value) {
|
|
||||||
if (c.key != "customize") {
|
|
||||||
conf = "$conf${c.key}=${c.value}\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (customizeCtrl.text.trim().isNotEmpty) {
|
|
||||||
final lines = customizeCtrl.text.split("\n");
|
|
||||||
for (var value in lines) {
|
|
||||||
final sp = value.split("=");
|
|
||||||
// 忽略无效的配置文件
|
|
||||||
if (sp.length == 2) {
|
|
||||||
conf = "$conf${sp[0].trim()}=${sp[1].trim()}\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
workingString = "写出配置文件";
|
|
||||||
notifyListeners();
|
|
||||||
if (await confFile.exists()) {
|
|
||||||
await confFile.delete();
|
|
||||||
}
|
|
||||||
await confFile.create();
|
|
||||||
await confFile.writeAsString(conf);
|
|
||||||
if (cleanShader) {
|
|
||||||
workingString = "清理着色器";
|
|
||||||
notifyListeners();
|
|
||||||
await _cleanShaderCache();
|
|
||||||
}
|
|
||||||
workingString = "完成...";
|
|
||||||
notifyListeners();
|
|
||||||
await await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
await reloadData();
|
|
||||||
workingString = "";
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _cleanShaderCache() async {
|
|
||||||
final gameShaderCachePath = await SCLoggerHelper.getShaderCachePath();
|
|
||||||
final l =
|
|
||||||
await Directory(gameShaderCachePath!).list(recursive: false).toList();
|
|
||||||
for (var value in l) {
|
|
||||||
if (value is Directory) {
|
|
||||||
if (!value.absolute.path.contains("Crashes")) {
|
|
||||||
await value.delete(recursive: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
showToast(context!, "清理着色器后首次进入游戏可能会出现卡顿,请耐心等待游戏初始化完毕。");
|
|
||||||
}
|
|
||||||
|
|
||||||
_readConf() async {
|
|
||||||
if (performanceMap == null) return;
|
|
||||||
enabled = true;
|
|
||||||
final confString = await confFile.readAsString();
|
|
||||||
for (var value in confString.split("\n")) {
|
|
||||||
final kv = value.split("=");
|
|
||||||
for (var m in performanceMap!.entries) {
|
|
||||||
for (var value in m.value) {
|
|
||||||
if (value.key == kv[0].trim()) {
|
|
||||||
final v = int.tryParse(kv[1].trim());
|
|
||||||
if (v != null) value.value = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (kv.length == 2 && !inAppKeys.contains(kv[0].trim())) {
|
|
||||||
customizeCtrl.text =
|
|
||||||
"${customizeCtrl.text}${kv[0].trim()}=${kv[1].trim()}\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
clean() async {
|
|
||||||
workingString = "删除配置文件...";
|
|
||||||
notifyListeners();
|
|
||||||
if (await confFile.exists()) {
|
|
||||||
await confFile.delete(recursive: true);
|
|
||||||
}
|
|
||||||
workingString = "清理着色器";
|
|
||||||
notifyListeners();
|
|
||||||
await _cleanShaderCache();
|
|
||||||
workingString = "完成...";
|
|
||||||
await await Future.delayed(const Duration(milliseconds: 300));
|
|
||||||
await reloadData();
|
|
||||||
workingString = "";
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh() async {
|
|
||||||
await reloadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
closeTip() async {
|
|
||||||
final box = await Hive.openBox("app_conf");
|
|
||||||
await box.put(
|
|
||||||
"close_graphics_performance_tip", _graphicsPerformanceTipVersion);
|
|
||||||
loadData();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,318 +0,0 @@
|
|||||||
// ignore_for_file: use_build_context_synchronously
|
|
||||||
|
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:cryptography/cryptography.dart';
|
|
||||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:local_auth/local_auth.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/win32/credentials.dart';
|
|
||||||
import 'package:starcitizen_doctor/data/app_web_localization_versions_data.dart';
|
|
||||||
|
|
||||||
import '../../../base/ui.dart';
|
|
||||||
|
|
||||||
typedef RsiLoginCallback = void Function(Map? data, bool success);
|
|
||||||
|
|
||||||
class WebViewModel {
|
|
||||||
late Webview webview;
|
|
||||||
final BuildContext context;
|
|
||||||
|
|
||||||
bool _isClosed = false;
|
|
||||||
|
|
||||||
bool get isClosed => _isClosed;
|
|
||||||
|
|
||||||
WebViewModel(this.context,
|
|
||||||
{this.loginMode = false, this.loginCallback, this.loginChannel = "LIVE"});
|
|
||||||
|
|
||||||
String url = "";
|
|
||||||
bool canGoBack = false;
|
|
||||||
|
|
||||||
final localizationResource = <String, dynamic>{};
|
|
||||||
|
|
||||||
var localizationScript = "";
|
|
||||||
|
|
||||||
bool enableCapture = false;
|
|
||||||
|
|
||||||
bool isEnableToolSiteMirrors = false;
|
|
||||||
|
|
||||||
Map<String, String>? _curReplaceWords;
|
|
||||||
|
|
||||||
Map<String, String>? get curReplaceWords => _curReplaceWords;
|
|
||||||
|
|
||||||
final bool loginMode;
|
|
||||||
final String loginChannel;
|
|
||||||
|
|
||||||
bool _loginModeSuccess = false;
|
|
||||||
|
|
||||||
final RsiLoginCallback? loginCallback;
|
|
||||||
|
|
||||||
initWebView({String title = ""}) async {
|
|
||||||
try {
|
|
||||||
final userBox = await Hive.openBox("app_conf");
|
|
||||||
isEnableToolSiteMirrors =
|
|
||||||
userBox.get("isEnableToolSiteMirrors", defaultValue: false);
|
|
||||||
webview = await WebviewWindow.create(
|
|
||||||
configuration: CreateConfiguration(
|
|
||||||
windowWidth: loginMode ? 960 : 1920,
|
|
||||||
windowHeight: loginMode ? 720 : 1080,
|
|
||||||
userDataFolderWindows:
|
|
||||||
"${AppConf.applicationSupportDir}/webview_data",
|
|
||||||
title: title));
|
|
||||||
// webview.openDevToolsWindow();
|
|
||||||
webview.isNavigating.addListener(() async {
|
|
||||||
if (!webview.isNavigating.value && localizationResource.isNotEmpty) {
|
|
||||||
dPrint("webview Navigating url === $url");
|
|
||||||
if (url.contains("robertsspaceindustries.com")) {
|
|
||||||
// SC 官网
|
|
||||||
dPrint("load script");
|
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
|
||||||
await webview.evaluateJavaScript(localizationScript);
|
|
||||||
dPrint("update replaceWords");
|
|
||||||
final replaceWords = _getLocalizationResource("zh-CN");
|
|
||||||
|
|
||||||
const org = "https://robertsspaceindustries.com/orgs";
|
|
||||||
const citizens = "https://robertsspaceindustries.com/citizens";
|
|
||||||
const organization =
|
|
||||||
"https://robertsspaceindustries.com/account/organization";
|
|
||||||
const concierge =
|
|
||||||
"https://robertsspaceindustries.com/account/concierge";
|
|
||||||
const referral =
|
|
||||||
"https://robertsspaceindustries.com/account/referral-program";
|
|
||||||
const address =
|
|
||||||
"https://robertsspaceindustries.com/account/addresses";
|
|
||||||
|
|
||||||
const hangar = "https://robertsspaceindustries.com/account/pledges";
|
|
||||||
|
|
||||||
const spectrum =
|
|
||||||
"https://robertsspaceindustries.com/spectrum/community/";
|
|
||||||
// 跳过光谱论坛 https://github.com/StarCitizenToolBox/StarCitizenBoxBrowserEx/issues/1
|
|
||||||
if (url.startsWith(spectrum)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url.startsWith(org) ||
|
|
||||||
url.startsWith(citizens) ||
|
|
||||||
url.startsWith(organization)) {
|
|
||||||
replaceWords.add({"word": 'members', "replacement": '名成员'});
|
|
||||||
replaceWords.addAll(_getLocalizationResource("orgs"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (address.startsWith(address)) {
|
|
||||||
replaceWords.addAll(_getLocalizationResource("address"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url.startsWith(referral)) {
|
|
||||||
replaceWords.addAll([
|
|
||||||
{"word": 'Total recruits: ', "replacement": '总邀请数:'},
|
|
||||||
{"word": 'Prospects ', "replacement": '未完成的邀请'},
|
|
||||||
{"word": 'Recruits', "replacement": '已完成的邀请'},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url.startsWith(concierge)) {
|
|
||||||
replaceWords.clear();
|
|
||||||
replaceWords.addAll(_getLocalizationResource("concierge"));
|
|
||||||
}
|
|
||||||
if (url.startsWith(hangar)) {
|
|
||||||
replaceWords.addAll(_getLocalizationResource("hangar"));
|
|
||||||
}
|
|
||||||
|
|
||||||
_curReplaceWords = {};
|
|
||||||
for (var element in replaceWords) {
|
|
||||||
_curReplaceWords?[element["word"] ?? ""] =
|
|
||||||
element["replacement"] ?? "";
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
|
||||||
await webview.evaluateJavaScript(
|
|
||||||
"WebLocalizationUpdateReplaceWords(${json.encode(replaceWords)},$enableCapture)");
|
|
||||||
|
|
||||||
/// loginMode
|
|
||||||
if (loginMode) {
|
|
||||||
dPrint(
|
|
||||||
"--- do rsi login ---\n run === getRSILauncherToken(\"$loginChannel\");");
|
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
|
||||||
webview.evaluateJavaScript(
|
|
||||||
"getRSILauncherToken(\"$loginChannel\");");
|
|
||||||
}
|
|
||||||
} else if (url
|
|
||||||
.startsWith(await _handleMirrorsUrl("https://www.erkul.games"))) {
|
|
||||||
dPrint("load script");
|
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
|
||||||
await webview.evaluateJavaScript(localizationScript);
|
|
||||||
dPrint("update replaceWords");
|
|
||||||
final replaceWords = _getLocalizationResource("DPS");
|
|
||||||
await webview.evaluateJavaScript(
|
|
||||||
"WebLocalizationUpdateReplaceWords(${json.encode(replaceWords)},$enableCapture)");
|
|
||||||
} else if (url
|
|
||||||
.startsWith(await _handleMirrorsUrl("https://uexcorp.space"))) {
|
|
||||||
dPrint("load script");
|
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
|
||||||
await webview.evaluateJavaScript(localizationScript);
|
|
||||||
dPrint("update replaceWords");
|
|
||||||
final replaceWords = _getLocalizationResource("UEX");
|
|
||||||
await webview.evaluateJavaScript(
|
|
||||||
"WebLocalizationUpdateReplaceWords(${json.encode(replaceWords)},$enableCapture)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
webview.addOnUrlRequestCallback((url) {
|
|
||||||
dPrint("OnUrlRequestCallback === $url");
|
|
||||||
this.url = url;
|
|
||||||
});
|
|
||||||
webview.onClose.whenComplete(dispose);
|
|
||||||
if (loginMode) {
|
|
||||||
webview.addOnWebMessageReceivedCallback((messageString) {
|
|
||||||
final message = json.decode(messageString);
|
|
||||||
if (message["action"] == "webview_rsi_login_show_window") {
|
|
||||||
webview.setWebviewWindowVisibility(true);
|
|
||||||
_checkAutoLogin(webview);
|
|
||||||
} else if (message["action"] == "webview_rsi_login_success") {
|
|
||||||
_loginModeSuccess = true;
|
|
||||||
loginCallback?.call(message, true);
|
|
||||||
webview.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Future.delayed(const Duration(seconds: 1))
|
|
||||||
.then((value) => {webview.setWebviewWindowVisibility(false)});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
showToast(context, "初始化失败:$e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> _handleMirrorsUrl(String url) async {
|
|
||||||
var finalUrl = url;
|
|
||||||
if (isEnableToolSiteMirrors) {
|
|
||||||
for (var kv in AppConf.networkVersionData!.webMirrors!.entries) {
|
|
||||||
if (url.startsWith(kv.key)) {
|
|
||||||
finalUrl = url.replaceFirst(kv.key, kv.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return finalUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
launch(String url) async {
|
|
||||||
webview.launch(await _handleMirrorsUrl(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
initLocalization(AppWebLocalizationVersionsData v) async {
|
|
||||||
localizationScript = await rootBundle.loadString('assets/web_script.js');
|
|
||||||
|
|
||||||
/// https://github.com/CxJuice/Uex_Chinese_Translate
|
|
||||||
// get versions
|
|
||||||
final hostUrl = URLConf.webTranslateHomeUrl;
|
|
||||||
dPrint("AppWebLocalizationVersionsData === ${v.toJson()}");
|
|
||||||
|
|
||||||
localizationResource["zh-CN"] = await _getJson("$hostUrl/zh-CN-rsi.json",
|
|
||||||
cacheKey: "rsi", version: v.rsi);
|
|
||||||
localizationResource["concierge"] = await _getJson(
|
|
||||||
"$hostUrl/concierge.json",
|
|
||||||
cacheKey: "concierge",
|
|
||||||
version: v.concierge);
|
|
||||||
localizationResource["orgs"] =
|
|
||||||
await _getJson("$hostUrl/orgs.json", cacheKey: "orgs", version: v.orgs);
|
|
||||||
localizationResource["address"] = await _getJson("$hostUrl/addresses.json",
|
|
||||||
cacheKey: "addresses", version: v.addresses);
|
|
||||||
localizationResource["hangar"] = await _getJson("$hostUrl/hangar.json",
|
|
||||||
cacheKey: "hangar", version: v.hangar);
|
|
||||||
localizationResource["UEX"] = await _getJson("$hostUrl/zh-CN-uex.json",
|
|
||||||
cacheKey: "uex", version: v.uex);
|
|
||||||
localizationResource["DPS"] = await _getJson("$hostUrl/zh-CN-dps.json",
|
|
||||||
cacheKey: "dps", version: v.dps);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Map<String, String>> _getLocalizationResource(String key) {
|
|
||||||
final List<Map<String, String>> localizations = [];
|
|
||||||
final dict = localizationResource[key];
|
|
||||||
if (dict is Map) {
|
|
||||||
for (var element in dict.entries) {
|
|
||||||
final k = element.key
|
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.replaceAll(RegExp("/\xa0/g"), ' ')
|
|
||||||
.replaceAll(RegExp("/s{2,}/g"), ' ');
|
|
||||||
localizations
|
|
||||||
.add({"word": k, "replacement": element.value.toString().trim()});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return localizations;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Map> _getJson(String url,
|
|
||||||
{String cacheKey = "", String? version}) async {
|
|
||||||
final box = await Hive.openBox("web_localization_cache_data");
|
|
||||||
if (cacheKey.isNotEmpty) {
|
|
||||||
final localVersion = box.get("${cacheKey}_version}", defaultValue: "");
|
|
||||||
var data = box.get(cacheKey, defaultValue: {});
|
|
||||||
if (data is Map && data.isNotEmpty && localVersion == version) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final startTime = DateTime.now();
|
|
||||||
final r = await RSHttp.getText(url);
|
|
||||||
final endTime = DateTime.now();
|
|
||||||
final data = json.decode(r);
|
|
||||||
if (cacheKey.isNotEmpty) {
|
|
||||||
dPrint(
|
|
||||||
"update $cacheKey v == $version time == ${(endTime.microsecondsSinceEpoch - startTime.microsecondsSinceEpoch) / 1000 / 1000}s");
|
|
||||||
await box.put(cacheKey, data);
|
|
||||||
await box.put("${cacheKey}_version}", version);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addOnWebMessageReceivedCallback(OnWebMessageReceivedCallback callback) {
|
|
||||||
webview.addOnWebMessageReceivedCallback(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeOnWebMessageReceivedCallback(
|
|
||||||
OnWebMessageReceivedCallback callback) {
|
|
||||||
webview.removeOnWebMessageReceivedCallback(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
FutureOr<void> dispose() {
|
|
||||||
if (loginMode && !_loginModeSuccess) {
|
|
||||||
loginCallback?.call(null, false);
|
|
||||||
}
|
|
||||||
_isClosed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _checkAutoLogin(Webview webview) async {
|
|
||||||
final LocalAuthentication localAuth = LocalAuthentication();
|
|
||||||
if (!await localAuth.isDeviceSupported()) return;
|
|
||||||
|
|
||||||
final userBox = await Hive.openBox("rsi_account_data");
|
|
||||||
final email = await userBox.get("account_email", defaultValue: "");
|
|
||||||
|
|
||||||
final pwdE = await userBox.get("account_pwd_encrypted", defaultValue: "");
|
|
||||||
final nonceStr = await userBox.get("nonce", defaultValue: "");
|
|
||||||
final macStr = await userBox.get("mac", defaultValue: "");
|
|
||||||
if (email == "") return;
|
|
||||||
webview.evaluateJavaScript("RSIAutoLogin(\"$email\",\"\")");
|
|
||||||
if (pwdE != "" && nonceStr != "" && macStr != "") {
|
|
||||||
// send toast
|
|
||||||
webview.evaluateJavaScript("SCTShowToast(\"请完成 Windows Hello 验证以填充密码\")");
|
|
||||||
// decrypt
|
|
||||||
if (await localAuth.authenticate(localizedReason: "请输入设备PIN以自动登录RSI账户") !=
|
|
||||||
true) return;
|
|
||||||
final kv = Win32Credentials.read("SCToolbox_RSI_Account_secret");
|
|
||||||
if (kv == null || kv.key != email) return;
|
|
||||||
|
|
||||||
final algorithm = AesGcm.with256bits();
|
|
||||||
final r = await algorithm.decrypt(
|
|
||||||
SecretBox(base64.decode(pwdE),
|
|
||||||
nonce: base64.decode(nonceStr), mac: Mac(base64.decode(macStr))),
|
|
||||||
secretKey: SecretKey(base64.decode(kv.value)));
|
|
||||||
final decryptedPwd = utf8.decode(r);
|
|
||||||
webview.evaluateJavaScript("RSIAutoLogin(\"$email\",\"$decryptedPwd\")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
import 'package:markdown_widget/config/all.dart';
|
|
||||||
import 'package:markdown_widget/widget/blocks/leaf/code_block.dart';
|
|
||||||
import 'package:markdown_widget/widget/markdown.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
|
|
||||||
import 'webview_localization_capture_ui_model.dart';
|
|
||||||
|
|
||||||
class WebviewLocalizationCaptureUI
|
|
||||||
extends BaseUI<WebviewLocalizationCaptureUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(
|
|
||||||
BuildContext context, WebviewLocalizationCaptureUIModel model) {
|
|
||||||
return makeDefaultPage(context, model,
|
|
||||||
content: model.data.isEmpty
|
|
||||||
? const Center(
|
|
||||||
child: Text("等待数据"),
|
|
||||||
)
|
|
||||||
: Column(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: MarkdownWidget(
|
|
||||||
data: model.renderString,
|
|
||||||
config: MarkdownConfig(configs: [
|
|
||||||
const PreConfig(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Color.fromRGBO(0, 0, 0, .4),
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(8.0)),
|
|
||||||
)),
|
|
||||||
]),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(FluentIcons.refresh), onPressed: model.doClean)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(
|
|
||||||
BuildContext context, WebviewLocalizationCaptureUIModel model) =>
|
|
||||||
"Webview 翻译捕获工具";
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/webview/webview.dart';
|
|
||||||
|
|
||||||
class WebviewLocalizationCaptureUIModel extends BaseUIModel {
|
|
||||||
final WebViewModel webViewModel;
|
|
||||||
|
|
||||||
WebviewLocalizationCaptureUIModel(this.webViewModel);
|
|
||||||
|
|
||||||
Map<String, dynamic> data = {};
|
|
||||||
|
|
||||||
String renderString = "";
|
|
||||||
|
|
||||||
final jsonEncoder = const JsonEncoder.withIndent(' ');
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initModel() {
|
|
||||||
webViewModel.addOnWebMessageReceivedCallback(_onMessage);
|
|
||||||
super.initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
webViewModel.removeOnWebMessageReceivedCallback(_onMessage);
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onMessage(String message) {
|
|
||||||
final map = json.decode(message);
|
|
||||||
if (map["action"] == "webview_localization_capture") {
|
|
||||||
dPrint(
|
|
||||||
"<WebviewLocalizationCaptureUIModel> webview_localization_capture message == $map");
|
|
||||||
final key = map["key"];
|
|
||||||
if (key != null && key.toString().trim() != "") {
|
|
||||||
if (!(webViewModel.curReplaceWords?.containsKey(key) ?? false)) {
|
|
||||||
data[key] = map["value"];
|
|
||||||
}
|
|
||||||
_updateRenderString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_updateRenderString() {
|
|
||||||
renderString = "```json\n${jsonEncoder.convert(data)}\n```";
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
doClean() {
|
|
||||||
data.clear();
|
|
||||||
_updateRenderString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,166 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/main.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/about/about_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/about/about_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/home_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/party_room/party_room_home_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/settings/settings_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/tools/tools_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/tools/tools_ui_model.dart';
|
|
||||||
import 'package:window_manager/window_manager.dart';
|
|
||||||
|
|
||||||
import 'home/home_ui_model.dart';
|
|
||||||
import 'index_ui_model.dart';
|
|
||||||
import 'party_room/party_room_home_ui.dart';
|
|
||||||
|
|
||||||
class IndexUI extends BaseUI<IndexUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, IndexUIModel model) {
|
|
||||||
return NavigationView(
|
|
||||||
appBar: NavigationAppBar(
|
|
||||||
automaticallyImplyLeading: false,
|
|
||||||
title: () {
|
|
||||||
return DragToMoveArea(
|
|
||||||
child: Align(
|
|
||||||
alignment: AlignmentDirectional.centerStart,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Image.asset(
|
|
||||||
"assets/app_logo_mini.png",
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Text(
|
|
||||||
"SC汉化盒子 V${AppConf.appVersion} ${AppConf.isMSE ? "" : " Dev"}")
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}(),
|
|
||||||
actions: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: Stack(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(6),
|
|
||||||
child: Icon(
|
|
||||||
FluentIcons.installation,
|
|
||||||
size: 22,
|
|
||||||
color: Colors.white.withOpacity(.6),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (model.aria2TotalTaskNum != 0)
|
|
||||||
Positioned(
|
|
||||||
bottom: 0,
|
|
||||||
right: 0,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 6, right: 6, bottom: 1.5, top: 1.5),
|
|
||||||
child: Text(
|
|
||||||
"${model.aria2TotalTaskNum}",
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 8,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: model.goDownloader),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
const WindowButtons()
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
pane: NavigationPane(
|
|
||||||
selected: model.curIndex,
|
|
||||||
items: getNavigationPaneItems(model),
|
|
||||||
size: const NavigationPaneSize(openWidth: 64),
|
|
||||||
),
|
|
||||||
paneBodyBuilder: (item, child) {
|
|
||||||
// final name =
|
|
||||||
// item?.key is ValueKey ? (item!.key as ValueKey).value : null;
|
|
||||||
return FocusTraversalGroup(
|
|
||||||
key: ValueKey('body_${model.curIndex}'),
|
|
||||||
child: getPage(model),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget getPage(IndexUIModel model) {
|
|
||||||
switch (model.curIndex) {
|
|
||||||
case 0:
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => HomeUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
model.getChildUIModelProviders<HomeUIModel>("home"));
|
|
||||||
case 1:
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => PartyRoomHomeUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
model.getChildUIModelProviders<PartyRoomHomeUIModel>("party"));
|
|
||||||
case 2:
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => ToolsUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
model.getChildUIModelProviders<ToolsUIModel>("tools"));
|
|
||||||
case 3:
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => SettingUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
model.getChildUIModelProviders<SettingUIModel>("settings"));
|
|
||||||
case 4:
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => AboutUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
model.getChildUIModelProviders<AboutUIModel>("about"));
|
|
||||||
}
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<NavigationPaneItem> getNavigationPaneItems(IndexUIModel model) {
|
|
||||||
final menus = {
|
|
||||||
FluentIcons.home: "首页",
|
|
||||||
FluentIcons.game: "大厅",
|
|
||||||
FluentIcons.toolbox: "工具",
|
|
||||||
FluentIcons.settings: "设置",
|
|
||||||
FluentIcons.info: "关于",
|
|
||||||
};
|
|
||||||
return [
|
|
||||||
for (final kv in menus.entries)
|
|
||||||
PaneItem(
|
|
||||||
icon: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 6, bottom: 6, left: 4),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Icon(kv.key, size: 18),
|
|
||||||
const SizedBox(height: 3),
|
|
||||||
Text(
|
|
||||||
kv.value,
|
|
||||||
style: const TextStyle(fontSize: 11),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// title: Text(kv.value),
|
|
||||||
body: const SizedBox.shrink(),
|
|
||||||
onTap: () {
|
|
||||||
model.onIndexMenuTap(kv.value);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, IndexUIModel model) => "";
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:aria2/models/aria2GlobalStat.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/aria2c.dart';
|
|
||||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/about/about_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/downloader/downloader_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/downloader/downloader_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/tools/tools_ui_model.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
import 'party_room/party_room_home_ui_model.dart';
|
|
||||||
|
|
||||||
class IndexUIModel extends BaseUIModel {
|
|
||||||
int curIndex = 0;
|
|
||||||
|
|
||||||
Aria2GlobalStat? aria2globalStat;
|
|
||||||
|
|
||||||
int get aria2TotalTaskNum => aria2globalStat == null
|
|
||||||
? 0
|
|
||||||
: ((aria2globalStat!.numActive ?? 0) +
|
|
||||||
(aria2globalStat!.numWaiting ?? 0));
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initModel() {
|
|
||||||
_checkRuntime();
|
|
||||||
_listenAria2c();
|
|
||||||
Future.delayed(const Duration(milliseconds: 300))
|
|
||||||
.then((value) => globalUIModel.doCheckUpdate(context!));
|
|
||||||
super.initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
BaseUIModel? onCreateChildUIModel(modelKey) {
|
|
||||||
switch (modelKey) {
|
|
||||||
case "home":
|
|
||||||
return HomeUIModel();
|
|
||||||
case "tools":
|
|
||||||
return ToolsUIModel();
|
|
||||||
case "settings":
|
|
||||||
return SettingUIModel();
|
|
||||||
case "about":
|
|
||||||
return AboutUIModel();
|
|
||||||
case "party":
|
|
||||||
return PartyRoomHomeUIModel();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onIndexMenuTap(String value) {
|
|
||||||
final index = {
|
|
||||||
"首页": 0,
|
|
||||||
"大厅": 1,
|
|
||||||
"工具": 2,
|
|
||||||
"设置": 3,
|
|
||||||
"关于": 4,
|
|
||||||
};
|
|
||||||
curIndex = index[value] ?? 0;
|
|
||||||
switch (curIndex) {
|
|
||||||
case 0:
|
|
||||||
getCreatedChildUIModel("home")?.reloadData();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
getCreatedChildUIModel("party")?.reloadData();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
getCreatedChildUIModel("tools")?.reloadData();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
getCreatedChildUIModel("settings")?.reloadData();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _checkRuntime() async {
|
|
||||||
Future<void> onError() async {
|
|
||||||
await showToast(context!, "运行环境出错,请检查系统环境变量 (PATH)!");
|
|
||||||
await launchUrlString(
|
|
||||||
"https://answers.microsoft.com/zh-hans/windows/forum/all/%E7%B3%BB%E7%BB%9F%E7%8E%AF%E5%A2%83%E5%8F%98/b88369e6-2620-4a77-b07a-d0af50894a07");
|
|
||||||
await AnalyticsApi.touch("error_powershell");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
var result =
|
|
||||||
await Process.run(SystemHelper.powershellPath, ["echo", "ping"]);
|
|
||||||
if (result.stdout.toString().startsWith("ping")) {
|
|
||||||
dPrint("powershell check pass");
|
|
||||||
} else {
|
|
||||||
onError();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
onError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> goDownloader() async {
|
|
||||||
await BaseUIContainer(
|
|
||||||
uiCreate: () => DownloaderUI(),
|
|
||||||
modelCreate: () => DownloaderUIModel()).push(context!);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _listenAria2c() async {
|
|
||||||
while (true) {
|
|
||||||
if (!mounted) return;
|
|
||||||
try {
|
|
||||||
if (Aria2cManager.isAvailable) {
|
|
||||||
final aria2c = Aria2cManager.getClient();
|
|
||||||
aria2globalStat = await aria2c.getGlobalStat();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("aria2globalStat update error:$e");
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(seconds: 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,197 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
|
||||||
|
|
||||||
import 'party_room_create_dialog_ui_model.dart';
|
|
||||||
|
|
||||||
class PartyRoomCreateDialogUI extends BaseUI<PartyRoomCreateDialogUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, PartyRoomCreateDialogUIModel model) {
|
|
||||||
return ContentDialog(
|
|
||||||
title: makeTitle(context, model),
|
|
||||||
constraints:
|
|
||||||
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .6),
|
|
||||||
content: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 12, right: 12, top: 12),
|
|
||||||
child: AnimatedSize(
|
|
||||||
duration: const Duration(milliseconds: 130),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
if (model.userName == null) ...[
|
|
||||||
SizedBox(
|
|
||||||
height: 200,
|
|
||||||
child: makeLoading(context),
|
|
||||||
)
|
|
||||||
] else ...[
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Text("请选择一种玩法"),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: ComboBox<RoomType>(
|
|
||||||
value: model.selectedRoomType,
|
|
||||||
items: [
|
|
||||||
for (final t in model.roomTypes.entries)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: t.value,
|
|
||||||
child: Text(t.value.name),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: model.onChangeRoomType)),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (model.selectedRoomType != null &&
|
|
||||||
(model.selectedRoomType?.subTypes.isNotEmpty ?? false))
|
|
||||||
...makeSubTypeSelectWidgets(context, model),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Text("游戏用户名(自动获取)"),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: TextFormBox(
|
|
||||||
initialValue: model.userName,
|
|
||||||
enabled: false,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Text("最大玩家数(2 ~ 32)"),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: TextFormBox(
|
|
||||||
controller: model.playerMaxCtrl,
|
|
||||||
onChanged: (_) => model.notifyListeners(),
|
|
||||||
inputFormatters: [
|
|
||||||
FilteringTextInputFormatter.digitsOnly
|
|
||||||
],
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
const Text("公告(可选)"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
TextFormBox(
|
|
||||||
controller: model.announcementCtrl,
|
|
||||||
maxLines: 5,
|
|
||||||
placeholder: "可编写 任务简报,集合地点,船只要求,活动规则等,公告将会自动发送给进入房间的玩家。",
|
|
||||||
placeholderStyle:
|
|
||||||
TextStyle(color: Colors.white.withOpacity(.4)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
for (var v in [
|
|
||||||
"创建房间后,其他玩家可以在大厅首页看到您的房间和您选择的玩法,当一个玩家选择加入房间时,你们将可以互相看到对方的用户名。当房间人数达到最大玩家数时,将不再接受新的玩家加入。",
|
|
||||||
"这是《SC汉化盒子》提供的公益服务,请勿滥用,我们保留拒绝服务的权力。"
|
|
||||||
]) ...[
|
|
||||||
Text(
|
|
||||||
v,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
],
|
|
||||||
]
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
if (model.isWorking)
|
|
||||||
const ProgressRing()
|
|
||||||
else
|
|
||||||
FilledButton(
|
|
||||||
onPressed: model.onSubmit(),
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(3),
|
|
||||||
child: Text("创建房间"),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color generateColorFromSeed(String seed) {
|
|
||||||
int hash = utf8
|
|
||||||
.encode(seed)
|
|
||||||
.fold(0, (previousValue, element) => 31 * previousValue + element);
|
|
||||||
Random random = Random(hash);
|
|
||||||
return Color.fromARGB(
|
|
||||||
255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> makeSubTypeSelectWidgets(
|
|
||||||
BuildContext context, PartyRoomCreateDialogUIModel model) {
|
|
||||||
bool isItemSelected(RoomSubtype subtype) {
|
|
||||||
return model.selectedSubType.contains(subtype);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
const Text("标签(可选)"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
for (var item in model.selectedRoomType!.subTypes)
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: isItemSelected(item)
|
|
||||||
? generateColorFromSeed(item.name).withOpacity(.4)
|
|
||||||
: FluentTheme.of(context).cardColor,
|
|
||||||
borderRadius: BorderRadius.circular(1000)),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 12),
|
|
||||||
margin: const EdgeInsets.only(right: 12),
|
|
||||||
child: IconButton(
|
|
||||||
icon: Row(
|
|
||||||
children: [
|
|
||||||
Icon(isItemSelected(item)
|
|
||||||
? FluentIcons.check_mark
|
|
||||||
: FluentIcons.add),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(
|
|
||||||
item.name,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: isItemSelected(item)
|
|
||||||
? null
|
|
||||||
: Colors.white.withOpacity(.4)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onPressed: () => model.onTapSubType(item)),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeTitle(BuildContext context, PartyRoomCreateDialogUIModel model) {
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(
|
|
||||||
FluentIcons.back,
|
|
||||||
size: 22,
|
|
||||||
),
|
|
||||||
onPressed: model.onBack()),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(getUITitle(context, model)),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, PartyRoomCreateDialogUIModel model) =>
|
|
||||||
"创建房间";
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/grpc/party_room_server.dart';
|
|
||||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
|
||||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
|
||||||
|
|
||||||
class PartyRoomCreateDialogUIModel extends BaseUIModel {
|
|
||||||
Map<String?, RoomType> roomTypes;
|
|
||||||
|
|
||||||
RoomType? selectedRoomType;
|
|
||||||
|
|
||||||
List<RoomSubtype> selectedSubType = [];
|
|
||||||
|
|
||||||
PartyRoomCreateDialogUIModel(this.roomTypes);
|
|
||||||
|
|
||||||
String? userName;
|
|
||||||
|
|
||||||
bool isWorking = false;
|
|
||||||
|
|
||||||
final playerMaxCtrl = TextEditingController(text: "8");
|
|
||||||
final announcementCtrl = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
initModel() {
|
|
||||||
super.initModel();
|
|
||||||
roomTypes.removeWhere((key, value) => key == "");
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
loadData() async {
|
|
||||||
userName = await globalUIModel.getRunningGameUser();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
onBack() {
|
|
||||||
if (isWorking) return null;
|
|
||||||
return () {
|
|
||||||
Navigator.pop(context!);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChangeRoomType(RoomType? value) {
|
|
||||||
selectedSubType = [];
|
|
||||||
selectedRoomType = value;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
onTapSubType(RoomSubtype item) {
|
|
||||||
if (!selectedSubType.contains(item)) {
|
|
||||||
selectedSubType.add(item);
|
|
||||||
} else {
|
|
||||||
selectedSubType.remove(item);
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
onSubmit() {
|
|
||||||
final maxPlayer = int.tryParse(playerMaxCtrl.text) ?? 0;
|
|
||||||
if (selectedRoomType == null) return null;
|
|
||||||
if (maxPlayer < 2 || maxPlayer > 32) return null;
|
|
||||||
return () async {
|
|
||||||
isWorking = true;
|
|
||||||
notifyListeners();
|
|
||||||
final room = await handleError(() => PartyRoomGrpcServer.createRoom(
|
|
||||||
RoomData(
|
|
||||||
roomTypeID: selectedRoomType?.id,
|
|
||||||
roomSubTypeIds: [for (var value in selectedSubType) value.id],
|
|
||||||
owner: userName,
|
|
||||||
deviceUUID: AppConf.deviceUUID,
|
|
||||||
maxPlayer: maxPlayer,
|
|
||||||
announcement: announcementCtrl.text.trim())));
|
|
||||||
isWorking = false;
|
|
||||||
notifyListeners();
|
|
||||||
if (room != null) {
|
|
||||||
Navigator.pop(context!, room);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
|
||||||
import 'package:starcitizen_doctor/widgets/cache_image.dart';
|
|
||||||
|
|
||||||
import 'party_room_chat_ui_model.dart';
|
|
||||||
|
|
||||||
class PartyRoomChatUI extends BaseUI<PartyRoomChatUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, PartyRoomChatUIModel model) {
|
|
||||||
final roomData = model.serverResultRoomData;
|
|
||||||
if (roomData == null) return makeLoading(context);
|
|
||||||
final typesMap = model.partyRoomHomeUIModel.roomTypes;
|
|
||||||
final title =
|
|
||||||
"${roomData.owner} 的 ${typesMap?[roomData.roomTypeID]?.name ?? roomData.roomTypeID}房间";
|
|
||||||
// final createTime =
|
|
||||||
// DateTime.fromMillisecondsSinceEpoch(roomData.createTime.toInt());
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(color: Colors.black.withOpacity(.25)),
|
|
||||||
child: makeTitleBar(model, title, roomData),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
width: 220,
|
|
||||||
padding: const EdgeInsets.only(left: 12, right: 12),
|
|
||||||
decoration: BoxDecoration(color: Colors.black.withOpacity(.07)),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeItemRow("玩家数量:",
|
|
||||||
"${model.playersMap?.length ?? 0} / ${roomData.maxPlayer}"),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
if (model.playersMap == null)
|
|
||||||
Expanded(child: makeLoading(context))
|
|
||||||
else
|
|
||||||
Expanded(
|
|
||||||
child: ListView.builder(
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
final item = model.playersMap!.entries
|
|
||||||
.elementAt(index)
|
|
||||||
.value;
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(1000),
|
|
||||||
child: CacheNetImage(
|
|
||||||
url: item.avatar,
|
|
||||||
width: 28,
|
|
||||||
height: 28,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Expanded(child: Text(item.playerName)),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 3, bottom: 3, left: 12, right: 12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.green,
|
|
||||||
borderRadius:
|
|
||||||
BorderRadius.circular(1000)),
|
|
||||||
child: Text(
|
|
||||||
"${model.playerStatusMap[item.status] ?? item.status}",
|
|
||||||
style: const TextStyle(fontSize: 13),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
itemCount: model.playersMap!.length,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeItemRow(String title, String value) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 1, bottom: 1),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
value,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeTitleBar(
|
|
||||||
PartyRoomChatUIModel model, String title, RoomData roomData) {
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(1000),
|
|
||||||
child: CacheNetImage(
|
|
||||||
url: roomData.avatar,
|
|
||||||
width: 32,
|
|
||||||
height: 32,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: const TextStyle(fontSize: 18),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Container(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.only(top: 3, bottom: 3, left: 12, right: 12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.green, borderRadius: BorderRadius.circular(1000)),
|
|
||||||
child: Text(
|
|
||||||
"${model.partyRoomHomeUIModel.roomStatus[roomData.status]}")),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Spacer(),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(
|
|
||||||
FluentIcons.leave,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
onPressed: () => model.onClose())
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, PartyRoomChatUIModel model) => "Chat";
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
import 'package:grpc/grpc.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/grpc/party_room_server.dart';
|
|
||||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
|
||||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
|
||||||
|
|
||||||
import 'party_room_home_ui_model.dart';
|
|
||||||
|
|
||||||
class PartyRoomChatUIModel extends BaseUIModel {
|
|
||||||
PartyRoomHomeUIModel partyRoomHomeUIModel;
|
|
||||||
|
|
||||||
PartyRoomChatUIModel(this.partyRoomHomeUIModel);
|
|
||||||
|
|
||||||
RoomData? selectRoom;
|
|
||||||
|
|
||||||
RoomData? serverResultRoomData;
|
|
||||||
|
|
||||||
ResponseStream<RoomUpdateMessage>? roomStream;
|
|
||||||
|
|
||||||
Map<String, RoomUserData>? playersMap;
|
|
||||||
|
|
||||||
setRoom(RoomData? selectRoom) {
|
|
||||||
if (this.selectRoom == null) {
|
|
||||||
this.selectRoom = selectRoom;
|
|
||||||
notifyListeners();
|
|
||||||
loadRoom();
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
final playerStatusMap = {
|
|
||||||
RoomUserStatus.RoomUserStatusJoin: "在线",
|
|
||||||
RoomUserStatus.RoomUserStatusLostOffline: "离线",
|
|
||||||
RoomUserStatus.RoomUserStatusLeave: "已离开",
|
|
||||||
RoomUserStatus.RoomUserStatusWaitingConnect: "正在连接...",
|
|
||||||
};
|
|
||||||
|
|
||||||
onClose() async {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!, "确认离开房间?", const Text("离开房间后,您的位置将被释放。"));
|
|
||||||
if (ok == true) {
|
|
||||||
partyRoomHomeUIModel.pageCtrl.animateToPage(0,
|
|
||||||
duration: const Duration(milliseconds: 130),
|
|
||||||
curve: Curves.easeInOutSine);
|
|
||||||
disposeRoom();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadRoom() async {
|
|
||||||
if (selectRoom == null) return;
|
|
||||||
final userName = await globalUIModel.getRunningGameUser();
|
|
||||||
if (userName == null) return;
|
|
||||||
roomStream = PartyRoomGrpcServer.joinRoom(
|
|
||||||
selectRoom!.id, userName, AppConf.deviceUUID);
|
|
||||||
roomStream!.listen((value) {
|
|
||||||
dPrint("PartyRoomChatUIModel.roomStream.listen === $value");
|
|
||||||
if (value.roomUpdateType == RoomUpdateType.RoomClose) {
|
|
||||||
} else if (value.roomUpdateType == RoomUpdateType.RoomUpdateData) {
|
|
||||||
if (value.hasRoomData()) {
|
|
||||||
serverResultRoomData = value.roomData;
|
|
||||||
}
|
|
||||||
if (value.usersData.isNotEmpty) {
|
|
||||||
_updatePlayerList(value.usersData);
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
..onError((err) {
|
|
||||||
// showToast(context!, "连接到服务器出现错误:$err");
|
|
||||||
dPrint("PartyRoomChatUIModel.roomStream onError $err");
|
|
||||||
})
|
|
||||||
..onDone(() {
|
|
||||||
// showToast(context!, "房间已关闭");
|
|
||||||
dPrint("PartyRoomChatUIModel.roomStream onDone");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
disposeRoom() {
|
|
||||||
selectRoom = null;
|
|
||||||
roomStream?.cancel();
|
|
||||||
roomStream = null;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _updatePlayerList(List<RoomUserData> usersData) {
|
|
||||||
playersMap ??= {};
|
|
||||||
for (var element in usersData) {
|
|
||||||
playersMap![element.playerName] = element;
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,357 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:math';
|
|
||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
import 'package:extended_image/extended_image.dart';
|
|
||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
||||||
import 'package:flutter_tilt/flutter_tilt.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
|
||||||
import 'package:starcitizen_doctor/widgets/cache_image.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
|
|
||||||
import 'party_room_home_ui_model.dart';
|
|
||||||
|
|
||||||
class PartyRoomHomeUI extends BaseUI<PartyRoomHomeUIModel> {
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
Future.delayed(const Duration(milliseconds: 16)).then((_) {
|
|
||||||
ref.watch(provider).checkUIInit();
|
|
||||||
});
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
// final model = ref.watch(provider);
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
"联机大厅,敬请期待 !",
|
|
||||||
style: TextStyle(fontSize: 20),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
launchUrlString("https://wj.qq.com/s2/14112124/f4c8/");
|
|
||||||
},
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Text("诚邀您参与 "),
|
|
||||||
Text(
|
|
||||||
"问卷调查。",
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.blue,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// return PageView(
|
|
||||||
// controller: model.pageCtrl,
|
|
||||||
// physics: const NeverScrollableScrollPhysics(),
|
|
||||||
// children: [
|
|
||||||
// super.build(context),
|
|
||||||
// BaseUIContainer(
|
|
||||||
// uiCreate: () => PartyRoomChatUI(),
|
|
||||||
// modelCreate: () =>
|
|
||||||
// model.getChildUIModelProviders<PartyRoomChatUIModel>("chat"))
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, PartyRoomHomeUIModel model) {
|
|
||||||
if (model.pingServerMessage == null) return makeLoading(context);
|
|
||||||
if (model.pingServerMessage!.isNotEmpty) {
|
|
||||||
return Center(
|
|
||||||
child: Text("${model.pingServerMessage}"),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (model.roomTypes == null) return makeLoading(context);
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
makeHeader(context, model),
|
|
||||||
if (model.rooms == null)
|
|
||||||
Expanded(child: makeLoading(context))
|
|
||||||
else if (model.rooms!.isEmpty)
|
|
||||||
const Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Text("没有符合条件的房间!"),
|
|
||||||
))
|
|
||||||
else
|
|
||||||
Expanded(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 24, right: 24),
|
|
||||||
child: AlignedGridView.count(
|
|
||||||
crossAxisCount: 3,
|
|
||||||
mainAxisSpacing: 24,
|
|
||||||
crossAxisSpacing: 24,
|
|
||||||
itemCount: model.rooms!.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return makeRoomItemWidget(context, model, index);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeRoomItemWidget(
|
|
||||||
BuildContext context,
|
|
||||||
PartyRoomHomeUIModel model,
|
|
||||||
int index,
|
|
||||||
) {
|
|
||||||
final item = model.rooms![index];
|
|
||||||
final itemType = model.roomTypes?[item.roomTypeID];
|
|
||||||
final itemSubTypes = {
|
|
||||||
for (var t in itemType?.subTypes ?? <RoomSubtype>[]) t.id: t
|
|
||||||
};
|
|
||||||
final createTime =
|
|
||||||
DateTime.fromMillisecondsSinceEpoch(item.createTime.toInt());
|
|
||||||
return Tilt(
|
|
||||||
borderRadius: BorderRadius.circular(13),
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(13),
|
|
||||||
image: DecorationImage(
|
|
||||||
image: ExtendedNetworkImageProvider(item.avatar, cache: true),
|
|
||||||
fit: BoxFit.cover)),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black.withOpacity(.4),
|
|
||||||
borderRadius: BorderRadius.circular(13),
|
|
||||||
),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(13),
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: BackdropFilter(
|
|
||||||
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 16, right: 16, top: 12, bottom: 12),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => model.onTapRoom(item),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"${itemType?.name ?? item.roomTypeID}房间",
|
|
||||||
style: const TextStyle(fontSize: 20),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
top: 3, bottom: 3, left: 12, right: 12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.green,
|
|
||||||
borderRadius: BorderRadius.circular(1000)),
|
|
||||||
child: Text("${model.roomStatus[item.status]}")),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
makeItemRow("房主:", item.owner),
|
|
||||||
makeItemRow("玩家数量:",
|
|
||||||
"${item.curPlayer} / ${item.maxPlayer}"),
|
|
||||||
makeItemRow("创建时间:", "${createTime.toLocal()}"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(1000),
|
|
||||||
child: CacheNetImage(
|
|
||||||
url: item.avatar,
|
|
||||||
width: 64,
|
|
||||||
height: 64,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
SingleChildScrollView(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
for (var value in item.roomSubTypeIds)
|
|
||||||
makeSubTypeTag(value, model, itemSubTypes),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeSubTypeTag(String id, PartyRoomHomeUIModel model,
|
|
||||||
Map<String, RoomSubtype> itemSubTypes) {
|
|
||||||
final name = itemSubTypes[id]?.name ?? id;
|
|
||||||
final color = generateColorFromSeed(name).withOpacity(.6);
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.only(left: 12, right: 12, top: 5, bottom: 5),
|
|
||||||
margin: const EdgeInsets.only(right: 6),
|
|
||||||
decoration:
|
|
||||||
BoxDecoration(color: color, borderRadius: BorderRadius.circular(12)),
|
|
||||||
child: Text(
|
|
||||||
name,
|
|
||||||
style: const TextStyle(fontSize: 13),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color generateColorFromSeed(String seed) {
|
|
||||||
int hash = utf8
|
|
||||||
.encode(seed)
|
|
||||||
.fold(0, (previousValue, element) => 31 * previousValue + element);
|
|
||||||
Random random = Random(hash);
|
|
||||||
return Color.fromARGB(
|
|
||||||
255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeItemRow(String title, String value) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 1, bottom: 1),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
value,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeHeader(BuildContext context, PartyRoomHomeUIModel model) {
|
|
||||||
final subTypes = model.getCurRoomSubTypes();
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.only(left: 24, right: 24, top: 16, bottom: 16),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Text("房间类型:"),
|
|
||||||
SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: ComboBox<RoomType>(
|
|
||||||
value: model.selectedRoomType,
|
|
||||||
items: [
|
|
||||||
for (final t in model.roomTypes!.entries)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: t.value,
|
|
||||||
child: Text(t.value.name),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: model.onChangeRoomType)),
|
|
||||||
if (subTypes != null) ...[
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
const Text("子类型:"),
|
|
||||||
SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: ComboBox<RoomSubtype>(
|
|
||||||
value: model.selectedRoomSubType,
|
|
||||||
items: [
|
|
||||||
for (final t in subTypes.entries)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: t.value,
|
|
||||||
child: Text(t.value.name),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: model.onChangeRoomSubType)),
|
|
||||||
],
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
const Text("房间状态:"),
|
|
||||||
SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: ComboBox<RoomStatus>(
|
|
||||||
value: model.selectedStatus,
|
|
||||||
items: [
|
|
||||||
for (final t in model.roomStatus.entries)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: t.key,
|
|
||||||
child: Text(t.value),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: model.onChangeRoomStatus)),
|
|
||||||
const SizedBox(width: 24),
|
|
||||||
const Text("排序:"),
|
|
||||||
SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: ComboBox<RoomSortType>(
|
|
||||||
value: model.selectedSortType,
|
|
||||||
items: [
|
|
||||||
for (final t in model.roomSorts.entries)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: t.key,
|
|
||||||
child: Text(t.value),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: model.onChangeRoomSort)),
|
|
||||||
const Spacer(),
|
|
||||||
Button(
|
|
||||||
onPressed: model.onRefreshRoom,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.refresh),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
onPressed: () => model.onCreateRoom(),
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(3),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(FluentIcons.add),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Text("创建房间")
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 6,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
model.selectedRoomType?.desc ?? "",
|
|
||||||
style: TextStyle(fontSize: 13, color: Colors.white.withOpacity(.4)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, PartyRoomHomeUIModel model) =>
|
|
||||||
"PartyRoom";
|
|
||||||
}
|
|
@ -1,204 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/generated/grpc/party_room_server/index.pb.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/party_room/dialogs/party_room_create_dialog_ui_model.dart';
|
|
||||||
|
|
||||||
import 'dialogs/party_room_create_dialog_ui.dart';
|
|
||||||
import 'party_room_chat_ui_model.dart';
|
|
||||||
|
|
||||||
class PartyRoomHomeUIModel extends BaseUIModel {
|
|
||||||
String? pingServerMessage;
|
|
||||||
|
|
||||||
Map<String?, RoomType>? roomTypes;
|
|
||||||
|
|
||||||
RoomType? selectedRoomType;
|
|
||||||
|
|
||||||
RoomSubtype? selectedRoomSubType;
|
|
||||||
|
|
||||||
final roomStatus = <RoomStatus, String>{
|
|
||||||
RoomStatus.All: "全部",
|
|
||||||
RoomStatus.Open: "开启中",
|
|
||||||
RoomStatus.Full: "已满员",
|
|
||||||
RoomStatus.Closed: "已封闭",
|
|
||||||
RoomStatus.WillOffline: "房主离线",
|
|
||||||
RoomStatus.Offline: "已离线",
|
|
||||||
};
|
|
||||||
|
|
||||||
RoomStatus selectedStatus = RoomStatus.All;
|
|
||||||
|
|
||||||
final roomSorts = <RoomSortType, String>{
|
|
||||||
RoomSortType.Default: "默认",
|
|
||||||
RoomSortType.MostPlayerNumber: "最多玩家",
|
|
||||||
RoomSortType.MinimumPlayerNumber: "最少玩家",
|
|
||||||
RoomSortType.RecentlyCreated: "最近创建",
|
|
||||||
RoomSortType.OldestCreated: "最久创建",
|
|
||||||
};
|
|
||||||
|
|
||||||
RoomSortType selectedSortType = RoomSortType.Default;
|
|
||||||
|
|
||||||
int pageNum = 0;
|
|
||||||
|
|
||||||
List<RoomData>? rooms;
|
|
||||||
|
|
||||||
final pageCtrl = PageController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
BaseUIModel? onCreateChildUIModel(modelKey) {
|
|
||||||
switch (modelKey) {
|
|
||||||
case "chat":
|
|
||||||
return PartyRoomChatUIModel(this);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future loadData() async {
|
|
||||||
// if (pingServerMessage != "") {
|
|
||||||
// pingServerMessage = null;
|
|
||||||
// notifyListeners();
|
|
||||||
// await _pingServer();
|
|
||||||
// }
|
|
||||||
// await _loadPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// reloadData() async {
|
|
||||||
// pageNum = 0;
|
|
||||||
// rooms = null;
|
|
||||||
// notifyListeners();
|
|
||||||
// _touchUser();
|
|
||||||
// return super.reloadData();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _loadPage() async {
|
|
||||||
// final r = await handleError(() => PartyRoomGrpcServer.getRoomList(
|
|
||||||
// RoomListPageReqData(
|
|
||||||
// pageNum: Int64.tryParseInt("$pageNum"),
|
|
||||||
// typeID: selectedRoomType?.id ?? "",
|
|
||||||
// subTypeID: selectedRoomSubType?.id ?? "",
|
|
||||||
// status: selectedStatus)));
|
|
||||||
// if (r == null) return;
|
|
||||||
// if (r.pageData.hasNext) {
|
|
||||||
// pageNum++;
|
|
||||||
// } else {
|
|
||||||
// pageNum = -1;
|
|
||||||
// }
|
|
||||||
// rooms = r.rooms;
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _pingServer() async {
|
|
||||||
// try {
|
|
||||||
// final r = await PartyRoomGrpcServer.pingServer();
|
|
||||||
// dPrint(
|
|
||||||
// "[PartyRoomHomeUIModel] Connected! serverVersion ==> ${r.serverVersion}");
|
|
||||||
// pingServerMessage = "";
|
|
||||||
// notifyListeners();
|
|
||||||
// } catch (e) {
|
|
||||||
// pingServerMessage = "服务器连接失败,请稍后重试。\n$e";
|
|
||||||
// notifyListeners();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Future<void> _loadTypes() async {
|
|
||||||
// final r = await handleError(() => PartyRoomGrpcServer.getRoomTypes());
|
|
||||||
// if (r == null) return;
|
|
||||||
// selectedRoomType =
|
|
||||||
// RoomType(id: "", name: "全部", desc: "查看所有类型的房间,寻找一起玩的伙伴。");
|
|
||||||
// selectedRoomSubType = RoomSubtype(id: "", name: "全部");
|
|
||||||
// roomTypes = {"": selectedRoomType!};
|
|
||||||
// for (var element in r.roomTypes) {
|
|
||||||
// roomTypes![element.id] = element;
|
|
||||||
// }
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
|
|
||||||
Map<String, RoomSubtype>? getCurRoomSubTypes() {
|
|
||||||
if (selectedRoomType?.subTypes == null) return null;
|
|
||||||
Map<String, RoomSubtype> types = {};
|
|
||||||
for (var element in selectedRoomType!.subTypes) {
|
|
||||||
types[element.id] = element;
|
|
||||||
}
|
|
||||||
if (types.isEmpty) return null;
|
|
||||||
final allSubType = RoomSubtype(id: "", name: "全部");
|
|
||||||
selectedRoomSubType ??= allSubType;
|
|
||||||
return {"all": allSubType}..addAll(types);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChangeRoomType(RoomType? value) {
|
|
||||||
selectedRoomType = value;
|
|
||||||
selectedRoomSubType = null;
|
|
||||||
reloadData();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChangeRoomStatus(RoomStatus? value) {
|
|
||||||
if (value == null) return;
|
|
||||||
selectedStatus = value;
|
|
||||||
reloadData();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChangeRoomSort(RoomSortType? value) {
|
|
||||||
if (value == null) return;
|
|
||||||
selectedSortType = value;
|
|
||||||
reloadData();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChangeRoomSubType(RoomSubtype? value) {
|
|
||||||
if (value == null) return;
|
|
||||||
selectedRoomSubType = value;
|
|
||||||
reloadData();
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
onCreateRoom() async {
|
|
||||||
final room = await showDialog(
|
|
||||||
context: context!,
|
|
||||||
dismissWithEsc: false,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return BaseUIContainer(
|
|
||||||
uiCreate: () => PartyRoomCreateDialogUI(),
|
|
||||||
modelCreate: () =>
|
|
||||||
PartyRoomCreateDialogUIModel(Map.from(roomTypes!)));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (room == null) return;
|
|
||||||
dPrint(room);
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
onRefreshRoom() {
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Future<void> _touchUser() async {
|
|
||||||
// if (getCreatedChildUIModel<PartyRoomChatUIModel>("chat")?.selectRoom ==
|
|
||||||
// null) {
|
|
||||||
// final userName = await globalUIModel.getRunningGameUser();
|
|
||||||
// if (userName == null) return;
|
|
||||||
// // 检测用户已加入的房间
|
|
||||||
// final room = await handleError(() =>
|
|
||||||
// PartyRoomGrpcServer.touchUserRoom(userName, AppConf.deviceUUID));
|
|
||||||
// dPrint("touch room == ${room?.toProto3Json()}");
|
|
||||||
// if (room == null || room.id == "") return;
|
|
||||||
// onTapRoom(room);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
onTapRoom(RoomData item) {
|
|
||||||
getCreatedChildUIModel<PartyRoomChatUIModel>("chat", create: true)
|
|
||||||
?.setRoom(item);
|
|
||||||
notifyListeners();
|
|
||||||
pageCtrl.animateToPage(1,
|
|
||||||
duration: const Duration(milliseconds: 100), curve: Curves.easeInExpo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkUIInit() {
|
|
||||||
if (getCreatedChildUIModel<PartyRoomChatUIModel>("chat")?.selectRoom !=
|
|
||||||
null) {
|
|
||||||
pageCtrl.jumpToPage(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
|
|
||||||
|
|
||||||
class SettingUI extends BaseUI<SettingUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, SettingUIModel model) {
|
|
||||||
return Container(
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
height: MediaQuery.of(context).size.height,
|
|
||||||
margin: const EdgeInsets.all(16),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
makeSettingsItem(const Icon(FluentIcons.link, size: 20), "创建设置快捷方式",
|
|
||||||
subTitle: "在桌面创建《SC汉化盒子》快捷方式", onTap: model.addShortCut),
|
|
||||||
if (AppConf.isMSE) ...[
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeSettingsItem(
|
|
||||||
const Icon(FluentIcons.reset_device, size: 20), "重置自动密码填充",
|
|
||||||
subTitle:
|
|
||||||
"启用:${model.isEnableAutoLogin ? "已启用" : "已禁用"} 设备支持:${model.isDeviceSupportWinHello ? "支持" : "不支持"} 邮箱:${model.autoLoginEmail} 密码:${model.isEnableAutoLoginPwd ? "已加密保存" : "未保存"}",
|
|
||||||
onTap: model.onResetAutoLogin),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeSettingsItem(const Icon(FontAwesomeIcons.microchip, size: 20),
|
|
||||||
"启动游戏时忽略能效核心( 适用于Intel 12th+ 处理器 ) [实验性功能,请随时反馈]",
|
|
||||||
subTitle:
|
|
||||||
"已设置的核心数量:${model.inputGameLaunchECore} (此功能适用于首页的盒子一键启动 或 工具中的RSI启动器管理员模式,当为 0 时不启用此功能 )",
|
|
||||||
onTap: model.setGameLaunchECore),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeSettingsItem(const Icon(FluentIcons.folder_open, size: 20),
|
|
||||||
"设置启动器文件(RSI Launcher.exe)",
|
|
||||||
subTitle: model.customLauncherPath != null
|
|
||||||
? "${model.customLauncherPath}"
|
|
||||||
: "手动设置启动器位置,建议仅在无法自动扫描安装位置时使用",
|
|
||||||
onTap: model.setLauncherPath, onDel: () {
|
|
||||||
model.delName("custom_launcher_path");
|
|
||||||
}),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeSettingsItem(const Icon(FluentIcons.game, size: 20),
|
|
||||||
"设置游戏文件 (StarCitizen.exe)",
|
|
||||||
subTitle: model.customGamePath != null
|
|
||||||
? "${model.customGamePath}"
|
|
||||||
: "手动设置游戏安装位置,建议仅在无法自动扫描安装位置时使用",
|
|
||||||
onTap: model.setGamePath, onDel: () {
|
|
||||||
model.delName("custom_game_path");
|
|
||||||
}),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeSettingsItem(const Icon(FluentIcons.delete, size: 20), "清理汉化文件缓存",
|
|
||||||
subTitle:
|
|
||||||
"缓存大小 ${(model.locationCacheSize / 1024 / 1024).toStringAsFixed(2)}MB,清理盒子下载的汉化文件缓存,不会影响已安装的汉化",
|
|
||||||
onTap: model.cleanLocationCache),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeSettingsItem(
|
|
||||||
const Icon(FluentIcons.speed_high, size: 20), "工具站访问加速",
|
|
||||||
onTap: () =>
|
|
||||||
model.onChangeToolSiteMirror(!model.isEnableToolSiteMirrors),
|
|
||||||
subTitle:
|
|
||||||
"使用镜像服务器加速访问 Dps Uex 等工具网站,若访问异常请关闭该功能。 为保护账户安全,任何情况下都不会加速RSI官网。",
|
|
||||||
onSwitch: model.onChangeToolSiteMirror,
|
|
||||||
switchStatus: model.isEnableToolSiteMirrors),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeSettingsItem(
|
|
||||||
const Icon(FluentIcons.document_set, size: 20), "查看log",
|
|
||||||
onTap: () => model.showLogs(),
|
|
||||||
subTitle: "查看汉化盒子的 log 文件,以定位盒子的 bug"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeSettingsItem(Widget icon, String title,
|
|
||||||
{String? subTitle,
|
|
||||||
VoidCallback? onTap,
|
|
||||||
VoidCallback? onDel,
|
|
||||||
void Function(bool? b)? onSwitch,
|
|
||||||
bool switchStatus = false}) {
|
|
||||||
return Button(
|
|
||||||
onPressed: onTap,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 12, bottom: 12),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
icon,
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(title),
|
|
||||||
const Spacer(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (subTitle != null) ...[
|
|
||||||
const SizedBox(height: 3),
|
|
||||||
Text(
|
|
||||||
subTitle,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12, color: Colors.white.withOpacity(.6)),
|
|
||||||
)
|
|
||||||
]
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (onDel != null) ...[
|
|
||||||
Button(
|
|
||||||
onPressed: onDel,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.delete),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
if (onSwitch != null) ...[
|
|
||||||
ToggleSwitch(checked: switchStatus, onChanged: onSwitch),
|
|
||||||
],
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Icon(FluentIcons.chevron_right),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, SettingUIModel model) => "SettingUI";
|
|
||||||
}
|
|
@ -1,197 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:local_auth/local_auth.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/win32/credentials.dart';
|
|
||||||
|
|
||||||
class SettingUIModel extends BaseUIModel {
|
|
||||||
var isDeviceSupportWinHello = false;
|
|
||||||
|
|
||||||
String autoLoginEmail = "-";
|
|
||||||
bool isEnableAutoLogin = false;
|
|
||||||
bool isEnableAutoLoginPwd = false;
|
|
||||||
bool isEnableToolSiteMirrors = false;
|
|
||||||
String inputGameLaunchECore = "0";
|
|
||||||
|
|
||||||
String? customLauncherPath;
|
|
||||||
String? customGamePath;
|
|
||||||
|
|
||||||
int locationCacheSize = 0;
|
|
||||||
|
|
||||||
@override
|
|
||||||
loadData() async {
|
|
||||||
dPrint("SettingUIModel.loadData");
|
|
||||||
final LocalAuthentication localAuth = LocalAuthentication();
|
|
||||||
isDeviceSupportWinHello = await localAuth.isDeviceSupported();
|
|
||||||
notifyListeners();
|
|
||||||
_updateGameLaunchECore();
|
|
||||||
if (AppConf.isMSE) {
|
|
||||||
_updateAutoLoginAccount();
|
|
||||||
}
|
|
||||||
_loadCustomPath();
|
|
||||||
_loadLocationCacheSize();
|
|
||||||
_loadToolSiteMirrorState();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onResetAutoLogin() async {
|
|
||||||
final ok = await showConfirmDialogs(context!, "确认重置自动填充?",
|
|
||||||
const Text("这将会删除本地的账号记录,或在下次启动游戏时将自动填充选择 ‘否’ 以禁用自动填充。"));
|
|
||||||
if (ok) {
|
|
||||||
final userBox = await Hive.openBox("rsi_account_data");
|
|
||||||
await userBox.deleteFromDisk();
|
|
||||||
Win32Credentials.delete("SCToolbox_RSI_Account_secret");
|
|
||||||
showToast(context!, "已清理自动填充数据");
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _updateAutoLoginAccount() async {
|
|
||||||
final userBox = await Hive.openBox("rsi_account_data");
|
|
||||||
autoLoginEmail = userBox.get("account_email", defaultValue: "-");
|
|
||||||
isEnableAutoLogin = userBox.get("enable", defaultValue: true);
|
|
||||||
isEnableAutoLoginPwd =
|
|
||||||
userBox.get("account_pwd_encrypted", defaultValue: "") != "";
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setGameLaunchECore() async {
|
|
||||||
final userBox = await Hive.openBox("app_conf");
|
|
||||||
final defaultInput =
|
|
||||||
userBox.get("gameLaunch_eCore_count", defaultValue: "0");
|
|
||||||
final input = await showInputDialogs(context!,
|
|
||||||
title: "请输入要忽略的 CPU 核心数",
|
|
||||||
content:
|
|
||||||
"Tip:您的设备拥有几个能效核心就输入几,非大小核设备请保持 0\n\n此功能适用于首页的盒子一键启动 或 工具中的 RSI启动器管理员模式,当为 0 时不启用此功能。",
|
|
||||||
initialValue: defaultInput,
|
|
||||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly]);
|
|
||||||
if (input == null) return;
|
|
||||||
userBox.put("gameLaunch_eCore_count", input);
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _updateGameLaunchECore() async {
|
|
||||||
final userBox = await Hive.openBox("app_conf");
|
|
||||||
inputGameLaunchECore =
|
|
||||||
userBox.get("gameLaunch_eCore_count", defaultValue: "0");
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setLauncherPath() async {
|
|
||||||
final r = await FilePicker.platform.pickFiles(
|
|
||||||
dialogTitle: "请选择RSI启动器位置(RSI Launcher.exe)",
|
|
||||||
type: FileType.custom,
|
|
||||||
allowedExtensions: ["exe"]);
|
|
||||||
if (r == null || r.files.firstOrNull?.path == null) return;
|
|
||||||
final fileName = r.files.first.path!;
|
|
||||||
if (fileName.endsWith("\\RSI Launcher.exe")) {
|
|
||||||
await _saveCustomPath("custom_launcher_path", fileName);
|
|
||||||
showToast(context!, "设置成功,在对应页面点击刷新即可扫描出新路径");
|
|
||||||
reloadData();
|
|
||||||
} else {
|
|
||||||
showToast(context!, "文件有误!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setGamePath() async {
|
|
||||||
final r = await FilePicker.platform.pickFiles(
|
|
||||||
dialogTitle: "请选择游戏安装位置(StarCitizen.exe)",
|
|
||||||
type: FileType.custom,
|
|
||||||
allowedExtensions: ["exe"]);
|
|
||||||
if (r == null || r.files.firstOrNull?.path == null) return;
|
|
||||||
final fileName = r.files.first.path!;
|
|
||||||
dPrint(fileName);
|
|
||||||
final fileNameRegExp =
|
|
||||||
RegExp(r"^(.*\\StarCitizen\\.*\\)Bin64\\StarCitizen\.exe$");
|
|
||||||
if (fileNameRegExp.hasMatch(fileName)) {
|
|
||||||
RegExp pathRegex = RegExp(r"\\[^\\]+\\Bin64\\StarCitizen\.exe$");
|
|
||||||
String extractedPath = fileName.replaceFirst(pathRegex, '');
|
|
||||||
await _saveCustomPath("custom_game_path", extractedPath);
|
|
||||||
showToast(context!, "设置成功,在对应页面点击刷新即可扫描出新路径");
|
|
||||||
reloadData();
|
|
||||||
} else {
|
|
||||||
showToast(context!, "文件有误!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_saveCustomPath(String pathKey, String dir) async {
|
|
||||||
final confBox = await Hive.openBox("app_conf");
|
|
||||||
await confBox.put(pathKey, dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
_loadCustomPath() async {
|
|
||||||
final confBox = await Hive.openBox("app_conf");
|
|
||||||
customLauncherPath = confBox.get("custom_launcher_path");
|
|
||||||
customGamePath = confBox.get("custom_game_path");
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> delName(String key) async {
|
|
||||||
final confBox = await Hive.openBox("app_conf");
|
|
||||||
await confBox.delete(key);
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
|
|
||||||
_loadLocationCacheSize() async {
|
|
||||||
final len = await SystemHelper.getDirLen(
|
|
||||||
"${AppConf.applicationSupportDir}/Localizations");
|
|
||||||
locationCacheSize = len;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> cleanLocationCache() async {
|
|
||||||
final ok = await showConfirmDialogs(
|
|
||||||
context!, "确认清理汉化缓存?", const Text("这不会影响已安装的汉化。"));
|
|
||||||
if (ok == true) {
|
|
||||||
final dir = Directory("${AppConf.applicationSupportDir}/Localizations");
|
|
||||||
await handleError(() => dir.delete(recursive: true));
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> addShortCut() async {
|
|
||||||
if (AppConf.isMSE) {
|
|
||||||
showToast(context!, "因微软版功能限制,请在接下来打开的窗口中 手动将《SC汉化盒子》拖动到桌面,即可创建快捷方式。");
|
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
|
||||||
Process.run("explorer.exe", ["shell:AppsFolder"]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dPrint(Platform.resolvedExecutable);
|
|
||||||
final script = """
|
|
||||||
\$targetPath = "${Platform.resolvedExecutable}";
|
|
||||||
\$shortcutPath = [System.IO.Path]::Combine([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::DesktopDirectory), "SC汉化盒子DEV.lnk");
|
|
||||||
\$shell = New-Object -ComObject WScript.Shell
|
|
||||||
\$shortcut = \$shell.CreateShortcut(\$shortcutPath)
|
|
||||||
if (\$shortcut -eq \$null) {
|
|
||||||
Write-Host "Failed to create shortcut."
|
|
||||||
} else {
|
|
||||||
\$shortcut.TargetPath = \$targetPath
|
|
||||||
\$shortcut.Save()
|
|
||||||
Write-Host "Shortcut created successfully."
|
|
||||||
}
|
|
||||||
""";
|
|
||||||
await Process.run(SystemHelper.powershellPath, [script]);
|
|
||||||
showToast(context!, "创建完毕,请返回桌面查看");
|
|
||||||
}
|
|
||||||
|
|
||||||
_loadToolSiteMirrorState() async {
|
|
||||||
final userBox = await Hive.openBox("app_conf");
|
|
||||||
isEnableToolSiteMirrors =
|
|
||||||
userBox.get("isEnableToolSiteMirrors", defaultValue: false);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChangeToolSiteMirror(bool? b) async {
|
|
||||||
final userBox = await Hive.openBox("app_conf");
|
|
||||||
isEnableToolSiteMirrors = b == true;
|
|
||||||
await userBox.put("isEnableToolSiteMirrors", isEnableToolSiteMirrors);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
showLogs() async {
|
|
||||||
SystemHelper.openDir(AppConf.appLogFile?.absolute.path);
|
|
||||||
}
|
|
||||||
}
|
|
263
lib/ui/settings/upgrade_dialog.dart
Normal file
263
lib/ui/settings/upgrade_dialog.dart
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
|
import 'package:flutter/material.dart' show Material;
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:markdown/markdown.dart' as markdown;
|
||||||
|
import 'package:starcitizen_doctor/api/api.dart';
|
||||||
|
import 'package:starcitizen_doctor/app.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/conf/const_conf.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||||
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
||||||
|
import 'package:html/parser.dart' as html_parser;
|
||||||
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
|
class UpgradeDialogUI extends HookConsumerWidget {
|
||||||
|
const UpgradeDialogUI({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final appState = ref.watch(appGlobalModelProvider);
|
||||||
|
final appModel = ref.read(appGlobalModelProvider.notifier);
|
||||||
|
final description = useState<String?>(null);
|
||||||
|
final isUsingDiversion = useState(false);
|
||||||
|
final isUpgrading = useState(false);
|
||||||
|
final progress = useState(0.0);
|
||||||
|
final downloadUrl = useState("");
|
||||||
|
|
||||||
|
final targetVersion = ConstConf.isMSE
|
||||||
|
? appState.networkVersionData!.mSELastVersion!
|
||||||
|
: appState.networkVersionData!.lastVersion!;
|
||||||
|
|
||||||
|
final minVersionCode = ConstConf.isMSE
|
||||||
|
? appState.networkVersionData?.mSEMinVersionCode
|
||||||
|
: appState.networkVersionData?.minVersionCode;
|
||||||
|
|
||||||
|
useEffect(() {
|
||||||
|
_getUpdateInfo(context, targetVersion, description, downloadUrl);
|
||||||
|
return null;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return Material(
|
||||||
|
child: ContentDialog(
|
||||||
|
title: Text("发现新版本 -> $targetVersion"),
|
||||||
|
constraints:
|
||||||
|
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .55),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 24, right: 24),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
if (description.value == null) ...[
|
||||||
|
const Center(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
ProgressRing(),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Text("正在获取新版本详情...")
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
] else
|
||||||
|
...makeMarkdownView(description.value!,
|
||||||
|
attachmentsUrl: URLConf.giteaAttachmentsUrl),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
if (isUsingDiversion.value) ...[
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: _launchReleaseUrl,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white.withOpacity(.1),
|
||||||
|
borderRadius: BorderRadius.circular(7)),
|
||||||
|
child: Text(
|
||||||
|
"提示:当前正在使用分流服务器进行更新,可能会出现下载速度下降,但有助于我们进行成本控制,若下载异常请点击这里跳转手动安装。",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14, color: Colors.white.withOpacity(.7)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
if (isUpgrading.value) ...[
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Text(progress.value == 100
|
||||||
|
? "正在安装: "
|
||||||
|
: "正在下载: ${progress.value.toStringAsFixed(2)}% "),
|
||||||
|
Expanded(
|
||||||
|
child: ProgressBar(
|
||||||
|
value: progress.value == 100 ? null : progress.value,
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: isUpgrading.value
|
||||||
|
? null
|
||||||
|
: [
|
||||||
|
if (downloadUrl.value.isNotEmpty)
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () => _doUpgrade(
|
||||||
|
context,
|
||||||
|
appState,
|
||||||
|
isUpgrading,
|
||||||
|
appModel,
|
||||||
|
downloadUrl,
|
||||||
|
description,
|
||||||
|
isUsingDiversion,
|
||||||
|
progress),
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
top: 4, bottom: 4, left: 8, right: 8),
|
||||||
|
child: Text("立即更新"),
|
||||||
|
)),
|
||||||
|
if (ConstConf.appVersionCode >= (minVersionCode ?? 0))
|
||||||
|
Button(
|
||||||
|
onPressed: () => _doCancel(context),
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
top: 4, bottom: 4, left: 8, right: 8),
|
||||||
|
child: Text("下次吧"),
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _getUpdateInfo(
|
||||||
|
BuildContext context,
|
||||||
|
targetVersion,
|
||||||
|
ValueNotifier<String?> description,
|
||||||
|
ValueNotifier<String> downloadUrl) async {
|
||||||
|
try {
|
||||||
|
final r = await Api.getAppReleaseDataByVersionName(targetVersion);
|
||||||
|
description = r["body"];
|
||||||
|
final assets = List.of(r["assets"] ?? []);
|
||||||
|
for (var asset in assets) {
|
||||||
|
if (asset["name"].toString().endsWith("SETUP.exe")) {
|
||||||
|
downloadUrl.value = asset["browser_download_url"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
dPrint("UpgradeDialogUIModel.loadData Error : $e");
|
||||||
|
if (!context.mounted) return;
|
||||||
|
Navigator.pop(context, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _launchReleaseUrl() {
|
||||||
|
launchUrlString(URLConf.devReleaseUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _doCancel(BuildContext context) {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getDiversionUrl(String description) {
|
||||||
|
try {
|
||||||
|
final htmlStr = markdown.markdownToHtml(description);
|
||||||
|
final html = html_parser.parse(htmlStr);
|
||||||
|
for (var element in html.querySelectorAll('a')) {
|
||||||
|
String linkText = element.text;
|
||||||
|
String linkUrl = element.attributes['href'] ?? '';
|
||||||
|
if (linkText.trim().endsWith("_SETUP.exe")) {
|
||||||
|
final diversionDownloadUrl = linkUrl.trim();
|
||||||
|
dPrint("diversionDownloadUrl === $diversionDownloadUrl");
|
||||||
|
return diversionDownloadUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
dPrint("_checkDiversionUrl Error:$e");
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _doUpgrade(
|
||||||
|
BuildContext context,
|
||||||
|
AppGlobalState appState,
|
||||||
|
ValueNotifier<bool> isUpgrading,
|
||||||
|
AppGlobalModel appModel,
|
||||||
|
ValueNotifier<String> downloadUrl,
|
||||||
|
ValueNotifier<String?> description,
|
||||||
|
ValueNotifier<bool> isUsingDiversion,
|
||||||
|
ValueNotifier<double> progress) async {
|
||||||
|
if (ConstConf.isMSE) {
|
||||||
|
launchUrlString("ms-windows-store://pdp/?productid=9NF3SWFWNKL1");
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
if (ConstConf.appVersionCode <
|
||||||
|
(appState.networkVersionData?.minVersionCode ?? 0)) {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (!context.mounted) return;
|
||||||
|
_doCancel(context);
|
||||||
|
}
|
||||||
|
isUpgrading.value = true;
|
||||||
|
final fileName = "${appModel.getUpgradePath()}/next_SETUP.exe";
|
||||||
|
try {
|
||||||
|
// check diversionDownloadUrl
|
||||||
|
var url = downloadUrl.value;
|
||||||
|
final diversionDownloadUrl = _getDiversionUrl(description.value!);
|
||||||
|
final dio = Dio();
|
||||||
|
if (diversionDownloadUrl.isNotEmpty) {
|
||||||
|
try {
|
||||||
|
final resp = await dio.head(diversionDownloadUrl,
|
||||||
|
options: Options(
|
||||||
|
sendTimeout: const Duration(seconds: 10),
|
||||||
|
receiveTimeout: const Duration(seconds: 10)));
|
||||||
|
if (resp.statusCode == 200) {
|
||||||
|
isUsingDiversion.value = true;
|
||||||
|
url = diversionDownloadUrl;
|
||||||
|
} else {
|
||||||
|
isUsingDiversion.value = false;
|
||||||
|
}
|
||||||
|
dPrint("diversionDownloadUrl head resp == ${resp.headers}");
|
||||||
|
} catch (e) {
|
||||||
|
dPrint("diversionDownloadUrl err:$e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await dio.download(url, fileName,
|
||||||
|
onReceiveProgress: (int count, int total) {
|
||||||
|
progress.value = (count / total) * 100;
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
isUpgrading.value = false;
|
||||||
|
progress.value = 0;
|
||||||
|
if (!context.mounted) return;
|
||||||
|
showToast(context, "下载失败,请尝试手动安装!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final r = await (Process.run(
|
||||||
|
SystemHelper.powershellPath, ["start", fileName, "/SILENT"]));
|
||||||
|
if (r.stderr.toString().isNotEmpty) {
|
||||||
|
throw r.stderr;
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
} catch (_) {
|
||||||
|
isUpgrading.value = false;
|
||||||
|
progress.value = 0;
|
||||||
|
if (!context.mounted) return;
|
||||||
|
showToast(context, "运行失败,请尝试手动安装!");
|
||||||
|
Process.run(SystemHelper.powershellPath,
|
||||||
|
["explorer.exe", "/select,\"$fileName\""]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,104 +0,0 @@
|
|||||||
import 'package:flutter/material.dart' show Material;
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
||||||
|
|
||||||
import 'upgrade_dialog_ui_model.dart';
|
|
||||||
|
|
||||||
class UpgradeDialogUI extends BaseUI<UpgradeDialogUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, UpgradeDialogUIModel model) {
|
|
||||||
return Material(
|
|
||||||
child: ContentDialog(
|
|
||||||
title: Text("发现新版本 -> ${model.targetVersion}"),
|
|
||||||
constraints:
|
|
||||||
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .55),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 24, right: 24),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
if (model.description == null) ...[
|
|
||||||
const Center(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
ProgressRing(),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Text("正在获取新版本详情...")
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
] else
|
|
||||||
...makeMarkdownView(model.description!,
|
|
||||||
attachmentsUrl: URLConf.giteaAttachmentsUrl),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
if (model.isUsingDiversion) ...[
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: model.launchReleaseUrl,
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white.withOpacity(.1),
|
|
||||||
borderRadius: BorderRadius.circular(7)),
|
|
||||||
child: Text(
|
|
||||||
"提示:当前正在使用分流服务器进行更新,可能会出现下载速度下降,但有助于我们进行成本控制,若下载异常请点击这里跳转手动安装。",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14, color: Colors.white.withOpacity(.7)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
if (model.isUpgrading) ...[
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(model.progress == 100
|
|
||||||
? "正在安装: "
|
|
||||||
: "正在下载: ${model.progress?.toStringAsFixed(2) ?? 0}% "),
|
|
||||||
Expanded(
|
|
||||||
child: ProgressBar(
|
|
||||||
value: model.progress == 100 ? null : model.progress,
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: model.isUpgrading
|
|
||||||
? null
|
|
||||||
: [
|
|
||||||
if (model.downloadUrl.isNotEmpty)
|
|
||||||
FilledButton(
|
|
||||||
onPressed: model.doUpgrade,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
top: 4, bottom: 4, left: 8, right: 8),
|
|
||||||
child: Text("立即更新"),
|
|
||||||
)),
|
|
||||||
if (AppConf.appVersionCode >=
|
|
||||||
(AppConf.networkVersionData?.minVersionCode ?? 0))
|
|
||||||
Button(
|
|
||||||
onPressed: model.doCancel,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
top: 4, bottom: 4, left: 8, right: 8),
|
|
||||||
child: Text("下次吧"),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, UpgradeDialogUIModel model) => "";
|
|
||||||
}
|
|
@ -1,136 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:markdown/markdown.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
import 'package:html/parser.dart';
|
|
||||||
|
|
||||||
class UpgradeDialogUIModel extends BaseUIModel {
|
|
||||||
String? description;
|
|
||||||
String targetVersion = "";
|
|
||||||
String downloadUrl = "";
|
|
||||||
String? diversionDownloadUrl;
|
|
||||||
bool isUsingDiversion = false;
|
|
||||||
|
|
||||||
bool isUpgrading = false;
|
|
||||||
double? progress;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future loadData() async {
|
|
||||||
// get download url for gitlab release
|
|
||||||
try {
|
|
||||||
targetVersion = AppConf.isMSE
|
|
||||||
? AppConf.networkVersionData!.mSELastVersion!
|
|
||||||
: AppConf.networkVersionData!.lastVersion!;
|
|
||||||
final r = await Api.getAppReleaseDataByVersionName(targetVersion);
|
|
||||||
description = r["body"];
|
|
||||||
_checkDiversionUrl();
|
|
||||||
final assets = List.of(r["assets"] ?? []);
|
|
||||||
for (var asset in assets) {
|
|
||||||
if (asset["name"].toString().endsWith("SETUP.exe")) {
|
|
||||||
downloadUrl = asset["browser_download_url"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("UpgradeDialogUIModel.loadData Error : $e");
|
|
||||||
Navigator.pop(context!, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
doUpgrade() async {
|
|
||||||
if (AppConf.isMSE) {
|
|
||||||
launchUrlString("ms-windows-store://pdp/?productid=9NF3SWFWNKL1");
|
|
||||||
await Future.delayed(const Duration(seconds: 3));
|
|
||||||
if (AppConf.appVersionCode <
|
|
||||||
(AppConf.networkVersionData?.minVersionCode ?? 0)) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
Navigator.pop(context!);
|
|
||||||
}
|
|
||||||
isUpgrading = true;
|
|
||||||
notifyListeners();
|
|
||||||
final fileName = "${AppConf.getUpgradePath()}/next_SETUP.exe";
|
|
||||||
try {
|
|
||||||
// check diversionDownloadUrl
|
|
||||||
var url = downloadUrl;
|
|
||||||
final dio = Dio();
|
|
||||||
if (diversionDownloadUrl != null) {
|
|
||||||
try {
|
|
||||||
final resp = await dio.head(diversionDownloadUrl!,
|
|
||||||
options: Options(
|
|
||||||
sendTimeout: const Duration(seconds: 10),
|
|
||||||
receiveTimeout: const Duration(seconds: 10)));
|
|
||||||
if (resp.statusCode == 200) {
|
|
||||||
isUsingDiversion = true;
|
|
||||||
url = diversionDownloadUrl!;
|
|
||||||
notifyListeners();
|
|
||||||
} else {
|
|
||||||
isUsingDiversion = false;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
dPrint("diversionDownloadUrl head resp == ${resp.headers}");
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("diversionDownloadUrl err:$e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await dio.download(url, fileName,
|
|
||||||
onReceiveProgress: (int count, int total) {
|
|
||||||
progress = (count / total) * 100;
|
|
||||||
notifyListeners();
|
|
||||||
});
|
|
||||||
} catch (_) {
|
|
||||||
isUpgrading = false;
|
|
||||||
progress = null;
|
|
||||||
showToast(context!, "下载失败,请尝试手动安装!");
|
|
||||||
notifyListeners();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final r = await (Process.run(
|
|
||||||
SystemHelper.powershellPath, ["start", fileName, "/SILENT"]));
|
|
||||||
if (r.stderr.toString().isNotEmpty) {
|
|
||||||
throw r.stderr;
|
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
} catch (_) {
|
|
||||||
isUpgrading = false;
|
|
||||||
progress = null;
|
|
||||||
showToast(context!, "运行失败,请尝试手动安装!");
|
|
||||||
Process.run(SystemHelper.powershellPath,
|
|
||||||
["explorer.exe", "/select,\"$fileName\""]);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void doCancel() {
|
|
||||||
Navigator.pop(context!, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _checkDiversionUrl() {
|
|
||||||
try {
|
|
||||||
final htmlStr = markdownToHtml(description!);
|
|
||||||
final html = parse(htmlStr);
|
|
||||||
html.querySelectorAll('a').forEach((element) {
|
|
||||||
String linkText = element.text;
|
|
||||||
String linkUrl = element.attributes['href'] ?? '';
|
|
||||||
if (linkText.trim().endsWith("_SETUP.exe")) {
|
|
||||||
diversionDownloadUrl = linkUrl.trim();
|
|
||||||
dPrint("diversionDownloadUrl === $diversionDownloadUrl");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("_checkDiversionUrl Error:$e");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void launchReleaseUrl() {
|
|
||||||
launchUrlString(URLConf.devReleaseUrl);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,29 @@
|
|||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||||
|
import 'package:starcitizen_doctor/app.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/conf/const_conf.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/io/aria2c.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||||
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
||||||
|
|
||||||
import 'splash_ui_model.dart';
|
class SplashUI extends HookConsumerWidget {
|
||||||
|
const SplashUI({super.key});
|
||||||
|
|
||||||
class SplashUI extends BaseUI<SplashUIModel> {
|
|
||||||
@override
|
@override
|
||||||
Widget? buildBody(BuildContext context, SplashUIModel model) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return makeDefaultPage(context, model,
|
final stepState = useState(0);
|
||||||
|
final step = stepState.value;
|
||||||
|
|
||||||
|
useEffect(() {
|
||||||
|
final appModel = ref.read(appGlobalModelProvider.notifier);
|
||||||
|
_initApp(context, appModel, stepState);
|
||||||
|
return null;
|
||||||
|
}, const []);
|
||||||
|
|
||||||
|
return makeDefaultPage(context,
|
||||||
content: Center(
|
content: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@ -15,9 +32,9 @@ class SplashUI extends BaseUI<SplashUIModel> {
|
|||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
const ProgressRing(),
|
const ProgressRing(),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
if (model.step == 0) const Text("正在检测可用性,这可能需要一点时间..."),
|
if (step == 0) const Text("正在检测可用性,这可能需要一点时间..."),
|
||||||
if (model.step == 1) const Text("正在检查更新..."),
|
if (step == 1) const Text("正在检查更新..."),
|
||||||
if (model.step == 2) const Text("即将完成..."),
|
if (step == 2) const Text("即将完成..."),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -34,12 +51,31 @@ class SplashUI extends BaseUI<SplashUIModel> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
const Text(
|
const Text(
|
||||||
"SC汉化盒子 V${AppConf.appVersion} ${AppConf.isMSE ? "" : " Dev"}")
|
"SC汉化盒子 V${ConstConf.appVersion} ${ConstConf.isMSE ? "" : " Dev"}")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
void _initApp(BuildContext context, AppGlobalModel appModel,
|
||||||
String getUITitle(BuildContext context, SplashUIModel model) => "";
|
ValueNotifier<int> stepState) async {
|
||||||
|
await appModel.initApp();
|
||||||
|
AnalyticsApi.touch("launch");
|
||||||
|
try {
|
||||||
|
await URLConf.checkHost();
|
||||||
|
} catch (e) {
|
||||||
|
dPrint("checkHost Error:$e");
|
||||||
|
}
|
||||||
|
stepState.value = 1;
|
||||||
|
if (!context.mounted) return;
|
||||||
|
await appModel.checkUpdate(context);
|
||||||
|
stepState.value = 2;
|
||||||
|
await Aria2cManager.checkLazyLoad();
|
||||||
|
// Navigator.pushAndRemoveUntil(
|
||||||
|
// context!,
|
||||||
|
// BaseUIContainer(
|
||||||
|
// uiCreate: () => IndexUI(),
|
||||||
|
// modelCreate: () => IndexUIModel()).makeRoute(context!),
|
||||||
|
// (route) => false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/aria2c.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/index_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/index_ui_model.dart';
|
|
||||||
|
|
||||||
import '../common/conf/app_conf.dart';
|
|
||||||
|
|
||||||
class SplashUIModel extends BaseUIModel {
|
|
||||||
int step = 0;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initModel() {
|
|
||||||
_initApp();
|
|
||||||
super.initModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _initApp() async {
|
|
||||||
AnalyticsApi.touch("launch");
|
|
||||||
try {
|
|
||||||
await URLConf.checkHost();
|
|
||||||
} catch (e) {
|
|
||||||
dPrint("checkHost Error:$e");
|
|
||||||
}
|
|
||||||
step = 1;
|
|
||||||
notifyListeners();
|
|
||||||
await AppConf.checkUpdate();
|
|
||||||
step = 2;
|
|
||||||
notifyListeners();
|
|
||||||
await Aria2cManager.checkLazyLoad();
|
|
||||||
Navigator.pushAndRemoveUntil(
|
|
||||||
context!,
|
|
||||||
BaseUIContainer(
|
|
||||||
uiCreate: () => IndexUI(),
|
|
||||||
modelCreate: () => IndexUIModel()).makeRoute(context!),
|
|
||||||
(route) => false);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,247 +0,0 @@
|
|||||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui.dart';
|
|
||||||
|
|
||||||
import 'tools_ui_model.dart';
|
|
||||||
|
|
||||||
class ToolsUI extends BaseUI<ToolsUIModel> {
|
|
||||||
@override
|
|
||||||
Widget? buildBody(BuildContext context, ToolsUIModel model) {
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 22, right: 22),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
makeGameLauncherPathSelect(context, model),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
makeGamePathSelect(context, model),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Button(
|
|
||||||
onPressed: model.working ? null : model.loadData,
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
top: 30, bottom: 30, left: 12, right: 12),
|
|
||||||
child: Icon(FluentIcons.refresh),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
if (model.items.isEmpty)
|
|
||||||
const Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
ProgressRing(),
|
|
||||||
SizedBox(height: 12),
|
|
||||||
Text("正在扫描..."),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Expanded(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
child: AlignedGridView.count(
|
|
||||||
crossAxisCount: 3,
|
|
||||||
mainAxisSpacing: 12,
|
|
||||||
crossAxisSpacing: 12,
|
|
||||||
itemCount: (model.isItemLoading)
|
|
||||||
? model.items.length + 1
|
|
||||||
: model.items.length,
|
|
||||||
shrinkWrap: true,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index == model.items.length) {
|
|
||||||
return Container(
|
|
||||||
width: 300,
|
|
||||||
height: 200,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
child: makeLoading(context));
|
|
||||||
}
|
|
||||||
final item = model.items[index];
|
|
||||||
return Container(
|
|
||||||
width: 300,
|
|
||||||
height: 200,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
color: FluentTheme.of(context).cardColor,
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white.withOpacity(.2),
|
|
||||||
borderRadius:
|
|
||||||
BorderRadius.circular(1000)),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: item.icon,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
item.name,
|
|
||||||
style: const TextStyle(fontSize: 16),
|
|
||||||
)),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
item.infoString,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.white.withOpacity(.6)),
|
|
||||||
)),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Spacer(),
|
|
||||||
Button(
|
|
||||||
onPressed: model.working
|
|
||||||
? null
|
|
||||||
: item.onTap == null
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
try {
|
|
||||||
item.onTap?.call();
|
|
||||||
} catch (e) {
|
|
||||||
showToast(
|
|
||||||
context, "处理失败!:$e");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.play),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (model.working)
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black.withAlpha(150),
|
|
||||||
),
|
|
||||||
child: const Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
ProgressRing(),
|
|
||||||
SizedBox(height: 12),
|
|
||||||
Text("正在处理..."),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeGamePathSelect(BuildContext context, ToolsUIModel model) {
|
|
||||||
return Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Text("游戏安装位置: "),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Expanded(
|
|
||||||
child: SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: ComboBox<String>(
|
|
||||||
value: model.scInstalledPath,
|
|
||||||
items: [
|
|
||||||
for (final path in model.scInstallPaths)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: path,
|
|
||||||
child: Text(path),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: (v) {
|
|
||||||
model.loadData(skipPathScan: true);
|
|
||||||
model.scInstalledPath = v!;
|
|
||||||
model.notifyListeners();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Button(
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.folder_open),
|
|
||||||
),
|
|
||||||
onPressed: () => model.openDir(model.scInstalledPath))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget makeGameLauncherPathSelect(BuildContext context, ToolsUIModel model) {
|
|
||||||
return Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Text("RSI启动器位置:"),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Expanded(
|
|
||||||
child: SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: ComboBox<String>(
|
|
||||||
value: model.rsiLauncherInstalledPath,
|
|
||||||
items: [
|
|
||||||
for (final path in model.rsiLauncherInstallPaths)
|
|
||||||
ComboBoxItem(
|
|
||||||
value: path,
|
|
||||||
child: Text(path),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
onChanged: (v) {
|
|
||||||
model.loadData(skipPathScan: true);
|
|
||||||
model.rsiLauncherInstalledPath = v!;
|
|
||||||
model.notifyListeners();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Button(
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.all(6),
|
|
||||||
child: Icon(FluentIcons.folder_open),
|
|
||||||
),
|
|
||||||
onPressed: () => model.openDir(model.rsiLauncherInstalledPath))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getUITitle(BuildContext context, ToolsUIModel model) => "ToolsUI";
|
|
||||||
}
|
|
@ -1,500 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
|
||||||
import 'package:starcitizen_doctor/api/api.dart';
|
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/aria2c.dart';
|
|
||||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/downloader/downloader_ui.dart';
|
|
||||||
import 'package:starcitizen_doctor/ui/home/downloader/downloader_ui_model.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
|
||||||
import 'package:xml/xml.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class ToolsUIModel extends BaseUIModel {
|
|
||||||
bool _working = false;
|
|
||||||
|
|
||||||
String scInstalledPath = "";
|
|
||||||
String rsiLauncherInstalledPath = "";
|
|
||||||
|
|
||||||
List<String> scInstallPaths = [];
|
|
||||||
List<String> rsiLauncherInstallPaths = [];
|
|
||||||
|
|
||||||
set working(bool b) {
|
|
||||||
_working = b;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get working => _working;
|
|
||||||
|
|
||||||
var items = <_ToolsItemData>[];
|
|
||||||
|
|
||||||
bool isItemLoading = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future loadData({bool skipPathScan = false}) async {
|
|
||||||
if (isItemLoading) return;
|
|
||||||
items.clear();
|
|
||||||
notifyListeners();
|
|
||||||
if (!skipPathScan) {
|
|
||||||
await reScanPath();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
items = [
|
|
||||||
_ToolsItemData(
|
|
||||||
"systeminfo",
|
|
||||||
"查看系统信息",
|
|
||||||
"查看系统关键信息,用于快速问诊 \n\n耗时操作,请耐心等待。",
|
|
||||||
const Icon(FluentIcons.system, size: 28),
|
|
||||||
onTap: _showSystemInfo,
|
|
||||||
),
|
|
||||||
_ToolsItemData(
|
|
||||||
"p4k_downloader",
|
|
||||||
"P4K 分流下载 / 修复",
|
|
||||||
"使用星际公民中文百科提供的分流下载服务,可用于下载或修复 p4k。 \n资源有限,请勿滥用。",
|
|
||||||
const Icon(FontAwesomeIcons.download, size: 28),
|
|
||||||
onTap: _downloadP4k,
|
|
||||||
),
|
|
||||||
_ToolsItemData(
|
|
||||||
"reinstall_eac",
|
|
||||||
"重装 EasyAntiCheat 反作弊",
|
|
||||||
"若您遇到 EAC 错误,且自动修复无效,请尝试使用此功能重装 EAC。",
|
|
||||||
const Icon(FluentIcons.game, size: 28),
|
|
||||||
onTap: _reinstallEAC,
|
|
||||||
),
|
|
||||||
_ToolsItemData(
|
|
||||||
"rsilauncher_admin_mode",
|
|
||||||
"RSI Launcher 管理员模式",
|
|
||||||
"以管理员身份运行RSI启动器,可能会解决一些问题。\n\n若设置了能效核心屏蔽参数,也会在此应用。",
|
|
||||||
const Icon(FluentIcons.admin, size: 28),
|
|
||||||
onTap: _adminRSILauncher,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
isItemLoading = true;
|
|
||||||
items.add(await _addShaderCard());
|
|
||||||
notifyListeners();
|
|
||||||
items.add(await _addPhotographyCard());
|
|
||||||
notifyListeners();
|
|
||||||
items.addAll(await _addLogCard());
|
|
||||||
notifyListeners();
|
|
||||||
items.addAll(await _addNvmePatchCard());
|
|
||||||
notifyListeners();
|
|
||||||
// close loading
|
|
||||||
isItemLoading = false;
|
|
||||||
notifyListeners();
|
|
||||||
} catch (e) {
|
|
||||||
showToast(context!, "初始化失败,请截图报告给开发者。$e");
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<_ToolsItemData>> _addLogCard() async {
|
|
||||||
double logPathLen = 0;
|
|
||||||
try {
|
|
||||||
logPathLen =
|
|
||||||
(await File(await SCLoggerHelper.getLogFilePath() ?? "").length()) /
|
|
||||||
1024 /
|
|
||||||
1024;
|
|
||||||
} catch (_) {}
|
|
||||||
return [
|
|
||||||
_ToolsItemData(
|
|
||||||
"rsilauncher_log_fix",
|
|
||||||
"RSI Launcher Log 修复",
|
|
||||||
"在某些情况下 RSI启动器 的 log 文件会损坏,导致无法完成问题扫描,使用此工具清理损坏的 log 文件。\n\n当前日志文件大小:${(logPathLen.toStringAsFixed(4))} MB",
|
|
||||||
const Icon(FontAwesomeIcons.bookBible, size: 28),
|
|
||||||
onTap: _rsiLogFix,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<_ToolsItemData>> _addNvmePatchCard() async {
|
|
||||||
final nvmePatchStatus = await SystemHelper.checkNvmePatchStatus();
|
|
||||||
return [
|
|
||||||
if (nvmePatchStatus)
|
|
||||||
_ToolsItemData(
|
|
||||||
"remove_nvme_settings",
|
|
||||||
"移除 nvme 注册表补丁",
|
|
||||||
"若您使用 nvme 补丁出现问题,请运行此工具。(可能导致游戏 安装/更新 不可用。)\n\n当前补丁状态:${(nvmePatchStatus) ? "已安装" : "未安装"}",
|
|
||||||
const Icon(FluentIcons.hard_drive, size: 28),
|
|
||||||
onTap: nvmePatchStatus
|
|
||||||
? () async {
|
|
||||||
working = true;
|
|
||||||
await SystemHelper.doRemoveNvmePath();
|
|
||||||
working = false;
|
|
||||||
showToast(context!, "已移除,重启生效!");
|
|
||||||
loadData(skipPathScan: true);
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
if (!nvmePatchStatus)
|
|
||||||
_ToolsItemData(
|
|
||||||
"add_nvme_settings",
|
|
||||||
"写入 nvme 注册表补丁",
|
|
||||||
"手动写入NVM补丁,该功能仅在您知道自己在作什么的情况下使用",
|
|
||||||
const Icon(FontAwesomeIcons.cashRegister, size: 28),
|
|
||||||
onTap: () async {
|
|
||||||
working = true;
|
|
||||||
final r = await SystemHelper.addNvmePatch();
|
|
||||||
if (r == "") {
|
|
||||||
showToast(context!,
|
|
||||||
"修复成功,请尝试重启后继续安装游戏! 若注册表修改操作导致其他软件出现兼容问题,请使用 工具 中的 NVME 注册表清理。");
|
|
||||||
notifyListeners();
|
|
||||||
} else {
|
|
||||||
showToast(context!, "修复失败,$r");
|
|
||||||
}
|
|
||||||
working = false;
|
|
||||||
loadData(skipPathScan: true);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<_ToolsItemData> _addShaderCard() async {
|
|
||||||
final gameShaderCachePath = await SCLoggerHelper.getShaderCachePath();
|
|
||||||
return _ToolsItemData(
|
|
||||||
"clean_shaders",
|
|
||||||
"清理着色器缓存",
|
|
||||||
"若游戏画面出现异常或版本更新后可使用本工具清理过期的着色器(当大于500M时,建议清理) \n\n缓存大小:${((await SystemHelper.getDirLen(gameShaderCachePath ?? "", skipPath: [
|
|
||||||
"$gameShaderCachePath\\Crashes"
|
|
||||||
])) / 1024 / 1024).toStringAsFixed(4)} MB",
|
|
||||||
const Icon(FontAwesomeIcons.shapes, size: 28),
|
|
||||||
onTap: _cleanShaderCache,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<_ToolsItemData> _addPhotographyCard() async {
|
|
||||||
// 获取配置文件状态
|
|
||||||
final isEnable = await _checkPhotographyStatus();
|
|
||||||
|
|
||||||
return _ToolsItemData(
|
|
||||||
"photography_mode",
|
|
||||||
isEnable ? "关闭摄影模式" : "开启摄影模式",
|
|
||||||
isEnable
|
|
||||||
? "还原镜头摇晃效果。\n\n@拉邦那 Lapernum 提供参数信息。"
|
|
||||||
: "一键关闭游戏内镜头晃动以便于摄影操作。\n\n @拉邦那 Lapernum 提供参数信息。",
|
|
||||||
const Icon(FontAwesomeIcons.camera, size: 28),
|
|
||||||
onTap: () => _onChangePhotographyMode(isEnable),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ---------------------------- func -------------------------------------------------------
|
|
||||||
/// -----------------------------------------------------------------------------------------
|
|
||||||
/// -----------------------------------------------------------------------------------------
|
|
||||||
/// -----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Future<void> reScanPath() async {
|
|
||||||
scInstallPaths.clear();
|
|
||||||
rsiLauncherInstallPaths.clear();
|
|
||||||
scInstalledPath = "";
|
|
||||||
rsiLauncherInstalledPath = "";
|
|
||||||
try {
|
|
||||||
rsiLauncherInstalledPath = await SystemHelper.getRSILauncherPath();
|
|
||||||
rsiLauncherInstallPaths.add(rsiLauncherInstalledPath);
|
|
||||||
final listData = await SCLoggerHelper.getLauncherLogList();
|
|
||||||
if (listData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scInstallPaths = await SCLoggerHelper.getGameInstallPath(listData,
|
|
||||||
checkExists: false, withVersion: ["LIVE", "PTU", "EPTU"]);
|
|
||||||
if (scInstallPaths.isNotEmpty) {
|
|
||||||
scInstalledPath = scInstallPaths.first;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dPrint(e);
|
|
||||||
showToast(context!, "解析 log 文件失败!\n请尝试使用 RSI Launcher log 修复 工具!");
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
|
|
||||||
if (rsiLauncherInstalledPath == "") {
|
|
||||||
showToast(context!, "未找到 RSI 启动器,请尝试重新安装,或在设置中手动添加。");
|
|
||||||
}
|
|
||||||
if (scInstalledPath == "") {
|
|
||||||
showToast(context!, "未找到星际公民游戏安装位置,请至少完成一次游戏启动操作 或在设置中手动添加。");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 重装EAC
|
|
||||||
Future<void> _reinstallEAC() async {
|
|
||||||
if (scInstalledPath.isEmpty) {
|
|
||||||
showToast(context!, "该功能需要一个有效的游戏安装目录");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
working = true;
|
|
||||||
try {
|
|
||||||
final eacPath = "$scInstalledPath\\EasyAntiCheat";
|
|
||||||
final eacJsonPath = "$eacPath\\Settings.json";
|
|
||||||
if (await File(eacJsonPath).exists()) {
|
|
||||||
Map<String, String> envVars = Platform.environment;
|
|
||||||
final eacJsonData = await File(eacJsonPath).readAsString();
|
|
||||||
final Map eacJson = json.decode(eacJsonData);
|
|
||||||
final eacID = eacJson["productid"];
|
|
||||||
if (eacID != null) {
|
|
||||||
final eacCacheDir =
|
|
||||||
Directory("${envVars["appdata"]}\\EasyAntiCheat\\$eacID");
|
|
||||||
if (await eacCacheDir.exists()) {
|
|
||||||
await eacCacheDir.delete(recursive: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final dir = Directory(eacPath);
|
|
||||||
if (await dir.exists()) {
|
|
||||||
await dir.delete(recursive: true);
|
|
||||||
}
|
|
||||||
final eacLauncher = File("$scInstalledPath\\StarCitizen_Launcher.exe");
|
|
||||||
if (await eacLauncher.exists()) {
|
|
||||||
await eacLauncher.delete(recursive: true);
|
|
||||||
}
|
|
||||||
showToast(context!,
|
|
||||||
"已为您移除 EAC 文件,接下来将为您打开 RSI 启动器,请您前往 SETTINGS -> VERIFY 重装 EAC。");
|
|
||||||
_adminRSILauncher();
|
|
||||||
} catch (e) {
|
|
||||||
showToast(context!, "出现错误:$e");
|
|
||||||
}
|
|
||||||
working = false;
|
|
||||||
loadData(skipPathScan: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> getSystemInfo() async {
|
|
||||||
return "系统:${await SystemHelper.getSystemName()}\n\n"
|
|
||||||
"处理器:${await SystemHelper.getCpuName()}\n\n"
|
|
||||||
"内存大小:${await SystemHelper.getSystemMemorySizeGB()}GB\n\n"
|
|
||||||
"显卡信息:\n${await SystemHelper.getGpuInfo()}\n\n"
|
|
||||||
"硬盘信息:\n${await SystemHelper.getDiskInfo()}\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 管理员模式运行 RSI 启动器
|
|
||||||
Future _adminRSILauncher() async {
|
|
||||||
if (rsiLauncherInstalledPath == "") {
|
|
||||||
showToast(context!, "未找到 RSI 启动器目录,请您尝试手动操作。");
|
|
||||||
}
|
|
||||||
handleError(
|
|
||||||
() => SystemHelper.checkAndLaunchRSILauncher(rsiLauncherInstalledPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _rsiLogFix() async {
|
|
||||||
working = true;
|
|
||||||
final path = await SCLoggerHelper.getLogFilePath();
|
|
||||||
if (!await File(path!).exists()) {
|
|
||||||
showToast(
|
|
||||||
context!, "日志文件不存在,请尝试进行一次游戏启动或游戏安装,并退出启动器,若无法解决问题,请尝试将启动器更新至最新版本!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
SystemHelper.killRSILauncher();
|
|
||||||
await File(path).delete(recursive: true);
|
|
||||||
showToast(context!, "清理完毕,请完成一次安装 / 游戏启动 操作。");
|
|
||||||
SystemHelper.checkAndLaunchRSILauncher(rsiLauncherInstalledPath);
|
|
||||||
} catch (_) {
|
|
||||||
showToast(context!, "清理失败,请手动移除,文件位置:$path");
|
|
||||||
}
|
|
||||||
working = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
openDir(path) async {
|
|
||||||
await Process.run(
|
|
||||||
SystemHelper.powershellPath, ["explorer.exe", "/select,\"$path\""]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _showSystemInfo() async {
|
|
||||||
working = true;
|
|
||||||
final systemInfo = await getSystemInfo();
|
|
||||||
showDialog<String>(
|
|
||||||
context: context!,
|
|
||||||
builder: (context) => ContentDialog(
|
|
||||||
title: const Text('系统信息'),
|
|
||||||
content: Text(systemInfo),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context).size.width * .65,
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
FilledButton(
|
|
||||||
child: const Padding(
|
|
||||||
padding: EdgeInsets.only(top: 2, bottom: 2, left: 8, right: 8),
|
|
||||||
child: Text('关闭'),
|
|
||||||
),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
working = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _cleanShaderCache() async {
|
|
||||||
working = true;
|
|
||||||
final gameShaderCachePath = await SCLoggerHelper.getShaderCachePath();
|
|
||||||
final l =
|
|
||||||
await Directory(gameShaderCachePath!).list(recursive: false).toList();
|
|
||||||
for (var value in l) {
|
|
||||||
if (value is Directory) {
|
|
||||||
if (!value.absolute.path.contains("Crashes")) {
|
|
||||||
await value.delete(recursive: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loadData(skipPathScan: true);
|
|
||||||
working = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _downloadP4k() async {
|
|
||||||
String savePath = scInstalledPath;
|
|
||||||
String fileName = "Data.p4k";
|
|
||||||
|
|
||||||
if ((await SystemHelper.getPID("\"RSI Launcher\"")).isNotEmpty) {
|
|
||||||
showToast(context!, "RSI启动器正在运行!请先关闭启动器再使用此功能!",
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: MediaQuery.of(context!).size.width * .35));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await showToast(
|
|
||||||
context!,
|
|
||||||
"P4k 是星际公民的核心游戏文件,高达 100GB+,盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户 或用于修复官方启动器无法修复的 p4k 文件。"
|
|
||||||
"\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。");
|
|
||||||
|
|
||||||
try {
|
|
||||||
working = true;
|
|
||||||
notifyListeners();
|
|
||||||
|
|
||||||
await Aria2cManager.launchDaemon();
|
|
||||||
final aria2c = Aria2cManager.getClient();
|
|
||||||
|
|
||||||
// check download task list
|
|
||||||
for (var value in [
|
|
||||||
...await aria2c.tellActive(),
|
|
||||||
...await aria2c.tellWaiting(0, 100000)
|
|
||||||
]) {
|
|
||||||
final t = DownloaderUIModel.getTaskTypeAndName(value);
|
|
||||||
if (t.key == "torrent" && t.value.contains("Data.p4k")) {
|
|
||||||
showToast(context!, "已经有一个p4k下载任务正在进行中,请前往下载管理器查看!");
|
|
||||||
working = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var torrentUrl = "";
|
|
||||||
final l = await Api.getAppTorrentDataList();
|
|
||||||
for (var torrent in l) {
|
|
||||||
if (torrent.name == "Data.p4k") {
|
|
||||||
torrentUrl = torrent.url!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (torrentUrl == "") {
|
|
||||||
working = false;
|
|
||||||
showToast(context!, "功能维护中,请稍后重试!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final userSelect = await FilePicker.platform.saveFile(
|
|
||||||
initialDirectory: savePath,
|
|
||||||
fileName: fileName,
|
|
||||||
lockParentWindow: true);
|
|
||||||
if (userSelect == null) {
|
|
||||||
working = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
savePath = userSelect;
|
|
||||||
dPrint(savePath);
|
|
||||||
notifyListeners();
|
|
||||||
if (savePath.endsWith("\\$fileName")) {
|
|
||||||
savePath = savePath.substring(0, savePath.length - fileName.length - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
final btData = await handleError(() => RSHttp.get(torrentUrl));
|
|
||||||
if (btData == null || btData.data == null) {
|
|
||||||
working = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final b64Str = base64Encode(btData.data!);
|
|
||||||
|
|
||||||
final gid =
|
|
||||||
await aria2c.addTorrent(b64Str, extraParams: {"dir": savePath});
|
|
||||||
working = false;
|
|
||||||
dPrint("Aria2cManager.aria2c.addUri resp === $gid");
|
|
||||||
await aria2c.saveSession();
|
|
||||||
AnalyticsApi.touch("p4k_download");
|
|
||||||
|
|
||||||
BaseUIContainer(
|
|
||||||
uiCreate: () => DownloaderUI(),
|
|
||||||
modelCreate: () => DownloaderUIModel()).push(context!);
|
|
||||||
} catch (e) {
|
|
||||||
working = false;
|
|
||||||
showToast(context!, "初始化失败!: $e");
|
|
||||||
}
|
|
||||||
await Future.delayed(const Duration(seconds: 3));
|
|
||||||
launchUrlString(
|
|
||||||
"https://citizenwiki.cn/SC%E6%B1%89%E5%8C%96%E7%9B%92%E5%AD%90#%E5%88%86%E6%B5%81%E4%B8%8B%E8%BD%BD%E6%95%99%E7%A8%8B");
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> _checkPhotographyStatus({bool? setMode}) async {
|
|
||||||
const keys = ["AudioShakeStrength", "CameraSpringMovement", "ShakeScale"];
|
|
||||||
final attributesFile = File(
|
|
||||||
"$scInstalledPath\\USER\\Client\\0\\Profiles\\default\\attributes.xml");
|
|
||||||
if (setMode == null) {
|
|
||||||
bool isEnable = false;
|
|
||||||
if (scInstalledPath.isNotEmpty) {
|
|
||||||
if (await attributesFile.exists()) {
|
|
||||||
final xmlFile =
|
|
||||||
XmlDocument.parse(await attributesFile.readAsString());
|
|
||||||
isEnable = true;
|
|
||||||
for (var k in keys) {
|
|
||||||
if (!isEnable) break;
|
|
||||||
final e = xmlFile.rootElement.children
|
|
||||||
.where((element) => element.getAttribute("name") == k)
|
|
||||||
.firstOrNull;
|
|
||||||
if (e != null && e.getAttribute("value") == "0") {
|
|
||||||
} else {
|
|
||||||
isEnable = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isEnable;
|
|
||||||
} else {
|
|
||||||
if (!await attributesFile.exists()) {
|
|
||||||
showToast(context!, "配置文件不存在,请尝试运行一次游戏");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final xmlFile = XmlDocument.parse(await attributesFile.readAsString());
|
|
||||||
// clear all
|
|
||||||
xmlFile.rootElement.children.removeWhere(
|
|
||||||
(element) => keys.contains(element.getAttribute("name")));
|
|
||||||
if (setMode) {
|
|
||||||
for (var element in keys) {
|
|
||||||
XmlElement newNode = XmlElement(XmlName('Attr'), [
|
|
||||||
XmlAttribute(XmlName('name'), element),
|
|
||||||
XmlAttribute(XmlName('value'), '0'),
|
|
||||||
]);
|
|
||||||
xmlFile.rootElement.children.add(newNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dPrint(xmlFile);
|
|
||||||
await attributesFile.delete();
|
|
||||||
await attributesFile.writeAsString(xmlFile.toXmlString(pretty: true));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_onChangePhotographyMode(bool isEnable) async {
|
|
||||||
await handleError(() => _checkPhotographyStatus(setMode: !isEnable));
|
|
||||||
reloadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ToolsItemData {
|
|
||||||
String key;
|
|
||||||
|
|
||||||
_ToolsItemData(this.key, this.name, this.infoString, this.icon, {this.onTap});
|
|
||||||
|
|
||||||
String name;
|
|
||||||
String infoString;
|
|
||||||
Widget icon;
|
|
||||||
AsyncCallback? onTap;
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
import 'package:extended_image/extended_image.dart';
|
|
||||||
import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
|
|
||||||
class CacheNetImage extends StatelessWidget {
|
|
||||||
final String url;
|
|
||||||
final double? width;
|
|
||||||
final double? height;
|
|
||||||
final BoxFit? fit;
|
|
||||||
|
|
||||||
const CacheNetImage(
|
|
||||||
{super.key, required this.url, this.width, this.height, this.fit});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ExtendedImage.network(
|
|
||||||
url,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
fit: fit,
|
|
||||||
loadStateChanged: (ExtendedImageState state) {
|
|
||||||
switch (state.extendedImageLoadState) {
|
|
||||||
case LoadState.loading:
|
|
||||||
return const Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.all(8.0),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
ProgressRing(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case LoadState.failed:
|
|
||||||
return const Text("Loading Image error");
|
|
||||||
case LoadState.completed:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
|
|
||||||
class CountdownTimeText extends StatefulWidget {
|
|
||||||
final DateTime targetTime;
|
|
||||||
|
|
||||||
const CountdownTimeText({super.key, required this.targetTime});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<CountdownTimeText> createState() => _CountdownTimeTextState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CountdownTimeTextState extends State<CountdownTimeText> {
|
|
||||||
Timer? _timer;
|
|
||||||
|
|
||||||
Widget? textWidget;
|
|
||||||
|
|
||||||
bool stopTimer = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
initState() {
|
|
||||||
_onUpdateTime(null);
|
|
||||||
if (!stopTimer) {
|
|
||||||
_timer = Timer.periodic(const Duration(seconds: 1), _onUpdateTime);
|
|
||||||
}
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
dispose() {
|
|
||||||
_timer?.cancel();
|
|
||||||
_timer = null;
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
_onUpdateTime(_) {
|
|
||||||
final now = DateTime.now();
|
|
||||||
final dur = widget.targetTime.difference(now);
|
|
||||||
setState(() {
|
|
||||||
textWidget = _chineseTimeText(dur);
|
|
||||||
});
|
|
||||||
// 时间到,停止计时,并向宿主传递超时信息
|
|
||||||
if (dur.inMilliseconds <= 0) {
|
|
||||||
stopTimer = true;
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
if (stopTimer) {
|
|
||||||
_timer?.cancel();
|
|
||||||
_timer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _chineseTimeText(Duration duration) {
|
|
||||||
final surplus = duration;
|
|
||||||
int day = (surplus.inSeconds ~/ 3600) ~/ 24;
|
|
||||||
int hour = (surplus.inSeconds ~/ 3600) % 24;
|
|
||||||
int minute = surplus.inSeconds % 3600 ~/ 60;
|
|
||||||
int second = surplus.inSeconds % 60;
|
|
||||||
return Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"$day天 ",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 24, color: day < 30 ? Colors.red : Colors.white),
|
|
||||||
),
|
|
||||||
Text("${timePart(hour)}:${timePart(minute)}:${timePart(second)}"),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String timePart(int p) {
|
|
||||||
if (p.toString().length == 1) return "0$p";
|
|
||||||
return "$p";
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
if (stopTimer) {
|
|
||||||
return const Text(
|
|
||||||
"正在进行中",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
color: Color.fromRGBO(32, 220, 89, 1.0),
|
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return textWidget ?? const Text("");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
|
|
||||||
class MyPageRoute extends FluentPageRoute {
|
|
||||||
late final WidgetBuilder _builder;
|
|
||||||
|
|
||||||
MyPageRoute({required super.builder}) : _builder = builder;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget buildPage(BuildContext context, Animation<double> animation,
|
|
||||||
Animation<double> secondaryAnimation) {
|
|
||||||
assert(debugCheckHasFluentTheme(context));
|
|
||||||
final result = _builder(context);
|
|
||||||
return Semantics(
|
|
||||||
scopesRoute: true,
|
|
||||||
explicitChildNodes: true,
|
|
||||||
child: EntrancePageTransition(
|
|
||||||
animation: CurvedAnimation(
|
|
||||||
parent: animation,
|
|
||||||
curve: FluentTheme.of(context).animationCurve,
|
|
||||||
),
|
|
||||||
child: result,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +1,56 @@
|
|||||||
import 'package:extended_image/extended_image.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
import 'dart:ui' as ui;
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:markdown_widget/config/all.dart';
|
import 'package:markdown_widget/config/all.dart';
|
||||||
import 'package:markdown_widget/widget/all.dart';
|
import 'package:markdown_widget/widget/all.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:extended_image/extended_image.dart';
|
||||||
|
|
||||||
import '../base/ui.dart';
|
Widget makeDefaultPage(BuildContext context,
|
||||||
|
{Widget? titleRow,
|
||||||
Widget makeLoading(
|
List<Widget>? actions,
|
||||||
BuildContext context, {
|
Widget? content,
|
||||||
double? width,
|
bool automaticallyImplyLeading = true,
|
||||||
}) {
|
String title = ""}) {
|
||||||
width ??= 30;
|
return NavigationView(
|
||||||
return Center(
|
appBar: NavigationAppBar(
|
||||||
child: SizedBox(
|
automaticallyImplyLeading: automaticallyImplyLeading,
|
||||||
width: width,
|
title: DragToMoveArea(
|
||||||
height: width,
|
child: titleRow ??
|
||||||
// child: Lottie.asset("images/lottie/loading.zip", width: width),
|
Column(
|
||||||
child: const ProgressRing(),
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(title),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [...?actions, const WindowButtons()],
|
||||||
|
)),
|
||||||
|
content: content,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget makeSafeAre(BuildContext context, {bool withKeyboard = true}) {
|
class WindowButtons extends StatelessWidget {
|
||||||
return SafeArea(
|
const WindowButtons({super.key});
|
||||||
child: Column(
|
|
||||||
children: [
|
@override
|
||||||
const SizedBox(height: 4),
|
Widget build(BuildContext context) {
|
||||||
if (withKeyboard)
|
final FluentThemeData theme = FluentTheme.of(context);
|
||||||
SizedBox(
|
return SizedBox(
|
||||||
height: MediaQuery.of(context).viewInsets.bottom,
|
width: 138,
|
||||||
|
height: 50,
|
||||||
|
child: WindowCaption(
|
||||||
|
brightness: theme.brightness,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
),
|
),
|
||||||
],
|
);
|
||||||
));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
makeSvgColor(Color color) {
|
|
||||||
return ui.ColorFilter.mode(color, ui.BlendMode.srcIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isPadUI(BuildContext context) {
|
|
||||||
final size = MediaQuery.of(context).size;
|
|
||||||
return size.width >= size.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
fastPadding(
|
|
||||||
{required double? all,
|
|
||||||
required Widget child,
|
|
||||||
double left = 0.0,
|
|
||||||
double top = 0.0,
|
|
||||||
double right = 0.0,
|
|
||||||
double bottom = 0.0}) {
|
|
||||||
return Padding(
|
|
||||||
padding: all != null
|
|
||||||
? EdgeInsets.all(all)
|
|
||||||
: EdgeInsets.only(left: left, top: top, right: right, bottom: bottom),
|
|
||||||
child: child);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> makeMarkdownView(String description, {String? attachmentsUrl}) {
|
List<Widget> makeMarkdownView(String description, {String? attachmentsUrl}) {
|
||||||
@ -102,11 +97,3 @@ List<Widget> makeMarkdownView(String description, {String? attachmentsUrl}) {
|
|||||||
})
|
})
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
class NoScrollBehavior extends ScrollBehavior {
|
|
||||||
@override
|
|
||||||
Widget buildOverscrollIndicator(
|
|
||||||
BuildContext context, Widget child, ScrollableDetails details) {
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
17
pubspec.yaml
17
pubspec.yaml
@ -30,7 +30,12 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_riverpod: ^2.3.6
|
flutter_riverpod: ^2.4.10
|
||||||
|
riverpod_annotation: ^2.3.4
|
||||||
|
flutter_hooks: ^0.20.5
|
||||||
|
hooks_riverpod: ^2.4.10
|
||||||
|
json_annotation: ^4.8.1
|
||||||
|
go_router: ^13.2.0
|
||||||
window_manager: ^0.3.2
|
window_manager: ^0.3.2
|
||||||
fluent_ui: 4.8.5
|
fluent_ui: 4.8.5
|
||||||
flutter_staggered_grid_view: ^0.7.0
|
flutter_staggered_grid_view: ^0.7.0
|
||||||
@ -73,8 +78,8 @@ dependencies:
|
|||||||
rust_builder:
|
rust_builder:
|
||||||
path: rust_builder
|
path: rust_builder
|
||||||
aria2:
|
aria2:
|
||||||
#git: https://github.com/xkeyC/dart_aria2_rpc.git
|
git: https://github.com/xkeyC/dart_aria2_rpc.git
|
||||||
path: ../../xkeyC/dart_aria2_rpc
|
# path: ../../xkeyC/dart_aria2_rpc
|
||||||
intl: ^0.18.0
|
intl: ^0.18.0
|
||||||
synchronized: ^3.1.0+1
|
synchronized: ^3.1.0+1
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
@ -91,8 +96,12 @@ dev_dependencies:
|
|||||||
# rules and activating additional ones.
|
# rules and activating additional ones.
|
||||||
flutter_lints: ^3.0.0
|
flutter_lints: ^3.0.0
|
||||||
msix: ^3.16.4
|
msix: ^3.16.4
|
||||||
build_runner: ^2.4.6
|
build_runner: ^2.4.8
|
||||||
freezed: ^2.4.5
|
freezed: ^2.4.5
|
||||||
|
json_serializable: ^6.7.1
|
||||||
|
riverpod_generator: ^2.3.11
|
||||||
|
custom_lint: ^0.6.2
|
||||||
|
riverpod_lint: ^2.3.9
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
Loading…
Reference in New Issue
Block a user