fix(tauri): add F12/Ctrl+Shift+I shortcut and shift+right-click for DevTools
- Add open_devtools IPC command - Frontend keydown listener for F12 / Ctrl+Shift+I - Allow contextmenu when Shift is held (for Inspect element) - Auto open_devtools after window.show() with 1s delay
This commit is contained in:
@@ -30,6 +30,11 @@ fn restart_app(app: tauri::AppHandle) {
|
||||
app.restart();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn open_devtools(window: tauri::WebviewWindow) {
|
||||
let _ = window.open_devtools();
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 公共类型导出
|
||||
// ============================================================
|
||||
@@ -72,6 +77,9 @@ pub fn run() {
|
||||
});
|
||||
}
|
||||
|
||||
// 全局快捷键备选:F12 / Ctrl+Shift+I 手动打开 DevTools
|
||||
// (通过前端 keydown 事件 + invoke 调用,无需额外插件)
|
||||
|
||||
// macOS 自定义菜单栏(中文本地化)
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
@@ -136,6 +144,7 @@ pub fn run() {
|
||||
storage::config::save_app_config,
|
||||
storage::config::get_environment_presets,
|
||||
restart_app,
|
||||
open_devtools,
|
||||
// 项目存储
|
||||
commands::project::save_project_meta_raw,
|
||||
commands::project::load_project_meta,
|
||||
|
||||
+14
-2
@@ -5,16 +5,28 @@ import './styles/variables.css';
|
||||
import './styles/global.css';
|
||||
|
||||
// 全局禁用浏览器默认右键菜单,提升桌面应用质感
|
||||
// 输入框/文本区自动放行(保留复制/粘贴/全选)
|
||||
// 输入框/文本区自动放行;按住 Shift 时放行(方便 DevTools 检查)
|
||||
document.addEventListener('contextmenu', (e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
const tag = target.tagName.toLowerCase();
|
||||
const isInput = tag === 'input' || tag === 'textarea' || target.isContentEditable;
|
||||
if (!isInput) {
|
||||
if (!isInput && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
// 全局快捷键:F12 / Ctrl+Shift+I 打开 DevTools(release 构建备用)
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'F12' || (e.ctrlKey && e.shiftKey && (e.key === 'I' || e.key === 'i'))) {
|
||||
e.preventDefault();
|
||||
import('@tauri-apps/api/core')
|
||||
.then(({ invoke }) => invoke('open_devtools'))
|
||||
.catch(() => {
|
||||
// 非 Tauri 环境忽略
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
||||
|
||||
root.render(
|
||||
|
||||
Reference in New Issue
Block a user