mirror of
https://github.com/norohind/EDMC_SpanshRouter.git
synced 2025-04-21 19:47:36 +03:00
Better update button
This commit is contained in:
parent
d742701efc
commit
ae8e5ecdd7
14
load.py
14
load.py
@ -40,7 +40,7 @@ def plugin_start(plugin_dir):
|
||||
if response.status_code == 200:
|
||||
if this.plugin_version != response.content:
|
||||
this.update_available = True
|
||||
this.spansh_updater = SpanshUpdater(response.content)
|
||||
this.spansh_updater = SpanshUpdater(response.content, plugin_dir)
|
||||
|
||||
if not this.spansh_updater.download_zip():
|
||||
sys.stderr.write("Error when downloading the latest SpanshRouter update")
|
||||
@ -351,8 +351,10 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
elif entry['event'] == 'FSSDiscoveryScan' and entry['SystemName'] == this.next_stop:
|
||||
update_route()
|
||||
|
||||
def goto_update_page(self=None):
|
||||
webbrowser.open('https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/releases')
|
||||
def goto_changelog_page(self=None):
|
||||
changelog_url = 'https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/blob/master/CHANGELOG.md#'
|
||||
changelog_url += this.spansh_updater.version.replace('.', '')
|
||||
webbrowser.open(changelog_url)
|
||||
|
||||
def plugin_app(parent):
|
||||
this.parent = parent
|
||||
@ -418,7 +420,11 @@ def plugin_app(parent):
|
||||
this.clear_route_btn.grid_remove()
|
||||
|
||||
if this.update_available:
|
||||
this.update_btn = tk.Button(this.frame, text="SpanshRouter update available for download!", command=goto_update_page)
|
||||
update_txt = ("A SpanshRouter update is available.\n"
|
||||
"It will be installed next time you start EDMC.\n"
|
||||
"Click to dismiss this message, right click to see what's new.")
|
||||
this.update_btn = tk.Button(this.frame, text=update_txt, command=lambda: this.update_btn.grid_forget())
|
||||
this.update_btn.bind("<Button-3>", goto_changelog_page)
|
||||
this.update_btn.grid(row=row, pady=5, columnspan=2)
|
||||
row += 1
|
||||
|
||||
|
18
updater.py
18
updater.py
@ -3,11 +3,15 @@
|
||||
import os
|
||||
import requests
|
||||
import zipfile
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
class SpanshUpdater():
|
||||
def __init__(self, version):
|
||||
def __init__(self, version, plugin_dir):
|
||||
self.version = version
|
||||
self.zip_name = "EDMC_SpanshRouter_" + version.replace('.', '') + ".zip"
|
||||
self.plugin_dir = plugin_dir
|
||||
self.zip_path = os.path.join(self.plugin_dir, self.zip_name)
|
||||
self.zip_downloaded = False
|
||||
|
||||
def download_zip(self):
|
||||
@ -16,8 +20,9 @@ class SpanshUpdater():
|
||||
try:
|
||||
r = requests.get(url)
|
||||
if r.status_code == 200:
|
||||
with open(self.zip_name, 'wb') as f:
|
||||
f.write(r.content)
|
||||
with open(self.zip_path, 'wb') as f:
|
||||
print("Downloading SpanshRouter to " + self.zip_path)
|
||||
f.write(os.path.join(r.content))
|
||||
self.zip_downloaded = True
|
||||
else:
|
||||
sys.stderr.write("Failed to fetch SpanchRouter update. Status code: " + str(r.status_code))
|
||||
@ -30,14 +35,13 @@ class SpanshUpdater():
|
||||
finally:
|
||||
return self.zip_downloaded
|
||||
|
||||
|
||||
def install(self):
|
||||
if self.zip_downloaded:
|
||||
try:
|
||||
with zipfile.ZipFile(self.zip_name, 'r') as zip_ref:
|
||||
zip_ref.extractall("./")
|
||||
with zipfile.ZipFile(self.zip_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(self.plugin_dir)
|
||||
|
||||
os.remove(self.zip_name)
|
||||
os.remove(self.zip_path)
|
||||
except NameError:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
||||
|
Loading…
x
Reference in New Issue
Block a user