diff --git a/README.md b/README.md index 4dfb34a..268e02b 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,27 @@ Install dependencies: -```bash -python -m venv .venv -source .venv/bin/activate -python -m pip install -r requirements.txt +```powershell +.\install.ps1 ``` Run with: -```bash -python .\ltspice-discord.py +```powershell +.\run.ps1 ``` +Create a shortcut in `shell:startup` to start listening on startup: + +Target: `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command [PATH]\ltspice-discord\run.ps1`\ +Start in: `[PATH]\ltspice-discord\` + +## How does it work + +This script extracts file type from the title of any LTspice application then uses it to update the status on Discord. + +The code should be short enough to audit if you are worried about data exfiltration, etc. + ## Icons Icons adapted from: diff --git a/icons/graph.png b/icons/graph.png index 513360c..b438ee9 100644 Binary files a/icons/graph.png and b/icons/graph.png differ diff --git a/icons/schematic.png b/icons/schematic.png index cbfaf88..a616d12 100644 Binary files a/icons/schematic.png and b/icons/schematic.png differ diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..f79f837 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,4 @@ +cd $(Split-Path $MyInvocation.MyCommand.Path) +python -m venv .venv +.\.venv\Scripts\Activate.ps1 +python -m pip install -r requirements.txt \ No newline at end of file diff --git a/ltspice-discord.py b/ltspice-discord.py index 7c07db2..a808940 100644 --- a/ltspice-discord.py +++ b/ltspice-discord.py @@ -33,6 +33,14 @@ def handle_ltspice(title: str) -> None: global last_state filename = title.replace("LTspice XVII - ", "") file, ext = os.path.splitext(filename) + + # The window title is of the format "LTspice XVII - [filename.extension]" + # if the view is maximized + if ext and ext[-1] == "]": + ext = ext[:-1] + file = file[1:] + # filename = filename[1:-1] + state = {} if ext in (".asc",): # SCHEMATICS state = { @@ -116,14 +124,17 @@ def main() -> None: foreground_hwnd = win32gui.GetForegroundWindow() pid = win32process.GetWindowThreadProcessId(foreground_hwnd) if pid[-1] >= 0: - active_process = psutil.Process(pid[-1]) - if active_process.name() in WINDOW_HANDLERS.keys(): - handler = WINDOW_HANDLERS[active_process.name()] - if handler(win32gui.GetWindowText(foreground_hwnd)): - last_program = { - "pid": active_process.pid, - "path": active_process.name(), - } + try: + active_process = psutil.Process(pid[-1]) + if active_process.name() in WINDOW_HANDLERS.keys(): + handler = WINDOW_HANDLERS[active_process.name()] + if handler(win32gui.GetWindowText(foreground_hwnd)): + last_program = { + "pid": active_process.pid, + "path": active_process.name(), + } + except psutil.NoSuchProcess: + pass if last_program["pid"] is not None and last_program[ "pid" ] not in find_active_processes(last_program["path"]): diff --git a/run.ps1 b/run.ps1 new file mode 100644 index 0000000..b99494a --- /dev/null +++ b/run.ps1 @@ -0,0 +1,3 @@ +cd $(Split-Path $MyInvocation.MyCommand.Path) +.\.venv\Scripts\Activate.ps1 +Start-Process "python" -ArgumentList "ltspice-discord.py" -WindowStyle Hidden