From 427209e51803a85c27711545580cc3e1f64c51a3 Mon Sep 17 00:00:00 2001 From: 2mal3 <56305732+2mal3@users.noreply.github.com> Date: Tue, 6 Jan 2026 19:18:18 +0100 Subject: [PATCH] refactor(control): make run_on_all_selected_displays more generic --- .../frontend/src/lib/components/InodeElement.svelte | 2 +- control/frontend/src/lib/ts/stores/displays.ts | 9 ++++----- control/frontend/src/routes/ControlView.svelte | 13 +++++++++---- control/frontend/src/routes/KeyInput.svelte | 2 +- control/frontend/src/routes/TipTapInput.svelte | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/control/frontend/src/lib/components/InodeElement.svelte b/control/frontend/src/lib/components/InodeElement.svelte index 7db5849..17d795f 100755 --- a/control/frontend/src/lib/components/InodeElement.svelte +++ b/control/frontend/src/lib/components/InodeElement.svelte @@ -160,7 +160,7 @@ await change_file_path($current_file_path + file.name + '/'); } else { const path_to_file = $current_file_path + file.name; - await run_on_all_selected_displays(open_file, true, path_to_file); + await run_on_all_selected_displays((d) => open_file(d.ip, path_to_file)); } } diff --git a/control/frontend/src/lib/ts/stores/displays.ts b/control/frontend/src/lib/ts/stores/displays.ts index adb06b8..bb27de4 100755 --- a/control/frontend/src/lib/ts/stores/displays.ts +++ b/control/frontend/src/lib/ts/stores/displays.ts @@ -142,15 +142,14 @@ export async function screenshot_loop(display_id: string, initial_retry_count: n await db.displays.update(display.id, { preview: display.preview }); } -export async function run_on_all_selected_displays( - run_function: (ip: string, ...args: T) => void | Promise, - update_screenshot_afterwards: boolean, - ...args: T +export async function run_on_all_selected_displays( + run_function: (display: Display) => void | Promise, + update_screenshot_afterwards: boolean = true ) { for (const display_id of get(selected_display_ids)) { const display = await get_display_by_id(display_id); if (!display || !display.ip || display.status !== 'app_online') continue; - await run_function(display.ip, ...args); + await run_function(display); if (update_screenshot_afterwards) { await screenshot_loop(display_id); } diff --git a/control/frontend/src/routes/ControlView.svelte b/control/frontend/src/routes/ControlView.svelte index 43368a1..399be56 100644 --- a/control/frontend/src/routes/ControlView.svelte +++ b/control/frontend/src/routes/ControlView.svelte @@ -19,6 +19,7 @@ import { get_display_by_id, run_on_all_selected_displays } from '$lib/ts/stores/displays'; import { selected_display_ids } from '$lib/ts/stores/select'; import TipTapInput from './TipTapInput.svelte'; + import { db } from '$lib/ts/database'; let popup_content: PopupContent = $state({ open: false, @@ -78,7 +79,11 @@ async function shutdown_action() { popup_content.open = false; - await run_on_all_selected_displays((ip) => shutdown(ip), false); + await run_on_all_selected_displays((d) => shutdown(d.ip), false); // no await here because we want to be fast + // await run_on_all_selected_displays((d) => { + // shutdown(d.ip); // no await here because we want to be fast + // db.displays.update(d.id, { status: 'app_offline' }); + // }, false); } @@ -121,7 +126,7 @@ className="px-9" disabled={$selected_display_ids.length === 0} click_function={async () => { - await run_on_all_selected_displays(send_keyboard_input, true, 'VK_LEFT'); + await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, 'VK_LEFT')); }}> @@ -142,7 +147,7 @@ className="px-3 flex gap-3 w-75 justify-normal" disabled={$selected_display_ids.length === 0} click_function={async () => { - await run_on_all_selected_displays(show_blackscreen, true); + await run_on_all_selected_displays((d) => show_blackscreen(d.ip)); }}>Blackout
diff --git a/control/frontend/src/routes/KeyInput.svelte b/control/frontend/src/routes/KeyInput.svelte index 30e90db..be686f2 100644 --- a/control/frontend/src/routes/KeyInput.svelte +++ b/control/frontend/src/routes/KeyInput.svelte @@ -31,7 +31,7 @@ add_to_last_keys(e.code); if (e.repeat) return; - await run_on_all_selected_displays(send_keyboard_input, true, id); + await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, id)); } diff --git a/control/frontend/src/routes/TipTapInput.svelte b/control/frontend/src/routes/TipTapInput.svelte index b371a74..b904bb9 100644 --- a/control/frontend/src/routes/TipTapInput.svelte +++ b/control/frontend/src/routes/TipTapInput.svelte @@ -117,7 +117,7 @@ const html = editor_state.editor?.getHTML() + ``; - await run_on_all_selected_displays(show_html, true, html); + await run_on_all_selected_displays((d) => show_html(d.ip, html)); } onMount(() => {