mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-05 16:37:09 +00:00
refactor(control): make run_on_all_selected_displays more generic
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T extends unknown[]>(
|
||||
run_function: (ip: string, ...args: T) => void | Promise<void>,
|
||||
update_screenshot_afterwards: boolean,
|
||||
...args: T
|
||||
export async function run_on_all_selected_displays(
|
||||
run_function: (display: Display) => void | Promise<void>,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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'));
|
||||
}}><ArrowBigLeft /></Button
|
||||
>
|
||||
<Button
|
||||
@@ -129,7 +134,7 @@
|
||||
className="px-9"
|
||||
disabled={$selected_display_ids.length === 0}
|
||||
click_function={async () => {
|
||||
await run_on_all_selected_displays(send_keyboard_input, true, 'VK_RIGHT');
|
||||
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, 'VK_RIGHT'));
|
||||
}}><ArrowBigRight /></Button
|
||||
>
|
||||
</div>
|
||||
@@ -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));
|
||||
}}><Presentation />Blackout</Button
|
||||
>
|
||||
<div class="flex flex-row justify-normal">
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
const html =
|
||||
editor_state.editor?.getHTML() +
|
||||
`<style>:root {--background-color: ${color_states.bg.value} !important;}
|
||||
</style>`;
|
||||
</style>`;
|
||||
await run_on_all_selected_displays((d) => show_html(d.ip, html));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user