mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 16:53:36 +05:00
fix: disallow installing client config if another client config is installed
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ from components.webui_client.client_dialogs import (
|
||||
)
|
||||
from components.webui_client.client_utils import (
|
||||
backup_client_config_data,
|
||||
config_for_other_client_exist,
|
||||
detect_client_cfg_conflict,
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
@@ -36,7 +36,7 @@ def install_client_config(client_data: BaseWebClient) -> None:
|
||||
client_config: BaseWebClientConfig = client_data.client_config
|
||||
display_name = client_config.display_name
|
||||
|
||||
if config_for_other_client_exist(client_data.client):
|
||||
if detect_client_cfg_conflict(client_data):
|
||||
Logger.print_info("Another Client-Config is already installed! Skipped ...")
|
||||
return
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ from components.webui_client.client_dialogs import (
|
||||
)
|
||||
from components.webui_client.client_utils import (
|
||||
backup_mainsail_config_json,
|
||||
config_for_other_client_exist,
|
||||
detect_client_cfg_conflict,
|
||||
enable_mainsail_remotemode,
|
||||
restore_mainsail_config_json,
|
||||
symlink_webui_nginx_log,
|
||||
@@ -90,7 +90,7 @@ def install_client(client: BaseWebClient) -> None:
|
||||
if (
|
||||
kl_instances
|
||||
and not client_config.config_dir.exists()
|
||||
and not config_for_other_client_exist(client_to_ignore=client.client)
|
||||
and not detect_client_cfg_conflict(client)
|
||||
):
|
||||
print_install_client_config_dialog(client)
|
||||
question = f"Download the recommended {client_config.display_name}?"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# ======================================================================= #
|
||||
from __future__ import annotations
|
||||
|
||||
import json # noqa: I001
|
||||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import List, get_args
|
||||
@@ -16,9 +16,9 @@ from typing import List, get_args
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.webui_client.base_data import (
|
||||
BaseWebClient,
|
||||
BaseWebClientConfig,
|
||||
WebClientType,
|
||||
)
|
||||
from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
@@ -187,30 +187,24 @@ def get_existing_clients() -> List[BaseWebClient]:
|
||||
return installed_clients
|
||||
|
||||
|
||||
def get_existing_client_config() -> List[BaseWebClient]:
|
||||
clients = list(get_args(WebClientType))
|
||||
installed_client_configs: List[BaseWebClient] = []
|
||||
for client in clients:
|
||||
c_config_data: BaseWebClientConfig = client.client_config
|
||||
if c_config_data.config_dir.exists():
|
||||
installed_client_configs.append(client)
|
||||
|
||||
return installed_client_configs
|
||||
|
||||
|
||||
def config_for_other_client_exist(client_to_ignore: WebClientType) -> bool:
|
||||
def detect_client_cfg_conflict(curr_client: BaseWebClient) -> bool:
|
||||
"""
|
||||
Check if any other client configs are present on the system.
|
||||
It is usually not harmful, but chances are they can conflict each other.
|
||||
Multiple client configs are, at least, redundant to have them installed
|
||||
:param client_to_ignore: The client name to ignore for the check
|
||||
:param curr_client: The client name to check for the conflict
|
||||
:return: True, if other client configs were found, else False
|
||||
"""
|
||||
|
||||
clients = set([c.name for c in get_existing_client_config()])
|
||||
clients = clients - {client_to_ignore.value}
|
||||
mainsail_cfg_status: ComponentStatus = get_client_config_status(MainsailData())
|
||||
fluidd_cfg_status: ComponentStatus = get_client_config_status(FluiddData())
|
||||
|
||||
return True if len(clients) > 0 else False
|
||||
if curr_client.client == WebClientType.MAINSAIL and fluidd_cfg_status.status == 2:
|
||||
return True
|
||||
if curr_client.client == WebClientType.FLUIDD and mainsail_cfg_status.status == 2:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_download_url(base_url: str, client: BaseWebClient) -> str:
|
||||
|
||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
||||
WebClientConfigType,
|
||||
WebClientType,
|
||||
)
|
||||
from components.webui_client.client_utils import get_download_url
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
|
||||
@@ -47,6 +46,8 @@ class FluiddData(BaseWebClient):
|
||||
|
||||
@property
|
||||
def download_url(self) -> str:
|
||||
from components.webui_client.client_utils import get_download_url
|
||||
|
||||
return get_download_url(self.BASE_DL_URL, self)
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user