feat: 优化指引

This commit is contained in:
xkeyC 2024-11-06 19:39:59 +08:00
parent 9f7e0dad52
commit 49cef9ed90
3 changed files with 179 additions and 153 deletions

View File

@ -802,8 +802,8 @@ class HomeUI extends HookConsumerWidget {
context: context, builder: (context) => const HomeCountdownDialogUI()); context: context, builder: (context) => const HomeCountdownDialogUI());
} }
_onMenuTap(BuildContext context, String key, HomeUIModelState homeState, Future<void> _onMenuTap(BuildContext context, String key,
WidgetRef ref) async { HomeUIModelState homeState, WidgetRef ref) async {
String gameInstallReqInfo = String gameInstallReqInfo =
S.current.home_action_info_valid_install_location_required; S.current.home_action_info_valid_install_location_required;
switch (key) { switch (key) {
@ -868,15 +868,32 @@ class HomeUI extends HookConsumerWidget {
Text("是否前往汉化管理安装?\n\n如已安装汉化,请卸载并在重新安装时打开社区输入法支持开关。")); Text("是否前往汉化管理安装?\n\n如已安装汉化,请卸载并在重新安装时打开社区输入法支持开关。"));
if (userOK) { if (userOK) {
if (!context.mounted) return; if (!context.mounted) return;
_onMenuTap(context, 'localization', homeState, ref); () async {
await _onMenuTap(context, 'localization', homeState, ref);
final localizationState = ref.read(localizationUIModelProvider);
if (localizationState.installedCommunityInputMethodSupportVersion != null) {
await Future.delayed(Duration(milliseconds: 300));
if (!context.mounted) return;
await _goInputMethod(context, model);
return;
}
}();
await Future.delayed(Duration(milliseconds: 300));
final localizationModel =
ref.read(localizationUIModelProvider.notifier);
if (!context.mounted) return;
localizationModel.checkReinstall(context);
} }
return; return;
} }
showDialog( await _goInputMethod(context, model);
}
Future<void> _goInputMethod(BuildContext context, HomeUIModel model) async {
await showDialog(
context: context, context: context,
builder: (BuildContext context) { builder: (context) => const InputMethodDialogUI(),
return InputMethodDialogUI();
},
); );
} }
} }

View File

