From fcd3cc118aacf7a13464c8fb86d9d546724d409c Mon Sep 17 00:00:00 2001 From: Mohammad Faiz Date: Wed, 22 Jul 2026 18:56:46 +0530 Subject: [PATCH] Fix crashes, clean up dead code, and fix documentation This commit fixes several issues that would cause the app to crash or behave incorrectly: 1. CRASH FIX - No internet: The app needed server settings to run, but if the internet was off or the server was down, the app would crash. Now it keeps working using the last saved settings, or shows a helpful message instead of crashing. 2. CRASH FIX - Settings window: A window where you add passwords/API keys would crash when opening because of a wrong icon instruction. Fixed it to match how every other window in the app already works. 3. SPEED IMPROVEMENT - Unnecessary work: A button was secretly redrawing itself 60 times every second even when untouched. Now it only updates when you actually hover over it - same look, no wasted work. 4. DOCUMENTATION FIX - Wrong command: The README told users to type 'python main.py' but that file doesn't exist, so it would fail immediately. Corrected to the real filename. 5. CLEANUP - Removed dead files and unused code: - Deleted an empty placeholder file (Docs/app.py - was just a blank line) - Deleted a shopping list for software packages that weren't actually needed (Docs/requirements.txt) - Removed 4 lines of imported code that were never used - Created .gitignore so temporary files don't get accidentally saved All changes are safe and make the app more reliable. --- .gitignore | 13 +++++++++++++ Desktop_App/app.py | 14 ++++++-------- Desktop_App/mcp_link.py | 17 ++++++++++++++--- Docs/app.py | 1 - Docs/requirements.txt | 2 -- README.md | 2 +- 6 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 .gitignore delete mode 100644 Docs/app.py delete mode 100644 Docs/requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4500e08 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +__pycache__/ +*.py[cod] +*$py.class +*.egg-info/ +dist/ +build/ +*.egg +.env +.venv/ +venv/ +env/ +*.exe +*.zip diff --git a/Desktop_App/app.py b/Desktop_App/app.py index c383d4a..8d3181b 100644 --- a/Desktop_App/app.py +++ b/Desktop_App/app.py @@ -4,7 +4,7 @@ THIS IS NOT YET DEPLOYED. Here it is about Desktop APP. """ -import sys, os, math, random, threading, json +import sys, os, math, random, json from pathlib import Path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) @@ -14,8 +14,8 @@ QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QTextEdit, QLineEdit, QPushButton, QFrame, QScrollArea, QStackedWidget, QSizePolicy, QGraphicsOpacityEffect, - QTabWidget, QDialog, QDialogButtonBox, QMessageBox, - QGroupBox, QComboBox + QDialog, QDialogButtonBox, QMessageBox, + QComboBox ) from PySide6.QtCore import ( QThread, Signal, Qt, QTimer, QPointF, QRectF, QRect, @@ -339,10 +339,8 @@ def __init__(self,text,accent="#2AFFA0",parent=None): super().__init__(text,parent); self._ac=QColor(accent); self._h=0.0 self.setCursor(Qt.PointingHandCursor); self.setFixedHeight(48) self.setFont(QFont("Segoe UI",11,QFont.DemiBold)) - QTimer(self,timeout=self.update,interval=16).start() - - def enterEvent(self,e): self._h=1.0 - def leaveEvent(self,e): self._h=0.0 + def enterEvent(self,e): self._h=1.0; self.update() + def leaveEvent(self,e): self._h=0.0; self.update() def paintEvent(self,_): p=QPainter(self); p.setRenderHint(QPainter.Antialiasing) @@ -1039,7 +1037,7 @@ def __init__(self, parent=None, group_name="", existing_data=None, lock_name=Fal title="🔑 Credential Group", subtitle=None): super().__init__(parent) self.setWindowTitle(title.replace("🔑","").strip() or "Credential Group") - self.setWindowIcon("npmai.png") + self.setWindowIcon(QIcon("npmai.png")) self.setMinimumWidth(440) self.setStyleSheet(f"QDialog{{background:{P['void']};}}") self._row_widgets = [] diff --git a/Desktop_App/mcp_link.py b/Desktop_App/mcp_link.py index e1ead6c..30df3aa 100644 --- a/Desktop_App/mcp_link.py +++ b/Desktop_App/mcp_link.py @@ -1,4 +1,3 @@ -import os import json import uuid import threading @@ -13,13 +12,25 @@ CONFIG_URL = "https://raw.githubusercontent.com/npmaiecosystem/NPM-AutoCode-AI/refs/heads/main/Desktop_App/app_config.json" def load_config() -> dict: - """Fetch latest config from GitHub""" + """Fetch latest config from GitHub, falling back to local cache.""" try: response = requests.get(CONFIG_URL, timeout=8) if response.status_code == 200: - return response.json() + data = response.json() + try: + CONFIG_PATH.parent.mkdir(exist_ok=True) + CONFIG_PATH.write_text(json.dumps(data)) + except Exception: + pass + return data except Exception as e: print(f"Failed to fetch remote config: {e}") + if CONFIG_PATH.exists(): + try: + return json.loads(CONFIG_PATH.read_text()) + except Exception: + pass + return {} def save_config(url: str, anon_key: str, mcp_base_url: str = None): diff --git a/Docs/app.py b/Docs/app.py deleted file mode 100644 index 8b13789..0000000 --- a/Docs/app.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Docs/requirements.txt b/Docs/requirements.txt deleted file mode 100644 index cef5a16..0000000 --- a/Docs/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -Flask -gunicorn diff --git a/README.md b/README.md index d76f6cf..136576b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Install the app: [Download Latest Release](https://github.com/sonuramashishnpm/NPM-AutoCode-AI/releases/download/v2.2/NPM_AutoCode_AI.zip) 1. Unzip the file. -2. Run `NPM_AutoCode_AI.exe` (Windows) or `python main.py` (Python 3.12+). +2. Run `NPM_AutoCode_AI.exe` (Windows) or `python Desktop_App/app.py` (Python 3.12+). 3. Enter your task in the input box (e.g., "Plot a sine wave"). 4. Click **Generate & Execute**. 5. Watch logs and progress bar – AI generates, checks safety, executes, and fixes errors if needed.