GUI: Convert more osascript calls

This commit is contained in:
Mykola Grymalyuk
2023-05-17 13:12:35 -06:00
parent 7417fc4180
commit 831fbc3319
3 changed files with 25 additions and 37 deletions
+2 -2
View File
@@ -73,8 +73,8 @@ class OpenCoreLegacyPatcher:
launcher_script = __file__ launcher_script = __file__
if "main.py" in launcher_script: if "main.py" in launcher_script:
launcher_script = launcher_script.replace("/resources/main.py", "/OpenCore-Patcher-GUI.command") launcher_script = launcher_script.replace("/resources/main.py", "/OpenCore-Patcher-GUI.command")
self.constants.launcher_binary = launcher_binary self.constants.launcher_binary = str(launcher_binary)
self.constants.launcher_script = launcher_script self.constants.launcher_script = str(launcher_script)
# Initialize working directory # Initialize working directory
self.constants.unpack_thread = threading.Thread(target=reroute_payloads.RoutePayloadDiskImage, args=(self.constants,)) self.constants.unpack_thread = threading.Thread(target=reroute_payloads.RoutePayloadDiskImage, args=(self.constants,))
+12 -18
View File
@@ -83,36 +83,30 @@ class AutomaticSysPatch:
logging.info("- No new binaries found on Github, proceeding with patching") logging.info("- No new binaries found on Github, proceeding with patching")
if self.constants.launcher_script is None: if self.constants.launcher_script is None:
args_string = f"'{self.constants.launcher_binary}' --gui_patch" args = [self.constants.launcher_binary, "--gui_patch"]
else: else:
args_string = f"{self.constants.launcher_binary} {self.constants.launcher_script} --gui_patch" args = [self.constants.launcher_binary, self.constants.launcher_script, "--gui_patch"]
warning_str = "" warning_str = ""
if network_handler.NetworkUtilities("https://api.github.com/repos/dortania/OpenCore-Legacy-Patcher/releases/latest").verify_network_connection() is False: if network_handler.NetworkUtilities("https://api.github.com/repos/dortania/OpenCore-Legacy-Patcher/releases/latest").verify_network_connection() is False:
warning_str = f"""\n\nWARNING: We're unable to verify whether there are any new releases of OpenCore Legacy Patcher on Github. Be aware that you may be using an outdated version for this OS. If you're unsure, verify on Github that OpenCore Legacy Patcher {self.constants.patcher_version} is the latest official release""" warning_str = f"""\n\nWARNING: We're unable to verify whether there are any new releases of OpenCore Legacy Patcher on Github. Be aware that you may be using an outdated version for this OS. If you're unsure, verify on Github that OpenCore Legacy Patcher {self.constants.patcher_version} is the latest official release"""
args = [
"osascript",
"-e",
f"""display dialog "OpenCore Legacy Patcher has detected you're running without Root Patches, and would like to install them.\n\nmacOS wipes all root patches during OS installs and updates, so they need to be reinstalled.\n\nFollowing Patches have been detected for your system: \n{patch_string}\nWould you like to apply these patches?{warning_str}" """
f'with icon POSIX file "{self.constants.app_icon_path}"',
]
output = subprocess.run( output = subprocess.run(
args, [
"osascript",
"-e",
f"""display dialog "OpenCore Legacy Patcher has detected you're running without Root Patches, and would like to install them.\n\nmacOS wipes all root patches during OS installs and updates, so they need to be reinstalled.\n\nFollowing Patches have been detected for your system: \n{patch_string}\nWould you like to apply these patches?{warning_str}" """
f'with icon POSIX file "{self.constants.app_icon_path}"',
],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
if output.returncode == 0: if output.returncode == 0:
args = [
"osascript",
"-e",
f'''do shell script "{args_string}"'''
f' with prompt "OpenCore Legacy Patcher would like to patch your root volume"'
" with administrator privileges"
" without altering line endings"
]
subprocess.run( subprocess.run(
args, [
self.constants.oclp_helper_path,
*args
],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT stderr=subprocess.STDOUT
) )
+11 -17
View File
@@ -4,6 +4,7 @@ import time
import logging import logging
import threading import threading
import subprocess import subprocess
import applescript
from pathlib import Path from pathlib import Path
@@ -184,7 +185,10 @@ class RestartHost:
# Reboots with Count Down prompt (user can still dismiss if needed) # Reboots with Count Down prompt (user can still dismiss if needed)
self.frame.Hide() self.frame.Hide()
wx.GetApp().Yield() wx.GetApp().Yield()
subprocess.call(['osascript', '-e', 'tell app "loginwindow" to «event aevtrrst»']) try:
applescript.AppleScript('tell app "loginwindow" to «event aevtrrst»').run()
except applescript.ScriptError as e:
logging.error(f"Error while trying to reboot: {e}")
sys.exit(0) sys.exit(0)
@@ -213,32 +217,22 @@ class RelaunchApplicationAsRoot:
return return
timer: int = 5 timer: int = 5
program_arguments: str = "" program_arguments: list = []
if event: if event:
if event.GetEventObject() != wx.Menu: if event.GetEventObject() != wx.Menu:
try: try:
if event.GetEventObject().GetLabel() in ["Start Root Patching", "Reinstall Root Patches"]: if event.GetEventObject().GetLabel() in ["Start Root Patching", "Reinstall Root Patches"]:
program_arguments = " --gui_patch" program_arguments += ["--gui_patch"]
elif event.GetEventObject().GetLabel() == "Revert Root Patches": elif event.GetEventObject().GetLabel() == "Revert Root Patches":
program_arguments = " --gui_unpatch" program_arguments += ["--gui_unpatch"]
except TypeError: except TypeError:
pass pass
if self.constants.launcher_script is None: if self.constants.launcher_script is None:
program_arguments = f"'{self.constants.launcher_binary}'{program_arguments}" program_arguments = [self.constants.launcher_binary] + program_arguments
else: else:
program_arguments = f"{self.constants.launcher_binary} {self.constants.launcher_script}{program_arguments}" program_arguments = [self.constants.launcher_binary, self.constants.launcher_script] + program_arguments
# Relaunch as root
args = [
"osascript",
"-e",
f'''do shell script "{program_arguments}"'''
' with prompt "OpenCore Legacy Patcher needs administrator privileges to relaunch as admin."'
" with administrator privileges"
" without altering line endings",
]
self.frame.DestroyChildren() self.frame.DestroyChildren()
self.frame.SetSize(400, 300) self.frame.SetSize(400, 300)
@@ -259,7 +253,7 @@ class RelaunchApplicationAsRoot:
wx.GetApp().Yield() wx.GetApp().Yield()
logging.info(f"- Relaunching as root with command: {program_arguments}") logging.info(f"- Relaunching as root with command: {program_arguments}")
subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) subprocess.Popen([self.constants.oclp_helper_path, *program_arguments], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True: while True:
wx.GetApp().Yield() wx.GetApp().Yield()