feat(update): huge changes

This commit is contained in:
sankalp committed 2025-04-25 06:33:51 +05:45
1 parent 53c077106f
commit 6b9b419aa9
98 files changed
+9636 -5575

No files matched your search

+27 -15
View File
@@ -5,9 +5,9 @@ from fabric.widgets.centerbox import CenterBox
from fabric.widgets.label import Label
from fabric.widgets.button import Button
from fabric.widgets.stack import Stack
from loguru import logger
from gi.repository import Gtk
import utils.icons as icons
import config.data as data
class UpdatesWidget(Button):
@@ -17,8 +17,15 @@ class UpdatesWidget(Button):
self,
**kwargs,
):
# Determine if we should use vertical layout for components
is_vertical_layout = data.VERTICAL
# Initialize the button with specific name and style
super().__init__(name="button-bar", **kwargs)
super().__init__(
name="update",
orientation="h" if not is_vertical_layout else "v",
**kwargs,
)
self.script_file = get_relative_path("../../../config/scripts/systemupdates.sh")
@@ -31,45 +38,49 @@ class UpdatesWidget(Button):
self.update_icon = Label(name="update-icon", markup=icons.update)
self.updated_icon = Label(name="updated-icon", markup=icons.updated)
# Create boxes with proper orientation
self.update_box = CenterBox(
orientation="v" if is_vertical_layout else "h",
center_children=[self.update_icon, self.update_level_label],
)
self.updated_box = CenterBox(
orientation="v" if is_vertical_layout else "h",
center_children=[self.updated_icon],
)
# Stack to switch between states
self.stack = Stack()
self.stack.add_named(self.update_box, "update_box")
self.stack.add_named(self.updated_box, "updated_box")
self.stack.set_visible_child_name("update_box")
self.children = Box(
orientation="v" if is_vertical_layout else "h",
children=self.stack,
)
# Ensure the stack resizes to the current visible child
# Configure stack transitions
self.stack.set_homogeneous(False)
self.stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
# Connect the button press event
# Connect click handler
self.connect("button-press-event", self.on_button_press)
# Set up a repeater to call the update method at specified intervals
# Check for updates every minute
invoke_repeater(60000, self.update, initial_call=True)
def update_values(self, value: str):
logger.info(f"[Updates] Received update JSON: {value}")
def update_values(self, value: str) -> bool:
"""Update the widget state based on update check results"""
try:
value = json.loads(value)
except json.JSONDecodeError:
logger.error("[Updates] Failed to parse update JSON")
return False
update_count = str(value["total"])
self.update_level_label.set_label(update_count)
# Show appropriate state based on update count
if update_count == "0":
self.stack.set_visible_child_name("updated_box")
self.update_level_label.set_visible(False)
@@ -80,8 +91,10 @@ class UpdatesWidget(Button):
self.set_tooltip_text(value.get("tooltip", ""))
return True
def on_button_press(self, _, event):
if event.button == 1:
def on_button_press(self, _, event) -> bool:
"""Handle button press events"""
if event.button == 1: # Left click
# Run update command
exec_shell_command_async(
f"{self.script_file} -arch -up",
lambda _: None,
@@ -89,12 +102,11 @@ class UpdatesWidget(Button):
self.update()
return True
else:
# Other clicks just refresh
self.update()
def update(self):
logger.info("[Updates] Checking for updates...")
# Execute the update script asynchronously and update values
def update(self) -> bool:
"""Check for system updates"""
exec_shell_command_async(
f"{self.script_file} -arch",
lambda output: self.update_values(output),