mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-23 11:30:15 +10:00
gui_main.py: Prevent Idle sleep during long processes
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
- Avoids UI elements getting under the dock
|
- Avoids UI elements getting under the dock
|
||||||
- Add return to disk when selecting partitions
|
- Add return to disk when selecting partitions
|
||||||
- Add "Search for disks again" option during OpenCore Install
|
- Add "Search for disks again" option during OpenCore Install
|
||||||
|
- Prevent Idle Sleep while running long processes (ie. downloading, flashing)
|
||||||
- Resolve failing to find binaries with `--patch_sys_vol` argument
|
- Resolve failing to find binaries with `--patch_sys_vol` argument
|
||||||
|
|
||||||
## 0.4.5
|
## 0.4.5
|
||||||
|
|||||||
@@ -106,6 +106,9 @@ class wx_python_gui:
|
|||||||
sys.stderr = self.stock_stderr
|
sys.stderr = self.stock_stderr
|
||||||
self.reset_frame_modal()
|
self.reset_frame_modal()
|
||||||
|
|
||||||
|
# Re-enable sleep if we failed to do so before returning to the main menu
|
||||||
|
utilities.enable_sleep_after_running()
|
||||||
|
|
||||||
def reset_frame_modal(self):
|
def reset_frame_modal(self):
|
||||||
if not self.frame_modal:
|
if not self.frame_modal:
|
||||||
self.frame_modal = wx.Dialog(self.frame)
|
self.frame_modal = wx.Dialog(self.frame)
|
||||||
@@ -1551,6 +1554,7 @@ class wx_python_gui:
|
|||||||
# If we're unable to download the integrity file immediately after downloading the IA, there's a legitmate issue
|
# If we're unable to download the integrity file immediately after downloading the IA, there's a legitmate issue
|
||||||
# on Apple's end.
|
# on Apple's end.
|
||||||
# Fail gracefully and just head to installing the IA.
|
# Fail gracefully and just head to installing the IA.
|
||||||
|
utilities.disable_sleep_while_running()
|
||||||
apple_integrity_file = str(integrity_path)
|
apple_integrity_file = str(integrity_path)
|
||||||
chunks = integrity_verification.generate_chunklist_dict(str(apple_integrity_file))
|
chunks = integrity_verification.generate_chunklist_dict(str(apple_integrity_file))
|
||||||
if chunks:
|
if chunks:
|
||||||
@@ -1600,6 +1604,7 @@ class wx_python_gui:
|
|||||||
self.verifying_chunk_label.Centre(wx.HORIZONTAL)
|
self.verifying_chunk_label.Centre(wx.HORIZONTAL)
|
||||||
self.return_to_main_menu.Bind(wx.EVT_BUTTON, self.flash_installer_menu)
|
self.return_to_main_menu.Bind(wx.EVT_BUTTON, self.flash_installer_menu)
|
||||||
self.return_to_main_menu.Centre(wx.HORIZONTAL)
|
self.return_to_main_menu.Centre(wx.HORIZONTAL)
|
||||||
|
utilities.enable_sleep_after_running()
|
||||||
|
|
||||||
|
|
||||||
def flash_installer_menu(self, event=None):
|
def flash_installer_menu(self, event=None):
|
||||||
@@ -1871,6 +1876,7 @@ class wx_python_gui:
|
|||||||
self.return_to_main_menu.Enable()
|
self.return_to_main_menu.Enable()
|
||||||
|
|
||||||
def start_script(self):
|
def start_script(self):
|
||||||
|
utilities.disable_sleep_while_running()
|
||||||
args = [self.constants.oclp_helper_path, "/bin/sh", self.constants.installer_sh_path]
|
args = [self.constants.oclp_helper_path, "/bin/sh", self.constants.installer_sh_path]
|
||||||
output, error, returncode = run.Run()._stream_output(comm=args)
|
output, error, returncode = run.Run()._stream_output(comm=args)
|
||||||
if "Install media now available at" in output:
|
if "Install media now available at" in output:
|
||||||
@@ -1886,6 +1892,7 @@ class wx_python_gui:
|
|||||||
print("- Failed to create macOS installer")
|
print("- Failed to create macOS installer")
|
||||||
popup = wx.MessageDialog(self.frame, f"Failed to create macOS installer\n\nOutput: {output}\n\nError: {error}", "Error", wx.OK | wx.ICON_ERROR)
|
popup = wx.MessageDialog(self.frame, f"Failed to create macOS installer\n\nOutput: {output}\n\nError: {error}", "Error", wx.OK | wx.ICON_ERROR)
|
||||||
popup.ShowModal()
|
popup.ShowModal()
|
||||||
|
utilities.enable_sleep_after_running()
|
||||||
|
|
||||||
|
|
||||||
def download_and_unzip_pkg(self):
|
def download_and_unzip_pkg(self):
|
||||||
@@ -1908,6 +1915,8 @@ class wx_python_gui:
|
|||||||
path = self.constants.installer_pkg_path
|
path = self.constants.installer_pkg_path
|
||||||
|
|
||||||
if utilities.download_file(link, path):
|
if utilities.download_file(link, path):
|
||||||
|
# Download thread will re-enable Idle Sleep after downloading
|
||||||
|
utilities.disable_sleep_while_running()
|
||||||
if str(path).endswith(".zip"):
|
if str(path).endswith(".zip"):
|
||||||
if Path(self.constants.installer_pkg_path).exists():
|
if Path(self.constants.installer_pkg_path).exists():
|
||||||
subprocess.run(["rm", self.constants.installer_pkg_path])
|
subprocess.run(["rm", self.constants.installer_pkg_path])
|
||||||
|
|||||||
@@ -12,15 +12,8 @@ import binascii
|
|||||||
import argparse
|
import argparse
|
||||||
from ctypes import CDLL, c_uint, byref
|
from ctypes import CDLL, c_uint, byref
|
||||||
import time
|
import time
|
||||||
|
import atexit
|
||||||
try:
|
import requests
|
||||||
import requests
|
|
||||||
except ImportError:
|
|
||||||
subprocess.run(["pip3", "install", "requests"], stdout=subprocess.PIPE)
|
|
||||||
try:
|
|
||||||
import requests
|
|
||||||
except ImportError:
|
|
||||||
raise Exception("Missing requests library!\nPlease run the following before starting OCLP:\npip3 install requests")
|
|
||||||
|
|
||||||
from resources import constants, ioreg
|
from resources import constants, ioreg
|
||||||
from data import sip_data, os_data
|
from data import sip_data, os_data
|
||||||
@@ -135,6 +128,23 @@ def csr_decode(os_sip):
|
|||||||
def friendly_hex(integer: int):
|
def friendly_hex(integer: int):
|
||||||
return "{:02X}".format(integer)
|
return "{:02X}".format(integer)
|
||||||
|
|
||||||
|
sleep_process = None
|
||||||
|
|
||||||
|
def disable_sleep_while_running():
|
||||||
|
global sleep_process
|
||||||
|
print("- Disabling Idle Sleep")
|
||||||
|
if sleep_process is None:
|
||||||
|
# If sleep_process is active, we'll just keep it running
|
||||||
|
sleep_process = subprocess.Popen(["caffeinate", "-d", "-i", "-s"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
# Ensures that if we don't properly close the process, 'atexit' will for us
|
||||||
|
atexit.register(enable_sleep_after_running)
|
||||||
|
|
||||||
|
def enable_sleep_after_running():
|
||||||
|
global sleep_process
|
||||||
|
if sleep_process:
|
||||||
|
print("- Re-enabling Idle Sleep")
|
||||||
|
sleep_process.kill()
|
||||||
|
sleep_process = None
|
||||||
|
|
||||||
def amfi_status():
|
def amfi_status():
|
||||||
amfi_1 = "amfi_get_out_of_my_way=0x1"
|
amfi_1 = "amfi_get_out_of_my_way=0x1"
|
||||||
@@ -362,6 +372,7 @@ def verify_network_connection(url):
|
|||||||
|
|
||||||
def download_file(link, location, is_gui=None, verify_checksum=False):
|
def download_file(link, location, is_gui=None, verify_checksum=False):
|
||||||
if verify_network_connection(link):
|
if verify_network_connection(link):
|
||||||
|
disable_sleep_while_running()
|
||||||
short_link = os.path.basename(link)
|
short_link = os.path.basename(link)
|
||||||
if Path(location).exists():
|
if Path(location).exists():
|
||||||
Path(location).unlink()
|
Path(location).unlink()
|
||||||
@@ -421,7 +432,9 @@ def download_file(link, location, is_gui=None, verify_checksum=False):
|
|||||||
while chunk:
|
while chunk:
|
||||||
checksum.update(chunk)
|
checksum.update(chunk)
|
||||||
chunk = file.read(1024 * 1024 * 16)
|
chunk = file.read(1024 * 1024 * 16)
|
||||||
|
enable_sleep_after_running()
|
||||||
return checksum
|
return checksum
|
||||||
|
enable_sleep_after_running()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
cls()
|
cls()
|
||||||
|
|||||||
Reference in New Issue
Block a user