mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
show update prompt after gui is loaded
renamed auto_upgrade to update_now made config init similar to hotkey update now is a popup which runs from gui thread instead of an independent process if the user decides to upgrade, bot is quited and update is started in the end of the main thread if update flag is set
This commit is contained in:
parent
572604ff36
commit
c9c2982403
@ -10,7 +10,7 @@ import fishy
|
||||
from fishy import gui, helper, web
|
||||
from fishy.engine.common.event_handler import EngineEventHandler
|
||||
from fishy.gui import GUI, splash, update_dialog
|
||||
from fishy.helper import hotkey
|
||||
from fishy.helper import hotkey, auto_update
|
||||
from fishy.helper.active_poll import active
|
||||
from fishy.helper.config import config
|
||||
from fishy.helper.helper import print_exc
|
||||
@ -45,20 +45,6 @@ def initialize(window_to_hide):
|
||||
if is_admin:
|
||||
logging.info("Running with admin privileges")
|
||||
|
||||
try:
|
||||
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:
|
||||
print_exc()
|
||||
|
||||
if not config.get("debug", False) and check_window_name(win32gui.GetWindowText(window_to_hide)):
|
||||
win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE)
|
||||
helper.install_thread_excepthook()
|
||||
@ -77,6 +63,10 @@ def main():
|
||||
finish_splash = splash.start()
|
||||
hotkey.init()
|
||||
|
||||
def on_gui_load():
|
||||
finish_splash()
|
||||
update_dialog.check_update(gui_window)
|
||||
|
||||
print("launching please wait...")
|
||||
|
||||
info_logger = ["comtypes", "PIL"]
|
||||
@ -87,7 +77,7 @@ def main():
|
||||
window_to_hide = win32gui.GetForegroundWindow()
|
||||
|
||||
bot = EngineEventHandler(lambda: gui_window)
|
||||
gui_window = GUI(lambda: bot, finish_splash)
|
||||
gui_window = GUI(lambda: bot, on_gui_load)
|
||||
|
||||
hotkey.start()
|
||||
|
||||
@ -102,6 +92,7 @@ def main():
|
||||
hotkey.stop()
|
||||
active.stop()
|
||||
config.stop()
|
||||
bot.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -1,6 +1,8 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
from fishy.helper import auto_update
|
||||
|
||||
from fishy.engine import SemiFisherEngine
|
||||
from fishy.engine.fullautofisher.engine import FullAuto
|
||||
|
||||
@ -22,7 +24,10 @@ class IEngineHandler:
|
||||
def check_pixel_val(self):
|
||||
...
|
||||
|
||||
def quit(self):
|
||||
def set_update(self, version):
|
||||
...
|
||||
|
||||
def quit_me(self):
|
||||
...
|
||||
|
||||
|
||||
@ -32,6 +37,9 @@ class EngineEventHandler(IEngineHandler):
|
||||
self.event_handler_running = True
|
||||
self.event = []
|
||||
|
||||
self.update_flag = False
|
||||
self.to_version = ""
|
||||
|
||||
self.semi_fisher_engine = SemiFisherEngine(gui_ref)
|
||||
self.full_fisher_engine = FullAuto(gui_ref)
|
||||
|
||||
@ -57,7 +65,16 @@ class EngineEventHandler(IEngineHandler):
|
||||
|
||||
self.event.append(func)
|
||||
|
||||
def quit(self):
|
||||
def set_update(self, version):
|
||||
self.to_version = version
|
||||
self.update_flag = True
|
||||
self.quit_me()
|
||||
|
||||
def stop(self):
|
||||
if self.update_flag:
|
||||
auto_update.update_now(self.to_version)
|
||||
|
||||
def quit_me(self):
|
||||
def func():
|
||||
if self.semi_fisher_engine.start:
|
||||
self.semi_fisher_engine.turn_off()
|
||||
|
@ -139,10 +139,11 @@ def _create(gui: 'GUI'):
|
||||
|
||||
gui._root.protocol("WM_DELETE_WINDOW", set_destroy)
|
||||
gui._destroyed = False
|
||||
gui._root.update()
|
||||
gui.on_ready()
|
||||
gui._root.after(0, gui._root.attributes, "-alpha", 1.0)
|
||||
|
||||
gui._root.update()
|
||||
gui._clear_function_queue()
|
||||
gui._root.after(0, gui._root.attributes, "-alpha", 1.0)
|
||||
gui.on_ready()
|
||||
while True:
|
||||
gui._root.update()
|
||||
gui._clear_function_queue()
|
||||
@ -152,6 +153,6 @@ def _create(gui: 'GUI'):
|
||||
gui._start_restart = False
|
||||
gui.create()
|
||||
if gui._destroyed:
|
||||
gui.engine.quit()
|
||||
gui.engine.quit_me()
|
||||
break
|
||||
time.sleep(0.01)
|
||||
|
@ -1,11 +1,22 @@
|
||||
import logging
|
||||
import tkinter as tk
|
||||
from multiprocessing import Manager, Process
|
||||
|
||||
from fishy import helper
|
||||
from fishy.helper import helper, auto_update
|
||||
from fishy.helper.config import config
|
||||
from fishy.helper.popup import PopUp
|
||||
|
||||
|
||||
def show(currentversion, newversion, returns):
|
||||
top = tk.Tk()
|
||||
def _show(gui, currentversion, newversion, returns):
|
||||
|
||||
def _clickYes():
|
||||
returns[0], returns[1] = True, False
|
||||
top.quit_top()
|
||||
|
||||
def _clickNo():
|
||||
returns[0], returns[1] = False, bool(cbVar.get())
|
||||
top.quit_top()
|
||||
|
||||
top = PopUp(helper.empty_function, gui._root)
|
||||
top.title("A wild fishy update appeared!")
|
||||
top.iconbitmap(helper.manifest_file('icon.ico'))
|
||||
|
||||
@ -19,14 +30,6 @@ def show(currentversion, newversion, returns):
|
||||
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 = tk.PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols
|
||||
dialogBtnNo = tk.Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual,
|
||||
width=buttonWidth, compound="c")
|
||||
@ -37,14 +40,21 @@ def show(currentversion, newversion, returns):
|
||||
dialogBtnYes.focus_set()
|
||||
|
||||
top.protocol('WM_DELETE_WINDOW', _clickNo)
|
||||
|
||||
top.update()
|
||||
top.mainloop()
|
||||
top.start()
|
||||
|
||||
|
||||
def start(currentversion, newversion):
|
||||
returns = Manager().dict()
|
||||
p = Process(target=show, args=(currentversion, newversion, returns))
|
||||
p.start()
|
||||
p.join()
|
||||
return returns[0], returns[1]
|
||||
def check_update(gui):
|
||||
if not auto_update.upgrade_avail() or config.get("dont_ask_update", False):
|
||||
return
|
||||
|
||||
cv, hv = auto_update.versions()
|
||||
returns = [None, None]
|
||||
_show(gui, cv, hv, returns)
|
||||
[update_now, dont_ask_update] = returns
|
||||
if dont_ask_update:
|
||||
config.set("dont_ask_update", dont_ask_update)
|
||||
else:
|
||||
config.delete("dont_ask_update")
|
||||
|
||||
if update_now:
|
||||
gui.engine.set_update(hv)
|
||||
|
@ -1,4 +1,3 @@
|
||||
from .auto_update import auto_upgrade, upgrade_avail, versions
|
||||
from .config import Config
|
||||
from .helper import (addon_exists, create_shortcut, create_shortcut_first,
|
||||
get_addonversion, get_savedvarsdir, initialize_uid,
|
||||
|
@ -88,13 +88,12 @@ def upgrade_avail():
|
||||
return _get_current_version() < _get_highest_version(index, pkg)
|
||||
|
||||
|
||||
def auto_upgrade():
|
||||
def update_now(version):
|
||||
"""
|
||||
public function,
|
||||
compares current version with the latest version (from web),
|
||||
if current version is older, then it updates and restarts the script
|
||||
"""
|
||||
version = _hr_version(_get_highest_version(index, pkg))
|
||||
logging.info(f"Updating to v{version}, Please Wait...")
|
||||
subprocess.call(["python", '-m', 'pip', 'install', '--upgrade', 'fishy', '--user'])
|
||||
execl(sys.executable, *([sys.executable, '-m', 'fishy'] + sys.argv[1:]))
|
||||
|
@ -92,8 +92,9 @@ class config:
|
||||
|
||||
@staticmethod
|
||||
def init():
|
||||
config._instance = Config()
|
||||
config._instance.initialize()
|
||||
if not config._instance:
|
||||
config._instance = Config()
|
||||
config._instance.initialize()
|
||||
|
||||
@staticmethod
|
||||
def start_backup_scheduler():
|
||||
|
@ -19,6 +19,7 @@ class PopUp(Toplevel):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.running = True
|
||||
self.quit_callback = quit_callback
|
||||
self.protocol("WM_DELETE_WINDOW", self.quit_top)
|
||||
|
||||
def quit_top(self):
|
||||
self.quit_callback()
|
||||
@ -26,7 +27,6 @@ class PopUp(Toplevel):
|
||||
self.running = False
|
||||
|
||||
def start(self):
|
||||
self.protocol("WM_DELETE_WINDOW", self.quit_top)
|
||||
self.grab_set()
|
||||
center(self)
|
||||
while self.running:
|
||||
|
Loading…
Reference in New Issue
Block a user