mirror of
https://github.com/peter-tanner/LTspice-discord-rich-presence.git
synced 2024-11-30 14:10:16 +08:00
Instal and run scripts, recognize maximized views
This commit is contained in:
parent
fb3d9d5edd
commit
db2adcb15e
21
README.md
21
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:
|
||||
|
|
BIN
icons/graph.png
BIN
icons/graph.png
Binary file not shown.
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 9.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
4
install.ps1
Normal file
4
install.ps1
Normal file
|
@ -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
|
|
@ -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,6 +124,7 @@ def main() -> None:
|
|||
foreground_hwnd = win32gui.GetForegroundWindow()
|
||||
pid = win32process.GetWindowThreadProcessId(foreground_hwnd)
|
||||
if pid[-1] >= 0:
|
||||
try:
|
||||
active_process = psutil.Process(pid[-1])
|
||||
if active_process.name() in WINDOW_HANDLERS.keys():
|
||||
handler = WINDOW_HANDLERS[active_process.name()]
|
||||
|
@ -124,6 +133,8 @@ def main() -> None:
|
|||
"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"]):
|
||||
|
|
Loading…
Reference in New Issue
Block a user