Skip to content

Commit

Permalink
perf(UI): ⚡ 优化启动速度,UI 界面卡顿, Optimize the startup speed, UI interface …
Browse files Browse the repository at this point in the history
…is stuck
  • Loading branch information
ys1231 committed Nov 23, 2024
1 parent 6ba8776 commit ce882f4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 50 deletions.
22 changes: 17 additions & 5 deletions android/app/src/main/kotlin/cn/ys1231/appproxy/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ class MainActivity : FlutterActivity() {
private val CHANNEL_VPN = "cn.ys1231/appproxy/vpn"
private val CHANNEL_APP_UPDATE = "cn.ys1231/appproxy/appupdate"
private var FLUTTER_VPN_CHANNEL: MethodChannel? = null
private var FLUTTER_CHANNEL: MethodChannel? = null

private var utils: Utils? = null
private var intentVpnService: Intent? = null
private var iyueVpnService: IyueVPNService? = null
private var isBind: Boolean = false
private var currentProxy: Map<String, Any>? = null

private var conn: ServiceConnection? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
utils = Utils(this)
intentVpnService = Intent(this, IyueVPNService::class.java)
conn = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
Expand Down Expand Up @@ -99,15 +98,17 @@ class MainActivity : FlutterActivity() {

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
utils = Utils(this)

MethodChannel(
FLUTTER_CHANNEL = MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
CHANNEL
).setMethodCallHandler { call, result ->
)
FLUTTER_CHANNEL!!.setMethodCallHandler { call, result ->
if (call.method == "getAppList") {
try {
Log.d(TAG, "configureFlutterEngine ${call.method} ")
val appList = Utils(this).getAppList()
val appList = utils!!.getAppList()
result.success(appList)
} catch (e: Exception) {
result.error("-1", e.message, null)
Expand Down Expand Up @@ -156,6 +157,17 @@ class MainActivity : FlutterActivity() {
}
}
}

// 遍历所有 app 通知刷新
Thread {
Log.d(TAG, "configureFlutterEngine: start get app list info")
utils!!.initAppList()
runOnUiThread {
Log.d(TAG, "configureFlutterEngine: call onRefresh")
FLUTTER_CHANNEL!!.invokeMethod("onRefresh", null)
Log.d(TAG, "configureFlutterEngine: end get app list info")
}
}.start()
}

private val VPN_REQUEST_CODE = 100
Expand Down
38 changes: 18 additions & 20 deletions android/app/src/main/kotlin/cn/ys1231/appproxy/data/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import java.io.ByteArrayOutputStream

class Utils(private val context: Context) {
private val TAG = "iyue->${this.javaClass.simpleName} "
// val sharedPreferences = context.getSharedPreferences("vpnconfig", Context.MODE_PRIVATE)

//val sharedPreferences = context.getSharedPreferences("vpnconfig", Context.MODE_PRIVATE)
private var appList: String? = null
private var isFirstGetApps: Boolean = true

init {
Log.d(TAG, "Utils init !")
Expand All @@ -30,8 +33,8 @@ class Utils(private val context: Context) {
*
* @return 返回包含已安装应用信息的JSON字符串,如果无应用满足条件或发生错误,则返回null。
*/
fun getAppList(): String? {

fun initAppList() {
Log.d(TAG, "initAppList: start")
// 通过上下文获取PackageManager对象,用于管理安装的应用程序
val pm = context.packageManager

Expand Down Expand Up @@ -78,7 +81,18 @@ class Utils(private val context: Context) {
}

// 使用Gson将应用信息列表转换为JSON字符串并返回
return Gson().toJson(appInfoList)
appList = Gson().toJson(appInfoList)
Log.d(TAG, "initAppList: end")
}

fun getAppList(): String? {
if (isFirstGetApps && appList != null) {
isFirstGetApps = false
return appList
} else {
initAppList()
return appList
}
}

private val PackageInfo.isSystemApp: Boolean
Expand All @@ -96,20 +110,4 @@ class Utils(private val context: Context) {
return bitmap
}

// public fun setVpnStatus(status: Boolean){
// var edit = sharedPreferences.edit()
// edit.putBoolean("vpnStatus", status)
// edit.commit()
// }
// public fun getVpnStatus(): Boolean{
// return sharedPreferences.getBoolean("vpnStatus", false)
// }
// public fun setProxyName(name: String){
// var edit = sharedPreferences.edit()
// edit.putString("proxyName", name)
// edit.commit()
// }
// public fun getProxyName(): String{
// return sharedPreferences.getString("proxyName", "") ?: ""
// }
}
4 changes: 2 additions & 2 deletions assets/appproxy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"VersionName": "v0.0.8",
"ModifyContent": "\r\n1、perf(startup): ⚡ #12 Optimize startup speed.\r\n2、fix(update): :bug: 国内更新通道, Domestic update channel",
"VersionName": "v0.1.3",
"ModifyContent": "\n\rperf(UI): :zap: 优化启动速度,UI 界面卡顿, Optimize the startup speed, UI interface is stuck",
"DownloadUrl": "https://pfile.ys1231.cn/modules/appproxy/"
}
22 changes: 1 addition & 21 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,7 @@ class _iyueMainPageState extends State<iyueMainPage> {
// 首页Widget
const ProxyListHome(),
// app配置列表
FutureBuilder(
// 先启动后加载
future: Future.delayed(const Duration(milliseconds: 100)),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
// 当计算状态为等待时,显示加载动画
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
// 显示一个加载动画
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
// 当 future 出现错误时,显示错误信息
return Center(
child: Text('Error: ${snapshot.error}'),
);
} else {
// 当计算完成时,显示app配置列表
return const AppConfigList();
}
}),
// const AppConfigList(),
const AppConfigList(),
// 设置页面
const AppSettings(), // 设置页Widget
];
Expand Down
10 changes: 9 additions & 1 deletion lib/ui/app_config_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class AppConfigState extends State<AppConfigList> {
// app列表配置文件
final AppProxyConfigData _appfile = AppProxyConfigData("proxyconfig.json");

// 远程调用通道
final platform = const MethodChannel('cn.ys1231/appproxy');

// 用于更新调用子控件列表项选择状态
List<GlobalKey<CardCheckboxState>> _cardKeys = [];

Expand All @@ -120,7 +123,12 @@ class AppConfigState extends State<AppConfigList> {
super.initState();
debugPrint("iyue-> initState");
_initData();
getAppList();
platform.setMethodCallHandler((call) async {
if (call.method == 'onRefresh') {
// 执行Flutter逻辑
getAppList();
}
});
}

// 初始化数据
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class _AppSettingsState extends State<AppSettings> {
children: [
Text(S.of(context).text_describe),
Text(S.of(context).text_author),
Text('${S.of(context).text_update_time}:2024-11-18'),
Text('${S.of(context).text_update_time}:2024-11-23'),
Row(
children: [
const Text('github:'),
Expand Down

0 comments on commit ce882f4

Please sign in to comment.