locate static method

Chrome? locate()

Implementation

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

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

    if (FileSystemEntity.isFileSync(defaultPath)) {
      return Chrome.from(defaultPath);
    }
  } else if (Platform.isWindows) {
    final progFiles = Platform.environment['PROGRAMFILES(X86)']!;
    final chromeInstall = '$progFiles\\Google\\Chrome';
    final 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;
}