mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-19 13:46:05 +10:00
Merge pull request #1105 from Jazzzny/readme-update
GUI - Refresh update menu
This commit is contained in:
@@ -4,4 +4,5 @@ wxpython
|
|||||||
pyinstaller
|
pyinstaller
|
||||||
packaging
|
packaging
|
||||||
py_sip_xnu
|
py_sip_xnu
|
||||||
py-applescript
|
py-applescript
|
||||||
|
markdown2
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
# Copyright (C) 2022, Mykola Grymalyuk
|
# Copyright (C) 2022, Mykola Grymalyuk
|
||||||
|
# Copyright (c) 2023 Jazzzny
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
|
import wx.html2
|
||||||
|
import requests
|
||||||
|
import markdown2
|
||||||
import logging
|
import logging
|
||||||
import plistlib
|
import plistlib
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -51,19 +55,85 @@ class AutomaticSysPatch:
|
|||||||
logging.info(f"- Found new version: {version}")
|
logging.info(f"- Found new version: {version}")
|
||||||
|
|
||||||
app = wx.App()
|
app = wx.App()
|
||||||
frame = wx.Frame(None, -1, "OpenCore Legacy Patcher")
|
mainframe = wx.Frame(None, -1, "OpenCore Legacy Patcher")
|
||||||
dialog = wx.MessageDialog(
|
|
||||||
parent=frame,
|
ID_GITHUB = wx.NewId()
|
||||||
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?",
|
ID_UPDATE = wx.NewId()
|
||||||
caption="Update Available for OpenCore Legacy Patcher!",
|
|
||||||
style=wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION
|
url = "https://api.github.com/repos/dortania/OpenCore-Legacy-Patcher/releases/latest"
|
||||||
)
|
response = requests.get(url).json()
|
||||||
dialog.SetYesNoCancelLabels("Download and install", "View on Github", "Ignore")
|
changelog = response["body"].split("## Asset Information")[0]
|
||||||
response = dialog.ShowModal()
|
|
||||||
if response == wx.ID_YES:
|
html_markdown = markdown2.markdown(changelog)
|
||||||
gui_entry.EntryPoint(self.constants).start(entry=gui_entry.SupportedEntryPoints.UPDATE_APP)
|
html_css = """
|
||||||
elif response == wx.ID_NO:
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-size: 13px;
|
||||||
|
margin-top: 20px;
|
||||||
|
background-color: rgb(238,238,238);
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
line-height: 0.5;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: -apple-system-control-accent;
|
||||||
|
}
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
body {
|
||||||
|
color: #fff;
|
||||||
|
background-color: rgb(47,47,47);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
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("<a href=", "<a target='_blank' href=")
|
||||||
|
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"])
|
webbrowser.open(dict["Github Link"])
|
||||||
|
elif result == ID_UPDATE:
|
||||||
|
gui_entry.EntryPoint(self.constants).start(entry=gui_entry.SupportedEntryPoints.UPDATE_APP)
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if utilities.check_seal() is True:
|
if utilities.check_seal() is True:
|
||||||
@@ -127,6 +197,9 @@ class AutomaticSysPatch:
|
|||||||
if self._determine_if_versions_match():
|
if self._determine_if_versions_match():
|
||||||
self._determine_if_boot_matches()
|
self._determine_if_boot_matches()
|
||||||
|
|
||||||
|
def _onWebviewNav(self, event):
|
||||||
|
url = event.GetURL()
|
||||||
|
webbrowser.open(url)
|
||||||
|
|
||||||
def _determine_if_versions_match(self):
|
def _determine_if_versions_match(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class DownloadFrame(wx.Frame):
|
|||||||
title_label.SetFont(gui_support.font_factory(19, wx.FONTWEIGHT_BOLD))
|
title_label.SetFont(gui_support.font_factory(19, wx.FONTWEIGHT_BOLD))
|
||||||
title_label.Centre(wx.HORIZONTAL)
|
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)
|
progress_bar.Centre(wx.HORIZONTAL)
|
||||||
|
|
||||||
label_amount = wx.StaticText(frame, label="Preparing download", pos=(-1, progress_bar.GetPosition()[1] + progress_bar.GetSize()[1]))
|
label_amount = wx.StaticText(frame, label="Preparing download", pos=(-1, progress_bar.GetPosition()[1] + progress_bar.GetSize()[1]))
|
||||||
@@ -68,7 +68,9 @@ class DownloadFrame(wx.Frame):
|
|||||||
self.download_obj.download()
|
self.download_obj.download()
|
||||||
while self.download_obj.is_active():
|
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
|
||||||
|
|
||||||
if percentage == -1:
|
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)"
|
amount_str = f"{utilities.human_fmt(self.download_obj.downloaded_file_size)} downloaded ({utilities.human_fmt(self.download_obj.get_speed())}/s)"
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# Generate GUI for main menu
|
# Generate GUI for main menu
|
||||||
|
# Portions of this file Copyright (c) 2023 Jazzzny
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
|
import wx.html2
|
||||||
|
import markdown2
|
||||||
|
import requests
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
@@ -271,7 +276,7 @@ class MainFrame(wx.Frame):
|
|||||||
def _check_for_updates(self):
|
def _check_for_updates(self):
|
||||||
if self.constants.has_checked_updates is True:
|
if self.constants.has_checked_updates is True:
|
||||||
return
|
return
|
||||||
|
|
||||||
ignore_updates = global_settings.GlobalEnviromentSettings().read_property("IgnoreAppUpdates")
|
ignore_updates = global_settings.GlobalEnviromentSettings().read_property("IgnoreAppUpdates")
|
||||||
if ignore_updates is True:
|
if ignore_updates is True:
|
||||||
self.constants.ignore_updates = True
|
self.constants.ignore_updates = True
|
||||||
@@ -285,20 +290,8 @@ class MainFrame(wx.Frame):
|
|||||||
|
|
||||||
version = dict["Version"]
|
version = dict["Version"]
|
||||||
logging.info(f"New version: {version}")
|
logging.info(f"New version: {version}")
|
||||||
dialog = wx.MessageDialog(
|
|
||||||
parent=self,
|
wx.CallAfter(self.on_update, dict["Link"], version, dict["Github Link"])
|
||||||
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"])
|
|
||||||
|
|
||||||
|
|
||||||
def on_build_and_install(self, event: wx.Event = None):
|
def on_build_and_install(self, event: wx.Event = None):
|
||||||
self.Hide()
|
self.Hide()
|
||||||
@@ -345,12 +338,90 @@ class MainFrame(wx.Frame):
|
|||||||
screen_location=self.GetPosition()
|
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):
|
||||||
gui_update.UpdateFrame(
|
|
||||||
|
ID_GITHUB = wx.NewId()
|
||||||
|
ID_UPDATE = wx.NewId()
|
||||||
|
|
||||||
|
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 = """
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-size: 13px;
|
||||||
|
margin-top: 20px;
|
||||||
|
background-color: rgb(238,238,238);
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
line-height: 0.5;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: -apple-system-control-accent;
|
||||||
|
}
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
body {
|
||||||
|
color: #fff;
|
||||||
|
background-color: rgb(47,47,47);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
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("<a href=", "<a target='_blank' href=")
|
||||||
|
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="Dismiss")
|
||||||
|
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(oclp_github_url)
|
||||||
|
elif result == ID_UPDATE:
|
||||||
|
gui_update.UpdateFrame(
|
||||||
parent=self,
|
parent=self,
|
||||||
title=self.title,
|
title=self.title,
|
||||||
global_constants=self.constants,
|
global_constants=self.constants,
|
||||||
screen_location=self.GetPosition(),
|
screen_location=self.GetPosition(),
|
||||||
url=oclp_url,
|
url=oclp_url,
|
||||||
version_label=oclp_version
|
version_label=oclp_version
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _onWebviewNav(self, event):
|
||||||
|
url = event.GetURL()
|
||||||
|
webbrowser.open(url)
|
||||||
Reference in New Issue
Block a user