forked from Support/sp-hydra-veil-gui
Legacy Database clients flow into recovery prompt
This commit is contained in:
parent
42e06b71c2
commit
7910586e1a
6 changed files with 68 additions and 112 deletions
|
|
@ -1,24 +1,76 @@
|
|||
from core.errors.logger import logger
|
||||
from core.models.manage.session_management import init_session, get_session, close_session, create_ALL_tables, create_ONLY_db_version_table, get_path
|
||||
from core.models.manage.session_management import init_session, get_session, close_session, create_ALL_tables, create_ONLY_db_version_table, get_path, does_it_exist, does_db_version_table_exist
|
||||
from core.models.manage.version_check import check_database_compatibility, insert_new_version, get_custom_message
|
||||
from core.Constants import Constants
|
||||
# generic
|
||||
import os
|
||||
import sys
|
||||
|
||||
# ============================================================================
|
||||
# DISPLAY CHOICES AND RECOVERY UI
|
||||
# ============================================================================
|
||||
def recovery_dialog(custom_error, db_version_you_have):
|
||||
"""This ends the app by forcing them to delete the database, move it, or just quit."""
|
||||
|
||||
from v2.ui.popups.Database_version import show_recovery_dialog
|
||||
choice = show_recovery_dialog({"message": custom_error, "db_version": db_version_you_have, "status": "version_mismatch"})
|
||||
logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}")
|
||||
|
||||
if choice == 1:
|
||||
if os.path.exists(database_path):
|
||||
os.remove(database_path)
|
||||
logger.info(f"[DB MANAGEMENT] Deleted the DB file at {database_path}")
|
||||
logger.info(f"[DB MANAGEMENT] Closing the app gracefully, for them to reboot..")
|
||||
sys.exit()
|
||||
|
||||
elif choice == 2:
|
||||
logger.info(f"[DB MANAGEMENT] User opted to move the DB file.")
|
||||
from v2.ui.popups.pick_folder_to_move import launch_file_picker
|
||||
launch_file_picker(database_path)
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
logger.error(f"[DB MANAGEMENT] User opted to close the app WITHOUT wiping the database, even though they need to.")
|
||||
sys.exit()
|
||||
|
||||
# ============================================================================
|
||||
# INITIALIZE DATABASE
|
||||
# ============================================================================
|
||||
# Does the database exist?
|
||||
system_path = get_path()
|
||||
database_path = system_path / "storage.db"
|
||||
main_db_exists = does_it_exist(database_path)
|
||||
|
||||
# (engine, Session, _session all initialized from session_management)
|
||||
init_session()
|
||||
# Setup operations on the main DB which create it
|
||||
init_session() # (engine, Session, _session all initialized from session_management)
|
||||
session = get_session()
|
||||
|
||||
# does the version checker table exist?
|
||||
version_table_exists = does_db_version_table_exist()
|
||||
|
||||
# are they upgrading from a legacy version?
|
||||
# that would mean the table existed, but not the version table,
|
||||
if not version_table_exists and main_db_exists:
|
||||
logger.info(f"[DB MANAGEMENT] We are dealing with a legacy database, we need to transition the user.")
|
||||
|
||||
# shut down db connection
|
||||
close_session()
|
||||
|
||||
# THEN DISPLAY CHOICES AND RECOVERY UI
|
||||
custom_error = "You're using a Legacy version of the Database scheme. Please delete it and fetch the new data."
|
||||
db_version_you_have = "Old System"
|
||||
recovery_dialog(custom_error, db_version_you_have)
|
||||
sys.exit()
|
||||
|
||||
# If they're still here, then if it's NOT a legacy version,
|
||||
|
||||
# and the new version table doesn't exist, then create it:
|
||||
if not version_table_exists:
|
||||
create_ONLY_db_version_table()
|
||||
|
||||
# ============================================================================
|
||||
# COMPARE DB VERISONS
|
||||
# ============================================================================
|
||||
|
||||
compatability_dict = check_database_compatibility(session)
|
||||
reason = compatability_dict.get("reason", "error")
|
||||
is_compatable = compatability_dict.get("result", False)
|
||||
|
|
@ -75,29 +127,6 @@ else:
|
|||
# shut down db connection
|
||||
close_session()
|
||||
|
||||
# ============================================================================
|
||||
# THEN DISPLAY CHOICES AND RECOVERY UI
|
||||
# ============================================================================
|
||||
from v2.ui.popups.Database_version import show_recovery_dialog
|
||||
choice = show_recovery_dialog({"message": custom_error, "db_version": db_version_you_have, "status": "version_mismatch"})
|
||||
logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}")
|
||||
recovery_dialog(custom_error, db_version_you_have)
|
||||
|
||||
system_path = get_path()
|
||||
database_path = system_path / "storage.db"
|
||||
|
||||
if choice == 1:
|
||||
if os.path.exists(database_path):
|
||||
os.remove(database_path)
|
||||
logger.info(f"[DB MANAGEMENT] Deleted the DB file at {database_path}")
|
||||
logger.info(f"[DB MANAGEMENT] Closing the app gracefully, for them to reboot..")
|
||||
sys.exit()
|
||||
|
||||
elif choice == 2:
|
||||
logger.info(f"[DB MANAGEMENT] User opted to move the DB file.")
|
||||
from v2.ui.popups.pick_folder_to_move import launch_file_picker
|
||||
launch_file_picker(database_path)
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
logger.error(f"[DB MANAGEMENT] User opted to close the app WITHOUT wiping the database, even though they need to.")
|
||||
sys.exit()
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,54 +0,0 @@
|
|||
fields:
|
||||
- name: country_code
|
||||
path: ['country', 'code']
|
||||
required: true
|
||||
|
||||
- name: code # this is city code
|
||||
path: ['code']
|
||||
required: true
|
||||
|
||||
- name: id
|
||||
path: ['id']
|
||||
|
||||
- name: country_name
|
||||
path: ['country', 'name']
|
||||
|
||||
- name: name # this is CITY name
|
||||
path: ['name']
|
||||
|
||||
- name: time_zone
|
||||
path: ['time_zone', 'code']
|
||||
|
||||
- name: operator_id
|
||||
path: ['operator_id']
|
||||
required: true
|
||||
|
||||
- name: provider_name
|
||||
path: ['provider', 'name']
|
||||
|
||||
- name: is_proxy_capable
|
||||
path: ['is_proxy_capable']
|
||||
|
||||
- name: is_wireguard_capable
|
||||
path: ['is_wireguard_capable']
|
||||
required: true
|
||||
|
||||
- name: is_hysteria2_capable
|
||||
path: ['is_hysteria2_capable']
|
||||
|
||||
- name: is_vless_capable
|
||||
path: ['is_vless_capable']
|
||||
|
||||
|
||||
# original version:
|
||||
# locations.append((
|
||||
# location['country']['code'],
|
||||
# location['code'],
|
||||
# location['id'],
|
||||
# location['country']['name'],
|
||||
# location['name'],
|
||||
# location['time_zone']['code'],
|
||||
# location['operator_id'],
|
||||
# location['provider']['name'],
|
||||
# location['is_proxy_capable'],
|
||||
# location['is_wireguard_capable']))
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fields:
|
||||
- name: group_a_code
|
||||
path: ['group_a', 'code']
|
||||
- name: code
|
||||
path: ['code']
|
||||
- name: id
|
||||
path: ['id']
|
||||
required: true
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
fields:
|
||||
- name: id
|
||||
path: ['id']
|
||||
required: true
|
||||
|
||||
- name: name
|
||||
path: ['name']
|
||||
|
||||
- name: public_key # this is ed25519
|
||||
path: ['public_key']
|
||||
|
||||
- name: nostr_public_key
|
||||
path: ['nostr_public_key']
|
||||
|
||||
- name: nostr_profile_reference
|
||||
path: ['nostr_profile_reference']
|
||||
|
||||
- name: nostr_attestation_event_reference
|
||||
path: ['nostr_attestation', 'event_reference']
|
||||
|
|
@ -2,7 +2,7 @@ import os
|
|||
|
||||
from PyQt6.QtWidgets import QApplication, QLabel, QLineEdit, QPushButton
|
||||
from PyQt6.QtGui import QIcon, QPixmap
|
||||
from PyQt6.QtCore import QSize, QTimer
|
||||
from PyQt6.QtCore import QSize, QTimer, QThread
|
||||
from PyQt6 import QtCore
|
||||
|
||||
from gui.v2.ui.pages.Page import Page
|
||||
|
|
@ -340,6 +340,14 @@ class PaymentDetailsPage(Page):
|
|||
self._populate_ticket_fields(invoice)
|
||||
if self.ticket_poll_timer.isActive():
|
||||
self.ticket_poll_timer.stop()
|
||||
|
||||
### NEW THREAD SAFETY DEBUG SECTION ####
|
||||
# print(f"Timer starting from thread: {QThread.currentThread()}")
|
||||
# print(f"Main thread is: {QApplication.instance().thread()}")
|
||||
# if QThread.currentThread() != QApplication.instance().thread():
|
||||
# print("⚠️ WARNING: Not on main thread!")
|
||||
###############################################################
|
||||
|
||||
self.ticket_poll_timer.start(3000)
|
||||
self.update_status.update_status('Awaiting ticket payment...')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue