Skip to content

Commit a910ff0

Browse files
authored
Fix launching Chrome on Windows (#324)
* Fix launching Chrome on Windows
1 parent 2d61960 commit a910ff0

File tree

5 files changed

+265
-246
lines changed

5 files changed

+265
-246
lines changed

webdev/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1
2+
3+
- Fix launching Chrome on Windows.
4+
15
## 2.0.0
26

37
## Breaking Changes

webdev/lib/src/serve/chrome.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@ const _linuxExecutable = 'google-chrome';
1616
const _macOSExecutable =
1717
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
1818
const _windowsExecutable = r'Google\Chrome\Application\chrome.exe';
19+
var _windowsPrefixes = [
20+
Platform.environment['LOCALAPPDATA'],
21+
Platform.environment['PROGRAMFILES'],
22+
Platform.environment['PROGRAMFILES(X86)']
23+
];
1924

2025
String get _executable {
2126
if (Platform.environment.containsKey(_chromeEnvironment)) {
2227
return Platform.environment[_chromeEnvironment];
2328
}
2429
if (Platform.isLinux) return _linuxExecutable;
2530
if (Platform.isMacOS) return _macOSExecutable;
26-
if (Platform.isWindows) return _windowsExecutable;
31+
if (Platform.isWindows) {
32+
return p.join(
33+
_windowsPrefixes.firstWhere((prefix) {
34+
if (prefix == null) return false;
35+
var path = p.join(prefix, _windowsExecutable);
36+
return File(path).existsSync();
37+
}, orElse: () => '.'),
38+
_windowsExecutable);
39+
}
2740
throw StateError('Unexpected platform type.');
2841
}
2942

0 commit comments

Comments
 (0)