This commit is contained in:
Jazzzny
2023-10-04 17:12:51 -04:00
parent 04a2e55d24
commit 526594a90d
2 changed files with 106 additions and 25 deletions

View File

@@ -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 = """
<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, 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("<a href=", "<a target='_blank' href=").replace("<h1>OpenCore Legacy Patcher changelog</h1>", "")
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):
"""

View File

@@ -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):
}
</style>
"""
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
)
)
def _onWebviewNav(self, event):
url = event.GetURL()
webbrowser.open(url)