GeezerVison is showing github.com — perf(UI): :zap: 优化启动速度,UI 界面卡顿, Optimize the startup speed, UI inter… · CKNetCapture/appproxy@ce882f4
File treeExpand file treeCollapse file tree Open diff view settings android/app/src/main/kotlin/cn/ys1231/appproxy
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: android/app/src/main/kotlin/cn/ys1231/appproxy/MainActivity.kt +17-5Lines changed: 17 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,18 +30,17 @@ class MainActivity : FlutterActivity() { | 30 | 30 | private val CHANNEL_VPN = "cn.ys1231/appproxy/vpn" | 31 | 31 | private val CHANNEL_APP_UPDATE = "cn.ys1231/appproxy/appupdate" | 32 | 32 | private var FLUTTER_VPN_CHANNEL: MethodChannel? = null | | 33 | + private var FLUTTER_CHANNEL: MethodChannel? = null | 33 | 34 |
| 34 | 35 | private var utils: Utils? = null | 35 | 36 | private var intentVpnService: Intent? = null | 36 | 37 | private var iyueVpnService: IyueVPNService? = null | 37 | 38 | private var isBind: Boolean = false | 38 | 39 | private var currentProxy: Map<String, Any>? = null | 39 | | - | 40 | 40 | private var conn: ServiceConnection? = null | 41 | 41 |
| 42 | 42 | override fun onCreate(savedInstanceState: Bundle?) { | 43 | 43 | super.onCreate(savedInstanceState) | 44 | | - utils = Utils(this) | 45 | 44 | intentVpnService = Intent(this, IyueVPNService::class.java) | 46 | 45 | conn = object : ServiceConnection { | 47 | 46 | override fun onServiceConnected(name: ComponentName?, service: IBinder?) { | @@ -99,15 +98,17 @@ class MainActivity : FlutterActivity() { | 99 | 98 |
| 100 | 99 | override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | 101 | 100 | super.configureFlutterEngine(flutterEngine) | | 101 | + utils = Utils(this) | 102 | 102 |
| 103 | | - MethodChannel( | | 103 | + FLUTTER_CHANNEL = MethodChannel( | 104 | 104 | flutterEngine.dartExecutor.binaryMessenger, | 105 | 105 | CHANNEL | 106 | | - ).setMethodCallHandler { call, result -> | | 106 | + ) | | 107 | + FLUTTER_CHANNEL!!.setMethodCallHandler { call, result -> | 107 | 108 | if (call.method == "getAppList") { | 108 | 109 | try { | 109 | 110 | Log.d(TAG, "configureFlutterEngine ${call.method} ") | 110 | | - val appList = Utils(this).getAppList() | | 111 | + val appList = utils!!.getAppList() | 111 | 112 | result.success(appList) | 112 | 113 | } catch (e: Exception) { | 113 | 114 | result.error("-1", e.message, null) | @@ -156,6 +157,17 @@ class MainActivity : FlutterActivity() { | 156 | 157 | } | 157 | 158 | } | 158 | 159 | } | | 160 | + | | 161 | + // 遍历所有 app 通知刷新 | | 162 | + Thread { | | 163 | + Log.d(TAG, "configureFlutterEngine: start get app list info") | | 164 | + utils!!.initAppList() | | 165 | + runOnUiThread { | | 166 | + Log.d(TAG, "configureFlutterEngine: call onRefresh") | | 167 | + FLUTTER_CHANNEL!!.invokeMethod("onRefresh", null) | | 168 | + Log.d(TAG, "configureFlutterEngine: end get app list info") | | 169 | + } | | 170 | + }.start() | 159 | 171 | } | 160 | 172 |
| 161 | 173 | private val VPN_REQUEST_CODE = 100 | |
Collapse file Copy file name to clipboardExpand all lines: android/app/src/main/kotlin/cn/ys1231/appproxy/data/Utils.kt +18-20Lines changed: 18 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,10 @@ import java.io.ByteArrayOutputStream | 16 | 16 |
| 17 | 17 | class Utils(private val context: Context) { | 18 | 18 | private val TAG = "iyue->${this.javaClass.simpleName} " | 19 | | -// val sharedPreferences = context.getSharedPreferences("vpnconfig", Context.MODE_PRIVATE) | | 19 | + | | 20 | + //val sharedPreferences = context.getSharedPreferences("vpnconfig", Context.MODE_PRIVATE) | | 21 | + private var appList: String? = null | | 22 | + private var isFirstGetApps: Boolean = true | 20 | 23 |
| 21 | 24 | init { | 22 | 25 | Log.d(TAG, "Utils init !") | @@ -30,8 +33,8 @@ class Utils(private val context: Context) { | 30 | 33 | * | 31 | 34 | * @return 返回包含已安装应用信息的JSON字符串,如果无应用满足条件或发生错误,则返回null。 | 32 | 35 | */ | 33 | | - fun getAppList(): String? { | 34 | | - | | 36 | + fun initAppList() { | | 37 | + Log.d(TAG, "initAppList: start") | 35 | 38 | // 通过上下文获取PackageManager对象,用于管理安装的应用程序 | 36 | 39 | val pm = context.packageManager | 37 | 40 |
| @@ -78,7 +81,18 @@ class Utils(private val context: Context) { | 78 | 81 | } | 79 | 82 |
| 80 | 83 | // 使用Gson将应用信息列表转换为JSON字符串并返回 | 81 | | - return Gson().toJson(appInfoList) | | 84 | + appList = Gson().toJson(appInfoList) | | 85 | + Log.d(TAG, "initAppList: end") | | 86 | + } | | 87 | + | | 88 | + fun getAppList(): String? { | | 89 | + if (isFirstGetApps && appList != null) { | | 90 | + isFirstGetApps = false | | 91 | + return appList | | 92 | + } else { | | 93 | + initAppList() | | 94 | + return appList | | 95 | + } | 82 | 96 | } | 83 | 97 |
| 84 | 98 | private val PackageInfo.isSystemApp: Boolean | @@ -96,20 +110,4 @@ class Utils(private val context: Context) { | 96 | 110 | return bitmap | 97 | 111 | } | 98 | 112 |
| 99 | | -// public fun setVpnStatus(status: Boolean){ | 100 | | -// var edit = sharedPreferences.edit() | 101 | | -// edit.putBoolean("vpnStatus", status) | 102 | | -// edit.commit() | 103 | | -// } | 104 | | -// public fun getVpnStatus(): Boolean{ | 105 | | -// return sharedPreferences.getBoolean("vpnStatus", false) | 106 | | -// } | 107 | | -// public fun setProxyName(name: String){ | 108 | | -// var edit = sharedPreferences.edit() | 109 | | -// edit.putString("proxyName", name) | 110 | | -// edit.commit() | 111 | | -// } | 112 | | -// public fun getProxyName(): String{ | 113 | | -// return sharedPreferences.getString("proxyName", "") ?: "" | 114 | | -// } | 115 | 113 | } |
Collapse file Copy file name to clipboard +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | | - "VersionName": "v0.0.8", | 3 | | - "ModifyContent": "\r\n1、perf(startup): ⚡ #12 Optimize startup speed.\r\n2、fix(update): :bug: 国内更新通道, Domestic update channel", | | 2 | + "VersionName": "v0.1.3", | | 3 | + "ModifyContent": "\n\rperf(UI): :zap: 优化启动速度,UI 界面卡顿, Optimize the startup speed, UI interface is stuck", | 4 | 4 | "DownloadUrl": "https://pfile.ys1231.cn/modules/appproxy/" | 5 | 5 | } |
Collapse file Copy file name to clipboardExpand all lines: lib/main.dart +1-21Lines changed: 1 addition & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,27 +85,7 @@ class _iyueMainPageState extends State<iyueMainPage> { | 85 | 85 | // 首页Widget | 86 | 86 | const ProxyListHome(), | 87 | 87 | // app配置列表 | 88 | | - FutureBuilder( | 89 | | - // 先启动后加载 | 90 | | - future: Future.delayed(const Duration(milliseconds: 100)), | 91 | | - builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) { | 92 | | - // 当计算状态为等待时,显示加载动画 | 93 | | - if (snapshot.connectionState == ConnectionState.waiting) { | 94 | | - return const Center( | 95 | | - // 显示一个加载动画 | 96 | | - child: CircularProgressIndicator(), | 97 | | - ); | 98 | | - } else if (snapshot.hasError) { | 99 | | - // 当 future 出现错误时,显示错误信息 | 100 | | - return Center( | 101 | | - child: Text('Error: ${snapshot.error}'), | 102 | | - ); | 103 | | - } else { | 104 | | - // 当计算完成时,显示app配置列表 | 105 | | - return const AppConfigList(); | 106 | | - } | 107 | | - }), | 108 | | - // const AppConfigList(), | | 88 | + const AppConfigList(), | 109 | 89 | // 设置页面 | 110 | 90 | const AppSettings(), // 设置页Widget | 111 | 91 | ]; | |
Collapse file Copy file name to clipboardExpand all lines: lib/ui/app_config_list.dart +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,6 +112,9 @@ class AppConfigState extends State<AppConfigList> { | 112 | 112 | // app列表配置文件 | 113 | 113 | final AppProxyConfigData _appfile = AppProxyConfigData("proxyconfig.json"); | 114 | 114 |
| | 115 | + // 远程调用通道 | | 116 | + final platform = const MethodChannel('cn.ys1231/appproxy'); | | 117 | + | 115 | 118 | // 用于更新调用子控件列表项选择状态 | 116 | 119 | List<GlobalKey<CardCheckboxState>> _cardKeys = []; | 117 | 120 |
| @@ -120,7 +123,12 @@ class AppConfigState extends State<AppConfigList> { | 120 | 123 | super.initState(); | 121 | 124 | debugPrint("iyue-> initState"); | 122 | 125 | _initData(); | 123 | | - getAppList(); | | 126 | + platform.setMethodCallHandler((call) async { | | 127 | + if (call.method == 'onRefresh') { | | 128 | + // 执行Flutter逻辑 | | 129 | + getAppList(); | | 130 | + } | | 131 | + }); | 124 | 132 | } | 125 | 133 |
| 126 | 134 | // 初始化数据 | |
Collapse file Copy file name to clipboardExpand all lines: lib/ui/settings.dart +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,7 +116,7 @@ class _AppSettingsState extends State<AppSettings> { | 116 | 116 | children: [ | 117 | 117 | Text(S.of(context).text_describe), | 118 | 118 | Text(S.of(context).text_author), | 119 | | - Text('${S.of(context).text_update_time}:2024-11-18'), | | 119 | + Text('${S.of(context).text_update_time}:2024-11-23'), | 120 | 120 | Row( | 121 | 121 | children: [ | 122 | 122 | const Text('github:'), | |
|