instead of restarting fishy when session is not created due to incorrect uid, re generate uid and try to create session again

removed restart from debug options (fishy should always exit safely)
added debug logs for when systems start and stop
update button from tool bar now opens update dialogue correctly
This commit is contained in:
Adam Saudagar 2022-02-03 03:47:35 +05:30
parent d22a4e79e5
commit a12c397357
7 changed files with 50 additions and 33 deletions

View File

@ -31,9 +31,9 @@ def initialize(window_to_hide):
Migration.migrate()
helper.create_shortcut_first()
helper.initialize_uid()
new_session = web.get_session()
if new_session is None:
logging.error("Couldn't create a session, some features might not work")
print(f"created session {new_session}")
@ -58,9 +58,9 @@ def main():
if not gui.check_eula():
return
finish_splash = splash.start()
config.start_backup_scheduler()
active.init()
finish_splash = splash.start()
hotkey.init()
def on_gui_load():

View File

@ -57,7 +57,7 @@ def _create(gui: 'GUI'):
filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode,
variable=dark_mode_var)
if config.get("dont_ask_update", False):
filemenu.add_command(label="Update", command=helper.update)
filemenu.add_command(label="Update", command=lambda: helper.update(gui))
def installer():
if filemenu.entrycget(4, 'label') == "Remove FishyQR":
@ -82,7 +82,6 @@ def _create(gui: '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="Restart", command=helper.restart)
menubar.add_cascade(label="Debug", menu=debug_menu)
help_menu = tk.Menu(menubar, tearoff=0)

View File

@ -1,8 +1,8 @@
from .config import Config
from .helper import (addon_exists, create_shortcut, create_shortcut_first,
get_addonversion, get_savedvarsdir, initialize_uid,
get_addonversion, get_savedvarsdir,
install_addon, install_thread_excepthook, manifest_file,
not_implemented, open_web, playsound_multiple,
remove_addon, restart, unhandled_exception_logging,
remove_addon, unhandled_exception_logging,
update, install_required_addons)
from .luaparser import sv_color_extract

View File

@ -1,3 +1,5 @@
import logging
from event_scheduler import EventScheduler
from fishy.web import web
@ -13,11 +15,14 @@ class active:
active._scheduler = EventScheduler()
active._scheduler.start()
logging.debug("active scheduler initialized")
@staticmethod
def start():
active._scheduler.enter_recurring(60, 1, web.ping)
logging.debug("active scheduler started")
@staticmethod
def stop():
active._scheduler.stop(hard_stop=True)
logging.debug("active scheduler stopped")

View File

@ -57,14 +57,17 @@ class Config:
else:
self._config_dict = dict()
logging.debug("config initialized")
def start_backup_scheduler(self):
self._create_backup()
self._scheduler.start()
self._scheduler.enter_recurring(5 * 60, 1, self._create_backup)
logging.debug("scheduler started")
def stop(self):
self._scheduler.stop(True)
logging.debug("config stopped")
def _create_backup(self):
with open(temp_file, 'w') as f:

View File

@ -15,6 +15,7 @@ from zipfile import ZipFile
import requests
import winshell
from fishy.gui import update_dialog
from playsound import playsound
from win32com.client import Dispatch
from win32comext.shell import shell, shellcon
@ -66,19 +67,6 @@ def open_web(website):
Thread(target=lambda: webbrowser.open(website, new=2)).start()
def initialize_uid():
from .config import config
if config.get("uid") is not None:
return
new_uid = web.register_user()
if new_uid is not None:
config.set("uid", new_uid)
else:
logging.error("Couldn't register uid, some features might not work")
def _create_new_uid():
"""
Creates a unique id for user
@ -239,20 +227,16 @@ def get_documents():
return shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
def restart():
os.execl(sys.executable, *([sys.executable] + sys.argv))
def log_raise(msg):
logging.error(msg)
raise Exception(msg)
def update():
def update(gui):
from .config import config
config.delete("dont_ask_update")
restart()
update_dialog.check_update(gui)
def is_eso_active():

View File

@ -1,3 +1,5 @@
import logging
import requests
from whatsmyip.ip import get_ip
from whatsmyip.providers import GoogleDnsProvider
@ -112,24 +114,48 @@ def unsub():
return result["success"]
@fallback(None)
def get_session(lazy=True):
global _session_id
# lazy loading logic
if lazy and _session_id is not None:
return _session_id
body = {"uid": config.get("uid"), "apiversion": apiversion}
# check if user has uid
uid = config.get("uid")
# then create session
if uid:
_session_id, online = _create_new_session(uid)
# if not, create new id then try creating session again
else:
uid = register_user()
logging.debug("New User, generated new uid")
if uid:
_session_id, online = _create_new_session(uid)
else:
online = False
# when the user is already registered but session is not created as uid is not found
if online and not _session_id:
logging.error("user not found, generating new uid.. contact dev if you don't want to loose data")
new_uid = register_user()
_session_id, online = _create_new_session(new_uid)
config.set("uid", new_uid)
config.set("old_uid", uid)
return _session_id
@fallback((None, False))
def _create_new_session(uid):
body = {"uid": uid, "apiversion": apiversion}
response = requests.post(urls.session, params=body)
if response.status_code == 405:
config.delete("uid")
helper.restart()
return None
_session_id = response.json()["session_id"]
return _session_id
return None, True
return response.json()["session_id"], True
@fallback(False)
def has_beta():