Skip to content

Commit 9cbee06

Browse files
authored
fix: Windows lock file - use USERPROFILE fallback when HOME is not set
Co-authored-by: guxiyuesi <339558YYmy>
1 parent cf37e9a commit 9cbee06

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

lib/src/bridge/web_bridge_proxy.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,14 @@ class WebBridgeProxy {
156156

157157
// Read the SDK script — try common locations
158158
String? sdkSource;
159+
final home = Platform.environment['HOME'] ??
160+
Platform.environment['USERPROFILE'];
159161
final candidates = [
160162
// Relative to the flutter-skill package
161163
'sdks/web/flutter-skill.js',
162164
// npm global install
163-
'${Platform.environment['HOME']}/.pub-cache/hosted/pub.dev/flutter_skill-latest/sdks/web/flutter-skill.js',
165+
if (home != null)
166+
'$home/.pub-cache/hosted/pub.dev/flutter_skill-latest/sdks/web/flutter-skill.js',
164167
];
165168

166169
for (final path in candidates) {

lib/src/cli/init.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,12 @@ Future<void> _configureMCP() async {
470470
print('');
471471
print('🤖 Configuring AI agent MCP...');
472472

473-
final home = Platform.environment['HOME'] ?? '';
473+
final home = Platform.environment['HOME'] ??
474+
Platform.environment['USERPROFILE'];
475+
if (home == null) {
476+
print(' Warning: Could not determine home directory');
477+
return;
478+
}
474479

475480
// Claude Code
476481
final claudeSettings = File('$home/.claude/settings.json');

lib/src/cli/quickstart.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,14 +773,17 @@ Future<String?> _findFlutter() async {
773773
if (inPath != null) return 'flutter';
774774

775775
// Check common locations
776-
final home = Platform.environment['HOME'] ?? '';
776+
final home = Platform.environment['HOME'] ??
777+
Platform.environment['USERPROFILE'];
777778
final candidates = [
778-
'$home/development/flutter/bin/flutter',
779-
'$home/flutter/bin/flutter',
780-
'$home/.flutter/bin/flutter',
779+
if (home != null) ...[
780+
'$home/development/flutter/bin/flutter',
781+
'$home/flutter/bin/flutter',
782+
'$home/.flutter/bin/flutter',
783+
'$home/snap/flutter/common/flutter/bin/flutter',
784+
'$home/fvm/default/bin/flutter',
785+
],
781786
'/opt/flutter/bin/flutter',
782-
'$home/snap/flutter/common/flutter/bin/flutter',
783-
'$home/fvm/default/bin/flutter',
784787
];
785788
for (final path in candidates) {
786789
if (await File(path).exists()) {

lib/src/cli/server.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ class FlutterMcpServer {
10411041

10421042
/// Acquire a lock file to prevent multiple server instances
10431043
Future<File?> _acquireLock() async {
1044-
final home = Platform.environment['HOME'];
1044+
final home = Platform.environment['HOME'] ??
1045+
Platform.environment['USERPROFILE'];
10451046
if (home == null) return null;
10461047

10471048
final lockFile = File('$home/.flutter_skill.lock');

lib/src/cli/tool_handlers/discovery_helpers.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ extension _DiscoveryHelpers on FlutterMcpServer {
4343
}
4444

4545
String _findAdb() {
46+
final home = Platform.environment['HOME'] ??
47+
Platform.environment['USERPROFILE'];
4648
final androidHome = Platform.environment['ANDROID_HOME'] ??
4749
Platform.environment['ANDROID_SDK_ROOT'] ??
48-
'${Platform.environment['HOME']}/Library/Android/sdk';
49-
final adbPath = '$androidHome/platform-tools/adb';
50-
if (File(adbPath).existsSync()) return adbPath;
50+
(home != null ? '$home/Library/Android/sdk' : null);
51+
if (androidHome != null) {
52+
final adbPath = '$androidHome/platform-tools/adb';
53+
if (File(adbPath).existsSync()) return adbPath;
54+
}
5155
return 'adb'; // fallback to PATH
5256
}
5357

test/lock_mechanism_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import 'package:flutter_test/flutter_test.dart';
33

44
void main() {
55
group('Lock Mechanism Tests', () {
6-
final lockFilePath = '${Platform.environment['HOME']}/.flutter_skill.lock';
6+
final home = Platform.environment['HOME'] ??
7+
Platform.environment['USERPROFILE'];
8+
final lockFilePath = '${home ?? "/tmp"}/.flutter_skill.lock';
79
final lockFile = File(lockFilePath);
810

911
tearDown(() async {

0 commit comments

Comments
 (0)