Skip to content

Commit 1adf7e3

Browse files
authored
docs(notification): Add capability instructions and usage example (#1569)
1 parent 21bf0a4 commit 1adf7e3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

plugins/notification/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,40 @@ fn main() {
5757
}
5858
```
5959

60+
Then you need to add the permissions to your capabilities file:
61+
62+
`src-tauri/capabilities/main.json`
63+
64+
```json
65+
{
66+
...
67+
"permissions": [
68+
...
69+
"notification:default"
70+
],
71+
...
72+
}
73+
```
74+
75+
6076
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
6177

6278
```javascript
79+
import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification';
6380

81+
async function checkPermission() {
82+
if (!(await isPermissionGranted())) {
83+
return (await requestPermission()) === 'granted';
84+
}
85+
return true;
86+
}
87+
88+
export async function enqueueNotification(title, body) {
89+
if (!(await checkPermission())) {
90+
return;
91+
}
92+
sendNotification({ title, body });
93+
}
6494
```
6595

6696
## Contributing

0 commit comments

Comments
 (0)