Skip to content

Commit

Permalink
feat(notifications) use confirm() instead of dialog crate
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 12, 2020
1 parent ca893f6 commit 36d02fc
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 311 deletions.
31 changes: 24 additions & 7 deletions cli/tauri.js/templates/tauri.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,17 @@ window.tauri = {
Object.freeze(options);
}

return this.promisified({
cmd: 'notification',
options: typeof options === 'string' ? {
body: options
} : options
});
return window.tauri.isNotificationPermissionGranted()
.then(function (permission) {
if (permission) {
return window.tauri.promisified({
cmd: 'notification',
options: typeof options === 'string' ? {
body: options
} : options
});
}
})
<% } else { %>
<% if (ctx.dev) { %>
return __whitelistWarning('notification')
Expand All @@ -682,6 +687,9 @@ window.tauri = {

isNotificationPermissionGranted: function isNotificationPermissionGranted() {
<% if (tauri.whitelist.notification === true || tauri.whitelist.all === true) { %>
if (window.Notification.permission !== 'default' && window.Notification.permission !== 'loading') {
return Promise.resolve(window.Notification.permission === 'granted')
}
return window.tauri.promisified({
cmd: 'isNotificationPermissionGranted'
})
Expand All @@ -697,6 +705,14 @@ window.tauri = {
<% if (tauri.whitelist.notification === true || tauri.whitelist.all === true) { %>
return window.tauri.promisified({
cmd: 'requestNotificationPermission'
}).then(function (state) {
if (state === 'default') {
return window.tauri.isNotificationPermissionGranted()
.then(function (permission) {
return permission === 'granted'
})
}
return state
})
<% } else { %>
<% if (ctx.dev) { %>
Expand Down Expand Up @@ -729,8 +745,9 @@ window.tauri = {
.then(function (response) {
if (response === null) {
window.Notification.permission = 'default'
} else {
window.Notification.permission = response ? 'granted' : 'denied'
}
window.Notification.permission = response ? 'granted' : 'denied'
})
<% } %>

Expand Down
15 changes: 0 additions & 15 deletions tauri-api/src/dialog.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub use nfd::Response;
use nfd::{open_dialog, DialogType};
use dialog::DialogBox;
pub use dialog::Choice as DialogAnswer;

fn open_dialog_internal(
dialog_type: DialogType,
Expand All @@ -15,19 +13,6 @@ fn open_dialog_internal(
}
}

/// Displays a dialog with a message and an optional title with a "yes" and a "no" button.
pub fn ask(
message: String,
title: Option<String>,
) -> crate::Result<DialogAnswer> {
let mut question = dialog::Question::new(message);
if let Some(title) = title {
question.title(title);
}
question.show()
.map_err(|e| anyhow::anyhow!(e))
}

/// Open single select file dialog
pub fn select(
filter_list: Option<String>,
Expand Down
Loading

0 comments on commit 36d02fc

Please sign in to comment.