Skip to content

Commit

Permalink
refactor(power): rename power utility module and streamline widget hi…
Browse files Browse the repository at this point in the history
…ding logic
  • Loading branch information
amnweb committed Nov 20, 2024
1 parent 136e8d2 commit 84b4ad7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
32 changes: 15 additions & 17 deletions src/core/utils/win32/power.py → src/core/utils/widgets/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
import ctypes

class PowerOperations:
def __init__(self, main_window, overlay):
def __init__(self, main_window=None, overlay=None):
self.main_window = main_window
self.overlay = overlay

def clear_widget(self):
if self.main_window:
self.main_window.hide()
if self.overlay:
self.overlay

def signout(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
QCoreApplication.exit(0)
subprocess.Popen("shutdown /l", stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)

def lock(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
subprocess.Popen("rundll32.exe user32.dll,LockWorkStation", stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)

def sleep(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
access = (win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY)
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), access)
if htoken:
Expand All @@ -33,32 +36,27 @@ def sleep(self):
win32api.CloseHandle(htoken)

def restart(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
QCoreApplication.exit(0)
subprocess.Popen("shutdown /r /t 0", stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)

def shutdown(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
QCoreApplication.exit(0)
subprocess.Popen("shutdown /s /hybrid /t 0", stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)

def force_shutdown(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
QCoreApplication.exit(0)
subprocess.Popen("shutdown /s /f /t 0", stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)

def force_restart(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
QCoreApplication.exit(0)
subprocess.Popen("shutdown /r /f /t 0", stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)

def hibernate(self):
self.main_window.hide()
self.overlay.hide()
self.clear_widget()
subprocess.Popen("shutdown /h", stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)

def cancel(self):
Expand Down
2 changes: 1 addition & 1 deletion src/core/widgets/yasb/power_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from core.widgets.base import BaseWidget
from core.validation.widgets.yasb.power_menu import VALIDATION_SCHEMA
from core.config import get_stylesheet
from core.utils.win32.power import PowerOperations
from core.utils.widgets.power import PowerOperations
import datetime
import psutil
from core.utils.utilities import is_windows_10
Expand Down

0 comments on commit 84b4ad7

Please sign in to comment.