diff --git a/.changes/fix-toggle-devtools.md b/.changes/fix-toggle-devtools.md new file mode 100644 index 000000000000..95b89b71bf6f --- /dev/null +++ b/.changes/fix-toggle-devtools.md @@ -0,0 +1,5 @@ +--- +"tauri": patch:bug +--- + +Fix devtools not toggling on `ctrl+shift+i` or `cmd+alt+i` shortcuts. diff --git a/core/tauri/scripts/toggle-devtools.js b/core/tauri/scripts/toggle-devtools.js index f7e521ce5cd9..854bff4c80a2 100644 --- a/core/tauri/scripts/toggle-devtools.js +++ b/core/tauri/scripts/toggle-devtools.js @@ -3,10 +3,12 @@ // SPDX-License-Identifier: MIT (function () { + const osName = __TEMPLATE_os_name__ + function toggleDevtoolsHotkey() { - const isHotkey = navigator.appVersion.includes("Mac") - ? (event) => event.metaKey && event.altKey && event.key === "I" - : (event) => event.ctrlKey && event.shiftKey && event.key === "I"; + const isHotkey = osName === 'macos' ? + (event) => event.metaKey && event.altKey && event.code === "KeyI" : + (event) => event.ctrlKey && event.shiftKey && event.code === "KeyI"; document.addEventListener("keydown", (event) => { if (isHotkey(event)) { diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 4e66be645c53..5c9a3490d592 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -802,6 +802,12 @@ impl WindowManager { protocol_scheme: &'a str, } + #[derive(Template)] + #[default_template("../scripts/toggle-devtools.js")] + struct ToggleDevtoolsScript<'a> { + os_name: &'a str, + } + let bundle_script = if with_global_tauri { include_str!("../scripts/bundle.global.js") } else { @@ -815,9 +821,13 @@ impl WindowManager { }; #[cfg(any(debug_assertions, feature = "devtools"))] - let hotkeys = include_str!("../scripts/toggle-devtools.js"); + let hotkeys = ToggleDevtoolsScript { + os_name: std::env::consts::OS, + } + .render_default(&Default::default())? + .into_string(); #[cfg(not(any(debug_assertions, feature = "devtools")))] - let hotkeys = ""; + let hotkeys = String::default(); InitJavascript { pattern_script, @@ -846,7 +856,7 @@ impl WindowManager { event_initialization_script: &self.event_initialization_script(), plugin_initialization_script, freeze_prototype, - hotkeys, + hotkeys: &hotkeys, } .render_default(&Default::default()) .map(|s| s.into_string()) diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 1d214dab15a1..8a4a03fc4b70 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -1954,9 +1954,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "loom" @@ -3529,7 +3529,7 @@ checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5" [[package]] name = "tauri" -version = "1.4.1" +version = "1.5.0" dependencies = [ "anyhow", "base64 0.21.2", @@ -3591,10 +3591,11 @@ dependencies = [ [[package]] name = "tauri-build" -version = "1.4.0" +version = "1.5.0" dependencies = [ "anyhow", "cargo_toml", + "dirs-next", "heck 0.4.1", "json-patch", "quote", @@ -3604,11 +3605,12 @@ dependencies = [ "tauri-codegen", "tauri-utils", "tauri-winres", + "walkdir", ] [[package]] name = "tauri-codegen" -version = "1.4.0" +version = "1.4.1" dependencies = [ "base64 0.21.2", "brotli", @@ -3632,7 +3634,7 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "1.4.0" +version = "1.4.1" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -3644,7 +3646,7 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "0.14.0" +version = "0.14.1" dependencies = [ "gtk", "http", @@ -3663,7 +3665,7 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "0.14.0" +version = "0.14.1" dependencies = [ "cocoa", "gtk", @@ -3681,7 +3683,7 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "1.4.0" +version = "1.5.0" dependencies = [ "aes-gcm", "brotli", @@ -3694,6 +3696,7 @@ dependencies = [ "infer 0.12.0", "json-patch", "kuchikiki", + "log", "memchr", "phf 0.10.1", "proc-macro2",