poetaman / arttime

arttime is a CLI application that blends beauty of ASCII / text art with functionality of clock / timer / pattern-based time manager in terminal ⏰
Other
969 stars 15 forks source link

Feature: Add support for WSL desktop integration #53

Closed poetaman closed 1 year ago

poetaman commented 1 year ago

As visible from @wychwitch's testing in arttime discussions, it is possible to add desktop integration for arttime running in WSL.

poetaman commented 1 year ago

@wychwitch Please give \r\n a try. Check this article on genealogy of CRLF in modern Windows operating system. My guess is that should format new lines.

wychwitch commented 1 year ago

huh! That doesn't work, even though it should 🤔

This is what I sent through

wsl-notify-send.exe --category "ARTTIME" "Sat May 06, 2023 12:16:55AM PDT\r\ngoal: 1m\r\nart: buttefly\r\nID: 23342"

And I get this notification

image

Maybe it can't support line breaks? Which would be really strange if so...

poetaman commented 1 year ago

@wychwitch One last try... I think I know what is going on. Perhaps you are running that command from bash. Bash does not substitute \r/\n with actual codes for CR/LF by default, zsh does. Try these options:

  1. Launch zsh , and in it's prompt run your command as is (without any modifications).
  2. Don't launch zsh, instead run this modified command from bash:
CRLF=$'\r\n'; wsl-notify-send.exe --category "ARTTIME" "Sat May 06, 2023 12:16:55AM PDT${CRLF}goal: 1m${CRLF}art: buttefly${CRLF}ID: 23342"
wychwitch commented 1 year ago

Interesting, I was using it in zsh, but for whatever reason the \r\n still didn't work. However setting it as a variable works perfectly!

image

poetaman commented 1 year ago

@wychwitch Awesome! Will figure the zsh mystery... Like why it works for some commands and not for others. For instance echo on zsh will translate \r and \n by default (bash echo doesn't). But looks like that is not true for other commands (while variable substitution works for all commands)... Can we try this without \n? For some reason, on Ubuntu's Gnome translates \n to space, but works perfect with just \r. I would prefer to keep it simple if \r just works for all platforms.

CRLF=$'\r'; wsl-notify-send.exe --category "ARTTIME" "Sat May 06, 2023 12:16:55AM PDT${CRLF}goal: 1m${CRLF}art: buttefly${CRLF}ID: 23342"
wychwitch commented 1 year ago

@poetaman YEP \r works the same!! That's fantastic, it'll make adapting the script easier :)

As for the ZSH thing, it could be my zshrc maybe?

poetaman commented 1 year ago

@wychwitch

As for the ZSH thing, it could be my zshrc maybe?

Most likely it is just a few special print builtins like echo that take character sequences \ followed by n, etc and substitute them with correct codes for moving the cursor. And the shell just passes the string with these character sequences untouched to all builtins and commands. But shell always seems to expand any variable $varname or command $(commandname ...). Check the help page for zsh's builtin echo (which is different from bash's echo or some binary command /bin/echo) below.

Screenshot 2023-05-07 at 1 42 59 PM
stuartleeks commented 1 year ago

Hey - I see that you are using wsl-notify-send :-)

My motivation when creating it was to create something that can be aliased to notify-send in WSL so that any scripts that expect to call notify-send will "just work" in WSL and route notifications to the Windows desktop. (I have a blog post that I wrote about it, too).

If you're not so concerned about the argument compatibility with notify-send, you might also want to take a look at toast. I have a fork of the original project that made a few tweaks, but toast gives a bit more control over the notification than wsl-notify-send. (I have a blog post on toast, too!)

poetaman commented 1 year ago

@wychwitch Please do git pull, install and run arttime again. You can even run arttime without installing, just cd to the top of its clone and run $ ./bin/arttime The commit https://github.com/poetaman/arttime/commit/e18f2620d7e4c5ab31bcf404b33f445a5a8c4053 should enable support for WSL. Give a few different goals a try: 5s, 5s;loop4 and post a screenshot :)

@stuartleeks Yes, I don't have a machine that can run WSL or this feature would have been tested in past... It would be great if you could also give it a try. Also, do options like -u critical make any sense for Windows? For rest of the platforms arttime intends to emulate the behavior of -u critical (notification must not disappear from screen after a timeout). Thanks for your notification softwares :)

wychwitch commented 1 year ago

@poetaman oh im so sorry ive been swamped with the end of school

Ill totally do this tomorrow!! I cant wait to try it out ^^

wychwitch commented 1 year ago

@wychwitch Please do git pull, install and run arttime again. You can even run arttime without installing, just cd to the top of its clone and run $ ./bin/arttime The commit e18f262 should enable support for WSL. Give a few different goals a try: 5s, 5s;loop4 and post a screenshot :)

@stuartleeks Yes, I don't have a machine that can run WSL or this feature would have been tested in past... It would be great if you could also give it a try. Also, do options like -u critical make any sense for Windows? For rest of the platforms arttime intends to emulate the behavior of -u critical (notification must not disappear from screen after a timeout). Thanks for your notification softwares :)

