Blocker can now send notify-send messages as root.

This commit is contained in:
2021-10-17 11:30:15 -04:00
parent f6f0715cb3
commit 4b76ec2d61

View File

@@ -8,7 +8,7 @@ import sys
import time import time
BLOCKED_BROWSER_WORDS = ["mogelpower", "nitter", "spon"] BLOCKED_BROWSER_WORDS = ["mogelpower", "DER SPIEGEL", "nitter"]
def is_window_blocked(window_name, blocked): def is_window_blocked(window_name, blocked):
@@ -35,7 +35,6 @@ def find_window_name(window_name):
if p.returncode != 0: if p.returncode != 0:
return "" return ""
l = p.stdout.decode().split("\n") l = p.stdout.decode().split("\n")
print(l)
def init_kill_sequence(blocked): def init_kill_sequence(blocked):
@@ -55,8 +54,13 @@ def init_kill_sequence(blocked):
def notify(message): def notify(message):
CMD = ["runuser", "-u", "felixm", "notify-send", message] env = {
p = subprocess.run(CMD) **os.environ,
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus"
}
user = env["SUDO_USER"]
CMD = ["runuser", "-m", "-u", user, "notify-send", message]
p = subprocess.run(CMD, env=env)
def main(): def main():
@@ -76,5 +80,5 @@ if __name__ == "__main__":
main() main()
else: else:
cmd = ["sudo"] + sys.argv cmd = ["sudo"] + sys.argv
subprocess.Popen(cmd, start_new_session=True) subprocess.Popen(cmd)