0.3.0 bugs squashed

- sends hole_deplete even on interupt
- application doesnt restart after updating
- image doesnt display in shortcut
- optimize startup: multithreaded web request for gui init
This commit is contained in:
DESKTOP-JVKHS7I\Adam 2020-05-05 20:41:00 +05:30
parent 3fdfb35622
commit 79c7f748e1
6 changed files with 56 additions and 17 deletions

Binary file not shown.

View File

@ -1,6 +1,9 @@
import ctypes
import logging
import os
import sys
import time
from os import execl
from tkinter import messagebox
import win32con
@ -129,6 +132,14 @@ def initialize(gui, c: Config):
logging.error("Couldn't create a session, some features might not work")
print(f"created session {new_session}")
try:
is_admin = os.getuid() == 0
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
if is_admin and c.get("debug"):
logging.info("Running with admin privileges")
try:
auto_upgrade()
except Exception:

View File

@ -37,6 +37,7 @@ class GUIFunction(Enum):
STARTED = 1 # args: bool
ASK_DIRECTORY = 2 # callback: callable
SHOW_ERROR = 3
SET_NOTIFY = 4
class GUI:
@ -54,7 +55,8 @@ class GUI:
self.root = None
self.console = None
self.start_button = None
self.notif = None
self.notify = None
self.notify_check = None
self.thread = threading.Thread(target=self.create, args=())
@ -99,8 +101,8 @@ class GUI:
logging.debug("Restart to update the changes")
debug_menu.add_checkbutton(label="Keep Console", command=keep_console, variable=debug_var)
debug_menu.add_command(label="Log Dump", command=lambda: logging.error("Not Implemented"))
debug_menu.add_command(label="Restart", command=helper.restart)
menubar.add_cascade(label="Debug", menu=debug_menu)
help_menu = Menu(menubar, tearoff=0)
@ -126,9 +128,17 @@ class GUI:
Label(left_frame, text="Notification:").grid(row=0, column=0)
self.notif = IntVar(value=int(web.is_subbed(self.config.get('uid'))))
Checkbutton(left_frame, command=self.give_notification_link,
variable=self.notif).grid(row=0, column=1)
self.notify = IntVar(0)
self.notify_check = Checkbutton(left_frame, command=self.give_notification_link,
variable=self.notify)
self.notify_check.grid(row=0, column=1)
self.notify_check['state'] = DISABLED
def update_notify_check():
is_subbed = web.is_subbed(self.config.get('uid'))
self.call(GUIFunction.SET_NOTIFY, (int(is_subbed[0]),is_subbed[1]))
threading.Thread(target=update_notify_check).start()
Label(left_frame, text="Fullscreen: ").grid(row=1, column=0, pady=(5, 5))
borderless = Checkbutton(left_frame, )
@ -199,6 +209,10 @@ class GUI:
threading.Thread(target=func[1][0], args=(path,)).start()
elif func[0] == GUIFunction.SHOW_ERROR:
messagebox.showerror("ERROR", func[1][0])
elif func[0] == GUIFunction.SET_NOTIFY:
self.notify.set(func[1][0])
if func[1][1]:
self.notify_check['state'] = NORMAL
def _apply_theme(self, dark):
self.root["theme"] = "equilux" if dark else "breeze"
@ -238,22 +252,22 @@ class GUI:
def give_notification_link(self):
from fishy.systems import web
if web.is_subbed(self.config.get("uid")):
if web.is_subbed(self.config.get("uid"))[0]:
web.unsub(self.config.get("uid"))
return
# set notification checkbutton
self.notif.set(0)
self.notify.set(0)
def quit_top():
top.destroy()
top_running[0] = False
def check():
if web.is_subbed(self.config.get("uid"), False):
if web.is_subbed(self.config.get("uid"), False)[0]:
messagebox.showinfo("Note!", "Notification configured successfully!")
web.send_notification(self.config.get("uid"), "Sending a test notification :D")
self.notif.set(1)
self.notify.set(1)
quit_top()
else:
messagebox.showerror("Error", "Subscription wasn't successful")

View File

@ -14,7 +14,10 @@ import numpy as np
from uuid import uuid1
from hashlib import md5
from win32com.client import Dispatch
import fishy
import winshell
import functools
from fishy.systems.gui import GUIFunction
@ -60,9 +63,6 @@ def open_web(website):
Thread(target=lambda: webbrowser.open(website, new=2)).start()
def create_new_uid():
return md5(str(uuid1()).encode()).hexdigest()
@ -114,7 +114,16 @@ def create_shortcut(gui):
def _copy_shortcut(path):
shutil.copy(get_data_file_path('FishybotESO.lnk'), path)
desktop = winshell.desktop()
path = os.path.join(desktop, "Fishybot ESO.lnk")
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = os.path.join(os.path.dirname(sys.executable), "python.exe")
shortcut.Arguments = "-m fishy"
shortcut.IconLocation = get_data_file_path("icon.ico")
shortcut.save()
logging.info("Shortcut created")
@ -130,3 +139,7 @@ def check_addon():
"Also, make sure the addon is visible clearly on top left corner of the game window")
except Exception:
print("couldn't install addon, try doing it manually")
def restart():
os.execl(sys.executable, *([sys.executable] + sys.argv))

View File

@ -83,18 +83,18 @@ def send_hole_deplete(uid, fish_caught, hole_time, fish_times):
requests.post(domain + hole_depleted, json=body)
@fallback(False)
@fallback((False, False))
def is_subbed(uid, lazy=True):
if lazy and G._is_subbed is not None:
return G._is_subbed
return G._is_subbed, True
if uid is None:
return False
return False, False
body = {"uid": uid}
response = requests.get(domain + subscription, params=body)
G._is_subbed = response.json()["subbed"]
return G._is_subbed
return G._is_subbed, True
@fallback(None)

View File

@ -1,3 +1,4 @@
winshell
imutils
numpy
opencv_python