state method
Where the host stands for b.
Implementation
Future<TomSecretsBrowserHostState> state(TomSecretsBrowser b) async {
final present = Directory(profileFolder(b)).existsSync();
final sandboxed = present ? null : _sandboxed(b);
final path = manifestPath(b);
final file = File(path);
final key = registryKey(b);
final registered = key == null ? null : await _registry.read(key);
final installed = file.existsSync() && (key == null || registered != null);
final problems = <String>[];
if (installed) {
try {
final written = jsonDecode(file.readAsStringSync());
if (written is! Map || written['path'] != hostExecutable) {
problems.add('the manifest names another host');
}
final want = manifest(b);
final allowed = b.isFirefox ? 'allowed_extensions' : 'allowed_origins';
if (written is Map && '${written[allowed]}' != '${want[allowed]}') {
problems.add('the manifest allows other extensions');
}
} on FormatException {
problems.add('the manifest cannot be read');
}
if (key != null && registered != path) {
problems.add('the registry names another manifest');
}
}
return TomSecretsBrowserHostState(
b,
present: present,
installed: installed,
current: installed && problems.isEmpty,
manifest: path,
sandboxed: sandboxed,
problems: problems,
);
}