fix: hotkeys back working

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-26 06:45:37 +02:00
parent 29922b8058
commit 8258b044b1
8 changed files with 93 additions and 3 deletions

View File

@@ -24,6 +24,10 @@ defmodule BDS.Desktop.Automation do
GenServer.call(session, {:click, selector}, @request_timeout)
end
def press(session, shortcut) when is_binary(shortcut) do
GenServer.call(session, {:press, shortcut}, @request_timeout)
end
def capture_screenshot(session, destination) when is_binary(destination) do
GenServer.call(session, {:capture_screenshot, destination}, @request_timeout)
end
@@ -78,6 +82,11 @@ defmodule BDS.Desktop.Automation do
{:reply, normalize_simple_reply(reply), state}
end
def handle_call({:press, shortcut}, _from, state) do
{reply, state} = driver_request(state, %{"command" => "press", "shortcut" => shortcut})
{:reply, normalize_simple_reply(reply), state}
end
def handle_call({:capture_screenshot, destination}, _from, state) do
File.mkdir_p!(Path.dirname(destination))

View File

@@ -6,6 +6,7 @@ defmodule BDS.Desktop.ShellLive do
import Phoenix.HTML
alias BDS.Desktop.ShellData
alias BDS.UI.Commands
alias BDS.UI.Registry
alias BDS.UI.Workbench
@@ -65,6 +66,14 @@ defmodule BDS.Desktop.ShellLive do
{:noreply, open_sidebar_item(socket, params, :pin)}
end
def handle_event("shortcut", params, socket) do
if ignore_shortcut?(params) do
{:noreply, socket}
else
{:noreply, reload_shell(socket, Commands.handle_shortcut(socket.assigns.workbench, params))}
end
end
def handle_event("select_tab", %{"type" => type, "id" => id}, socket) do
workbench =
Workbench.open_tab(socket.assigns.workbench, String.to_existing_atom(type), id, :preview)
@@ -430,6 +439,14 @@ defmodule BDS.Desktop.ShellLive do
Enum.find(tabs, &(&1.type == type and &1.id == id))
end
defp ignore_shortcut?(params) do
Map.get(params, "alt", false) or
Map.get(params, "contentEditable", false) or
Map.get(params, "content_editable", false) or
Map.get(params, "tag") in ["INPUT", "TEXTAREA", "SELECT"] or
Map.get(params, :tag) in ["INPUT", "TEXTAREA", "SELECT"]
end
defp open_sidebar_item(socket, params, intent) do
route_atom = sidebar_route_atom(Map.fetch!(params, "route"))
tab_id = tab_id_for_route(route_atom, Map.fetch!(params, "id"))

View File

@@ -1,4 +1,4 @@
<div class="app" id="bds-shell-app">
<div class="app" id="bds-shell-app" phx-window-keydown="shortcut">
<div class="window-titlebar" data-region="title-bar">
<div class="window-titlebar-menu-bar is-hidden">
<button class="window-titlebar-menu-button" type="button">File</button>

View File

@@ -33,7 +33,9 @@ defmodule BDS.UI.Commands do
def handle_shortcut(state, shortcut) when is_map(shortcut) do
key = shortcut |> Map.get(:key, Map.get(shortcut, "key", "")) |> String.downcase()
primary = Map.get(shortcut, :meta, false) or Map.get(shortcut, :ctrl, false)
primary =
Map.get(shortcut, :meta, Map.get(shortcut, "meta", false)) or
Map.get(shortcut, :ctrl, Map.get(shortcut, "ctrl", false))
case Enum.find(@menu_shortcuts, &shortcut_match?(&1, key, primary)) do
%{id: command_id} -> MenuBar.execute(state, command_id)