diff --git a/fishy/__main__.py b/fishy/__main__.py index 7fc156b..37414ca 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -9,7 +9,7 @@ import win32gui import fishy from fishy import web, helper, gui from fishy.engine.common.event_handler import EngineEventHandler -from fishy.gui import GUI, splash +from fishy.gui import GUI, splash, update_dialog from fishy.helper import hotkey from fishy.helper.config import config @@ -36,12 +36,20 @@ def initialize(window_to_hide): is_admin = os.getuid() == 0 except AttributeError: is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 - if is_admin: logging.info("Running with admin privileges") try: - helper.auto_upgrade() + if helper.upgrade_avail() and not config.get("dont_ask_update", False): + cv,hv = helper.versions() + update_now, dont_ask_update = update_dialog.start(cv,hv) + if dont_ask_update: + config.set("dont_ask_update", dont_ask_update) + else: + config.delete("dont_ask_update") + + if update_now: + helper.auto_upgrade() except Exception: logging.error(traceback.format_exc()) diff --git a/fishy/gui/update_dialog.py b/fishy/gui/update_dialog.py new file mode 100644 index 0000000..9313310 --- /dev/null +++ b/fishy/gui/update_dialog.py @@ -0,0 +1,43 @@ +from multiprocessing import Process, Manager +from tkinter import * +import time + +def show(currentversion, newversion, returns): + top = Tk() + top.title("A wild update appears!") + + dialogLabel = Label(top, text="There is a new update available ("+currentversion+"->"+newversion+"). Do you want to update now?") + dialogLabel.grid(row=0, columnspan=2, padx=5, pady=5) + + cbVar = IntVar() + dialogCheckbutton = Checkbutton(top, text="don't ask again", variable=cbVar) + dialogCheckbutton.grid(row=1, columnspan=2, padx=5, pady=0) + top.update() + buttonWidth = int(dialogLabel.winfo_width()/2)-20 + + def _clickYes(): + returns[0],returns[1]=True, False + top.destroy() + + def _clickNo(): + returns[0],returns[1]=False, bool(cbVar.get()) + top.destroy() + + pixelVirtual = PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols + dialogBtnYes = Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, width=buttonWidth, compound="c") + dialogBtnYes.grid(row=2, column=0, padx=5, pady=5) + dialogBtnNo = Button(top, text="No " + str(chr(10005)), fg='red', command=_clickNo, image=pixelVirtual, width=buttonWidth, compound="c") + dialogBtnNo.grid(row=2, column=1, padx=5, pady=5) + + top.protocol('WM_DELETE_WINDOW', _clickNo) + + top.update() + top.mainloop() + + +def start(currentversion, newversion): + returns = Manager().dict() + p = Process(target=show, args=(currentversion, newversion, returns)) + p.start() + p.join() + return returns[0], returns[1]