From 8258b044b194812a80b8d438f58bb729f36fa31f Mon Sep 17 00:00:00 2001 From: Chili Palmer Date: Sun, 26 Apr 2026 06:45:37 +0200 Subject: [PATCH] fix: hotkeys back working Co-authored-by: Copilot --- lib/bds/desktop/automation.ex | 9 +++++++ lib/bds/desktop/shell_live.ex | 17 +++++++++++++ lib/bds/desktop/shell_live/index.html.heex | 2 +- lib/bds/ui/commands.ex | 4 ++- priv/ui/live.js | 13 +++++++++- scripts/desktop_automation_runner.mjs | 7 ++++++ test/bds/desktop/automation_test.exs | 15 +++++++++++ test/bds/desktop/shell_live_test.exs | 29 ++++++++++++++++++++++ 8 files changed, 93 insertions(+), 3 deletions(-) diff --git a/lib/bds/desktop/automation.ex b/lib/bds/desktop/automation.ex index 8f2c9e2..e907fba 100644 --- a/lib/bds/desktop/automation.ex +++ b/lib/bds/desktop/automation.ex @@ -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)) diff --git a/lib/bds/desktop/shell_live.ex b/lib/bds/desktop/shell_live.ex index 57a8f8f..3392f42 100644 --- a/lib/bds/desktop/shell_live.ex +++ b/lib/bds/desktop/shell_live.ex @@ -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")) diff --git a/lib/bds/desktop/shell_live/index.html.heex b/lib/bds/desktop/shell_live/index.html.heex index 1c4534f..631eb3e 100644 --- a/lib/bds/desktop/shell_live/index.html.heex +++ b/lib/bds/desktop/shell_live/index.html.heex @@ -1,4 +1,4 @@ -
+