From 43d0d8454ce193ab0e08a3652c5cab27be95645a Mon Sep 17 00:00:00 2001
From: xkeyC <3334969096@qq.com>
Date: Fri, 20 Dec 2024 19:17:30 +0800
Subject: [PATCH] feat: networkGameChannels Support

---
 lib/app.dart                                  |  4 ++-
 lib/common/conf/conf.dart                     | 28 +++++++++++++++++++
 lib/common/conf/const_conf.dart               | 10 -------
 lib/common/helper/log_helper.dart             |  4 +--
 lib/common/io/doh_client.dart                 |  2 +-
 lib/common/io/rs_http.dart                    |  2 +-
 lib/data/app_version_data.dart                |  3 ++
 lib/ui/about/about_ui.dart                    |  2 +-
 lib/ui/guide/guide_ui.dart                    |  2 +-
 lib/ui/home/home_ui_model.dart                |  2 +-
 lib/ui/home/input_method/server.dart          |  2 +-
 .../localization/localization_ui_model.dart   |  4 +--
 lib/ui/index_ui.dart                          |  2 +-
 lib/ui/settings/settings_ui_model.dart        |  2 +-
 lib/ui/settings/upgrade_dialog.dart           |  2 +-
 lib/ui/splash_ui.dart                         |  2 +-
 lib/ui/tools/tools_ui_model.dart              |  4 +--
 17 files changed, 50 insertions(+), 27 deletions(-)
 create mode 100644 lib/common/conf/conf.dart
 delete mode 100644 lib/common/conf/const_conf.dart

diff --git a/lib/app.dart b/lib/app.dart
index 5cd2b8b..9551c39 100644
--- a/lib/app.dart
+++ b/lib/app.dart
@@ -10,7 +10,7 @@ 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/conf/conf.dart';
 import 'package:starcitizen_doctor/common/utils/log.dart';
 import 'package:starcitizen_doctor/ui/guide/guide_ui.dart';
 import 'package:starcitizen_doctor/ui/home/performance/performance_ui.dart';
