Skip to content

Commit 38deef4

Browse files
fix(deep-link): local machine registry handling (#2483)
* fix(deep-link): local machine registry handling * typo * Wrong version bump * return false if registry open fails --------- Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
1 parent c245f12 commit 38deef4

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'deep-link': 'patch:bug'
3+
'deep-link-js': 'patch:bug'
4+
---
5+
6+
Fix `is_registered` not being able to pickup deep link registered in `HKEY_LOCAL_MACHINE` on Windows
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'deep-link': 'patch:bug'
3+
'deep-link-js': 'patch:bug'
4+
---
5+
6+
Fix `unregister` not being able to remove deep link registered in `HKEY_LOCAL_MACHINE` on Windows

plugins/deep-link/src/lib.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ mod imp {
172172
use tauri::Manager;
173173
use tauri::{AppHandle, Runtime};
174174
#[cfg(windows)]
175-
use windows_registry::CURRENT_USER;
175+
use windows_registry::{CLASSES_ROOT, CURRENT_USER, LOCAL_MACHINE};
176176

177177
/// Access to the deep-link APIs.
178178
pub struct DeepLink<R: Runtime> {
@@ -258,7 +258,8 @@ mod imp {
258258
pub fn register<S: AsRef<str>>(&self, _protocol: S) -> crate::Result<()> {
259259
#[cfg(windows)]
260260
{
261-
let key_base = format!("Software\\Classes\\{}", _protocol.as_ref());
261+
let protocol = _protocol.as_ref();
262+
let key_base = format!("Software\\Classes\\{protocol}");
262263

263264
let exe = dunce::simplified(&tauri::utils::platform::current_exe()?)
264265
.display()
@@ -348,13 +349,21 @@ mod imp {
348349
///
349350
/// ## Platform-specific:
350351
///
352+
/// - **Windows**: Requires admin rights if the protocol is registered on local machine
353+
/// (this can happen when registered from the NSIS installer when the install mode is set to both or per machine)
351354
/// - **Linux**: Can only unregister the scheme if it was initially registered with [`register`](`Self::register`). May not work on older distros.
352355
/// - **macOS / Android / iOS**: Unsupported, will return [`Error::UnsupportedPlatform`](`crate::Error::UnsupportedPlatform`).
353356
pub fn unregister<S: AsRef<str>>(&self, _protocol: S) -> crate::Result<()> {
354357
#[cfg(windows)]
355358
{
356-
CURRENT_USER.remove_tree(format!("Software\\Classes\\{}", _protocol.as_ref()))?;
357-
359+
let protocol = _protocol.as_ref();
360+
let path = format!("Software\\Classes\\{protocol}");
361+
if LOCAL_MACHINE.open(&path).is_ok() {
362+
LOCAL_MACHINE.remove_tree(&path)?;
363+
}
364+
if CURRENT_USER.open(&path).is_ok() {
365+
CURRENT_USER.remove_tree(&path)?;
366+
}
358367
Ok(())
359368
}
360369

@@ -398,10 +407,11 @@ mod imp {
398407
pub fn is_registered<S: AsRef<str>>(&self, _protocol: S) -> crate::Result<bool> {
399408
#[cfg(windows)]
400409
{
401-
let cmd_reg = CURRENT_USER.open(format!(
402-
"Software\\Classes\\{}\\shell\\open\\command",
403-
_protocol.as_ref()
404-
))?;
410+
let protocol = _protocol.as_ref();
411+
let Ok(cmd_reg) = CLASSES_ROOT.open(format!("{protocol}\\shell\\open\\command"))
412+
else {
413+
return Ok(false);
414+
};
405415

406416
let registered_cmd = cmd_reg.get_string("")?;
407417

0 commit comments

Comments
 (0)