Skip to content

Commit db07043

Browse files
committed
augment macos screensaver detection with screen lock detection
Fixes #168
1 parent 70640fb commit db07043

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

ntfy/screensaver.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,24 @@ def macos_detect():
9797

9898

9999
def macos_is_locked():
100-
# Strictly-speaking, this detects whether or not the screensaver is running. The screensaver
100+
# Strictly-speaking, this detects whether or not the screensaver is running. The screensaver
101101
# may or may not be locked.
102102
cmd = '''tell application "System Events"
103103
get running of screen saver preferences
104104
end tell'''
105-
return check_output([ 'osascript', '-e', cmd ]) == b'true\n'
105+
screensaver_is_running = check_output(
106+
['osascript', '-e', cmd]) == b'true\n'
107+
if screensaver_is_running:
108+
return True
109+
110+
# The screen may be locked even if the scrensaver is not running. This
111+
# *should* cover that scenario.
112+
# https: // stackoverflow.com/questions/11505255/osx-check-if-the-screen-is-locked
113+
import Quartz
114+
d = Quartz.CGSessionCopyCurrentDictionary()
115+
screen_is_locked = d.get("CGSSessionScreenIsLocked", 0) == 1
116+
117+
return screen_is_locked
106118

107119

108120
def is_locked():

0 commit comments

Comments
 (0)