lookupExtensionEnabledState method

ExtensionEnabledState lookupExtensionEnabledState({
  1. required Uri devtoolsOptionsUri,
  2. required String extensionName,
})

Returns the current enabled state for extensionName in the 'devtools_options.yaml' file at devtoolsOptionsUri.

If the 'devtools_options.yaml' file does not exist, it will be created with an empty set of extensions.

devtoolsOptionsUri is expected to be a file:// URI.

Implementation

ExtensionEnabledState lookupExtensionEnabledState({
  required Uri devtoolsOptionsUri,
  required String extensionName,
}) {
  final options = _optionsAsMap(optionsUri: devtoolsOptionsUri);
  if (options == null) return ExtensionEnabledState.error;

  final extensions =
      (options[_extensionsKey] as List?)?.cast<Map<String, Object?>>();
  if (extensions == null) return ExtensionEnabledState.none;

  for (final e in extensions) {
    // Each entry should only have one key / value pair (e.g. '- foo: true').
    assert(e.keys.length == 1);

    if (e.keys.first == extensionName) {
      return _extensionStateForValue(e[extensionName]);
    }
  }
  return ExtensionEnabledState.none;
}