chore: refactor imports and adopt new utils utilities

This commit is contained in:
sankalp committed 2026-07-14 18:45:52 +05:45
1 parent b2114f52b1
commit 6f2d0bf444
65 files changed
+221 -266

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
from fabric.utils import GLib, get_relative_path, logger, os
from utils.functions import parse_timeout_string
from utils.utils import toml_file
from utils.gtk_utils import toml_file
HOME_DIR = GLib.get_home_dir()
APP_NAME = "modus"
View File
Whitespace-only changes.
+35 -35
View File
@@ -1,10 +1,8 @@
import subprocess
from fabric.utils import GdkPixbuf, Gtk, get_relative_path, logger, os, re
from utils.functions import escape_markup_text, find_binary
from utils.functions import escape_markup_text, find_binary, run_command
from utils.gtk_utils import setup_cursor_hover
from utils.icon_resolver import IconResolver
from utils.utils import setup_cursor_hover
def read_dmi(field):
@@ -20,13 +18,14 @@ def read_dmi(field):
def get_gpu_name():
try:
output = (
subprocess.check_output(
"lspci -nn | grep -i 'VGA compatible controller'", shell=True, text=True
)
.strip()
.split("\n")
)
result = run_command(["lspci", "-nn"])
if result.returncode != 0:
return "Unknown"
output = [
line
for line in result.stdout.strip().split("\n")
if "VGA compatible controller" in line.lower()
]
def clean(line):
matches = re.findall(r"\[(.*?)\]", line)
@@ -495,37 +494,38 @@ class About(Gtk.Window):
return label
# Info values
kernel_result = run_command(["uname", "-r"])
cpu_result = run_command(["lscpu"])
cpu_model = ""
if cpu_result.returncode == 0:
for line in cpu_result.stdout.split("\n"):
if "Model name:" in line:
cpu_model = line.split(":", 1)[1].strip()
break
mem_result = run_command(["free", "-h", "--giga"])
mem_value = ""
if mem_result.returncode == 0:
for line in mem_result.stdout.split("\n"):
if line.startswith("Mem:"):
mem_value = line.split()[1]
break
uptime_result = run_command(["uptime", "-p"])
labels = [
(
"Kernel",
subprocess.run(
"uname -r", shell=True, capture_output=True, text=True
).stdout.strip(),
),
(
"CPU",
subprocess.run(
"lscpu | grep 'Model name:' | cut -d ':' -f2-",
shell=True,
capture_output=True,
text=True,
).stdout.strip(),
),
(
"Memory",
subprocess.run(
"free -h --giga | grep Mem | tr -s ' ' | cut -d ' ' -f 2",
shell=True,
capture_output=True,
text=True,
).stdout.strip(),
kernel_result.stdout.strip()
if kernel_result.returncode == 0
else "Unknown",
),
("CPU", cpu_model),
("Memory", mem_value),
("GPU", get_gpu_name()),
(
"Uptime",
subprocess.run(
"uptime -p", shell=True, capture_output=True, text=True
).stdout.strip(),
uptime_result.stdout.strip()
if uptime_result.returncode == 0
else "Unknown",
),
]
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+3 -6
View File
@@ -9,7 +9,7 @@ from fabric.widgets.separator import Separator
from services.battery import Battery
from services.gamemode import GameModeService
from utils.functions import clear_children, format_duration
from utils.utils import svg_file
from utils.gtk_utils import svg_file
class EnergyModeButton(Box):
@@ -332,9 +332,6 @@ class BatteryControl(Box):
self.game_mode_button = GameModeButton(parent=self)
self.game_mode_container.add(self.game_mode_button)
def _format_time(self, seconds: int) -> str:
return format_duration(seconds)
def update_battery_info(self):
is_present = self.battery_service.available
if not is_present:
@@ -360,7 +357,7 @@ class BatteryControl(Box):
if state in ["CHARGING", "PENDING_CHARGE"]:
self.power_source_label.set_label("Power Source: Power Adapter")
seconds_to_full = self.battery_service.time_to_full
time_to_full = self._format_time(seconds_to_full)
time_to_full = format_duration(seconds_to_full)
if time_to_full != "N/A" and time_to_full != "0m":
self.charging_time_label.set_label(
f"{time_to_full} until fully charged"
@@ -373,7 +370,7 @@ class BatteryControl(Box):
elif state in ["DISCHARGING", "PENDING_DISCHARGE"]:
self.power_source_label.set_label("Power Source: Battery")
seconds_to_empty = self.battery_service.time_remaining
time_to_empty = self._format_time(seconds_to_empty)
time_to_empty = format_duration(seconds_to_empty)
if time_to_empty != "N/A" and not time_to_empty.startswith(
"4553h"
): # Filter out unrealistic times