Implement callback

This commit is contained in:
Mykola Grymalyuk
2023-05-06 21:10:53 -06:00
parent f3e2dfc4de
commit f8b2b5a759
6 changed files with 60 additions and 22 deletions

View File

@@ -7,6 +7,7 @@ import plistlib
import shutil import shutil
import zipfile import zipfile
import logging import logging
import time
from pathlib import Path from pathlib import Path
from datetime import date from datetime import date
@@ -145,6 +146,8 @@ class BuildOpenCore:
support.BuildSupport(self.model, self.constants, self.config).cleanup() support.BuildSupport(self.model, self.constants, self.config).cleanup()
self._save_config() self._save_config()
time.sleep(5)
# Post-build handling # Post-build handling
support.BuildSupport(self.model, self.constants, self.config).sign_files() support.BuildSupport(self.model, self.constants, self.config).sign_files()
support.BuildSupport(self.model, self.constants, self.config).validate_pathing() support.BuildSupport(self.model, self.constants, self.config).validate_pathing()

View File

@@ -100,6 +100,8 @@ class tui_disk_installation:
" without altering line endings", " 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: 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) result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else: else:
@@ -128,8 +130,6 @@ class tui_disk_installation:
ssd_type = False ssd_type = False
mount_path = Path(partition_info["MountPoint"]) mount_path = Path(partition_info["MountPoint"])
disk_type = partition_info["BusProtocol"] disk_type = partition_info["BusProtocol"]
utilities.cls()
utilities.header(["Copying OpenCore"])
if mount_path.exists(): if mount_path.exists():
if (mount_path / Path("EFI/Microsoft")).exists() and self.constants.gui_mode is False: if (mount_path / Path("EFI/Microsoft")).exists() and self.constants.gui_mode is False:

View File

@@ -76,13 +76,23 @@ class BuildFrame(wx.Frame):
def _invoke_build(self): 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 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) build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants)
logging.getLogger().handlers[0].stream = self.stock_output logger.removeHandler(logger.handlers[2])
self.install_button.Enable()
def on_return_to_main_menu(self, event): def on_return_to_main_menu(self, event):

View File

@@ -15,6 +15,7 @@ class InstallOCFrame(wx.Frame):
self.constants: constants.Constants = global_constants self.constants: constants.Constants = global_constants
self.title: str = title self.title: str = title
self.result: bool = False
self.available_disks: dict = None self.available_disks: dict = None
self.stock_output = logging.getLogger().handlers[0].stream self.stock_output = logging.getLogger().handlers[0].stream
@@ -220,20 +221,19 @@ class InstallOCFrame(wx.Frame):
self.dialog = dialog self.dialog = dialog
# Install OpenCore # Install OpenCore
self._install_oc(partition) self._invoke_install_oc(partition)
return_button.Enable() return_button.Enable()
def _install_oc(self, partition: dict) -> None: def _invoke_install_oc(self, partition: dict) -> None:
""" thread = threading.Thread(target=self._install_oc, args=(partition,))
Install OpenCore to disk thread.start()
"""
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
if result is True: while thread.is_alive():
# wx.Yield()
wx.GetApp().Yield()
if self.result is True:
if not self.constants.custom_model: 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?") 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: else:
@@ -245,6 +245,18 @@ class InstallOCFrame(wx.Frame):
popup_message.ShowModal() 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: def _reload_frame(self, event) -> None:
""" """
Reload frame Reload frame

View File

@@ -8,6 +8,16 @@ import subprocess
from resources import constants 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): class RedirectText(object):
""" """
Redirects stdout to a wxPython TextCtrl Redirects stdout to a wxPython TextCtrl

View File

@@ -20,13 +20,13 @@ class SysPatchMenu(wx.Frame):
Uses a Modal Dialog for smoother transition from other frames 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): 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.title = title
self.constants: constants.Constants = global_constants self.constants: constants.Constants = global_constants
self.frame_modal: wx.Dialog = None 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) self._generate_elements(self.frame_modal)
@@ -116,26 +116,29 @@ class SysPatchMenu(wx.Frame):
# Button: Start Root Patching # 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.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.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont"))
start_button.Center(wx.HORIZONTAL) start_button.Center(wx.HORIZONTAL)
# Button: Revert Root Patches # Button: Revert Root Patches
revert_button = wx.Button(frame, label="Revert Root Patches", pos=(10, start_button.GetPosition().y + start_button.GetSize().height - 5 revert_button = wx.Button(frame, label="Revert Root Patches", pos=(10, start_button.GetPosition().y + start_button.GetSize().height - 5), size=(170, 30))
), size=(170, 30))
revert_button.Bind(wx.EVT_BUTTON, lambda event: self._revert_root_patching(frame, patches, can_unpatch)) 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.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont"))
revert_button.Center(wx.HORIZONTAL) revert_button.Center(wx.HORIZONTAL)
# Button: Return to Main Menu # 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.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.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont"))
return_button.Center(wx.HORIZONTAL) return_button.Center(wx.HORIZONTAL)
if not patches:
start_button.Disable()
revert_button.Disable()
# Set frame size # 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))