From dac1db39831ecbcf23c630351d5753af01ccd500 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Thu, 16 Jul 2020 19:17:41 -0300 Subject: [PATCH] fix(tauri) notification body optional, requestPermission() regression, closes #793 (#844) * fix(tauri) notification body optional, title required * fix(tauri) regression on requestPermission() --- .changes/notificaiton-fix.md | 6 ++++++ .changes/notification-permission-regression.md | 6 ++++++ cli/tauri.js/templates/tauri.js | 2 +- tauri/src/endpoints/cmd.rs | 4 ++-- tauri/src/endpoints/notification.rs | 13 ++++++------- 5 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 .changes/notificaiton-fix.md create mode 100644 .changes/notification-permission-regression.md diff --git a/.changes/notificaiton-fix.md b/.changes/notificaiton-fix.md new file mode 100644 index 00000000000..329c7f176fb --- /dev/null +++ b/.changes/notificaiton-fix.md @@ -0,0 +1,6 @@ +--- +"tauri.js": patch +"tauri": patch +--- + +The notification's `body` is now optional, closes #793. diff --git a/.changes/notification-permission-regression.md b/.changes/notification-permission-regression.md new file mode 100644 index 00000000000..5e8cec2ad67 --- /dev/null +++ b/.changes/notification-permission-regression.md @@ -0,0 +1,6 @@ +--- +"tauri": patch +--- + +Fixes a regression on the storage of requestPermission response. +ß \ No newline at end of file diff --git a/cli/tauri.js/templates/tauri.js b/cli/tauri.js/templates/tauri.js index 5e26779d5d5..53b5a023dba 100644 --- a/cli/tauri.js/templates/tauri.js +++ b/cli/tauri.js/templates/tauri.js @@ -220,7 +220,7 @@ switch (navigator.platform) { return window.__TAURI__.promisified({ cmd: 'notification', options: typeof options === 'string' ? { - body: options + title: options } : options }) } diff --git a/tauri/src/endpoints/cmd.rs b/tauri/src/endpoints/cmd.rs index 17d6f3149bf..5a874d20129 100644 --- a/tauri/src/endpoints/cmd.rs +++ b/tauri/src/endpoints/cmd.rs @@ -53,9 +53,9 @@ pub struct SaveDialogOptions { #[derive(Deserialize)] pub struct NotificationOptions { /// The notification title. - pub title: Option, + pub title: String, /// The notification body. - pub body: String, + pub body: Option, /// The notification icon. pub icon: Option, } diff --git a/tauri/src/endpoints/notification.rs b/tauri/src/endpoints/notification.rs index 41bb0dfd3bf..2b53250cd25 100644 --- a/tauri/src/endpoints/notification.rs +++ b/tauri/src/endpoints/notification.rs @@ -11,10 +11,9 @@ pub fn send( 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); @@ -56,8 +55,8 @@ pub fn request_permission( 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 }); } @@ -76,7 +75,7 @@ pub fn request_permission( crate::settings::write_settings(settings)?; Ok(denied) } - _ => Ok(r#""default""#.to_string()), + _ => Ok("default".to_string()), } }, callback,