Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions fetch_cord/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def main(
args = parse_args()
handle_args(args)

# Get the ids for the components
fetchcord_ids = {
"cpu": get_infos("cpus"),
"gpu": get_infos("gpus"),
Expand All @@ -136,14 +135,11 @@ def main(
"system_type": get_infos("system_types"),
}

# Stop event for the loop (injectable for tests)
if stop_event is None:
stop_event = Event()

# Load config
config = Config()
config["commands"] = Config("fetchcord_cmds.yml")["commands"]
# Load cycles
cycles = [Cycle(cycle, stop_event) for cycle in config["cycles"]]

# Apply CLI overrides: honor --debug / --time and drop disabled cycles.
Expand Down Expand Up @@ -215,7 +211,6 @@ def signal_handler(signum: int, frame: object) -> None:
signal(SIGINT, signal_handler)
signal(SIGTERM, signal_handler)

# Main loop
current_client_id = None
while not stop_event.is_set():
if pause.check():
Expand All @@ -238,7 +233,6 @@ def signal_handler(signum: int, frame: object) -> None:
# Windows a snapshot is a dozen PowerShell processes.
snapshot = fetch.snapshot()

# Loop through the cycles defined in the config
for cycle in cycles:
if stop_event.is_set():
break
Expand Down Expand Up @@ -275,7 +269,6 @@ def signal_handler(signum: int, frame: object) -> None:
large_image: {large_image}"""
)

# Reconnect if client_id changed
if client_id != current_client_id:
# Close ALL cycles' connections since Discord only allows one RP at a time
for c in cycles:
Expand Down
3 changes: 0 additions & 3 deletions fetch_cord/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def try_connect(self) -> None:
self.wait(DEFAULT_CYCLE_TIME_SECONDS)

def close_connection(self) -> None:
"""Fully close the RPC connection and ensure cleanup."""
if self.rpc is not None:
try:
self.rpc.clear()
Expand Down Expand Up @@ -107,14 +106,12 @@ def update(
except ConnectionResetError as e:
if self.debug:
print(f'update: ConnectionResetError for "{self.name}": {e}')
# Connection was reset - need to reconnect
self.close_connection()
raise

except exceptions.InvalidID as e:
if self.debug:
print(f'update: InvalidID for "{self.name}": {e}')
# Invalid client_id - need to re-setup with new client_id
self.close_connection()
raise

Expand Down
17 changes: 0 additions & 17 deletions fetch_cord/resources/fetchcord_cmds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,41 @@ commands:
system_profiler SPDisplaysDataType | grep 'Chipset Model' | xargs| cut -d " " -f3- | sed -e 's/" "/\t/g' -e 's/\"//g' | cut -f1-
mem:
Windows: |
# Get total physical memory (in bytes)
$TotalMemory = (Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory

# Get available physical memory (in bytes)
$AvailableMemory = (Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Memory).AvailableBytes

# Convert values to GB
$TotalMemory = [int64]$TotalMemory/1024/1024/1024
$AvailableMemory = [int64]$AvailableMemory/1024/1024/1024

# Calculate used memory
$UsedMemory = $TotalMemory - $AvailableMemory

# Output used and total memory in GB
Write-Output ("{0:N2} GB / {1:N2} GB" -f $UsedMemory, $TotalMemory)
Linux: &mem_sh |
# Get total physical memory (in bytes)
TotalMemory=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')

# Get available physical memory (in bytes)
AvailableMemory=$(cat /proc/meminfo | grep MemAvailable | awk '{print $2}')

# Convert values to GB
TotalMemory=$(awk "BEGIN {printf \"%.2f\", $TotalMemory / 1024 / 1024}")
AvailableMemory=$(awk "BEGIN {printf \"%.2f\", $AvailableMemory / 1024 / 1024}")

# Calculate used memory
UsedMemory=$(awk "BEGIN {printf \"%.2f\", $TotalMemory - $AvailableMemory}")

# Output used and total memory in GB
echo "$UsedMemory GB / $TotalMemory GB"
Darwin: |
# Get total physical memory (in bytes)
TotalMemory=$(sysctl -n hw.memsize)

# Get free memory in pages
FreePages=$(vm_stat | grep 'Pages free:' | awk '{print $3}' | sed 's/\.//')

# Get the page size in bytes (usually 4096)
PageSize=$(vm_stat | grep 'page size of' | awk '{print $8}')

# Calculate free memory in bytes
AvailableMemory=$(($FreePages * $PageSize))

# Convert values to GB
TotalMemory=$(awk "BEGIN {printf \"%.2f\", $TotalMemory / 1024 / 1024 / 1024}")
AvailableMemory=$(awk "BEGIN {printf \"%.2f\", $AvailableMemory / 1024 / 1024 / 1024}")

# Calculate used memory
UsedMemory=$(awk "BEGIN {printf \"%.2f\", $TotalMemory - $AvailableMemory}")

# Output used and total memory in GB
echo "$UsedMemory GB / $TotalMemory GB"
kernel:
Windows: |
Expand Down
17 changes: 0 additions & 17 deletions fetch_cord/resources/systemd_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,18 @@ def validate_systemd_cmd(cmd: str) -> str:


def get_systemd_user_dir() -> str:
"""Get the systemd user directory path."""
home = os.path.expanduser("~")
if not home or home == "~":
raise ValueError("Unable to determine home directory")
return os.path.join(home, ".local", "share", "systemd", "user")


def get_service_file_url(testing: bool = False) -> str:
"""Get the service file URL based on branch.

Args:
testing: If True, use testing branch; otherwise use master.

Returns:
The URL to download the service file from.
"""
branch = TESTING_BRANCH if testing else DEFAULT_BRANCH
return SERVICE_FILE_URL_TEMPLATE.format(branch=branch)


def systemd_cmd(cmd: str) -> None:
"""Execute a systemd command with validation."""
try:
validated_cmd = validate_systemd_cmd(cmd)
service_file = os.path.join(get_systemd_user_dir(), "fetchcord.service")
Expand All @@ -61,7 +51,6 @@ def systemd_cmd(cmd: str) -> None:


def install(testing: bool = False) -> None:
"""Install the systemd service."""
systemd_dir = get_systemd_user_dir()

try:
Expand All @@ -84,7 +73,6 @@ def install(testing: bool = False) -> None:


def uninstall() -> None:
"""Uninstall the systemd service."""
systemd_cmd("stop")
systemd_cmd("disable")

Expand All @@ -101,30 +89,25 @@ def uninstall() -> None:


def enable() -> None:
"""Enable the systemd service."""
systemd_cmd("enable")
sys.exit(0)


def disable() -> None:
"""Disable the systemd service."""
systemd_cmd("disable")
sys.exit(0)


def start() -> None:
"""Start the systemd service."""
systemd_cmd("start")
sys.exit(0)


def stop() -> None:
"""Stop the systemd service."""
systemd_cmd("stop")
sys.exit(0)


def status() -> None:
"""Check the systemd service status."""
systemd_cmd("status")
sys.exit(0)
4 changes: 0 additions & 4 deletions fetch_cord/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

# trunk-ignore(bandit/B404)
import subprocess
from importlib import resources
from pathlib import Path
Expand Down Expand Up @@ -39,7 +38,6 @@ def exec_bash(command: str) -> str:
# diagnostics, never a field value.
capture_output=True,
timeout=COMMAND_TIMEOUT_SECONDS,
# trunk-ignore(bandit/B602)
shell=True,
)
except subprocess.TimeoutExpired as exc:
Expand All @@ -60,8 +58,6 @@ def exec_bash(command: str) -> str:


def exec_ps1(command: str) -> str:
# trunk-ignore(bandit/B603)
# trunk-ignore(bandit/B607)
try:
result = subprocess.run(
[
Expand Down
3 changes: 1 addition & 2 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ grade: devel
description: |
FetchCord grabs your OS info and displays it as Discord Rich Presence.

The Snap package is unmaintained for 3.0 (classic confinement + core18
cannot ship Python 3.12). Prefer pip or Homebrew. This file is kept so
Prefer pip or Homebrew. This file is kept so
existing snap listings do not break the repo layout.
base: core24
confinement: classic
Expand Down
Loading
Loading