-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_shortcut.py
More file actions
121 lines (101 loc) · 4.51 KB
/
create_shortcut.py
File metadata and controls
121 lines (101 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""
Shortcut Creator for Edge Node Launcher
This script creates a Windows shortcut with the correct icon and settings.
Run this script after installation to ensure shortcuts have the right icon.
"""
import os
import sys
import subprocess
import winshell
from win32com.client import Dispatch
def create_shortcut(target_path, shortcut_path, icon_path=None, description=None):
"""Create a Windows shortcut with the specified icon and description."""
print(f"Creating shortcut: {shortcut_path}")
print(f"Target: {target_path}")
print(f"Icon: {icon_path}")
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(shortcut_path)
shortcut.Targetpath = target_path
shortcut.WorkingDirectory = os.path.dirname(target_path)
if icon_path:
shortcut.IconLocation = icon_path
if description:
shortcut.Description = description
shortcut.save()
print(f"Shortcut created successfully")
return shortcut_path
def create_app_shortcuts(exe_path, icon_path=None):
"""Create shortcuts for the application on desktop and start menu."""
if not os.path.exists(exe_path):
print(f"Error: Executable not found at {exe_path}")
return False
app_name = os.path.basename(exe_path).replace('.exe', '')
description = f"Launch {app_name}"
# If icon_path is not specified, use the exe itself as the icon source
if not icon_path or not os.path.exists(icon_path):
print(f"Warning: Icon file not found, using executable as icon source")
icon_path = f"{exe_path},0"
else:
print(f"Using icon from: {icon_path}")
# Create desktop shortcut
desktop_path = winshell.desktop()
desktop_shortcut = os.path.join(desktop_path, f"{app_name}.lnk")
create_shortcut(exe_path, desktop_shortcut, icon_path, description)
# Create start menu shortcut
start_menu_path = os.path.join(winshell.start_menu(), "Programs", app_name)
if not os.path.exists(start_menu_path):
os.makedirs(start_menu_path)
start_menu_shortcut = os.path.join(start_menu_path, f"{app_name}.lnk")
create_shortcut(exe_path, start_menu_shortcut, icon_path, description)
# Create additional shortcut that suppresses console windows
# This sets the shortcut to run minimized/hidden
launcher_shortcut = os.path.join(start_menu_path, f"{app_name} (No Console).lnk")
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(launcher_shortcut)
shortcut.Targetpath = exe_path
shortcut.WorkingDirectory = os.path.dirname(exe_path)
shortcut.IconLocation = icon_path
shortcut.Description = f"Launch {app_name} without console windows"
# Set window style to minimized
shortcut.WindowStyle = 7 # 7 = Minimized
shortcut.save()
return True
if __name__ == "__main__":
# Get the script directory
script_dir = os.path.dirname(os.path.abspath(__file__))
# Get paths
exe_path = os.path.join(script_dir, "dist", "EdgeNodeLauncher.exe")
icon_path = os.path.join(script_dir, "assets", "r1_icon.ico")
print(f"Script directory: {script_dir}")
print(f"Creating shortcuts for: {exe_path}")
print(f"Using icon: {icon_path}")
if not os.path.exists(exe_path):
print(f"Executable not found at {exe_path}")
# Try alternate path for installed app
alt_exe_path = os.path.join(os.environ.get('ProgramFiles', 'C:\\Program Files'),
"EdgeNodeLauncher", "EdgeNodeLauncher.exe")
if os.path.exists(alt_exe_path):
exe_path = alt_exe_path
print(f"Using alternate executable path: {exe_path}")
else:
print(f"Executable not found. Please build the application first.")
sys.exit(1)
if not os.path.exists(icon_path):
print(f"Warning: Icon file not found at {icon_path}")
# Try alternate paths
alt_icon_paths = [
os.path.join(os.path.dirname(exe_path), "assets", "r1_icon.ico"),
os.path.join(os.path.dirname(exe_path), "r1_icon.ico")
]
for alt_path in alt_icon_paths:
if os.path.exists(alt_path):
icon_path = alt_path
print(f"Using alternate icon path: {icon_path}")
break
else:
print("Using executable's embedded icon as fallback")
icon_path = None
if create_app_shortcuts(exe_path, icon_path):
print("Shortcuts created successfully.")
else:
print("Failed to create shortcuts.")