Add do-not-disturb scripts
This commit is contained in:
parent
2b7ce9a5d4
commit
3bfe9a367e
3 changed files with 54 additions and 0 deletions
|
|
@ -7,6 +7,7 @@
|
|||
./cli
|
||||
./communication
|
||||
./direnv.nix
|
||||
./do-not-disturb
|
||||
./dynamic-colors.nix
|
||||
./firefox
|
||||
./fish.nix
|
||||
|
|
|
|||
26
users/jalr/modules/do-not-disturb/android-set-dnd.py
Executable file
26
users/jalr/modules/do-not-disturb/android-set-dnd.py
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
import os
|
||||
import sys
|
||||
from urllib import request
|
||||
|
||||
|
||||
def read_url():
|
||||
try:
|
||||
with open(os.getenv("NTFY_URL_FILE")) as f:
|
||||
return f.read()
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
|
||||
def set_android_dnd(active: bool):
|
||||
url = read_url()
|
||||
if url is not None:
|
||||
request.urlopen(
|
||||
request.Request(
|
||||
read_url(), method="POST", data=("on" if active else "off").encode()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
_, state = sys.argv
|
||||
set_android_dnd(state == "on")
|
||||
27
users/jalr/modules/do-not-disturb/default.nix
Normal file
27
users/jalr/modules/do-not-disturb/default.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{ nixosConfig, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
androidSetDnd = pkgs.writeScript "android-set-dnd" ''
|
||||
#!${pkgs.python3}/bin/python3
|
||||
${builtins.readFile ./android-set-dnd.py}
|
||||
'';
|
||||
do-not-disturb = pkgs.writeShellScriptBin "dnd" ''
|
||||
if [[ "$1" != off && "$1" != on ]]; then
|
||||
echo "USAGE: $0 [on|off]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export NTFY_URL_FILE=/run/secrets/ntfy_shiftphone
|
||||
${androidSetDnd} $1
|
||||
|
||||
if [[ $1 == on ]]; then
|
||||
makoctl mode -a dnd > /dev/null
|
||||
else
|
||||
makoctl mode -r dnd > /dev/null
|
||||
fi
|
||||
'';
|
||||
|
||||
in
|
||||
lib.mkIf nixosConfig.jalr.gui.enable {
|
||||
home.packages = [ do-not-disturb ];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue