From 250e74228f3ad70ff2ddc3c24ed8f1fd6372fb35 Mon Sep 17 00:00:00 2001 From: kenzieschmoll Date: Wed, 24 Apr 2019 15:53:08 -0700 Subject: [PATCH] Fix Chrome on Windows. --- packages/devtools_server/lib/src/chrome.dart | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/devtools_server/lib/src/chrome.dart b/packages/devtools_server/lib/src/chrome.dart index f57f2a7da32..81ef554ac9c 100644 --- a/packages/devtools_server/lib/src/chrome.dart +++ b/packages/devtools_server/lib/src/chrome.dart @@ -3,9 +3,9 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:convert'; import 'dart:io'; +import 'package:path/path.dart' as p; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; // TODO(kenzie): move this code to dart-lang/browser_launcher. This code was @@ -16,6 +16,11 @@ const _linuxExecutable = 'google-chrome'; const _macOSExecutable = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; const _windowsExecutable = r'Google\Chrome\Application\chrome.exe'; +var _windowsPrefixes = [ + Platform.environment['LOCALAPPDATA'], + Platform.environment['PROGRAMFILES'], + Platform.environment['PROGRAMFILES(X86)'] +]; String get _executable { if (Platform.environment.containsKey(_chromeEnvironment)) { @@ -23,7 +28,15 @@ String get _executable { } if (Platform.isLinux) return _linuxExecutable; if (Platform.isMacOS) return _macOSExecutable; - if (Platform.isWindows) return _windowsExecutable; + if (Platform.isWindows) { + return p.join( + _windowsPrefixes.firstWhere((prefix) { + if (prefix == null) return false; + final path = p.join(prefix, _windowsExecutable); + return File(path).existsSync(); + }, orElse: () => '.'), + _windowsExecutable); + } throw StateError('Unexpected platform type.'); }