#Notification API misses TimestampTrigger

1 messages · Page 1 of 1 (latest)

wanton marsh
#

So it is really good that the Notification API exists, but I am wanting to make scheduled notifications and with the services workers on the web I can do it using TimestampTrigger, but here with Tauri I cannot

slow bear
#

idk but i don't recommend really waiting for this. Even google stopped working on the Notification Triggers Web API because they weren't able to implement it nicely and reliable in a cross-platform way

wanton marsh
#

Is there any other way to do scheduled notifictations?

slow bear
#

hmm, maybe setup a timer/timeout yourself. that would of course require the app to still be open when the notification should be displayed

wanton marsh
slow bear
#

still requires that the user does not close the whole app. But yes, it's less likely that they will close it completely if you do this

#

you could also do it without a system tray icon btw

wanton marsh
#

Oke

wanton marsh
#

I got it working...

    if ("__TAURI__" in window) {
        class TimestampTrigger{
            constructor(timestamp) {this.timestamp = timestamp;}
        }
        window.TimestampTrigger = TimestampTrigger;
        Notification.showNotification = (title, option={}) => {
            if (typeof(title) == 'object') option = title;
            if (!("title" in option)) option.title = title;
            if ("showTrigger" in option) setTimeout(() => new Notification(option.title, option), option.showTrigger.timestamp - new Date().getTime());
            else new Notification(option.title, option);
        }
    }

For if anyone want to use

wanton marsh
#

Hey uhmm with the background running thingy: I wanted to have double click to open the window, but now I get thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src\main.rs:60:49
for:
let window = app.get_window("main").unwrap();

slow bear
#

that means that the main windows doesn't exist anymore (= it was closed)

wanton marsh
#

it is/was hidden

slow bear
#

can you show your code? Because if that'd be the case the panic would not make sense

wanton marsh
#

It is too big

slow bear
wanton marsh
#

yes

slow bear
#

(you can upload .rs files directly)

wanton marsh
#

I will have to remove the spaces and replace with tabs

#

o

#

Oh wait I see it. The ExitRequested thingy might be the problem here

#

because with the tray it just works fine

slow bear
#

yeah that's what i meant. ExitRequested only prevents the eventloop from exiting (the thing that keeps the tray alive). The window will still be closed. You need to handle the CloseRequested window event

wanton marsh
#

To just get a different type of close button function

#

Or there is a better way? Can you come up with some code?

slow bear
slow bear
wanton marsh
wanton marsh
slow bear
wanton marsh
#

I need to do it using the Rust code, cause the js is also for website edition

#
      tauri::RunEvent::CloseRequested { api, .. } => {
        api.prevent_close();
      }
wanton marsh
wanton marsh
#

if I click yes, the window is gone, but the tray not and then when I double click (or just select Show) then it again give thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'

slow bear
#

this was just an example to show you how to react to the CloseRequested event

wanton marsh
#

will add app_handle.exit(0); after close()

#

ALso with the notifications (to just get back to the topic) when will actions: option be added?

And how to handle even a single click on a notification without buttons?