From 194774d6fbf428f1353f707fe33517bb6091e29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Tue, 9 Sep 2025 13:10:40 +0800 Subject: [PATCH] opt.: system detect logic to avoid creating useless file (#905) --- .github/workflows/analysis.yml | 1 - lib/data/helper/system_detector.dart | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 59833f68..0b88e676 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -32,7 +32,6 @@ jobs: path: | ${{ env.PUB_CACHE }} ~/.pub-cache - ${{ runner.tool_cache }}/flutter key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }} restore-keys: | ${{ runner.os }}-pub- diff --git a/lib/data/helper/system_detector.dart b/lib/data/helper/system_detector.dart index ffd0fccc..15bf1bce 100644 --- a/lib/data/helper/system_detector.dart +++ b/lib/data/helper/system_detector.dart @@ -9,8 +9,8 @@ class SystemDetector { /// /// First checks if a custom system type is configured in [spi]. /// If not, attempts to detect the system by running commands: - /// 1. 'ver' command to detect Windows - /// 2. 'uname -a' command to detect Linux/BSD/Darwin + /// 1. 'uname -a' command to detect Linux/BSD/Darwin + /// 2. 'ver' command to detect Windows (if uname fails) /// /// Returns [SystemType.linux] as default if detection fails. static Future detect(SSHClient client, Spi spi) async { @@ -22,17 +22,8 @@ class SystemDetector { } try { - // Try to detect Windows systems first (more reliable detection) - final powershellResult = await client.run('ver 2>nul').string; - if (powershellResult.isNotEmpty && - (powershellResult.contains('Windows') || powershellResult.contains('NT'))) { - detectedSystemType = SystemType.windows; - dprint('Detected Windows system type for ${spi.oldId}'); - return detectedSystemType; - } - - // Try to detect Unix/Linux/BSD systems - final unixResult = await client.run('uname -a').string; + // Try to detect Unix/Linux/BSD systems first (more reliable and doesn't create files) + final unixResult = await client.run('uname -a 2>/dev/null').string; if (unixResult.contains('Linux')) { detectedSystemType = SystemType.linux; dprint('Detected Linux system type for ${spi.oldId}'); @@ -42,6 +33,15 @@ class SystemDetector { dprint('Detected BSD system type for ${spi.oldId}'); return detectedSystemType; } + + // If uname fails, try to detect Windows systems + final powershellResult = await client.run('ver 2>nul').string; + if (powershellResult.isNotEmpty && + (powershellResult.contains('Windows') || powershellResult.contains('NT'))) { + detectedSystemType = SystemType.windows; + dprint('Detected Windows system type for ${spi.oldId}'); + return detectedSystemType; + } } catch (e) { Loggers.app.warning('System detection failed for ${spi.oldId}: $e'); }