Skip to content

Commit e2a0704

Browse files
authored
refactor(core): remove salt APIs (#2426)
1 parent fbf8caf commit e2a0704

File tree

5 files changed

+15
-86
lines changed

5 files changed

+15
-86
lines changed

.changes/remove-salt.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Remove salt-related APIs (no longer needed after the `__TAURI_INVOKE_KEY__` implementation).

core/tauri/src/endpoints.rs

-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ mod event;
2222
mod file_system;
2323
mod global_shortcut;
2424
mod http;
25-
mod internal;
2625
mod notification;
2726
mod operating_system;
2827
mod path;
@@ -54,7 +53,6 @@ enum Module {
5453
Window(Box<window::Cmd>),
5554
Shell(shell::Cmd),
5655
Event(event::Cmd),
57-
Internal(internal::Cmd),
5856
Dialog(dialog::Cmd),
5957
Cli(cli::Cmd),
6058
Notification(notification::Cmd),
@@ -113,12 +111,6 @@ impl Module {
113111
.and_then(|r| r.json)
114112
.map_err(InvokeError::from)
115113
}),
116-
Self::Internal(cmd) => resolver.respond_async(async move {
117-
cmd
118-
.run(window)
119-
.and_then(|r| r.json)
120-
.map_err(InvokeError::from)
121-
}),
122114
// on macOS, the dialog must run on another thread: https://github.com/rust-windowing/winit/issues/1779
123115
// we do the same on Windows just to stay consistent with `tao` (and it also improves UX because of the event loop)
124116
#[cfg(not(target_os = "linux"))]

core/tauri/src/endpoints/internal.rs

-22
This file was deleted.

core/tauri/src/manager.rs

+9-50
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use std::{
4444
};
4545
use tauri_macros::default_runtime;
4646
use url::Url;
47-
use uuid::Uuid;
4847

4948
const WINDOW_RESIZED_EVENT: &str = "tauri://resize";
5049
const WINDOW_MOVED_EVENT: &str = "tauri://move";
@@ -72,8 +71,6 @@ pub struct InnerWindowManager<R: Runtime> {
7271
assets: Arc<dyn Assets>,
7372
default_window_icon: Option<Vec<u8>>,
7473

75-
/// A list of salts that are valid for the current application.
76-
salts: Mutex<HashSet<Uuid>>,
7774
package_info: PackageInfo,
7875
/// The webview protocols protocols available to all windows.
7976
uri_scheme_protocols: HashMap<String, Arc<CustomProtocol>>,
@@ -96,7 +93,6 @@ impl<R: Runtime> fmt::Debug for InnerWindowManager<R> {
9693
.field("state", &self.state)
9794
.field("config", &self.config)
9895
.field("default_window_icon", &self.default_window_icon)
99-
.field("salts", &self.salts)
10096
.field("package_info", &self.package_info);
10197
{
10298
w = w
@@ -158,7 +154,6 @@ impl<R: Runtime> WindowManager<R> {
158154
config: Arc::new(context.config),
159155
assets: context.assets,
160156
default_window_icon: context.default_window_icon,
161-
salts: Mutex::default(),
162157
package_info: context.package_info,
163158
uri_scheme_protocols,
164159
menu_ids: {
@@ -444,37 +439,24 @@ impl<R: Runtime> WindowManager<R> {
444439
} else {
445440
""
446441
},
447-
event_initialization_script = self.event_initialization_script(key),
442+
event_initialization_script = self.event_initialization_script(),
448443
plugin_initialization_script = plugin_initialization_script
449444
)
450445
}
451446

452-
fn event_initialization_script(&self, key: u32) -> String {
447+
fn event_initialization_script(&self) -> String {
453448
return format!(
454449
"
455-
window['{function}'] = function (eventData, salt) {{
450+
window['{function}'] = function (eventData) {{
456451
const listeners = (window['{listeners}'] && window['{listeners}'][eventData.event]) || []
457452
458-
if (listeners.length > 0) {{
459-
window.__TAURI_INVOKE__('tauri', {{
460-
__tauriModule: 'Internal',
461-
message: {{
462-
cmd: 'validateSalt',
463-
salt: salt
464-
}}
465-
}}, {key}).then(function (flag) {{
466-
if (flag) {{
467-
for (let i = listeners.length - 1; i >= 0; i--) {{
468-
const listener = listeners[i]
469-
eventData.id = listener.id
470-
listener.handler(eventData)
471-
}}
472-
}}
473-
}})
453+
for (let i = listeners.length - 1; i >= 0; i--) {{
454+
const listener = listeners[i]
455+
eventData.id = listener.id
456+
listener.handler(eventData)
474457
}}
475458
}}
476459
",
477-
key = key,
478460
function = self.inner.listeners.function_name(),
479461
listeners = self.inner.listeners.listeners_object_name()
480462
);
@@ -708,37 +690,14 @@ impl<R: Runtime> WindowManager<R> {
708690
) -> EventHandler {
709691
self.inner.listeners.once(event, window, handler)
710692
}
693+
711694
pub fn event_listeners_object_name(&self) -> String {
712695
self.inner.listeners.listeners_object_name()
713696
}
697+
714698
pub fn event_emit_function_name(&self) -> String {
715699
self.inner.listeners.function_name()
716700
}
717-
pub fn generate_salt(&self) -> Uuid {
718-
let salt = Uuid::new_v4();
719-
self
720-
.inner
721-
.salts
722-
.lock()
723-
.expect("poisoned salt mutex")
724-
.insert(salt);
725-
salt
726-
}
727-
pub fn verify_salt(&self, salt: String) -> bool {
728-
// flat out ignore any invalid uuids
729-
let uuid: Uuid = match salt.parse() {
730-
Ok(uuid) => uuid,
731-
Err(_) => return false,
732-
};
733-
734-
// HashSet::remove lets us know if the entry was found
735-
self
736-
.inner
737-
.salts
738-
.lock()
739-
.expect("poisoned salt mutex")
740-
.remove(&uuid)
741-
}
742701

743702
pub fn get_window(&self, label: &str) -> Option<Window<R>> {
744703
self.windows_lock().get(label).cloned()

core/tauri/src/window.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,10 @@ impl<R: Runtime> Window<R> {
239239
/// Emits an event to the current window.
240240
pub fn emit<S: Serialize>(&self, event: &str, payload: S) -> crate::Result<()> {
241241
self.eval(&format!(
242-
"window['{}']({{event: {}, payload: {}}}, '{}')",
242+
"window['{}']({{event: {}, payload: {}}})",
243243
self.manager.event_emit_function_name(),
244244
serde_json::to_string(event)?,
245245
serde_json::to_value(payload)?,
246-
self.manager.generate_salt(),
247246
))?;
248247

249248
Ok(())
@@ -689,8 +688,4 @@ impl<R: Runtime> Window<R> {
689688
pub fn start_dragging(&self) -> crate::Result<()> {
690689
self.window.dispatcher.start_dragging().map_err(Into::into)
691690
}
692-
693-
pub(crate) fn verify_salt(&self, salt: String) -> bool {
694-
self.manager.verify_salt(salt)
695-
}
696691
}

0 commit comments

Comments
 (0)