From 5e672116853b8fd70cd460ed12ed93f2450b43a8 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Sat, 23 Mar 2024 17:53:42 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Apowershell=20auto=20select?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app.dart | 18 ++++++++++++------ lib/common/helper/system_helper.dart | 11 +++++++---- lib/common/utils/log.dart | 8 ++++---- lib/ui/splash_ui.dart | 2 ++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 924c920..9154e8b 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -120,6 +120,11 @@ class AppGlobalModel extends _$AppGlobalModel { applicationBinaryModuleDir: applicationBinaryModuleDir, ); + // init Rust bridge + await RustLib.init(); + await RSHttp.init(); + dPrint("---- rust bridge init -----"); + // init Hive try { Hive.init("$applicationSupportDir/db"); @@ -144,13 +149,13 @@ class AppGlobalModel extends _$AppGlobalModel { exit(1); } - // init Rust bridge - await RustLib.init(); - await RSHttp.init(); - dPrint("---- rust bridge inited -----"); - // init powershell - await SystemHelper.initPowershellPath(); + try { + await SystemHelper.initPowershellPath(); + dPrint("---- Powershell init -----"); + }catch (e){ + dPrint("powershell init failed : $e"); + } // get windows info WindowsDeviceInfo? windowsDeviceInfo; @@ -177,6 +182,7 @@ class AppGlobalModel extends _$AppGlobalModel { } }); + dPrint("---- Window init -----"); _initialized = true; ref.keepAlive(); } diff --git a/lib/common/helper/system_helper.dart b/lib/common/helper/system_helper.dart index d2040ee..0c74974 100644 --- a/lib/common/helper/system_helper.dart +++ b/lib/common/helper/system_helper.dart @@ -7,9 +7,13 @@ class SystemHelper { static String powershellPath = "powershell.exe"; static initPowershellPath() async { - var result = await Process.run(powershellPath, ["echo", "ping"]); - if (!result.stdout.toString().startsWith("ping") && - powershellPath == "powershell.exe") { + try { + var result = await Process.run(powershellPath, ["echo", "ping"]); + if (!result.stdout.toString().startsWith("ping") && + powershellPath == "powershell.exe") { + throw "powershell check failed"; + } + } catch (e) { Map envVars = Platform.environment; final systemRoot = envVars["SYSTEMROOT"]; if (systemRoot != null) { @@ -17,7 +21,6 @@ class SystemHelper { "$systemRoot\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"; dPrint("auto search powershell path === $autoSearchPath"); powershellPath = autoSearchPath; - initPowershellPath(); } } } diff --git a/lib/common/utils/log.dart b/lib/common/utils/log.dart index 7e07ae0..2b572e7 100644 --- a/lib/common/utils/log.dart +++ b/lib/common/utils/log.dart @@ -12,11 +12,11 @@ void dPrint(src) async { if (kDebugMode) { print(src); } - try { - await _logLock.synchronized(() async { + await _logLock.synchronized(() async { + try { _logFile?.writeAsString("$src\n", mode: FileMode.append); - }); - } catch (_) {} + } catch (_) {} + }); } void setDPrintFile(File file) { diff --git a/lib/ui/splash_ui.dart b/lib/ui/splash_ui.dart index 6c1f21d..20bec30 100644 --- a/lib/ui/splash_ui.dart +++ b/lib/ui/splash_ui.dart @@ -69,8 +69,10 @@ class SplashUI extends HookConsumerWidget { } stepState.value = 1; if (!context.mounted) return; + dPrint("_initApp checkUpdate"); await appModel.checkUpdate(context); stepState.value = 2; + dPrint("_initApp aria2cModelProvider"); ref.read(aria2cModelProvider); if (!context.mounted) return; context.go("/index");