#Notifications API + Building for Production

19 messages · Page 1 of 1 (latest)

normal stump
#

Refer to this Github issue I opened about the Docs. https://github.com/tauri-apps/tauri/issues/7997

Ill copy and paste it here though for ease of access.

Link to docs:
https://tauri.app/v1/api/js/notification/

I'm encountering some ambiguity while preparing for production deployment. While I managed to get the sound to play during development, the documentation seems vague about how to package the sound for the production app.

I attempted to bundle it with the binary's resources, but in the production environment, the notification remains silent.

To utilize a sound in production, I'm trying to access one from /System/Library/Sounds. Given potential access issues on our CI Server, I copied it to my project directory. I've included this sound in the tauri.conf.json resources section, and confirmed it's correctly bundled in the packaged app. How should I reference it? For context, the sound file is named Blow.aiff and its path in the compiled app is Contents/Resources/_up_/src/assets/sounds/Blow.aiff.

hallow hedge
#

I am so very confused by this and want to blame chatgpt or its kin for being misleading.

#

You are bundling an app, and want to include an .aiff file for use on bundled macOS apps.

#

In development it works, in production it doesn’t

#

Can you provide a way for us to reproduce what you are doing?

normal stump
# hallow hedge I am so very confused by this and want to blame chatgpt or its kin for being mis...

LOL sorry. I ran it through chat GPT because my normal writing comes off as harsh and running it through GPT makes it sound nicer. 🙂

Yes in development it works and in production it does not work. I don't think it knows where the file is on production and the documentation is a little unclear where it is looking for this sound file. Since in development it seems to look in the /System/Library/Sounds directory.

The documentation says we need to copy the file but where do we need to copy the file?

#
import { sendNotification} from '@tauri-apps/api/notification';

import { platform } from '@tauri-apps/api/os';


const os_platform = await platform();

if (os_platform === 'darwin') {
  sendNotification({ title: "TEST", body: "TEST BODY", sound: 'Blow' });
} else {
  sendNotification({ "TEST", body: "TEST BODY", sound: 'Default' });
}

The above code works in development and plays the sound.

It works in production but does not play the sound.

So I'm using the JS API to call sendNotification which works in Development, but when running in production it can't seem to find the sound file ''Blow" which is a native system file. Which I have included in the resources.

tauri.config.js

"bundle": {
    "resources": ["../src/assets/sounds/Blow.aiff"]
 }
hallow hedge
#

I expect the problem is the path here.
Contents/Resources/_up_/src/assets/sounds/Blow.aiff

You claim its there, but it SHOULD AFAIK be here:

Contents/Resources/Blow.aiff

#

so something is going wrong with the depositing of the resource in the Resources folder

#

can you try manually moving it within the app bundle to the place where I showed you?

normal stump
#

I moved it to

Contents/Resources/Blow.aiff

Still no sound playing.

normal stump
#

Standby

normal stump
#

Okay so it was working now.

A thing worth noting though if you have the window focused that is firing the notification it will not play the notification. I think this OS related.

Thanks for your help.

hallow hedge
#

sure - but we still need to figure out WHY the path got all weird.

#

what does pnpm tauri info (or yarn / npm) tell us?

novel gate
#

The path is correct. The resources will have the same path as in the config with ../ replaced with _up_ and / & C:/ with _root_.

#

I think you're mixing it up with the sidecars where all binaries indeed end up in the same dir no matter the source path.

normal stump
#

Yeah the path is correct with the _up_ It was working this entire time, but the notification on the lastest mac OS does not play if the owner of the notification event is in focus. In this case it was my app sending it and did not play when it was in focus.