From 072db77f9456ed40665364bd652e3c7caf8f5900 Mon Sep 17 00:00:00 2001 From: KevinKor01 Date: Sat, 6 Sep 2025 02:18:21 +0300 Subject: [PATCH] Added -backend for frontend intergration --- CLI/Init.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/CLI/Init.py b/CLI/Init.py index 2338ea3..9e7c30a 100644 --- a/CLI/Init.py +++ b/CLI/Init.py @@ -2,6 +2,12 @@ import configparser import os from pathlib import Path import requests +import argparse +import sys + +parser = argparse.ArgumentParser(description='TiropitLauncher CLI & Back-End') +parser.add_argument('-backend', help="Runs the app in backend mode (no UI)", action="store_true") + #declare default vars class Config(): @@ -20,6 +26,8 @@ class Server(): else: Icon = "⛔" +args = parser.parse_args() + #declare files config = configparser.ConfigParser() @@ -29,12 +37,16 @@ class Display(): def Clear(): os.system('cls' if os.name == 'nt' else 'clear') + + + def showIntroText(): print("Tiropit Launcher CLI - Release Branch") print(f"[TCLI]=============[Select option]==============[{Config.version}]") + def WarnMissingConfig(ConfigError): print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}") print("Program will exit before it crashes :)") @@ -45,6 +57,8 @@ def WarnMissingConfig(ConfigError): exit(0) + + def makeConfig(): config['DEFAULT'] = {'Version': Config.version} config['ACCOUNT'] = {} @@ -101,20 +115,27 @@ def loadConfig(): except Exception as e: WarnMissingConfig(e) + + def grabServerResolver(): try: - response = requests.get("https://kevinblog.sytes.net/APIS/test1.php") + response = requests.get("https://kevinblog.sytes.net/APIhS/test1.php") response.raise_for_status() data = response.json() server_ip = data.get("HostIp") - Server.isReachable = False + Server.isReachable = True + Server.state = "Connected" Server.host = server_ip + if args.backend: print(f"2:CONNECTED TO: {server_ip}") return server_ip except requests.exceptions.RequestException as e: - print("Error resolving a host, Considering service is offline.") + Server.isReachable = False + Server.state = f"Failed/Timed Out - {e}" + if args.backend: print(f"3:FAILED CONN TO: {e}") + else: print("Error resolving a host, Considering service is offline.") pass @@ -230,6 +251,12 @@ def showMenu(menuID): #Begin -grabServerResolver() -checkConfig() -showMenu(1) +if not args.backend: + + grabServerResolver() + checkConfig() + showMenu(1) +else: + print("1:=== BACKEND MODE ===") + grabServerResolver() + \ No newline at end of file