summaryrefslogtreecommitdiffstats
path: root/src/windows
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-11-19 11:13:05 +0100
committerJose M. Guisado <jguisado@soleta.eu>2021-11-19 11:13:05 +0100
commit2e9e5bcb3d1522a7cd7053db7f7080a9e959e46b (patch)
tree15891817fb1f706d3738090a263e97fa1f2ca154 /src/windows
parent2dbcd18c06dd78491026bcb6fbd770175de4948f (diff)
#1065 windows: add poweroff and reboot
Uses ExitWindowsEx from user32.dll. Library is loaded using ctypes. See https://stackoverflow.com/a/50824776
Diffstat (limited to 'src/windows')
-rw-r--r--src/windows/ogOperations.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/windows/ogOperations.py b/src/windows/ogOperations.py
index 0af7250..baafbd9 100644
--- a/src/windows/ogOperations.py
+++ b/src/windows/ogOperations.py
@@ -7,6 +7,7 @@
# (at your option) any later version.
import os
+import ctypes
import subprocess
from subprocess import CalledProcessError
import multiprocessing as mp
@@ -18,6 +19,10 @@ from pystray import Icon, Menu, MenuItem
from src.ogRest import ThreadState
+EWX_POWEROFF=0x00000008
+EWX_REBOOT=0x00000002
+
+
def _create_default_image():
"""
Creates a default image for the tray icon. Use in case
@@ -69,10 +74,14 @@ class OgWindowsOperations:
raise NotImplementedError
def poweroff(self):
+ user32 = ctypes.WinDLL('user32')
systray_p.terminate()
+ user32.ExitWindowsEx(EWX_POWEROFF, 0x0)
def reboot(self):
+ user32 = ctypes.WinDLL('user32')
systray_p.terminate()
+ user32.ExitWindowsEx(EWX_REBOOT, 0x0)
def shellrun(self, request, ogRest):
cmd = request.getrun()