mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
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:
parent
d22a4e79e5
commit
a12c397357
@ -31,9 +31,9 @@ def initialize(window_to_hide):
|
|||||||
Migration.migrate()
|
Migration.migrate()
|
||||||
|
|
||||||
helper.create_shortcut_first()
|
helper.create_shortcut_first()
|
||||||
helper.initialize_uid()
|
|
||||||
|
|
||||||
new_session = web.get_session()
|
new_session = web.get_session()
|
||||||
|
|
||||||
if new_session is None:
|
if new_session is None:
|
||||||
logging.error("Couldn't create a session, some features might not work")
|
logging.error("Couldn't create a session, some features might not work")
|
||||||
print(f"created session {new_session}")
|
print(f"created session {new_session}")
|
||||||
@ -58,9 +58,9 @@ def main():
|
|||||||
if not gui.check_eula():
|
if not gui.check_eula():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
finish_splash = splash.start()
|
||||||
config.start_backup_scheduler()
|
config.start_backup_scheduler()
|
||||||
active.init()
|
active.init()
|
||||||
finish_splash = splash.start()
|
|
||||||
hotkey.init()
|
hotkey.init()
|
||||||
|
|
||||||
def on_gui_load():
|
def on_gui_load():
|
||||||
|
@ -57,7 +57,7 @@ def _create(gui: 'GUI'):
|
|||||||
filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode,
|
filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode,
|
||||||
variable=dark_mode_var)
|
variable=dark_mode_var)
|
||||||
if config.get("dont_ask_update", False):
|
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():
|
def installer():
|
||||||
if filemenu.entrycget(4, 'label') == "Remove FishyQR":
|
if filemenu.entrycget(4, 'label') == "Remove FishyQR":
|
||||||
@ -82,7 +82,6 @@ def _create(gui: 'GUI'):
|
|||||||
logging.debug("Restart to update the changes")
|
logging.debug("Restart to update the changes")
|
||||||
|
|
||||||
debug_menu.add_checkbutton(label="Keep Console", command=keep_console, variable=debug_var)
|
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)
|
menubar.add_cascade(label="Debug", menu=debug_menu)
|
||||||
|
|
||||||
help_menu = tk.Menu(menubar, tearoff=0)
|
help_menu = tk.Menu(menubar, tearoff=0)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from .config import Config
|
from .config import Config
|
||||||
from .helper import (addon_exists, create_shortcut, create_shortcut_first,
|
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,
|
install_addon, install_thread_excepthook, manifest_file,
|
||||||
not_implemented, open_web, playsound_multiple,
|
not_implemented, open_web, playsound_multiple,
|
||||||
remove_addon, restart, unhandled_exception_logging,
|
remove_addon, unhandled_exception_logging,
|
||||||
update, install_required_addons)
|
update, install_required_addons)
|
||||||
from .luaparser import sv_color_extract
|
from .luaparser import sv_color_extract
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from event_scheduler import EventScheduler
|
from event_scheduler import EventScheduler
|
||||||
from fishy.web import web
|
from fishy.web import web
|
||||||
|
|
||||||
@ -13,11 +15,14 @@ class active:
|
|||||||
|
|
||||||
active._scheduler = EventScheduler()
|
active._scheduler = EventScheduler()
|
||||||
active._scheduler.start()
|
active._scheduler.start()
|
||||||
|
logging.debug("active scheduler initialized")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def start():
|
def start():
|
||||||
active._scheduler.enter_recurring(60, 1, web.ping)
|
active._scheduler.enter_recurring(60, 1, web.ping)
|
||||||
|
logging.debug("active scheduler started")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop():
|
def stop():
|
||||||
active._scheduler.stop(hard_stop=True)
|
active._scheduler.stop(hard_stop=True)
|
||||||
|
logging.debug("active scheduler stopped")
|
||||||
|
@ -57,14 +57,17 @@ class Config:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
self._config_dict = dict()
|
self._config_dict = dict()
|
||||||
|
logging.debug("config initialized")
|
||||||
|
|
||||||
def start_backup_scheduler(self):
|
def start_backup_scheduler(self):
|
||||||
self._create_backup()
|
self._create_backup()
|
||||||
self._scheduler.start()
|
self._scheduler.start()
|
||||||
self._scheduler.enter_recurring(5 * 60, 1, self._create_backup)
|
self._scheduler.enter_recurring(5 * 60, 1, self._create_backup)
|
||||||
|
logging.debug("scheduler started")
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._scheduler.stop(True)
|
self._scheduler.stop(True)
|
||||||
|
logging.debug("config stopped")
|
||||||
|
|
||||||
def _create_backup(self):
|
def _create_backup(self):
|
||||||
with open(temp_file, 'w') as f:
|
with open(temp_file, 'w') as f:
|
||||||
|
@ -15,6 +15,7 @@ from zipfile import ZipFile
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
import winshell
|
import winshell
|
||||||
|
from fishy.gui import update_dialog
|
||||||
from playsound import playsound
|
from playsound import playsound
|
||||||
from win32com.client import Dispatch
|
from win32com.client import Dispatch
|
||||||
from win32comext.shell import shell, shellcon
|
from win32comext.shell import shell, shellcon
|
||||||
@ -66,19 +67,6 @@ def open_web(website):
|
|||||||
Thread(target=lambda: webbrowser.open(website, new=2)).start()
|
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():
|
def _create_new_uid():
|
||||||
"""
|
"""
|
||||||
Creates a unique id for user
|
Creates a unique id for user
|
||||||
@ -239,20 +227,16 @@ def get_documents():
|
|||||||
return shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
|
return shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
|
||||||
|
|
||||||
|
|
||||||
def restart():
|
|
||||||
os.execl(sys.executable, *([sys.executable] + sys.argv))
|
|
||||||
|
|
||||||
|
|
||||||
def log_raise(msg):
|
def log_raise(msg):
|
||||||
logging.error(msg)
|
logging.error(msg)
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
|
|
||||||
def update():
|
def update(gui):
|
||||||
from .config import config
|
from .config import config
|
||||||
|
|
||||||
config.delete("dont_ask_update")
|
config.delete("dont_ask_update")
|
||||||
restart()
|
update_dialog.check_update(gui)
|
||||||
|
|
||||||
|
|
||||||
def is_eso_active():
|
def is_eso_active():
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from whatsmyip.ip import get_ip
|
from whatsmyip.ip import get_ip
|
||||||
from whatsmyip.providers import GoogleDnsProvider
|
from whatsmyip.providers import GoogleDnsProvider
|
||||||
@ -112,24 +114,48 @@ def unsub():
|
|||||||
return result["success"]
|
return result["success"]
|
||||||
|
|
||||||
|
|
||||||
@fallback(None)
|
|
||||||
def get_session(lazy=True):
|
def get_session(lazy=True):
|
||||||
global _session_id
|
global _session_id
|
||||||
|
|
||||||
|
# lazy loading logic
|
||||||
if lazy and _session_id is not None:
|
if lazy and _session_id is not None:
|
||||||
return _session_id
|
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)
|
response = requests.post(urls.session, params=body)
|
||||||
|
|
||||||
if response.status_code == 405:
|
if response.status_code == 405:
|
||||||
config.delete("uid")
|
return None, True
|
||||||
helper.restart()
|
|
||||||
return None
|
|
||||||
|
|
||||||
_session_id = response.json()["session_id"]
|
|
||||||
return _session_id
|
|
||||||
|
|
||||||
|
return response.json()["session_id"], True
|
||||||
|
|
||||||
@fallback(False)
|
@fallback(False)
|
||||||
def has_beta():
|
def has_beta():
|
||||||
|
Loading…
Reference in New Issue
Block a user