@@ -214,6 +214,8 @@ class AppGlobalModel extends _$AppGlobalModel {
 
     try {
       final networkVersionData = await Api.getAppVersion();
+      dPrint("networkVersionData == ${networkVersionData.toJson()}");
+      AppConf.setNetworkChannels(networkVersionData.gameChannels);
       checkActivityThemeColor(networkVersionData);
       if (ConstConf.isMSE) {
         dPrint(
diff --git a/lib/common/conf/conf.dart b/lib/common/conf/conf.dart
new file mode 100644
index 0000000..3962917
--- /dev/null
+++ b/lib/common/conf/conf.dart
@@ -0,0 +1,28 @@
+class ConstConf {
+  static const String appVersion = "2.13.3";
+  static const int appVersionCode = 61;
+  static const String appVersionDate = "2024-11-23";
+  static const _gameChannels = [
+    "LIVE",
+    "4.0_PREVIEW",
+    "PTU",
+    "EPTU",
+    "TECH-PREVIEW",
+    "HOTFIX"
+  ];
+  static const isMSE =
+      String.fromEnvironment("MSE", defaultValue: "false") == "true";
+  static const dohAddress = "https://223.6.6.6/resolve";
+  static const inputMethodServerPort = 59399;
+}
+
+class AppConf {
+  static List<String>? _networkGameChannels;
+
+  static setNetworkChannels(List<String>? channels) {
+    _networkGameChannels = channels;
+  }
+
+  static List<String> get gameChannels =>
+      _networkGameChannels ?? ConstConf._gameChannels;
+}
diff --git a/lib/common/conf/const_conf.dart b/lib/common/conf/const_conf.dart
deleted file mode 100644
index f77bb9a..0000000
--- a/lib/common/conf/const_conf.dart
+++ /dev/null
@@ -1,10 +0,0 @@
-class ConstConf {
-  static const String appVersion = "2.13.3";
-  static const int appVersionCode = 61;
-  static const String appVersionDate = "2024-11-23";
-  static const gameChannels = ["LIVE", "4.0_PREVIEW","PTU", "EPTU", "TECH-PREVIEW", "HOTFIX"];
-  static const isMSE =
-      String.fromEnvironment("MSE", defaultValue: "false") == "true";
-  static const dohAddress = "https://223.6.6.6/resolve";
-  static const inputMethodServerPort = 59399;
-}
diff --git a/lib/common/helper/log_helper.dart b/lib/common/helper/log_helper.dart
index 977498d..a2ecfa6 100644
--- a/lib/common/helper/log_helper.dart
+++ b/lib/common/helper/log_helper.dart
@@ -2,7 +2,7 @@ import 'dart:convert';
 import 'dart:io';
 
 import 'package:hive/hive.dart';
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/conf.dart';
 import 'package:starcitizen_doctor/common/utils/log.dart';
 
 class SCLoggerHelper {
@@ -108,7 +108,7 @@ class SCLoggerHelper {
   }
 
   static String getGameChannelID(String installPath) {
-    for (var value in ConstConf.gameChannels) {
+    for (var value in AppConf.gameChannels) {
       if (installPath.endsWith("\\$value")) {
         return value;
       }
diff --git a/lib/common/io/doh_client.dart b/lib/common/io/doh_client.dart
index 9c6a28c..9849066 100644
--- a/lib/common/io/doh_client.dart
+++ b/lib/common/io/doh_client.dart
@@ -1,6 +1,6 @@
 import 'dart:convert';
 
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/conf.dart';
 import 'package:starcitizen_doctor/common/io/rs_http.dart';
 import 'package:starcitizen_doctor/common/utils/log.dart';
 import 'package:starcitizen_doctor/data/doh_client_response_data.dart';
diff --git a/lib/common/io/rs_http.dart b/lib/common/io/rs_http.dart
index 5f7a5ab..558a5f6 100644
--- a/lib/common/io/rs_http.dart
+++ b/lib/common/io/rs_http.dart
@@ -1,7 +1,7 @@
 import 'dart:convert';
 import 'dart:typed_data';
 
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/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';
 import 'package:starcitizen_doctor/common/rust/http_package.dart';
diff --git a/lib/data/app_version_data.dart b/lib/data/app_version_data.dart
index c52bdf7..07ad647 100644
--- a/lib/data/app_version_data.dart
+++ b/lib/data/app_version_data.dart
@@ -30,6 +30,7 @@ class AppVersionData {
     activityColors = json['activityColors'] != null
         ? ActivityColors.fromJson(json['activityColors'])
         : null;
+    gameChannels = List.from(json["game_channels"]).cast<String>();
     webMirrors = json["web_mirrors"];
   }
 
@@ -41,6 +42,7 @@ class AppVersionData {
   num? mSEMinVersionCode;
   String? p4kDownloadUrl;
   ActivityColors? activityColors;
+  List<String>? gameChannels;
   Map? webMirrors;
 
   Map<String, dynamic> toJson() {
@@ -56,6 +58,7 @@ class AppVersionData {
       map['activityColors'] = activityColors?.toJson();
     }
     map["web_mirrors"] = webMirrors;
+    map["game_channels"] = gameChannels;
     return map;
   }
 }
diff --git a/lib/ui/about/about_ui.dart b/lib/ui/about/about_ui.dart
index ad5a4e0..c66cce1 100644
--- a/lib/ui/about/about_ui.dart
+++ b/lib/ui/about/about_ui.dart
@@ -4,7 +4,7 @@ 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/app.dart';
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/conf.dart';
 import 'package:starcitizen_doctor/common/conf/url_conf.dart';
 import 'package:starcitizen_doctor/widgets/src/flow_number_text.dart';
 import 'package:starcitizen_doctor/widgets/widgets.dart';
diff --git a/lib/ui/guide/guide_ui.dart b/lib/ui/guide/guide_ui.dart
index 2bc2bcd..5129abd 100644
--- a/lib/ui/guide/guide_ui.dart
+++ b/lib/ui/guide/guide_ui.dart
@@ -3,7 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
 import 'package:go_router/go_router.dart';
 import 'package:hive/hive.dart';
 import 'package:hooks_riverpod/hooks_riverpod.dart';
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/conf.dart';
 import 'package:starcitizen_doctor/common/conf/url_conf.dart';
 import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
 import 'package:starcitizen_doctor/ui/tools/tools_ui_model.dart';
diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart
index 98259fc..4f21e1b 100644
--- a/lib/ui/home/home_ui_model.dart
+++ b/lib/ui/home/home_ui_model.dart
@@ -11,7 +11,7 @@ import 'package:riverpod_annotation/riverpod_annotation.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/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/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';
diff --git a/lib/ui/home/input_method/server.dart b/lib/ui/home/input_method/server.dart
index f157039..aa71d7f 100644
--- a/lib/ui/home/input_method/server.dart
+++ b/lib/ui/home/input_method/server.dart
@@ -8,7 +8,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
 import 'package:riverpod_annotation/riverpod_annotation.dart';
 import 'package:shelf/shelf.dart';
 import 'package:shelf/shelf_io.dart' as shelf_io;
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/conf.dart';
 import 'package:starcitizen_doctor/common/utils/log.dart';
 import 'package:starcitizen_doctor/ui/home/input_method/server_qr_dialog_ui.dart';
 import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart';
diff --git a/lib/ui/home/localization/localization_ui_model.dart b/lib/ui/home/localization/localization_ui_model.dart
index 28cfd5d..ee1c948 100644
--- a/lib/ui/home/localization/localization_ui_model.dart
+++ b/lib/ui/home/localization/localization_ui_model.dart
@@ -11,7 +11,7 @@ import 'package:hive/hive.dart';
 import 'package:riverpod_annotation/riverpod_annotation.dart';
 import 'package:starcitizen_doctor/api/analytics.dart';
 import 'package:starcitizen_doctor/api/api.dart';
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/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';
@@ -578,7 +578,7 @@ class LocalizationUIModel extends _$LocalizationUIModel {
             dPrint("check Localization update $scInstallPath");
             if (!(curData?.keys.contains(installedVersion) ?? false)) {
               // has update
-              for (var channel in ConstConf.gameChannels) {
+              for (var channel in AppConf.gameChannels) {
                 if (scInstallPath.contains(channel)) {
                   dPrint("check Localization update: has update -> $channel");
                   updates.add(channel);
diff --git a/lib/ui/index_ui.dart b/lib/ui/index_ui.dart
index ef033c4..db1eae5 100644
--- a/lib/ui/index_ui.dart
+++ b/lib/ui/index_ui.dart
@@ -3,7 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
 import 'package:go_router/go_router.dart';
 import 'package:hooks_riverpod/hooks_riverpod.dart';
 import 'package:starcitizen_doctor/app.dart';
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/conf.dart';
 import 'package:starcitizen_doctor/provider/aria2c.dart';
 import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
 import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
diff --git a/lib/ui/settings/settings_ui_model.dart b/lib/ui/settings/settings_ui_model.dart
index a5d1861..8970932 100644
--- a/lib/ui/settings/settings_ui_model.dart
+++ b/lib/ui/settings/settings_ui_model.dart
@@ -7,7 +7,7 @@ import 'package:flutter/services.dart';
 import 'package:freezed_annotation/freezed_annotation.dart';
 import 'package:hive/hive.dart';
 import 'package:riverpod_annotation/riverpod_annotation.dart';
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/conf.dart';
 import 'package:starcitizen_doctor/common/helper/system_helper.dart';
 import 'package:starcitizen_doctor/common/utils/log.dart';
 import 'package:starcitizen_doctor/common/utils/provider.dart';
diff --git a/lib/ui/settings/upgrade_dialog.dart b/lib/ui/settings/upgrade_dialog.dart
index 5d5f33a..3c7f376 100644
--- a/lib/ui/settings/upgrade_dialog.dart
+++ b/lib/ui/settings/upgrade_dialog.dart
@@ -8,7 +8,7 @@ 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/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/log.dart';
diff --git a/lib/ui/splash_ui.dart b/lib/ui/splash_ui.dart
index c669f2b..c483b2a 100644
--- a/lib/ui/splash_ui.dart
+++ b/lib/ui/splash_ui.dart
@@ -8,7 +8,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
 import 'package:markdown_widget/widget/markdown.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/conf.dart';
 import 'package:starcitizen_doctor/common/conf/url_conf.dart';
 import 'package:starcitizen_doctor/common/utils/log.dart';
 import 'package:starcitizen_doctor/provider/aria2c.dart';
diff --git a/lib/ui/tools/tools_ui_model.dart b/lib/ui/tools/tools_ui_model.dart
index 0ee012b..7a3a760 100644
--- a/lib/ui/tools/tools_ui_model.dart
+++ b/lib/ui/tools/tools_ui_model.dart
@@ -11,7 +11,7 @@ import 'package:go_router/go_router.dart';
 import 'package:riverpod_annotation/riverpod_annotation.dart';
 import 'package:starcitizen_doctor/api/analytics.dart';
 import 'package:starcitizen_doctor/api/api.dart';
-import 'package:starcitizen_doctor/common/conf/const_conf.dart';
+import 'package:starcitizen_doctor/common/conf/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';
@@ -268,7 +268,7 @@ class ToolsUIModel extends _$ToolsUIModel {
         return;
       }
       scInstallPaths = await SCLoggerHelper.getGameInstallPath(listData,
-          checkExists: checkActive, withVersion: ConstConf.gameChannels);
+          checkExists: checkActive, withVersion: AppConf.gameChannels);
       if (scInstallPaths.isNotEmpty) {
         scInstalledPath = scInstallPaths.first;
       }