diff --git a/control/frontend/src/routes/+page.svelte b/control/frontend/src/routes/+page.svelte index 6c19554..0a90e8b 100644 --- a/control/frontend/src/routes/+page.svelte +++ b/control/frontend/src/routes/+page.svelte @@ -55,10 +55,10 @@ const mac = text_inputs_valid.mac.value === '' ? null : text_inputs_valid.mac.value; const name = text_inputs_valid.name.value; if (!!existing_display_id) { - edit_display_data(existing_display_id, ip, mac, name); + await edit_display_data(existing_display_id, ip, mac, name); } else { const status = await ping_ip(text_inputs_valid.ip.value); - add_display(ip, mac, name, status); + await add_display(ip, mac, name, status); } popup_close_function(); } diff --git a/control/frontend/src/ts/main.ts b/control/frontend/src/ts/main.ts index 61076ee..0193427 100644 --- a/control/frontend/src/ts/main.ts +++ b/control/frontend/src/ts/main.ts @@ -1,23 +1,32 @@ import { get } from "svelte/store"; -import { displays, update_displays_with_map } from "./stores/displays" +import { displays, run_on_all_selected_displays, update_displays_with_map, update_screenshot } from "./stores/displays" import { ping_ip } from "./api_handler"; import type { Display } from "./types"; -import { change_file_path, update_all_display_files } from "./stores/files"; +import { change_file_path, update_folder_elements_recursively } from "./stores/files"; const update_display_status_interval_seconds = 20; -export function on_start() { - update_all_display_status(); - setInterval(update_all_display_status, update_display_status_interval_seconds * 1000); - update_all_display_files('/'); +export async function on_start() { + await update_all_display_status(); + await setInterval(update_all_display_status, update_display_status_interval_seconds * 1000); + } async function update_all_display_status() { - update_displays_with_map(async (display: Display) => { + await update_displays_with_map(async (display: Display) => { const new_status = await ping_ip(display.ip); if (new_status === null && display.status !== null) return display; + if (new_status === "app_online" && display.status !== "app_online") { + await on_display_start(display); + } return { ...display, status: new_status, }; }); console.log("Display Status updated") +} + + +async function on_display_start(display: Display) { + await update_folder_elements_recursively(display, '/'); + await update_screenshot(display.id); } \ No newline at end of file diff --git a/control/frontend/src/ts/stores/displays.ts b/control/frontend/src/ts/stores/displays.ts index 3cce3db..c2eafb3 100644 --- a/control/frontend/src/ts/stores/displays.ts +++ b/control/frontend/src/ts/stores/displays.ts @@ -3,7 +3,6 @@ import type { Display, DisplayGroup, DisplayStatus } from "../types"; import { is_selected, select, selected_display_ids } from "./select"; import { get_uuid, image_content_hash } from "../utils"; import { get_screenshot } from "../api_handler"; -import DisplayGroupObject from "../../components/DisplayGroupObject.svelte"; export const displays: Writable = writable([{ id: get_uuid(), @@ -25,8 +24,8 @@ export function add_display(ip: string, mac: string | null, name: string, status }); } -export function edit_display_data(display_id: string, ip: string, mac: string | null, name: string) { - update_displays_with_map((display: Display) => { +export async function edit_display_data(display_id: string, ip: string, mac: string | null, name: string) { + await update_displays_with_map((display: Display) => { if (display.id !== display_id) return display; return { ...display, ip: ip, mac: mac, name: name }; }) diff --git a/control/frontend/src/ts/stores/files.ts b/control/frontend/src/ts/stores/files.ts index c084a7b..260964a 100644 --- a/control/frontend/src/ts/stores/files.ts +++ b/control/frontend/src/ts/stores/files.ts @@ -66,7 +66,7 @@ export function get_display_ids_where_file_is_missing(path: string, file: Folder return [missing, colliding]; } -export async function get_changed_directory_paths(display: Display, file_path: string): Promise { +async function get_changed_directory_paths(display: Display, file_path: string): Promise { const current_folder = await get_file_tree_data(display.ip, file_path); if (current_folder === null) return null; const directory_strings = get_recursive_changed_directory_paths(display, file_path, current_folder, get(all_files)); @@ -100,15 +100,7 @@ function get_recursive_changed_directory_paths(display: Display, current_file_pa return has_changed; } -export async function update_all_display_files(path: string) { - for (const display_group of get(displays)) { - for (const display of display_group.data) { - await update_folder_elements_recursively(display, path); - } - } -} - -async function update_folder_elements_recursively(display: Display, file_path: string = '/'): Promise { +export async function update_folder_elements_recursively(display: Display, file_path: string = '/'): Promise { const new_folder_elements = await get_file_data(display.ip, file_path); all_files.update((files: Record>) => { if (!files.hasOwnProperty(file_path)) {