windows app launcher fix
This commit is contained in:
@@ -9,9 +9,13 @@ import shlex
|
|||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
try:
|
try:
|
||||||
from win32com.client import Dispatch
|
from win32com.client import Dispatch
|
||||||
|
import win32api
|
||||||
|
import win32con
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("Windows specific functionality requires 'pywin32'. Please run 'pip install pywin32'.")
|
print("Windows specific functionality requires 'pywin32'. Please run 'pip install pywin32'.")
|
||||||
Dispatch = None
|
Dispatch = None
|
||||||
|
win32api = None
|
||||||
|
win32con = None
|
||||||
|
|
||||||
_app_cache: Optional[list['App']] = None
|
_app_cache: Optional[list['App']] = None
|
||||||
|
|
||||||
@@ -178,16 +182,28 @@ def reload_app_cache() -> list[App]:
|
|||||||
|
|
||||||
def launch(app: App):
|
def launch(app: App):
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
if not win32api or not win32con:
|
||||||
|
print(f"Failed to launch '{app.name}': pywin32 components are missing.")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
command_args = shlex.split(app.exec, posix=False)
|
# Using ShellExecute is more robust for launching various application types on Windows,
|
||||||
|
# as it leverages the Windows shell's own mechanisms. This is particularly helpful for
|
||||||
|
# non-standard executables like PWAs or Microsoft Store apps.
|
||||||
|
command_parts = shlex.split(app.exec, posix=False)
|
||||||
|
target = command_parts[0]
|
||||||
|
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
# Use subprocess.list2cmdline to correctly re-assemble the arguments string,
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
# preserving quotes around arguments with spaces.
|
||||||
|
arguments = subprocess.list2cmdline(command_parts[1:])
|
||||||
subprocess.Popen(
|
|
||||||
command_args,
|
win32api.ShellExecute(
|
||||||
creationflags=subprocess.DETACHED_PROCESS,
|
0, # Parent window handle (0 for desktop)
|
||||||
startupinfo=startupinfo
|
"open", # Operation
|
||||||
|
target, # File to execute or open
|
||||||
|
arguments, # Parameters
|
||||||
|
"", # Working directory (None for default)
|
||||||
|
win32con.SW_SHOWNORMAL # How to show the window
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to launch '{app.name}': {e}")
|
print(f"Failed to launch '{app.name}': {e}")
|
||||||
|
|||||||
2
main.py
2
main.py
@@ -37,7 +37,7 @@ def main():
|
|||||||
|
|
||||||
restart = "--restart" in sys.argv
|
restart = "--restart" in sys.argv
|
||||||
no_quit = "--no-quit" in sys.argv
|
no_quit = "--no-quit" in sys.argv
|
||||||
super_menu = not "--no-super" in sys.argv
|
super_menu = not "--no-super" in sys.argv and not "--no-start" in sys.argv
|
||||||
noupdate = "--no-update" in sys.argv
|
noupdate = "--no-update" in sys.argv
|
||||||
|
|
||||||
if not noupdate:
|
if not noupdate:
|
||||||
|
|||||||
@@ -3,6 +3,5 @@ pynput
|
|||||||
requests
|
requests
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
GitPython
|
GitPython
|
||||||
discord-rpc
|
|
||||||
pywin32 ; sys_platform == 'win32'
|
pywin32 ; sys_platform == 'win32'
|
||||||
discord-rich-presence
|
discord-rich-presence
|
||||||
Reference in New Issue
Block a user