desktop/devtools: habilitar F12/Ctrl+Shift+I e menu de contexto para abrir DevTools

- src-tauri: adiciona comando open_devtools que chama window.open_devtools()
- frontend: listeners para F12/Ctrl+Shift+I e botão direito com Ctrl/Shift

Facilita depuração de UI no executável Tauri.
This commit is contained in:
Esdras Renan 2025-10-14 15:26:59 -03:00
parent 087170e321
commit 0b39bcb56c
2 changed files with 31 additions and 1 deletions

View file

@ -32,6 +32,12 @@ fn stop_machine_agent(state: tauri::State<AgentRuntime>) -> Result<(), String> {
Ok(())
}
#[tauri::command]
fn open_devtools(window: tauri::WebviewWindow) -> Result<(), String> {
window.open_devtools();
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
@ -44,7 +50,8 @@ pub fn run() {
collect_machine_profile,
collect_machine_inventory,
start_machine_agent,
stop_machine_agent
stop_machine_agent,
open_devtools
])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View file

@ -769,3 +769,26 @@ function StatusBadge({ status }: { status: string | null }) {
const root = document.getElementById("root") || (() => { const el = document.createElement("div"); el.id = "root"; document.body.appendChild(el); return el })()
createRoot(root).render(<App />)
// DevTools shortcut (F12 / Ctrl+Shift+I) and context menu with modifier
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
const key = (e.key || '').toLowerCase()
if (key === 'f12' || (e.ctrlKey && e.shiftKey && key === 'i')) {
invoke('open_devtools').catch(() => {})
e.preventDefault()
}
}
function onContextMenu(e: MouseEvent) {
// Evita abrir sempre: use Ctrl ou Shift + botão direito para abrir DevTools
if (e.ctrlKey || e.shiftKey) {
invoke('open_devtools').catch(() => {})
e.preventDefault()
}
}
window.addEventListener('keydown', onKeyDown)
window.addEventListener('contextmenu', onContextMenu)
return () => {
window.removeEventListener('keydown', onKeyDown)
window.removeEventListener('contextmenu', onContextMenu)
}
}, [])