find method

  1. @override
Future<String?> find(
  1. ProtocolScheme scheme
)
override

Used to get the application path of the scheme if its already registered.

Implementation

@override
Future<String?> find(ProtocolScheme scheme) async {
  final ProcessResult result1 = await Process.run(
    'REG',
    <String>[
      'QUERY',
      'HKCU\\Software\\Classes\\${scheme.scheme}',
      '/v',
      'URL Protocol'
    ],
  );

  final ProcessResult result2 = await Process.run(
    'REG',
    <String>[
      'QUERY',
      'HKCU\\Software\\Classes\\${scheme.scheme}\\shell\\open\\command',
      '/s'
    ],
  );

  try {
    return result1.stdout.toString().contains('URL Protocol')
        ? RegExp(
            '.*?\\n\\s+\\(Default\\)\\s+REG_SZ\\s+"?([^ "]+)',
          ).firstMatch(result2.stdout.toString())?.group(1)?.trim()
        : null;
  } catch (_) {}
}