@ -209,8 +209,9 @@ class LocalizationDialogUI extends HookConsumerWidget {
borderRadius: BorderRadius.circular(7), borderRadius: BorderRadius.circular(7),
disable: tapDisabled, disable: tapDisabled,
child: GestureDetector( child: GestureDetector(
onTap: onTap: tapDisabled
tapDisabled ? null : () => doInsTall(context, model, item, state), ? null
: () => model.onRemoteInsTall(context, item, state),
child: Container( child: Container(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -423,101 +424,6 @@ class LocalizationDialogUI extends HookConsumerWidget {
); );
} }
doInsTall(
BuildContext context,
LocalizationUIModel model,
MapEntry<String, ScLocalizationData> item,
LocalizationUIState state) async {
bool enableCommunityInputMethod =
state.communityInputMethodLanguageData != null;
final userOK = await showConfirmDialogs(
context,
"${item.value.info}",
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.current.localization_info_version_number(
item.value.versionName ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current
.localization_info_channel(item.value.gameChannel ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current
.localization_info_update_time(item.value.updateAt ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 12),
],
),
const SizedBox(height: 12),
Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).cardColor,
borderRadius: BorderRadius.circular(7)),
padding: const EdgeInsets.all(12),
child: Row(
children: [
Expanded(
child: Text(
item.value.note ?? S.current.home_localization_msg_no_note,
style: const TextStyle(fontSize: 15),
),
),
],
),
),
SizedBox(height: 12),
Row(
children: [
Text(
"安装社区输入法支持",
),
Spacer(),
StatefulBuilder(
builder: (BuildContext context,
void Function(void Function()) setState) {
return ToggleSwitch(
checked: enableCommunityInputMethod,
onChanged: state.communityInputMethodLanguageData == null
? null
: (v) {
enableCommunityInputMethod = v;
setState(() {});
},
);
},
)
],
)
],
),
confirm: S.current.localization_action_install,
cancel: S.current.home_action_cancel,
constraints:
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .45),
);
if (userOK) {
if (!context.mounted) return;
dPrint("doRemoteInstall ${item.value} $enableCommunityInputMethod");
model
.doRemoteInstall(context, item.value,
isEnableCommunityInputMethod: enableCommunityInputMethod)
?.call();
}
}
Widget makeToolsListContainer(BuildContext context, LocalizationUIModel model, Widget makeToolsListContainer(BuildContext context, LocalizationUIModel model,
LocalizationUIState state) { LocalizationUIState state) {
final toolsMenu = { final toolsMenu = {

View File

@ -233,7 +233,7 @@ class LocalizationUIModel extends _$LocalizationUIModel {
return path.split("\\").last; return path.split("\\").last;
} }
installFormString( Future<void> installFormString(
StringBuffer globalIni, StringBuffer globalIni,
String versionName, { String versionName, {
bool? advanced, bool? advanced,
@ -309,56 +309,54 @@ class LocalizationUIModel extends _$LocalizationUIModel {
return null; return null;
} }
VoidCallback? doRemoteInstall(BuildContext context, ScLocalizationData value, Future? doRemoteInstall(BuildContext context, ScLocalizationData value,
{bool isEnableCommunityInputMethod = false}) { {bool isEnableCommunityInputMethod = false}) async {
return () async { AnalyticsApi.touch("install_localization");
AnalyticsApi.touch("install_localization");
final savePath = final savePath =
File("${_downloadDir.absolute.path}\\${value.versionName}.sclang"); File("${_downloadDir.absolute.path}\\${value.versionName}.sclang");
try { try {
state = state.copyWith(workingVersion: value.versionName!); state = state.copyWith(workingVersion: value.versionName!);
if (!await savePath.exists()) { if (!await savePath.exists()) {
// download // download
await downloadLocalizationFile(savePath, value); await downloadLocalizationFile(savePath, value);
} else { } else {
dPrint("use cache $savePath"); dPrint("use cache $savePath");
}
final communityInputMethodData = state.communityInputMethodLanguageData;
String? communityInputMethodSupportData;
if (isEnableCommunityInputMethod && communityInputMethodData != null) {
final str = await downloadOrGetCachedCommunityInputMethodSupportFile(
communityInputMethodData);
if (str.trim().isNotEmpty) {
communityInputMethodSupportData = str;
}
}
await Future.delayed(const Duration(milliseconds: 300));
// check file
final globalIni = await compute(readArchive, savePath.absolute.path);
if (globalIni.isEmpty) {
throw S.current.localization_info_corrupted_file;
}
await installFormString(
globalIni,
value.versionName ?? "",
communityInputMethodSupportData: communityInputMethodSupportData,
communityInputMethodVersion: isEnableCommunityInputMethod
? communityInputMethodData?.version
: null,
);
} catch (e) {
if (!context.mounted) return;
await showToast(
context, S.current.localization_info_installation_error(e));
if (await savePath.exists()) await savePath.delete();
} }
state = state.copyWith(workingVersion: "");
}; final communityInputMethodData = state.communityInputMethodLanguageData;
String? communityInputMethodSupportData;
if (isEnableCommunityInputMethod && communityInputMethodData != null) {
final str = await downloadOrGetCachedCommunityInputMethodSupportFile(
communityInputMethodData);
if (str.trim().isNotEmpty) {
communityInputMethodSupportData = str;
}
}
await Future.delayed(const Duration(milliseconds: 300));
// check file
final globalIni = await compute(readArchive, savePath.absolute.path);
if (globalIni.isEmpty) {
throw S.current.localization_info_corrupted_file;
}
await installFormString(
globalIni,
value.versionName ?? "",
communityInputMethodSupportData: communityInputMethodSupportData,
communityInputMethodVersion: isEnableCommunityInputMethod
? communityInputMethodData?.version
: null,
);
} catch (e) {
if (!context.mounted) return;
await showToast(
context, S.current.localization_info_installation_error(e));
if (await savePath.exists()) await savePath.delete();
}
state = state.copyWith(workingVersion: "");
} }
Future<String> downloadOrGetCachedCommunityInputMethodSupportFile( Future<String> downloadOrGetCachedCommunityInputMethodSupportFile(
@ -566,4 +564,109 @@ class LocalizationUIModel extends _$LocalizationUIModel {
Future<void> onChangeGameInstallPath(String value) async { Future<void> onChangeGameInstallPath(String value) async {
await _loadData(); await _loadData();
} }
Future<void> onRemoteInsTall(
BuildContext context,
MapEntry<String, ScLocalizationData> item,
LocalizationUIState state) async {
bool enableCommunityInputMethod =
state.communityInputMethodLanguageData != null;
final userOK = await showConfirmDialogs(
context,
"${item.value.info}",
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.current.localization_info_version_number(
item.value.versionName ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current
.localization_info_channel(item.value.gameChannel ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current
.localization_info_update_time(item.value.updateAt ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 12),
],
),
const SizedBox(height: 12),
Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).cardColor,
borderRadius: BorderRadius.circular(7)),
padding: const EdgeInsets.all(12),
child: Row(
children: [
Expanded(
child: Text(
item.value.note ?? S.current.home_localization_msg_no_note,
style: const TextStyle(fontSize: 15),
),
),
],
),
),
SizedBox(height: 12),
Row(
children: [
Text(
"安装社区输入法支持",
),
Spacer(),
StatefulBuilder(
builder: (BuildContext context,
void Function(void Function()) setState) {
return ToggleSwitch(
checked: enableCommunityInputMethod,
onChanged: state.communityInputMethodLanguageData == null
? null
: (v) {
enableCommunityInputMethod = v;
setState(() {});
},
);
},
)
],
)
],
),
confirm: S.current.localization_action_install,
cancel: S.current.home_action_cancel,
constraints:
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .45),
);
if (userOK) {
if (!context.mounted) return;
dPrint("doRemoteInstall ${item.value} $enableCommunityInputMethod");
await doRemoteInstall(context, item.value,
isEnableCommunityInputMethod: enableCommunityInputMethod);
}
}
Future<void> checkReinstall(BuildContext context) async {
final installedVersion = state.patchStatus?.value;
if (installedVersion == null) return;
final curData = state.apiLocalizationData;
if (curData == null) return;
if (curData.keys.contains(installedVersion)) {
final data = curData[installedVersion];
if (data != null) {
await onRemoteInsTall(context, MapEntry(installedVersion, data), state);
}
}
}
} }