diff --git a/bin/hooks/README.md b/bin/hooks/README.md index 6a52b844..594660f6 100644 --- a/bin/hooks/README.md +++ b/bin/hooks/README.md @@ -6,8 +6,8 @@ these programs either take zero arguments, or a filepath (the affected file), or # after upload -* [notify.py](notify.py) shows a desktop notification -* [discord-announce.py](discord-announce.py) announces new uploads on discord using webhooks +* [notify.py](notify.py) shows a desktop notification ([example](https://user-images.githubusercontent.com/241032/215335767-9c91ed24-d36e-4b6b-9766-fb95d12d163f.png)) +* [discord-announce.py](discord-announce.py) announces new uploads on discord using webhooks ([example](https://user-images.githubusercontent.com/241032/215304439-1c1cb3c8-ec6f-4c17-9f27-81f969b1811a.png)) * [reject-mimetype.py](reject-mimetype.py) rejects uploads unless the mimetype is acceptable diff --git a/bin/hooks/notify.py b/bin/hooks/notify.py old mode 100644 new mode 100755 index 8541e479..06e38c52 --- a/bin/hooks/notify.py +++ b/bin/hooks/notify.py @@ -1,20 +1,24 @@ #!/usr/bin/env python3 +import os import sys +import subprocess as sp from plyer import notification _ = r""" -show os notification on upload; works on windows, linux, macos +show os notification on upload; works on windows, linux, macos, android depdencies: - python3 -m pip install --user -U plyer + windows: python3 -m pip install --user -U plyer + linux: python3 -m pip install --user -U plyer + macos: python3 -m pip install --user -U plyer pyobjus + android: just termux and termux-api -example usage as global config: +example usages; either as global config (all volumes) or as volflag: --xau f,bin/hooks/notify.py - -example usage as a volflag (per-volume config): -v srv/inc:inc:c,xau=f,bin/hooks/notify.py + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ parameters explained, xau = execute after upload @@ -23,7 +27,21 @@ parameters explained, def main(): - notification.notify(title="new file uploaded", message=sys.argv[1], timeout=10) + dp, fn = os.path.split(sys.argv[1]) + msg = "šŸ·ļø {}\nšŸ“ {}".format(fn, dp) + title = "File received" + + if "com.termux" in sys.executable: + sp.run(["termux-notification", "-t", title, "-c", msg]) + return + + icon = "emblem-documents-symbolic" if sys.platform == "linux" else "" + notification.notify( + title=title, + message=msg, + app_icon=icon, + timeout=10, + ) if __name__ == "__main__":