Преглед изворни кода

[new]增加渠道信息记录

zk пре 1 година
родитељ
комит
41827606c7
2 измењених фајлова са 29 додато и 5 уклоњено
  1. 5 0
      lib/data/consts/constants.dart
  2. 24 5
      lib/main.dart

+ 5 - 0
lib/data/consts/constants.dart

@@ -42,6 +42,11 @@ class Constants {
   }
 
   static const String recordServerVersion = 'recordServerVersion';
+
+  //渠道
+  static const String appChanelName = "app_channel_name";
+  static const String appChannelId = "app_channel_id";
+  static const String appTgPlatformId = "app_tg_platform_id";
 }
 
 String getBaseUrl() {

+ 24 - 5
lib/main.dart

@@ -12,7 +12,6 @@ import 'package:electronic_assistant/utils/app_info_util.dart';
 import 'package:electronic_assistant/device/device_info_util.dart';
 import 'package:electronic_assistant/utils/desktop_shortcut_utils.dart';
 import 'package:electronic_assistant/utils/mmkv_util.dart';
-import 'package:electronic_assistant/utils/notification_util.dart';
 import 'package:electronic_assistant/utils/toast_util.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_foreground_task/flutter_foreground_task.dart';
@@ -57,10 +56,30 @@ void checkEnv() {
 
 initChannel() async {
   await AtmobChannelReader.default4Test(Constants.appDefaultChannel,
-      Constants.appDefaultTgPlatformId, Constants.appDefaultAppId);
-  atmobPlatformInfo.setChannelName(await AtmobChannelReader.getChannel());
-  atmobPlatformInfo.setTgPlatform(await AtmobChannelReader.getTgPlatformId());
-  atmobPlatformInfo.setAppId(await AtmobChannelReader.getAppId());
+      Constants.appDefaultAppId, Constants.appDefaultTgPlatformId);
+
+  String? channel = KVUtil.getString(
+      Constants.appChanelName, await AtmobChannelReader.getChannel());
+  KVUtil.putString(Constants.appChanelName, channel);
+
+  int? channelId = KVUtil.getInt(Constants.appChannelId, -1);
+  if (channelId == -1) {
+    channelId = await AtmobChannelReader.getAppId();
+  }
+  if (channelId != null) {
+    KVUtil.putInt(Constants.appChannelId, channelId);
+  }
+
+  int? appTgPlatformId = KVUtil.getInt(Constants.appTgPlatformId, -1);
+  if (appTgPlatformId == -1) {
+    appTgPlatformId = await AtmobChannelReader.getTgPlatformId();
+  }
+  if (appTgPlatformId != null) {
+    KVUtil.putInt(Constants.appTgPlatformId, appTgPlatformId);
+  }
+  atmobPlatformInfo.setChannelName(channel);
+  atmobPlatformInfo.setAppId(channelId);
+  atmobPlatformInfo.setTgPlatform(appTgPlatformId);
 }
 
 Future<void> initAfterGrant() async {