forked from Support/sp-hydra-veil-gui
Compare commits
2 commits
db9553a0f5
...
f7d792745a
| Author | SHA1 | Date | |
|---|---|---|---|
| f7d792745a | |||
| 17c6a8e258 |
4 changed files with 40 additions and 7 deletions
|
|
@ -107,8 +107,6 @@ def emergency_sync():
|
||||||
# BEGIN PROGRAM
|
# BEGIN PROGRAM
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# ASSETS FOLDER
|
# ASSETS FOLDER
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from PyQt6 import QtGui
|
||||||
from PyQt6.QtCore import Qt, QTimer, QEvent
|
from PyQt6.QtCore import Qt, QTimer, QEvent
|
||||||
|
|
||||||
from core.Constants import Constants
|
from core.Constants import Constants
|
||||||
|
from core.infrastructure.global_state_coordinator import evaluate_state_on_startup
|
||||||
from core.infrastructure.service_registry import ServiceLocator
|
from core.infrastructure.service_registry import ServiceLocator
|
||||||
from core.controllers.ConfigurationController import ConfigurationController
|
from core.controllers.ConfigurationController import ConfigurationController
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
|
|
@ -909,6 +910,10 @@ class CustomWindow(QMainWindow):
|
||||||
|
|
||||||
|
|
||||||
def start_ui(force_sync):
|
def start_ui(force_sync):
|
||||||
|
worked = evaluate_state_on_startup()
|
||||||
|
if worked.valid:
|
||||||
|
core_logger.info("State evaluated.")
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
calculate_max_screensize(app)
|
calculate_max_screensize(app)
|
||||||
window = CustomWindow(force_sync=force_sync)
|
window = CustomWindow(force_sync=force_sync)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
from core.services.profiles.profile_connections import enable_profile #, disable_profile
|
from core.services.profiles.profile_connections import enable_profile #, disable_profile
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
from core.models.Configuration import Configuration, ConnectionChoice
|
from core.models.Configuration import Configuration, ConnectionChoice
|
||||||
from core.services.subscriptions.subscriptions_by_protocol import get_profile_subscription, start_new_payment_cycle
|
from core.services.subscriptions.subscriptions_by_protocol import get_profile_subscription, start_new_payment_cycle, wipe_subscription
|
||||||
|
from core.utils.check_if_time_lapsed import check_if_time_lapsed
|
||||||
from core.models.enum_models import PaymentCategory
|
from core.models.enum_models import PaymentCategory
|
||||||
from core.utils.type_checker import type_checker
|
from core.utils.type_checker import type_checker
|
||||||
from core.models.Result import Result, ResultError
|
from core.models.Result import Result, ResultError
|
||||||
|
|
@ -62,6 +63,16 @@ def navigate_to_new_sub_page() -> Result:
|
||||||
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="id", message="No subscription. Pick a payment method.")
|
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="id", message="No subscription. Pick a payment method.")
|
||||||
|
|
||||||
|
|
||||||
|
@register_action(ResultError.EXPIRED_SUB)
|
||||||
|
def wipe_expired_subscription(profile_id: int) -> Result:
|
||||||
|
"""Call core to wipe a subscription, then navigate to the billing page"""
|
||||||
|
wiped = wipe_subscription(profile_id)
|
||||||
|
if wiped.valid:
|
||||||
|
return navigate_to_new_sub_page()
|
||||||
|
else:
|
||||||
|
return wiped
|
||||||
|
|
||||||
|
|
||||||
def filter_subscription(profile_id: int) -> Result:
|
def filter_subscription(profile_id: int) -> Result:
|
||||||
"""Evaluate if this profile has a subscription that's ready to connect."""
|
"""Evaluate if this profile has a subscription that's ready to connect."""
|
||||||
|
|
||||||
|
|
@ -81,6 +92,15 @@ def filter_subscription(profile_id: int) -> Result:
|
||||||
logger.info(f"Returning the error of start_result {start_result}")
|
logger.info(f"Returning the error of start_result {start_result}")
|
||||||
return start_result
|
return start_result
|
||||||
|
|
||||||
|
expiration_date = subscription.expires_at
|
||||||
|
if not expiration_date:
|
||||||
|
# auto check tickets would be here.
|
||||||
|
return navigate_to_new_sub_page()
|
||||||
|
|
||||||
|
expired = check_if_time_lapsed(expiration_date)
|
||||||
|
if expired:
|
||||||
|
return Result(valid=False, error_type=ResultError.EXPIRED_SUB, message="This subscription is expired, would you like to wipe it and get a new one?")
|
||||||
|
|
||||||
# has a valid sub:
|
# has a valid sub:
|
||||||
logger.info(f"Profile id {profile_id} has a valid subscription ready to go..")
|
logger.info(f"Profile id {profile_id} has a valid subscription ready to go..")
|
||||||
return Result(valid=True)
|
return Result(valid=True)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from core.infrastructure.global_state import ProfileStateRepository
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
from core.controllers.SystemStateController import SystemStateController
|
from core.controllers.SystemStateController import SystemStateController
|
||||||
from core.models.system.SystemProfile import SystemProfile
|
from core.models.system.SystemProfile import SystemProfile
|
||||||
|
|
@ -21,7 +22,16 @@ def _system_state_profile_id():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def is_profile_enabled_for_gui(profile):
|
|
||||||
if isinstance(profile, SystemProfile) and _connection_code(profile) in SINGBOX_PROTOCOLS:
|
|
||||||
return _system_state_profile_id() == int(profile.id)
|
def is_profile_enabled_for_gui(profile) -> bool:
|
||||||
return ProfileController.is_enabled(profile)
|
"""Checks Profile State Against in-memory Repo"""
|
||||||
|
is_enabled = ProfileStateRepository().is_profile_active(profile.id)
|
||||||
|
print(f"profile id: {profile.id} | Enabled: {is_enabled}")
|
||||||
|
return is_enabled
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# if isinstance(profile, SystemProfile) and _connection_code(profile) in SINGBOX_PROTOCOLS:
|
||||||
|
# return _system_state_profile_id() == int(profile.id)
|
||||||
|
# return ProfileController.is_enabled(profile)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue