Skip to content

Commit

Permalink
refactor(yasb/home): expand user paths and handle file missing case w…
Browse files Browse the repository at this point in the history
…ith logger

This commit refactors the `create_menu_action` method in `HomeWidget` class to expand user paths before calling `os.startfile`.
  • Loading branch information
amnweb committed Feb 5, 2025
1 parent d725933 commit f595216
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core/widgets/yasb/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from core.utils.widgets.power import PowerOperations
from core.utils.utilities import PopupWidget
from core.utils.widgets.animation_manager import AnimationManager
import logging

class HomeWidget(BaseWidget):
validation_schema = VALIDATION_SCHEMA
Expand Down Expand Up @@ -95,9 +96,10 @@ def process_content(content):


def create_menu_action(self, path):
expanded_path = os.path.expanduser(path)
return lambda: os.startfile(expanded_path)

path = os.path.expanduser(path)
return lambda: os.startfile(path) if os.path.exists(path) else logging.error(f"The system cannot find the file specified: '{path}'")


def _create_menu(self):
self._menu = PopupWidget(self, self._blur, self._round_corners, self._round_corners_type, self._border_color)
self._menu.setProperty('class', 'home-menu')
Expand All @@ -119,6 +121,7 @@ def _create_menu(self):

self._add_menu_item(main_layout, self._menu_labels['system'],
lambda: os.startfile("ms-settings:"))

self._add_menu_item(main_layout, self._menu_labels['task_manager'],
lambda: subprocess.Popen("taskmgr", shell=True, creationflags=subprocess.CREATE_NO_WINDOW))

Expand Down

0 comments on commit f595216

Please # to comment.