mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-14 04:38:20 +10:00
GUI: Add app update checks
This commit is contained in:
@@ -5,6 +5,7 @@ import subprocess
|
||||
import webbrowser
|
||||
import logging
|
||||
from pathlib import Path
|
||||
import wx
|
||||
|
||||
from resources import utilities, updates, global_settings, network_handler, constants
|
||||
from resources.sys_patch import sys_patch_detect
|
||||
@@ -42,6 +43,26 @@ class AutomaticSysPatch:
|
||||
logging.info("- Auto Patch option is not supported on TUI, please use GUI")
|
||||
return
|
||||
|
||||
dict = updates.CheckBinaryUpdates(self.constants).check_binary_updates()
|
||||
if dict:
|
||||
for key in dict:
|
||||
version = dict[key]["Version"]
|
||||
logging.info(f"- Found new version: {version}")
|
||||
|
||||
app = wx.App()
|
||||
frame = wx.Frame(None, -1, "OpenCore Legacy Patcher")
|
||||
dialog = wx.MessageDialog(
|
||||
parent=frame,
|
||||
message=f"Current Version: {self.constants.patcher_version}{' (Nightly)' if not self.constants.commit_info[0].startswith('refs/tags') else ''}\nNew version: {version}\nWould you like to update?",
|
||||
caption="Update Available for OpenCore Legacy Patcher!",
|
||||
style=wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION
|
||||
)
|
||||
dialog.SetYesNoCancelLabels("Download and install", "Always Ignore", "Ignore Once")
|
||||
response = dialog.ShowModal()
|
||||
if response == wx.ID_YES:
|
||||
gui_entry.EntryPoint(self.constants).start(entry=gui_entry.SupportedEntryPoints.UPDATE_APP)
|
||||
return
|
||||
|
||||
if utilities.check_seal() is True:
|
||||
logging.info("- Detected Snapshot seal intact, detecting patches")
|
||||
patches = sys_patch_detect.DetectRootPatch(self.constants.computer.real_model, self.constants).detect_patch_set()
|
||||
@@ -58,69 +79,43 @@ class AutomaticSysPatch:
|
||||
for patch in patches:
|
||||
if patches[patch] is True and not patch.startswith("Settings") and not patch.startswith("Validation"):
|
||||
patch_string += f"- {patch}\n"
|
||||
# Check for updates
|
||||
dict = updates.CheckBinaryUpdates(self.constants).check_binary_updates()
|
||||
if not dict:
|
||||
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:
|
||||
warning_str = f"""\n\nWARNING: We're unable to verify whether there are any new releases of OpenCore Legacy Patcher on Github. Be aware that you may be using an outdated version for this OS. If you're unsure, verify on Github that OpenCore Legacy Patcher {self.constants.patcher_version} is the latest official release"""
|
||||
|
||||
args = [
|
||||
"osascript",
|
||||
"-e",
|
||||
f"""display dialog "OpenCore Legacy Patcher has detected you're running without Root Patches, and would like to install them.\n\nmacOS wipes all root patches during OS installs and updates, so they need to be reinstalled.\n\nFollowing Patches have been detected for your system: \n{patch_string}\nWould you like to apply these patches?{warning_str}" """
|
||||
f'with icon POSIX file "{self.constants.app_icon_path}"',
|
||||
]
|
||||
output = subprocess.run(
|
||||
args,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT
|
||||
)
|
||||
if output.returncode == 0:
|
||||
args = [
|
||||
"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
|
||||
)
|
||||
return
|
||||
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:
|
||||
for key in dict:
|
||||
version = dict[key]["Version"]
|
||||
github_link = dict[key]["Github Link"]
|
||||
logging.info(f"- Found new version: {version}")
|
||||
args_string = f"{self.constants.launcher_binary} {self.constants.launcher_script} --gui_patch"
|
||||
|
||||
# launch osascript to ask user if they want to apply the update
|
||||
# if yes, open the link in the default browser
|
||||
# we never want to run the root patcher if there are updates available
|
||||
warning_str = ""
|
||||
if network_handler.NetworkUtilities("https://api.github.com/repos/dortania/OpenCore-Legacy-Patcher/releases/latest").verify_network_connection() is False:
|
||||
warning_str = f"""\n\nWARNING: We're unable to verify whether there are any new releases of OpenCore Legacy Patcher on Github. Be aware that you may be using an outdated version for this OS. If you're unsure, verify on Github that OpenCore Legacy Patcher {self.constants.patcher_version} is the latest official release"""
|
||||
|
||||
args = [
|
||||
"osascript",
|
||||
"-e",
|
||||
f"""display dialog "OpenCore Legacy Patcher has detected you're running without Root Patches, and would like to install them.\n\nmacOS wipes all root patches during OS installs and updates, so they need to be reinstalled.\n\nFollowing Patches have been detected for your system: \n{patch_string}\nWould you like to apply these patches?{warning_str}" """
|
||||
f'with icon POSIX file "{self.constants.app_icon_path}"',
|
||||
]
|
||||
output = subprocess.run(
|
||||
args,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT
|
||||
)
|
||||
if output.returncode == 0:
|
||||
args = [
|
||||
"osascript",
|
||||
"-e",
|
||||
f"""display dialog "OpenCore Legacy Patcher has detected you're running without Root Patches, and would like to install them.\n\nHowever we've detected a new version of OCLP on Github. Would you like to view this?\n\nCurrent Version: {self.constants.patcher_version}\nLatest Version: {version}\n\nNote: After downloading the latest OCLP version, open the app and run the 'Post Install Root Patcher' from the main menu." """
|
||||
f'with icon POSIX file "{self.constants.app_icon_path}"',
|
||||
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"
|
||||
]
|
||||
output = subprocess.run(
|
||||
subprocess.run(
|
||||
args,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT
|
||||
)
|
||||
if output.returncode == 0:
|
||||
webbrowser.open(github_link)
|
||||
|
||||
return
|
||||
return
|
||||
else:
|
||||
logging.info("- No patches detected")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user