fix: drag-resize working now
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="app" id="bds-shell-app" phx-window-keydown="shortcut">
|
||||
<div class="app" id="bds-shell-app" phx-hook="AppShell" 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>
|
||||
|
||||
Reference in New Issue
Block a user