Fetch the changelogs and display them in a popup asking if we should install

This commit is contained in:
Kiel42 2019-10-29 00:23:20 +01:00
parent 26efd0b680
commit 24e15111b8
2 changed files with 29 additions and 10 deletions

View File

@ -108,14 +108,15 @@ class SpanshRouter():
self.clear_route_btn.grid_remove()
if self.update_available:
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.")
self.update_btn = tk.Button(self.frame, text=update_txt, command=lambda: self.update_btn.grid_forget())
self.update_btn.bind("<Button-3>", self.goto_changelog_page)
self.update_btn.grid(row=row, pady=5, columnspan=2)
row += 1
update_txt = "New Spansh update available!\n"
update_txt += "If you choose to install it, you will have to restart EDMC for it to take effect.\n\n"
update_txt += self.spansh_updater.changelogs
update_txt += "Install?"
install_update = confirmDialog.askyesno("SpanshRouter", update_txt)
if install_update:
confirmDialog.showinfo("SpanshRouter", "The update will be installed as soon as you close EDMC.")
self.update_gui()
return self.frame
@ -560,17 +561,20 @@ class SpanshRouter():
def check_for_update(self):
self.cleanup_old_version()
url = "https://raw.githubusercontent.com/CMDR-Kiel42/EDMC_SpanshRouter/master/version.json"
version_url = "https://raw.githubusercontent.com/CMDR-Kiel42/EDMC_SpanshRouter/master/version.json"
try:
response = requests.get(url, timeout=2)
response = requests.get(version_url, timeout=2)
if response.status_code == 200:
if self.plugin_version != response.content:
self.update_available = True
self.spansh_updater = SpanshUpdater(response.content, self.plugin_dir)
if not self.spansh_updater.download_zip():
if self.spansh_updater.download_zip():
self.spansh_updater.get_changelog()
else:
sys.stderr.write("Error when downloading the latest SpanshRouter update")
else:
sys.stderr.write("Could not query latest SpanshRouter version: " + str(response.status_code) + response.text)
except:

View File

@ -13,6 +13,7 @@ class SpanshUpdater():
self.plugin_dir = plugin_dir
self.zip_path = os.path.join(self.plugin_dir, self.zip_name)
self.zip_downloaded = False
self.changelogs = ""
def download_zip(self):
url = 'https://github.com/CMDR-Kiel42/EDMC_SpanshRouter/releases/download/v' + self.version + '/' + self.zip_name
@ -46,3 +47,17 @@ class SpanshUpdater():
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
sys.stderr.write(''.join('!! ' + line for line in lines))
def get_changelog(self):
url = "https://raw.githubusercontent.com/CMDR-Kiel42/EDMC_SpanshRouter/master/CHANGELOG.md"
try:
r = requests.get(url, timeout=2)
if r.status_code == 200:
start_index = r.content.find("## " + self.version)
stop_index = r.content.find("##", start_index + 2)
self.changelogs = r.content[start_index: stop_index:]
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
sys.stderr.write(''.join('!! ' + line for line in lines))