@@ -172,7 +172,7 @@ mod imp {
172
172
use tauri:: Manager ;
173
173
use tauri:: { AppHandle , Runtime } ;
174
174
#[ cfg( windows) ]
175
- use windows_registry:: CURRENT_USER ;
175
+ use windows_registry:: { CLASSES_ROOT , CURRENT_USER , LOCAL_MACHINE } ;
176
176
177
177
/// Access to the deep-link APIs.
178
178
pub struct DeepLink < R : Runtime > {
@@ -258,7 +258,8 @@ mod imp {
258
258
pub fn register < S : AsRef < str > > ( & self , _protocol : S ) -> crate :: Result < ( ) > {
259
259
#[ cfg( windows) ]
260
260
{
261
- let key_base = format ! ( "Software\\ Classes\\ {}" , _protocol. as_ref( ) ) ;
261
+ let protocol = _protocol. as_ref ( ) ;
262
+ let key_base = format ! ( "Software\\ Classes\\ {protocol}" ) ;
262
263
263
264
let exe = dunce:: simplified ( & tauri:: utils:: platform:: current_exe ( ) ?)
264
265
. display ( )
@@ -348,13 +349,21 @@ mod imp {
348
349
///
349
350
/// ## Platform-specific:
350
351
///
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)
351
354
/// - **Linux**: Can only unregister the scheme if it was initially registered with [`register`](`Self::register`). May not work on older distros.
352
355
/// - **macOS / Android / iOS**: Unsupported, will return [`Error::UnsupportedPlatform`](`crate::Error::UnsupportedPlatform`).
353
356
pub fn unregister < S : AsRef < str > > ( & self , _protocol : S ) -> crate :: Result < ( ) > {
354
357
#[ cfg( windows) ]
355
358
{
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
+ }
358
367
Ok ( ( ) )
359
368
}
360
369
@@ -398,10 +407,11 @@ mod imp {
398
407
pub fn is_registered < S : AsRef < str > > ( & self , _protocol : S ) -> crate :: Result < bool > {
399
408
#[ cfg( windows) ]
400
409
{
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
+ } ;
405
415
406
416
let registered_cmd = cmd_reg. get_string ( "" ) ?;
407
417
0 commit comments