From 4bcb2c4e8999df814e13e56e9b6342077fc557d8 Mon Sep 17 00:00:00 2001 From: leukipp Date: Tue, 30 Sep 2025 21:26:39 +0200 Subject: [PATCH] feat: auto on-screen keyboard #85 --- html/navigation.html | 18 +++++++++++------- js/webview.js | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/html/navigation.html b/html/navigation.html index 4ccbed5..d728afb 100644 --- a/html/navigation.html +++ b/html/navigation.html @@ -132,7 +132,7 @@
  • - +
  • @@ -207,17 +207,21 @@ }); ipcRenderer.on("button-hidden", (e, button) => { document.getElementById(button.id).parentNode.classList.toggle("hidden", button.hidden); - }); - ipcRenderer.on("input-blur", (e, input) => { - document.getElementById(input.id).blur(); - }); - ipcRenderer.on("input-select", (e, input) => { - document.getElementById(input.id).select(); + }); + ipcRenderer.on("input-readonly", (e, input) => { + document.getElementById(input.id).readOnly = input.readonly; }); ipcRenderer.on("input-text", (e, input) => { document.getElementById(input.id).value = input.text; document.getElementById(input.id).placeholder = input.placeholder; }); + ipcRenderer.on("input-select", (e, input) => { + if (input.select) { + document.getElementById(input.id).select(); + } else { + window.getSelection()?.removeAllRanges(); + } + }); ipcRenderer.on("data-theme", (e, data) => { document.documentElement.setAttribute("data-theme", data.theme); }); diff --git a/js/webview.js b/js/webview.js index 4ad0326..3fa1796 100644 --- a/js/webview.js +++ b/js/webview.js @@ -263,6 +263,10 @@ const updateNavigation = () => { text: currentUrl.startsWith("data:") ? "" : currentUrl, placeholder: defaultUrl.startsWith("data:") ? "" : defaultUrl, }); + WEBVIEW.navigation.webContents.send("input-readonly", { + id: "url", + readonly: !!HARDWARE.support.keyboardVisibility, + }); // Disable zoom buttons WEBVIEW.navigation.webContents.send("button-disabled", { @@ -632,22 +636,17 @@ const navigationEvents = async () => { return; } - // Handle navigation blur events - let selected = false; - WEBVIEW.navigation.webContents.on("blur", () => { - const visibility = hardware.getKeyboardVisibility(); - if (visibility === "ON" && selected) { - WEBVIEW.navigation.webContents.send("input-blur", { id: "url" }); - } - }); - // Handle input blur events + let selected = false; ipcMain.on("input-blur", (e, input) => { const visibility = hardware.getKeyboardVisibility(); switch (input.id) { case "url": if (visibility === "ON" && selected) { - hardware.setKeyboardVisibility("OFF"); + hardware.setKeyboardVisibility("OFF", () => { + WEBVIEW.navigation.webContents.send("input-select", { id: "url", select: false }); + WEBVIEW.navigation.webContents.send("input-readonly", { id: "url", readonly: true }); + }); } break; } @@ -664,7 +663,8 @@ const navigationEvents = async () => { setTimeout(() => { selected = true; WEBVIEW.navigation.webContents.focus(); - WEBVIEW.navigation.webContents.send("input-select", { id: "url" }); + WEBVIEW.navigation.webContents.send("input-select", { id: "url", select: true }); + WEBVIEW.navigation.webContents.send("input-readonly", { id: "url", readonly: false }); }, 400); }); }