registerShortcutMenu function

void registerShortcutMenu(
  1. String key, {
  2. required String name,
  3. required String executable,
  4. String? icon,
})

Register shortcut menu.

Implementation

void registerShortcutMenu(
  String key, {
  required String name,
  required String executable,
  String? icon,
}) {
  final regValueMenu = RegistryValue.string(
    '',
    name,
  );
  final regValueMenuIcon = RegistryValue.string(
    'Icon',
    icon ?? '',
  );
  final regValueMenuCommand = RegistryValue.string(
    '',
    '$executable shortcut_menu_extender --key $key --path "%1"',
  );
  // Register shortcut menu for file.
  final regKeyForFile = Registry.classesRoot.createKey('*\\shell\\$key');
  regKeyForFile.createValue(regValueMenu);
  if ((icon ?? '').isNotEmpty) {
    regKeyForFile.createValue(regValueMenuIcon);
  }
  final regKeyForFileCommand = regKeyForFile.createKey('command');
  regKeyForFileCommand.createValue(regValueMenuCommand);

  // Register shortcut menu for folder.
  final regKeyForFolder = Registry.classesRoot.createKey('Folder\\shell\\$key');
  regKeyForFolder.createValue(regValueMenu);
  if ((icon ?? '').isNotEmpty) {
    regKeyForFolder.createValue(regValueMenuIcon);
  }
  final regKeyForFolderCommand = regKeyForFolder.createKey('command');
  regKeyForFolderCommand.createValue(regValueMenuCommand);
}