From 3556ab45b3b18f1580cf76ed5910797fcb9c3e5d Mon Sep 17 00:00:00 2001 From: Chili Palmer Date: Sun, 26 Apr 2026 06:55:18 +0200 Subject: [PATCH] fix: drag-resize working now Co-authored-by: Copilot --- lib/bds/desktop/automation.ex | 20 ++++ lib/bds/desktop/shell_live.ex | 46 +++++++++ lib/bds/desktop/shell_live/index.html.heex | 2 +- priv/ui/live.js | 109 +++++++++++++++++++++ scripts/desktop_automation_runner.mjs | 29 ++++++ test/bds/desktop/automation_test.exs | 28 ++++++ test/bds/desktop/shell_live_test.exs | 24 +++++ 7 files changed, 257 insertions(+), 1 deletion(-) diff --git a/lib/bds/desktop/automation.ex b/lib/bds/desktop/automation.ex index e907fba..97ce83f 100644 --- a/lib/bds/desktop/automation.ex +++ b/lib/bds/desktop/automation.ex @@ -24,10 +24,18 @@ defmodule BDS.Desktop.Automation do GenServer.call(session, {:click, selector}, @request_timeout) end + def drag(session, selector, delta_x) when is_binary(selector) and is_integer(delta_x) do + GenServer.call(session, {:drag, selector, delta_x}, @request_timeout) + end + def press(session, shortcut) when is_binary(shortcut) do GenServer.call(session, {:press, shortcut}, @request_timeout) end + def reload(session) do + GenServer.call(session, :reload, @request_timeout) + end + def capture_screenshot(session, destination) when is_binary(destination) do GenServer.call(session, {:capture_screenshot, destination}, @request_timeout) end @@ -82,11 +90,23 @@ defmodule BDS.Desktop.Automation do {:reply, normalize_simple_reply(reply), state} end + def handle_call({:drag, selector, delta_x}, _from, state) do + {reply, state} = + driver_request(state, %{"command" => "drag", "selector" => selector, "deltaX" => delta_x}) + + {: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(:reload, _from, state) do + {reply, state} = driver_request(state, %{"command" => "reload"}) + {: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 3392f42..4015490 100644 --- a/lib/bds/desktop/shell_live.ex +++ b/lib/bds/desktop/shell_live.ex @@ -66,6 +66,14 @@ defmodule BDS.Desktop.ShellLive do {:noreply, open_sidebar_item(socket, params, :pin)} end + def handle_event("sync_layout", params, socket) do + {:noreply, reload_shell(socket, sync_layout(socket.assigns.workbench, params))} + end + + def handle_event("resize_panel", %{"target" => target, "width" => width}, socket) do + {:noreply, reload_shell(socket, resize_panel(socket.assigns.workbench, target, width))} + end + def handle_event("shortcut", params, socket) do if ignore_shortcut?(params) do {:noreply, socket} @@ -439,6 +447,44 @@ defmodule BDS.Desktop.ShellLive do Enum.find(tabs, &(&1.type == type and &1.id == id)) end + defp sync_layout(workbench, params) do + workbench + |> maybe_set_sidebar_width(Map.get(params, "sidebar_width")) + |> maybe_set_assistant_width(Map.get(params, "assistant_sidebar_width")) + end + + defp resize_panel(workbench, "sidebar", width) do + workbench + |> Workbench.set_sidebar_width(parse_width(width)) + |> Map.put(:sidebar_visible, true) + end + + defp resize_panel(workbench, "assistant", width) do + workbench + |> Workbench.set_assistant_sidebar_width(parse_width(width)) + |> Map.put(:assistant_sidebar_visible, true) + end + + defp resize_panel(workbench, _target, _width), do: workbench + + defp maybe_set_sidebar_width(workbench, nil), do: workbench + defp maybe_set_sidebar_width(workbench, width), do: Workbench.set_sidebar_width(workbench, parse_width(width)) + + defp maybe_set_assistant_width(workbench, nil), do: workbench + + defp maybe_set_assistant_width(workbench, width) do + Workbench.set_assistant_sidebar_width(workbench, parse_width(width)) + end + + defp parse_width(width) when is_integer(width), do: width + + defp parse_width(width) when is_binary(width) do + case Integer.parse(width) do + {parsed, _rest} -> parsed + :error -> 0 + end + end + defp ignore_shortcut?(params) do Map.get(params, "alt", false) or Map.get(params, "contentEditable", false) or diff --git a/lib/bds/desktop/shell_live/index.html.heex b/lib/bds/desktop/shell_live/index.html.heex index b461acd..9133e20 100644 --- a/lib/bds/desktop/shell_live/index.html.heex +++ b/lib/bds/desktop/shell_live/index.html.heex @@ -1,4 +1,4 @@ -
+