locate static method

Chrome? locate()

Implementation

static Chrome? locate() {
  if (Platform.isMacOS) {
    const String defaultPath = '/Applications/Google Chrome.app';
    const String bundlePath = 'Contents/MacOS/Google Chrome';

    if (FileSystemEntity.isDirectorySync(defaultPath)) {
      return Chrome.from(path.join(defaultPath, bundlePath));
    }
  } else if (Platform.isLinux) {
    const String defaultPath = '/usr/bin/google-chrome';

    if (FileSystemEntity.isFileSync(defaultPath)) {
      return Chrome.from(defaultPath);
    }
  } else if (Platform.isWindows) {
    final String progFiles = Platform.environment['PROGRAMFILES(X86)']!;
    final String chromeInstall = '$progFiles\\Google\\Chrome';
    final String defaultPath = '$chromeInstall\\Application\\chrome.exe';

    if (FileSystemEntity.isFileSync(defaultPath)) {
      return Chrome.from(defaultPath);
    }
  }

  final pathFromEnv = Platform.environment['CHROME_PATH'];
  if (pathFromEnv != null && FileSystemEntity.isFileSync(pathFromEnv)) {
    return Chrome.from(pathFromEnv);
  }

  // TODO(devoncarew): check default install locations for linux
  // TODO(devoncarew): try `which` on mac, linux

  return null;
}