YESS it works!! I tried this by doing cloning a new repo and running it with ./bin/arttime like you suggested!

image

It's the normal windows notification sound in case you tried to customize it, but it works great! Thank you so much!

Let me know if there's anything else you'd like for me to test ^^

poetaman commented 1 year ago

@wychwitch: Awesome! A couple of questions:

  1. On other platforms all arttime notifications are sticky, i.e. they don't time out. How is it here?
  2. Your screenshot shows notification for sprint 3/4 while arttime has already passed 4th sprint. Why is that?
  3. How was your experience installing wsl-notify-send? Did you have to change any setting on Windows to get it working?
  4. Unlike notify-send on Linux, seems like desktop notifications on Windows platform have a default sound. I did not have to do anything special for sounds. We will stick with default sound as playing sounds from Linux side is going to add extra dependencies. In future, maybe we can collaborate on playing sounds from Linux side.

More testing is always welcome. If you feel like, please play with arttime's features and post your testing experience on https://github.com/poetaman/arttime/discussions. The screencast below shows how notifications show up on macOS. On Linux, the way multiple notifications are handled depends on DE (Desktop Environment). Some Linux DEs show only 1 notification at a time on the screen, and the next is shown in the same place once you click on the currently show notification (oldest unclicked). On other DEs, each new notification is shown on an empty space on screen. That happens till all space is filled with notifications, and notifications start stacking. Just curious what happened to the other 3 notifications for this test you ran?

https://github.com/poetaman/arttime/assets/71736629/846a5709-155b-402c-85c2-1cffecf6e43c

wychwitch commented 1 year ago

OH I know what happened with the 3/4 and the 4/4 goals difference. This actually has to do with your question about notification behavior! On windows, a notification is shown onscreen for a few seconds before automatically timing out and disappearing (only like, 5 seconds or so). If multiple notifications show up back to back, rather than OSX the notifications wont "stack", instead it will take its time to cycle through them one by one. I'm not sure if this behavior can be overwritten?

But yes, in that screenshot I'm pretty sure the difference happened because the 3/4 notification hadn't gone away when I took the screenshot, which meant the 4/4 one was queued up behind it! I didn't even notice hahahw

As for installing wsl-notify, it was pretty easy! I wasn't able to figure out how to properly get it working as a function in nushell (my shell of choice) but considering how different nushell's scripting is it's not surprising lmao

I hope that clears things up!! I'll do more testing when I get to the computer

poetaman commented 1 year ago

@wychwitch Yes yes! That does clear things a lot. When you get to your computer, please try wsl-notify-send.exe with an additional option -u critical. On Linux's notify-send, it is supposed to make the notification stick and not timeout. Try a few such commands back to back, and see if all notifications still stack in order, and not time out. Also try --urgency critical if short option -u doesn't work. Also, I am not sure if a = sign is needed for long option names...

wsl-notify-send.exe' -u critical --category "ARTTIME" "Notification-1"
wsl-notify-send.exe' -u critical --category "ARTTIME" "Notification-2"
wsl-notify-send.exe' -u critical --category "ARTTIME" "Notification-3"
wsl-notify-send.exe' -u critical --category "ARTTIME" "Notification-4"
wsl-notify-send.exe' -u critical --category "ARTTIME" "Notification-5"
wychwitch commented 1 year ago

@poetaman Oh I just got to the computer, and I realized after checking help that the urgency flag is completely ignored in wsl-notify!

Usage:
  wsl-notify-send [flags]

Flags:
      --appId string          [non-standard] Specifies the app ID (default "wsl-notify-send")
  -c, --category string       Specifies the notification category (default "wsl-notify-send")
  -t, --expire-time int       [Ignored in wsl-notiy-send] (default -1)
  -?, --help                  Show a help message
  -h, --hint stringArray      Ignored in wsl-notify-send
  -i, --icon string           An icon filename to display (stock icons are not currently supported)
  -u, --urgency stringArray   Ignored in wsl-notify-send
      --version               Show version information

Sure enough, they don't stay onscreen! Here's the video recorded: ezgif-5-0f38448dda.webm

EDIT: Well that didn't embed lmao, hold on here's a gif version

ezgif-5-30897215c1

poetaman commented 1 year ago

@stuartleeks Is it possible to get the effect of -u critical on Windows? On Linux Desktop Environments, the effect of -u critical is to make the notification stick till the user has clicked on each to acknowledge having seen them. The same effect exists for macOS if user does a one time setting change for notifications triggered by applescripts (reference to technique: https://github.com/poetaman/arttime/issues/11).

@wychwitch Thanks! At least they are ordered, which is good enough for now. Did you hear the sound accompanying notification 5 times (synchronized with it)? That would be my guess...

wychwitch commented 1 year ago

@poetaman yep! The sound happens for each time the notification pops up! and no problem, I'm happy to help!

poetaman commented 1 year ago

This can be closed as desktop notifications work on Windows under WSL since release 2.1.0. For persistence/timeout of notifications, I have filed a feature request on wsl-notify-send here: https://github.com/stuartleeks/wsl-notify-send/issues/8.