opt.: system detect logic to avoid creating useless file (#905)

This commit is contained in:
lollipopkit🏳️‍⚧️
2025-09-09 13:10:40 +08:00
committed by GitHub
parent 640d61bab9
commit 194774d6fb
2 changed files with 13 additions and 14 deletions

View File

@@ -32,7 +32,6 @@ jobs:
path: | path: |
${{ env.PUB_CACHE }} ${{ env.PUB_CACHE }}
~/.pub-cache ~/.pub-cache
${{ runner.tool_cache }}/flutter
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }} key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pub- ${{ runner.os }}-pub-

View File

@@ -9,8 +9,8 @@ class SystemDetector {
/// ///
/// First checks if a custom system type is configured in [spi]. /// First checks if a custom system type is configured in [spi].
/// If not, attempts to detect the system by running commands: /// If not, attempts to detect the system by running commands:
/// 1. 'ver' command to detect Windows /// 1. 'uname -a' command to detect Linux/BSD/Darwin
/// 2. '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. /// Returns [SystemType.linux] as default if detection fails.
static Future<SystemType> detect(SSHClient client, Spi spi) async { static Future<SystemType> detect(SSHClient client, Spi spi) async {
@@ -22,17 +22,8 @@ class SystemDetector {
} }
try { try {
// Try to detect Windows systems first (more reliable detection) // Try to detect Unix/Linux/BSD systems first (more reliable and doesn't create files)
final powershellResult = await client.run('ver 2>nul').string; final unixResult = await client.run('uname -a 2>/dev/null').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;
if (unixResult.contains('Linux')) { if (unixResult.contains('Linux')) {
detectedSystemType = SystemType.linux; detectedSystemType = SystemType.linux;
dprint('Detected Linux system type for ${spi.oldId}'); dprint('Detected Linux system type for ${spi.oldId}');
@@ -42,6 +33,15 @@ class SystemDetector {
dprint('Detected BSD system type for ${spi.oldId}'); dprint('Detected BSD system type for ${spi.oldId}');
return detectedSystemType; 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) { } catch (e) {
Loggers.app.warning('System detection failed for ${spi.oldId}: $e'); Loggers.app.warning('System detection failed for ${spi.oldId}: $e');
} }