Skip to content

Commit 2e95e5e

Browse files
authored
enh: add windows registration handler
1 parent e36f90c commit 2e95e5e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

IDCBrowser/IDCHandlerModule.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,34 @@ def registerCustomProtocol(self):
195195
# Update MIME database
196196
os.system("update-desktop-database ~/.local/share/applications/")
197197
os.system("xdg-mime default idcbrowser.desktop x-scheme-handler/idcbrowser")
198+
199+
elif platform.system() == "Windows":
200+
201+
# Get the directory of the current Python executable
202+
python_dir = os.path.dirname(sys.executable)
203+
204+
# Construct the path to PythonSlicer.exe in the same directory
205+
python_path = os.path.join(python_dir, "PythonSlicer.exe")
206+
207+
current_dir = os.path.dirname(os.path.realpath(__file__))
208+
python_script_path = os.path.join(current_dir,'Resources', 'resolver.py')
209+
210+
# Register IDC Browser URL protocol in Windows Registry
211+
import winreg as reg
212+
213+
try:
214+
reg.CreateKey(reg.HKEY_CURRENT_USER, r"Software\Classes\idcbrowser")
215+
with reg.OpenKey(reg.HKEY_CURRENT_USER, r"Software\Classes\idcbrowser", 0, reg.KEY_WRITE) as key:
216+
reg.SetValue(key, None, reg.REG_SZ, "URL:IDC Browser Protocol")
217+
reg.SetValueEx(key, "URL Protocol", 0, reg.REG_SZ, "")
218+
219+
reg.CreateKey(reg.HKEY_CURRENT_USER, r"Software\Classes\idcbrowser\shell\open\command")
220+
with reg.OpenKey(reg.HKEY_CURRENT_USER, r"Software\Classes\idcbrowser\shell\open\command", 0, reg.KEY_WRITE) as key:
221+
reg.SetValue(key, None, reg.REG_SZ, f'"{python_path}" "{python_script_path}" "%1"')
222+
223+
print("IDC Browser URL protocol has been registered on Windows.")
224+
except Exception as e:
225+
print(f"Failed to register IDC Browser URL protocol on Windows: {e}")
198226
else:
199227
print("IDC Browser URL protocol registration is not supported on this operating system.")
200228

0 commit comments

Comments
 (0)