mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
improve control main display structure
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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<DisplayGroup[]> = writable<DisplayGroup[]>([{
|
||||
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 };
|
||||
})
|
||||
|
||||
@@ -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<string[] | null> {
|
||||
async function get_changed_directory_paths(display: Display, file_path: string): Promise<string[] | null> {
|
||||
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<number> {
|
||||
export async function update_folder_elements_recursively(display: Display, file_path: string = '/'): Promise<number> {
|
||||
const new_folder_elements = await get_file_data(display.ip, file_path);
|
||||
all_files.update((files: Record<string, Record<string, FolderElement[]>>) => {
|
||||
if (!files.hasOwnProperty(file_path)) {
|
||||
|
||||
Reference in New Issue
Block a user