Compare commits

..

24 Commits

Author SHA1 Message Date
E44 c96b8fe7e4 bump to version v0.0.17 2026-01-19 18:58:28 +01:00
E44 671c74f25d chore(control): save text and url 2026-01-19 18:57:56 +01:00
2mal3 4d5d9849da feat: support sending modifier keys (#18)
Co-authored-by: E44 <129310925+programmer-44@users.noreply.github.com>
2026-01-19 18:47:53 +01:00
E44 c8e21a64bf fix(control): fix warning in compile process 2026-01-19 18:36:33 +01:00
E44 2711d89f22 chore(control): show folder_size as sum of all folder_elements 2026-01-19 18:33:59 +01:00
E44 c09e4b2d8d chore(control): set size of all folders in db to 0 2026-01-19 17:57:32 +01:00
E44 209080db22 refactor(control): replace === 'inode/directory' with is_folder() 2026-01-19 17:54:47 +01:00
2mal3 4acbc96a58 chore(control): prevent closing popups by clicking outside (#20)
Multiple test users closed various popups accidentally by clicking outside and rarely used the feature to close the popup.
2026-01-19 17:40:53 +01:00
E44 99643f8029 chore(control): display transferring file correctly (still a few bugs) 2026-01-19 15:39:53 +01:00
2mal3 ef7dfa49fe chore(control/ping): increase timeout 2026-01-19 12:43:22 +01:00
E44 7cfa56a906 chore(control): set preview update mode in dev mode to never automatically 2026-01-18 22:34:43 +01:00
E44 63c7cea4ca bump to v0.0.16 2026-01-18 22:24:35 +01:00
E44 0e87ca3ae1 fix(control): screenshot_loop is no longer blocking, preview states are now consistently changed 2026-01-18 22:22:30 +01:00
2mal3 d61ef0fe94 fix: browser insecurity warning 2026-01-18 22:13:03 +01:00
E44 5d1f3e2d20 refactor(control): correct spelling 2026-01-18 19:11:24 +01:00
E44 6dfb29bbd1 chore(control): improve handling with offline displays 2026-01-18 19:05:15 +01:00
2mal3 49410bf372 chore(control): more user friendly open website pop up 2026-01-18 18:59:12 +01:00
2mal3 5d22f62a6e chore(control): german button names 2026-01-18 18:52:22 +01:00
2mal3 a31080c602 chore(control): rename keyboard input 2026-01-18 18:47:59 +01:00
2mal3 ea3cbcb8c6 chore(control): title case for buttons and headings 2026-01-18 18:46:21 +01:00
2mal3 a0cf45c8dc chore: consistent display naming 2026-01-18 18:41:23 +01:00
E44 97d2608adf fix(control): wrong url in not-dev-mode 2026-01-18 18:23:49 +01:00
E44 36d2887247 fix(control): unknown status at app_start 2026-01-18 18:23:01 +01:00
E44 1e9148bff2 fix(control): use local ip address only in dev mode 2026-01-18 18:17:04 +01:00
27 changed files with 832 additions and 748 deletions
@@ -41,7 +41,7 @@
} else {
$pinned_display_id = display_id_object.id;
}
await screenshot_loop(display_id_object.id);
screenshot_loop(display_id_object.id);
e.stopPropagation();
}
</script>
@@ -11,7 +11,8 @@
type Inode,
get_file_primary_key,
type FileOnDisplay,
type CompleteFileLoadingData
type FileTransferTask,
is_folder
} from '$lib/ts/types';
import {
@@ -24,6 +25,7 @@
change_file_path,
current_file_path,
get_date_mapping,
get_folder_elements,
get_missing_colliding_display_ids
} from '$lib/ts/stores/files';
import RefreshPlay from '../svgs/RefreshPlay.svelte';
@@ -33,9 +35,12 @@
import { get_thumbnail_url } from '$lib/ts/stores/thumbnails';
import { liveQuery, type Observable } from 'dexie';
import { db } from '$lib/ts/database';
import { file_transfer_tasks } from '$lib/ts/file_transfer_handler';
let { file, not_interactable = false }: { file: Inode; not_interactable?: boolean } = $props();
let file_primary_key = $derived(get_file_primary_key(file));
let missing_colliding_displays_ids:
| Observable<{ missing: string[]; colliding: string[] }>
| undefined = $state();
@@ -44,34 +49,35 @@
missing_colliding_displays_ids = liveQuery(() => get_missing_colliding_display_ids(file, s));
});
let loading_data:
| Observable<CompleteFileLoadingData>
| undefined = $state();
let file_size: Observable<number> | undefined = $state();
$effect(() => {
const d = $selected_display_ids;
loading_data = liveQuery(() => get_loading_data(get_file_primary_key(file), d));
const f = file;
file_size = liveQuery(() => get_size_recursively(f));
});
let loading_finished = $state(false);
$effect(() => {
if (!loading_data) return;
let prev: boolean | undefined;
const sub = loading_data.subscribe((v) => {
if (prev === true && v.is_loading === false) {
loading_finished = true;
setTimeout(() => (loading_finished = false), 200);
}
prev = v.is_loading;
});
return () => sub.unsubscribe();
});
let thumbnail_url = liveQuery(() => get_thumbnail_url(get_file_primary_key(file)));
let date_mapping: Observable<Record<string, Date>> = liveQuery(() =>
get_date_mapping(get_file_primary_key(file))
let file_transfer_task: FileTransferTask | null = $derived(
$file_transfer_tasks.hasOwnProperty(file_primary_key)
? $file_transfer_tasks[file_primary_key]
: null
);
const is_folder = file.type === 'inode/directory';
let loading_finished = $state(false);
let previous_loading_state = $state(false);
$effect(() => {
const ftt = file_transfer_task;
if (previous_loading_state && !ftt) {
loading_finished = true;
setTimeout(() => (loading_finished = false), 200);
}
previous_loading_state = !!ftt;
});
let thumbnail_url = liveQuery(() => get_thumbnail_url(file_primary_key));
let date_mapping: Observable<Record<string, Date>> = liveQuery(() =>
get_date_mapping(file_primary_key)
);
const file_is_folder = $derived(is_folder(file));
function get_created_info(date_mapping: Record<string, Date> | undefined, full_string = false) {
if (!date_mapping) return '';
@@ -130,7 +136,7 @@
function get_grayed_out_text_color_strings(is_selected: boolean): string {
if (not_interactable) return 'text-stone-400';
if ($loading_data?.is_loading) return 'text-white/20';
if (!!file_transfer_task) return 'text-white/20';
const color = is_selected ? 'text-stone-600' : 'text-stone-400';
const factor = is_selected ? -1 : 1;
return `${color} group-hover:${get_shifted_color(color, factor * 100)} group-active:${get_shifted_color(color, factor * 150)}`;
@@ -138,20 +144,20 @@
function get_grayed_out_border_color_strings(is_selected: boolean): string {
if (not_interactable) return 'border-stone-550';
if ($loading_data?.is_loading) return 'border-white/10';
if (!!file_transfer_task) return 'border-white/10';
const color = is_selected ? 'border-stone-450' : 'border-stone-550';
const factor = is_selected ? 1 : 1;
return `${color} group-hover:${get_shifted_color(color, factor * 100)} group-active:${get_shifted_color(color, factor * 150)}`;
}
function onclick(e: Event) {
if (not_interactable || $loading_data?.is_loading) return;
select(selected_file_ids, get_file_primary_key(file), 'toggle');
if (not_interactable || !!file_transfer_task) return;
select(selected_file_ids, file_primary_key, 'toggle');
e.stopPropagation();
}
async function open() {
if (is_folder) {
if (file_is_folder) {
await change_file_path($current_file_path + file.name + '/');
} else {
const path_to_file = $current_file_path + file.name;
@@ -164,11 +170,11 @@
if (loading_finished) {
out += 'bg-stone-500 text-white/30';
} else if ($loading_data?.is_loading) {
} else if (!!file_transfer_task) {
out += 'bg-stone-700 text-white/30';
} else {
out += get_selectable_color_classes(
!not_interactable && is_selected(get_file_primary_key(file), $selected_file_ids),
!not_interactable && is_selected(file_primary_key, $selected_file_ids),
{
bg: true,
hover: !not_interactable,
@@ -180,7 +186,7 @@
if (not_interactable) {
out += ' rounded-lg';
} else if ($loading_data?.is_loading) {
} else if (!!file_transfer_task) {
out += ' rounded-r-lg';
} else {
out += ' rounded-r-lg cursor-pointer';
@@ -189,54 +195,36 @@
return out;
}
async function get_loading_data(
file_primary_key: string,
selected_display_ids: string[]
): Promise<CompleteFileLoadingData> {
const file_on_display_data: FileOnDisplay[] = await db.files_on_display
.where('file_primary_key')
.equals(file_primary_key)
.filter((e) => selected_display_ids.includes(e.display_id))
.toArray();
if (file_on_display_data.length === 0) {
return {
is_loading: true,
total_percentage: 0,
total_seconds_until_finish: -1,
display_data: []
};
function get_total_percentage(ftt: FileTransferTask): number {
let total_percentage: number;
if (ftt.data.type === 'upload') {
total_percentage = ftt.loading_data.percentage;
} else {
const percentage_array = ftt.data.destination_display_data.map(
(dd) => dd.loading_data.percentage
);
total_percentage =
(ftt.loading_data.percentage + percentage_array.reduce((total, n) => total + n, 0)) /
(1 + percentage_array.length);
}
const display_data = [];
let is_loading = false;
let percentage_sum = 0;
let total_seconds_until_finish = 0;
for (const fod of file_on_display_data) {
if (!!fod.loading_data) {
if (!is_loading) is_loading = true;
percentage_sum += fod.loading_data.percentage;
total_seconds_until_finish += fod.loading_data.seconds_until_finish;
const display = await get_display_by_id(fod.display_id);
if (!display) continue;
const display_data_element = {
loading_data: fod.loading_data,
display_name: display.name
};
if (fod.loading_data.type === 'sync_download') {
display_data.unshift(display_data_element); // insert sync_download element at beginning
} else {
display_data.push(display_data_element);
}
} else {
percentage_sum += 100;
return Math.min(total_percentage, 100);
}
async function get_size_recursively(file: Inode): Promise<number> {
if (is_folder(file)) {
const folder_elements = await get_folder_elements(
file.path + file.name + '/',
$selected_display_ids
);
let out: number = 0;
for (const el of folder_elements) {
out += await get_size_recursively(el);
}
return out;
} else {
return file.size;
}
let total_percentage = percentage_sum / display_data.length;
return {
is_loading,
total_percentage,
total_seconds_until_finish,
display_data
};
}
</script>
@@ -249,28 +237,28 @@
{#if !not_interactable}
<div class="h-{$current_height.file} aspect-square max-w-15 flex">
<Button
disabled={!is_folder && get_file_type(file) === null}
title={!is_folder && get_file_type(file) === null ? 'Dateityp nicht unterstützt' : ''}
className="flex rounded-l-lg rounded-r-none {is_folder
disabled={!file_is_folder && get_file_type(file) === null}
title={!file_is_folder && get_file_type(file) === null ? 'Dateityp nicht unterstützt' : ''}
className="flex rounded-l-lg rounded-r-none {file_is_folder
? 'text-stone-450'
: 'text-stone-800'} w-full"
div_class="w-full"
bg={get_selectable_color_classes(
!is_folder && get_file_type(file) !== null,
!file_is_folder && get_file_type(file) !== null,
{
bg: true
},
-50
)}
hover_bg={get_selectable_color_classes(
!is_folder,
!file_is_folder,
{
bg: true
},
50
)}
active_bg={get_selectable_color_classes(
!is_folder,
!file_is_folder,
{
bg: true
},
@@ -281,7 +269,7 @@
e.stopPropagation();
}}
>
{#if is_folder}
{#if file_is_folder}
<ArrowRight class="size-full" strokeWidth="3" />
{:else if $missing_colliding_displays_ids && $missing_colliding_displays_ids.missing.length !== 0}
<RefreshPlay className="size-full" />
@@ -302,15 +290,15 @@
{onclick}
class="{get_main_classes()} relative transition-colors duration-200 gap-4 flex flex-row justify-between group w-full min-w-0"
>
{#if $loading_data?.is_loading}
{#if !!file_transfer_task}
<div
class="absolute pointer-events-none inset-y-0 left-0 transition-[width] duration-200 bg-stone-600 rounded-r-lg"
style={`width: ${Math.min($loading_data.total_percentage, 100)}%;`}
class="absolute pointer-events-none inset-y-0 left-0 transition-[width] duration-400 bg-stone-600 rounded-r-lg"
style={`width: ${get_total_percentage(file_transfer_task)}%;`}
></div>
{/if}
<div class="flex flex-row gap-2 min-w-0 w-full z-10">
<div class="aspect-square rounded-md flex justify-center items-center">
{#if is_folder}
{#if file_is_folder}
<Folder class="size-full p-2" />
{:else if $thumbnail_url || null}
<img
@@ -327,14 +315,14 @@
{/if}
</div>
<div class="content-center truncate select-none w-full" title={file.name}>
{file.name.includes('.') && !is_folder && get_file_type(file)
{file.name.includes('.') && !file_is_folder && get_file_type(file)
? file.name.slice(0, file.name.lastIndexOf('.'))
: file.name}
</div>
</div>
<div
class=" p-1 flex flex-row items-center gap-1 pr-1 z-10 {get_grayed_out_text_color_strings(
is_selected(get_file_primary_key(file), $selected_file_ids)
is_selected(file_primary_key, $selected_file_ids)
)} duration-200 transition-colors"
>
<!-- {#if get_display_ids_where_file_is_missing($current_file_path, file, $selected_display_ids, $all_files)[1].length !== 0}
@@ -372,25 +360,25 @@
</div>
<div
class="h-[70%] border {get_grayed_out_border_color_strings(
is_selected(get_file_primary_key(file), $selected_file_ids)
is_selected(file_primary_key, $selected_file_ids)
)} duration-200 transition-colors my-1"
></div>
<div
class="w-12 content-center text-center select-none text-xs whitespace-nowrap truncate"
title={file.type}
>
{is_folder ? 'Ordner' : (get_file_type(file)?.display_name ?? '?')}
{file_is_folder ? 'Ordner' : (get_file_type(file)?.display_name ?? '?')}
</div>
<div
class="h-[70%] border {get_grayed_out_border_color_strings(
is_selected(get_file_primary_key(file), $selected_file_ids)
is_selected(file_primary_key, $selected_file_ids)
)} duration-200 transition-colors"
></div>
<div
class="w-12 content-center text-center select-none text-xs whitespace-nowrap"
title={get_file_size_display_string(file.size, 3)}
title={get_file_size_display_string($file_size ?? -1, 3)}
>
{get_file_size_display_string(file.size)}
{get_file_size_display_string($file_size ?? -1)}
</div>
</div>
</div>
@@ -18,7 +18,7 @@
} = $props();
function try_to_close() {
if (!content.closable || !content.open) return;
if (!content.open) return;
close_function();
}
@@ -35,19 +35,13 @@
</script>
{#if content.open}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
class="absolute inset-0 backdrop-blur flex justify-center items-center z-50 {className}"
onclick={try_to_close}
transition:fade={{ duration: 100 }}
>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
class="bg-stone-800 rounded-2xl min-w-[30%] max-w-[90%] max-h-[85%] flex flex-col shadow-2xl/60 overflow-hidden {content.window_class ??
''}"
onclick={(e) => e.stopPropagation()}
>
{#if content.title}
<div class="font-bold bg-stone-700 p-1.5 flex flex-row justify-between gap-8 w-full">
@@ -64,16 +58,16 @@
</div>
</div>
<div class="flex aspect-square shrink-0">
{#if content.closable}
<Button className="aspect-square p-1.5!" click_function={try_to_close}>
<X />
</Button>
{/if}
<Button className="aspect-square p-1.5!" click_function={try_to_close}>
<X />
</Button>
</div>
</div>
{/if}
<div class="p-2 min-h-0 overflow-auto flex flex-col gap-2 {snippet_container_class}">
{@render content.snippet(content.snippet_arg)}
{#if content.snippet}
{@render content.snippet(content.snippet_arg ?? '')}
{/if}
</div>
</div>
</div>
@@ -30,7 +30,7 @@
enter_function?: (() => void) | null;
} = $props();
let focus_bg = get_shifted_color(bg, 100);
let focus_bg = $derived(get_shifted_color(bg, 100));
let focused: boolean = $state(false);
let current_info = $state('');
let input_element: HTMLInputElement;
+24 -2
View File
@@ -1,5 +1,6 @@
import { notifications } from './stores/notification';
import {
is_folder,
to_display_status,
type DisplayStatus,
type Inode,
@@ -9,6 +10,9 @@ import {
} from './types';
import { dev } from '$app/environment';
import { get_sanitized_file_url } from './utils';
import { online_displays } from './stores/displays';
import { get } from 'svelte/store';
import { update_display_status } from './main';
export async function get_screenshot(ip: string): Promise<Blob | null> {
const options = { method: 'PATCH' };
@@ -92,6 +96,7 @@ export async function get_file_data(
size: Number(response_element.size),
thumbnail: null
};
if (is_folder(folder_element)) folder_element.size = 0;
folder_element_list.push({ folder_element, date_created: new Date(response_element.created) });
}
return folder_element_list;
@@ -188,14 +193,30 @@ async function request_display(
supress_error_handling_http_codes: number[] = []
): Promise<RequestResponse> {
const url = `http://${ip}:1323/api${api_route}`;
return await request(url, options, supress_error_handling_http_codes);
const current_online_displays = get(online_displays);
if (!current_online_displays.map((d) => d.ip).includes(ip)) return { ok: false };
const response = await request(url, options, supress_error_handling_http_codes);
if (!response.ok && response.http_code === 408) {
// Network error -> device possibly not longer online -> test status and throw no error if its offline
const possible_displays = current_online_displays.filter((d) => d.ip === ip);
for (const display of possible_displays) {
const current_status = await update_display_status(display);
if (current_status === 'app_online') {
console.error(`No response from ${url}`);
notifications.push('error', 'Netzwerk-Fehler bei API-Anfrage', `${url}`);
}
}
}
return response;
}
async function request_control(
api_route: string,
options: { method: string; headers?: Record<string, string>; body?: string }
): Promise<RequestResponse> {
const url = `http://127.0.0.1:8080/api${api_route}`;
const url = `${dev ? 'http://127.0.0.1:8080' : window.location.origin}/api${api_route}`;
return await request(url, options);
}
@@ -245,6 +266,7 @@ async function request(
if (dev) {
console.warn('Request failed - Is the targeted device online?');
}
return { ok: false, http_code: 408 };
} else {
console.error(url, error);
notifications.push('error', `Fataler Fehler bei API-Anfrage`, `${url}\nFehler: ${error}`);
+1 -2
View File
@@ -23,8 +23,7 @@ export class FileDatabase extends Dexie {
[display_id+file_primary_key],
display_id,
file_primary_key,
date_created,
loading_data
date_created
`,
displays: `
id,
@@ -1,3 +1,4 @@
import { get, writable, type Writable } from 'svelte/store';
import { db } from './database';
import { get_display_by_id } from './stores/displays';
import {
@@ -11,6 +12,7 @@ import { notifications } from './stores/notification';
import { generate_thumbnail } from './stores/thumbnails';
import {
get_file_primary_key,
is_folder,
type FileLoadingData,
type FileOnDisplay,
type FileTransferTask,
@@ -19,8 +21,17 @@ import {
} from './types';
import { get_sanitized_file_url, get_uuid, make_valid_name } from './utils';
const START_LOADING_DATA = {
percentage: 0,
bytes_per_second: 0,
seconds_until_finish: -1
};
export const file_transfer_tasks: Writable<Record<string, FileTransferTask>> = writable<
Record<string, FileTransferTask>
>({});
let is_processing: boolean = false;
const tasks: FileTransferTask[] = [];
export async function add_upload(
file_list: FileList,
@@ -28,7 +39,6 @@ export async function add_upload(
current_file_path: string
) {
if (file_list.length === 0) return console.warn('Upload canceled: no selected files');
await create_path_on_all_selected_displays(current_file_path, selected_display_ids);
const used_file_names: string[] = await (
@@ -47,6 +57,10 @@ export async function add_upload(
thumbnail: null
};
const file_primary_key = get_file_primary_key(db_file);
if (Object.prototype.hasOwnProperty.call(file_transfer_tasks, file_primary_key))
return show_already_in_tasks_error(db_file, 'upload'); // file is already in task
await db.files.put(db_file);
const upload_task_promises = selected_display_ids.map(async (display_id) => {
@@ -56,17 +70,11 @@ export async function add_upload(
const db_file_on_display: FileOnDisplay = {
display_id,
file_primary_key,
date_created: new Date(),
loading_data: {
type: 'upload',
percentage: 0,
bytes_per_second: 0,
seconds_until_finish: -1
}
date_created: new Date()
};
await db.files_on_display.put(db_file_on_display);
return {
const new_task = {
data: {
type: 'upload' as const,
file
@@ -77,13 +85,16 @@ export async function add_upload(
},
path: current_file_path,
file_name: file_name,
file_primary_key,
loading_data: START_LOADING_DATA,
bytes_total: file.size
};
file_transfer_tasks.update((tasks) => ({
...tasks,
[file_primary_key]: new_task
}));
});
const upload_tasks = (await Promise.all(upload_task_promises)).filter((e) => !!e);
tasks.push(...upload_tasks);
await Promise.all(upload_task_promises);
}
await start_task_processing();
@@ -99,7 +110,7 @@ export async function add_sync_recursively(
);
if (!file_data) return console.warn('Sync canceled: no file_data');
if (file_data.file.type === 'inode/directory') {
if (is_folder(file_data.file)) {
const new_path = file_data.file.path + file_data.file.name + '/';
const elements_in_folder = await get_folder_elements(new_path, selected_display_ids);
if (elements_in_folder.length === 0) {
@@ -113,42 +124,36 @@ export async function add_sync_recursively(
}
if (file_data.short_displays_without_file.length === 0) return; // file is present on all selected displays
if (Object.prototype.hasOwnProperty.call(file_transfer_tasks, selected_file_id))
return show_already_in_tasks_error(file_data.file, 'sync'); // file is already in task
await create_path_on_all_selected_displays(file_data.file.path, selected_display_ids);
tasks.push({
const new_task: FileTransferTask = {
data: {
type: 'sync',
destination_displays: file_data.short_displays_without_file
destination_display_data: file_data.short_displays_without_file.map((display) => ({
display,
loading_data: START_LOADING_DATA
}))
},
display: file_data.short_display_with_file,
path: file_data.file.path,
file_name: file_data.file.name,
file_primary_key: selected_file_id,
loading_data: START_LOADING_DATA,
bytes_total: file_data.file.size
});
await db.files_on_display.update([file_data.short_display_with_file.id, selected_file_id], {
loading_data: {
type: 'sync_download',
percentage: 0,
bytes_per_second: 0,
seconds_until_finish: -1
}
});
const display_ids_without_file = file_data.short_displays_without_file.map((d) => d.id);
const new_file_loading_data: FileLoadingData = {
type: 'sync_upload',
percentage: 0,
bytes_per_second: 0,
seconds_until_finish: -1
};
file_transfer_tasks.update((tasks) => ({
...tasks,
[selected_file_id]: new_task
}));
const display_ids_without_file = file_data.short_displays_without_file.map((d) => d.id);
const new_fods: FileOnDisplay[] = display_ids_without_file.map((display_id) => ({
display_id,
file_primary_key: selected_file_id,
date_created: new Date(),
loading_data: new_file_loading_data
date_created: new Date()
}));
console.log("TEST", new_fods)
await db.files_on_display.bulkPut(new_fods);
await start_task_processing();
@@ -222,15 +227,15 @@ function generate_valid_file_name(original_file_name: string, used_file_names: s
return name;
}
async function upload(task: FileTransferTask): Promise<void> {
async function upload(file_primary_key: string, task: FileTransferTask): Promise<void> {
const task_data = task.data;
if (task_data.type !== 'upload' || !task_data.file)
return console.warn('Task cancelled: wrong task type:', task);
await upload_file_via_xhr(task, task.display, task_data.file);
await upload_file_via_xhr(file_primary_key, task, task_data.file);
}
export async function sync(task: FileTransferTask) {
export async function sync(file_primary_key: string, task: FileTransferTask) {
if (task.data.type !== 'sync') return console.warn('Task cancelled: wrong task type:', task);
const hasOPFS =
@@ -238,7 +243,8 @@ export async function sync(task: FileTransferTask) {
'storage' in navigator &&
'getDirectory' in navigator.storage;
if (!hasOPFS) {
return show_error(
return show_general_error(
file_primary_key,
task,
'OPFS (navigator.storage.getDirectory) nicht verfügbar bitte Chromium/Edge/Chrome nutzen.'
);
@@ -251,7 +257,7 @@ export async function sync(task: FileTransferTask) {
const url = `http://${task.display.ip}:1323/api${get_sanitized_file_url(task.path + task.file_name)}`;
const fetch_source = await fetch(url, { method: 'GET' });
if (!fetch_source.ok || !fetch_source.body)
return show_error(task, `HTTP ${fetch_source.status}`);
return show_general_error(file_primary_key, task, `HTTP ${fetch_source.status}`);
const dir = await navigator.storage.getDirectory();
const file_handle = await dir.getFileHandle(temp_name, { create: true });
@@ -264,25 +270,23 @@ export async function sync(task: FileTransferTask) {
if (done) break;
if (!value) continue;
await update_current_loading_data('sync_download', task, value.byteLength, start_time);
update_current_loading_data(file_primary_key, value.byteLength, start_time);
await writable.write(value);
}
await writable.close();
await db.files_on_display.update([task.display.id, task.file_primary_key], {
loading_data: null
});
finish_loading_data(file_primary_key);
// 02 - send downloaded file to every destination_display
const temp_file = await file_handle.getFile();
for (const current_short_display of task.data.destination_displays) {
await upload_file_via_xhr(task, current_short_display, temp_file);
for (const current_short_display of task.data.destination_display_data) {
await upload_file_via_xhr(file_primary_key, task, temp_file, current_short_display.display);
}
await dir.removeEntry(temp_name);
} catch (e) {
show_error(task, String(e));
show_general_error(file_primary_key, task, String(e));
}
}
@@ -291,7 +295,7 @@ export async function download_file(selected_file_id: string, selected_display_i
selected_file_id,
selected_display_ids
);
if (!file_data || file_data.file.type === 'inode/directory')
if (!file_data || is_folder(file_data.file))
return console.warn('Download cancelled: is folder');
try {
@@ -315,56 +319,62 @@ export async function download_file(selected_file_id: string, selected_display_i
async function start_task_processing() {
if (!is_processing) {
is_processing = tasks.length !== 0;
is_processing = Object.keys(get(file_transfer_tasks)).length !== 0;
await start_task_loop();
}
}
async function start_task_loop() {
while (tasks.length > 0) {
const current_task = tasks[0];
while (Object.keys(get(file_transfer_tasks)).length > 0) {
const tasks = get(file_transfer_tasks);
const current_file_id = Object.keys(tasks)[0];
const current_task = tasks[current_file_id];
if (current_task.data.type === 'upload') {
await upload(current_task);
await upload(current_file_id, current_task);
} else if (current_task.data.type === 'sync') {
await sync(current_task);
await sync(current_file_id, current_task);
}
tasks.shift(); // Remove current_task from tasks
file_transfer_tasks.update((all_tasks) => {
const next = { ...all_tasks };
delete next[current_file_id];
return next;
});
}
is_processing = false;
}
async function upload_file_via_xhr(
file_primary_key: string,
task: FileTransferTask,
current_short_display: ShortDisplay,
current_file: File
current_file: File,
destination_short_display: ShortDisplay | null = null
) {
const start_time = new Date();
const loading_type = task.data.type === 'upload' ? 'upload' : 'sync_upload';
return new Promise<void>((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open(
'POST',
`http://${current_short_display.ip}:1323/api${get_sanitized_file_url(task.path + task.file_name)}`,
`http://${destination_short_display ? destination_short_display.ip : task.display.ip}:1323/api${get_sanitized_file_url(task.path + task.file_name)}`,
true
);
xhr.setRequestHeader('content-type', 'application/octet-stream');
xhr.upload.onprogress = (e) => {
const apply = async () => {
await update_current_loading_data(
loading_type,
task,
update_current_loading_data(
file_primary_key,
e.loaded,
start_time,
current_short_display.id
destination_short_display ? destination_short_display.id : null
);
};
apply();
};
xhr.onerror = async (e: ProgressEvent) => {
await show_error(task, e);
await show_general_error(file_primary_key, task, e);
resolve();
};
@@ -372,21 +382,21 @@ async function upload_file_via_xhr(
if (xhr.readyState === 4) {
if (xhr.status == 200) {
// set loading_data to 100%
await db.files_on_display.update([current_short_display.id, task.file_primary_key], {
date_created: new Date(),
loading_data: null
});
finish_loading_data(
file_primary_key,
destination_short_display ? destination_short_display.id : null
);
// Generate Thumbnail if not done already
setTimeout(async () => {
const inode_element: Inode | undefined = await db.files.get(
JSON.parse(task.file_primary_key) as [string, string, number, string]
JSON.parse(file_primary_key) as [string, string, number, string]
);
if (!!inode_element && inode_element.thumbnail === null) {
await generate_thumbnail(task.display.ip, task.path, inode_element);
}
}, 10);
} else {
await show_error(task, `HTTP ${xhr.status}`);
await show_general_error(file_primary_key, task, `HTTP ${xhr.status}`);
}
resolve();
}
@@ -396,30 +406,74 @@ async function upload_file_via_xhr(
});
}
async function update_current_loading_data(
type: FileLoadingData['type'],
task: FileTransferTask,
function finish_loading_data(
file_primary_key: string,
destination_display_id: string | null = null
) {
file_transfer_tasks.update((tasks) => {
const task = tasks[file_primary_key];
const current_loading_data = {
percentage: 100,
bytes_per_second: 0,
seconds_until_finish: 0
};
return {
...tasks,
[file_primary_key]: get_updated_task(current_loading_data, destination_display_id, task)
};
});
}
function update_current_loading_data(
file_primary_key: string,
current_bytes: number,
start_time: Date,
other_display_id: string | null = null
destination_display_id: string | null = null
) {
const current_percentage = Math.min(
task.bytes_total > 0 ? Math.round((current_bytes / task.bytes_total) * 100) : 1,
99
); // calculate percantage, but maximum value is 99%
const prognosed_data = get_prognosed_data(start_time, current_bytes, task.bytes_total);
file_transfer_tasks.update((tasks) => {
const task = tasks[file_primary_key];
if (!task) return tasks;
await db.files_on_display.update(
[other_display_id ? other_display_id : task.display.id, task.file_primary_key],
{
loading_data: {
type,
percentage: current_percentage,
bytes_per_second: prognosed_data.bytes_per_second,
seconds_until_finish: prognosed_data.seconds_until_finish
const current_percentage = Math.min(
task.bytes_total > 0 ? Math.round((current_bytes / task.bytes_total) * 100) : 1,
99
);
const prognosed_data = get_prognosed_data(start_time, current_bytes, task.bytes_total);
const current_loading_data: FileLoadingData = {
percentage: current_percentage,
bytes_per_second: prognosed_data.bytes_per_second,
seconds_until_finish: prognosed_data.seconds_until_finish
};
return {
...tasks,
[file_primary_key]: get_updated_task(current_loading_data, destination_display_id, task)
};
});
}
function get_updated_task(current_loading_data: FileLoadingData, destination_display_id: string | null, task: FileTransferTask): FileTransferTask {
if (destination_display_id && task.data.type === 'sync') {
const updatedDestinations = task.data.destination_display_data.map((dd) =>
dd.display.id === destination_display_id ? { ...dd, loading_data: current_loading_data } : dd
);
return {
...task,
data: {
...task.data,
destination_display_data: updatedDestinations
}
}
);
};
} else {
return {
...task,
loading_data: current_loading_data
};
}
}
function get_prognosed_data(
@@ -434,7 +488,11 @@ function get_prognosed_data(
return { bytes_per_second, seconds_until_finish };
}
async function show_error(task: FileTransferTask, error: ProgressEvent | string) {
async function show_general_error(
file_primary_key: string,
task: FileTransferTask,
error: ProgressEvent | string
) {
const task_data = task.data;
console.error('Error in File-Transfer-Handler:', error, task);
notifications.push(
@@ -443,12 +501,20 @@ async function show_error(task: FileTransferTask, error: ProgressEvent | string)
`Datei: "${task.file_name}", Display-IP: ${task.display.ip}\nFehler: ${error}`
);
if (task_data.type === 'upload') {
await remove_file_from_display_recusively(task.display.id, task.file_primary_key);
await remove_file_from_display_recusively(task.display.id, file_primary_key);
await remove_all_files_without_display();
} else if (task_data.type === 'sync') {
for (const display_id of task_data.destination_displays.map((e) => e.id)) {
await remove_file_from_display_recusively(display_id, task.file_primary_key);
for (const display_id of task_data.destination_display_data.map((e) => e.display.id)) {
await remove_file_from_display_recusively(display_id, file_primary_key);
}
await remove_all_files_without_display();
}
}
function show_already_in_tasks_error(file: Inode, process: 'upload' | 'sync') {
notifications.push(
'error',
`Datei '${file.name}' konnte nicht ${process === 'upload' ? 'hochgeladen' : 'synchronisiert'} werden`,
`Eine Datei kann nicht in mehreren file_transfer_tasks enthalten sein. Bitte erneut versuchen, wenn die aktuellen Aktionen fertiggestellt wurden`
);
}
+8 -4
View File
@@ -1,6 +1,6 @@
import { screenshot_loop } from './stores/displays';
import { ping_ip } from './api_handler';
import type { Display } from './types';
import type { Display, DisplayStatus } from './types';
import { update_folder_elements_recursively } from './stores/files';
import { db } from './database';
@@ -12,6 +12,9 @@ const loading_display_ids: string[] = [];
export async function on_app_start() {
await db.files.clear();
await db.files_on_display.clear();
await db.displays
.toCollection()
.modify({ status: null, preview: { currently_updating: false, url: null } });
await update_all_display_status(false);
await setInterval(
() => update_all_display_status(false),
@@ -36,9 +39,9 @@ async function update_all_display_status(only_loading_displays: boolean) {
}
}
export async function update_display_status(display: Display) {
export async function update_display_status(display: Display): Promise<DisplayStatus> {
const new_status = await ping_ip(display.ip);
if (new_status === null && display.status !== null) return;
if (new_status === null && display.status !== null) return null;
if (new_status !== display.status) {
// status change
if (new_status === 'app_offline') {
@@ -52,6 +55,7 @@ export async function update_display_status(display: Display) {
display.status = new_status;
await db.displays.put(display); // save
}
return new_status;
}
export function remove_display_from_loading_displays(display_id: string) {
@@ -63,5 +67,5 @@ export function remove_display_from_loading_displays(display_id: string) {
async function on_display_start(display: Display) {
await update_folder_elements_recursively(display, '/');
await screenshot_loop(display.id);
screenshot_loop(display.id);
}
+73 -36
View File
@@ -14,6 +14,15 @@ import { db } from '../database';
import { dev } from '$app/environment';
import { remove_display_from_loading_displays } from '../main';
import { preview_settings } from './ui_behavior';
import { liveQuery } from 'dexie';
export const online_displays: Writable<Display[]> = writable<Display[]>([]);
export const online_displays_sub = liveQuery(() =>
db.displays.where('status').equals('app_online').toArray()
).subscribe((value) => {
online_displays.set(value);
});
export const local_displays: Writable<DisplayIdGroup[]> = writable<DisplayIdGroup[]>([]);
@@ -62,8 +71,15 @@ export async function edit_display_data(
): Promise<Display | null> {
let display = await db.displays.get(display_id);
if (!display) return null;
display = { ...display, ip: ip, mac: mac, name: name };
display = {
...display,
ip: ip,
mac: mac,
name,
preview: { currently_updating: false, url: null }
};
await db.displays.put(display); // save
screenshot_loop(display.id);
return display;
}
@@ -118,49 +134,60 @@ export async function get_display_by_id(display_id: string): Promise<Display | n
return (await db.displays.get(display_id)) ?? null;
}
export async function screenshot_loop(display_id: string) {
const settings = get(preview_settings);
if (settings.mode === 'never') return;
export function screenshot_loop(display_id: string) {
setTimeout(async () => {
let settings = get(preview_settings);
if (settings.mode === 'never') return;
const initial_retry_count = settings.retry_count.now;
const retry_seconds = get(preview_settings).retry_seconds.now;
const initial_retry_count = settings.retry_count.now;
const retry_seconds = get(preview_settings).retry_seconds.now;
const display = await db.displays.get(display_id);
if (!display || display.preview.currently_updating) return;
const display = await db.displays.get(display_id);
if (!display || display.preview.currently_updating) return;
display.preview.currently_updating = true;
await db.displays.update(display.id, { preview: display.preview });
display.preview.currently_updating = true;
await db.displays.update(display.id, { preview: display.preview });
let last_hash: number | null = null;
let last_hash: number | null = null;
let retry_count = initial_retry_count;
while (retry_count > 0) {
if (settings.mode !== 'always') retry_count -= 1;
let retry_count = initial_retry_count;
while (retry_count > 0) {
settings = get(preview_settings);
if (settings.mode === 'never') break;
if (settings.mode !== 'always') retry_count -= 1;
const new_blob = await get_screenshot(display.ip);
if (!new_blob) {
display.preview = { currently_updating: false, url: null };
await db.displays.update(display.id, { preview: display.preview });
return;
}
const new_hash = await image_content_hash(new_blob);
if (last_hash !== new_hash) {
if (display.preview.url) {
URL.revokeObjectURL(display.preview.url);
const new_blob = await get_screenshot(display.ip);
settings = get(preview_settings);
if (settings.mode === 'never') break;
if (!new_blob) {
display.preview = { currently_updating: false, url: null };
await db.displays.update(display.id, { preview: display.preview });
return;
}
const new_hash = await image_content_hash(new_blob);
if (last_hash !== new_hash) {
if (display.preview.url) {
URL.revokeObjectURL(display.preview.url);
}
last_hash = new_hash;
display.preview.url = URL.createObjectURL(new_blob);
await db.displays.update(display.id, { preview: display.preview });
retry_count = initial_retry_count;
}
last_hash = new_hash;
display.preview.url = URL.createObjectURL(new_blob);
await db.displays.update(display.id, { preview: display.preview });
retry_count = initial_retry_count;
await new Promise((resolve) => setTimeout(resolve, retry_seconds * 1000)); // sleep
}
await new Promise((resolve) => setTimeout(resolve, retry_seconds * 1000)); // sleep
}
display.preview.currently_updating = false;
await db.displays.update(display.id, { preview: display.preview });
if (settings.mode === 'never') {
await db.displays.update(display.id, { preview: { currently_updating: false, url: null } });
} else {
display.preview.currently_updating = false;
await db.displays.update(display.id, { preview: display.preview });
}
}, 0);
}
export async function run_on_all_selected_displays(
@@ -179,7 +206,7 @@ export async function run_on_all_selected_displays(
if (!display || (ignore_offline && display.status === 'host_offline')) return;
await run_function(display);
if (update_screenshot_afterwards) {
await screenshot_loop(display.id);
screenshot_loop(display.id);
}
})
);
@@ -204,7 +231,7 @@ export async function update_local_displays() {
export async function update_db_displays() {
local_displays.update((groups) => groups.filter((g) => g.displays.length !== 0));
const filtered_local_display_groups = get(local_displays)
const filtered_local_display_groups = get(local_displays);
const db_display_group_ids = (await db.display_groups.toArray()).map((group) => group.id);
const local_display_group_ids = filtered_local_display_groups.map((group) => group.id);
@@ -242,6 +269,16 @@ export function set_new_display_order(display_id_group_id: string, new_data: Dis
});
}
export function no_active_display_selected(
selected_display_ids: string[],
online_displays: Display[]
) {
const online_and_selected_displays = online_displays.filter((d) =>
selected_display_ids.includes(d.id)
);
return online_and_selected_displays.length === 0;
}
if (dev) {
setTimeout(add_testing_displays, 0);
async function add_testing_displays() {
+28 -21
View File
@@ -1,6 +1,7 @@
import { get, writable, type Writable } from 'svelte/store';
import {
get_file_primary_key,
is_folder,
type Display,
type FileOnDisplay,
type Inode,
@@ -11,6 +12,7 @@ import { is_selected, select, selected_display_ids, selected_file_ids } from './
import { create_path, get_file_data, get_file_tree_data } from '../api_handler';
import { deactivate_old_thumbnail_urls, generate_thumbnail } from './thumbnails';
import { db } from '../database';
import { file_transfer_tasks } from '../file_transfer_handler';
export const current_file_path: Writable<string> = writable<string>('/');
@@ -58,7 +60,7 @@ export async function remove_file_from_display_recusively(
const inode_element = await get_file_by_id(found.file_primary_key);
if (!inode_element) return;
if (inode_element.type === 'inode/directory') {
if (is_folder(inode_element)) {
const path_inside_folder = inode_element.path + inode_element.name + `/`;
const primary_file_keys_in_folder = (
await db.files.where('path').equals(path_inside_folder).toArray()
@@ -148,7 +150,7 @@ export async function get_displays_where_path_not_exists(
const folders_of_current_path = await db.files
.where('name')
.equals(last_path_part)
.filter((inode) => inode.path === path_without_last_part && inode.type === 'inode/directory')
.filter((inode) => inode.path === path_without_last_part && is_folder(inode))
.first();
if (!folders_of_current_path) return [];
const folder_primary_key = get_file_primary_key(folders_of_current_path);
@@ -231,9 +233,20 @@ export async function update_folder_elements_recursively(
const new_folder_elements = await get_file_data(display.ip, file_path);
if (!new_folder_elements) return;
const loading_file_ids = Object.keys(get(file_transfer_tasks));
const loading_file_keys_without_size = (
await db.files.bulkGet(
loading_file_ids.map((string_id) => JSON.parse(string_id) as [string, string, number, string])
)
)
.filter((f) => !!f)
.map((f) => JSON.stringify([f.path, f.name, f.type]));
// Filter new files, which aren't currently uploading
const existing_files_on_display_in_path: FileOnDisplay[] = await db.files_on_display
.where('display_id')
.equals(display.id)
.filter((f) => !loading_file_ids.includes(f.file_primary_key))
.toArray();
const existing_file_keys_on_display_in_path: [string, string, number, string][] =
existing_files_on_display_in_path.map(
@@ -245,17 +258,14 @@ export async function update_folder_elements_recursively(
.filter((e) => e.path === file_path)
.toArray();
const existing_files_with_loading_state: { folder_element: Inode; is_loading: boolean }[] =
existing_files.map((folder_element) => ({
folder_element,
is_loading: !!existing_files_on_display_in_path.find(
(e) => e.file_primary_key === get_file_primary_key(folder_element)
)?.loading_data
}));
const diff = get_folder_elements_difference(existing_files, new_folder_elements);
const diff = get_folder_elements_difference(
existing_files_with_loading_state,
new_folder_elements
// Filter new files, which aren't currently uploading -> don't compare size
diff.new = diff.new.filter(
(e) =>
!loading_file_keys_without_size.includes(
JSON.stringify([e.folder_element.path, e.folder_element.name, e.folder_element.type])
)
);
if (diff.new.length > 0) {
@@ -265,12 +275,11 @@ export async function update_folder_elements_recursively(
const file_on_display: FileOnDisplay = {
display_id: display.id,
file_primary_key: get_file_primary_key(new_element.folder_element),
loading_data: null,
date_created: new_element.date_created
};
await db.files_on_display.put(file_on_display);
if (new_element.folder_element.type === 'inode/directory') {
if (is_folder(new_element.folder_element)) {
await update_folder_elements_recursively(
display,
file_path + new_element.folder_element.name + '/'
@@ -295,15 +304,13 @@ export async function update_folder_elements_recursively(
}
function get_folder_elements_difference(
old_elements: { folder_element: Inode; is_loading: boolean }[],
old_elements: Inode[],
new_elements: { folder_element: Inode; date_created: Date }[]
): { deleted: Inode[]; new: { folder_element: Inode; date_created: Date }[] } {
const old_keys = new Set(old_elements.map((e) => get_file_primary_key(e.folder_element)));
const old_keys = new Set(old_elements.map((e) => get_file_primary_key(e)));
const new_keys = new Set(new_elements.map((e) => get_file_primary_key(e.folder_element)));
const only_in_old = old_elements
.filter((e) => !new_keys.has(get_file_primary_key(e.folder_element)) && !e.is_loading)
.map((e) => e.folder_element);
const only_in_old = old_elements.filter((e) => !new_keys.has(get_file_primary_key(e)));
const only_in_new = new_elements.filter(
(e) => !old_keys.has(get_file_primary_key(e.folder_element))
);
@@ -328,8 +335,8 @@ export async function get_folder_elements(
function sort_files(files: Inode[]) {
files.sort((a, b) => {
const isDirA = a.type === 'inode/directory';
const isDirB = b.type === 'inode/directory';
const isDirA = is_folder(a);
const isDirB = is_folder(b);
// Ordner zuerst
if (isDirA && !isDirB) return -1;
@@ -1,5 +1,6 @@
import { writable, type Writable } from 'svelte/store';
import type { NumberSetting } from '../types';
import { dev } from '$app/environment';
export const dnd_flip_duration_ms = 300;
@@ -33,7 +34,7 @@ export const preview_settings: Writable<{
retry_seconds: NumberSetting;
retry_count: NumberSetting;
}>({
mode: 'normal',
mode: dev ? 'never' : 'normal',
retry_seconds: {
max: 10,
min: 0.5,
+22 -25
View File
@@ -33,7 +33,7 @@ export type FileTransferTask = {
display: ShortDisplay;
path: string;
file_name: string;
file_primary_key: string;
loading_data: FileLoadingData;
bytes_total: number; // if type === 'sync' -> bytes_total = file_size * 2 (1x download + 1x upload)
};
@@ -44,9 +44,18 @@ export type FileTransferTaskData =
}
| {
type: 'sync';
destination_displays: ShortDisplay[];
destination_display_data: {
display: ShortDisplay;
loading_data: FileLoadingData;
}[];
};
export type FileLoadingData = {
percentage: number;
bytes_per_second: number;
seconds_until_finish: number;
};
export type ShortDisplay = {
id: string;
ip: string;
@@ -56,21 +65,6 @@ export type FileOnDisplay = {
display_id: string;
file_primary_key: string; // JSON.stringify([string, string, number, string])
date_created: Date;
loading_data: FileLoadingData | null; // null if not loading
};
export type FileLoadingData = {
type: 'upload' | 'download' | 'sync_download' | 'sync_upload';
percentage: number;
bytes_per_second: number;
seconds_until_finish: number;
};
export type CompleteFileLoadingData = {
is_loading: boolean;
total_percentage: number;
total_seconds_until_finish: number;
display_data: { loading_data: FileLoadingData; display_name: string }[];
};
export type Inode = {
@@ -132,21 +126,20 @@ export type MenuOption = {
export type PopupContent = {
open: boolean;
snippet: Snippet<[string]> | null;
snippet_arg?: string;
snippet: Snippet<[any]> | Snippet<[]> | Snippet | null | any;
snippet_arg?: any;
title?: string;
title_class?: string;
title_icon?: typeof X | null;
window_class?: string;
closable?: boolean;
};
export type NumberSetting = {
max: number,
min: number,
now: number,
step: number
}
max: number;
min: number;
now: number;
step: number;
};
export type DisplayStatus = 'host_offline' | 'app_offline' | 'app_online' | null;
@@ -155,3 +148,7 @@ export function to_display_status(value: string): DisplayStatus {
? (value as DisplayStatus)
: null;
}
export function is_folder(inode: Inode) {
return inode.type === 'inode/directory';
}
+1 -1
View File
@@ -55,7 +55,7 @@ export function get_uuid(): string {
export function get_file_size_display_string(size: number, toFixed: number | null = null): string {
if (size < 0)
return toFixed === null ? 'versch.' : 'Verschiedene Größen auf verschiedenen Bildschirmen';
return toFixed === null ? '...' : 'Größe wird aktuell berechnet';
if (size === 0) return '0 B';
const k = 1024;
+20 -12
View File
@@ -25,7 +25,8 @@
edit_display_data,
get_display_by_id,
is_display_name_taken,
remove_display
remove_display,
screenshot_loop
} from '$lib/ts/stores/displays';
import { notifications } from '$lib/ts/stores/notification';
import { ping_ip } from '$lib/ts/api_handler';
@@ -35,6 +36,7 @@
import HighlightedText from '$lib/components/HighlightedText.svelte';
import { preview_settings } from '$lib/ts/stores/ui_behavior';
import NumberSettingInput from '$lib/components/NumberSettingInput.svelte';
import { db } from '$lib/ts/database';
const ip_regex =
/^(?:(?:10|127)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)|192\.168\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)|172\.(?:1[6-9]|2\d|3[0-1])\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d))$/;
@@ -45,7 +47,6 @@
snippet: null,
title: '',
title_class: '!text-xl',
closable: true
});
let remove_display_name = $state('');
@@ -93,6 +94,20 @@
}
}
async function change_preview_mode(mode: 'never' | 'normal' | 'always') {
$preview_settings.mode = mode;
if (mode === 'never') {
await db.displays
.toCollection()
.modify({ preview: { currently_updating: false, url: null } });
} else {
const display_ids = (await db.displays.toArray()).map((d) => d.id);
for (const display_id of display_ids) {
screenshot_loop(display_id);
}
}
}
function popup_close_function() {
popup_content.open = false;
}
@@ -102,11 +117,10 @@
popup_content = {
open: true,
snippet: display_popup,
title: 'Neuen Bildschirm hinzufügen',
title: 'Neuen Bildschirm Hinzufügen',
title_icon: Monitor,
title_class: '!text-xl',
window_class: 'w-3xl',
closable: true
};
};
@@ -118,7 +132,6 @@
title_icon: Settings,
title_class: '!text-xl',
window_class: 'w-3xl',
closable: true
};
};
@@ -131,7 +144,6 @@
title: 'Bildschirm wirklich löschen?',
title_class: 'text-red-400 !text-xl',
title_icon: Trash2,
closable: true
};
};
@@ -150,7 +162,6 @@
title: 'Bildschirm bearbeiten',
title_icon: Monitor,
title_class: '!text-xl',
closable: true
};
};
@@ -163,7 +174,6 @@
title: 'Über PLG MuDiCS',
title_icon: Info,
title_class: '!text-xl',
closable: true
};
};
</script>
@@ -332,9 +342,7 @@
menu_options={(['never', 'normal', 'always'] as const).map((mode) => ({
icon: mode === $preview_settings.mode ? SquareCheckBig : Square,
name: get_display_preview_mode(mode),
on_select: () => {
$preview_settings.mode = mode;
}
on_select: async () => await change_preview_mode(mode)
}))}>{get_display_preview_mode($preview_settings.mode)} <ChevronDown /></Button
>
</div>
@@ -374,7 +382,7 @@
menu_options={[
{
icon: Plus,
name: 'Neuen Bildschirm hinzufügen',
name: 'Neuen Bildschirm Hinzufügen',
on_select: show_new_display_popup
},
{
+68 -64
View File
@@ -23,7 +23,12 @@
startup,
show_html
} from '$lib/ts/api_handler';
import { get_display_by_id, run_on_all_selected_displays } from '$lib/ts/stores/displays';
import {
get_display_by_id,
no_active_display_selected,
online_displays,
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';
@@ -40,9 +45,10 @@
open: false,
snippet: null,
title: '',
closable: true
});
let current_text = $state('');
function popup_close_function() {
popup_content.open = false;
}
@@ -51,9 +57,9 @@
popup_content = {
open: true,
snippet: send_keys_popup,
title: 'Tastatur-Eingaben durchgeben',
title: 'Tastatur-Eingaben Senden',
title_icon: Keyboard,
closable: true
window_class: 'h-full'
};
};
@@ -61,9 +67,8 @@
popup_content = {
open: true,
snippet: text_popup,
title: 'Text anzeigen',
title: 'Text Anzeigen',
title_icon: TextAlignStart,
closable: true,
window_class: 'size-full'
};
};
@@ -72,10 +77,9 @@
popup_content = {
open: true,
snippet: website_popup,
title: 'Webseite anzeigen',
title: 'Webseite Anzeigen',
window_class: 'w-xl',
title_icon: Globe,
closable: true
};
};
@@ -93,13 +97,12 @@
}
}
async function ask_shutdonw() {
async function ask_shutdown() {
popup_content = {
open: true,
snippet: ask_shutdonw_popup,
title: 'PC Herunterfahren',
snippet: ask_shutdown_popup,
title: 'Bildschirm Herunterfahren',
title_icon: PowerOff,
closable: true
};
}
@@ -107,7 +110,7 @@
popup_content.open = false;
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' });
db.displays.update(d.id, { status: 'app_offline', preview: { currently_updating: false, url: null} });
}, false);
}
@@ -123,24 +126,15 @@
);
}
async function send_single_key_press(key: string) {
await run_on_all_selected_displays((d) =>
send_keyboard_input(d.ip, [{ key, action: 'press' }])
);
setTimeout(
async () =>
await run_on_all_selected_displays((d) =>
send_keyboard_input(d.ip, [{ key, action: 'release' }])
),
10
);
async function send_single_key_press(key: string, action: 'press' | 'release') {
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, [{ key, action }]));
}
let website_url = $state('');
let website_url_valid = $state(false);
function validate_website_url(url: string): [boolean, string] {
if (url === '') return [true, ''];
const regex = /^https?:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/;
const regex = /^https?:\/\/[\w\-]+(\.[\w\-]+)+([\w\-\._~:/?#\[\]@!$&'\(\)\*\+,;=.])*/;
if (regex.test(url)) {
return [true, ''];
}
@@ -152,14 +146,13 @@
await run_on_all_selected_displays((d) =>
show_html(d.ip, `<iframe src="${website_url}"></iframe>`)
);
website_url = '';
}
</script>
{#snippet website_popup()}
<div class="flex flex-col gap-2">
<TextInput
title="URL"
title="URL (mit http:// oder https://)"
placeholder="https://example.com"
bind:current_value={website_url}
bind:current_valid={website_url_valid}
@@ -180,7 +173,7 @@
</div>
{/snippet}
{#snippet ask_shutdonw_popup()}
{#snippet ask_shutdown_popup()}
<p>Bist du sicher, dass du alle ausgewählten Displays herunterfahren möchtest?</p>
<div class="flex flex-row justify-end gap-2">
@@ -192,61 +185,70 @@
{/snippet}
{#snippet send_keys_popup()}
<div class="overflow-hidden flex flex-col gap-2">
<div>
<KeyInput />
</div>
<div class="flex flex-row justify-end gap-2">
<Button className="px-4 font-bold" click_function={popup_close_function}>Fertig</Button>
</div>
</div>
<KeyInput {popup_close_function}/>
{/snippet}
{#snippet text_popup()}
<TipTapInput />
<TipTapInput bind:text={current_text}/>
{/snippet}
<div class="grid grid-rows-[2.5rem_auto] bg-stone-800 rounded-2xl min-w-0">
<div class="text-xl font-bold pl-3 content-center bg-stone-700 rounded-t-2xl truncate min-w-0">
Bildschirme steuern
Bildschirme Steuern
</div>
<div class="relative flex flex-col gap-2 p-2 overflow-auto">
<div class="flex flex-row justify-between gap-2">
<div class="flex flex-col gap-2">
<div class="flex flex-row gap-2 w-75 justify-normal">
<Button
title="Vorherige Folie (Pfeil nach Links)"
className="px-9"
<button
title="Vorherige Folie (Pfeil nach Links) [gedrückt halten möglich]"
class="px-9 bg-stone-700 {$selected_display_ids.length === 0
? 'text-stone-500 cursor-not-allowed'
: 'hover:bg-stone-600 active:bg-stone-500 cursor-pointer'} py-2 rounded-xl flex justify-center items-center transition-colors duration-200"
disabled={$selected_display_ids.length === 0}
click_function={async () => {
await send_single_key_press('VK_LEFT');
}}><ArrowBigLeft /></Button
onmousedown={async () => {
await send_single_key_press('ArrowLeft', 'press');
}}
onmouseup={async () => {
await send_single_key_press('ArrowLeft', 'release');
}}
>
<Button
title="Nächste Folie (Pfeil nach Rechts)"
className="px-9"
<ArrowBigLeft />
</button>
<button
title="Vorherige Folie (Pfeil nach Links) [gedrückt halten möglich]"
class="px-9 bg-stone-700 {$selected_display_ids.length === 0
? 'text-stone-500 cursor-not-allowed'
: 'hover:bg-stone-600 active:bg-stone-500 cursor-pointer'} py-2 rounded-xl flex justify-center items-center transition-colors duration-200"
disabled={$selected_display_ids.length === 0}
click_function={async () => {
await send_single_key_press('VK_RIGHT');
}}><ArrowBigRight /></Button
onmousedown={async () => {
await send_single_key_press('ArrowRight', 'press');
}}
onmouseup={async () => {
await send_single_key_press('ArrowRight', 'release');
}}
>
<ArrowBigRight />
</button>
</div>
<Button
className="px-3 flex gap-3 w-75 justify-normal"
disabled={$selected_display_ids.length === 0}
click_function={show_text_popup}><TextAlignStart /> Text anzeigen</Button
click_function={show_text_popup}
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
><TextAlignStart /> Text Anzeigen</Button
>
<Button
className="px-3 flex gap-3 w-75 justify-normal"
disabled={$selected_display_ids.length === 0}
click_function={show_website_popup}><Globe /> Webseite anzeigen</Button
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
click_function={show_website_popup}><Globe /> Webseite Anzeigen</Button
>
<Button
className="px-3 flex gap-3 w-75 justify-normal"
disabled={$selected_display_ids.length === 0}
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
click_function={async () => {
await run_on_all_selected_displays((d) => show_blackscreen(d.ip));
}}><Presentation />Blackout</Button
@@ -254,38 +256,40 @@
<div class="flex flex-row justify-normal">
<Button className="rounded-r-none pl-3 flex gap-3 grow w-65 justify-normal" disabled>
<TrafficCone /> Fallback-Bild anzeigen
<TrafficCone /> Fallback-Bild Anzeigen
</Button>
<Button className="rounded-l-none flex grow-0 w-10" disabled><ChevronDown /></Button>
</div>
<Button
className="px-3 flex gap-3 w-75 justify-normal"
disabled={$selected_display_ids.length === 0}
click_function={show_send_keys_popup}><Keyboard /> Tastatur-Eingaben durchgeben</Button
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
click_function={show_send_keys_popup}><Keyboard /> Tastatur-Eingaben Senden</Button
>
</div>
<div class="flex flex-col gap-2 justify-between">
<div class="flex flex-col gap-2">
<Button
className="px-3 flex gap-3 w-full xl:w-75 justify-normal"
disabled={$all_display_states === 'on' || $selected_display_ids.length === 0}
disabled={$all_display_states === 'on' ||
no_active_display_selected($selected_display_ids, $online_displays)}
click_function={startup_action}
>
<Power /> PC hochfahren
<Power /> Bildschirm Hochfahren
</Button>
<Button
className="px-3 flex gap-3 w-full xl:w-75 justify-normal"
disabled={$all_display_states === 'off' || $selected_display_ids.length === 0}
click_function={ask_shutdonw}
disabled={$all_display_states === 'off' ||
no_active_display_selected($selected_display_ids, $online_displays)}
click_function={ask_shutdown}
>
<PowerOff /> PC herunterfahren</Button
<PowerOff /> Bildschirm Herunterfahren</Button
>
</div>
<Button className="px-3 flex gap-3 w-full xl:w-75 justify-normal" disabled>
<SquareTerminal />
Shell-Befehl ausführen
Shell-Befehl Ausführen
</Button>
</div>
</div>
@@ -218,7 +218,7 @@
class="min-w-40 px-4 rounded-xl cursor-pointer duration-200 transition-colors bg-stone-600"
onclick={async () => await toggle_all_selected_displays($display_groups)}
>
<span>{$all_groups_selected || false ? 'Alle abwählen' : 'Alle auswählen'}</span>
<span>{$all_groups_selected || false ? 'Alle Abwählen' : 'Alle Auswählen'}</span>
</button>
<div class="flex flex-row">
<Button
+14 -15
View File
@@ -27,7 +27,7 @@
import { slide } from 'svelte/transition';
import InodeElement from '../lib/components/InodeElement.svelte';
import PopUp from '$lib/components/PopUp.svelte';
import { get_file_primary_key, type Inode, type PopupContent } from '$lib/ts/types';
import { get_file_primary_key, is_folder, type Inode, type PopupContent } from '$lib/ts/types';
import TextInput from '$lib/components/TextInput.svelte';
import {
first_letter_is_valid,
@@ -38,6 +38,7 @@
import HighlightedText from '$lib/components/HighlightedText.svelte';
import { liveQuery, type Observable } from 'dexie';
import { download_file, add_upload, add_sync_recursively } from '$lib/ts/file_transfer_handler';
import { no_active_display_selected, online_displays } from '$lib/ts/stores/displays';
let current_name: string = $state('');
let current_valid: boolean = $state(false);
@@ -58,7 +59,9 @@
$effect(() => {
const s = $selected_file_ids;
one_file_selected = liveQuery(async () => {
return s.length === 1 && (await get_file_by_id(s[0]))?.type !== 'inode/directory';
const inode = await get_file_by_id(s[0]);
if (!inode) return false;
return s.length === 1 && is_folder(inode);
});
});
@@ -66,7 +69,6 @@
open: false,
snippet: null,
title: '',
closable: true
});
let file_input: HTMLInputElement;
@@ -110,17 +112,16 @@
const show_edit_file_popup = async () => {
const file = await get_file_by_id($selected_file_ids[0]);
if (!file) return;
const is_folder = file.type === 'inode/directory';
const extension = is_folder ? '' : '.' + file.name.split('.').at(-1) || '';
const file_is_folder = is_folder(file);
const extension = file_is_folder ? '' : '.' + file.name.split('.').at(-1) || '';
current_name = file.name.slice(0, file.name.length - extension.length);
current_valid = true;
popup_content = {
open: true,
snippet: edit_file_name_popup,
title: `${is_folder ? 'Ordner' : 'Datei'} umbenennen`,
title: `${file_is_folder ? 'Ordner' : 'Datei'} umbenennen`,
title_icon: FolderPlus,
snippet_arg: extension,
closable: true
};
};
@@ -135,7 +136,6 @@
snippet: new_folder_popup,
title: 'Neuen Ordner erstellen',
title_icon: FolderPlus,
closable: true
};
};
@@ -145,7 +145,6 @@
snippet: delete_request_popup,
title: `${$selected_file_ids.length} ${$selected_file_ids.length === 1 ? 'Objekt' : 'Objekte'} wirklich löschen?`,
title_icon: Trash2,
closable: true
};
};
@@ -285,7 +284,7 @@
<div class="bg-stone-800 h-full rounded-2xl grid grid-rows-[2.5rem_1fr] min-h-0">
<div class="bg-stone-700 flex justify-between w-full p-1 rounded-t-2xl min-w-0 gap-2">
<span class="text-xl font-bold pl-2 content-center truncate min-w-0">
Dateien anzeigen und verwalten
Dateien Anzeigen und Verwalten
</span>
<div class="flex flex-row">
<Button
@@ -321,7 +320,7 @@
title="Neuen Ordner erstellen (Neuen Ordner mit ausgewählten Objekten erstellen)"
className="px-3 flex"
click_function={show_new_folder_popup}
disabled={$selected_display_ids.length === 0}><FolderPlus /></Button
disabled={no_active_display_selected($selected_display_ids, $online_displays)}><FolderPlus /></Button
>
<div class="border border-stone-700 my-1"></div>
<Button
@@ -330,7 +329,7 @@
click_function={() => {
if (file_input) file_input.click();
}}
disabled={$selected_display_ids.length === 0}><Upload /></Button
disabled={no_active_display_selected($selected_display_ids, $online_displays)}><Upload /></Button
>
<Button
title="Ausgewählte Datei herunterladen"
@@ -349,7 +348,7 @@
$selected_display_ids,
$current_folder_elements ?? []
)}
disabled={$selected_display_ids.length === 0}
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
><RefreshCcw />
<span class="hidden 2xl:flex">Synchronisieren</span>
</Button>
@@ -363,7 +362,7 @@
<Button
title="Ausgewählte Datei(en) einfügen"
className="px-3 flex"
disabled={$selected_display_ids.length === 0}
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
>
<ClipboardPaste />
</Button>
@@ -387,7 +386,7 @@
</div>
<div class="min-h-0 h-full overflow-y-auto overflow-x-hidden bg-stone-750 rounded-xl">
<div class="flex flex-col gap-2 p-2 min-h-0 max-w-full">
{#if $selected_display_ids.length === 0}
{#if no_active_display_selected($selected_display_ids, $online_displays)}
<span class="text-stone-450 px-10 py-6 leading-relaxed text-center">
Es sind keine Bildschirme ausgewählt.
</span>
+127 -63
View File
@@ -1,106 +1,170 @@
<script lang="ts">
import { flip } from 'svelte/animate';
import { get_selectable_color_classes } from '$lib/ts/stores/ui_behavior';
import key_map_json from './../../../../shared/keys.json';
import { fade } from 'svelte/transition';
import { run_on_all_selected_displays } from '$lib/ts/stores/displays';
import { send_keyboard_input } from '$lib/ts/api_handler';
import { ArrowDownToLine, ArrowUpFromLine, Grid2x2, Grid2X2, Option } from 'lucide-svelte';
import Button from '$lib/components/Button.svelte';
import { onDestroy } from 'svelte';
const key_map: Record<string, string> = key_map_json as Record<string, string>;
let {
popup_close_function
}: {
popup_close_function: () => void;
} = $props();
let active = $state(false);
const current_keys: string[] = $state([]);
let last_keys: { id: number; key: string }[] = $state([]);
let seq = 0;
let el: HTMLDivElement;
function add_to_last_keys(name: string) {
const id = Date.now();
last_keys.push({ id, key: name });
const id = ++seq;
// Neueste oben
last_keys = [{ id, key: name }, ...last_keys].slice(0, 6);
setTimeout(() => {
last_keys = last_keys.filter((e) => e.id !== id);
}, 1500);
}
async function on_key(e: KeyboardEvent, key_down: boolean) {
async function on_keyboard_input(e: KeyboardEvent, key_down: boolean) {
if (!active) return;
const id = key_map[e.code];
const id = e.code;
if (!id) return;
if (key_down) {
if (current_keys.includes(e.code)) return;
current_keys.push(e.code);
} else {
const index = current_keys.indexOf(e.code);
if (index === -1) return;
current_keys.splice(index, 1);
}
if (e.repeat) return;
e.preventDefault();
e.stopPropagation();
if (e.repeat) return;
await on_key(id, key_down);
}
async function on_key(key: string, key_down: boolean) {
if (key_down) {
if (current_keys.includes(key)) return;
current_keys.push(key);
} else {
const index = current_keys.indexOf(key);
if (index === -1) return;
current_keys.splice(index, 1);
}
const action: 'press' | 'release' = key_down ? 'press' : 'release';
add_to_last_keys(action.toUpperCase() + ' ' + e.code);
await run_on_all_selected_displays(
(d) => send_keyboard_input(d.ip, [{ key: id, action }]),
true
);
add_to_last_keys(action.toUpperCase() + ' ' + key);
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, [{ key, action }]), true);
}
async function release_all_pressed_keys() {
const inputs: {key: string; action: 'press' | 'release' }[] = [];
const inputs: { key: string; action: 'press' | 'release' }[] = [];
for (let i = current_keys.length - 1; i >= 0; i--) {
inputs.push({key: current_keys[i], action: 'release'})
inputs.push({ key: current_keys[i], action: 'release' });
current_keys.splice(i, 1);
}
await run_on_all_selected_displays(
(d) => send_keyboard_input(d.ip, inputs),
true
);
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, inputs), true);
}
onDestroy(() => {
release_all_pressed_keys();
});
</script>
<div
role="textbox"
tabindex="0"
bind:this={el}
onclick={() => {
if (active) {
el.blur();
} else {
el.focus();
active = true;
}
}}
onblur={async () => {
active = false;
await release_all_pressed_keys();
}}
onkeydown={(e) => on_key(e, true)}
onkeyup={(e) => on_key(e, false)}
class="relative flex justify-center items-center h-15 w-full cursor-pointer rounded-xl transition-colors duration-200 select-none {get_selectable_color_classes(
active,
{
bg: true,
hover: true,
active: true,
text: true
}
)}"
>
{active ? 'Erfassung aktiv' : 'Hier für Erfassung klicken'}
<div class="absolute top-full left-0 ml-1 mt-0.5 flex flex-col-reverse text-sm text-stone-400">
{#each last_keys as key (key.id)}
<div class="flex flex-row gap-2 overflow-hidden h-full">
<div
role="textbox"
tabindex="0"
bind:this={el}
onclick={() => {
if (active) {
el.blur();
} else {
el.focus();
active = true;
}
}}
onblur={async () => {
active = false;
await release_all_pressed_keys();
}}
onkeydown={(e) => on_keyboard_input(e, true)}
onkeyup={(e) => on_keyboard_input(e, false)}
class="flex justify-center items-center text-center grow py-2 px-8 w-70 h-full cursor-pointer rounded-xl transition-colors duration-200 select-none {get_selectable_color_classes(
active,
{
bg: true,
hover: true,
active: true,
text: true
}
)}"
>
{active ? 'Erfassung aktiv' : 'Hier für Erfassung klicken'}
</div>
<div
class="relative flex flex-col gap-1 text-sm w-40 p-2 bg-stone-750 rounded-xl overflow-hidden h-full"
>
{#each last_keys as item (item.id)}
<span
animate:flip={{ duration: 200 }}
in:fade={{ duration: 200 }}
out:fade={{ duration: 500 }}>{key.key}</span
class="flex flex-row gap-2 {item.key.split(' ')[0] === 'PRESS'
? 'text-sky-600'
: 'text-lime-600'}"
animate:flip={{ duration: 120 }}
in:fade={{ duration: 120 }}
out:fade={{ duration: 200 }}
>
{#if item.key.split(' ')[0] === 'PRESS'}
<ArrowDownToLine />
{:else}
<ArrowUpFromLine />
{/if}
{item.key.split(' ').at(-1)}
</span>
{/each}
<div
class="absolute bottom-0 right-0 left-0 h-5 bg-linear-to-b from-transparent to-stone-750"
></div>
</div>
<div class="flex flex-col gap-2 justify-between">
<div class="flex flex-col gap-2">
<button
title="Windows-/Meta-Taste [gedrückt halten möglich]"
class="px-3 bg-stone-700 py-2 gap-2 rounded-xl flex items-center transition-colors duration-200 hover:bg-stone-600 active:bg-stone-500 cursor-pointer"
onmousedown={async (e) => {
e.preventDefault();
await on_key('MetaLeft', true);
}}
onmouseup={async () => {
await on_key('MetaLeft', false);
}}
>
<Grid2x2 /> Meta
</button>
<button
title="Alt-Taste [gedrückt halten möglich]"
class="px-3 bg-stone-700 py-2 gap-2 rounded-xl flex items-center transition-colors duration-200 hover:bg-stone-600 active:bg-stone-500 cursor-pointer"
onmousedown={async (e) => {
e.preventDefault();
await on_key('AltLeft', true);
}}
onmouseup={async () => {
await on_key('AltLeft', false);
}}
>
<Option /> Alt
</button>
</div>
<Button
div_class="mt-2 justify-end"
className="px-4 font-bold"
click_function={popup_close_function}>Fertig</Button
>
</div>
</div>
+10 -2
View File
@@ -20,6 +20,12 @@
import { Color } from '@tiptap/extension-text-style';
import Highlight from '@tiptap/extension-highlight';
let {
text = $bindable()
}: {
text: string;
} = $props();
type TextEditOption = {
onclick: () => void;
is_selected: () => boolean;
@@ -128,15 +134,17 @@
multicolor: true
})
],
content: '',
content: text,
onTransaction: ({ editor }) => {
// Increment the state signal to force a re-render
editor_state = { editor };
},
autofocus: true
});
editor_state.editor.commands.selectAll();
});
onDestroy(() => {
if (editor_state.editor) text = editor_state.editor.getHTML();
editor_state.editor?.destroy();
});
</script>
@@ -210,7 +218,7 @@
{/each}
</div>
<Button click_function={show_text} className="w-full font-bold">Text anzeigen</Button>
<Button click_function={show_text} className="w-full font-bold">Text Anzeigen</Button>
</div>
</div>
+2 -2
View File
@@ -77,13 +77,13 @@ func pingRoute(ctx echo.Context) error {
return ctx.JSON(http.StatusBadRequest, PingResponse{Error: "missing 'ip' query parameter"})
}
cmd := exec.Command("ping", "-c", "1", "-w", "1", ip)
cmd := exec.Command("ping", "-c", "1", "-w", "5", ip)
result := shared.RunShellCommand(cmd)
if result.ExitCode != 0 {
return ctx.JSON(http.StatusOK, PingResponse{Status: "host_offline"})
}
conn, err := net.DialTimeout("tcp", ip+":1323", 1*time.Second)
conn, err := net.DialTimeout("tcp", ip+":1323", 5*time.Second)
if err != nil {
return ctx.JSON(http.StatusOK, PingResponse{Status: "app_offline"})
}
+178
View File
@@ -0,0 +1,178 @@
package pkg
import (
"fmt"
"log/slog"
"time"
"github.com/micmonay/keybd_event"
)
type KeyAction int
const (
KeyPress KeyAction = iota
KeyRelease
)
type Input struct {
Key string
Action KeyAction
}
func KeyboardInput(inputs []Input) error {
var err error
kb, err := keybd_event.NewKeyBonding()
if err != nil {
return fmt.Errorf("failed to create key bonding: %w", err)
}
for _, input := range inputs {
switch input.Key {
case "Shift", "ShiftLeft", "ShiftRight":
kb.HasSHIFT(true)
case "Ctrl", "Control", "ControlLeft", "ControlRight":
kb.HasCTRL(true)
case "Alt", "AltLeft", "AltRight":
kb.HasALT(true)
case "Super", "Meta", "MetaLeft", "MetaRight":
kb.HasSuper(true)
default:
keyCode, ok := KeyboardEvents[input.Key]
if !ok {
slog.Warn("Could not parse keyboard input", "key", input.Key)
continue
}
kb.SetKeys(keyCode)
}
switch input.Action {
case KeyPress:
err = kb.Press()
case KeyRelease:
err = kb.Release()
}
if err != nil {
return fmt.Errorf("failed to run key event: %w", err)
}
time.Sleep(time.Microsecond * 10)
}
return nil
}
var KeyboardEvents = map[string]int{
"Escape": keybd_event.VK_ESC,
"Digit1": keybd_event.VK_1,
"Digit2": keybd_event.VK_2,
"Digit3": keybd_event.VK_3,
"Digit4": keybd_event.VK_4,
"Digit5": keybd_event.VK_5,
"Digit6": keybd_event.VK_6,
"Digit7": keybd_event.VK_7,
"Digit8": keybd_event.VK_8,
"Digit9": keybd_event.VK_9,
"Digit0": keybd_event.VK_0,
"KeyQ": keybd_event.VK_Q,
"KeyW": keybd_event.VK_W,
"KeyE": keybd_event.VK_E,
"KeyR": keybd_event.VK_R,
"KeyT": keybd_event.VK_T,
"KeyY": keybd_event.VK_Y,
"KeyU": keybd_event.VK_U,
"KeyI": keybd_event.VK_I,
"KeyO": keybd_event.VK_O,
"KeyP": keybd_event.VK_P,
"KeyA": keybd_event.VK_A,
"KeyS": keybd_event.VK_S,
"KeyD": keybd_event.VK_D,
"KeyF": keybd_event.VK_F,
"KeyG": keybd_event.VK_G,
"KeyH": keybd_event.VK_H,
"KeyJ": keybd_event.VK_J,
"KeyK": keybd_event.VK_K,
"KeyL": keybd_event.VK_L,
"KeyZ": keybd_event.VK_Z,
"KeyX": keybd_event.VK_X,
"KeyC": keybd_event.VK_C,
"KeyV": keybd_event.VK_V,
"KeyB": keybd_event.VK_B,
"KeyN": keybd_event.VK_N,
"KeyM": keybd_event.VK_M,
"F1": keybd_event.VK_F1,
"F2": keybd_event.VK_F2,
"F3": keybd_event.VK_F3,
"F4": keybd_event.VK_F4,
"F5": keybd_event.VK_F5,
"F6": keybd_event.VK_F6,
"F7": keybd_event.VK_F7,
"F8": keybd_event.VK_F8,
"F9": keybd_event.VK_F9,
"F10": keybd_event.VK_F10,
"F11": keybd_event.VK_F11,
"F12": keybd_event.VK_F12,
"F13": keybd_event.VK_F13,
"F14": keybd_event.VK_F14,
"F15": keybd_event.VK_F15,
"F16": keybd_event.VK_F16,
"F17": keybd_event.VK_F17,
"F18": keybd_event.VK_F18,
"F19": keybd_event.VK_F19,
"F20": keybd_event.VK_F20,
"F21": keybd_event.VK_F21,
"F22": keybd_event.VK_F22,
"F23": keybd_event.VK_F23,
"F24": keybd_event.VK_F24,
"NumLock": keybd_event.VK_NUMLOCK,
"ScrollLock": keybd_event.VK_SCROLLLOCK,
"CapsLock": keybd_event.VK_CAPSLOCK,
"Minus": keybd_event.VK_SP2,
"Equal": keybd_event.VK_SP3,
"Backspace": keybd_event.VK_BACKSPACE,
"Tab": keybd_event.VK_TAB,
"BracketLeft": keybd_event.VK_SP4,
"BracketRight": keybd_event.VK_SP5,
"Enter": keybd_event.VK_ENTER,
"Semicolon": keybd_event.VK_SP6,
"Quote": keybd_event.VK_SP7,
"Backquote": keybd_event.VK_SP1,
"Backslash": keybd_event.VK_SP8,
"Comma": keybd_event.VK_SP9,
"Period": keybd_event.VK_SP10,
"Slash": keybd_event.VK_SP11,
"IntlBackslash": keybd_event.VK_SP12,
"NumpadMultiply": keybd_event.VK_KPASTERISK,
"NumpadAdd": keybd_event.VK_KPPLUS,
"NumpadSubtract": keybd_event.VK_KPMINUS,
"NumpadDecimal": keybd_event.VK_KPDOT,
"Space": keybd_event.VK_SPACE,
"Numpad0": keybd_event.VK_KP0,
"Numpad1": keybd_event.VK_KP1,
"Numpad2": keybd_event.VK_KP2,
"Numpad3": keybd_event.VK_KP3,
"Numpad4": keybd_event.VK_KP4,
"Numpad5": keybd_event.VK_KP5,
"Numpad6": keybd_event.VK_KP6,
"Numpad7": keybd_event.VK_KP7,
"Numpad8": keybd_event.VK_KP8,
"Numpad9": keybd_event.VK_KP9,
"PageUp": keybd_event.VK_PAGEUP,
"PageDown": keybd_event.VK_PAGEDOWN,
"End": keybd_event.VK_END,
"Home": keybd_event.VK_HOME,
"ArrowLeft": keybd_event.VK_LEFT,
"ArrowUp": keybd_event.VK_UP,
"ArrowRight": keybd_event.VK_RIGHT,
"ArrowDown": keybd_event.VK_DOWN,
"PrintScreen": keybd_event.VK_PRINT,
"Insert": keybd_event.VK_INSERT,
"Delete": keybd_event.VK_DELETE,
"Help": keybd_event.VK_HELP,
"BrowserBack": keybd_event.VK_BACK,
"Pause": keybd_event.VK_PAUSE,
"Lang1": keybd_event.VK_HANGUEL,
"Lang2": keybd_event.VK_HANJA,
}
-129
View File
@@ -1,129 +0,0 @@
package pkg
import "github.com/micmonay/keybd_event"
var KeyboardEvents = map[string]int{
"VK_SP1": keybd_event.VK_SP1,
"VK_SP2": keybd_event.VK_SP2,
"VK_SP3": keybd_event.VK_SP3,
"VK_SP4": keybd_event.VK_SP4,
"VK_SP5": keybd_event.VK_SP5,
"VK_SP6": keybd_event.VK_SP6,
"VK_SP7": keybd_event.VK_SP7,
"VK_SP8": keybd_event.VK_SP8,
"VK_SP9": keybd_event.VK_SP9,
"VK_SP10": keybd_event.VK_SP10,
"VK_SP11": keybd_event.VK_SP11,
"VK_SP12": keybd_event.VK_SP12,
"VK_ESC": keybd_event.VK_ESC,
"VK_1": keybd_event.VK_1,
"VK_2": keybd_event.VK_2,
"VK_3": keybd_event.VK_3,
"VK_4": keybd_event.VK_4,
"VK_5": keybd_event.VK_5,
"VK_6": keybd_event.VK_6,
"VK_7": keybd_event.VK_7,
"VK_8": keybd_event.VK_8,
"VK_9": keybd_event.VK_9,
"VK_0": keybd_event.VK_0,
"VK_Q": keybd_event.VK_Q,
"VK_W": keybd_event.VK_W,
"VK_E": keybd_event.VK_E,
"VK_R": keybd_event.VK_R,
"VK_T": keybd_event.VK_T,
"VK_Y": keybd_event.VK_Y,
"VK_U": keybd_event.VK_U,
"VK_I": keybd_event.VK_I,
"VK_O": keybd_event.VK_O,
"VK_P": keybd_event.VK_P,
"VK_A": keybd_event.VK_A,
"VK_S": keybd_event.VK_S,
"VK_D": keybd_event.VK_D,
"VK_F": keybd_event.VK_F,
"VK_G": keybd_event.VK_G,
"VK_H": keybd_event.VK_H,
"VK_J": keybd_event.VK_J,
"VK_K": keybd_event.VK_K,
"VK_L": keybd_event.VK_L,
"VK_Z": keybd_event.VK_Z,
"VK_X": keybd_event.VK_X,
"VK_C": keybd_event.VK_C,
"VK_V": keybd_event.VK_V,
"VK_B": keybd_event.VK_B,
"VK_N": keybd_event.VK_N,
"VK_M": keybd_event.VK_M,
"VK_F1": keybd_event.VK_F1,
"VK_F2": keybd_event.VK_F2,
"VK_F3": keybd_event.VK_F3,
"VK_F4": keybd_event.VK_F4,
"VK_F5": keybd_event.VK_F5,
"VK_F6": keybd_event.VK_F6,
"VK_F7": keybd_event.VK_F7,
"VK_F8": keybd_event.VK_F8,
"VK_F9": keybd_event.VK_F9,
"VK_F10": keybd_event.VK_F10,
"VK_F11": keybd_event.VK_F11,
"VK_F12": keybd_event.VK_F12,
"VK_F13": keybd_event.VK_F13,
"VK_F14": keybd_event.VK_F14,
"VK_F15": keybd_event.VK_F15,
"VK_F16": keybd_event.VK_F16,
"VK_F17": keybd_event.VK_F17,
"VK_F18": keybd_event.VK_F18,
"VK_F19": keybd_event.VK_F19,
"VK_F20": keybd_event.VK_F20,
"VK_F21": keybd_event.VK_F21,
"VK_F22": keybd_event.VK_F22,
"VK_F23": keybd_event.VK_F23,
"VK_F24": keybd_event.VK_F24,
"VK_NUMLOCK": keybd_event.VK_NUMLOCK,
"VK_SCROLLLOCK": keybd_event.VK_SCROLLLOCK,
"VK_RESERVED": keybd_event.VK_RESERVED,
"VK_MINUS": keybd_event.VK_MINUS,
"VK_EQUAL": keybd_event.VK_EQUAL,
"VK_BACKSPACE": keybd_event.VK_BACKSPACE,
"VK_TAB": keybd_event.VK_TAB,
"VK_LEFTBRACE": keybd_event.VK_LEFTBRACE,
"VK_RIGHTBRACE": keybd_event.VK_RIGHTBRACE,
"VK_ENTER": keybd_event.VK_ENTER,
"VK_SEMICOLON": keybd_event.VK_SEMICOLON,
"VK_APOSTROPHE": keybd_event.VK_APOSTROPHE,
"VK_GRAVE": keybd_event.VK_GRAVE,
"VK_BACKSLASH": keybd_event.VK_BACKSLASH,
"VK_COMMA": keybd_event.VK_COMMA,
"VK_DOT": keybd_event.VK_DOT,
"VK_SLASH": keybd_event.VK_SLASH,
"VK_KPASTERISK": keybd_event.VK_KPASTERISK,
"VK_SPACE": keybd_event.VK_SPACE,
"VK_CAPSLOCK": keybd_event.VK_CAPSLOCK,
"VK_KP0": keybd_event.VK_KP0,
"VK_KP1": keybd_event.VK_KP1,
"VK_KP2": keybd_event.VK_KP2,
"VK_KP3": keybd_event.VK_KP3,
"VK_KP4": keybd_event.VK_KP4,
"VK_KP5": keybd_event.VK_KP5,
"VK_KP6": keybd_event.VK_KP6,
"VK_KP7": keybd_event.VK_KP7,
"VK_KP8": keybd_event.VK_KP8,
"VK_KP9": keybd_event.VK_KP9,
"VK_KPMINUS": keybd_event.VK_KPMINUS,
"VK_KPPLUS": keybd_event.VK_KPPLUS,
"VK_KPDOT": keybd_event.VK_KPDOT,
"VK_CANCEL": keybd_event.VK_CANCEL,
"VK_BACK": keybd_event.VK_BACK,
"VK_PAUSE": keybd_event.VK_PAUSE,
"VK_HANGUEL": keybd_event.VK_HANGUEL,
"VK_HANJA": keybd_event.VK_HANJA,
"VK_PAGEUP": keybd_event.VK_PAGEUP,
"VK_PAGEDOWN": keybd_event.VK_PAGEDOWN,
"VK_END": keybd_event.VK_END,
"VK_HOME": keybd_event.VK_HOME,
"VK_LEFT": keybd_event.VK_LEFT,
"VK_UP": keybd_event.VK_UP,
"VK_RIGHT": keybd_event.VK_RIGHT,
"VK_DOWN": keybd_event.VK_DOWN,
"VK_PRINT": keybd_event.VK_PRINT,
"VK_INSERT": keybd_event.VK_INSERT,
"VK_DELETE": keybd_event.VK_DELETE,
"VK_HELP": keybd_event.VK_HELP,
}
-42
View File
@@ -11,8 +11,6 @@ import (
"time"
"plg-mudics/shared"
"github.com/micmonay/keybd_event"
)
func GetDeviceIp() (string, error) {
@@ -46,46 +44,6 @@ func GetDeviceMac() (string, error) {
return "", fmt.Errorf("no suitable MAC address found")
}
type KeyAction int
const (
KeyPress KeyAction = iota
KeyRelease
)
type Input struct {
Key int
Action KeyAction
}
func KeyboardInput(inputs []Input) error {
var err error
kb, err := keybd_event.NewKeyBonding()
if err != nil {
return fmt.Errorf("failed to create key bonding: %w", err)
}
for _, input := range inputs {
kb.SetKeys(input.Key)
switch input.Action {
case KeyPress:
err = kb.Press()
case KeyRelease:
err = kb.Release()
}
if err != nil {
return fmt.Errorf("failed to run key event: %w", err)
}
time.Sleep(time.Microsecond * 100)
}
return nil
}
func TakeScreenshot() (string, error) {
tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix()))
+1 -7
View File
@@ -216,12 +216,6 @@ func keyboardInputRoute(ctx echo.Context) error {
return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: fmt.Sprintf("Invalid action: %s", input.Action)})
}
code, ok := pkg.KeyboardEvents[input.Key]
if !ok {
slog.Error("Unsupported key", "key", input.Key)
return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: fmt.Sprintf("Unsupported key: %s", input.Key)})
}
var action pkg.KeyAction
if input.Action == "press" {
action = pkg.KeyPress
@@ -231,7 +225,7 @@ func keyboardInputRoute(ctx echo.Context) error {
}
inputs = append(inputs, pkg.Input{
Key: code,
Key: input.Key,
Action: action,
})
}
-114
View File
@@ -1,114 +0,0 @@
{
"Escape": "VK_ESC",
"Digit1": "VK_1",
"Digit2": "VK_2",
"Digit3": "VK_3",
"Digit4": "VK_4",
"Digit5": "VK_5",
"Digit6": "VK_6",
"Digit7": "VK_7",
"Digit8": "VK_8",
"Digit9": "VK_9",
"Digit0": "VK_0",
"KeyQ": "VK_Q",
"KeyW": "VK_W",
"KeyE": "VK_E",
"KeyR": "VK_R",
"KeyT": "VK_T",
"KeyY": "VK_Y",
"KeyU": "VK_U",
"KeyI": "VK_I",
"KeyO": "VK_O",
"KeyP": "VK_P",
"KeyA": "VK_A",
"KeyS": "VK_S",
"KeyD": "VK_D",
"KeyF": "VK_F",
"KeyG": "VK_G",
"KeyH": "VK_H",
"KeyJ": "VK_J",
"KeyK": "VK_K",
"KeyL": "VK_L",
"KeyZ": "VK_Z",
"KeyX": "VK_X",
"KeyC": "VK_C",
"KeyV": "VK_V",
"KeyB": "VK_B",
"KeyN": "VK_N",
"KeyM": "VK_M",
"F1": "VK_F1",
"F2": "VK_F2",
"F3": "VK_F3",
"F4": "VK_F4",
"F5": "VK_F5",
"F6": "VK_F6",
"F7": "VK_F7",
"F8": "VK_F8",
"F9": "VK_F9",
"F10": "VK_F10",
"F11": "VK_F11",
"F12": "VK_F12",
"F13": "VK_F13",
"F14": "VK_F14",
"F15": "VK_F15",
"F16": "VK_F16",
"F17": "VK_F17",
"F18": "VK_F18",
"F19": "VK_F19",
"F20": "VK_F20",
"F21": "VK_F21",
"F22": "VK_F22",
"F23": "VK_F23",
"F24": "VK_F24",
"NumLock": "VK_NUMLOCK",
"ScrollLock": "VK_SCROLLLOCK",
"CapsLock": "VK_CAPSLOCK",
"Minus": "VK_SP2",
"Equal": "VK_SP3",
"Backspace": "VK_BACKSPACE",
"Tab": "VK_TAB",
"BracketLeft": "VK_SP4",
"BracketRight": "VK_SP5",
"Enter": "VK_ENTER",
"Semicolon": "VK_SP6",
"Quote": "VK_SP7",
"Backquote": "VK_SP1",
"Backslash": "VK_SP8",
"Comma": "VK_SP9",
"Period": "VK_SP10",
"Slash": "VK_SP11",
"IntlBackslash": "VK_SP12",
"NumpadMultiply": "VK_KPASTERISK",
"NumpadDivide": "VK_KPSLASH",
"NumpadAdd": "VK_KPPLUS",
"NumpadSubtract": "VK_KPMINUS",
"NumpadDecimal": "VK_KPDOT",
"NumpadEnter": "VK_KPENTER",
"Space": "VK_SPACE",
"Numpad0": "VK_KP0",
"Numpad1": "VK_KP1",
"Numpad2": "VK_KP2",
"Numpad3": "VK_KP3",
"Numpad4": "VK_KP4",
"Numpad5": "VK_KP5",
"Numpad6": "VK_KP6",
"Numpad7": "VK_KP7",
"Numpad8": "VK_KP8",
"Numpad9": "VK_KP9",
"PageUp": "VK_PAGEUP",
"PageDown": "VK_PAGEDOWN",
"End": "VK_END",
"Home": "VK_HOME",
"ArrowLeft": "VK_LEFT",
"ArrowUp": "VK_UP",
"ArrowRight": "VK_RIGHT",
"ArrowDown": "VK_DOWN",
"PrintScreen": "VK_PRINT",
"Insert": "VK_INSERT",
"Delete": "VK_DELETE",
"Help": "VK_HELP",
"BrowserBack": "VK_BACK",
"Pause": "VK_PAUSE",
"Lang1": "VK_HANGUEL",
"Lang2": "VK_HANJA"
}
-1
View File
@@ -24,7 +24,6 @@ func OpenBrowserWindow(url string, fullscreen bool, profile string) error {
fmt.Sprintf("--app=%s", url),
"--autoplay-policy=no-user-gesture-required",
fmt.Sprintf("--user-data-dir=%s", browserProfileDirPath),
"--disable-web-security",
"--allow-running-insecure-content",
"--disable-features=XFrameOptions",
}
+1 -1
View File
@@ -1 +1 @@
v0.0.15
v0.0.17