From 3e0c329e533de5519d8e6c116e4fab203b7da6b9 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Thu, 28 Sep 2023 21:31:55 -0400 Subject: [PATCH 1/6] Add main menu portion --- resources/wx_gui/gui_main_menu.py | 95 +++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/resources/wx_gui/gui_main_menu.py b/resources/wx_gui/gui_main_menu.py index 8e5960357..fc023f00d 100644 --- a/resources/wx_gui/gui_main_menu.py +++ b/resources/wx_gui/gui_main_menu.py @@ -1,5 +1,8 @@ # Generate GUI for main menu import wx +import wx.html2 +import markdown2 +import requests import sys import logging import threading @@ -271,7 +274,7 @@ class MainFrame(wx.Frame): def _check_for_updates(self): if self.constants.has_checked_updates is True: return - + ignore_updates = global_settings.GlobalEnviromentSettings().read_property("IgnoreAppUpdates") if ignore_updates is True: self.constants.ignore_updates = True @@ -285,20 +288,8 @@ class MainFrame(wx.Frame): version = dict["Version"] logging.info(f"New version: {version}") - dialog = wx.MessageDialog( - parent=self, - 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", "Ignore", "View on Github") - response = dialog.ShowModal() - - if response == wx.ID_YES: - wx.CallAfter(self.on_update, dict["Link"], version) - elif response == wx.ID_CANCEL: - webbrowser.open(dict["Github Link"]) - + + wx.CallAfter(self.on_update, dict["Link"], version, dict["Github Link"]) def on_build_and_install(self, event: wx.Event = None): self.Hide() @@ -345,7 +336,79 @@ class MainFrame(wx.Frame): screen_location=self.GetPosition() ) - def on_update(self, oclp_url: str, oclp_version: str): + def on_update(self, oclp_url: str, oclp_version: str, oclp_github_url: str): + + url = f"https://raw.githubusercontent.com/dortania/OpenCore-Legacy-Patcher/{oclp_version}/CHANGELOG.md" + response = requests.get(url) + changelog = response.text.split(f"## {self.constants.patcher_version}\n")[0] + + html_markdown = markdown2.markdown(changelog) + html_css = """ + +""" + frame = wx.Frame(None, -1, title="", size=(600, 400)) + frame.SetMinSize((600, 400)) + frame.SetWindowStyle(wx.STAY_ON_TOP) + panel = wx.Panel(frame) + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.AddSpacer(10) + self.title_text = wx.StaticText(panel, label="A new version of OpenCore Legacy Patcher is available!") + self.description = wx.StaticText(panel, label=f"OpenCore Legacy Patcher {oclp_version} is now available - You have {self.constants.patcher_version}. Would you like to update?") + self.title_text.SetFont(wx.Font(19, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, ".AppleSystemUIFont")) + self.description.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont")) + self.web_view = wx.html2.WebView.New(panel, style=wx.BORDER_SUNKEN) + html_code = html_css+html_markdown.replace("OpenCore Legacy Patcher changelog", "") + self.web_view.SetPage(html_code, "") + self.web_view.Bind(wx.html2.EVT_WEBVIEW_NEWWINDOW, self._onWebviewNav) + self.web_view.EnableContextMenu(False) + self.close_button = wx.Button(panel, label="Ignore") + self.close_button.Bind(wx.EVT_BUTTON, lambda event: frame.Close()) + self.view_button = wx.Button(panel, label="View on GitHub") + self.view_button.Bind(wx.EVT_BUTTON, lambda event: (webbrowser.open(oclp_github_url), frame.Close())) + self.install_button = wx.Button(panel, label="Download and Install") + self.install_button.Bind(wx.EVT_BUTTON, lambda event: self._onUpdateChosen(frame, oclp_url, oclp_version)) + self.install_button.SetDefault() + + buttonsizer = wx.BoxSizer(wx.HORIZONTAL) + buttonsizer.Add(self.close_button, 0, wx.ALIGN_CENTRE | wx.RIGHT, 5) + buttonsizer.Add(self.view_button, 0, wx.ALIGN_CENTRE | wx.LEFT|wx.RIGHT, 5) + buttonsizer.Add(self.install_button, 0, wx.ALIGN_CENTRE | wx.LEFT, 5) + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(self.title_text, 0, wx.ALIGN_CENTRE | wx.TOP, 20) + sizer.Add(self.description, 0, wx.ALIGN_CENTRE | wx.BOTTOM, 20) + sizer.Add(self.web_view, 1, wx.EXPAND | wx.LEFT|wx.RIGHT, 10) + sizer.Add(buttonsizer, 0, wx.ALIGN_RIGHT | wx.ALL, 20) + panel.SetSizer(sizer) + frame.Show() + + def _onWebviewNav(self, event): + url = event.GetURL() + webbrowser.open(url) + + def _onUpdateChosen(self, frame, oclp_url, oclp_version): + frame.Close() gui_update.UpdateFrame( parent=self, title=self.title, From 25f5ea24570a2755b34f03515f6b215b406a1dd0 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Thu, 28 Sep 2023 22:02:26 -0400 Subject: [PATCH 2/6] Adjust requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a79dd44b2..a802b0603 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ wxpython pyinstaller packaging py_sip_xnu -py-applescript \ No newline at end of file +py-applescript +markdown2 \ No newline at end of file From ce0928ba38782dc331e294729e8f4362f3e456c6 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Fri, 29 Sep 2023 17:51:51 -0400 Subject: [PATCH 3/6] Changes --- resources/utilities.py | 4 ++-- resources/wx_gui/gui_download.py | 8 ++++++-- resources/wx_gui/gui_main_menu.py | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/resources/utilities.py b/resources/utilities.py index 9c866e948..803af348b 100644 --- a/resources/utilities.py +++ b/resources/utilities.py @@ -60,8 +60,8 @@ def seconds_to_readable_time(seconds) -> str: seconds = int(seconds) time = "" - if seconds == 0: - return "0m " + if seconds < 60: + return "Less than a minute " if seconds < 0: return "Indeterminate time " diff --git a/resources/wx_gui/gui_download.py b/resources/wx_gui/gui_download.py index e1d77d42f..8e456ab18 100644 --- a/resources/wx_gui/gui_download.py +++ b/resources/wx_gui/gui_download.py @@ -50,7 +50,7 @@ class DownloadFrame(wx.Frame): title_label.SetFont(gui_support.font_factory(19, wx.FONTWEIGHT_BOLD)) title_label.Centre(wx.HORIZONTAL) - progress_bar = wx.Gauge(frame, range=100, pos=(-1, title_label.GetPosition()[1] + title_label.GetSize()[1] + 5), size=(300, 20)) + progress_bar = wx.Gauge(frame, range=100, pos=(-1, title_label.GetPosition()[1] + title_label.GetSize()[1] + 5), size=(300, 20), style=wx.GA_SMOOTH|wx.GA_PROGRESS) progress_bar.Centre(wx.HORIZONTAL) label_amount = wx.StaticText(frame, label="Preparing download", pos=(-1, progress_bar.GetPosition()[1] + progress_bar.GetSize()[1])) @@ -68,7 +68,11 @@ class DownloadFrame(wx.Frame): self.download_obj.download() while self.download_obj.is_active(): - percentage: int = self.download_obj.get_percent() + percentage: int = round(self.download_obj.get_percent()) + if percentage == 0: + percentage = 1 + + logging.info(f"Download progress: {percentage}%") if percentage == -1: amount_str = f"{utilities.human_fmt(self.download_obj.downloaded_file_size)} downloaded ({utilities.human_fmt(self.download_obj.get_speed())}/s)" diff --git a/resources/wx_gui/gui_main_menu.py b/resources/wx_gui/gui_main_menu.py index fc023f00d..bafdf1344 100644 --- a/resources/wx_gui/gui_main_menu.py +++ b/resources/wx_gui/gui_main_menu.py @@ -402,6 +402,7 @@ class MainFrame(wx.Frame): sizer.Add(buttonsizer, 0, wx.ALIGN_RIGHT | wx.ALL, 20) panel.SetSizer(sizer) frame.Show() + frame.Centre() def _onWebviewNav(self, event): url = event.GetURL() From 3bf92c35875feeab4c757af276b5ed6d0e8221f7 Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Fri, 29 Sep 2023 17:54:28 -0400 Subject: [PATCH 4/6] Remove logging --- resources/wx_gui/gui_download.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/wx_gui/gui_download.py b/resources/wx_gui/gui_download.py index 8e456ab18..fb5a45656 100644 --- a/resources/wx_gui/gui_download.py +++ b/resources/wx_gui/gui_download.py @@ -71,8 +71,6 @@ class DownloadFrame(wx.Frame): percentage: int = round(self.download_obj.get_percent()) if percentage == 0: percentage = 1 - - logging.info(f"Download progress: {percentage}%") if percentage == -1: amount_str = f"{utilities.human_fmt(self.download_obj.downloaded_file_size)} downloaded ({utilities.human_fmt(self.download_obj.get_speed())}/s)" From 526594a90d3d5d2e7595ef061e9ef0fceb881dfa Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Wed, 4 Oct 2023 17:12:51 -0400 Subject: [PATCH 5/6] Fix up --- resources/sys_patch/sys_patch_auto.py | 97 +++++++++++++++++++++++---- resources/wx_gui/gui_main_menu.py | 34 ++++++---- 2 files changed, 106 insertions(+), 25 deletions(-) diff --git a/resources/sys_patch/sys_patch_auto.py b/resources/sys_patch/sys_patch_auto.py index 0c275919a..eefe3e61d 100644 --- a/resources/sys_patch/sys_patch_auto.py +++ b/resources/sys_patch/sys_patch_auto.py @@ -1,6 +1,10 @@ # Copyright (C) 2022, Mykola Grymalyuk +# Copyright (c) 2023 Jazzzny import wx +import wx.html2 +import requests +import markdown2 import logging import plistlib import subprocess @@ -51,19 +55,85 @@ class AutomaticSysPatch: 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", "View on Github", "Ignore") - response = dialog.ShowModal() - if response == wx.ID_YES: - gui_entry.EntryPoint(self.constants).start(entry=gui_entry.SupportedEntryPoints.UPDATE_APP) - elif response == wx.ID_NO: + mainframe = wx.Frame(None, -1, "OpenCore Legacy Patcher") + + ID_GITHUB = wx.NewId() + ID_UPDATE = wx.NewId() + + url = f"https://raw.githubusercontent.com/dortania/OpenCore-Legacy-Patcher/{version}/CHANGELOG.md" + response = requests.get(url) + changelog = response.text.split(f"## {self.constants.patcher_version}\n")[0] + + html_markdown = markdown2.markdown(changelog) + html_css = """ + + """ + frame = wx.Dialog(None, -1, title="", size=(600, 400)) + frame.SetMinSize((600, 400)) + frame.SetWindowStyle(wx.STAY_ON_TOP) + panel = wx.Panel(frame) + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.AddSpacer(10) + self.title_text = wx.StaticText(panel, label="A new version of OpenCore Legacy Patcher is available!") + self.description = wx.StaticText(panel, label=f"OpenCore Legacy Patcher {version} is now available - You have {self.constants.patcher_version}. Would you like to update?") + self.title_text.SetFont(wx.Font(19, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, ".AppleSystemUIFont")) + self.description.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont")) + self.web_view = wx.html2.WebView.New(panel, style=wx.BORDER_SUNKEN) + html_code = html_css+html_markdown.replace("OpenCore Legacy Patcher changelog", "") + self.web_view.SetPage(html_code, "") + self.web_view.Bind(wx.html2.EVT_WEBVIEW_NEWWINDOW, self._onWebviewNav) + self.web_view.EnableContextMenu(False) + self.close_button = wx.Button(panel, label="Ignore") + self.close_button.Bind(wx.EVT_BUTTON, lambda event: frame.EndModal(wx.ID_CANCEL)) + self.view_button = wx.Button(panel, ID_GITHUB, label="View on GitHub") + self.view_button.Bind(wx.EVT_BUTTON, lambda event: frame.EndModal(ID_GITHUB)) + self.install_button = wx.Button(panel, label="Download and Install") + self.install_button.Bind(wx.EVT_BUTTON, lambda event: frame.EndModal(ID_UPDATE)) + self.install_button.SetDefault() + + buttonsizer = wx.BoxSizer(wx.HORIZONTAL) + buttonsizer.Add(self.close_button, 0, wx.ALIGN_CENTRE | wx.RIGHT, 5) + buttonsizer.Add(self.view_button, 0, wx.ALIGN_CENTRE | wx.LEFT|wx.RIGHT, 5) + buttonsizer.Add(self.install_button, 0, wx.ALIGN_CENTRE | wx.LEFT, 5) + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(self.title_text, 0, wx.ALIGN_CENTRE | wx.TOP, 20) + sizer.Add(self.description, 0, wx.ALIGN_CENTRE | wx.BOTTOM, 20) + sizer.Add(self.web_view, 1, wx.EXPAND | wx.LEFT|wx.RIGHT, 10) + sizer.Add(buttonsizer, 0, wx.ALIGN_RIGHT | wx.ALL, 20) + panel.SetSizer(sizer) + frame.Centre() + + result = frame.ShowModal() + + + if result == ID_GITHUB: webbrowser.open(dict["Github Link"]) + elif result == ID_UPDATE: + gui_entry.EntryPoint(self.constants).start(entry=gui_entry.SupportedEntryPoints.UPDATE_APP) + + return if utilities.check_seal() is True: @@ -127,6 +197,9 @@ class AutomaticSysPatch: if self._determine_if_versions_match(): self._determine_if_boot_matches() + def _onWebviewNav(self, event): + url = event.GetURL() + webbrowser.open(url) def _determine_if_versions_match(self): """ diff --git a/resources/wx_gui/gui_main_menu.py b/resources/wx_gui/gui_main_menu.py index bafdf1344..0ebf0b538 100644 --- a/resources/wx_gui/gui_main_menu.py +++ b/resources/wx_gui/gui_main_menu.py @@ -1,4 +1,6 @@ # Generate GUI for main menu +# Portions of this file Copyright (c) 2023 Jazzzny + import wx import wx.html2 import markdown2 @@ -338,6 +340,9 @@ class MainFrame(wx.Frame): def on_update(self, oclp_url: str, oclp_version: str, oclp_github_url: str): + ID_GITHUB = wx.NewId() + ID_UPDATE = wx.NewId() + url = f"https://raw.githubusercontent.com/dortania/OpenCore-Legacy-Patcher/{oclp_version}/CHANGELOG.md" response = requests.get(url) changelog = response.text.split(f"## {self.constants.patcher_version}\n")[0] @@ -368,7 +373,7 @@ class MainFrame(wx.Frame): } """ - frame = wx.Frame(None, -1, title="", size=(600, 400)) + frame = wx.Dialog(None, -1, title="", size=(600, 400)) frame.SetMinSize((600, 400)) frame.SetWindowStyle(wx.STAY_ON_TOP) panel = wx.Panel(frame) @@ -384,11 +389,11 @@ class MainFrame(wx.Frame): self.web_view.Bind(wx.html2.EVT_WEBVIEW_NEWWINDOW, self._onWebviewNav) self.web_view.EnableContextMenu(False) self.close_button = wx.Button(panel, label="Ignore") - self.close_button.Bind(wx.EVT_BUTTON, lambda event: frame.Close()) - self.view_button = wx.Button(panel, label="View on GitHub") - self.view_button.Bind(wx.EVT_BUTTON, lambda event: (webbrowser.open(oclp_github_url), frame.Close())) + self.close_button.Bind(wx.EVT_BUTTON, lambda event: frame.EndModal(wx.ID_CANCEL)) + self.view_button = wx.Button(panel, ID_GITHUB, label="View on GitHub") + self.view_button.Bind(wx.EVT_BUTTON, lambda event: frame.EndModal(ID_GITHUB)) self.install_button = wx.Button(panel, label="Download and Install") - self.install_button.Bind(wx.EVT_BUTTON, lambda event: self._onUpdateChosen(frame, oclp_url, oclp_version)) + self.install_button.Bind(wx.EVT_BUTTON, lambda event: frame.EndModal(ID_UPDATE)) self.install_button.SetDefault() buttonsizer = wx.BoxSizer(wx.HORIZONTAL) @@ -401,20 +406,23 @@ class MainFrame(wx.Frame): sizer.Add(self.web_view, 1, wx.EXPAND | wx.LEFT|wx.RIGHT, 10) sizer.Add(buttonsizer, 0, wx.ALIGN_RIGHT | wx.ALL, 20) panel.SetSizer(sizer) - frame.Show() frame.Centre() - def _onWebviewNav(self, event): - url = event.GetURL() - webbrowser.open(url) + result = frame.ShowModal() + - def _onUpdateChosen(self, frame, oclp_url, oclp_version): - frame.Close() - gui_update.UpdateFrame( + if result == ID_GITHUB: + webbrowser.open(oclp_github_url) + elif result == ID_UPDATE: + gui_update.UpdateFrame( parent=self, title=self.title, global_constants=self.constants, screen_location=self.GetPosition(), url=oclp_url, version_label=oclp_version - ) \ No newline at end of file + ) + + def _onWebviewNav(self, event): + url = event.GetURL() + webbrowser.open(url) \ No newline at end of file From 4429b5cb4b0d4333c29c4e8a8957b9ac3a2b394b Mon Sep 17 00:00:00 2001 From: Jazzzny Date: Wed, 4 Oct 2023 18:01:05 -0400 Subject: [PATCH 6/6] Changes --- resources/sys_patch/sys_patch_auto.py | 12 ++++++------ resources/wx_gui/gui_main_menu.py | 15 +++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/resources/sys_patch/sys_patch_auto.py b/resources/sys_patch/sys_patch_auto.py index eefe3e61d..d6276de29 100644 --- a/resources/sys_patch/sys_patch_auto.py +++ b/resources/sys_patch/sys_patch_auto.py @@ -60,9 +60,9 @@ class AutomaticSysPatch: ID_GITHUB = wx.NewId() ID_UPDATE = wx.NewId() - url = f"https://raw.githubusercontent.com/dortania/OpenCore-Legacy-Patcher/{version}/CHANGELOG.md" - response = requests.get(url) - changelog = response.text.split(f"## {self.constants.patcher_version}\n")[0] + url = "https://api.github.com/repos/dortania/OpenCore-Legacy-Patcher/releases/latest" + response = requests.get(url).json() + changelog = response["body"].split("## Asset Information")[0] html_markdown = markdown2.markdown(changelog) html_css = """ @@ -90,8 +90,8 @@ class AutomaticSysPatch: } """ - frame = wx.Dialog(None, -1, title="", size=(600, 400)) - frame.SetMinSize((600, 400)) + frame = wx.Dialog(None, -1, title="", size=(600, 500)) + frame.SetMinSize((600, 500)) frame.SetWindowStyle(wx.STAY_ON_TOP) panel = wx.Panel(frame) sizer = wx.BoxSizer(wx.VERTICAL) @@ -101,7 +101,7 @@ class AutomaticSysPatch: self.title_text.SetFont(wx.Font(19, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, ".AppleSystemUIFont")) self.description.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont")) self.web_view = wx.html2.WebView.New(panel, style=wx.BORDER_SUNKEN) - html_code = html_css+html_markdown.replace("OpenCore Legacy Patcher changelog", "") + html_code = html_css+html_markdown.replace(" """ - frame = wx.Dialog(None, -1, title="", size=(600, 400)) - frame.SetMinSize((600, 400)) + frame = wx.Dialog(None, -1, title="", size=(600, 500)) + frame.SetMinSize((600, 500)) frame.SetWindowStyle(wx.STAY_ON_TOP) panel = wx.Panel(frame) sizer = wx.BoxSizer(wx.VERTICAL) @@ -384,11 +383,11 @@ class MainFrame(wx.Frame): self.title_text.SetFont(wx.Font(19, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, ".AppleSystemUIFont")) self.description.SetFont(wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, ".AppleSystemUIFont")) self.web_view = wx.html2.WebView.New(panel, style=wx.BORDER_SUNKEN) - html_code = html_css+html_markdown.replace("OpenCore Legacy Patcher changelog", "") + html_code = html_css+html_markdown.replace("