mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-17 13:22:54 +10:00
Implement callback
This commit is contained in:
@@ -7,6 +7,7 @@ import plistlib
|
||||
import shutil
|
||||
import zipfile
|
||||
import logging
|
||||
import time
|
||||
|
||||
from pathlib import Path
|
||||
from datetime import date
|
||||
@@ -145,6 +146,8 @@ class BuildOpenCore:
|
||||
support.BuildSupport(self.model, self.constants, self.config).cleanup()
|
||||
self._save_config()
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
# Post-build handling
|
||||
support.BuildSupport(self.model, self.constants, self.config).sign_files()
|
||||
support.BuildSupport(self.model, self.constants, self.config).validate_pathing()
|
||||
|
||||
@@ -100,6 +100,8 @@ class tui_disk_installation:
|
||||
" without altering line endings",
|
||||
]
|
||||
|
||||
logging.info(f"- Mounting partition: {full_disk_identifier}")
|
||||
|
||||
if self.constants.detected_os >= os_data.os_data.el_capitan and not self.constants.recovery_status:
|
||||
result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
else:
|
||||
@@ -128,8 +130,6 @@ class tui_disk_installation:
|
||||
ssd_type = False
|
||||
mount_path = Path(partition_info["MountPoint"])
|
||||
disk_type = partition_info["BusProtocol"]
|
||||
utilities.cls()
|
||||
utilities.header(["Copying OpenCore"])
|
||||
|
||||
if mount_path.exists():
|
||||
if (mount_path / Path("EFI/Microsoft")).exists() and self.constants.gui_mode is False:
|
||||
|
||||
@@ -76,13 +76,23 @@ class BuildFrame(wx.Frame):
|
||||
|
||||
|
||||
def _invoke_build(self):
|
||||
thread = threading.Thread(target=self._build)
|
||||
thread.start()
|
||||
|
||||
while thread.is_alive():
|
||||
wx.Yield()
|
||||
|
||||
self.install_button.Enable()
|
||||
|
||||
|
||||
def _build(self):
|
||||
"""
|
||||
Calls build function and redirects stdout to the text box
|
||||
"""
|
||||
logging.getLogger().handlers[0].stream = gui_support.RedirectText(self.text_box, False)
|
||||
logger = logging.getLogger()
|
||||
logger.addHandler(gui_support.ThreadHandler(self.text_box))
|
||||
build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants)
|
||||
logging.getLogger().handlers[0].stream = self.stock_output
|
||||
self.install_button.Enable()
|
||||
logger.removeHandler(logger.handlers[2])
|
||||
|
||||
|
||||
def on_return_to_main_menu(self, event):
|
||||
|
||||
@@ -15,6 +15,7 @@ class InstallOCFrame(wx.Frame):
|
||||
|
||||
self.constants: constants.Constants = global_constants
|
||||
self.title: str = title
|
||||
self.result: bool = False
|
||||
|
||||
self.available_disks: dict = None
|
||||
self.stock_output = logging.getLogger().handlers[0].stream
|
||||
@@ -220,20 +221,19 @@ class InstallOCFrame(wx.Frame):
|
||||
self.dialog = dialog
|
||||
|
||||
# Install OpenCore
|
||||
self._install_oc(partition)
|
||||
self._invoke_install_oc(partition)
|
||||
return_button.Enable()
|
||||
|
||||
|
||||
def _install_oc(self, partition: dict) -> None:
|
||||
"""
|
||||
Install OpenCore to disk
|
||||
"""
|
||||
logging.info(f"- Installing OpenCore to {partition}")
|
||||
logging.getLogger().handlers[0].stream = gui_support.RedirectText(self.text_box, False)
|
||||
result = install.tui_disk_installation(self.constants).install_opencore(partition)
|
||||
logging.getLogger().handlers[0].stream = self.stock_output
|
||||
def _invoke_install_oc(self, partition: dict) -> None:
|
||||
thread = threading.Thread(target=self._install_oc, args=(partition,))
|
||||
thread.start()
|
||||
|
||||
if result is True:
|
||||
while thread.is_alive():
|
||||
# wx.Yield()
|
||||
wx.GetApp().Yield()
|
||||
|
||||
if self.result is True:
|
||||
if not self.constants.custom_model:
|
||||
gui_support.RestartHost(self).restart(message="OpenCore has finished installing to disk.\n\nYou will need to reboot and hold the Option key and select OpenCore/Boot EFI's option.\n\nWould you like to reboot?")
|
||||
else:
|
||||
@@ -245,6 +245,18 @@ class InstallOCFrame(wx.Frame):
|
||||
popup_message.ShowModal()
|
||||
|
||||
|
||||
def _install_oc(self, partition: dict) -> None:
|
||||
"""
|
||||
Install OpenCore to disk
|
||||
"""
|
||||
logging.info(f"- Installing OpenCore to {partition}")
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.addHandler(gui_support.ThreadHandler(self.text_box))
|
||||
self.result = install.tui_disk_installation(self.constants).install_opencore(partition)
|
||||
logger.removeHandler(logger.handlers[2])
|
||||
|
||||
|
||||
def _reload_frame(self, event) -> None:
|
||||
"""
|
||||
Reload frame
|
||||
|
||||
@@ -8,6 +8,16 @@ import subprocess
|
||||
|
||||
from resources import constants
|
||||
|
||||
|
||||
class ThreadHandler(logging.Handler):
|
||||
def __init__(self, text_box: wx.TextCtrl):
|
||||
logging.Handler.__init__(self)
|
||||
self.text_box = text_box
|
||||
|
||||
def emit(self, record):
|
||||
wx.CallAfter(self.text_box.AppendText, self.format(record) + '\n')
|
||||
|
||||
|
||||
class RedirectText(object):
|
||||
"""
|
||||
Redirects stdout to a wxPython TextCtrl
|
||||
|
||||
@@ -20,13 +20,13 @@ class SysPatchMenu(wx.Frame):
|
||||
Uses a Modal Dialog for smoother transition from other frames
|
||||
"""
|
||||
def __init__(self, parent: wx.Frame, title: str, global_constants: constants.Constants, screen_location: tuple = None):
|
||||
super(SysPatchMenu, self).__init__(parent, title=title, size=(350, 250))
|
||||
super(SysPatchMenu, self).__init__(parent, title=title, size=(350, 260))
|
||||
|
||||
self.title = title
|
||||
self.constants: constants.Constants = global_constants
|
||||
self.frame_modal: wx.Dialog = None
|
||||
|
||||
self.frame_modal = wx.Dialog(self, title=title, size=(370, 200))
|
||||
self.frame_modal = wx.Dialog(self, title=title, size=(360, 200))
|
||||
|
||||
self._generate_elements(self.frame_modal)
|
||||
|
||||
@@ -116,26 +116,29 @@ class SysPatchMenu(wx.Frame):
|
||||
|
||||
|
||||
# Button: Start Root Patching
|
||||
start_button = wx.Button(frame, label="Start Root Patching", pos=(10, patch_label.GetPosition().y + 40), size=(170, 30))
|
||||
start_button = wx.Button(frame, label="Start Root Patching", pos=(10, patch_label.GetPosition().y + 20), size=(170, 30))
|
||||
start_button.Bind(wx.EVT_BUTTON, lambda event: self._start_root_patching(frame, patches, no_new_patches))
|
||||
start_button.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont"))
|
||||
start_button.Center(wx.HORIZONTAL)
|
||||
|
||||
# Button: Revert Root Patches
|
||||
revert_button = wx.Button(frame, label="Revert Root Patches", pos=(10, start_button.GetPosition().y + start_button.GetSize().height - 5
|
||||
), size=(170, 30))
|
||||
revert_button = wx.Button(frame, label="Revert Root Patches", pos=(10, start_button.GetPosition().y + start_button.GetSize().height - 5), size=(170, 30))
|
||||
revert_button.Bind(wx.EVT_BUTTON, lambda event: self._revert_root_patching(frame, patches, can_unpatch))
|
||||
revert_button.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont"))
|
||||
revert_button.Center(wx.HORIZONTAL)
|
||||
|
||||
# Button: Return to Main Menu
|
||||
return_button = wx.Button(frame, label="Return to Main Menu", pos=(10, revert_button.GetPosition().y + revert_button.GetSize().height + 10), size=(150, 30))
|
||||
return_button = wx.Button(frame, label="Return to Main Menu", pos=(10, revert_button.GetPosition().y + revert_button.GetSize().height), size=(150, 30))
|
||||
return_button.Bind(wx.EVT_BUTTON, self.on_return_to_main_menu)
|
||||
return_button.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont"))
|
||||
return_button.Center(wx.HORIZONTAL)
|
||||
|
||||
if not patches:
|
||||
start_button.Disable()
|
||||
revert_button.Disable()
|
||||
|
||||
# Set frame size
|
||||
frame.SetSize((-1, return_button.GetPosition().y + return_button.GetSize().height + 40))
|
||||
frame.SetSize((-1, return_button.GetPosition().y + return_button.GetSize().height + 35))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user