mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-24 12:00:15 +10:00
subprocess_wrapper.py: Add unified error handling
Additionally adds backend support for Privileged Helper Tool
This commit is contained in:
@@ -26,6 +26,7 @@ from ..support import (
|
||||
utilities,
|
||||
network_handler,
|
||||
kdk_handler,
|
||||
subprocess_wrapper
|
||||
)
|
||||
|
||||
|
||||
@@ -525,7 +526,7 @@ class macOSInstallerFlashFrame(wx.Frame):
|
||||
result = subprocess.run(["/usr/bin/hdiutil", "attach", kdk_dmg_path, "-mountpoint", mount_point, "-nobrowse"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if result.returncode != 0:
|
||||
logging.info("Failed to mount KDK")
|
||||
logging.info(result.stdout.decode("utf-8"))
|
||||
subprocess_wrapper.log(result)
|
||||
return
|
||||
|
||||
logging.info("Copying KDK")
|
||||
@@ -535,7 +536,7 @@ class macOSInstallerFlashFrame(wx.Frame):
|
||||
result = subprocess.run(["/usr/bin/hdiutil", "detach", mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if result.returncode != 0:
|
||||
logging.info("Failed to unmount KDK")
|
||||
logging.info(result.stdout.decode("utf-8"))
|
||||
subprocess_wrapper.log(result)
|
||||
return
|
||||
|
||||
logging.info("Removing KDK Disk Image")
|
||||
|
||||
@@ -24,7 +24,8 @@ from ..support import (
|
||||
global_settings,
|
||||
defaults,
|
||||
generate_smbios,
|
||||
network_handler
|
||||
network_handler,
|
||||
subprocess_wrapper
|
||||
)
|
||||
from ..datasets import (
|
||||
model_array,
|
||||
@@ -1324,7 +1325,7 @@ Hardware Information:
|
||||
raise Exception("Test Exception")
|
||||
|
||||
def on_mount_root_vol(self, event: wx.Event) -> None:
|
||||
if os.geteuid() != 0:
|
||||
if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
||||
wx.MessageDialog(self.parent, "Please relaunch as Root to mount the Root Volume", "Error", wx.OK | wx.ICON_ERROR).ShowModal()
|
||||
else:
|
||||
#Don't need to pass model as we're bypassing all logic
|
||||
@@ -1334,7 +1335,7 @@ Hardware Information:
|
||||
wx.MessageDialog(self.parent, "Root Volume Mount Failed, check terminal output", "Error", wx.OK | wx.ICON_ERROR).ShowModal()
|
||||
|
||||
def on_bless_root_vol(self, event: wx.Event) -> None:
|
||||
if os.geteuid() != 0:
|
||||
if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
||||
wx.MessageDialog(self.parent, "Please relaunch as Root to save changes", "Error", wx.OK | wx.ICON_ERROR).ShowModal()
|
||||
else:
|
||||
#Don't need to pass model as we're bypassing all logic
|
||||
|
||||
@@ -15,10 +15,12 @@ import packaging.version
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from . import gui_about
|
||||
|
||||
from .. import constants
|
||||
|
||||
from ..wx_gui import gui_about
|
||||
from ..detections import device_probe
|
||||
from ..support import subprocess_wrapper
|
||||
|
||||
from ..datasets import (
|
||||
model_array,
|
||||
@@ -75,7 +77,7 @@ class GenerateMenubar:
|
||||
self.frame.Bind(wx.EVT_MENU, lambda event: RelaunchApplicationAsRoot(self.frame, self.constants).relaunch(None), relaunchItem)
|
||||
self.frame.Bind(wx.EVT_MENU, lambda event: subprocess.run(["/usr/bin/open", "--reveal", self.constants.log_filepath]), revealLogItem)
|
||||
|
||||
if os.geteuid() == 0:
|
||||
if os.geteuid() == 0 or subprocess_wrapper.supports_privileged_helper() is True:
|
||||
relaunchItem.Enable(False)
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ from pathlib import Path
|
||||
from .. import constants
|
||||
|
||||
from ..sys_patch import sys_patch_detect
|
||||
from ..support import subprocess_wrapper
|
||||
|
||||
from ..wx_gui import (
|
||||
gui_main_menu,
|
||||
@@ -242,7 +243,7 @@ class SysPatchDisplayFrame(wx.Frame):
|
||||
revert_button.Disable()
|
||||
|
||||
# Relaunch as root if not root
|
||||
if os.geteuid() != 0:
|
||||
if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
||||
start_button.Bind(wx.EVT_BUTTON, gui_support.RelaunchApplicationAsRoot(frame, self.constants).relaunch)
|
||||
revert_button.Bind(wx.EVT_BUTTON, gui_support.RelaunchApplicationAsRoot(frame, self.constants).relaunch)
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ from ..wx_gui import (
|
||||
)
|
||||
from ..support import (
|
||||
network_handler,
|
||||
updates
|
||||
updates,
|
||||
subprocess_wrapper
|
||||
)
|
||||
|
||||
|
||||
@@ -200,7 +201,8 @@ class UpdateFrame(wx.Frame):
|
||||
["/usr/bin/ditto", "-xk", str(self.constants.payload_path / "OpenCore-Patcher-GUI.app.zip"), str(self.constants.payload_path)], capture_output=True
|
||||
)
|
||||
if result.returncode != 0:
|
||||
logging.error(f"Failed to extract update. Error: {result.stderr.decode('utf-8')}")
|
||||
logging.error(f"Failed to extract update.")
|
||||
subprocess_wrapper.log(result)
|
||||
wx.CallAfter(self.progress_bar_animation.stop_pulse)
|
||||
wx.CallAfter(self.progress_bar.SetValue, 0)
|
||||
wx.CallAfter(wx.MessageBox, f"Failed to extract update. Error: {result.stderr.decode('utf-8')}", "Critical Error!", wx.OK | wx.ICON_ERROR)
|
||||
@@ -278,7 +280,8 @@ EOF
|
||||
logging.info("User cancelled update")
|
||||
wx.CallAfter(wx.MessageBox, "User cancelled update", "Update Cancelled", wx.OK | wx.ICON_INFORMATION)
|
||||
else:
|
||||
logging.critical(f"Failed to install update. Error: {result.stderr.decode('utf-8')}")
|
||||
logging.critical("Failed to install update.")
|
||||
subprocess_wrapper.log(result)
|
||||
wx.CallAfter(wx.MessageBox, f"Failed to install update. Error: {result.stderr.decode('utf-8')}", "Critical Error!", wx.OK | wx.ICON_ERROR)
|
||||
wx.CallAfter(sys.exit, 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user