added --gui option to fabric. this will open the gui

This commit is contained in:
Jonathan Dunn 2024-04-01 10:39:33 -04:00
parent 7e3e38ee18
commit fda9e9866d
2 changed files with 40 additions and 1 deletions

View File

@ -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()

View File

@ -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}")