diff --git a/README.md b/README.md index 4ef171f..8d2bacd 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Tech: nixOS, ollama, postgres, FastAPI, huggingface-transformers --- ## (MacOS) Easy Install With .dmg +[![Download](https://img.shields.io/badge/Download-File-blue?style=for-the-badge&logo=google-drive)](https://drive.google.com/file/d/1UpI8YOqqXnSQQbCo3oB28-w8nNlbhPHp/view?usp=sharing) + *(Experimental)*: This is new, and should work on most MacOS machines! Simply double click the topos.dmg file, and drag the app into your Applications directory. You should be able to launch the Topos service anywhere from your machine. @@ -39,7 +41,7 @@ If nix is not installed: windows: `sh <(curl -L https://nixos.org/nix/install) --daemon` 2. Run Topos and all its dependencies: ``` - nix run github:jonnyjohnson1/topos-cli/v0.2.7 + nix run github:jonnyjohnson1/topos-cli/v0.2.8 ``` This will start all services including Topos, Postgres, Kafka, and Ollama. @@ -146,4 +148,4 @@ Insert this url into the field under settings-> "Api Endpoints" -> "Custom API" ## Future Setup [ ] Theme the TUI [docs](https://f1bonacc1.github.io/process-compose/tui/) -[ ] Remotely connect to TUI [docs](https://f1bonacc1.github.io/process-compose/client/) +[ ] Remotely connect to TUI [docs](https://f1bonacc1.github.io/process-compose/client/) \ No newline at end of file diff --git a/justfile b/justfile index 3532c76..f3ee046 100644 --- a/justfile +++ b/justfile @@ -27,4 +27,8 @@ stoppg: export PGDATA=$(pwd)/pgdata echo "Stopping any existing PostgreSQL server..." pg_ctl -D "$PGDATA" stop || echo "No existing server to stop." - \ No newline at end of file + + +# TESTS +test_update: + poetry run python -m topos.test.topos_updater.test_check_update \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 6659204..273ed2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "topos" -version = "0.2.7" +version = "0.2.8" description = "The official Python client for Topos." authors = ["Dialogues "] license = "MIT" diff --git a/scripts/install.sh b/scripts/install.sh index eb521b5..58bf733 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -15,6 +15,6 @@ tell application "Terminal" echo 'Nix installation complete.'; \ else \ echo 'Nix is already installed.'; \ - fi && nix run github:jonnyjohnson1/topos-cli/v0.2.7 --extra-experimental-features nix-command --extra-experimental-features flakes --show-trace" + fi && nix run github:jonnyjohnson1/topos-cli/v0.2.8 --extra-experimental-features nix-command --extra-experimental-features flakes --show-trace" end tell EOF \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 7aa2917..c289fda 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = topos -version = 0.2.7 +version = 0.2.8 author = Jonny Johnson author_email = jonnyjohnson1@gmail.com description = For interacting with Topos tooling diff --git a/setup.py b/setup.py index 1fce45d..e3a7194 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='topos', - version='0.2.7', + version='0.2.8', packages=find_packages(), entry_points={ 'console_scripts': [ diff --git a/topos.dmg b/topos.dmg index 041db98..c14765c 100644 Binary files a/topos.dmg and b/topos.dmg differ diff --git a/topos/app/menu_bar_app.py b/topos/app/menu_bar_app.py index b43f547..e46a44d 100644 --- a/topos/app/menu_bar_app.py +++ b/topos/app/menu_bar_app.py @@ -30,58 +30,98 @@ def start_web_app(): api_thread.start() # Create and start the tray icon on the main thread create_tray_icon() - + + +status_checks = { + "health_check": False, + "update_check": False, +} + def check_health(icon): + """Periodically check the service health.""" certs = get_ssl_certificates() if not os.path.exists(certs['cert_path']): print(f"Certificate file not found: {certs['cert_path']}") if not os.path.exists(certs['key_path']): print(f"Key file not found: {certs['key_path']}") - + while icon.visible: try: - with warnings.catch_warnings(): # cert=(certs['cert_path'], certs['key_path']) #for verification, but wasn't working + with warnings.catch_warnings(): warnings.filterwarnings('ignore', message='Unverified HTTPS request') response = requests.get(API_URL, verify=False) - if response.status_code == 200: - update_status(icon, "Service is running", (170, 255, 0, 255)) - else: - update_status(icon, "Service is not running", "red") + # Update health check status based on response + status_checks["health_check"] = response.status_code == 200 except requests.exceptions.RequestException as e: - update_status(icon, f"Error: {str(e)}", "red") + print(f"Health check error: {str(e)}") + status_checks["health_check"] = False + finally: + evaluate_icon_status(icon) time.sleep(5) -def check_for_update(): - # Check the latest release status from the GitHub API - # Returns True if an update is available, else False - update_is_available = check_for_update("jonnyjohnson1", "topos-cli") - return update_is_available - +def check_update(): + """Check if an update is available.""" + return check_for_update("jonnyjohnson1", "topos-cli") + + +def evaluate_icon_status(icon): + """Evaluate and update the icon's status and menu based on checks.""" + if not status_checks["health_check"]: + # If the service is not running + update_status(icon, "Service is not running", "red") + elif status_checks["update_check"]: + # If an update is available + update_status(icon, "Update available", (255, 165, 0, 255)) # Orange + else: + # If all checks pass + update_status(icon, "Service is running", (170, 255, 0, 255)) # Green + + # Update the menu based on the current status + update_menu(icon) + def check_update_available(icon): + """Periodically check for updates.""" while icon.visible: - if check_for_update(): - update_status(icon, "Update available", (255, 165, 0, 255)) # Orange indicator - # Add "Check for Update" option if update is available - icon.menu = pystray.Menu( - pystray.MenuItem("Open API Docs", open_docs), - pystray.MenuItem("Update your Topos", pull_latest_release), - pystray.MenuItem("Exit", on_exit) - ) - else: - # Set the menu back to its default state without "Check for Update" - icon.menu = pystray.Menu( - pystray.MenuItem("Open API Docs", open_docs), - pystray.MenuItem("Exit", on_exit) - ) - update_status(icon, "Service is running", (170, 255, 0, 255)) # Normal green status - time.sleep(60) # Check every minute + # Update the update check status + status_checks["update_check"] = check_update() + evaluate_icon_status(icon) + time.sleep(60) def pull_latest_release(): print("Pulling latest release...") update_topos() +def update_icon(icon): + # Start a separate thread for checking updates + update_thread = threading.Thread(target=check_update_available, args=(icon,), daemon=True) + update_thread.start() + + # Start a separate thread for checking health + health_thread = threading.Thread(target=check_health, args=(icon,), daemon=True) + health_thread.start() + def update_status(icon, text, color): icon.icon = create_image(color) + # icon.notify(text) + +def update_menu(icon): + """Dynamically update the icon menu based on update status.""" + if status_checks["update_check"]: + icon.menu = pystray.Menu( + pystray.MenuItem("Open API Docs", open_docs), + pystray.MenuItem("Update Topos", pull_latest_release), + pystray.MenuItem("Exit", on_exit) + ) + else: + icon.menu = pystray.Menu( + pystray.MenuItem("Open API Docs", open_docs), + pystray.MenuItem("Exit", on_exit) + ) + +# def update_status(icon, text, color): +# icon.icon = create_image(color) +# icon.notify(text) + def open_docs(): webbrowser.open_new(DOCS_URL) @@ -115,7 +155,7 @@ def create_tray_icon(): def on_setup(icon): icon.visible = True # Start health check in a separate thread - health_thread = threading.Thread(target=check_health, args=(icon,)) + health_thread = threading.Thread(target=update_icon, args=(icon,)) health_thread.daemon = True health_thread.start() diff --git a/topos/test/topos_updater/test_check_update.py b/topos/test/topos_updater/test_check_update.py new file mode 100644 index 0000000..f3247ab --- /dev/null +++ b/topos/test/topos_updater/test_check_update.py @@ -0,0 +1,7 @@ +from ...utils.check_for_update import check_for_update, update_topos + +import logging +logging.basicConfig(level=logging.DEBUG) + +update_is_available = check_for_update("jonnyjohnson1", "topos-cli") +print(update_is_available) \ No newline at end of file diff --git a/topos/utils/check_for_update.py b/topos/utils/check_for_update.py index 7952e8c..0d48793 100644 --- a/topos/utils/check_for_update.py +++ b/topos/utils/check_for_update.py @@ -6,7 +6,6 @@ # logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) - repo_owner = "jonnyjohnson1" repo_name = "topos-cli" @@ -16,7 +15,7 @@ def get_local_version_with_poetry(): """ result = subprocess.run(["poetry", "version", "--short"], capture_output=True, text=True, check=True) local_version = "v" + result.stdout.strip() - # logger.debug(f"Local version from Poetry: {local_version}") + logger.debug(f"Local version from Poetry: {local_version}") return local_version def get_latest_release_tag(repo_owner, repo_name): @@ -28,7 +27,7 @@ def get_latest_release_tag(repo_owner, repo_name): response = requests.get(url) response.raise_for_status() latest_release = response.json()["tag_name"] - # logger.debug(f"Latest release from GitHub: {latest_release}") + logger.debug(f"Latest release from GitHub: {latest_release}") return latest_release except requests.ConnectionError: logger.debug("No internet connection. Cannot check for the latest release.")