Skip to content

Commit

Permalink
fix(tauri) notification body optional, requestPermission() regression,
Browse files Browse the repository at this point in the history
…closes #793 (#844)

* fix(tauri) notification body optional, title required

* fix(tauri) regression on requestPermission()
  • Loading branch information
lucasfernog authored Jul 16, 2020
1 parent 0591f1f commit dac1db3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changes/notificaiton-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri.js": patch
"tauri": patch
---

The notification's `body` is now optional, closes #793.
6 changes: 6 additions & 0 deletions .changes/notification-permission-regression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": patch
---

Fixes a regression on the storage of requestPermission response.
ß
2 changes: 1 addition & 1 deletion cli/tauri.js/templates/tauri.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ switch (navigator.platform) {
return window.__TAURI__.promisified({
cmd: 'notification',
options: typeof options === 'string' ? {
body: options
title: options
} : options
})
}
Expand Down
4 changes: 2 additions & 2 deletions tauri/src/endpoints/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub struct SaveDialogOptions {
#[derive(Deserialize)]
pub struct NotificationOptions {
/// The notification title.
pub title: Option<String>,
pub title: String,
/// The notification body.
pub body: String,
pub body: Option<String>,
/// The notification icon.
pub icon: Option<String>,
}
Expand Down
13 changes: 6 additions & 7 deletions tauri/src/endpoints/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ pub fn send<T: 'static>(
crate::execute_promise(
webview,
move || {
let mut notification = tauri_api::notification::Notification::new();
notification = notification.body(options.body);
if let Some(title) = options.title {
notification = notification.title(title);
let mut notification = tauri_api::notification::Notification::new().title(options.title);
if let Some(body) = options.body {
notification = notification.body(body);
}
if let Some(icon) = options.icon {
notification = notification.icon(icon);
Expand Down Expand Up @@ -56,8 +55,8 @@ pub fn request_permission<T: 'static>(
webview,
move || {
let mut settings = crate::settings::read_settings()?;
let granted = r#""granted""#.to_string();
let denied = r#""denied""#.to_string();
let granted = "granted".to_string();
let denied = "denied".to_string();
if let Some(allow_notification) = settings.allow_notification {
return Ok(if allow_notification { granted } else { denied });
}
Expand All @@ -76,7 +75,7 @@ pub fn request_permission<T: 'static>(
crate::settings::write_settings(settings)?;
Ok(denied)
}
_ => Ok(r#""default""#.to_string()),
_ => Ok("default".to_string()),
}
},
callback,
Expand Down

0 comments on commit dac1db3

Please sign in to comment.