Repository: ultrabug/py3status

Issue:
do_not_disturb: mako doesn't work anymore (changed commands for dnd)
I use mako as my notification daemon and want to use the do_not_disturb module, which does not work.

py3status calls `makoctl set invisble={}`, however current version of mako uses
`makoctl set-mode do-not-disturb` to set DND mode and
`makoctl set-mode default` to unset DND mode.

**Your py3status version**
py3status version 3.39 (python 3.10.0) on i3 (it's sway, actually.)

**To Reproduce**
1. Add module do_not_disturb
2. Set `server` to `mako`
3. Switch to DND mode
4. Send a notification

**Expected behavior**
Notification shouldn't be shown


Discussion:
I'm no mako user and it seems that the mako documentation is only available through man ?

What I see from the py3status module code is:

```
class Mako(Notification):
    """
    Mako Notification.
    """

    def toggle(self, state):
        self.parent.py3.command_run("makoctl set invisible={}".format(int(state)))
```

while in dunst we have `dunstctl` and we can be more clever like this:

```
    def get_state(self):
        if self.has_dunstctl:
            state = self.parent.py3.command_output("dunstctl is-paused")
            return state.strip() == "true"
        else:
            return self.parent.state

    def toggle(self, state):
        if self.has_dunstctl:
            self.parent.py3.command_run(
                "dunstctl set-paused {}".format(str(state).lower())
            )
        elif state:
            # pause
            self.parent.py3.command_run("pkill -SIGUSR1 dunst")
        else:
            if self.parent.pause:
                # resume
                self.parent.py3.command_run("pkill -SIGUSR2 dunst")
            else:
                # delete all pending notifications and resume
                self.parent.py3.command_run("pkill -SIGTERM dunst")

```

I don't have mako, but it seems like makoctl exists, do you get something to check the state etc?
Hi ultrabug,

indeed a `makoctl` exists, but there is no way to query for the current mode, only `set-mode` is avaible to switch modes: https://man.voidlinux.org/makoctl

What makes things a bit more complicated is that you can have an arbitrary number of different modes which you can configure via the config file and then set via `makoctl`. However, the documentation suggests to use `do-not-disturb` for DND: https://man.voidlinux.org/mako.5#MODES - so I would suggest using this too?

I don't know how problematic it is that it's impossible to query for the current mode, though. I run the `do_not_disturb` module with `cache_timeout = -1` since py3status would be the only means to switch modes in mako (but thats just me, ofc).

Resolving patch:
diff --git a/py3status/modules/do_not_disturb.py b/py3status/modules/do_not_disturb.py
--- a/py3status/modules/do_not_disturb.py
+++ b/py3status/modules/do_not_disturb.py
@@ -35,6 +35,14 @@
     This means that by default (pause = False), all notifications sent while
     DND is active will NOT be queued and displayed when DND is deactivated.
 
+Mako Miscellaneous:
+    Mako requires that you manually create a 'do-not-disturb' mode as shown
+    in https://man.voidlinux.org/mako.5#MODES.
+    This module expects this mode to be configured by the user as suggested by
+    the mako documentation:
+    [mode=do-not-disturb]
+    invisible=1
+
 
 Examples:
 ```
@@ -121,8 +129,14 @@ class Mako(Notification):
     Mako Notification.
     """
 
+    def setup(self, parent):
+        self.toggle(parent.state)
+
     def toggle(self, state):
-        self.parent.py3.command_run("makoctl set invisible={}".format(int(state)))
+        if state is True:
+            self.parent.py3.command_run("makoctl set-mode do-not-disturb")
+        else:
+            self.parent.py3.command_run("makoctl set-mode default")
 
 
 class Xfce4_notifyd(Notification):


Test patch: