mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-05 14:59:29 -05:00
scheme: add notify opt
For sending a notification on error
This commit is contained in:
@@ -94,6 +94,7 @@ complete -c caelestia -n "$seen scheme && $seen get" -s 'f' -l 'flavour' -d 'Get
|
||||
complete -c caelestia -n "$seen scheme && $seen get" -s 'm' -l 'mode' -d 'Get scheme mode'
|
||||
complete -c caelestia -n "$seen scheme && $seen get" -s 'v' -l 'variant' -d 'Get scheme variant'
|
||||
|
||||
complete -c caelestia -n "$seen scheme && $seen set" -l 'notify' -d 'Send a notification on error'
|
||||
complete -c caelestia -n "$seen scheme && $seen set" -s 'r' -l 'random' -d 'Switch to a random scheme'
|
||||
complete -c caelestia -n "$seen scheme && $seen set" -s 'n' -l 'name' -d 'Set scheme name' -a "$(caelestia scheme list -n)" -r
|
||||
complete -c caelestia -n "$seen scheme && $seen set" -s 'f' -l 'flavour' -d 'Set scheme flavour' -a "$(caelestia scheme list -f)" -r
|
||||
|
||||
@@ -68,6 +68,7 @@ def parse_args() -> (argparse.ArgumentParser, argparse.Namespace):
|
||||
|
||||
set_parser = scheme_command_parser.add_parser("set", help="set the current scheme")
|
||||
set_parser.set_defaults(cls=scheme.Set)
|
||||
set_parser.add_argument("--notify", action="store_true", help="send a notification on error")
|
||||
set_parser.add_argument("-r", "--random", action="store_true", help="switch to a random scheme")
|
||||
set_parser.add_argument("-n", "--name", choices=get_scheme_names(), help="the name of the scheme to switch to")
|
||||
set_parser.add_argument("-f", "--flavour", help="the flavour to switch to")
|
||||
|
||||
@@ -3,6 +3,7 @@ import time
|
||||
from argparse import Namespace
|
||||
from datetime import datetime
|
||||
|
||||
from caelestia.utils.notify import notify
|
||||
from caelestia.utils.paths import recording_notif_path, recording_path, recordings_dir
|
||||
|
||||
|
||||
@@ -48,20 +49,10 @@ class Command:
|
||||
# Send notif if proc hasn't ended after a small delay
|
||||
time.sleep(0.1)
|
||||
if proc.poll() is None:
|
||||
notif = subprocess.check_output(
|
||||
["notify-send", "-p", "-a", "caelestia-cli", "Recording started", "Recording..."], text=True
|
||||
).strip()
|
||||
notif = notify("-p", "Recording started", "Recording...")
|
||||
recording_notif_path.write_text(notif)
|
||||
else:
|
||||
subprocess.run(
|
||||
[
|
||||
"notify-send",
|
||||
"-a",
|
||||
"caelestia-cli",
|
||||
"Recording failed",
|
||||
f"Recording failed to start: {proc.communicate()[1]}",
|
||||
]
|
||||
)
|
||||
notify("Recording failed", f"Recording failed to start: {proc.communicate()[1]}")
|
||||
|
||||
def stop(self) -> None:
|
||||
subprocess.run(["pkill", "wl-screenrec"])
|
||||
@@ -87,19 +78,13 @@ class Command:
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
action = subprocess.check_output(
|
||||
[
|
||||
"notify-send",
|
||||
"-a",
|
||||
"caelestia-cli",
|
||||
"--action=watch=Watch",
|
||||
"--action=open=Open",
|
||||
"--action=delete=Delete",
|
||||
"Recording stopped",
|
||||
f"Recording saved in {new_path}",
|
||||
],
|
||||
text=True,
|
||||
).strip()
|
||||
action = notify(
|
||||
"--action=watch=Watch",
|
||||
"--action=open=Open",
|
||||
"--action=delete=Delete",
|
||||
"Recording stopped",
|
||||
f"Recording saved in {new_path}",
|
||||
)
|
||||
|
||||
if action == "watch":
|
||||
subprocess.Popen(["app2unit", "-O", new_path], start_new_session=True)
|
||||
|
||||
@@ -13,6 +13,9 @@ class Set:
|
||||
def run(self) -> None:
|
||||
scheme = get_scheme()
|
||||
|
||||
if self.args.notify:
|
||||
scheme.notify = True
|
||||
|
||||
if self.args.random:
|
||||
scheme.set_random()
|
||||
apply_colours(scheme.colours, scheme.mode)
|
||||
|
||||
@@ -4,6 +4,7 @@ from argparse import Namespace
|
||||
from datetime import datetime
|
||||
|
||||
from caelestia.utils import hypr
|
||||
from caelestia.utils.notify import notify
|
||||
from caelestia.utils.paths import screenshots_cache_dir, screenshots_dir
|
||||
|
||||
|
||||
@@ -59,22 +60,16 @@ class Command:
|
||||
screenshots_cache_dir.mkdir(exist_ok=True, parents=True)
|
||||
dest.write_bytes(sc_data)
|
||||
|
||||
action = subprocess.check_output(
|
||||
[
|
||||
"notify-send",
|
||||
"-i",
|
||||
"image-x-generic-symbolic",
|
||||
"-h",
|
||||
f"STRING:image-path:{dest}",
|
||||
"-a",
|
||||
"caelestia-cli",
|
||||
"--action=open=Open",
|
||||
"--action=save=Save",
|
||||
"Screenshot taken",
|
||||
f"Screenshot stored in {dest} and copied to clipboard",
|
||||
],
|
||||
text=True,
|
||||
).strip()
|
||||
action = notify(
|
||||
"-i",
|
||||
"image-x-generic-symbolic",
|
||||
"-h",
|
||||
f"STRING:image-path:{dest}",
|
||||
"--action=open=Open",
|
||||
"--action=save=Save",
|
||||
"Screenshot taken",
|
||||
f"Screenshot stored in {dest} and copied to clipboard",
|
||||
)
|
||||
|
||||
if action == "open":
|
||||
subprocess.Popen(["swappy", "-f", dest], start_new_session=True)
|
||||
@@ -82,4 +77,4 @@ class Command:
|
||||
new_dest = (screenshots_dir / dest.name).with_suffix(".png")
|
||||
new_dest.parent.mkdir(exist_ok=True, parents=True)
|
||||
dest.rename(new_dest)
|
||||
subprocess.run(["notify-send", "Screenshot saved", f"Saved to {new_dest}"])
|
||||
notify("Screenshot saved", f"Saved to {new_dest}")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
def notify(*args: list[str]) -> str:
|
||||
return subprocess.check_output(["notify-send", "-a", "caelestia-cli", *args], text=True).strip()
|
||||
@@ -3,6 +3,7 @@ import random
|
||||
from pathlib import Path
|
||||
|
||||
from caelestia.utils.material import get_colours_for_image
|
||||
from caelestia.utils.notify import notify
|
||||
from caelestia.utils.paths import atomic_dump, scheme_data_dir, scheme_path
|
||||
|
||||
|
||||
@@ -12,6 +13,7 @@ class Scheme:
|
||||
_mode: str
|
||||
_variant: str
|
||||
_colours: dict[str, str]
|
||||
notify: bool
|
||||
|
||||
def __init__(self, json: dict[str, any] | None) -> None:
|
||||
if json is None:
|
||||
@@ -26,6 +28,7 @@ class Scheme:
|
||||
self._mode = json["mode"]
|
||||
self._variant = json["variant"]
|
||||
self._colours = json["colours"]
|
||||
self.notify = False
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -37,6 +40,11 @@ class Scheme:
|
||||
return
|
||||
|
||||
if name not in get_scheme_names():
|
||||
if self.notify:
|
||||
notify(
|
||||
"Unable to set scheme",
|
||||
f'"{name}" is not a valid scheme.\nValid schemes are: {get_scheme_names()}',
|
||||
)
|
||||
raise ValueError(f"Invalid scheme name: {name}")
|
||||
|
||||
self._name = name
|
||||
@@ -55,6 +63,12 @@ class Scheme:
|
||||
return
|
||||
|
||||
if flavour not in get_scheme_flavours():
|
||||
if self.notify:
|
||||
notify(
|
||||
"Unable to set scheme flavour",
|
||||
f'"{flavour}" is not a valid flavour of scheme "{self.name}".\n'
|
||||
f"Valid flavours are: {get_scheme_flavours()}",
|
||||
)
|
||||
raise ValueError(f'Invalid scheme flavour: "{flavour}". Valid flavours: {get_scheme_flavours()}')
|
||||
|
||||
self._flavour = flavour
|
||||
@@ -71,6 +85,12 @@ class Scheme:
|
||||
return
|
||||
|
||||
if mode not in get_scheme_modes():
|
||||
if self.notify:
|
||||
notify(
|
||||
"Unable to set scheme mode",
|
||||
f'"{mode}" is not a valid mode of scheme "{self.name} {self.flavour}".\n'
|
||||
f"Valid modes are: {get_scheme_modes()}",
|
||||
)
|
||||
raise ValueError(f'Invalid scheme mode: "{mode}". Valid modes: {get_scheme_modes()}')
|
||||
|
||||
self._mode = mode
|
||||
|
||||
Reference in New Issue
Block a user