Skip to content

Commit

Permalink
refactor(core): remove notification API (#6745)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Apr 19, 2023
1 parent f78a378 commit 86488a6
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 1,241 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-fmt-core.yml
Expand Up @@ -50,7 +50,7 @@ jobs:
clippy:
- { args: '', key: 'empty' }
- {
args: '--features compression,wry,linux-protocol-headers,isolation,custom-protocol,api-all,updater,system-tray,windows7-compat,http-multipart',
args: '--features compression,wry,linux-protocol-headers,isolation,custom-protocol,api-all,updater,system-tray,http-multipart',
key: 'all'
}
- { args: '--features custom-protocol', key: 'custom-protocol' }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-core.yml
Expand Up @@ -76,7 +76,7 @@ jobs:
key: api-all
}
- {
args: --features compression,wry,linux-protocol-headers,isolation,custom-protocol,api-all,updater,system-tray,windows7-compat,http-multipart,
args: --features compression,wry,linux-protocol-headers,isolation,custom-protocol,api-all,updater,system-tray,http-multipart,
key: all
}

Expand Down
9 changes: 1 addition & 8 deletions core/tauri/Cargo.toml
Expand Up @@ -19,7 +19,6 @@ features = [
"wry",
"custom-protocol",
"api-all",
"windows7-compat",
"updater",
"fs-extract-api",
"system-tray",
Expand Down Expand Up @@ -81,9 +80,6 @@ png = { version = "0.17", optional = true }
ico = { version = "0.2.0", optional = true }
encoding_rs = "0.8.31"

[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
notify-rust = { version = "4.5", optional = true }

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
gtk = { version = "0.16", features = [ "v3_24" ] }
glib = "0.16"
Expand All @@ -96,7 +92,6 @@ objc = "0.2"

[target."cfg(windows)".dependencies]
webview2-com = "0.22"
win7-notifications = { version = "0.3.1", optional = true }

[target."cfg(windows)".dependencies.windows]
version = "0.44"
Expand Down Expand Up @@ -154,15 +149,13 @@ native-tls = [ "reqwest/native-tls" ]
native-tls-vendored = [ "reqwest/native-tls-vendored" ]
rustls-tls = [ "reqwest/rustls-tls" ]
process-command-api = [ "shared_child", "os_pipe" ]
notification = [ "notify-rust" ]
system-tray = [ "tauri-runtime/system-tray", "tauri-runtime-wry/system-tray" ]
devtools = [ "tauri-runtime/devtools", "tauri-runtime-wry/devtools" ]
dox = [ "tauri-runtime-wry/dox" ]
macos-private-api = [
"tauri-runtime/macos-private-api",
"tauri-runtime-wry/macos-private-api"
]
windows7-compat = [ "win7-notifications" ]
window-data-url = [ "data-url" ]
api-all = [
"clipboard-all",
Expand Down Expand Up @@ -211,7 +204,7 @@ fs-write-file = [ ]
global-shortcut-all = [ ]
http-all = [ "http-request" ]
http-request = [ ]
notification-all = [ "notification", "dialog-ask" ]
notification-all = [ ]
os-all = [ "os_info" ]
path-all = [ ]
process-all = [ "process-relaunch", "process-exit" ]
Expand Down
8 changes: 4 additions & 4 deletions core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

86 changes: 0 additions & 86 deletions core/tauri/scripts/core.js
Expand Up @@ -154,90 +154,4 @@
})
}
})

let permissionSettable = false
let permissionValue = 'default'

function isPermissionGranted() {
if (window.Notification.permission !== 'default') {
return Promise.resolve(window.Notification.permission === 'granted')
}
return window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Notification',
message: {
cmd: 'isNotificationPermissionGranted'
}
})
}

function setNotificationPermission(value) {
permissionSettable = true
window.Notification.permission = value
permissionSettable = false
}

function requestPermission() {
return window
.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Notification',
message: {
cmd: 'requestNotificationPermission'
}
})
.then(function (permission) {
setNotificationPermission(permission)
return permission
})
}

function sendNotification(options) {
if (typeof options === 'object') {
Object.freeze(options)
}

return window.__TAURI_INVOKE__('tauri', {
__tauriModule: 'Notification',
message: {
cmd: 'notification',
options:
typeof options === 'string'
? {
title: options
}
: options
}
})
}

window.Notification = function (title, options) {
var opts = options || {}
sendNotification(
Object.assign(opts, {
title: title
})
)
}

window.Notification.requestPermission = requestPermission

Object.defineProperty(window.Notification, 'permission', {
enumerable: true,
get: function () {
return permissionValue
},
set: function (v) {
if (!permissionSettable) {
throw new Error('Readonly property')
}
permissionValue = v
}
})

isPermissionGranted().then(function (response) {
if (response === null) {
setNotificationPermission('default')
} else {
setNotificationPermission(response ? 'granted' : 'denied')
}
})
})()
4 changes: 0 additions & 4 deletions core/tauri/src/api/error.rs
Expand Up @@ -56,10 +56,6 @@ pub enum Error {
#[cfg(feature = "fs-extract-api")]
#[error("Failed to extract: {0}")]
Extract(String),
/// Notification error.
#[cfg(notification_all)]
#[error(transparent)]
Notification(#[from] notify_rust::error::Error),
/// Url error.
#[error(transparent)]
Url(#[from] url::ParseError),
Expand Down
4 changes: 0 additions & 4 deletions core/tauri/src/api/mod.rs
Expand Up @@ -13,10 +13,6 @@ pub mod process;
pub mod shell;
pub mod version;

#[cfg(all(desktop, feature = "notification"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "notification"))))]
pub mod notification;

mod error;

/// The error type of Tauri API module.
Expand Down
207 changes: 0 additions & 207 deletions core/tauri/src/api/notification.rs

This file was deleted.

0 comments on commit 86488a6

Please sign in to comment.