Skip to content

Commit f482b09

Browse files
betamoslucasfernog
andauthored
fix: remove notification permission prompt (#4302)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent a6f45d5 commit f482b09

10 files changed

Lines changed: 29 additions & 170 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
The notification's `isPermissionGranted` function now returns `boolean` instead of `boolean | null`. The response is never `null` because we won't check the permission for now, always returning `true` instead.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
No longer ask for permission to send notifications and always allow it.

.changes/remove-settings-module.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
**Breaking change:** Removed the `settings` module.

core/tauri/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ zip = { version = "0.6", default-features = false, optional = true }
6868
ignore = "0.4"
6969
flate2 = "1.0"
7070
http = "0.2"
71-
bincode = "1.3"
7271
dirs-next = "2.0"
7372
percent-encoding = "2.1"
7473
base64 = { version = "0.13", optional = true }

core/tauri/src/api/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ pub enum Error {
5353
/// JSON error.
5454
#[error(transparent)]
5555
Json(#[from] serde_json::Error),
56-
/// Bincode error.
57-
#[error(transparent)]
58-
Bincode(#[from] Box<bincode::ErrorKind>),
5956
/// IO error.
6057
#[error(transparent)]
6158
Io(#[from] std::io::Error),

core/tauri/src/endpoints/notification.rs

Lines changed: 13 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use tauri_macros::{command_enum, module_command_handler, CommandModule};
1313
use crate::{api::notification::Notification, Env, Manager};
1414

1515
// `Granted` response from `request_permission`. Matches the Web API return value.
16-
#[cfg(notification_all)]
1716
const PERMISSION_GRANTED: &str = "granted";
1817
// `Denied` response from `request_permission`. Matches the Web API return value.
1918
const PERMISSION_DENIED: &str = "denied";
@@ -49,13 +48,6 @@ impl Cmd {
4948
context: InvokeContext<R>,
5049
options: NotificationOptions,
5150
) -> super::Result<()> {
52-
let allowed = match is_permission_granted(&context) {
53-
Some(p) => p,
54-
None => request_permission(&context),
55-
};
56-
if !allowed {
57-
return Err(crate::Error::NotificationNotAllowed.into_anyhow());
58-
}
5951
let mut notification =
6052
Notification::new(context.config.tauri.bundle.identifier.clone()).title(options.title);
6153
if let Some(body) = options.body {
@@ -68,80 +60,23 @@ impl Cmd {
6860
Ok(())
6961
}
7062

71-
#[cfg(notification_all)]
72-
fn request_notification_permission<R: Runtime>(
73-
context: InvokeContext<R>,
74-
) -> super::Result<&'static str> {
75-
if request_permission(&context) {
76-
Ok(PERMISSION_GRANTED)
77-
} else {
78-
Ok(PERMISSION_DENIED)
79-
}
80-
}
81-
82-
#[cfg(not(notification_all))]
8363
fn request_notification_permission<R: Runtime>(
8464
_context: InvokeContext<R>,
8565
) -> super::Result<&'static str> {
86-
Ok(PERMISSION_DENIED)
87-
}
88-
89-
#[cfg(notification_all)]
90-
fn is_notification_permission_granted<R: Runtime>(
91-
context: InvokeContext<R>,
92-
) -> super::Result<Option<bool>> {
93-
if let Some(allow_notification) = is_permission_granted(&context) {
94-
Ok(Some(allow_notification))
66+
Ok(if cfg!(notification_all) {
67+
PERMISSION_GRANTED
9568
} else {
96-
Ok(None)
97-
}
69+
PERMISSION_DENIED
70+
})
9871
}
9972

100-
#[cfg(not(notification_all))]
10173
fn is_notification_permission_granted<R: Runtime>(
10274
_context: InvokeContext<R>,
103-
) -> super::Result<Option<bool>> {
104-
Ok(Some(false))
75+
) -> super::Result<bool> {
76+
Ok(cfg!(notification_all))
10577
}
10678
}
10779

108-
#[cfg(notification_all)]
109-
fn request_permission<R: Runtime>(context: &InvokeContext<R>) -> bool {
110-
let mut settings = crate::settings::read_settings(
111-
&context.config,
112-
&context.package_info,
113-
context.window.state::<Env>().inner(),
114-
);
115-
if let Some(allow_notification) = settings.allow_notification {
116-
return allow_notification;
117-
}
118-
let answer = crate::api::dialog::blocking::ask(
119-
Some(&context.window),
120-
"Permissions",
121-
"This app wants to show notifications. Do you allow?",
122-
);
123-
124-
settings.allow_notification = Some(answer);
125-
let _ = crate::settings::write_settings(
126-
&context.config,
127-
&context.package_info,
128-
context.window.state::<Env>().inner(),
129-
settings,
130-
);
131-
132-
answer
133-
}
134-
135-
#[cfg(notification_all)]
136-
fn is_permission_granted<R: Runtime>(context: &InvokeContext<R>) -> Option<bool> {
137-
crate::settings::read_settings(
138-
&context.config,
139-
&context.package_info,
140-
context.window.state::<Env>().inner(),
141-
)
142-
.allow_notification
143-
}
144-
14580
#[cfg(test)]
14681
mod tests {
14782
use super::NotificationOptions;
@@ -163,16 +98,21 @@ mod tests {
16398
fn request_notification_permission() {
16499
assert_eq!(
165100
super::Cmd::request_notification_permission(crate::test::mock_invoke_context()).unwrap(),
166-
super::PERMISSION_DENIED
101+
if cfg!(notification_all) {
102+
super::PERMISSION_GRANTED
103+
} else {
104+
super::PERMISSION_DENIED
105+
}
167106
)
168107
}
169108

170109
#[cfg(not(notification_all))]
171110
#[test]
172111
fn is_notification_permission_granted() {
112+
let expected = cfg!(notification_all);
173113
assert_eq!(
174114
super::Cmd::is_notification_permission_granted(crate::test::mock_invoke_context()).unwrap(),
175-
Some(false)
115+
expected,
176116
);
177117
}
178118

core/tauri/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ pub mod window;
172172
use tauri_runtime as runtime;
173173
/// The allowlist scopes.
174174
pub mod scope;
175-
pub mod settings;
176175
mod state;
177176
#[cfg(updater)]
178177
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]

core/tauri/src/settings.rs

Lines changed: 0 additions & 81 deletions
This file was deleted.

examples/api/src-tauri/Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/api/src/notification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Permission = 'granted' | 'denied' | 'default'
4646
*
4747
* @returns
4848
*/
49-
async function isPermissionGranted(): Promise<boolean | null> {
49+
async function isPermissionGranted(): Promise<boolean> {
5050
if (window.Notification.permission !== 'default') {
5151
return Promise.resolve(window.Notification.permission === 'granted')
5252
}

0 commit comments

Comments
 (0)