Add Flag to Start App without Native GUI

This commit is contained in:
Debanjum Singh Solanky 2022-08-11 20:59:57 +03:00
parent b74ca1def6
commit 6af2d6bb6d
2 changed files with 30 additions and 20 deletions

View file

@ -29,6 +29,11 @@ def run():
args = cli(state.cli_args)
set_state(args)
if args.no_gui:
# Start Server
configure_server(args, required=True)
start_server(app, host=args.host, port=args.port, socket=args.socket)
else:
# Setup GUI
gui = QtWidgets.QApplication([])
gui.setQuitOnLastWindowClosed(False)
@ -56,6 +61,13 @@ def set_state(args):
state.verbose = args.verbose
def start_server(app, host=None, port=None, socket=None):
if socket:
uvicorn.run(app, proxy_headers=True, uds=socket)
else:
uvicorn.run(app, host=host, port=port)
class ServerThread(QThread):
def __init__(self, app, host=None, port=None, socket=None):
super(ServerThread, self).__init__()
@ -68,10 +80,7 @@ class ServerThread(QThread):
self.wait()
def run(self):
if self.socket:
uvicorn.run(app, proxy_headers=True, uds=self.socket)
else:
uvicorn.run(app, host=self.host, port=self.port)
start_server(self.app, self.host, self.port, self.socket)
if __name__ == '__main__':

View file

@ -11,6 +11,7 @@ def cli(args=None):
# Setup Argument Parser for the Commandline Interface
parser = argparse.ArgumentParser(description="Start Khoj; A Natural Language Search Engine for your personal Notes, Transactions and Photos")
parser.add_argument('--config-file', '-c', default='~/.khoj/khoj.yml', type=pathlib.Path, help="YAML file to configure Khoj")
parser.add_argument('--no-gui', action='store_true', default=False, help="Do not show native desktop GUI. Default: false")
parser.add_argument('--regenerate', action='store_true', default=False, help="Regenerate model embeddings from source files. Default: false")
parser.add_argument('--verbose', '-v', action='count', default=0, help="Show verbose conversion logs. Default: 0")
parser.add_argument('--host', type=str, default='127.0.0.1', help="Host address of the server. Default: 127.0.0.1")