Skip to content

Commit 28008d4

Browse files
fixed context menu bugs
1 parent a2d1379 commit 28008d4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

wormhole.exe

1.3 KB
Binary file not shown.

wormhole.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -558,25 +558,33 @@ def __init__(self):
558558
def register_context_menu(self):
559559
try:
560560
import winreg
561-
exe_path = sys.executable
562-
icon_path = exe_path # Use exe path for icon (embedded via PyInstaller --icon)
561+
if hasattr(sys, '_MEIPASS'):
562+
# Bundled mode
563+
exe_path = sys.executable
564+
else:
565+
# Script mode
566+
exe_path = f'"{sys.executable}" "{os.path.abspath(__file__)}"'
567+
icon_path = sys.executable if hasattr(sys, '_MEIPASS') else APP_ICON_PATH
563568
for cat, info in formats.items():
564569
for ext in info['extensions']:
565-
key_path = rf"Software\Classes\SystemFileAssociations\{ext}\shell\WormholeConvert"
566-
key = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, key_path, 0, winreg.KEY_SET_VALUE)
570+
main_key_path = rf"Software\Classes\SystemFileAssociations\{ext}\shell\WormholeConvert"
571+
key = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, main_key_path, 0, winreg.KEY_SET_VALUE)
567572
winreg.SetValueEx(key, None, 0, winreg.REG_SZ, "Convert with Wormhole")
568573
winreg.SetValueEx(key, "Icon", 0, winreg.REG_SZ, icon_path)
569-
winreg.CloseKey(key)
570-
shell_key_path = key_path + r"\shell"
574+
subcommands = []
571575
for tgt in info['targets']:
572-
sub_key_path = shell_key_path + rf"\To{tgt.replace(' ', '')}" # Clean tgt for key (remove spaces from extract audio)
576+
clean_tgt = tgt.replace(' ', '')
577+
subcommands.append(f"To{clean_tgt}")
578+
sub_key_path = rf"Software\Classes\SystemFileAssociations\{ext}\shell\To{clean_tgt}"
573579
sub_key = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, sub_key_path, 0, winreg.KEY_SET_VALUE)
574580
winreg.SetValueEx(sub_key, None, 0, winreg.REG_SZ, f"To {tgt}")
575581
winreg.CloseKey(sub_key)
576582
cmd_key_path = sub_key_path + r"\command"
577583
cmd_key = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, cmd_key_path, 0, winreg.KEY_SET_VALUE)
578-
winreg.SetValueEx(cmd_key, None, 0, winreg.REG_SZ, f'"{exe_path}" "%1" "{tgt}"')
584+
winreg.SetValueEx(cmd_key, None, 0, winreg.REG_SZ, f'{exe_path} "%1" "{tgt}"')
579585
winreg.CloseKey(cmd_key)
586+
winreg.SetValueEx(key, "SubCommands", 0, winreg.REG_SZ, "|".join(subcommands))
587+
winreg.CloseKey(key)
580588
except Exception as e:
581589
print(f"Failed to register context menu: {e}")
582590

@@ -585,8 +593,12 @@ def unregister_context_menu(self):
585593
import winreg
586594
for cat, info in formats.items():
587595
for ext in info['extensions']:
588-
key_path = rf"Software\Classes\SystemFileAssociations\{ext}\shell\WormholeConvert"
589-
self._delete_registry_key(winreg.HKEY_CURRENT_USER, key_path)
596+
main_key_path = rf"Software\Classes\SystemFileAssociations\{ext}\shell\WormholeConvert"
597+
self._delete_registry_key(winreg.HKEY_CURRENT_USER, main_key_path)
598+
for tgt in info['targets']:
599+
clean_tgt = tgt.replace(' ', '')
600+
sub_key_path = rf"Software\Classes\SystemFileAssociations\{ext}\shell\To{clean_tgt}"
601+
self._delete_registry_key(winreg.HKEY_CURRENT_USER, sub_key_path)
590602
except Exception as e:
591603
print(f"Failed to unregister context menu: {e}")
592604

0 commit comments

Comments
 (0)