From 348704c66935cebd92c5834dcd772d5bbe42a8be Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Tue, 7 May 2024 21:08:16 +0800 Subject: [PATCH] feat: AnalyticsApi update --- lib/api/analytics.dart | 5 +++- lib/provider/unp4kc.dart | 12 ++++++++++ lib/ui/home/game_doctor/game_doctor_ui.dart | 2 ++ .../advanced_localization_ui.dart | 6 +++++ .../advanced_localization_ui_model.dart | 11 ++++++++- .../dialogs/hosts_booster_dialog_ui.dart | 23 +++++++++++++------ .../rsi_launcher_enhance_dialog_ui.dart | 3 +++ lib/ui/tools/unp4kc/unp4kc_ui.dart | 10 +++++++- lib/ui/webview/webview.dart | 2 ++ 9 files changed, 64 insertions(+), 10 deletions(-) diff --git a/lib/api/analytics.dart b/lib/api/analytics.dart index 11a1b4e..f6be2d1 100644 --- a/lib/api/analytics.dart +++ b/lib/api/analytics.dart @@ -7,7 +7,10 @@ import 'package:starcitizen_doctor/common/utils/log.dart'; class AnalyticsApi { static touch(String key) async { - if (kDebugMode || kProfileMode) return; + if (kDebugMode || kProfileMode) { + dPrint("AnalyticsApi.touch === $key skip"); + return; + } dPrint("AnalyticsApi.touch === $key start"); try { final r = await RSHttp.postData( diff --git a/lib/provider/unp4kc.dart b/lib/provider/unp4kc.dart index d3c4767..ef0c270 100644 --- a/lib/provider/unp4kc.dart +++ b/lib/provider/unp4kc.dart @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:path_provider/path_provider.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/common/conf/binary_conf.dart'; import 'package:starcitizen_doctor/common/helper/log_helper.dart'; import 'package:starcitizen_doctor/common/rust/api/rs_process.dart'; @@ -51,6 +52,8 @@ class Unp4kCModel extends _$Unp4kCModel { String getGamePath() => _toolsState.scInstalledPath; + bool _hasUnp4kRunTimeError = false; + void _init() async { final execDir = "${appGlobalState.applicationBinaryModuleDir}\\unp4kc"; await BinaryModuleConf.extractModule( @@ -79,6 +82,15 @@ class Unp4kCModel extends _$Unp4kCModel { state = state.copyWith( errorMessage: "${state.errorMessage}\n${event.data}"); } + if (!_hasUnp4kRunTimeError) { + if (state.errorMessage.contains( + "You must install .NET to run this application") || + state.errorMessage.contains( + "You must install or update .NET to run this application")) { + _hasUnp4kRunTimeError = true; + AnalyticsApi.touch("unp4k_no_runtime"); + } + } break; case RsProcessStreamDataType.exit: dPrint("[unp4kc] exit: ${event.data}"); diff --git a/lib/ui/home/game_doctor/game_doctor_ui.dart b/lib/ui/home/game_doctor/game_doctor_ui.dart index 906899d..84017be 100644 --- a/lib/ui/home/game_doctor/game_doctor_ui.dart +++ b/lib/ui/home/game_doctor/game_doctor_ui.dart @@ -3,6 +3,7 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/common/helper/log_helper.dart'; import 'package:starcitizen_doctor/common/helper/system_helper.dart'; import 'package:starcitizen_doctor/common/utils/log.dart'; @@ -22,6 +23,7 @@ class HomeGameDoctorUI extends HookConsumerWidget { final model = ref.read(homeGameDoctorUIModelProvider.notifier); useEffect(() { + AnalyticsApi.touch("auto_scan_issues"); SchedulerBinding.instance.addPostFrameCallback((timeStamp) { dPrint("HomeGameDoctorUI useEffect doCheck timeStamp === $timeStamp"); model.doCheck(context); diff --git a/lib/ui/home/localization/advanced_localization_ui.dart b/lib/ui/home/localization/advanced_localization_ui.dart index b827820..1ab010e 100644 --- a/lib/ui/home/localization/advanced_localization_ui.dart +++ b/lib/ui/home/localization/advanced_localization_ui.dart @@ -6,6 +6,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:re_editor/re_editor.dart'; import 'package:re_highlight/languages/ini.dart'; import 'package:re_highlight/styles/vs2015.dart'; +import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/data/app_advanced_localization_data.dart'; import 'package:starcitizen_doctor/ui/home/home_ui_model.dart'; import 'package:starcitizen_doctor/ui/home/localization/advanced_localization_ui_model.dart'; @@ -34,6 +35,11 @@ class AdvancedLocalizationUI extends HookConsumerWidget { } } + useEffect(() { + AnalyticsApi.touch("advanced_localization_launch"); + return null; + }, const []); + return makeDefaultPage( title: S.current.home_localization_advanced_title( homeUIState.scInstalledPath ?? "-"), diff --git a/lib/ui/home/localization/advanced_localization_ui_model.dart b/lib/ui/home/localization/advanced_localization_ui_model.dart index 4f1227e..a1679c6 100644 --- a/lib/ui/home/localization/advanced_localization_ui_model.dart +++ b/lib/ui/home/localization/advanced_localization_ui_model.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/common/utils/log.dart'; import 'package:starcitizen_doctor/common/utils/provider.dart'; import 'package:starcitizen_doctor/data/app_advanced_localization_data.dart'; @@ -233,8 +234,15 @@ class AdvancedLocalizationUIModel extends _$AdvancedLocalizationUIModel { final iniData = String.fromCharCodes(data); return iniData; } catch (e) { + final errorMessage = e.toString(); + if (errorMessage + .contains("You must install .NET to run this application") || + errorMessage.contains( + "You must install or update .NET to run this application")) { + AnalyticsApi.touch("advanced_localization_no_runtime"); + } state = state.copyWith( - errorMessage: e.toString(), + errorMessage: errorMessage, ); // rethrow; } @@ -281,6 +289,7 @@ class AdvancedLocalizationUIModel extends _$AdvancedLocalizationUIModel { } Future doInstall() async { + AnalyticsApi.touch("advanced_localization_apply"); state = state.copyWith( workingText: S.current.home_localization_advanced_msg_gen_localization_text); diff --git a/lib/ui/tools/dialogs/hosts_booster_dialog_ui.dart b/lib/ui/tools/dialogs/hosts_booster_dialog_ui.dart index 8a70e54..ead1d40 100644 --- a/lib/ui/tools/dialogs/hosts_booster_dialog_ui.dart +++ b/lib/ui/tools/dialogs/hosts_booster_dialog_ui.dart @@ -4,6 +4,7 @@ import 'package:fluent_ui/fluent_ui.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/common/helper/system_helper.dart'; import 'package:starcitizen_doctor/common/io/rs_http.dart'; import 'package:starcitizen_doctor/common/utils/async.dart'; @@ -14,9 +15,15 @@ class HostsBoosterDialogUI extends HookConsumerWidget { static final _hostsMap = { "Recaptcha": ["www.recaptcha.net", "recaptcha.net"], - S.current.tools_hosts_info_rsi_official_website: ["robertsspaceindustries.com"], - S.current.tools_hosts_info_rsi_zendesk: ["cloudimperiumservicesllc.zendesk.com"], - S.current.tools_hosts_info_rsi_customer_service: ["support.robertsspaceindustries.com"], + S.current.tools_hosts_info_rsi_official_website: [ + "robertsspaceindustries.com" + ], + S.current.tools_hosts_info_rsi_zendesk: [ + "cloudimperiumservicesllc.zendesk.com" + ], + S.current.tools_hosts_info_rsi_customer_service: [ + "support.robertsspaceindustries.com" + ], }; @override @@ -48,6 +55,7 @@ class HostsBoosterDialogUI extends HookConsumerWidget { } useEffect(() { + AnalyticsApi.touch("host_dns_boost"); // 监听 Hosts 文件变更 _readHostsState(workingMap, checkedMap); return null; @@ -164,9 +172,10 @@ class HostsBoosterDialogUI extends HookConsumerWidget { child: FilledButton( onPressed: () => doHost(context), child: Padding( - padding: - const EdgeInsets.only(top: 3, bottom: 3, left: 12, right: 12), - child: Text(S.current.tools_hosts_action_one_click_acceleration), + padding: const EdgeInsets.only( + top: 3, bottom: 3, left: 12, right: 12), + child: Text( + S.current.tools_hosts_action_one_click_acceleration), ), ), ), @@ -287,4 +296,4 @@ class HostsBoosterDialogUI extends HookConsumerWidget { } } } -} \ No newline at end of file +} diff --git a/lib/ui/tools/dialogs/rsi_launcher_enhance_dialog_ui.dart b/lib/ui/tools/dialogs/rsi_launcher_enhance_dialog_ui.dart index 6f98ea7..2719e10 100644 --- a/lib/ui/tools/dialogs/rsi_launcher_enhance_dialog_ui.dart +++ b/lib/ui/tools/dialogs/rsi_launcher_enhance_dialog_ui.dart @@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:freezed_annotation/freezed_annotation.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/url_conf.dart'; import 'package:starcitizen_doctor/common/helper/system_helper.dart'; @@ -81,10 +82,12 @@ class RsiLauncherEnhanceDialogUI extends HookConsumerWidget { await assarState.value?.data .writeMainJs(content: utf8.encode(newScript)) .unwrap(context: context); + AnalyticsApi.touch("rsi_launcher_mod_apply"); await readState(); } useEffect(() { + AnalyticsApi.touch("rsi_launcher_mod_launch"); readState(); return null; }, const []); diff --git a/lib/ui/tools/unp4kc/unp4kc_ui.dart b/lib/ui/tools/unp4kc/unp4kc_ui.dart index bb4923d..3769382 100644 --- a/lib/ui/tools/unp4kc/unp4kc_ui.dart +++ b/lib/ui/tools/unp4kc/unp4kc_ui.dart @@ -5,6 +5,7 @@ import 'package:fluent_ui/fluent_ui.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:re_editor/re_editor.dart'; +import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/common/helper/system_helper.dart'; import 'package:starcitizen_doctor/data/app_unp4k_p4k_item_data.dart'; import 'package:starcitizen_doctor/provider/unp4kc.dart'; @@ -21,6 +22,12 @@ class UnP4kcUI extends HookConsumerWidget { final model = ref.read(unp4kCModelProvider.notifier); final files = model.getFiles(); final paths = state.curPath.trim().split("\\"); + + useEffect(() { + AnalyticsApi.touch("unp4k_launch"); + return null; + }, const []); + return makeDefaultPage(context, title: S.current.tools_unp4k_title(model.getGamePath()), useBodyContainer: false, @@ -308,7 +315,8 @@ class UnP4kErrorWidget extends StatelessWidget { const SizedBox(height: 16), FilledButton( child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3), + padding: + const EdgeInsets.symmetric(horizontal: 12, vertical: 3), child: Text( S.current.tools_unp4k_missing_runtime_action_install), ), diff --git a/lib/ui/webview/webview.dart b/lib/ui/webview/webview.dart index 977fd2c..bc3fb8a 100644 --- a/lib/ui/webview/webview.dart +++ b/lib/ui/webview/webview.dart @@ -7,6 +7,7 @@ import 'package:desktop_webview_window/desktop_webview_window.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:hive/hive.dart'; +import 'package:starcitizen_doctor/api/analytics.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/base_utils.dart'; @@ -206,6 +207,7 @@ class WebViewModel { for (var kv in appVersionData.webMirrors!.entries) { if (url.startsWith(kv.key)) { finalUrl = url.replaceFirst(kv.key, kv.value); + AnalyticsApi.touch("webLocalization_with_boost_mirror"); } } }