From fdfc86e0d6ea3fa9859cdde13ffca5d4b6ae8733 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Tue, 28 May 2024 12:23:33 -0600 Subject: [PATCH] sys_patch: Avoid relaunching OCLP --- .../sys_patch/sys_patch_auto.py | 19 ++----------------- opencore_legacy_patcher/wx_gui/gui_entry.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/opencore_legacy_patcher/sys_patch/sys_patch_auto.py b/opencore_legacy_patcher/sys_patch/sys_patch_auto.py index da46a3877..d840f04d7 100644 --- a/opencore_legacy_patcher/sys_patch/sys_patch_auto.py +++ b/opencore_legacy_patcher/sys_patch/sys_patch_auto.py @@ -162,10 +162,6 @@ Please check the Github page for more information about this release.""" patch_string += f"- {patch}\n" logging.info("- No new binaries found on Github, proceeding with patching") - if self.constants.launcher_script is None: - args_string = f"'{self.constants.launcher_binary}' --gui_patch" - else: - args_string = f"{self.constants.launcher_binary} {self.constants.launcher_script} --gui_patch" warning_str = "" if network_handler.NetworkUtilities("https://api.github.com/repos/dortania/OpenCore-Legacy-Patcher/releases/latest").verify_network_connection() is False: @@ -183,20 +179,9 @@ Please check the Github page for more information about this release.""" stderr=subprocess.STDOUT ) if output.returncode == 0: - args = [ - "/usr/bin/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( - args, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT - ) + gui_entry.EntryPoint(self.constants).start(entry=gui_entry.SupportedEntryPoints.SYS_PATCH, start_patching=True) return + else: logging.info("- No patches detected") else: diff --git a/opencore_legacy_patcher/wx_gui/gui_entry.py b/opencore_legacy_patcher/wx_gui/gui_entry.py index d5de49bd8..84b70f149 100644 --- a/opencore_legacy_patcher/wx_gui/gui_entry.py +++ b/opencore_legacy_patcher/wx_gui/gui_entry.py @@ -47,14 +47,19 @@ class EntryPoint: self.app = wx.App() self.app.SetAppName(self.constants.patcher_name) + # Reference: + # - https://discuss.wxpython.org/t/macos-window-opens-in-the-background-and-does-not-receive-focus/36763/10 + NSApplication.sharedApplication() + NSApp().activateIgnoringOtherApps_(True) - def start(self, entry: SupportedEntryPoints = gui_main_menu.MainFrame) -> None: + + def start(self, entry: SupportedEntryPoints = gui_main_menu.MainFrame, start_patching: bool = False) -> None: """ Launches entry point for the wxPython GUI """ self._generate_base_data() - if "--gui_patch" in sys.argv or "--gui_unpatch" in sys.argv: + if "--gui_patch" in sys.argv or "--gui_unpatch" in sys.argv or start_patching is True : entry = gui_sys_patch_start.SysPatchStartFrame patches = sys_patch_detect.DetectRootPatch(self.constants.computer.real_model, self.constants).detect_patch_set() @@ -68,12 +73,12 @@ class EntryPoint: title=f"{self.constants.patcher_name} {self.constants.patcher_version}{' (Nightly)' if not self.constants.commit_info[0].startswith('refs/tags') else ''}", global_constants=self.constants, screen_location=None, - **({"patches": patches} if "--gui_patch" in sys.argv or "--gui_unpatch" in sys.argv else {}) + **({"patches": patches} if "--gui_patch" in sys.argv or "--gui_unpatch" in sys.argv or start_patching is True else {}) ) atexit.register(self.OnCloseFrame) - if "--gui_patch" in sys.argv: + if "--gui_patch" in sys.argv or start_patching is True: self.frame.start_root_patching() elif "--gui_unpatch" in sys.argv: self.frame.revert_root_patching()