From fda9e9866dc6efa0d2ad3ef136c3dcd6fc3b2919 Mon Sep 17 00:00:00 2001 From: Jonathan Dunn Date: Mon, 1 Apr 2024 10:39:33 -0400 Subject: [PATCH] added --gui option to fabric. this will open the gui --- installer/client/cli/fabric.py | 6 +++++- installer/client/cli/utils.py | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/installer/client/cli/fabric.py b/installer/client/cli/fabric.py index 8c7772b..f05e4fb 100755 --- a/installer/client/cli/fabric.py +++ b/installer/client/cli/fabric.py @@ -1,4 +1,4 @@ -from .utils import Standalone, Update, Setup, Alias +from .utils import Standalone, Update, Setup, Alias, run_electron_app import argparse import sys import os @@ -28,6 +28,7 @@ def main(): const="analyzepaper.txt", default=None, ) + parser.add_argument("--gui", help="Use the GUI", action="store_true") parser.add_argument( "--stream", "-s", @@ -90,6 +91,9 @@ def main(): from .utils import AgentSetup AgentSetup().run() sys.exit() + if args.gui: + run_electron_app() + sys.exit() if args.update: Update() Alias() diff --git a/installer/client/cli/utils.py b/installer/client/cli/utils.py index 49d1c7f..1d927c9 100644 --- a/installer/client/cli/utils.py +++ b/installer/client/cli/utils.py @@ -8,6 +8,7 @@ import platform from dotenv import load_dotenv import zipfile import tempfile +import subprocess import re import shutil @@ -659,3 +660,37 @@ class AgentSetup: else: # If it does not end with a newline, add one before the new entries f.write(f"\n{browserless_entry}\n{serper_entry}\n") + + +def run_electron_app(): + # Step 1: Set CWD to the directory of the script + os.chdir(os.path.dirname(os.path.realpath(__file__))) + + # Step 2: Check for the './installer/client/gui' directory + target_dir = '../gui' + if not os.path.exists(target_dir): + print(f"The directory { + target_dir} does not exist. Please check the path and try again.") + return + + # Step 3: Check for NPM installation + try: + subprocess.run(['npm', '--version'], check=True, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + except subprocess.CalledProcessError: + print("NPM is not installed. Please install NPM and try again.") + return + + # If this point is reached, NPM is installed. + # Step 4: Change directory to the Electron app's directory + os.chdir(target_dir) + + # Step 5: Run 'npm install' and 'npm start' + try: + print("Running 'npm install'... This might take a few minutes.") + subprocess.run(['npm', 'install'], check=True) + print( + "'npm install' completed successfully. Starting the Electron app with 'npm start'...") + subprocess.run(['npm', 'start'], check=True) + except subprocess.CalledProcessError as e: + print(f"An error occurred while executing NPM commands: {e}")