add method

  1. @override
Future<bool> add(
  1. ProtocolScheme scheme
)
override

Used to add a scheme.

Implementation

@override
Future<bool> add(ProtocolScheme scheme) async {
  if (scheme.appPath == null) {
    throw ArgumentError.notNull('scheme.appPath');
  }

  final ProcessResult result1 = await Process.run(
    'REG',
    <String>[
      'ADD',
      'HKCU\\Software\\Classes\\${scheme.scheme}',
      '/v',
      'URL Protocol',
      '/f'
    ],
  );

  final ProcessResult result2 = await Process.run(
    'REG',
    <String>[
      'ADD',
      'HKCU\\Software\\Classes\\${scheme.scheme}\\shell\\open\\command',
      '/ve',
      '/d',
      '"${scheme.appPath}" "%1"',
      '/t',
      'REG_SZ',
      '/f'
    ],
  );

  return _isSuccessful(result1.stdout.toString()) &&
      _isSuccessful(result2.stdout.toString());
}