Compare commits

...

91 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
2mal3 346e511bb4 bump to version v0.0.15 2026-01-18 18:01:11 +01:00
2mal3 54e10b98e2 feat: show website button (#15) 2026-01-18 18:00:19 +01:00
E44 83eaf34475 chore(control): add settings with screenshot preview settings 2026-01-18 17:34:57 +01:00
2mal3 b251e8951f deps(control): update package-lock to follow package.json 2026-01-18 15:42:02 +01:00
2mal3 31cb614958 feat(control): about section 2026-01-18 15:38:29 +01:00
E44 8fb9f5b9db refactor(api_handler): better return types, formatting 2026-01-18 13:28:10 +01:00
E44 d13fd347ac chore(control): change visual error structure in api_handler 2026-01-18 13:20:52 +01:00
E44 922b47bd1e chore(control): improve app startup and display status ping behavior 2026-01-18 13:17:53 +01:00
E44 b57ea762bf fix(control): limit loading bar to 100% size 2026-01-18 12:29:06 +01:00
E44 c171706d96 fix(control): improve visual feedback of sync (still not finished) 2026-01-18 12:25:43 +01:00
E44 6d5aa9041f chore(control): add backend of sync, visuals still buggy 2026-01-18 11:59:14 +01:00
E44 c2d9a2b049 refactor(control): create gloabel type CompleteFileLoadingData 2026-01-18 11:58:28 +01:00
E44 f84a7c0520 refactor(control): rename get_current_folder_elements to get_folder_elements 2026-01-18 11:57:26 +01:00
E44 7f6891ecff chore(control): change create_folder api to create_path 2026-01-18 11:55:51 +01:00
2mal3 d63fc5cac4 fix: couldn't open control & display at the same time 2026-01-18 00:34:02 +01:00
E44 12f4ec7d6c refactor(control): improve structure in api_handler 2026-01-17 16:34:49 +01:00
2mal3 86f23077ea refactor(nixos): rename update.sh to update.nu 2026-01-17 15:17:46 +01:00
2mal3 47d462ba76 fix(nixos): wol broken 2026-01-17 15:17:12 +01:00
E44 5533696aad fix(control): rename function remove_file_from_display_recusively 2026-01-17 15:12:59 +01:00
2mal3 ac68939abd fix(control): glitchy add display popup 2026-01-17 13:18:02 +01:00
2mal3 d6bafd4e6f style(control): tailwind.config.js 2026-01-17 13:18:02 +01:00
E44 ce28a1f771 fix(control): delete files now recursively 2026-01-17 13:10:44 +01:00
E44 7632229704 fix(control): add path creation before uploading 2026-01-17 13:10:12 +01:00
2mal3 b5e997e675 chore(control): remove qr-code button for now 2026-01-17 12:56:59 +01:00
2mal3 ca08d6fb6a chore(control): remove "Weitere Einstellungen" for now 2026-01-17 12:51:12 +01:00
2mal3 4ab8f43295 fix(control): doesn't remember added displays 2026-01-17 12:50:12 +01:00
2mal3 fc59b576b5 bump to version v0.0.13 2026-01-15 15:18:48 +01:00
2mal3 e2a9558d3f fix(control): sometimes could not start browser 2026-01-15 15:16:02 +01:00
2mal3 662bcb3b8d deps(frontend): update 2026-01-15 15:04:27 +01:00
2mal3 9044262ab6 deps: update insecure go packages 2026-01-15 14:56:36 +01:00
E44 6c654e295c refactor(control): remove unnecessary comments and logs 2026-01-14 22:48:57 +01:00
E44 a2bbf19fee fix(control): Drag and Drop in DisplayView is now better 2026-01-14 22:48:02 +01:00
E44 246549acdf fix(control): folders could only be created in path '/' 2026-01-14 19:25:21 +01:00
E44 80cee15576 fix(control): handle_enter wasn't connected to valid_state 2026-01-14 19:06:38 +01:00
E44 1c59b40971 fix(control): startup and shutdown buttons were not reactive and flickered 2026-01-14 19:00:19 +01:00
E44 548f8ccba8 refactor(control): better indentation in ui_behavior 2026-01-14 18:48:57 +01:00
E44 5b93250e22 fix(control): Drag and Drop in DisplayView was completely buggy, now its just a little bit buggy 2026-01-14 18:48:10 +01:00
2mal3 5ca2487598 fix: wrong version number 2026-01-13 23:21:21 +01:00
2mal3 464422ec51 chore(nixos): remove rustdesk again because problems 2026-01-13 23:01:00 +01:00
2mal3 128bbb4ca2 bump to version v0.0.11 2026-01-13 20:03:49 +01:00
E44 8686a1cb47 fix(control): wrong scrollbar behavior in FileView while upload_finish_animation 2026-01-12 20:04:50 +01:00
E44 d3f8a0134b fix(control): wrong scrollbar behavior in notifications 2026-01-12 20:03:59 +01:00
E44 ea2f063991 fix(control): uploaded files never finished animation 2026-01-12 19:56:51 +01:00
E44 9be8a70452 fix: fade out splash-screen in display block directly after receiving command 2026-01-11 17:55:03 +01:00
E44 9ce2c1d8bb fix: bring version-label in splash screen behind bouncing cursor 2026-01-11 17:43:28 +01:00
2mal3 ce8133d59e docs: reference nixpkgs for requirements 2026-01-11 00:12:22 +01:00
E44 b0a57f9c67 chore: singe source of truth for version & show it on splash screen (#7)
Co-authored-by: 2mal3 <56305732+2mal3@users.noreply.github.com>
2026-01-10 20:06:10 +01:00
E44 c64eb345fd fix(display): change title to PLG MuDiCS Display 2026-01-10 19:04:07 +01:00
2mal3 9ed35750c4 fix(nixos): could not open pdf files 2026-01-10 18:43:54 +01:00
2mal3 2b58c8bc69 fix(control): could not shutdown 2026-01-10 18:23:40 +01:00
2mal3 9fdd2c4729 feat(nixos): rustdesk 2026-01-10 18:08:04 +01:00
2mal3 db925e1509 deps(nixos): update to 25.11 2026-01-10 18:07:37 +01:00
2mal3 438c64f055 fix(display): cursor visible 2026-01-10 01:06:29 +01:00
2mal3 6a65ac7e70 chore(control): change settings icon to menu
better describes the purpose
2026-01-10 01:02:17 +01:00
2mal3 74779740f7 chore(control): tell the user why mac address is needed 2026-01-10 00:57:50 +01:00
2mal3 5d868bc1fd refactor(control): move splash screen to layout 2026-01-10 00:52:52 +01:00
2mal3 8b7aabb473 fix(control): slpash screen only shows in dev mode 2026-01-10 00:52:52 +01:00
2mal3 fe5cc22cc0 chore(control/ControlView): disable currently unusable buttons 2026-01-10 00:52:52 +01:00
2mal3 30138ebe04 chore(display): dont hard fail when view reset fails 2026-01-10 00:52:52 +01:00
2mal3 f9c3161cf6 fix(control): hide dev display when not in dev mode 2026-01-10 00:52:52 +01:00
2mal3 0692034344 feat(control): proper website title 2026-01-10 00:52:52 +01:00
2mal3 c175e9d3f8 chore(display/takeScreenshot): remove annoying error log 2026-01-10 00:36:44 +01:00
2mal3 e27cf170ef fix(control): cors failed 2026-01-10 00:35:25 +01:00
2mal3 0d6d3a6012 chore(control): more detailed server error logs 2026-01-10 00:34:24 +01:00
2mal3 426ea4802e fix(nixos): missing command line tools 2026-01-10 00:23:43 +01:00
2mal3 bdcb0a8ce3 fix(control): could not start display over wol 2026-01-10 00:22:53 +01:00
E44 09adf5dba4 chore: improve splash screen with randomized animation of cursor-movement 2026-01-09 21:30:46 +01:00
52 changed files with 3748 additions and 3022 deletions
+1 -8
View File
@@ -6,14 +6,7 @@ Open source solution for advanced remote control and coordination of one or more
## Display Requirements ## Display Requirements
- Linux See [packages in the NixOS config](https://github.com/PLG-Development/PLG-MuDiCS/blob/b0a57f9c679e8c483d1a81cb3c749cf8555785f6/nixos/configuration.nix#L86).
- Bash
- Chromium
- LibreOffice (optional, presentation view)
- Xreader (optional, pdf view)
- ImageMagick (optional, image preview)
- ffmpeg (optional, video preview)
- Ghostscript (optional, pdf preview)
## Contributing ## Contributing
BIN
View File
Binary file not shown.
+286 -261
View File
File diff suppressed because it is too large Load Diff
+963 -1196
View File
File diff suppressed because it is too large Load Diff
+28 -28
View File
@@ -16,40 +16,40 @@
"test": "deno task test:e2e" "test": "deno task test:e2e"
}, },
"devDependencies": { "devDependencies": {
"@eslint/compat": "^1.2.5", "@eslint/compat": "^1.4.1",
"@eslint/js": "^9.18.0", "@eslint/js": "^9.39.2",
"@playwright/test": "1.56.1", "@playwright/test": "1.56.1",
"@sveltejs/adapter-auto": "^6.0.0", "@sveltejs/adapter-auto": "^6.1.1",
"@sveltejs/adapter-static": "^3.0.9", "@sveltejs/adapter-static": "^3.0.10",
"@sveltejs/kit": "^2.22.0", "@sveltejs/kit": "^2.49.3",
"@sveltejs/vite-plugin-svelte": "^6.0.0", "@sveltejs/vite-plugin-svelte": "^6.2.3",
"@tailwindcss/vite": "^4.0.0", "@tailwindcss/vite": "^4.1.18",
"@tiptap/extension-placeholder": "^3.11.0", "@tiptap/extension-placeholder": "^3.15.3",
"eslint": "^9.18.0", "eslint": "^9.39.2",
"eslint-config-prettier": "^10.0.1", "eslint-config-prettier": "^10.1.8",
"eslint-plugin-svelte": "^3.0.0", "eslint-plugin-svelte": "^3.14.0",
"globals": "^16.0.0", "globals": "^16.5.0",
"prettier": "^3.4.2", "prettier": "^3.7.4",
"prettier-plugin-svelte": "^3.3.3", "prettier-plugin-svelte": "^3.4.1",
"sass-embedded": "^1.93.3", "sass-embedded": "^1.97.2",
"svelte": "^5.0.0", "svelte": "^5.46.1",
"svelte-check": "^4.3.5", "svelte-check": "^4.3.5",
"svelte-dnd-action": "^0.9.65", "svelte-dnd-action": "^0.9.69",
"tailwindcss": "^4.0.0", "tailwindcss": "^4.1.18",
"typescript": "^5.0.0", "typescript": "^5.9.3",
"typescript-eslint": "^8.20.0", "typescript-eslint": "^8.52.0",
"vite": "^7.0.4" "vite": "^7.3.1"
}, },
"dependencies": { "dependencies": {
"@thisux/sveltednd": "^0.0.20", "@thisux/sveltednd": "^0.0.20",
"@tiptap/core": "^3.11.0", "@tiptap/core": "^3.15.3",
"@tiptap/extension-highlight": "^3.11.0", "@tiptap/extension-highlight": "^3.15.3",
"@tiptap/extension-text-style": "^3.11.0", "@tiptap/extension-text-style": "^3.15.3",
"@tiptap/extensions": "^3.11.0", "@tiptap/extensions": "^3.15.3",
"@tiptap/pm": "^3.11.0", "@tiptap/pm": "^3.15.3",
"@tiptap/starter-kit": "^3.11.0", "@tiptap/starter-kit": "^3.15.3",
"dexie": "^4.2.1", "dexie": "^4.2.1",
"lucide-svelte": "^0.545.0", "lucide-svelte": "^0.545.0",
"svelte-splitpanes": "^8.0.9" "svelte-splitpanes": "^8.0.12"
} }
} }
+9 -1
View File
@@ -12,6 +12,14 @@
--color-stone-850: oklch(0.242 0.0065 45.171); --color-stone-850: oklch(0.242 0.0065 45.171);
} }
.link {
@apply text-blue-300 underline;
&:hover {
@apply text-blue-400;
}
}
.button { .button {
&.space { &.space {
@apply px-4; @apply px-4;
@@ -26,7 +34,7 @@
} }
} }
main { html {
scrollbar-width: thin; scrollbar-width: thin;
scrollbar-color: var(--color-stone-300) transparent; scrollbar-color: var(--color-stone-300) transparent;
} }
@@ -11,22 +11,25 @@
import DisplayObject from './DisplayObject.svelte'; import DisplayObject from './DisplayObject.svelte';
import { import {
all_displays_of_group_selected, all_displays_of_group_selected,
get_display_ids_in_group,
set_select_for_group, set_select_for_group,
update_db_displays,
local_displays,
set_new_display_order set_new_display_order
} from '$lib/ts/stores/displays'; } from '$lib/ts/stores/displays';
import DNDGrip from '$lib/components/DNDGrip.svelte'; import DNDGrip from '$lib/components/DNDGrip.svelte';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
import type { MenuOption } from '$lib/ts/types'; import type { Display, DisplayIdGroup, MenuOption } from '$lib/ts/types';
import { selected_display_ids } from '$lib/ts/stores/select'; import { selected_display_ids } from '$lib/ts/stores/select';
import { liveQuery, type Observable } from 'dexie'; import { liveQuery, type Observable } from 'dexie';
import { onMount } from 'svelte';
import { get_uuid } from '$lib/ts/utils';
let { let {
display_group_id, display_id_group,
get_display_menu_options, get_display_menu_options,
close_pinned_display close_pinned_display
}: { }: {
display_group_id: string; display_id_group: DisplayIdGroup;
get_display_menu_options: (display_id: string) => MenuOption[]; get_display_menu_options: (display_id: string) => MenuOption[];
close_pinned_display: () => void; close_pinned_display: () => void;
} = $props(); } = $props();
@@ -34,14 +37,14 @@
let all_selected: Observable<boolean> | undefined = $state(); let all_selected: Observable<boolean> | undefined = $state();
$effect(() => { $effect(() => {
const sdi = $selected_display_ids; const sdi = $selected_display_ids;
all_selected = liveQuery(() => all_displays_of_group_selected(display_group_id, sdi)); all_selected = liveQuery(() => all_displays_of_group_selected(display_id_group.id, sdi));
}); });
let display_ids_in_group = liveQuery(() => get_display_ids_in_group(display_group_id));
let hovering_selectable = $state(false); let hovering_selectable = $state(false);
async function select_all_of_this_group() { async function select_all_of_this_group() {
const new_value = !($all_selected || false); const new_value = !($all_selected || false);
await set_select_for_group(display_group_id, new_value); await set_select_for_group(display_id_group.id, new_value);
} }
async function handle_consider(e: CustomEvent) { async function handle_consider(e: CustomEvent) {
@@ -49,14 +52,21 @@
if (items.length !== 1 && info.trigger === TRIGGERS.DRAG_STARTED) { if (items.length !== 1 && info.trigger === TRIGGERS.DRAG_STARTED) {
$is_display_drag = true; $is_display_drag = true;
// add_empty_display_group(); // add empty display group if its not just one group
if (!($local_displays.length === 1 && $local_displays[0].displays.length === 1)) {
$local_displays.push({
id: get_uuid(),
displays: []
});
}
} }
await set_new_display_order(items); set_new_display_order(display_id_group.id, items);
} }
async function handle_finalize(e: CustomEvent) { async function handle_finalize(e: CustomEvent) {
set_new_display_order(display_id_group.id, e.detail.items);
await update_db_displays();
$is_display_drag = false; $is_display_drag = false;
await set_new_display_order(e.detail.items);
} }
</script> </script>
@@ -77,7 +87,7 @@
<div <div
class="flex flex-col min-w-0 pl-2 py-2 gap-2 w-full" class="flex flex-col min-w-0 pl-2 py-2 gap-2 w-full"
use:dragHandleZone={{ use:dragHandleZone={{
items: $display_ids_in_group || [], items: display_id_group.displays,
type: 'item', type: 'item',
flipDurationMs: dnd_flip_duration_ms, flipDurationMs: dnd_flip_duration_ms,
dropTargetStyle: { outline: 'none' } dropTargetStyle: { outline: 'none' }
@@ -85,18 +95,15 @@
onconsider={handle_consider} onconsider={handle_consider}
onfinalize={handle_finalize} onfinalize={handle_finalize}
> >
{#each $display_ids_in_group || [] as display (display.id)} {#each display_id_group.displays as display_id_object (display_id_object.id)}
<!-- Each Group --> <!-- Each Group -->
<section <section class="outline-none" role="figure">
animate:flip={{ duration: $is_group_drag ? 0 : dnd_flip_duration_ms, easing: cubicOut }} <!-- animate:flip={{ duration: $is_group_drag ? 0 : dnd_flip_duration_ms, easing: cubicOut }} -->
class="outline-none" <DisplayObject {display_id_object} {get_display_menu_options} {close_pinned_display} />
role="figure"
>
<DisplayObject {display} {get_display_menu_options} {close_pinned_display} />
</section> </section>
{/each} {/each}
{#if ($display_ids_in_group || []).length === 0} {#if display_id_group.displays.length === 0}
<div class="min-h-10 h-full w-full pl-2 py-2 flex justify-center items-center"> <div class="min-h-10 h-full w-full pl-2 py-2 flex justify-center items-center">
Hier in leere neue Gruppe ablegen Hier in leere neue Gruppe ablegen
</div> </div>
@@ -8,38 +8,40 @@
import DNDGrip from '$lib/components/DNDGrip.svelte'; import DNDGrip from '$lib/components/DNDGrip.svelte';
import { Menu, Pin, PinOff, VideoOff } from 'lucide-svelte'; import { Menu, Pin, PinOff, VideoOff } from 'lucide-svelte';
import OnlineState from './OnlineState.svelte'; import OnlineState from './OnlineState.svelte';
import type { Display, MenuOption } from '$lib/ts/types'; import type { Display, DisplayIdObject, MenuOption } from '$lib/ts/types';
import { is_selected, select, selected_display_ids } from '$lib/ts/stores/select'; import { is_selected, select, selected_display_ids } from '$lib/ts/stores/select';
import { screenshot_loop } from '$lib/ts/stores/displays'; import { get_display_by_id, screenshot_loop } from '$lib/ts/stores/displays';
import { change_file_path, current_file_path } from '$lib/ts/stores/files'; import { change_file_path, current_file_path } from '$lib/ts/stores/files';
import { liveQuery } from 'dexie';
let { let {
display, display_id_object,
get_display_menu_options, get_display_menu_options,
close_pinned_display close_pinned_display
}: { }: {
display: Display; display_id_object: DisplayIdObject;
get_display_menu_options: (display_id: string) => MenuOption[]; get_display_menu_options: (display_id: string) => MenuOption[];
close_pinned_display: () => void; close_pinned_display: () => void;
} = $props(); } = $props();
let hovering_unselectable = $state(false); let hovering_unselectable = $state(false);
let display = liveQuery(() => get_display_by_id(display_id_object.id));
async function onclick(e: Event) { async function onclick(e: Event) {
e.stopPropagation(); e.stopPropagation();
select(selected_display_ids, display.id, 'toggle'); select(selected_display_ids, display_id_object.id, 'toggle');
// force file view update // force file view update
await change_file_path($current_file_path); await change_file_path($current_file_path);
} }
async function on_preview_click(e: MouseEvent) { async function on_preview_click(e: MouseEvent) {
if ($pinned_display_id === display.id) { if ($pinned_display_id === display_id_object.id) {
close_pinned_display(); close_pinned_display();
} else { } else {
$pinned_display_id = display.id; $pinned_display_id = display_id_object.id;
} }
await screenshot_loop(display.id); screenshot_loop(display_id_object.id);
e.stopPropagation(); e.stopPropagation();
} }
</script> </script>
@@ -52,7 +54,7 @@
if (e.key === 'Enter' || e.key === ' ') onclick(e); if (e.key === 'Enter' || e.key === ' ') onclick(e);
}} }}
{onclick} {onclick}
class="p-1 {get_selectable_color_classes(is_selected(display.id, $selected_display_ids), { class="p-1 {get_selectable_color_classes(is_selected(display_id_object.id, $selected_display_ids), {
bg: true, bg: true,
hover: true, hover: true,
active: !hovering_unselectable, active: !hovering_unselectable,
@@ -68,12 +70,12 @@
onclick={on_preview_click} onclick={on_preview_click}
> >
<div class="flex h-full w-full items-center justify-center"> <div class="flex h-full w-full items-center justify-center">
{#if $pinned_display_id === display.id} {#if $pinned_display_id === display_id_object.id}
<div class="size-[50%]"> <div class="size-[50%]">
<Pin class="size-full" /> <Pin class="size-full" />
</div> </div>
{:else if display.preview.url} {:else if $display && $display.preview.url}
<img src={display.preview.url} alt="preview" class="w-full object-cover bg-black" /> <img src={$display.preview.url} alt="preview" class="w-full object-cover bg-black" />
{:else} {:else}
<!-- No Signal --> <!-- No Signal -->
<div class="size-full bg-black flex justify-center items-center"> <div class="size-full bg-black flex justify-center items-center">
@@ -84,11 +86,11 @@
<!-- Hover Effect --> <!-- Hover Effect -->
<span <span
class="pointer-events-none absolute inset-0 {$pinned_display_id === display.id class="pointer-events-none absolute inset-0 {$pinned_display_id === display_id_object.id
? 'bg-stone-700' ? 'bg-stone-700'
: 'bg-stone-700/70'} opacity-0 transition-opacity duration-200 flex items-center justify-center group-hover:opacity-100" : 'bg-stone-700/70'} opacity-0 transition-opacity duration-200 flex items-center justify-center group-hover:opacity-100"
> >
{#if $pinned_display_id === display.id} {#if $pinned_display_id === display_id_object.id}
<PinOff class="size-[50%]" aria-hidden="true" /> <PinOff class="size-[50%]" aria-hidden="true" />
{:else} {:else}
<Pin class="size-[50%]" aria-hidden="true" /> <Pin class="size-[50%]" aria-hidden="true" />
@@ -100,20 +102,20 @@
class="h-full flex flex-col justify-center gap-1 select-none class="h-full flex flex-col justify-center gap-1 select-none
min-w-0 basis-0 flex-1" min-w-0 basis-0 flex-1"
> >
<div class="text-xl font-bold truncate w-full" title={display.name}> <div class="text-xl font-bold truncate w-full" title={$display?.name ?? ''}>
{display.name} {$display?.name ?? ''}
</div> </div>
<OnlineState <OnlineState
selected={is_selected(display.id, $selected_display_ids)} selected={is_selected(display_id_object.id, $selected_display_ids)}
status={display.status} status={$display?.status ?? null}
/> />
</div> </div>
</div> </div>
<!-- Right Controls --> <!-- Right Controls -->
<div class="flex flex-row h-full items-center gap-2 pr-3"> <div class="flex flex-row h-full items-center gap-2 pr-3">
<DNDGrip <DNDGrip
bg={get_selectable_color_classes(is_selected(display.id, $selected_display_ids), { bg={get_selectable_color_classes(is_selected(display_id_object.id, $selected_display_ids), {
bg: true bg: true
})} })}
/> />
@@ -125,16 +127,16 @@
> >
<Button <Button
bg="bg-transparent" bg="bg-transparent"
hover_bg={get_selectable_color_classes(is_selected(display.id, $selected_display_ids), { hover_bg={get_selectable_color_classes(is_selected(display_id_object.id, $selected_display_ids), {
bg: true bg: true
})} })}
active_bg={get_selectable_color_classes(is_selected(display.id, $selected_display_ids), { active_bg={get_selectable_color_classes(is_selected(display_id_object.id, $selected_display_ids), {
bg: true bg: true
})} })}
click_function={(e) => { click_function={(e) => {
e.stopPropagation(); e.stopPropagation();
}} }}
menu_options={get_display_menu_options(display.id)} menu_options={get_display_menu_options(display_id_object.id)}
> >
<Menu /> <Menu />
</Button> </Button>
@@ -11,7 +11,8 @@
type Inode, type Inode,
get_file_primary_key, get_file_primary_key,
type FileOnDisplay, type FileOnDisplay,
type FileLoadingData type FileTransferTask,
is_folder
} from '$lib/ts/types'; } from '$lib/ts/types';
import { import {
@@ -24,18 +25,22 @@
change_file_path, change_file_path,
current_file_path, current_file_path,
get_date_mapping, get_date_mapping,
get_folder_elements,
get_missing_colliding_display_ids get_missing_colliding_display_ids
} from '$lib/ts/stores/files'; } from '$lib/ts/stores/files';
import RefreshPlay from '../svgs/RefreshPlay.svelte'; import RefreshPlay from '../svgs/RefreshPlay.svelte';
import { get_file_size_display_string, get_file_type } from '$lib/ts/utils'; import { get_file_size_display_string, get_file_type } from '$lib/ts/utils';
import { open_file } from '$lib/ts/api_handler'; import { open_file } from '$lib/ts/api_handler';
import { run_on_all_selected_displays } from '$lib/ts/stores/displays'; import { get_display_by_id, run_on_all_selected_displays } from '$lib/ts/stores/displays';
import { get_thumbnail_url } from '$lib/ts/stores/thumbnails'; import { get_thumbnail_url } from '$lib/ts/stores/thumbnails';
import { liveQuery, type Observable } from 'dexie'; import { liveQuery, type Observable } from 'dexie';
import { db } from '$lib/ts/database'; 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, not_interactable = false }: { file: Inode; not_interactable?: boolean } = $props();
let file_primary_key = $derived(get_file_primary_key(file));
let missing_colliding_displays_ids: let missing_colliding_displays_ids:
| Observable<{ missing: string[]; colliding: string[] }> | Observable<{ missing: string[]; colliding: string[] }>
| undefined = $state(); | undefined = $state();
@@ -44,39 +49,35 @@
missing_colliding_displays_ids = liveQuery(() => get_missing_colliding_display_ids(file, s)); missing_colliding_displays_ids = liveQuery(() => get_missing_colliding_display_ids(file, s));
}); });
let loading_data: let file_size: Observable<number> | undefined = $state();
| Observable<{
is_loading: boolean;
total_percentage: number;
total_seconds_until_finish: number;
display_data: FileLoadingData[];
}>
| undefined = $state();
$effect(() => { $effect(() => {
const d = $selected_display_ids; const f = file;
loading_data = liveQuery(() => get_loading_data(get_file_primary_key(file), d)); file_size = liveQuery(() => get_size_recursively(f));
}); });
let loading_finished = $state(false); let file_transfer_task: FileTransferTask | null = $derived(
$effect(() => { $file_transfer_tasks.hasOwnProperty(file_primary_key)
if (!loading_data) return; ? $file_transfer_tasks[file_primary_key]
let prev: boolean | undefined; : null
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))
); );
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) { function get_created_info(date_mapping: Record<string, Date> | undefined, full_string = false) {
if (!date_mapping) return ''; if (!date_mapping) return '';
@@ -135,7 +136,7 @@
function get_grayed_out_text_color_strings(is_selected: boolean): string { function get_grayed_out_text_color_strings(is_selected: boolean): string {
if (not_interactable) return 'text-stone-400'; 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 color = is_selected ? 'text-stone-600' : 'text-stone-400';
const factor = is_selected ? -1 : 1; const factor = is_selected ? -1 : 1;
return `${color} group-hover:${get_shifted_color(color, factor * 100)} group-active:${get_shifted_color(color, factor * 150)}`; return `${color} group-hover:${get_shifted_color(color, factor * 100)} group-active:${get_shifted_color(color, factor * 150)}`;
@@ -143,20 +144,20 @@
function get_grayed_out_border_color_strings(is_selected: boolean): string { function get_grayed_out_border_color_strings(is_selected: boolean): string {
if (not_interactable) return 'border-stone-550'; 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 color = is_selected ? 'border-stone-450' : 'border-stone-550';
const factor = is_selected ? 1 : 1; const factor = is_selected ? 1 : 1;
return `${color} group-hover:${get_shifted_color(color, factor * 100)} group-active:${get_shifted_color(color, factor * 150)}`; return `${color} group-hover:${get_shifted_color(color, factor * 100)} group-active:${get_shifted_color(color, factor * 150)}`;
} }
function onclick(e: Event) { function onclick(e: Event) {
if (not_interactable || $loading_data?.is_loading) return; if (not_interactable || !!file_transfer_task) return;
select(selected_file_ids, get_file_primary_key(file), 'toggle'); select(selected_file_ids, file_primary_key, 'toggle');
e.stopPropagation(); e.stopPropagation();
} }
async function open() { async function open() {
if (is_folder) { if (file_is_folder) {
await change_file_path($current_file_path + file.name + '/'); await change_file_path($current_file_path + file.name + '/');
} else { } else {
const path_to_file = $current_file_path + file.name; const path_to_file = $current_file_path + file.name;
@@ -169,11 +170,11 @@
if (loading_finished) { if (loading_finished) {
out += 'bg-stone-500 text-white/30'; 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'; out += 'bg-stone-700 text-white/30';
} else { } else {
out += get_selectable_color_classes( 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, bg: true,
hover: !not_interactable, hover: !not_interactable,
@@ -185,7 +186,7 @@
if (not_interactable) { if (not_interactable) {
out += ' rounded-lg'; out += ' rounded-lg';
} else if ($loading_data?.is_loading) { } else if (!!file_transfer_task) {
out += ' rounded-r-lg'; out += ' rounded-r-lg';
} else { } else {
out += ' rounded-r-lg cursor-pointer'; out += ' rounded-r-lg cursor-pointer';
@@ -194,49 +195,36 @@
return out; return out;
} }
async function get_loading_data( function get_total_percentage(ftt: FileTransferTask): number {
file_primary_key: string, let total_percentage: number;
selected_display_ids: string[] if (ftt.data.type === 'upload') {
): Promise<{ total_percentage = ftt.loading_data.percentage;
is_loading: boolean; } else {
total_percentage: number; const percentage_array = ftt.data.destination_display_data.map(
total_seconds_until_finish: number; (dd) => dd.loading_data.percentage
display_data: FileLoadingData[]; );
}> { total_percentage =
const file_on_display_data: FileOnDisplay[] = await db.files_on_display (ftt.loading_data.percentage + percentage_array.reduce((total, n) => total + n, 0)) /
.where('file_primary_key') (1 + percentage_array.length);
.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: []
};
} }
const display_data = [];
let is_loading = false; return Math.min(total_percentage, 100);
let percentage_sum = 0; }
let total_seconds_until_finish = 0;
for (const fod of file_on_display_data) { async function get_size_recursively(file: Inode): Promise<number> {
if (!!fod.loading_data) { if (is_folder(file)) {
if (!is_loading) is_loading = true; const folder_elements = await get_folder_elements(
percentage_sum += fod.loading_data.percentage; file.path + file.name + '/',
total_seconds_until_finish += fod.loading_data.seconds_until_finish; $selected_display_ids
display_data.push(fod.loading_data); );
} else { let out: number = 0;
percentage_sum += 100; 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> </script>
@@ -249,28 +237,28 @@
{#if !not_interactable} {#if !not_interactable}
<div class="h-{$current_height.file} aspect-square max-w-15 flex"> <div class="h-{$current_height.file} aspect-square max-w-15 flex">
<Button <Button
disabled={!is_folder && get_file_type(file) === null} disabled={!file_is_folder && get_file_type(file) === null}
title={!is_folder && get_file_type(file) === null ? 'Dateityp nicht unterstützt' : ''} title={!file_is_folder && get_file_type(file) === null ? 'Dateityp nicht unterstützt' : ''}
className="flex rounded-l-lg rounded-r-none {is_folder className="flex rounded-l-lg rounded-r-none {file_is_folder
? 'text-stone-450' ? 'text-stone-450'
: 'text-stone-800'} w-full" : 'text-stone-800'} w-full"
div_class="w-full" div_class="w-full"
bg={get_selectable_color_classes( bg={get_selectable_color_classes(
!is_folder && get_file_type(file) !== null, !file_is_folder && get_file_type(file) !== null,
{ {
bg: true bg: true
}, },
-50 -50
)} )}
hover_bg={get_selectable_color_classes( hover_bg={get_selectable_color_classes(
!is_folder, !file_is_folder,
{ {
bg: true bg: true
}, },
50 50
)} )}
active_bg={get_selectable_color_classes( active_bg={get_selectable_color_classes(
!is_folder, !file_is_folder,
{ {
bg: true bg: true
}, },
@@ -281,7 +269,7 @@
e.stopPropagation(); e.stopPropagation();
}} }}
> >
{#if is_folder} {#if file_is_folder}
<ArrowRight class="size-full" strokeWidth="3" /> <ArrowRight class="size-full" strokeWidth="3" />
{:else if $missing_colliding_displays_ids && $missing_colliding_displays_ids.missing.length !== 0} {:else if $missing_colliding_displays_ids && $missing_colliding_displays_ids.missing.length !== 0}
<RefreshPlay className="size-full" /> <RefreshPlay className="size-full" />
@@ -302,17 +290,15 @@
{onclick} {onclick}
class="{get_main_classes()} relative transition-colors duration-200 gap-4 flex flex-row justify-between group w-full min-w-0" 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="pointer-events-none absolute inset-0"> -->
<div <div
class="absolute pointer-events-none inset-y-0 left-0 transition-[width] duration-200 bg-stone-600 rounded-r-lg" class="absolute pointer-events-none inset-y-0 left-0 transition-[width] duration-400 bg-stone-600 rounded-r-lg"
style={`width: ${$loading_data.total_percentage}%;`} style={`width: ${get_total_percentage(file_transfer_task)}%;`}
></div> ></div>
<!-- </div> -->
{/if} {/if}
<div class="flex flex-row gap-2 min-w-0 w-full z-10"> <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"> <div class="aspect-square rounded-md flex justify-center items-center">
{#if is_folder} {#if file_is_folder}
<Folder class="size-full p-2" /> <Folder class="size-full p-2" />
{:else if $thumbnail_url || null} {:else if $thumbnail_url || null}
<img <img
@@ -329,14 +315,14 @@
{/if} {/if}
</div> </div>
<div class="content-center truncate select-none w-full" title={file.name}> <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.slice(0, file.name.lastIndexOf('.'))
: file.name} : file.name}
</div> </div>
</div> </div>
<div <div
class=" p-1 flex flex-row items-center gap-1 pr-1 z-10 {get_grayed_out_text_color_strings( 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" )} duration-200 transition-colors"
> >
<!-- {#if get_display_ids_where_file_is_missing($current_file_path, file, $selected_display_ids, $all_files)[1].length !== 0} <!-- {#if get_display_ids_where_file_is_missing($current_file_path, file, $selected_display_ids, $all_files)[1].length !== 0}
@@ -374,25 +360,25 @@
</div> </div>
<div <div
class="h-[70%] border {get_grayed_out_border_color_strings( 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" )} duration-200 transition-colors my-1"
></div> ></div>
<div <div
class="w-12 content-center text-center select-none text-xs whitespace-nowrap truncate" class="w-12 content-center text-center select-none text-xs whitespace-nowrap truncate"
title={file.type} title={file.type}
> >
{is_folder ? 'Ordner' : (get_file_type(file)?.display_name ?? '?')} {file_is_folder ? 'Ordner' : (get_file_type(file)?.display_name ?? '?')}
</div> </div>
<div <div
class="h-[70%] border {get_grayed_out_border_color_strings( 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" )} duration-200 transition-colors"
></div> ></div>
<div <div
class="w-12 content-center text-center select-none text-xs whitespace-nowrap" 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> </div>
</div> </div>
@@ -0,0 +1,66 @@
<script lang="ts">
import type { NumberSetting } from '$lib/ts/types';
import { ChevronDown, ChevronUp, Minus, Plus } from 'lucide-svelte';
import Button from './Button.svelte';
let {
number_setting,
on_change,
className = '',
disabled = false,
}: {
number_setting: NumberSetting;
on_change: (new_value: number) => void;
className?: string;
disabled?: boolean;
} = $props();
let el: HTMLInputElement | null = null;
function increase() {
if (!el) return;
el.stepUp();
el.dispatchEvent(new Event('input', { bubbles: true }));
on_change(Number(el.value));
}
function decrease() {
if (!el) return;
el.stepDown();
el.dispatchEvent(new Event('input', { bubbles: true }));
on_change(Number(el.value));
}
function on_blur() {
if (!el) return;
let value = Number(el.value);
if (value > number_setting.max) value = number_setting.max;
else if (value < number_setting.min) value = number_setting.min;
el.value = String(value);
on_change(value);
}
</script>
<div class="flex flex-row {className}">
<Button click_function={increase} className="rounded-r-none" disabled={disabled}>
<ChevronUp />
</Button>
<input
bind:this={el}
class="bg-stone-700 focus:bg-stone-550 focus:outline-none transition-colors duration-200 py-2 px-4 w-15 text-center
{disabled ? 'text-stone-500 cursor-not-allowed' : 'hover:bg-stone-600'}
[appearance:textfield]
[&::-webkit-outer-spin-button]:appearance-none
[&::-webkit-inner-spin-button]:appearance-none"
type="number"
disabled={disabled}
max={number_setting.max}
min={number_setting.min}
value={number_setting.now}
step={number_setting.step}
onblur={on_blur}
/>
<Button click_function={decrease} className="rounded-l-none" disabled={disabled}>
<ChevronDown />
</Button>
</div>
@@ -18,7 +18,7 @@
} = $props(); } = $props();
function try_to_close() { function try_to_close() {
if (!content.closable || !content.open) return; if (!content.open) return;
close_function(); close_function();
} }
@@ -35,19 +35,13 @@
</script> </script>
{#if content.open} {#if content.open}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div <div
class="absolute inset-0 backdrop-blur flex justify-center items-center z-50 {className}" class="absolute inset-0 backdrop-blur flex justify-center items-center z-50 {className}"
onclick={try_to_close}
transition:fade={{ duration: 100 }} transition:fade={{ duration: 100 }}
> >
<!-- svelte-ignore a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div <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 ?? 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} {#if content.title}
<div class="font-bold bg-stone-700 p-1.5 flex flex-row justify-between gap-8 w-full"> <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> </div>
<div class="flex aspect-square shrink-0"> <div class="flex aspect-square shrink-0">
{#if content.closable} <Button className="aspect-square p-1.5!" click_function={try_to_close}>
<Button className="aspect-square p-1.5!" click_function={try_to_close}> <X />
<X /> </Button>
</Button>
{/if}
</div> </div>
</div> </div>
{/if} {/if}
<div class="p-2 min-h-0 overflow-auto flex flex-col gap-2 {snippet_container_class}"> <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> </div>
</div> </div>
@@ -30,7 +30,7 @@
enter_function?: (() => void) | null; enter_function?: (() => void) | null;
} = $props(); } = $props();
let focus_bg = get_shifted_color(bg, 100); let focus_bg = $derived(get_shifted_color(bg, 100));
let focused: boolean = $state(false); let focused: boolean = $state(false);
let current_info = $state(''); let current_info = $state('');
let input_element: HTMLInputElement; let input_element: HTMLInputElement;
@@ -61,7 +61,7 @@
} }
function handle_keydown(event: KeyboardEvent) { function handle_keydown(event: KeyboardEvent) {
if (event.key !== 'Enter') return; if (event.key !== 'Enter' || !current_valid) return;
if (enter_mode === 'focus_next') { if (enter_mode === 'focus_next') {
event.preventDefault(); event.preventDefault();
+40 -19
View File
@@ -1,5 +1,6 @@
import { notifications } from './stores/notification'; import { notifications } from './stores/notification';
import { import {
is_folder,
to_display_status, to_display_status,
type DisplayStatus, type DisplayStatus,
type Inode, type Inode,
@@ -9,6 +10,9 @@ import {
} from './types'; } from './types';
import { dev } from '$app/environment'; import { dev } from '$app/environment';
import { get_sanitized_file_url } from './utils'; 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> { export async function get_screenshot(ip: string): Promise<Blob | null> {
const options = { method: 'PATCH' }; const options = { method: 'PATCH' };
@@ -22,7 +26,10 @@ export async function open_file(ip: string, path_to_file: string): Promise<void>
await request_display(ip, get_sanitized_file_url(path_to_file), options); await request_display(ip, get_sanitized_file_url(path_to_file), options);
} }
export async function send_keyboard_input(ip: string, inputs: { key: string; action: 'press' | 'release'}[]): Promise<void> { export async function send_keyboard_input(
ip: string,
inputs: { key: string; action: 'press' | 'release' }[]
): Promise<void> {
const options = { const options = {
method: 'PATCH', method: 'PATCH',
headers: { 'content-type': 'application/json' }, headers: { 'content-type': 'application/json' },
@@ -33,7 +40,7 @@ export async function send_keyboard_input(ip: string, inputs: { key: string; act
await request_display(ip, '/keyboardInput', options); await request_display(ip, '/keyboardInput', options);
} }
export async function show_html(ip: string, html: string) { export async function show_html(ip: string, html: string): Promise<void> {
const options = { const options = {
method: 'PATCH', method: 'PATCH',
headers: { 'content-type': 'application/json' }, headers: { 'content-type': 'application/json' },
@@ -69,6 +76,7 @@ export async function get_file_data(
const json_response = raw_response.json as ShellCommandResponse; const json_response = raw_response.json as ShellCommandResponse;
if (json_response.exitCode === 0 && json_response.stdout.trim() === '') return []; if (json_response.exitCode === 0 && json_response.stdout.trim() === '') return [];
if (handle_shell_error(ip, json_response, command, true)) return null; if (handle_shell_error(ip, json_response, command, true)) return null;
if (json_response.stdout.trim() === '') return null;
const response: FileInfo[] = json_response.stdout const response: FileInfo[] = json_response.stdout
.trim() .trim()
@@ -88,6 +96,7 @@ export async function get_file_data(
size: Number(response_element.size), size: Number(response_element.size),
thumbnail: null thumbnail: null
}; };
if (is_folder(folder_element)) folder_element.size = 0;
folder_element_list.push({ folder_element, date_created: new Date(response_element.created) }); folder_element_list.push({ folder_element, date_created: new Date(response_element.created) });
} }
return folder_element_list; return folder_element_list;
@@ -106,16 +115,8 @@ export async function get_file_tree_data(ip: string, path: string): Promise<Tree
return tree_element?.contents || null; return tree_element?.contents || null;
} }
export async function create_folders( export async function create_path(ip: string, path: string): Promise<void> {
ip: string, const command = `mkdir -p ".${path}"`;
path: string,
folder_names: string[]
): Promise<void> {
let command = `cd ".${path}"`;
for (const part of folder_names) {
command += ` && mkdir "${part}" && cd "${part}/"`;
}
const raw_response = await run_shell_command(ip, command); const raw_response = await run_shell_command(ip, command);
if (!raw_response.ok || !raw_response.json) return; if (!raw_response.ok || !raw_response.json) return;
@@ -192,14 +193,30 @@ async function request_display(
supress_error_handling_http_codes: number[] = [] supress_error_handling_http_codes: number[] = []
): Promise<RequestResponse> { ): Promise<RequestResponse> {
const url = `http://${ip}:1323/api${api_route}`; 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( async function request_control(
api_route: string, api_route: string,
options: { method: string; headers?: Record<string, string>; body?: string } options: { method: string; headers?: Record<string, string>; body?: string }
): Promise<RequestResponse> { ): 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); return await request(url, options);
} }
@@ -239,12 +256,17 @@ async function request(
error_description += '\nCould not parse error description'; error_description += '\nCould not parse error description';
} }
} }
notifications.push('error', `Fehler ${response.status} bei API-Anfrage`, error_description); notifications.push(
'error',
`Fehler bei API-Anfrage`,
`\nHTTP: ${response.status}\n${error_description}`
);
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof TypeError && /fetch|NetworkError/i.test(error.message)) { if (error instanceof TypeError && /fetch|NetworkError/i.test(error.message)) {
if (dev) { if (dev) {
console.warn('Request failed - Is the targeted device online?'); console.warn('Request failed - Is the targeted device online?');
} }
return { ok: false, http_code: 408 };
} else { } else {
console.error(url, error); console.error(url, error);
notifications.push('error', `Fataler Fehler bei API-Anfrage`, `${url}\nFehler: ${error}`); notifications.push('error', `Fataler Fehler bei API-Anfrage`, `${url}\nFehler: ${error}`);
@@ -273,12 +295,11 @@ function handle_shell_error(
console.error(shell_response); console.error(shell_response);
notifications.push( notifications.push(
'error', 'error',
`Fehler ${shell_response.exitCode} in API-Shell`, `Fehler in API-Shell`,
`${ip}\n${shell_command}\nFehler: ${shell_response.stderr}` `${ip}\n${shell_command}\nFehler (${shell_response.exitCode}): ${shell_response.stderr}`
); );
return true; return true;
} }
if (shell_response.stdout.trim() === '') return true;
return false; return false;
} }
@@ -294,7 +315,7 @@ async function run_shell_command(ip: string, command: string): Promise<RequestRe
} }
export async function shutdown(ip: string): Promise<RequestResponse> { export async function shutdown(ip: string): Promise<RequestResponse> {
return await run_shell_command(ip, 'shutdown -h now'); return await run_shell_command(ip, 'xfce4-session-logout --halt');
} }
export async function startup(mac: string): Promise<RequestResponse> { export async function startup(mac: string): Promise<RequestResponse> {
+1 -2
View File
@@ -23,8 +23,7 @@ export class FileDatabase extends Dexie {
[display_id+file_primary_key], [display_id+file_primary_key],
display_id, display_id,
file_primary_key, file_primary_key,
date_created, date_created
loading_data
`, `,
displays: ` displays: `
id, id,
@@ -1,15 +1,18 @@
import { get, writable, type Writable } from 'svelte/store';
import { db } from './database'; import { db } from './database';
import { get_display_by_id } from './stores/displays'; import { get_display_by_id } from './stores/displays';
import { import {
get_current_folder_elements, create_path_on_all_selected_displays,
get_folder_elements,
get_file_by_id, get_file_by_id,
remove_all_files_without_display, remove_all_files_without_display,
remove_file_from_display remove_file_from_display_recusively
} from './stores/files'; } from './stores/files';
import { notifications } from './stores/notification'; import { notifications } from './stores/notification';
import { generate_thumbnail } from './stores/thumbnails'; import { generate_thumbnail } from './stores/thumbnails';
import { import {
get_file_primary_key, get_file_primary_key,
is_folder,
type FileLoadingData, type FileLoadingData,
type FileOnDisplay, type FileOnDisplay,
type FileTransferTask, type FileTransferTask,
@@ -18,8 +21,17 @@ import {
} from './types'; } from './types';
import { get_sanitized_file_url, get_uuid, make_valid_name } from './utils'; 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; let is_processing: boolean = false;
const tasks: FileTransferTask[] = [];
export async function add_upload( export async function add_upload(
file_list: FileList, file_list: FileList,
@@ -27,9 +39,10 @@ export async function add_upload(
current_file_path: string current_file_path: string
) { ) {
if (file_list.length === 0) return console.warn('Upload canceled: no selected files'); 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 ( const used_file_names: string[] = await (
await get_current_folder_elements(current_file_path, selected_display_ids) await get_folder_elements(current_file_path, selected_display_ids)
).map((e) => e.name); ).map((e) => e.name);
for (const file of file_list) { for (const file of file_list) {
@@ -44,6 +57,10 @@ export async function add_upload(
thumbnail: null thumbnail: null
}; };
const file_primary_key = get_file_primary_key(db_file); 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); await db.files.put(db_file);
const upload_task_promises = selected_display_ids.map(async (display_id) => { const upload_task_promises = selected_display_ids.map(async (display_id) => {
@@ -53,17 +70,11 @@ export async function add_upload(
const db_file_on_display: FileOnDisplay = { const db_file_on_display: FileOnDisplay = {
display_id, display_id,
file_primary_key, file_primary_key,
date_created: new Date(), date_created: new Date()
loading_data: {
type: 'upload',
percentage: 0,
bytes_per_second: 0,
seconds_until_finish: -1
}
}; };
await db.files_on_display.put(db_file_on_display); await db.files_on_display.put(db_file_on_display);
return { const new_task = {
data: { data: {
type: 'upload' as const, type: 'upload' as const,
file file
@@ -74,58 +85,77 @@ export async function add_upload(
}, },
path: current_file_path, path: current_file_path,
file_name: file_name, file_name: file_name,
file_primary_key, loading_data: START_LOADING_DATA,
bytes_total: file.size 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); await Promise.all(upload_task_promises);
tasks.push(...upload_tasks);
} }
await start_task_processing(); await start_task_processing();
} }
export async function add_sync(selected_file_id: string, selected_display_ids: string[]) { export async function add_sync_recursively(
selected_file_id: string,
selected_display_ids: string[]
) {
const file_data = await find_file_data_on_active_selected_display( const file_data = await find_file_data_on_active_selected_display(
selected_file_id, selected_file_id,
selected_display_ids selected_display_ids
); );
if (!file_data) return console.warn('Sync canceled: no file_data'); if (!file_data) return console.warn('Sync canceled: no file_data');
tasks.push({ 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) {
await create_path_on_all_selected_displays(new_path, selected_display_ids);
} else {
for (const el of elements_in_folder) {
await add_sync_recursively(get_file_primary_key(el), selected_display_ids);
}
}
return; // cannot sync folder
}
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);
const new_task: FileTransferTask = {
data: { data: {
type: 'sync', 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, display: file_data.short_display_with_file,
path: file_data.file.path, path: file_data.file.path,
file_name: file_data.file.name, file_name: file_data.file.name,
file_primary_key: selected_file_id, loading_data: START_LOADING_DATA,
bytes_total: file_data.file.size bytes_total: file_data.file.size
}); };
file_transfer_tasks.update((tasks) => ({
...tasks,
[selected_file_id]: new_task
}));
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 display_ids_without_file = file_data.short_displays_without_file.map((d) => d.id);
await db.files_on_display const new_fods: FileOnDisplay[] = display_ids_without_file.map((display_id) => ({
.where('file_primary_key') display_id,
.equals(selected_file_id) file_primary_key: selected_file_id,
.filter((e) => display_ids_without_file.includes(e.display_id)) date_created: new Date()
.modify({ }));
loading_data: { await db.files_on_display.bulkPut(new_fods);
type: 'sync_upload',
percentage: 0,
bytes_per_second: 0,
seconds_until_finish: -1
}
});
await start_task_processing(); await start_task_processing();
} }
@@ -197,24 +227,15 @@ function generate_valid_file_name(original_file_name: string, used_file_names: s
return name; 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; const task_data = task.data;
if (task_data.type !== 'upload' || !task_data.file) return console.warn('Task cancelled: wrong task type:', task); 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);
// 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]
);
if (!!inode_element && inode_element.thumbnail === null) {
await generate_thumbnail(task.display.ip, task.path, inode_element);
}
}, 10);
} }
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); if (task.data.type !== 'sync') return console.warn('Task cancelled: wrong task type:', task);
const hasOPFS = const hasOPFS =
@@ -222,7 +243,8 @@ export async function sync(task: FileTransferTask) {
'storage' in navigator && 'storage' in navigator &&
'getDirectory' in navigator.storage; 'getDirectory' in navigator.storage;
if (!hasOPFS) { if (!hasOPFS) {
return show_error( return show_general_error(
file_primary_key,
task, task,
'OPFS (navigator.storage.getDirectory) nicht verfügbar bitte Chromium/Edge/Chrome nutzen.' 'OPFS (navigator.storage.getDirectory) nicht verfügbar bitte Chromium/Edge/Chrome nutzen.'
); );
@@ -235,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 url = `http://${task.display.ip}:1323/api${get_sanitized_file_url(task.path + task.file_name)}`;
const fetch_source = await fetch(url, { method: 'GET' }); const fetch_source = await fetch(url, { method: 'GET' });
if (!fetch_source.ok || !fetch_source.body) 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 dir = await navigator.storage.getDirectory();
const file_handle = await dir.getFileHandle(temp_name, { create: true }); const file_handle = await dir.getFileHandle(temp_name, { create: true });
@@ -248,21 +270,23 @@ export async function sync(task: FileTransferTask) {
if (done) break; if (done) break;
if (!value) continue; 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.write(value);
} }
await writable.close(); await writable.close();
finish_loading_data(file_primary_key);
// 02 - send downloaded file to every destination_display // 02 - send downloaded file to every destination_display
const temp_file = await file_handle.getFile(); const temp_file = await file_handle.getFile();
for (const current_short_display of task.data.destination_displays) { for (const current_short_display of task.data.destination_display_data) {
await upload_file_via_xhr(task, current_short_display, temp_file); await upload_file_via_xhr(file_primary_key, task, temp_file, current_short_display.display);
} }
await dir.removeEntry(temp_name); await dir.removeEntry(temp_name);
} catch (e) { } catch (e) {
show_error(task, String(e)); show_general_error(file_primary_key, task, String(e));
} }
} }
@@ -271,7 +295,8 @@ export async function download_file(selected_file_id: string, selected_display_i
selected_file_id, selected_file_id,
selected_display_ids selected_display_ids
); );
if (!file_data || file_data.file.type === 'inode/directory') return console.warn('Download cancelled: is folder'); if (!file_data || is_folder(file_data.file))
return console.warn('Download cancelled: is folder');
try { try {
const url = `http://${file_data.short_display_with_file.ip}:1323/api${get_sanitized_file_url(file_data.file.path + file_data.file.name)}`; const url = `http://${file_data.short_display_with_file.ip}:1323/api${get_sanitized_file_url(file_data.file.path + file_data.file.name)}`;
@@ -294,81 +319,163 @@ export async function download_file(selected_file_id: string, selected_display_i
async function start_task_processing() { async function start_task_processing() {
if (!is_processing) { if (!is_processing) {
is_processing = tasks.length !== 0; is_processing = Object.keys(get(file_transfer_tasks)).length !== 0;
await start_task_loop(); await start_task_loop();
} }
} }
async function start_task_loop() { async function start_task_loop() {
while (tasks.length > 0) { while (Object.keys(get(file_transfer_tasks)).length > 0) {
console.log('NOCH', tasks.length, 'ZU TUN'); const tasks = get(file_transfer_tasks);
const current_task = tasks[0]; const current_file_id = Object.keys(tasks)[0];
const current_task = tasks[current_file_id];
if (current_task.data.type === 'upload') { 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_file_id, current_task);
} }
else if (current_task.data.type === 'sync') {
await sync(current_task); file_transfer_tasks.update((all_tasks) => {
} const next = { ...all_tasks };
tasks.shift(); // Remove current_task from tasks delete next[current_file_id];
return next;
});
} }
is_processing = false; is_processing = false;
} }
async function upload_file_via_xhr(task: FileTransferTask, current_short_display: ShortDisplay, current_file: File) { async function upload_file_via_xhr(
file_primary_key: string,
task: FileTransferTask,
current_file: File,
destination_short_display: ShortDisplay | null = null
) {
const start_time = new Date(); const start_time = new Date();
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open( xhr.open(
'POST', '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 true
); );
xhr.setRequestHeader('content-type', 'application/octet-stream'); xhr.setRequestHeader('content-type', 'application/octet-stream');
xhr.upload.onprogress = (e) => { xhr.upload.onprogress = (e) => {
const apply = async () => { const apply = async () => {
await update_current_loading_data(task.data.type === 'upload' ? 'upload' : 'sync_upload', task, e.loaded, start_time, current_short_display.id); update_current_loading_data(
file_primary_key,
e.loaded,
start_time,
destination_short_display ? destination_short_display.id : null
);
}; };
apply(); apply();
}; };
xhr.onerror = async (e: ProgressEvent) => { xhr.onerror = async (e: ProgressEvent) => {
await show_error(task, e); await show_general_error(file_primary_key, task, e);
resolve(); resolve();
}; };
xhr.onreadystatechange = async () => { xhr.onreadystatechange = async () => {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if (xhr.status == 200) { if (xhr.status == 200) {
await db.files_on_display.update([current_short_display.ip, task.file_primary_key], { // set loading_data to 100%
loading_data: null finish_loading_data(
}); // TODO: Stattdessen update machen und gucken, ob die Datei wirklich da ist 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(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 { } else {
await show_error(task, `HTTP ${xhr.status}`); await show_general_error(file_primary_key, task, `HTTP ${xhr.status}`);
} }
resolve(); resolve();
} }
}; };
xhr.send(current_file); xhr.send(current_file);
}) });
} }
async function update_current_loading_data(type: FileLoadingData['type'], task: FileTransferTask, current_bytes: number, start_time: Date, other_display_id: string | null = null) { function finish_loading_data(
const current_percentage = task.bytes_total > 0 ? Math.round((current_bytes / task.bytes_total) * 100) : 1; file_primary_key: string,
const prognosed_data = get_prognosed_data(start_time, current_bytes, task.bytes_total); 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
};
await db.files_on_display.update([other_display_id ? other_display_id : task.display.id, task.file_primary_key], { return {
loading_data: { ...tasks,
type, [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,
destination_display_id: string | null = null
) {
file_transfer_tasks.update((tasks) => {
const task = tasks[file_primary_key];
if (!task) return tasks;
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, percentage: current_percentage,
bytes_per_second: prognosed_data.bytes_per_second, bytes_per_second: prognosed_data.bytes_per_second,
seconds_until_finish: prognosed_data.seconds_until_finish 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( function get_prognosed_data(
start_time: Date, start_time: Date,
bytes_done: number, bytes_done: number,
@@ -381,7 +488,11 @@ function get_prognosed_data(
return { bytes_per_second, seconds_until_finish }; 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; const task_data = task.data;
console.error('Error in File-Transfer-Handler:', error, task); console.error('Error in File-Transfer-Handler:', error, task);
notifications.push( notifications.push(
@@ -390,12 +501,20 @@ async function show_error(task: FileTransferTask, error: ProgressEvent | string)
`Datei: "${task.file_name}", Display-IP: ${task.display.ip}\nFehler: ${error}` `Datei: "${task.file_name}", Display-IP: ${task.display.ip}\nFehler: ${error}`
); );
if (task_data.type === 'upload') { if (task_data.type === 'upload') {
await remove_file_from_display(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(); await remove_all_files_without_display();
} else if (task_data.type === 'sync') { } else if (task_data.type === 'sync') {
for (const display_id of task_data.destination_displays.map((e) => e.id)) { for (const display_id of task_data.destination_display_data.map((e) => e.display.id)) {
await remove_file_from_display(display_id, task.file_primary_key); await remove_file_from_display_recusively(display_id, file_primary_key);
} }
await remove_all_files_without_display(); 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`
);
}
+53 -16
View File
@@ -1,34 +1,71 @@
import { screenshot_loop } from './stores/displays'; import { screenshot_loop } from './stores/displays';
import { ping_ip } from './api_handler'; 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 { update_folder_elements_recursively } from './stores/files';
import { db } from './database'; import { db } from './database';
const update_display_status_interval_seconds = 20; const update_display_status_interval_seconds = 20;
const update_display_loading_status_interval_seconds = 2;
export async function on_start() { const loading_display_ids: string[] = [];
export async function on_app_start() {
await db.files.clear(); await db.files.clear();
await db.files_on_display.clear(); await db.files_on_display.clear();
await update_all_display_status(); await db.displays
await setInterval(update_all_display_status, update_display_status_interval_seconds * 1000); .toCollection()
.modify({ status: null, preview: { currently_updating: false, url: null } });
await update_all_display_status(false);
await setInterval(
() => update_all_display_status(false),
update_display_status_interval_seconds * 1000
);
await setInterval(
() => update_all_display_status(true),
update_display_loading_status_interval_seconds * 1000
);
} }
async function update_all_display_status() { async function update_all_display_status(only_loading_displays: boolean) {
const all_displays: Display[] = await db.displays.toArray(); const not_loading_displays: Display[] = await db.displays
for (const display of all_displays) { .filter((d) =>
const new_status = await ping_ip(display.ip); only_loading_displays
if (new_status === null && display.status !== null) continue; ? loading_display_ids.includes(d.id)
if (new_status === 'app_online' && display.status !== 'app_online') { : !loading_display_ids.includes(d.id)
on_display_start(display); )
} .toArray();
if (new_status !== display.status) { for (const display of not_loading_displays) {
display.status = new_status; await update_display_status(display);
await db.displays.put(display); // save }
}
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 null;
if (new_status !== display.status) {
// status change
if (new_status === 'app_offline') {
loading_display_ids.push(display.id);
} else {
remove_display_from_loading_displays(display.id);
if (new_status === 'app_online') {
on_display_start(display);
}
} }
display.status = new_status;
await db.displays.put(display); // save
}
return new_status;
}
export function remove_display_from_loading_displays(display_id: string) {
const index = loading_display_ids.indexOf(display_id);
if (index !== -1) {
loading_display_ids.splice(index, 1);
} }
} }
async function on_display_start(display: Display) { async function on_display_start(display: Display) {
await update_folder_elements_recursively(display, '/'); await update_folder_elements_recursively(display, '/');
await screenshot_loop(display.id); screenshot_loop(display.id);
} }
+149 -58
View File
@@ -1,10 +1,30 @@
import { get } from 'svelte/store'; import { get, writable, type Writable } from 'svelte/store';
import type { Display, DisplayGroup, DisplayStatus } from '../types'; import type {
Display,
DisplayGroup,
DisplayIdGroup,
DisplayIdObject,
DisplayStatus
} from '../types';
import { is_selected, select, selected_display_ids } from './select'; import { is_selected, select, selected_display_ids } from './select';
import { get_uuid, image_content_hash } from '../utils'; import { get_uuid, image_content_hash } from '../utils';
import { get_screenshot } from '../api_handler'; import { get_screenshot } from '../api_handler';
import { delete_and_deselect_unique_files_from_display } from './files'; import { delete_and_deselect_unique_files_from_display } from './files';
import { db } from '../database'; 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[]>([]);
export async function is_display_name_taken(name: string): Promise<boolean> { export async function is_display_name_taken(name: string): Promise<boolean> {
const exists = await db.displays.where('name').equals(name).first(); const exists = await db.displays.where('name').equals(name).first();
@@ -16,8 +36,8 @@ export async function add_display(
mac: string | null, mac: string | null,
name: string, name: string,
status: DisplayStatus status: DisplayStatus
) { ): Promise<Display | null> {
if (await is_display_name_taken(name)) return; if (await is_display_name_taken(name)) return null;
const new_id = get_uuid(); const new_id = get_uuid();
const group = await db.display_groups.toCollection().first(); const group = await db.display_groups.toCollection().first();
let group_id: string; let group_id: string;
@@ -29,7 +49,7 @@ export async function add_display(
} }
const element_count_in_group = (await db.displays.where('group_id').equals(group_id).toArray()) const element_count_in_group = (await db.displays.where('group_id').equals(group_id).toArray())
.length; .length;
await db.displays.put({ const display = {
id: new_id, id: new_id,
ip, ip,
mac, mac,
@@ -38,7 +58,9 @@ export async function add_display(
group_id: group_id, group_id: group_id,
name, name,
status status
}); };
await db.displays.put(display);
return display;
} }
export async function edit_display_data( export async function edit_display_data(
@@ -46,11 +68,19 @@ export async function edit_display_data(
ip: string, ip: string,
mac: string | null, mac: string | null,
name: string name: string
) { ): Promise<Display | null> {
let display = await db.displays.get(display_id); let display = await db.displays.get(display_id);
if (!display) return; 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 await db.displays.put(display); // save
screenshot_loop(display.id);
return display;
} }
export async function remove_display(display_id: string) { export async function remove_display(display_id: string) {
@@ -62,6 +92,7 @@ export async function remove_display(display_id: string) {
if (group_id && (await db.displays.where('group_id').equals(group_id).toArray()).length === 0) { if (group_id && (await db.displays.where('group_id').equals(group_id).toArray()).length === 0) {
await db.display_groups.delete(group_id); // delete empty group await db.display_groups.delete(group_id); // delete empty group
} }
await remove_display_from_loading_displays(display_id);
} }
export async function all_displays_of_group_selected( export async function all_displays_of_group_selected(
@@ -103,43 +134,60 @@ export async function get_display_by_id(display_id: string): Promise<Display | n
return (await db.displays.get(display_id)) ?? null; return (await db.displays.get(display_id)) ?? null;
} }
export async function screenshot_loop(display_id: string, initial_retry_count: number = 5) { export function screenshot_loop(display_id: string) {
const display = await db.displays.get(display_id); setTimeout(async () => {
if (!display || display.preview.currently_updating) return; let settings = get(preview_settings);
if (settings.mode === 'never') return;
display.preview.currently_updating = true; const initial_retry_count = settings.retry_count.now;
await db.displays.update(display.id, { preview: display.preview }); const retry_seconds = get(preview_settings).retry_seconds.now;
let last_hash: number | null = null; const display = await db.displays.get(display_id);
if (!display || display.preview.currently_updating) return;
let retry_count = initial_retry_count; display.preview.currently_updating = true;
while (retry_count > 0) { await db.displays.update(display.id, { preview: display.preview });
retry_count -= 1;
const new_blob = await get_screenshot(display.ip); let last_hash: number | null = null;
if (!new_blob) {
display.preview = { currently_updating: false, url: null }; let retry_count = initial_retry_count;
await db.displays.update(display.id, { preview: display.preview }); while (retry_count > 0) {
return; settings = get(preview_settings);
} if (settings.mode === 'never') break;
const new_hash = await image_content_hash(new_blob); if (settings.mode !== 'always') retry_count -= 1;
if (last_hash !== new_hash) {
if (display.preview.url) { const new_blob = await get_screenshot(display.ip);
URL.revokeObjectURL(display.preview.url); 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; await new Promise((resolve) => setTimeout(resolve, retry_seconds * 1000)); // sleep
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, 2000)); // sleep 2s if (settings.mode === 'never') {
} await db.displays.update(display.id, { preview: { currently_updating: false, url: null } });
} else {
display.preview.currently_updating = false; display.preview.currently_updating = false;
await db.displays.update(display.id, { preview: display.preview }); await db.displays.update(display.id, { preview: display.preview });
}
}, 0);
} }
export async function run_on_all_selected_displays( export async function run_on_all_selected_displays(
@@ -158,7 +206,7 @@ export async function run_on_all_selected_displays(
if (!display || (ignore_offline && display.status === 'host_offline')) return; if (!display || (ignore_offline && display.status === 'host_offline')) return;
await run_function(display); await run_function(display);
if (update_screenshot_afterwards) { if (update_screenshot_afterwards) {
await screenshot_loop(display.id); screenshot_loop(display.id);
} }
}) })
); );
@@ -168,30 +216,73 @@ export async function get_display_groups(): Promise<DisplayGroup[]> {
return await db.display_groups.orderBy('position').toArray(); return await db.display_groups.orderBy('position').toArray();
} }
export async function get_display_ids_in_group(display_group_id: string): Promise<Display[]> { export async function update_local_displays() {
const displays: Display[] = await db.displays const display_groups = await db.display_groups.orderBy('position').toArray();
.where('group_id') const displays = await db.displays.orderBy('position').toArray();
.equals(display_group_id) const out: DisplayIdGroup[] = [];
.sortBy('position'); for (const group of display_groups) {
return displays; out.push({
id: group.id,
displays: (await displays).filter((d) => d.group_id === group.id).map((d) => ({ id: d.id }))
});
}
return out;
} }
export async function set_new_display_order(new_ordered_items: Display[]) { export async function update_db_displays() {
for (let i = 0; i < new_ordered_items.length; i++) { local_displays.update((groups) => groups.filter((g) => g.displays.length !== 0));
new_ordered_items[i].position = i; const filtered_local_display_groups = get(local_displays);
await db.displays.put(new_ordered_items[i]); 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);
const display_group_ids_to_delete = db_display_group_ids.filter(
(group) => !local_display_group_ids.includes(group)
);
await db.display_groups.where('id').anyOf(display_group_ids_to_delete).delete();
for (let i = 0; i < filtered_local_display_groups.length; i++) {
const group = filtered_local_display_groups[i];
if (db_display_group_ids.includes(group.id)) {
await db.display_groups.update(group.id, { position: i });
} else {
await db.display_groups.put({
id: group.id,
position: i
});
}
for (let j = 0; j < group.displays.length; j++) {
const display_id = group.displays[j].id;
await db.displays.update(display_id, { position: j, group_id: group.id });
}
} }
} }
export async function set_new_display_group_order(new_ordered_items: DisplayGroup[]) { export function set_new_display_order(display_id_group_id: string, new_data: DisplayIdObject[]) {
for (let i = 0; i < new_ordered_items.length; i++) { local_displays.update((local_displays: DisplayIdGroup[]) => {
new_ordered_items[i].position = i; for (const display_id_group of local_displays) {
await db.display_groups.put(new_ordered_items[i]); if (display_id_group.id === display_id_group_id) {
} display_id_group.displays = new_data;
}
}
return local_displays;
});
} }
setTimeout(add_testing_displays, 0); export function no_active_display_selected(
async function add_testing_displays() { selected_display_ids: string[],
await add_display('127.0.0.1', '00:1A:2B:3C:4D:5E', 'PC', 'host_offline'); online_displays: Display[]
// await add_display("192.168.178.111", "D4:81:D7:C0:DF:3C", "Laptop", "host_offline"); ) {
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() {
await add_display('127.0.0.1', '00:1A:2B:3C:4D:5E', 'PC', 'host_offline');
// await add_display("192.168.178.111", "D4:81:D7:C0:DF:3C", "Laptop", "host_offline");
}
} }
+99 -57
View File
@@ -1,6 +1,7 @@
import { get, writable, type Writable } from 'svelte/store'; import { get, writable, type Writable } from 'svelte/store';
import { import {
get_file_primary_key, get_file_primary_key,
is_folder,
type Display, type Display,
type FileOnDisplay, type FileOnDisplay,
type Inode, type Inode,
@@ -8,9 +9,10 @@ import {
} from '../types'; } from '../types';
import { get_display_by_id } from './displays'; import { get_display_by_id } from './displays';
import { is_selected, select, selected_display_ids, selected_file_ids } from './select'; import { is_selected, select, selected_display_ids, selected_file_ids } from './select';
import { create_folders, get_file_data, get_file_tree_data } from '../api_handler'; import { create_path, get_file_data, get_file_tree_data } from '../api_handler';
import { deactivate_old_thumbnail_urls, generate_thumbnail } from './thumbnails'; import { deactivate_old_thumbnail_urls, generate_thumbnail } from './thumbnails';
import { db } from '../database'; import { db } from '../database';
import { file_transfer_tasks } from '../file_transfer_handler';
export const current_file_path: Writable<string> = writable<string>('/'); export const current_file_path: Writable<string> = writable<string>('/');
@@ -42,16 +44,38 @@ export async function delete_and_deselect_unique_files_from_display(display_id:
.equals(display_id) .equals(display_id)
.toArray(); .toArray();
for (const file of files_on_display) { for (const file of files_on_display) {
await remove_file_from_display(display_id, file.file_primary_key); await remove_file_from_display_recusively(display_id, file.file_primary_key);
} }
await remove_all_files_without_display(); await remove_all_files_without_display();
} }
export async function remove_file_from_display(display_id: string, file_primary_key: string) { export async function remove_file_from_display_recusively(
display_id: string,
file_primary_key: string
) {
const found = await db.files_on_display.get([display_id, file_primary_key]); const found = await db.files_on_display.get([display_id, file_primary_key]);
if (!found) return; if (!found) return;
select(selected_file_ids, file_primary_key, 'deselect'); select(selected_file_ids, file_primary_key, 'deselect');
await db.files_on_display.delete([display_id, file_primary_key]); await db.files_on_display.delete([display_id, file_primary_key]);
const inode_element = await get_file_by_id(found.file_primary_key);
if (!inode_element) return;
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()
).map((e) => get_file_primary_key(e));
const primary_file_keys_in_folder_on_display = (
await db.files_on_display
.where('file_primary_key')
.anyOf(primary_file_keys_in_folder)
.filter((file) => file.display_id === display_id)
.toArray()
).map((e) => e.file_primary_key);
for (const file_key of primary_file_keys_in_folder_on_display) {
await remove_file_from_display_recusively(display_id, file_key);
}
}
} }
export async function remove_all_files_without_display() { export async function remove_all_files_without_display() {
@@ -111,12 +135,11 @@ async function get_display_ids_where_file_is_missing(
); );
} }
export async function get_displays_where_path_exists( export async function get_displays_where_path_not_exists(
path: string, path: string,
selected_display_ids: string[], selected_display_ids: string[]
invert: boolean
): Promise<Display[]> { ): Promise<Display[]> {
if (path === '/') return []; if (path === '/') return await db.displays.where('id').anyOf(selected_display_ids).toArray();
const last_path_part = const last_path_part =
path path
.slice(0, path.length - 1) .slice(0, path.length - 1)
@@ -125,20 +148,19 @@ export async function get_displays_where_path_exists(
const path_without_last_part = path.slice(0, path.length - (last_path_part.length + 1)); const path_without_last_part = path.slice(0, path.length - (last_path_part.length + 1));
const folders_of_current_path = await db.files const folders_of_current_path = await db.files
.where('[path+name+type]') .where('name')
.equals([path_without_last_part, last_path_part, 'inode/directory']) .equals(last_path_part)
.filter((inode) => inode.path === path_without_last_part && is_folder(inode))
.first(); .first();
if (!folders_of_current_path) if (!folders_of_current_path) return [];
return await db.displays.where('id').anyOf(selected_display_ids).toArray();
const folder_primary_key = get_file_primary_key(folders_of_current_path); const folder_primary_key = get_file_primary_key(folders_of_current_path);
const display_ids = selected_display_ids.filter(async (display_id) => { const display_ids_with_folder = (
const folder_exists = await db.files_on_display.get([display_id, folder_primary_key]); await db.files_on_display.where('file_primary_key').equals(folder_primary_key).toArray()
if (invert) { ).map((fod) => fod.display_id);
return !folder_exists;
} else { const display_ids = selected_display_ids.filter((display_id) => {
return folder_exists; return !display_ids_with_folder.includes(display_id);
}
}); });
return (await db.displays.bulkGet(display_ids)).filter((e) => e !== undefined); return (await db.displays.bulkGet(display_ids)).filter((e) => e !== undefined);
@@ -211,18 +233,39 @@ export async function update_folder_elements_recursively(
const new_folder_elements = await get_file_data(display.ip, file_path); const new_folder_elements = await get_file_data(display.ip, file_path);
if (!new_folder_elements) return; if (!new_folder_elements) return;
const existing_file_keys_on_display_in_path: [string, string, number, string][] = ( const loading_file_ids = Object.keys(get(file_transfer_tasks));
await db.files_on_display.where('display_id').equals(display.id).toArray() const loading_file_keys_without_size = (
).map((e) => JSON.parse(e.file_primary_key) as [string, string, number, string]); await db.files.bulkGet(
const existing_files_on_display_in_path: Inode[] = await db.files 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(
(e) => JSON.parse(e.file_primary_key) as [string, string, number, string]
);
const existing_files: Inode[] = await db.files
.where('[path+name+size+type]') .where('[path+name+size+type]')
.anyOf(existing_file_keys_on_display_in_path) .anyOf(existing_file_keys_on_display_in_path)
.filter((e) => e.path === file_path) .filter((e) => e.path === file_path)
.toArray(); .toArray();
const diff = get_folder_elements_difference( const diff = get_folder_elements_difference(existing_files, new_folder_elements);
existing_files_on_display_in_path,
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) { if (diff.new.length > 0) {
@@ -232,12 +275,11 @@ export async function update_folder_elements_recursively(
const file_on_display: FileOnDisplay = { const file_on_display: FileOnDisplay = {
display_id: display.id, display_id: display.id,
file_primary_key: get_file_primary_key(new_element.folder_element), file_primary_key: get_file_primary_key(new_element.folder_element),
loading_data: null,
date_created: new_element.date_created date_created: new_element.date_created
}; };
await db.files_on_display.put(file_on_display); 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( await update_folder_elements_recursively(
display, display,
file_path + new_element.folder_element.name + '/' file_path + new_element.folder_element.name + '/'
@@ -255,7 +297,7 @@ export async function update_folder_elements_recursively(
if (diff.deleted.length > 0) { if (diff.deleted.length > 0) {
// Remove old Folder-Elements // Remove old Folder-Elements
for (const old_element of diff.deleted) { for (const old_element of diff.deleted) {
remove_file_from_display(display.id, get_file_primary_key(old_element)); remove_file_from_display_recusively(display.id, get_file_primary_key(old_element));
} }
await remove_all_files_without_display(); await remove_all_files_without_display();
} }
@@ -275,8 +317,8 @@ function get_folder_elements_difference(
return { deleted: only_in_old, new: only_in_new }; return { deleted: only_in_old, new: only_in_new };
} }
export async function get_current_folder_elements( export async function get_folder_elements(
current_file_path: string, file_path: string,
selected_display_ids: string[] selected_display_ids: string[]
): Promise<Inode[]> { ): Promise<Inode[]> {
const existing_file_keys_on_selected_displays: [string, string, number, string][] = ( const existing_file_keys_on_selected_displays: [string, string, number, string][] = (
@@ -285,7 +327,7 @@ export async function get_current_folder_elements(
const existing_files_on_selected_displays_in_path: Inode[] = await db.files const existing_files_on_selected_displays_in_path: Inode[] = await db.files
.where('[path+name+size+type]') .where('[path+name+size+type]')
.anyOf(existing_file_keys_on_selected_displays) .anyOf(existing_file_keys_on_selected_displays)
.filter((e) => e.path === current_file_path) .filter((e) => e.path === file_path)
.toArray(); .toArray();
return sort_files(existing_files_on_selected_displays_in_path); return sort_files(existing_files_on_selected_displays_in_path);
@@ -293,8 +335,8 @@ export async function get_current_folder_elements(
function sort_files(files: Inode[]) { function sort_files(files: Inode[]) {
files.sort((a, b) => { files.sort((a, b) => {
const isDirA = a.type === 'inode/directory'; const isDirA = is_folder(a);
const isDirB = b.type === 'inode/directory'; const isDirB = is_folder(b);
// Ordner zuerst // Ordner zuerst
if (isDirA && !isDirB) return -1; if (isDirA && !isDirB) return -1;
@@ -358,32 +400,32 @@ export async function create_folder_on_all_selected_displays(
path: string, path: string,
selected_display_ids: string[] selected_display_ids: string[]
): Promise<void> { ): Promise<void> {
const path_parts = path const path_with_folder_name = (path += folder_name + '/');
.slice(1, path.length - 1) await create_path_on_all_selected_displays(path_with_folder_name, selected_display_ids);
.split('/') }
.filter((e) => e.length !== 0);
let remaining_display_ids = [...selected_display_ids];
const getDisplaysForPath = async (currentPath: string): Promise<Display[]> => { export async function create_path_on_all_selected_displays(
if (currentPath === '/') { path: string,
const displays = await db.displays.bulkGet(remaining_display_ids); selected_display_ids: string[]
return displays.filter((d): d is Display => !!d); ) {
} const displays_without_path = await get_displays_where_path_not_exists(
return get_displays_where_path_exists(currentPath, remaining_display_ids, false); path,
}; selected_display_ids
);
for (let depth = path_parts.length; depth >= 0 && remaining_display_ids.length; depth--) { if (displays_without_path.length === 0) return;
const currentPath = depth === 0 ? '/' : `/${path_parts.slice(0, depth).join('/')}/`; for (const display of displays_without_path) {
await create_path(display.ip, path);
const displays = await getDisplaysForPath(currentPath);
if (!displays.length) continue;
const folders_to_create = [...path_parts.slice(depth), folder_name];
for (const display of displays) {
await create_folders(display.ip, currentPath, folders_to_create);
remaining_display_ids = remaining_display_ids.filter((id) => id !== display.id);
}
} }
setTimeout(async () => {
for (const display of displays_without_path) {
const changed_paths = await get_changed_directory_paths(display, '/');
if (!changed_paths) continue;
console.debug('Update file system from', display.name, ':', changed_paths);
for (const path of changed_paths) {
await update_folder_elements_recursively(display, path);
}
}
}, 0);
} }
export async function get_date_mapping(file_primary_key: string): Promise<Record<string, Date>> { export async function get_date_mapping(file_primary_key: string): Promise<Record<string, Date>> {
@@ -1,72 +1,97 @@
import { writable, type Writable } from "svelte/store"; import { writable, type Writable } from 'svelte/store';
import type { NumberSetting } from '../types';
import { dev } from '$app/environment';
export const dnd_flip_duration_ms = 300; export const dnd_flip_duration_ms = 300;
const heights_options: Record<string, { min: number; max: number; step: number }> = { const heights_options: Record<string, { min: number; max: number; step: number }> = {
display: { display: {
min: 15, min: 15,
max: 40, max: 40,
step: 5, step: 5
}, },
file: { file: {
min: 10, min: 10,
max: 20, max: 20,
step: 5, step: 5
} }
} };
export const current_height: Writable<Record<string, number>> = writable<Record<string, number>>({ export const current_height: Writable<Record<string, number>> = writable<Record<string, number>>({
display: 25, display: 25,
file: 10, file: 10
}); });
export const is_group_drag: Writable<boolean> = writable<boolean>(false); export const is_group_drag: Writable<boolean> = writable<boolean>(false);
export const is_display_drag: Writable<boolean> = writable<boolean>(false); export const is_display_drag: Writable<boolean> = writable<boolean>(false);
export const preview_settings: Writable<{
mode: 'never' | 'normal' | 'always';
retry_seconds: NumberSetting;
retry_count: NumberSetting;
}> = writable<{
mode: 'never' | 'normal' | 'always';
retry_seconds: NumberSetting;
retry_count: NumberSetting;
}>({
mode: dev ? 'never' : 'normal',
retry_seconds: {
max: 10,
min: 0.5,
now: 2,
step: 0.5
},
retry_count: {
max: 10,
min: 1,
now: 5,
step: 1
}
});
export const pinned_display_id: Writable<string | null> = writable<string | null>(null); export const pinned_display_id: Writable<string | null> = writable<string | null>(null);
export function change_height(key: 'display' | 'file', factor: number) { export function change_height(key: 'display' | 'file', factor: number) {
current_height.update((height) => { current_height.update((height) => {
height[key] = next_height_step_size(key, height, factor) || height[key]; height[key] = next_height_step_size(key, height, factor) || height[key];
return height; return height;
}); });
} }
export function next_height_step_size(key: 'display' | 'file', current_height_array: Record<string, number>, factor: number): number { export function next_height_step_size(
const new_size = current_height_array[key] + (factor * heights_options[key].step); key: 'display' | 'file',
if (new_size > heights_options[key].max || new_size < heights_options[key].min) { current_height_array: Record<string, number>,
return 0; factor: number
} else { ): number {
return new_size; const new_size = current_height_array[key] + factor * heights_options[key].step;
} if (new_size > heights_options[key].max || new_size < heights_options[key].min) {
return 0;
} else {
return new_size;
}
} }
export function get_selectable_color_classes( export function get_selectable_color_classes(
selected: boolean, selected: boolean,
returning_classes: { bg?: boolean; hover?: boolean; active?: boolean; text?: boolean } = {}, returning_classes: { bg?: boolean; hover?: boolean; active?: boolean; text?: boolean } = {},
base_bg_distance: number = 0, base_bg_distance: number = 0,
shifted_distance: number = 0 shifted_distance: number = 0
) { ) {
let base_bg = selected ? 'bg-stone-400' : 'bg-stone-600'; let base_bg = selected ? 'bg-stone-400' : 'bg-stone-600';
const base_text = selected ? 'text-stone-950' : 'text-stone-200'; const base_text = selected ? 'text-stone-950' : 'text-stone-200';
base_bg = get_shifted_color(base_bg, base_bg_distance); base_bg = get_shifted_color(base_bg, base_bg_distance);
const { bg = false, hover = false, active = false, text = false } = returning_classes; const { bg = false, hover = false, active = false, text = false } = returning_classes;
const out: string[] = []; const out: string[] = [];
if (bg) out.push(base_bg); if (bg) out.push(base_bg);
if (hover) out.push('hover:' + get_shifted_color(base_bg, 100 + shifted_distance)); if (hover) out.push('hover:' + get_shifted_color(base_bg, 100 + shifted_distance));
if (active) out.push('active:' + get_shifted_color(base_bg, 150 + shifted_distance)); if (active) out.push('active:' + get_shifted_color(base_bg, 150 + shifted_distance));
if (text) out.push(base_text); if (text) out.push(base_text);
return out.join(' '); return out.join(' ');
} }
export function get_shifted_color(base_color: string, distance: number): string { export function get_shifted_color(base_color: string, distance: number): string {
return base_color.replace(/(\d+)(?=(?:\/\d+)?$)/, (m: string) => String(+Number(m) - distance)); return base_color.replace(/(\d+)(?=(?:\/\d+)?$)/, (m: string) => String(+Number(m) - distance));
} }
+41 -21
View File
@@ -33,39 +33,40 @@ export type FileTransferTask = {
display: ShortDisplay; display: ShortDisplay;
path: string; path: string;
file_name: 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) bytes_total: number; // if type === 'sync' -> bytes_total = file_size * 2 (1x download + 1x upload)
}; };
export type FileTransferTaskData = { export type FileTransferTaskData =
type: 'upload', | {
file: File, type: 'upload';
} | { file: File;
type: "sync", }
destination_displays: ShortDisplay[], | {
} type: 'sync';
destination_display_data: {
display: ShortDisplay;
loading_data: FileLoadingData;
}[];
};
export type FileLoadingData = {
percentage: number;
bytes_per_second: number;
seconds_until_finish: number;
};
export type ShortDisplay = { export type ShortDisplay = {
id: string; id: string;
ip: string; ip: string;
} };
export type FileOnDisplay = { export type FileOnDisplay = {
display_id: string; display_id: string;
file_primary_key: string; // JSON.stringify([string, string, number, string]) file_primary_key: string; // JSON.stringify([string, string, number, string])
date_created: Date; 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 Inode = { export type Inode = {
path: string; path: string;
name: string; name: string;
@@ -101,6 +102,15 @@ export type DisplayGroup = {
position: number; position: number;
}; };
export type DisplayIdGroup = {
id: string;
displays: DisplayIdObject[];
};
export type DisplayIdObject = {
id: string;
};
export type PreviewObject = { export type PreviewObject = {
currently_updating: boolean; currently_updating: boolean;
url: string | null; url: string | null;
@@ -116,13 +126,19 @@ export type MenuOption = {
export type PopupContent = { export type PopupContent = {
open: boolean; open: boolean;
snippet: Snippet<[string]> | null; snippet: Snippet<[any]> | Snippet<[]> | Snippet | null | any;
snippet_arg?: string; snippet_arg?: any;
title?: string; title?: string;
title_class?: string; title_class?: string;
title_icon?: typeof X | null; title_icon?: typeof X | null;
window_class?: string; window_class?: string;
closable?: boolean; };
export type NumberSetting = {
max: number;
min: number;
now: number;
step: number;
}; };
export type DisplayStatus = 'host_offline' | 'app_offline' | 'app_online' | null; export type DisplayStatus = 'host_offline' | 'app_offline' | 'app_online' | null;
@@ -132,3 +148,7 @@ export function to_display_status(value: string): DisplayStatus {
? (value as DisplayStatus) ? (value as DisplayStatus)
: null; : 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 { export function get_file_size_display_string(size: number, toFixed: number | null = null): string {
if (size < 0) 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'; if (size === 0) return '0 B';
const k = 1024; const k = 1024;
@@ -1,10 +1,29 @@
<script lang="ts"> <script lang="ts">
import '../app.css'; import '../app.css';
import Notification from './Notification.svelte'; import Notification from './Notification.svelte';
import SplashScreen from './../../../../shared/splash_screen.html?raw';
import version from './../../../../shared/version.txt?raw';
import { dev } from '$app/environment';
let { children } = $props(); let { children } = $props();
let versionSplashScreen = SplashScreen.replaceAll('%%APP-VERSION%%', version.trim());
</script> </script>
<svelte:head>
<title>PLG MuDiCS Control</title>
</svelte:head>
{#if !dev}
{@html versionSplashScreen}
{/if}
{@render children()} {@render children()}
<Notification /> <Notification />
<style>
:root {
--splash-fade-out-delay: 3.5s !important;
}
</style>
+175 -18
View File
@@ -1,25 +1,42 @@
<script lang="ts"> <script lang="ts">
import { Monitor, Plus, Radio, Settings, Trash2, X } from 'lucide-svelte'; import {
Monitor,
Plus,
Radio,
Settings,
Trash2,
Menu,
ChevronDown,
icons,
SquareCheckBig,
Square,
X,
Info
} from 'lucide-svelte';
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
import FileView from './FileView.svelte'; import FileView from './FileView.svelte';
import ControlView from './ControlView.svelte'; import ControlView from './ControlView.svelte';
import DisplayView from './DisplayView.svelte'; import DisplayView from './DisplayView.svelte';
import PopUp from '$lib/components/PopUp.svelte'; import PopUp from '$lib/components/PopUp.svelte';
import { type PopupContent } from '$lib/ts/types'; import { type Display, type PopupContent } from '$lib/ts/types';
import TextInput from '$lib/components/TextInput.svelte'; import TextInput from '$lib/components/TextInput.svelte';
import { import {
add_display, add_display,
edit_display_data, edit_display_data,
get_display_by_id, get_display_by_id,
is_display_name_taken, is_display_name_taken,
remove_display remove_display,
screenshot_loop
} from '$lib/ts/stores/displays'; } from '$lib/ts/stores/displays';
import { notifications } from '$lib/ts/stores/notification'; import { notifications } from '$lib/ts/stores/notification';
import { ping_ip } from '$lib/ts/api_handler'; import { ping_ip } from '$lib/ts/api_handler';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { on_start } from '$lib/ts/main'; import { on_app_start, update_display_status } from '$lib/ts/main';
import { display_status_to_info } from '$lib/ts/utils'; import { display_status_to_info } from '$lib/ts/utils';
import HighlightedText from '$lib/components/HighlightedText.svelte'; 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 = 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))$/; /^(?:(?: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))$/;
@@ -30,7 +47,6 @@
snippet: null, snippet: null,
title: '', title: '',
title_class: '!text-xl', title_class: '!text-xl',
closable: true
}); });
let remove_display_name = $state(''); let remove_display_name = $state('');
@@ -55,11 +71,40 @@
const ip = text_inputs_valid.ip.value; const ip = text_inputs_valid.ip.value;
const mac = text_inputs_valid.mac.value === '' ? null : text_inputs_valid.mac.value; const mac = text_inputs_valid.mac.value === '' ? null : text_inputs_valid.mac.value;
const name = text_inputs_valid.name.value; const name = text_inputs_valid.name.value;
let display: Display | null = null;
if (!!existing_display_id) { if (!!existing_display_id) {
await edit_display_data(existing_display_id, ip, mac, name); display = await edit_display_data(existing_display_id, ip, mac, name);
} else { } else {
const status = await ping_ip(text_inputs_valid.ip.value); const status = await ping_ip(text_inputs_valid.ip.value);
await add_display(ip, mac, name, status); display = await add_display(ip, mac, name, status);
}
if (!!display) {
await update_display_status(display);
}
}
function get_display_preview_mode(mode: 'never' | 'normal' | 'always') {
switch (mode) {
case 'never':
return 'Nie';
case 'normal':
return 'Normal';
case 'always':
return 'Dauerhaft';
}
}
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);
}
} }
} }
@@ -72,10 +117,21 @@
popup_content = { popup_content = {
open: true, open: true,
snippet: display_popup, snippet: display_popup,
title: 'Neuen Bildschirm hinzufügen', title: 'Neuen Bildschirm Hinzufügen',
title_icon: Monitor, title_icon: Monitor,
title_class: '!text-xl', title_class: '!text-xl',
closable: true window_class: 'w-3xl',
};
};
const show_settings_popup = () => {
popup_content = {
open: true,
snippet: settings_popup,
title: 'Einstellungen',
title_icon: Settings,
title_class: '!text-xl',
window_class: 'w-3xl',
}; };
}; };
@@ -88,7 +144,6 @@
title: 'Bildschirm wirklich löschen?', title: 'Bildschirm wirklich löschen?',
title_class: 'text-red-400 !text-xl', title_class: 'text-red-400 !text-xl',
title_icon: Trash2, title_icon: Trash2,
closable: true
}; };
}; };
@@ -107,13 +162,65 @@
title: 'Bildschirm bearbeiten', title: 'Bildschirm bearbeiten',
title_icon: Monitor, title_icon: Monitor,
title_class: '!text-xl', title_class: '!text-xl',
closable: true
}; };
}; };
onMount(on_start); onMount(on_app_start);
const show_about_popup = () => {
popup_content = {
open: true,
snippet: about_popup,
title: 'Über PLG MuDiCS',
title_icon: Info,
title_class: '!text-xl',
};
};
</script> </script>
{#snippet about_popup(_: string)}
<div class="px-2">
<h3 class="text-lg font-bold mt-4">Entwickler</h3>
<p>
<a target="_blank" class="link" href="https://github.com/programmer-44">E44</a>
<a target="_blank" class="link" href="https://codeberg.org/2mal3">2mal3</a>,
</p>
<h3 class="text-lg font-bold mt-4">Lizenz</h3>
<a
target="_blank"
class="link"
href="https://github.com/PLG-Development/PLG-MuDiCS/blob/main/LICENSE.txt"
>
GNU Affero General Public License v3 (AGPL-3.0)
</a>
<h3 class="text-lg font-bold mt-4">Verwendete Bibliotheken</h3>
<ul class="list-disc list-inside">
<li><a target="_blank" href="https://svelte.dev/" class="link">Svelte & SvelteKit</a></li>
<li><a target="_blank" href="https://tailwindcss.com/" class="link">TailwindCSS</a></li>
<li><a target="_blank" href="https://lucide.dev/" class="link">Lucide Icons</a></li>
<li><a target="_blank" href="https://tiptap.dev/" class="link">Tiptap</a></li>
<li><a target="_blank" href="https://dexie.org/" class="link">Dexie.js</a></li>
<li>
<a target="_blank" href="https://github.com/orefalo/svelte-splitpanes" class="link"
>svelte-splitpanes</a
>
</li>
<li>
<a target="_blank" href="https://github.com/thisux/sveltednd" class="link"
>@thisux/sveltednd</a
>
</li>
<li><a target="_blank" href="https://echo.labstack.com/" class="link">Echo</a></li>
<li><a target="_blank" href="https://github.com/mdlayher/wol" class="link">wol</a></li>
</ul>
</div>
<div class="flex justify-end pt-2">
<Button click_function={popup_close_function} className="px-4">Schließen</Button>
</div>
{/snippet}
{#snippet remove_display_popup(display_id: string)} {#snippet remove_display_popup(display_id: string)}
<div class="max-w-prose px-2"> <div class="max-w-prose px-2">
Soll der Bildschirm <HighlightedText>{remove_display_name}</HighlightedText> wirklich gelöscht werden? Soll der Bildschirm <HighlightedText>{remove_display_name}</HighlightedText> wirklich gelöscht werden?
@@ -185,7 +292,7 @@
<TextInput <TextInput
bind:current_value={text_inputs_valid.mac.value} bind:current_value={text_inputs_valid.mac.value}
bind:current_valid={text_inputs_valid.mac.valid} bind:current_valid={text_inputs_valid.mac.valid}
title="MAC-Adresse (optional)" title="MAC-Adresse (optional, wird zum aufwecken des Displays benötigt)"
placeholder="z.B. D4:81:A6:C4:BF:3F" placeholder="z.B. D4:81:A6:C4:BF:3F"
is_valid_function={(input: string) => { is_valid_function={(input: string) => {
return input === '' return input === ''
@@ -220,9 +327,53 @@
</div> </div>
{/snippet} {/snippet}
<main class="bg-stone-900 h-dvh w-dvw text-stone-200 px-4 py-2 gap-2 grid grid-rows-[3rem_auto]"> {#snippet settings_popup()}
<!-- {@html SplashScreen} --> <div class="flex flex-col gap-2 pl-1">
<span class="font-bold text-lg">Vorschau-Verhalten</span>
<div class="flex flex-col gap-2 ml-2">
<span class="text-stone-400 text-sm max-w-prose"
>Die Vorschau eines Bildschirms ist das Bild, welches links neben dem Display-Namen zu sehen
ist. Es zeigt relativ aktuell das an, was auf dem jeweiligen Bildschirm zu sehen ist.</span
>
<div class="flex flex-row justify-between items-center">
<span>Aktualisierungs-Verhalten</span>
<Button
className="gap-3 pl-4 pr-3 w-35"
menu_options={(['never', 'normal', 'always'] as const).map((mode) => ({
icon: mode === $preview_settings.mode ? SquareCheckBig : Square,
name: get_display_preview_mode(mode),
on_select: async () => await change_preview_mode(mode)
}))}>{get_display_preview_mode($preview_settings.mode)} <ChevronDown /></Button
>
</div>
<div class="flex flex-row justify-between items-center">
<span>Intervall zwischen den Aktualisierungs-Anfragen</span>
<NumberSettingInput
disabled={$preview_settings.mode === 'never'}
number_setting={$preview_settings.retry_seconds}
on_change={(new_value: number) => {
$preview_settings.retry_seconds.now = new_value;
}}
/>
</div>
<div class="flex flex-row justify-between items-center max-w-full gap-8">
<span class="">Anzahl der änderungslosen Aktualisierungen bis pausiert wird</span>
<NumberSettingInput
disabled={$preview_settings.mode !== 'normal'}
number_setting={$preview_settings.retry_count}
on_change={(new_value: number) => {
$preview_settings.retry_count.now = new_value;
}}
/>
</div>
</div>
</div>
<div class="flex justify-end pt-4">
<Button click_function={popup_close_function} className="px-4">Schließen</Button>
</div>
{/snippet}
<main class="bg-stone-900 h-dvh w-dvw text-stone-200 px-4 py-2 gap-2 grid grid-rows-[3rem_auto]">
<div class="w-[calc(100dvw-(8*var(--spacing)))] flex justify-between"> <div class="w-[calc(100dvw-(8*var(--spacing)))] flex justify-between">
<span class="text-4xl font-bold content-center pl-1"> PLG MuDiCS </span> <span class="text-4xl font-bold content-center pl-1"> PLG MuDiCS </span>
<Button <Button
@@ -231,16 +382,22 @@
menu_options={[ menu_options={[
{ {
icon: Plus, icon: Plus,
name: 'Neuen Bildschirm hinzufügen', name: 'Neuen Bildschirm Hinzufügen',
on_select: show_new_display_popup on_select: show_new_display_popup
}, },
{ {
icon: Settings, icon: Settings,
name: 'Weitere Einstellungen' name: 'Einstellungen',
on_select: show_settings_popup
},
{
icon: Info,
name: 'Über',
on_select: show_about_popup
} }
]} ]}
> >
<Settings></Settings> <Menu />
</Button> </Button>
</div> </div>
<div class="w-[calc(100dvw-(8*var(--spacing)))] grid grid-cols-2 gap-2"> <div class="w-[calc(100dvw-(8*var(--spacing)))] grid grid-cols-2 gap-2">
+156 -78
View File
@@ -9,25 +9,46 @@
Presentation, Presentation,
SquareTerminal, SquareTerminal,
TextAlignStart, TextAlignStart,
TrafficCone TrafficCone,
Globe
} from 'lucide-svelte'; } from 'lucide-svelte';
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
import PopUp from '$lib/components/PopUp.svelte'; import PopUp from '$lib/components/PopUp.svelte';
import type { PopupContent } from '$lib/ts/types'; import type { PopupContent } from '$lib/ts/types';
import KeyInput from './KeyInput.svelte'; import KeyInput from './KeyInput.svelte';
import { send_keyboard_input, show_blackscreen, shutdown, startup } from '$lib/ts/api_handler'; import {
import { get_display_by_id, run_on_all_selected_displays } from '$lib/ts/stores/displays'; send_keyboard_input,
show_blackscreen,
shutdown,
startup,
show_html
} from '$lib/ts/api_handler';
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 { selected_display_ids } from '$lib/ts/stores/select';
import TipTapInput from './TipTapInput.svelte'; import TipTapInput from './TipTapInput.svelte';
import { db } from '$lib/ts/database'; import { db } from '$lib/ts/database';
import { liveQuery, type Observable } from 'dexie';
import TextInput from '$lib/components/TextInput.svelte';
let all_display_states: Observable<'on' | 'off' | 'mixed'> | undefined = $state();
$effect(() => {
const ids = $selected_display_ids;
all_display_states = liveQuery(() => all_state(ids));
});
let popup_content: PopupContent = $state({ let popup_content: PopupContent = $state({
open: false, open: false,
snippet: null, snippet: null,
title: '', title: '',
closable: true
}); });
let current_text = $state('');
function popup_close_function() { function popup_close_function() {
popup_content.open = false; popup_content.open = false;
} }
@@ -36,9 +57,9 @@
popup_content = { popup_content = {
open: true, open: true,
snippet: send_keys_popup, snippet: send_keys_popup,
title: 'Tastatur-Eingaben durchgeben', title: 'Tastatur-Eingaben Senden',
title_icon: Keyboard, title_icon: Keyboard,
closable: true window_class: 'h-full'
}; };
}; };
@@ -46,13 +67,22 @@
popup_content = { popup_content = {
open: true, open: true,
snippet: text_popup, snippet: text_popup,
title: 'Text anzeigen', title: 'Text Anzeigen',
title_icon: TextAlignStart, title_icon: TextAlignStart,
closable: true,
window_class: 'size-full' window_class: 'size-full'
}; };
}; };
const show_website_popup = () => {
popup_content = {
open: true,
snippet: website_popup,
title: 'Webseite Anzeigen',
window_class: 'w-xl',
title_icon: Globe,
};
};
async function all_state(selected_display_ids: string[]): Promise<'on' | 'off' | 'mixed'> { async function all_state(selected_display_ids: string[]): Promise<'on' | 'off' | 'mixed'> {
const selected_displays = await Promise.all( const selected_displays = await Promise.all(
selected_display_ids.map(async (id) => await get_display_by_id(id)) selected_display_ids.map(async (id) => await get_display_by_id(id))
@@ -67,13 +97,12 @@
} }
} }
async function ask_shutdonw() { async function ask_shutdown() {
popup_content = { popup_content = {
open: true, open: true,
snippet: ask_shutdonw_popup, snippet: ask_shutdown_popup,
title: 'PC Herunterfahren', title: 'Bildschirm Herunterfahren',
title_icon: PowerOff, title_icon: PowerOff,
closable: true
}; };
} }
@@ -81,7 +110,7 @@
popup_content.open = false; popup_content.open = false;
await run_on_all_selected_displays((d) => { await run_on_all_selected_displays((d) => {
shutdown(d.ip); // no await here because we want to be fast 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); }, false);
} }
@@ -97,25 +126,58 @@
); );
} }
async function send_single_key_press(key: string) { 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?:\/\/[\w\-]+(\.[\w\-]+)+([\w\-\._~:/?#\[\]@!$&'\(\)\*\+,;=.])*/;
if (regex.test(url)) {
return [true, ''];
}
return [false, 'Ungültige URL'];
}
async function send_website() {
popup_content.open = false;
await run_on_all_selected_displays((d) => await run_on_all_selected_displays((d) =>
send_keyboard_input(d.ip, [{ key, action: 'press' }]) show_html(d.ip, `<iframe src="${website_url}"></iframe>`)
);
setTimeout(
async () =>
await run_on_all_selected_displays((d) =>
send_keyboard_input(d.ip, [{ key, action: 'release' }])
),
10
); );
} }
</script> </script>
{#snippet ask_shutdonw_popup()} {#snippet website_popup()}
<div class="flex flex-col gap-2">
<TextInput
title="URL (mit http:// oder https://)"
placeholder="https://example.com"
bind:current_value={website_url}
bind:current_valid={website_url_valid}
is_valid_function={validate_website_url}
enter_mode="submit"
enter_function={send_website}
/>
<div class="flex flex-row justify-end gap-2">
<Button className="button space font-bold" click_function={popup_close_function}>
Abbrechen
</Button>
<Button
click_function={send_website}
disabled={!website_url_valid || website_url === ''}
className="button success space">Anzeigen</Button
>
</div>
</div>
{/snippet}
{#snippet ask_shutdown_popup()}
<p>Bist du sicher, dass du alle ausgewählten Displays herunterfahren möchtest?</p> <p>Bist du sicher, dass du alle ausgewählten Displays herunterfahren möchtest?</p>
<div class="flex flex-row justify-end gap-2"> <div class="flex flex-row justify-end gap-2">
<Button className="button space" click_function={() => (popup_content.open = false)}> <Button className="button space font-bold" click_function={() => (popup_content.open = false)}>
Abbrechen Abbrechen
</Button> </Button>
<Button click_function={shutdown_action} className="button error space">Herunterfahren</Button> <Button click_function={shutdown_action} className="button error space">Herunterfahren</Button>
@@ -123,96 +185,112 @@
{/snippet} {/snippet}
{#snippet send_keys_popup()} {#snippet send_keys_popup()}
<div class="overflow-hidden flex flex-col gap-2"> <KeyInput {popup_close_function}/>
<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>
{/snippet} {/snippet}
{#snippet text_popup()} {#snippet text_popup()}
<TipTapInput /> <TipTapInput bind:text={current_text}/>
{/snippet} {/snippet}
<div class="grid grid-rows-[2.5rem_auto] bg-stone-800 rounded-2xl min-w-0"> <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"> <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>
<div class="relative flex flex-col gap-2 p-2 overflow-auto"> <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-row justify-between gap-2">
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<div class="flex flex-row gap-2 w-75 justify-normal"> <div class="flex flex-row gap-2 w-75 justify-normal">
<Button <button
title="Vorherige Folie (Pfeil nach Links)" title="Vorherige Folie (Pfeil nach Links) [gedrückt halten möglich]"
className="px-9" 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} disabled={$selected_display_ids.length === 0}
click_function={async () => { onmousedown={async () => {
await send_single_key_press('VK_LEFT'); await send_single_key_press('ArrowLeft', 'press');
}}><ArrowBigLeft /></Button }}
onmouseup={async () => {
await send_single_key_press('ArrowLeft', 'release');
}}
> >
<Button <ArrowBigLeft />
title="Nächste Folie (Pfeil nach Rechts)" </button>
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} disabled={$selected_display_ids.length === 0}
click_function={async () => { onmousedown={async () => {
await send_single_key_press('VK_RIGHT'); await send_single_key_press('ArrowRight', 'press');
}}><ArrowBigRight /></Button }}
onmouseup={async () => {
await send_single_key_press('ArrowRight', 'release');
}}
> >
<ArrowBigRight />
</button>
</div> </div>
<Button <Button
className="px-3 flex gap-3 w-75 justify-normal" className="px-3 flex gap-3 w-75 justify-normal"
disabled={$selected_display_ids.length === 0} click_function={show_text_popup}
click_function={show_text_popup}><TextAlignStart /> Text anzeigen</Button disabled={no_active_display_selected($selected_display_ids, $online_displays)}
><TextAlignStart /> Text Anzeigen</Button
> >
<Button <Button
className="px-3 flex gap-3 w-75 justify-normal" 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={show_website_popup}><Globe /> Webseite Anzeigen</Button
>
<Button
className="px-3 flex gap-3 w-75 justify-normal"
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
click_function={async () => { click_function={async () => {
await run_on_all_selected_displays((d) => show_blackscreen(d.ip)); await run_on_all_selected_displays((d) => show_blackscreen(d.ip));
}}><Presentation />Blackout</Button }}><Presentation />Blackout</Button
> >
<div class="flex flex-row justify-normal"> <div class="flex flex-row justify-normal">
<Button <Button className="rounded-r-none pl-3 flex gap-3 grow w-65 justify-normal" disabled>
className="rounded-r-none pl-3 flex gap-3 grow w-65 justify-normal" <TrafficCone /> Fallback-Bild Anzeigen
disabled={$selected_display_ids.length === 0} </Button>
><TrafficCone /> Fallback-Bild anzeigen</Button <Button className="rounded-l-none flex grow-0 w-10" disabled><ChevronDown /></Button>
>
<Button className="rounded-l-none flex grow-0 w-10"><ChevronDown /></Button>
</div> </div>
<Button <Button
className="px-3 flex gap-3 w-75 justify-normal" 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={show_send_keys_popup}><Keyboard /> Tastatur-Eingaben durchgeben</Button click_function={show_send_keys_popup}><Keyboard /> Tastatur-Eingaben Senden</Button
> >
</div> </div>
<div class="flex flex-col gap-2 justify-between"> <div class="flex flex-col gap-2 justify-between">
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
{#await all_state($selected_display_ids) then all} <Button
<Button className="px-3 flex gap-3 w-full xl:w-75 justify-normal"
className="px-3 flex gap-3 w-full xl:w-75 justify-normal" disabled={$all_display_states === 'on' ||
disabled={all === 'on' || $selected_display_ids.length === 0} no_active_display_selected($selected_display_ids, $online_displays)}
click_function={startup_action} click_function={startup_action}
> >
<Power /> PC hochfahren <Power /> Bildschirm Hochfahren
</Button> </Button>
<Button <Button
className="px-3 flex gap-3 w-full xl:w-75 justify-normal" className="px-3 flex gap-3 w-full xl:w-75 justify-normal"
disabled={all === 'off' || $selected_display_ids.length === 0} disabled={$all_display_states === 'off' ||
click_function={ask_shutdonw} no_active_display_selected($selected_display_ids, $online_displays)}
> click_function={ask_shutdown}
<PowerOff /> PC herunterfahren</Button >
> <PowerOff /> Bildschirm Herunterfahren</Button
{/await} >
</div> </div>
<Button <Button className="px-3 flex gap-3 w-full xl:w-75 justify-normal" disabled>
className="px-3 flex gap-3 w-full xl:w-75 justify-normal" <SquareTerminal />
disabled={$selected_display_ids.length === 0} Shell-Befehl Ausführen
><SquareTerminal /> Shell-Befehl ausführen</Button </Button>
>
</div> </div>
</div> </div>
<PopUp <PopUp
+55 -44
View File
@@ -3,9 +3,11 @@
import { import {
all_displays_of_group_selected, all_displays_of_group_selected,
get_display_by_id, get_display_by_id,
get_display_groups,
set_select_for_group, set_select_for_group,
set_new_display_group_order local_displays,
update_local_displays,
update_db_displays,
get_display_groups
} from '$lib/ts/stores/displays'; } from '$lib/ts/stores/displays';
import { import {
change_height, change_height,
@@ -19,15 +21,16 @@
import { type Display, type DisplayGroup, type MenuOption } from '$lib/ts/types'; import { type Display, type DisplayGroup, type MenuOption } from '$lib/ts/types';
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
import OnlineState from '../lib/components/OnlineState.svelte'; import OnlineState from '../lib/components/OnlineState.svelte';
import { cubicOut } from 'svelte/easing'; import { Menu, Pencil, PinOff, Trash2, VideoOff, ZoomIn, ZoomOut } from 'lucide-svelte';
import { Menu, Pencil, PinOff, Settings, Trash2, VideoOff, ZoomIn, ZoomOut } from 'lucide-svelte';
import { selected_display_ids } from '$lib/ts/stores/select'; import { selected_display_ids } from '$lib/ts/stores/select';
import { dragHandleZone } from 'svelte-dnd-action'; import { dragHandleZone } from 'svelte-dnd-action';
import { flip } from 'svelte/animate';
import DisplayGroupObject from '../lib/components/DisplayGroupObject.svelte'; import DisplayGroupObject from '../lib/components/DisplayGroupObject.svelte';
import { Pane, Splitpanes } from 'svelte-splitpanes'; import { Pane, Splitpanes } from 'svelte-splitpanes';
import HighlightedText from '$lib/components/HighlightedText.svelte'; import HighlightedText from '$lib/components/HighlightedText.svelte';
import { liveQuery, type Observable } from 'dexie'; import { liveQuery, type Observable } from 'dexie';
import { onMount } from 'svelte';
import { flip } from 'svelte/animate';
import { cubicOut } from 'svelte/easing';
let { let {
handle_display_deletion, handle_display_deletion,
@@ -43,7 +46,16 @@
const pdi = $pinned_display_id; const pdi = $pinned_display_id;
pinned_display = liveQuery(() => get_display_by_id(pdi || '')); pinned_display = liveQuery(() => get_display_by_id(pdi || ''));
}); });
let display_groups = liveQuery(() => get_display_groups()); let display_groups = liveQuery(() => get_display_groups());
let display_id_groups = liveQuery(() => update_local_displays());
$effect(() => {
const current_displays = $display_id_groups;
if (!$is_group_drag && !$is_display_drag && current_displays) {
$local_displays = current_displays;
}
});
let all_groups_selected: Observable<boolean> | undefined = $state(); let all_groups_selected: Observable<boolean> | undefined = $state();
$effect(() => { $effect(() => {
const d = $display_groups; const d = $display_groups;
@@ -206,7 +218,7 @@
class="min-w-40 px-4 rounded-xl cursor-pointer duration-200 transition-colors bg-stone-600" 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)} 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> </button>
<div class="flex flex-row"> <div class="flex flex-row">
<Button <Button
@@ -234,51 +246,50 @@
</div> </div>
</div> </div>
</div> </div>
<div class="min-h-0 overflow-y-auto" bind:this={displays_scroll_box}> <div class="min-h-0 overflow-y-auto overflow-x-hidden" bind:this={displays_scroll_box}>
<div {#if $local_displays.length === 0}
class="min-h-full p-2 flex flex-col gap-4" <div class="text-stone-500 px-10 py-6 leading-relaxed text-center">
use:dragHandleZone={{ Es wurden noch keine Bildschirme hinzugefügt. Klicke oben rechts auf
items: $display_groups || [], <HighlightedText fg="text-stone-450" className="p-1!">
type: 'group', <Menu class="inline pb-1" />
flipDurationMs: dnd_flip_duration_ms, </HighlightedText>
dropFromOthersDisabled: true, und
dropTargetStyle: { outline: 'none' } <HighlightedText fg="text-stone-450">Neuen Bildschirm hinzufügen</HighlightedText>.
}} </div>
onconsider={async (e: CustomEvent) => { {:else}
$is_group_drag = true; <div
await set_new_display_group_order(e.detail.items); class="min-h-full p-2 flex flex-col gap-4"
}} use:dragHandleZone={{
onfinalize={async (e: CustomEvent) => { items: $local_displays,
await set_new_display_group_order(e.detail.items); type: 'group',
$is_group_drag = false; flipDurationMs: dnd_flip_duration_ms,
}} dropFromOthersDisabled: true,
> dropTargetStyle: { outline: 'none' }
{#if ($display_groups || []).length === 0} }}
<div class="text-stone-500 px-10 py-6 leading-relaxed text-center"> onconsider={(e: CustomEvent) => {
Es wurden noch keine Bildschirme hinzugefügt. Klicke oben rechts auf $is_group_drag = true;
<HighlightedText fg="text-stone-450" className="p-1!" $local_displays = e.detail.items;
><Settings class="inline pb-1" /></HighlightedText }}
> onfinalize={async (e: CustomEvent) => {
und $local_displays = e.detail.items;
<HighlightedText fg="text-stone-450">Neuen Bildschirm hinzufügen</HighlightedText>. await update_db_displays();
</div> $is_group_drag = false;
{:else} }}
{#each $display_groups || [] as display_group (display_group.id)} >
{#each $local_displays as display_id_group (display_id_group.id)}
<!-- Each Group --> <!-- Each Group -->
<section <section class="outline-none">
out:scale={{ duration: dnd_flip_duration_ms, easing: cubicOut }} <!-- out:scale={{ duration: dnd_flip_duration_ms, easing: cubicOut }}
animate:flip={{ duration: dnd_flip_duration_ms, easing: cubicOut }} animate:flip={{ duration: dnd_flip_duration_ms, easing: cubicOut }} -->
class="outline-none"
>
<DisplayGroupObject <DisplayGroupObject
display_group_id={display_group.id} {display_id_group}
{get_display_menu_options} {get_display_menu_options}
{close_pinned_display} {close_pinned_display}
/> />
</section> </section>
{/each} {/each}
{/if} </div>
</div> {/if}
</div> </div>
</div> </div>
</Pane> </Pane>
+46 -25
View File
@@ -17,17 +17,17 @@
import { selected_display_ids, selected_file_ids } from '$lib/ts/stores/select'; import { selected_display_ids, selected_file_ids } from '$lib/ts/stores/select';
import { import {
current_file_path, current_file_path,
get_current_folder_elements, get_folder_elements,
get_file_by_id, get_file_by_id,
run_for_selected_files_on_selected_displays, run_for_selected_files_on_selected_displays,
update_current_folder_on_selected_displays, update_current_folder_on_selected_displays,
get_displays_where_path_exists, get_displays_where_path_not_exists,
create_folder_on_all_selected_displays create_folder_on_all_selected_displays
} from '$lib/ts/stores/files'; } from '$lib/ts/stores/files';
import { slide } from 'svelte/transition'; import { slide } from 'svelte/transition';
import InodeElement from '../lib/components/InodeElement.svelte'; import InodeElement from '../lib/components/InodeElement.svelte';
import PopUp from '$lib/components/PopUp.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 TextInput from '$lib/components/TextInput.svelte';
import { import {
first_letter_is_valid, first_letter_is_valid,
@@ -37,7 +37,8 @@
import { delete_files, rename_file } from '$lib/ts/api_handler'; import { delete_files, rename_file } from '$lib/ts/api_handler';
import HighlightedText from '$lib/components/HighlightedText.svelte'; import HighlightedText from '$lib/components/HighlightedText.svelte';
import { liveQuery, type Observable } from 'dexie'; import { liveQuery, type Observable } from 'dexie';
import { download_file, add_upload } from '$lib/ts/file_transfer_handler'; 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_name: string = $state('');
let current_valid: boolean = $state(false); let current_valid: boolean = $state(false);
@@ -52,21 +53,22 @@
$effect(() => { $effect(() => {
const path = $current_file_path, const path = $current_file_path,
display_ids = $selected_display_ids; display_ids = $selected_display_ids;
current_folder_elements = liveQuery(() => get_current_folder_elements(path, display_ids)); current_folder_elements = liveQuery(() => get_folder_elements(path, display_ids));
}); });
let one_file_selected: Observable<boolean> | undefined = $state(); let one_file_selected: Observable<boolean> | undefined = $state();
$effect(() => { $effect(() => {
const s = $selected_file_ids; const s = $selected_file_ids;
one_file_selected = liveQuery(async () => { 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);
});
});
let popup_content: PopupContent = $state({ let popup_content: PopupContent = $state({
open: false, open: false,
snippet: null, snippet: null,
title: '', title: '',
closable: true
}); });
let file_input: HTMLInputElement; let file_input: HTMLInputElement;
@@ -110,17 +112,16 @@
const show_edit_file_popup = async () => { const show_edit_file_popup = async () => {
const file = await get_file_by_id($selected_file_ids[0]); const file = await get_file_by_id($selected_file_ids[0]);
if (!file) return; if (!file) return;
const is_folder = file.type === 'inode/directory'; const file_is_folder = is_folder(file);
const extension = is_folder ? '' : '.' + file.name.split('.').at(-1) || ''; const extension = file_is_folder ? '' : '.' + file.name.split('.').at(-1) || '';
current_name = file.name.slice(0, file.name.length - extension.length); current_name = file.name.slice(0, file.name.length - extension.length);
current_valid = true; current_valid = true;
popup_content = { popup_content = {
open: true, open: true,
snippet: edit_file_name_popup, snippet: edit_file_name_popup,
title: `${is_folder ? 'Ordner' : 'Datei'} umbenennen`, title: `${file_is_folder ? 'Ordner' : 'Datei'} umbenennen`,
title_icon: FolderPlus, title_icon: FolderPlus,
snippet_arg: extension, snippet_arg: extension,
closable: true
}; };
}; };
@@ -128,14 +129,13 @@
current_name = ''; current_name = '';
current_valid = false; current_valid = false;
display_names_where_path_does_not_exist = ( display_names_where_path_does_not_exist = (
await get_displays_where_path_exists($current_file_path, $selected_display_ids, true) await get_displays_where_path_not_exists($current_file_path, $selected_display_ids)
).map((display) => display.name); ).map((display) => display.name);
popup_content = { popup_content = {
open: true, open: true,
snippet: new_folder_popup, snippet: new_folder_popup,
title: 'Neuen Ordner erstellen', title: 'Neuen Ordner erstellen',
title_icon: FolderPlus, title_icon: FolderPlus,
closable: true
}; };
}; };
@@ -145,9 +145,23 @@
snippet: delete_request_popup, snippet: delete_request_popup,
title: `${$selected_file_ids.length} ${$selected_file_ids.length === 1 ? 'Objekt' : 'Objekte'} wirklich löschen?`, title: `${$selected_file_ids.length} ${$selected_file_ids.length === 1 ? 'Objekt' : 'Objekte'} wirklich löschen?`,
title_icon: Trash2, title_icon: Trash2,
closable: true
}; };
}; };
async function sync_selected_files(
selected_file_ids: string[],
selected_display_ids: string[],
current_folder_elements: Inode[]
) {
if (selected_file_ids.length === 0 && current_folder_elements.length > 0) {
selected_file_ids = current_folder_elements.map((inode) => get_file_primary_key(inode));
}
if (selected_file_ids.length === 0) return;
// Mit For-Schleife über ausgewählte Elemente gehen
for (const file_id of selected_file_ids) {
await add_sync_recursively(file_id, selected_display_ids);
}
}
</script> </script>
{#snippet new_folder_popup()} {#snippet new_folder_popup()}
@@ -232,7 +246,7 @@
<span class="text-stone-400 px-1" <span class="text-stone-400 px-1"
>{`${$selected_file_ids.length === 1 ? 'Folgendes Objekt' : `Folgende ${$selected_file_ids.length} Objekte`} löschen? (Wiederherstellung nicht möglich)`}</span >{`${$selected_file_ids.length === 1 ? 'Folgendes Objekt' : `Folgende ${$selected_file_ids.length} Objekte`} löschen? (Wiederherstellung nicht möglich)`}</span
> >
<div class="flex flex-col gap-2 overflow-auto h-full min-h-0 grow-0"> <div class="flex flex-col gap-2 overflow-y-auto h-full min-h-0 grow-0">
{#each $selected_files || [] as file} {#each $selected_files || [] as file}
<InodeElement {file} not_interactable /> <InodeElement {file} not_interactable />
{/each} {/each}
@@ -270,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-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"> <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"> <span class="text-xl font-bold pl-2 content-center truncate min-w-0">
Dateien anzeigen und verwalten Dateien Anzeigen und Verwalten
</span> </span>
<div class="flex flex-row"> <div class="flex flex-row">
<Button <Button
@@ -306,7 +320,7 @@
title="Neuen Ordner erstellen (Neuen Ordner mit ausgewählten Objekten erstellen)" title="Neuen Ordner erstellen (Neuen Ordner mit ausgewählten Objekten erstellen)"
className="px-3 flex" className="px-3 flex"
click_function={show_new_folder_popup} 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> <div class="border border-stone-700 my-1"></div>
<Button <Button
@@ -315,19 +329,26 @@
click_function={() => { click_function={() => {
if (file_input) file_input.click(); 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 <Button
title="Ausgewählte Datei herunterladen" title="Ausgewählte Datei herunterladen"
className="px-3 flex" className="px-3 flex"
click_function={() => (download_file($selected_file_ids[0], $selected_display_ids))} click_function={async () =>
await download_file($selected_file_ids[0], $selected_display_ids)}
disabled={!$one_file_selected}><Download /></Button disabled={!$one_file_selected}><Download /></Button
> >
<div class="border border-stone-700 my-1"></div> <div class="border border-stone-700 my-1"></div>
<Button <Button
title="Aktuellen Ordner / Ausgewählte Datei(en) zwischen Bildschirmen synchronisieren" title="Aktuellen Ordner / Ausgewählte Datei(en) zwischen Bildschirmen synchronisieren"
className="px-3 flex gap-3" className="px-3 flex gap-3"
disabled={$selected_display_ids.length === 0} click_function={async () =>
await sync_selected_files(
$selected_file_ids,
$selected_display_ids,
$current_folder_elements ?? []
)}
disabled={no_active_display_selected($selected_display_ids, $online_displays)}
><RefreshCcw /> ><RefreshCcw />
<span class="hidden 2xl:flex">Synchronisieren</span> <span class="hidden 2xl:flex">Synchronisieren</span>
</Button> </Button>
@@ -341,7 +362,7 @@
<Button <Button
title="Ausgewählte Datei(en) einfügen" title="Ausgewählte Datei(en) einfügen"
className="px-3 flex" className="px-3 flex"
disabled={$selected_display_ids.length === 0} disabled={no_active_display_selected($selected_display_ids, $online_displays)}
> >
<ClipboardPaste /> <ClipboardPaste />
</Button> </Button>
@@ -363,9 +384,9 @@
</div> </div>
</div> </div>
</div> </div>
<div class="min-h-0 h-full overflow-y-auto bg-stone-750 rounded-xl"> <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"> <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"> <span class="text-stone-450 px-10 py-6 leading-relaxed text-center">
Es sind keine Bildschirme ausgewählt. Es sind keine Bildschirme ausgewählt.
</span> </span>
+127 -63
View File
@@ -1,106 +1,170 @@
<script lang="ts"> <script lang="ts">
import { flip } from 'svelte/animate'; import { flip } from 'svelte/animate';
import { get_selectable_color_classes } from '$lib/ts/stores/ui_behavior'; 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 { fade } from 'svelte/transition';
import { run_on_all_selected_displays } from '$lib/ts/stores/displays'; import { run_on_all_selected_displays } from '$lib/ts/stores/displays';
import { send_keyboard_input } from '$lib/ts/api_handler'; 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); let active = $state(false);
const current_keys: string[] = $state([]); const current_keys: string[] = $state([]);
let last_keys: { id: number; key: string }[] = $state([]); let last_keys: { id: number; key: string }[] = $state([]);
let seq = 0;
let el: HTMLDivElement; let el: HTMLDivElement;
function add_to_last_keys(name: string) { function add_to_last_keys(name: string) {
const id = Date.now(); const id = ++seq;
last_keys.push({ id, key: name });
// Neueste oben
last_keys = [{ id, key: name }, ...last_keys].slice(0, 6);
setTimeout(() => { setTimeout(() => {
last_keys = last_keys.filter((e) => e.id !== id); last_keys = last_keys.filter((e) => e.id !== id);
}, 1500); }, 1500);
} }
async function on_key(e: KeyboardEvent, key_down: boolean) { async function on_keyboard_input(e: KeyboardEvent, key_down: boolean) {
if (!active) return; if (!active) return;
const id = key_map[e.code]; const id = e.code;
if (!id) return; 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.preventDefault();
e.stopPropagation(); 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'; const action: 'press' | 'release' = key_down ? 'press' : 'release';
add_to_last_keys(action.toUpperCase() + ' ' + e.code); add_to_last_keys(action.toUpperCase() + ' ' + key);
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, [{ key, action }]), true);
await run_on_all_selected_displays(
(d) => send_keyboard_input(d.ip, [{ key: id, action }]),
true
);
} }
async function release_all_pressed_keys() { 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--) { 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); current_keys.splice(i, 1);
} }
await run_on_all_selected_displays( await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, inputs), true);
(d) => send_keyboard_input(d.ip, inputs),
true
);
} }
onDestroy(() => {
release_all_pressed_keys();
});
</script> </script>
<div <div class="flex flex-row gap-2 overflow-hidden h-full">
role="textbox" <div
tabindex="0" role="textbox"
bind:this={el} tabindex="0"
onclick={() => { bind:this={el}
if (active) { onclick={() => {
el.blur(); if (active) {
} else { el.blur();
el.focus(); } else {
active = true; el.focus();
} active = true;
}} }
onblur={async () => { }}
active = false; onblur={async () => {
await release_all_pressed_keys(); active = false;
}} await release_all_pressed_keys();
onkeydown={(e) => on_key(e, true)} }}
onkeyup={(e) => on_key(e, false)} onkeydown={(e) => on_keyboard_input(e, true)}
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( onkeyup={(e) => on_keyboard_input(e, false)}
active, 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, bg: true,
active: true, hover: true,
text: 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"> {active ? 'Erfassung aktiv' : 'Hier für Erfassung klicken'}
{#each last_keys as key (key.id)} </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 <span
animate:flip={{ duration: 200 }} class="flex flex-row gap-2 {item.key.split(' ')[0] === 'PRESS'
in:fade={{ duration: 200 }} ? 'text-sky-600'
out:fade={{ duration: 500 }}>{key.key}</span : '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} {/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>
</div> </div>
@@ -29,7 +29,7 @@
> >
</div> </div>
<span class="whitespace-break-spaces max-h-[60vh] overflow-y-auto">{n.message}</span> <span class="max-h-[60vh] overflow-y-auto overflow-x-hidden whitespace-pre-line max-w-full break-normal wrap-anywhere">{n.message}</span>
<div class="absolute inset-x-0 bottom-0 h-1 bg-white/25"> <div class="absolute inset-x-0 bottom-0 h-1 bg-white/25">
<div class="block h-full w-full bg-white/80 origin-left animate-progress-bar"></div> <div class="block h-full w-full bg-white/80 origin-left animate-progress-bar"></div>
+10 -8
View File
@@ -20,6 +20,12 @@
import { Color } from '@tiptap/extension-text-style'; import { Color } from '@tiptap/extension-text-style';
import Highlight from '@tiptap/extension-highlight'; import Highlight from '@tiptap/extension-highlight';
let {
text = $bindable()
}: {
text: string;
} = $props();
type TextEditOption = { type TextEditOption = {
onclick: () => void; onclick: () => void;
is_selected: () => boolean; is_selected: () => boolean;
@@ -66,12 +72,6 @@
is_selected: () => editor_state.editor?.isActive('strike') ?? false, is_selected: () => editor_state.editor?.isActive('strike') ?? false,
title: 'Durchgestrichen', title: 'Durchgestrichen',
icon: Strikethrough icon: Strikethrough
},
{
onclick: () => {},
is_selected: () => false,
title: 'QR-Code anfügen',
icon: QrCode
} }
], ],
[ [
@@ -134,15 +134,17 @@
multicolor: true multicolor: true
}) })
], ],
content: '', content: text,
onTransaction: ({ editor }) => { onTransaction: ({ editor }) => {
// Increment the state signal to force a re-render // Increment the state signal to force a re-render
editor_state = { editor }; editor_state = { editor };
}, },
autofocus: true autofocus: true
}); });
editor_state.editor.commands.selectAll();
}); });
onDestroy(() => { onDestroy(() => {
if (editor_state.editor) text = editor_state.editor.getHTML();
editor_state.editor?.destroy(); editor_state.editor?.destroy();
}); });
</script> </script>
@@ -216,7 +218,7 @@
{/each} {/each}
</div> </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>
</div> </div>
+207 -207
View File
@@ -1,221 +1,221 @@
module.exports = { module.exports = {
content: ['./src/**/*.{html,js,svelte,ts}'], content: ['./src/**/*.{html,js,svelte,ts}'],
safelist: [ safelist: [
'bg-stone-50', 'bg-stone-50',
'bg-stone-100', 'bg-stone-100',
'bg-stone-150', 'bg-stone-150',
'bg-stone-200', 'bg-stone-200',
'bg-stone-250', 'bg-stone-250',
'bg-stone-300', 'bg-stone-300',
'bg-stone-350', 'bg-stone-350',
'bg-stone-400', 'bg-stone-400',
'bg-stone-450', 'bg-stone-450',
'bg-stone-500', 'bg-stone-500',
'bg-stone-550', 'bg-stone-550',
'bg-stone-600', 'bg-stone-600',
'bg-stone-650', 'bg-stone-650',
'bg-stone-700', 'bg-stone-700',
'bg-stone-750', 'bg-stone-750',
'bg-stone-800', 'bg-stone-800',
'bg-stone-850', 'bg-stone-850',
'bg-stone-900', 'bg-stone-900',
'bg-stone-950', 'bg-stone-950',
'hover:bg-stone-50', 'hover:bg-stone-50',
'hover:bg-stone-100', 'hover:bg-stone-100',
'hover:bg-stone-150', 'hover:bg-stone-150',
'hover:bg-stone-200', 'hover:bg-stone-200',
'hover:bg-stone-250', 'hover:bg-stone-250',
'hover:bg-stone-300', 'hover:bg-stone-300',
'hover:bg-stone-350', 'hover:bg-stone-350',
'hover:bg-stone-400', 'hover:bg-stone-400',
'hover:bg-stone-450', 'hover:bg-stone-450',
'hover:bg-stone-500', 'hover:bg-stone-500',
'hover:bg-stone-550', 'hover:bg-stone-550',
'hover:bg-stone-600', 'hover:bg-stone-600',
'hover:bg-stone-650', 'hover:bg-stone-650',
'hover:bg-stone-700', 'hover:bg-stone-700',
'hover:bg-stone-750', 'hover:bg-stone-750',
'hover:bg-stone-800', 'hover:bg-stone-800',
'hover:bg-stone-850', 'hover:bg-stone-850',
'hover:bg-stone-900', 'hover:bg-stone-900',
'hover:bg-stone-950', 'hover:bg-stone-950',
'active:bg-stone-50', 'active:bg-stone-50',
'active:bg-stone-100', 'active:bg-stone-100',
'active:bg-stone-150', 'active:bg-stone-150',
'active:bg-stone-200', 'active:bg-stone-200',
'active:bg-stone-250', 'active:bg-stone-250',
'active:bg-stone-300', 'active:bg-stone-300',
'active:bg-stone-350', 'active:bg-stone-350',
'active:bg-stone-400', 'active:bg-stone-400',
'active:bg-stone-450', 'active:bg-stone-450',
'active:bg-stone-500', 'active:bg-stone-500',
'active:bg-stone-550', 'active:bg-stone-550',
'active:bg-stone-600', 'active:bg-stone-600',
'active:bg-stone-650', 'active:bg-stone-650',
'active:bg-stone-700', 'active:bg-stone-700',
'active:bg-stone-750', 'active:bg-stone-750',
'active:bg-stone-800', 'active:bg-stone-800',
'active:bg-stone-850', 'active:bg-stone-850',
'active:bg-stone-900', 'active:bg-stone-900',
'active:bg-stone-950', 'active:bg-stone-950',
'focus:bg-stone-50', 'focus:bg-stone-50',
'focus:bg-stone-100', 'focus:bg-stone-100',
'focus:bg-stone-150', 'focus:bg-stone-150',
'focus:bg-stone-200', 'focus:bg-stone-200',
'focus:bg-stone-250', 'focus:bg-stone-250',
'focus:bg-stone-300', 'focus:bg-stone-300',
'focus:bg-stone-350', 'focus:bg-stone-350',
'focus:bg-stone-400', 'focus:bg-stone-400',
'focus:bg-stone-450', 'focus:bg-stone-450',
'focus:bg-stone-500', 'focus:bg-stone-500',
'focus:bg-stone-550', 'focus:bg-stone-550',
'focus:bg-stone-600', 'focus:bg-stone-600',
'focus:bg-stone-650', 'focus:bg-stone-650',
'focus:bg-stone-700', 'focus:bg-stone-700',
'focus:bg-stone-750', 'focus:bg-stone-750',
'focus:bg-stone-800', 'focus:bg-stone-800',
'focus:bg-stone-850', 'focus:bg-stone-850',
'focus:bg-stone-900', 'focus:bg-stone-900',
'focus:bg-stone-950', 'focus:bg-stone-950',
'text-stone-50', 'text-stone-50',
'text-stone-150', 'text-stone-150',
'text-stone-200', 'text-stone-200',
'text-stone-250', 'text-stone-250',
'text-stone-300', 'text-stone-300',
'text-stone-350', 'text-stone-350',
'text-stone-100', 'text-stone-100',
'text-stone-400', 'text-stone-400',
'text-stone-450', 'text-stone-450',
'text-stone-500', 'text-stone-500',
'text-stone-550', 'text-stone-550',
'text-stone-600', 'text-stone-600',
'text-stone-650', 'text-stone-650',
'text-stone-700', 'text-stone-700',
'text-stone-750', 'text-stone-750',
'text-stone-800', 'text-stone-800',
'text-stone-850', 'text-stone-850',
'text-stone-900', 'text-stone-900',
'text-stone-950', 'text-stone-950',
'group-hover:text-stone-100', 'group-hover:text-stone-100',
'group-hover:text-stone-150', 'group-hover:text-stone-150',
'group-hover:text-stone-200', 'group-hover:text-stone-200',
'group-hover:text-stone-50', 'group-hover:text-stone-50',
'group-hover:text-stone-250', 'group-hover:text-stone-250',
'group-hover:text-stone-300', 'group-hover:text-stone-300',
'group-hover:text-stone-350', 'group-hover:text-stone-350',
'group-hover:text-stone-400', 'group-hover:text-stone-400',
'group-hover:text-stone-450', 'group-hover:text-stone-450',
'group-hover:text-stone-500', 'group-hover:text-stone-500',
'group-hover:text-stone-550', 'group-hover:text-stone-550',
'group-hover:text-stone-600', 'group-hover:text-stone-600',
'group-hover:text-stone-650', 'group-hover:text-stone-650',
'group-hover:text-stone-700', 'group-hover:text-stone-700',
'group-hover:text-stone-750', 'group-hover:text-stone-750',
'group-hover:text-stone-800', 'group-hover:text-stone-800',
'group-hover:text-stone-850', 'group-hover:text-stone-850',
'group-hover:text-stone-900', 'group-hover:text-stone-900',
'group-hover:text-stone-950', 'group-hover:text-stone-950',
'group-active:text-stone-50', 'group-active:text-stone-50',
'group-active:text-stone-100', 'group-active:text-stone-100',
'group-active:text-stone-150', 'group-active:text-stone-150',
'group-active:text-stone-200', 'group-active:text-stone-200',
'group-active:text-stone-250', 'group-active:text-stone-250',
'group-active:text-stone-300', 'group-active:text-stone-300',
'group-active:text-stone-350', 'group-active:text-stone-350',
'group-active:text-stone-400', 'group-active:text-stone-400',
'group-active:text-stone-450', 'group-active:text-stone-450',
'group-active:text-stone-500', 'group-active:text-stone-500',
'group-active:text-stone-550', 'group-active:text-stone-550',
'group-active:text-stone-600', 'group-active:text-stone-600',
'group-active:text-stone-650', 'group-active:text-stone-650',
'group-active:text-stone-700', 'group-active:text-stone-700',
'group-active:text-stone-750', 'group-active:text-stone-750',
'group-active:text-stone-800', 'group-active:text-stone-800',
'group-active:text-stone-850', 'group-active:text-stone-850',
'group-active:text-stone-950', 'group-active:text-stone-950',
'group-active:text-stone-900', 'group-active:text-stone-900',
'border-stone-50', 'border-stone-50',
'border-stone-100', 'border-stone-100',
'border-stone-150', 'border-stone-150',
'border-stone-200', 'border-stone-200',
'border-stone-250', 'border-stone-250',
'border-stone-300', 'border-stone-300',
'border-stone-350', 'border-stone-350',
'border-stone-400', 'border-stone-400',
'border-stone-450', 'border-stone-450',
'border-stone-500', 'border-stone-500',
'border-stone-550', 'border-stone-550',
'border-stone-600', 'border-stone-600',
'border-stone-650', 'border-stone-650',
'border-stone-700', 'border-stone-700',
'border-stone-750', 'border-stone-750',
'border-stone-800', 'border-stone-800',
'border-stone-850', 'border-stone-850',
'border-stone-900', 'border-stone-900',
'border-stone-950', 'border-stone-950',
'group-hover:border-stone-50', 'group-hover:border-stone-50',
'group-hover:border-stone-100', 'group-hover:border-stone-100',
'group-hover:border-stone-150', 'group-hover:border-stone-150',
'group-hover:border-stone-200', 'group-hover:border-stone-200',
'group-hover:border-stone-250', 'group-hover:border-stone-250',
'group-hover:border-stone-300', 'group-hover:border-stone-300',
'group-hover:border-stone-350', 'group-hover:border-stone-350',
'group-hover:border-stone-400', 'group-hover:border-stone-400',
'group-hover:border-stone-450', 'group-hover:border-stone-450',
'group-hover:border-stone-500', 'group-hover:border-stone-500',
'group-hover:border-stone-550', 'group-hover:border-stone-550',
'group-hover:border-stone-600', 'group-hover:border-stone-600',
'group-hover:border-stone-650', 'group-hover:border-stone-650',
'group-hover:border-stone-700', 'group-hover:border-stone-700',
'group-hover:border-stone-750', 'group-hover:border-stone-750',
'group-hover:border-stone-800', 'group-hover:border-stone-800',
'group-hover:border-stone-850', 'group-hover:border-stone-850',
'group-hover:border-stone-950', 'group-hover:border-stone-950',
'group-hover:border-stone-900', 'group-hover:border-stone-900',
'group-active:border-stone-50', 'group-active:border-stone-50',
'group-active:border-stone-100', 'group-active:border-stone-100',
'group-active:border-stone-150', 'group-active:border-stone-150',
'group-active:border-stone-200', 'group-active:border-stone-200',
'group-active:border-stone-250', 'group-active:border-stone-250',
'group-active:border-stone-300', 'group-active:border-stone-300',
'group-active:border-stone-350', 'group-active:border-stone-350',
'group-active:border-stone-400', 'group-active:border-stone-400',
'group-active:border-stone-450', 'group-active:border-stone-450',
'group-active:border-stone-500', 'group-active:border-stone-500',
'group-active:border-stone-550', 'group-active:border-stone-550',
'group-active:border-stone-600', 'group-active:border-stone-600',
'group-active:border-stone-650', 'group-active:border-stone-650',
'group-active:border-stone-700', 'group-active:border-stone-700',
'group-active:border-stone-750', 'group-active:border-stone-750',
'group-active:border-stone-800', 'group-active:border-stone-800',
'group-active:border-stone-850', 'group-active:border-stone-850',
'group-active:border-stone-900', 'group-active:border-stone-900',
'group-active:border-stone-950', 'group-active:border-stone-950',
'h-10', 'h-10',
'h-15', 'h-15',
'h-20', 'h-20',
'h-25', 'h-25',
'h-30', 'h-30',
'h-35', 'h-35',
'h-40', 'h-40',
'right-0', 'right-0',
'left-0', 'left-0',
'hover:bg-red-400', 'hover:bg-red-400',
'active:bg-red-500', 'active:bg-red-500',
'hover:bg-stone-600/70', 'hover:bg-stone-600/70',
'active:bg-stone-500/80', 'active:bg-stone-500/80'
], ]
} };
+7 -7
View File
@@ -3,7 +3,7 @@ module plg-mudics/control
go 1.24.5 go 1.24.5
require ( require (
github.com/labstack/echo/v4 v4.13.4 github.com/labstack/echo/v4 v4.15.0
github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a github.com/mdlayher/wol v0.0.0-20220221231636-b763a792253a
) )
@@ -17,10 +17,10 @@ require (
github.com/mdlayher/socket v0.2.1 // indirect github.com/mdlayher/socket v0.2.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.38.0 // indirect golang.org/x/crypto v0.46.0 // indirect
golang.org/x/net v0.40.0 // indirect golang.org/x/net v0.48.0 // indirect
golang.org/x/sync v0.14.0 // indirect golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.33.0 // indirect golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.25.0 // indirect golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.11.0 // indirect golang.org/x/time v0.14.0 // indirect
) )
+12
View File
@@ -8,6 +8,8 @@ github.com/josharian/native v1.0.0 h1:Ts/E8zCSEsG17dUqv7joXJFybuMLjQfWE04tsBODTx
github.com/josharian/native v1.0.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= github.com/josharian/native v1.0.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
github.com/labstack/echo/v4 v4.15.0 h1:hoRTKWcnR5STXZFe9BmYun9AMTNeSbjHi2vtDuADJ24=
github.com/labstack/echo/v4 v4.15.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
@@ -34,13 +36,18 @@ github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -48,11 +55,16 @@ golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+10 -4
View File
@@ -37,6 +37,9 @@ func main() {
e := echo.New() e := echo.New()
// Allow requests from everywhere
e.Use(middleware.CORS())
// Serve the embedded SvelteKit frontend // Serve the embedded SvelteKit frontend
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{ e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Filesystem: http.FS(frontend.BuildDirFS), Filesystem: http.FS(frontend.BuildDirFS),
@@ -61,7 +64,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
}() }()
err = shared.OpenBrowserWindow("http://localhost:"+port, false, false) err = shared.OpenBrowserWindow("http://localhost:"+port, false, "control")
if err != nil { if err != nil {
slog.Error("Failed to open browser window", "error", err) slog.Error("Failed to open browser window", "error", err)
os.Exit(1) os.Exit(1)
@@ -74,13 +77,13 @@ func pingRoute(ctx echo.Context) error {
return ctx.JSON(http.StatusBadRequest, PingResponse{Error: "missing 'ip' query parameter"}) 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) result := shared.RunShellCommand(cmd)
if result.ExitCode != 0 { if result.ExitCode != 0 {
return ctx.JSON(http.StatusOK, PingResponse{Status: "host_offline"}) 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 { if err != nil {
return ctx.JSON(http.StatusOK, PingResponse{Status: "app_offline"}) return ctx.JSON(http.StatusOK, PingResponse{Status: "app_offline"})
} }
@@ -105,14 +108,17 @@ func wakeOnLanRoute(ctx echo.Context) error {
} }
mac, err := net.ParseMAC(data.MACAddress) mac, err := net.ParseMAC(data.MACAddress)
if err != nil { if err != nil {
slog.Warn("Invalid MAC address provided", "mac_address", data.MACAddress, "error", err)
return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: "Invalid MAC address"}) return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: "Invalid MAC address"})
} }
client, err := wol.NewClient() client, err := wol.NewClient()
if err != nil { if err != nil {
slog.Error("Failed to create Wake-on-LAN client", "error", err)
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to create Wake-on-LAN client"}) return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to create Wake-on-LAN client"})
} }
if err := client.Wake("255.255.255.255", mac); err != nil { if err := client.Wake("255.255.255.255:7", mac); err != nil {
slog.Error("Failed to send Wake-on-LAN packet", "error", err)
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to send Wake-on-LAN packet"}) return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to send Wake-on-LAN packet"})
} }
+10 -10
View File
@@ -4,10 +4,10 @@ go 1.24.4
require ( require (
github.com/a-h/templ v0.3.960 github.com/a-h/templ v0.3.960
github.com/labstack/echo/v4 v4.13.4 github.com/gabriel-vasile/mimetype v1.4.11
github.com/labstack/echo/v4 v4.15.0
github.com/micmonay/keybd_event v1.1.2 github.com/micmonay/keybd_event v1.1.2
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/gabriel-vasile/mimetype v1.4.11
) )
require ( require (
@@ -23,14 +23,14 @@ require (
github.com/natefinch/atomic v1.0.1 // indirect github.com/natefinch/atomic v1.0.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.40.0 // indirect golang.org/x/crypto v0.46.0 // indirect
golang.org/x/mod v0.26.0 // indirect golang.org/x/mod v0.30.0 // indirect
golang.org/x/net v0.42.0 // indirect golang.org/x/net v0.48.0 // indirect
golang.org/x/sync v0.16.0 // indirect golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.34.0 // indirect golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.27.0 // indirect golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.11.0 // indirect golang.org/x/time v0.14.0 // indirect
golang.org/x/tools v0.35.0 // indirect golang.org/x/tools v0.39.0 // indirect
) )
tool github.com/a-h/templ/cmd/templ tool github.com/a-h/templ/cmd/templ
+19
View File
@@ -20,6 +20,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
github.com/labstack/echo/v4 v4.15.0 h1:hoRTKWcnR5STXZFe9BmYun9AMTNeSbjHi2vtDuADJ24=
github.com/labstack/echo/v4 v4.15.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
@@ -36,26 +38,43 @@ github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg= golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ= golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs= golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8= golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0= golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw= golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+2 -4
View File
@@ -9,8 +9,6 @@ import (
"plg-mudics/shared" "plg-mudics/shared"
) )
const VERSION = "0.1.0"
//go:generate go tool templ generate //go:generate go tool templ generate
func main() { func main() {
@@ -27,8 +25,8 @@ func main() {
// the order is important, the open browser command exitsts as soon as the winodw is closed // the order is important, the open browser command exitsts as soon as the winodw is closed
// and since its the last action in the main go func all other goroutines (e.g. the webserver) are killed // and since its the last action in the main go func all other goroutines (e.g. the webserver) are killed
go web.StartWebServer(VERSION, port) go web.StartWebServer(shared.Version, port)
err = shared.OpenBrowserWindow("http://localhost:"+port, true, true) err = shared.OpenBrowserWindow("http://localhost:"+port, true, "display")
if err != nil { if err != nil {
slog.Error("Failed to open browser window", "error", err) slog.Error("Failed to open browser window", "error", err)
os.Exit(1) os.Exit(1)
+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,
}
-44
View File
@@ -3,7 +3,6 @@ package pkg
import ( import (
"errors" "errors"
"fmt" "fmt"
"log/slog"
"net" "net"
"os" "os"
"os/exec" "os/exec"
@@ -12,8 +11,6 @@ import (
"time" "time"
"plg-mudics/shared" "plg-mudics/shared"
"github.com/micmonay/keybd_event"
) )
func GetDeviceIp() (string, error) { func GetDeviceIp() (string, error) {
@@ -47,46 +44,6 @@ func GetDeviceMac() (string, error) {
return "", fmt.Errorf("no suitable MAC address found") 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) { func TakeScreenshot() (string, error) {
tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix())) tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix()))
@@ -100,7 +57,6 @@ func TakeScreenshot() (string, error) {
if commandOutput.ExitCode == 0 { if commandOutput.ExitCode == 0 {
return tempFilePath, nil return tempFilePath, nil
} }
slog.Warn("Screenshot error", "error", commandOutput.Stderr)
} }
return "", errors.New("no screenshot utility found or all failed") return "", errors.New("no screenshot utility found or all failed")
} }
+5 -10
View File
@@ -15,6 +15,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
shared "plg-mudics/shared" shared "plg-mudics/shared"
"strings"
"github.com/gabriel-vasile/mimetype" "github.com/gabriel-vasile/mimetype"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
@@ -35,7 +36,9 @@ func StartWebServer(v string, port string) {
e.GET("/", indexRoute) e.GET("/", indexRoute)
e.GET("/sse", sseRoute) e.GET("/sse", sseRoute)
e.GET("/splash", func(ctx echo.Context) error { e.GET("/splash", func(ctx echo.Context) error {
return ctx.HTML(http.StatusOK, shared.SplashScreenTemplate) html := shared.SplashScreenTemplate
html = strings.ReplaceAll(html, "%%APP-VERSION%%", version)
return ctx.HTML(http.StatusOK, html)
}) })
e.GET("/qr", qrRoute) e.GET("/qr", qrRoute)
@@ -213,12 +216,6 @@ func keyboardInputRoute(ctx echo.Context) error {
return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: fmt.Sprintf("Invalid action: %s", input.Action)}) 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 var action pkg.KeyAction
if input.Action == "press" { if input.Action == "press" {
action = pkg.KeyPress action = pkg.KeyPress
@@ -228,7 +225,7 @@ func keyboardInputRoute(ctx echo.Context) error {
} }
inputs = append(inputs, pkg.Input{ inputs = append(inputs, pkg.Input{
Key: code, Key: input.Key,
Action: action, Action: action,
}) })
} }
@@ -325,7 +322,6 @@ func openFileRoute(ctx echo.Context) error {
err = resetView() err = resetView()
if err != nil { if err != nil {
slog.Error("Failed to reset view", "error", err) slog.Error("Failed to reset view", "error", err)
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to reset view"})
} }
mType, err := mimetype.DetectFile(fullPath) mType, err := mimetype.DetectFile(fullPath)
@@ -372,7 +368,6 @@ func showHTMLRoute(ctx echo.Context) error {
err := resetView() err := resetView()
if err != nil { if err != nil {
slog.Error("Failed to reset view", "error", err) slog.Error("Failed to reset view", "error", err)
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to reset view"})
} }
sseConnection <- request.HTML sseConnection <- request.HTML
+39 -36
View File
@@ -1,16 +1,15 @@
package web package web
templ indexTemplate() { templ indexTemplate() {
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<head> <meta charset="UTF-8"/>
<meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>PLG MuDiCS Display</title>
<title>PLG Connect Display</title> <script src="/static/htmx.min.js"></script>
<script src="/static/htmx.min.js"></script> <script src="/static/htmx-ext-sse.min.js"></script>
<script src="/static/htmx-ext-sse.min.js"></script> <style>
<style>
:root { :root {
--background-color: black; --background-color: black;
--foreground-color: oklch(92.3% 0.003 48.717); --foreground-color: oklch(92.3% 0.003 48.717);
@@ -33,6 +32,7 @@ templ indexTemplate() {
background-color: var(--background-color); background-color: var(--background-color);
color: var(--foreground-color); color: var(--foreground-color);
font-family: ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; font-family: ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
cursor: none;
} }
video, video,
@@ -60,7 +60,7 @@ templ indexTemplate() {
padding-left: calc(var(--font-size)*1.5); padding-left: calc(var(--font-size)*1.5);
} }
</style> </style>
<script> <script>
document.addEventListener('keydown', function (event) { document.addEventListener('keydown', function (event) {
if (event.code === 'Space') { if (event.code === 'Space') {
event.preventDefault(); event.preventDefault();
@@ -75,42 +75,45 @@ templ indexTemplate() {
} }
}); });
</script> </script>
</head> </head>
<bod> <bod>
<div hx-get="/splash" hx-trigger="load"></div> <div hx-get="/splash" hx-trigger="load"></div>
<main hx-ext="sse" sse-connect="/sse" sse-swap="message"></main> <main hx-ext="sse" sse-connect="/sse" sse-swap="message"></main>
</bod> </bod>
</html>
</html>
} }
templ videoTemplate(path string) { templ videoTemplate(path string) {
<video autoplay> <video autoplay>
<source src={ "/api/file/" + path } type="video/mp4" /> <source src={ "/api/file/" + path } type="video/mp4"/>
</video> </video>
} }
templ imageTemplate(path string) { templ imageTemplate(path string) {
<img src={ "/api/file/" + path } /> <img src={ "/api/file/" + path }/>
} }
templ deviceInfoTemplate(ip string, mac string, showQR bool) { templ deviceInfoTemplate(ip string, mac string, showQR bool) {
<div style="width: 100vw; height: 100vh; display: flex; flex-direction: row; justify-content: space-between;"> <div style="width: 100vw; height: 100vh; display: flex; flex-direction: row; justify-content: space-between;">
<div <div
style="display: flex; flex-direction: column; gap: 1rem; justify-content: end; padding: 2rem; font-size: 4rem;"> style="display: flex; flex-direction: column; gap: 1rem; justify-content: end; padding: 2rem; font-size: 4rem;"
{ ip } >
<span style="text-transform: uppercase;">{ mac }</span> { ip }
</div> <span style="text-transform: uppercase;">{ mac }</span>
if showQR {
<div style="display: flex; justify-content: end; align-items: end; padding: 2rem;">
<div style="padding: 1rem; background-color: var(--foreground-color); border-radius: 1rem;">
<img style="height: 30vh; width: auto; image-rendering: pixelated; image-rendering: crisp-edges;"
src={ "/qr?data=http://" + ip + ":8080" } alt="QR-Code" />
</div> </div>
if showQR {
<div style="display: flex; justify-content: end; align-items: end; padding: 2rem;">
<div style="padding: 1rem; background-color: var(--foreground-color); border-radius: 1rem;">
<img
style="height: 30vh; width: auto; image-rendering: pixelated; image-rendering: crisp-edges;"
src={ "/qr?data=http://" + ip + ":8080" }
alt="QR-Code"
/>
</div>
</div>
}
</div> </div>
} <style>
</div>
<style>
:root { :root {
--splash-bg: transparent !important; --splash-bg: transparent !important;
--splash-fade-out-state: paused !important; --splash-fade-out-state: paused !important;
+5 -14
View File
@@ -1,24 +1,15 @@
github.com/a-h/htmlformat v0.0.0-20250209131833-673be874c677/go.mod h1:FMIm5afKmEfarNbIXOaPHFY8X7fo+fRQB6I9MPG2nB0= github.com/a-h/htmlformat v0.0.0-20250209131833-673be874c677/go.mod h1:FMIm5afKmEfarNbIXOaPHFY8X7fo+fRQB6I9MPG2nB0=
github.com/a-h/templ v0.3.960 h1:trshEpGa8clF5cdI39iY4ZrZG8Z/QixyzEyUnA7feTM=
github.com/a-h/templ v0.3.960/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs= golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0= golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
golang.org/x/telemetry v0.0.0-20250710130107-8d8967aff50b/go.mod h1:4ZwOYna0/zsOKwuR5X/m0QFOJpSZvAxFfkQT+Erd9D4= golang.org/x/telemetry v0.0.0-20250710130107-8d8967aff50b/go.mod h1:4ZwOYna0/zsOKwuR5X/m0QFOJpSZvAxFfkQT+Erd9D4=
golang.org/x/telemetry v0.0.0-20251111182119-bc8e575c7b54/go.mod h1:hKdjCMrbv9skySur+Nek8Hd0uJ0GuxJIoIX2payrIdQ=
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0= golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg= golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+15 -2
View File
@@ -86,7 +86,6 @@
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
# Programs # Programs
libreoffice libreoffice
#rustdesk
ungoogled-chromium ungoogled-chromium
xfce.thunar-archive-plugin xfce.thunar-archive-plugin
git git
@@ -94,6 +93,8 @@
unzip unzip
iputils iputils
xreader xreader
tree
jq
# Libraries # Libraries
imagemagick imagemagick
@@ -115,7 +116,7 @@
after = ["network-online.target"]; after = ["network-online.target"];
wants = ["network-online.target"]; wants = ["network-online.target"];
path = config.environment.systemPackages; path = config.environment.systemPackages;
script = "nu ${./update.sh}"; script = "nu ${./update.nu}";
serviceConfig = { serviceConfig = {
WorkingDirectory = "/home/mudics/mudics"; WorkingDirectory = "/home/mudics/mudics";
User = "mudics"; User = "mudics";
@@ -137,6 +138,7 @@
environment = { environment = {
DISPLAY = ":0"; DISPLAY = ":0";
XDG_RUNTIME_DIR = "/run/user/1000"; XDG_RUNTIME_DIR = "/run/user/1000";
XDG_DATA_DIRS = "/run/current-system/sw/share";
}; };
}; };
@@ -150,6 +152,17 @@
}; };
}; };
systemd.services.enable-wol = {
wantedBy = ["multi-user.target"];
after = ["network.target"];
path = with pkgs; [ethtool nushell];
script = "nu ${./wol.nu}";
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [
"d /home/mudics/mudics 0755 mudics - -" "d /home/mudics/mudics 0755 mudics - -"
]; ];
+8 -8
View File
@@ -7,32 +7,32 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1763992789, "lastModified": 1767910483,
"narHash": "sha256-WHkdBlw6oyxXIra/vQPYLtqY+3G8dUVZM8bEXk0t8x4=", "narHash": "sha256-MOU5YdVu4DVwuT5ztXgQpPuRRBjSjUGIdUzOQr9iQOY=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "44831a7eaba4360fb81f2acc5ea6de5fde90aaa3", "rev": "82fb7dedaad83e5e279127a38ef410bcfac6d77c",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "owner": "nix-community",
"ref": "release-25.05", "ref": "release-25.11",
"repo": "home-manager", "repo": "home-manager",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1761999846, "lastModified": 1767799921,
"narHash": "sha256-IYlYnp4O4dzEpL77BD/lj5NnJy2J8qbHkNSFiPBCbqo=", "narHash": "sha256-r4GVX+FToWVE2My8VVZH4V0pTIpnu2ZE8/Z4uxGEMBE=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "3de8f8d73e35724bf9abef41f1bdbedda1e14a31", "rev": "d351d0653aeb7877273920cd3e823994e7579b0b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-25.05", "ref": "nixos-25.11",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
+2 -2
View File
@@ -1,9 +1,9 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
home-manager = { home-manager = {
url = "github:nix-community/home-manager/release-25.05"; url = "github:nix-community/home-manager/release-25.11";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
View File
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env nu
ls /sys/class/net | get name | path basename | where $it != "lo" | each {|iface|
print $"Enabling WoL on ($iface)..."
try {
ethtool -s $iface wol g
print $"Successfully enabled WoL on ($iface)"
} catch {
print $"Failed to enable WoL on ($iface). It might not be supported."
}
}
+5
View File
@@ -2,7 +2,12 @@ package shared
import ( import (
_ "embed" _ "embed"
"strings"
) )
//go:embed splash_screen.html //go:embed splash_screen.html
var SplashScreenTemplate string var SplashScreenTemplate string
//go:embed version.txt
var versionNotTrimmed string
var Version = strings.TrimSpace(versionNotTrimmed)
-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"
}
+18 -10
View File
@@ -5,23 +5,31 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
) )
func OpenBrowserWindow(url string, fullscreen bool, temp bool) error { func OpenBrowserWindow(url string, fullscreen bool, profile string) error {
bins := []string{"chromium", "chromium-browser"} bins := []string{"chromium", "chromium-browser"}
args := []string{fmt.Sprintf("--app=%s", url), "--autoplay-policy=no-user-gesture-required"} home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("unable to determine user home directory: %w", err)
}
browserProfileDirPath := filepath.Join(home, ".local", "share", "plg-mudics", fmt.Sprintf("browser-%s", profile))
if err := os.MkdirAll(browserProfileDirPath, os.ModePerm); err != nil {
return fmt.Errorf("failed to create local config directory: %w", err)
}
args := []string{
fmt.Sprintf("--app=%s", url),
"--autoplay-policy=no-user-gesture-required",
fmt.Sprintf("--user-data-dir=%s", browserProfileDirPath),
"--allow-running-insecure-content",
"--disable-features=XFrameOptions",
}
if fullscreen { if fullscreen {
args = append(args, "--start-fullscreen") args = append(args, "--start-fullscreen")
} }
if temp {
tempDirPath, err := os.MkdirTemp("", "plg-mudics-browser-")
if err != nil {
return err
}
arg := fmt.Sprintf("--user-data-dir=%s", tempDirPath)
args = append(args, arg)
}
errs := []string{} errs := []string{}
for _, bin := range bins { for _, bin := range bins {
+441 -222
View File
@@ -1,267 +1,486 @@
<div id="splash"> <div id="splash">
<svg id="splash-svg" viewBox="0 0 950 550"> <svg id="splash-svg" class="fade-in" viewBox="0 0 950 550">
<!-- Paths --> <!-- Paths -->
<!-- Disabled Paths --> <!-- Disabled Paths -->
<path class="splash-stroke" d="M 385 350 V 270 H 100 V 112.5" /> <path class="splash-stroke" d="M 385 350 V 270 H 100 V 112.5" />
<path class="splash-stroke" d="M 445 350 V 210 H 350 V 112.5" /> <path class="splash-stroke" d="M 445 350 V 210 H 350 V 112.5" />
<path class="splash-stroke" d="M 505 350 V 210 H 600 V 112.5" /> <path class="splash-stroke" d="M 505 350 V 210 H 600 V 112.5" />
<path class="splash-stroke" d="M 565 350 V 270 H 850 V 112.5" /> <path class="splash-stroke" d="M 565 350 V 270 H 850 V 112.5" />
<!-- Masks --> <!-- Masks -->
<defs> <defs>
<mask id="m1" maskUnits="userSpaceOnUse" maskContentUnits="userSpaceOnUse"> <mask
<path class="splash-mask" pathLength="100" d="M 385 350 V 270 H 100 V 112.5" /> id="m1"
</mask> maskUnits="userSpaceOnUse"
<mask id="m2" maskUnits="userSpaceOnUse" maskContentUnits="userSpaceOnUse"> maskContentUnits="userSpaceOnUse"
<path class="splash-mask" pathLength="100" d="M 445 350 V 210 H 350 V 112.5" /> >
</mask> <path
<mask id="m3" maskUnits="userSpaceOnUse" maskContentUnits="userSpaceOnUse"> class="splash-mask"
<path class="splash-mask" pathLength="100" d="M 505 350 V 210 H 600 V 112.5" /> pathLength="100"
</mask> d="M 385 350 V 270 H 100 V 112.5"
<mask id="m4" maskUnits="userSpaceOnUse" maskContentUnits="userSpaceOnUse"> />
<path class="splash-mask" pathLength="100" d="M 565 350 V 270 H 850 V 112.5" /> </mask>
</mask> <mask
</defs> id="m2"
<!-- Active Paths --> maskUnits="userSpaceOnUse"
<path class="splash-stroke-active" mask="url(#m1)" d="M 385 350 V 270 H 100 V 112.5" /> maskContentUnits="userSpaceOnUse"
<path class="splash-stroke-active" mask="url(#m2)" d="M 445 350 V 210 H 350 V 112.5" /> >
<path class="splash-stroke-active" mask="url(#m3)" d="M 505 350 V 210 H 600 V 112.5" /> <path
<path class="splash-stroke-active" mask="url(#m4)" d="M 565 350 V 270 H 850 V 112.5" /> class="splash-mask"
pathLength="100"
d="M 445 350 V 210 H 350 V 112.5"
/>
</mask>
<mask
id="m3"
maskUnits="userSpaceOnUse"
maskContentUnits="userSpaceOnUse"
>
<path
class="splash-mask"
pathLength="100"
d="M 505 350 V 210 H 600 V 112.5"
/>
</mask>
<mask
id="m4"
maskUnits="userSpaceOnUse"
maskContentUnits="userSpaceOnUse"
>
<path
class="splash-mask"
pathLength="100"
d="M 565 350 V 270 H 850 V 112.5"
/>
</mask>
</defs>
<!-- Active Paths -->
<path
class="splash-stroke-active"
mask="url(#m1)"
d="M 385 350 V 270 H 100 V 112.5"
/>
<path
class="splash-stroke-active"
mask="url(#m2)"
d="M 445 350 V 210 H 350 V 112.5"
/>
<path
class="splash-stroke-active"
mask="url(#m3)"
d="M 505 350 V 210 H 600 V 112.5"
/>
<path
class="splash-stroke-active"
mask="url(#m4)"
d="M 565 350 V 270 H 850 V 112.5"
/>
<!-- Displays --> <!-- Displays -->
<rect x="0" y="0" width="200" height="112.5" rx="8" ry="8" class="splash-monitor" /> <rect
<rect x="250" y="0" width="200" height="112.5" rx="8" ry="8" class="splash-monitor" /> x="0"
<rect x="500" y="0" width="200" height="112.5" rx="8" ry="8" class="splash-monitor" /> y="0"
<rect x="750" y="0" width="200" height="112.5" rx="8" ry="8" class="splash-monitor" /> width="200"
height="112.5"
rx="8"
ry="8"
class="splash-monitor"
/>
<rect
x="250"
y="0"
width="200"
height="112.5"
rx="8"
ry="8"
class="splash-monitor"
/>
<rect
x="500"
y="0"
width="200"
height="112.5"
rx="8"
ry="8"
class="splash-monitor"
/>
<rect
x="750"
y="0"
width="200"
height="112.5"
rx="8"
ry="8"
class="splash-monitor"
/>
<!-- Text --> <!-- Text -->
<text class="splash-text" x="100" y="66.25" font-size="90">Mu</text> <text class="splash-text" x="100" y="66.25" font-size="90">Mu</text>
<text class="splash-text" x="350" y="66.25" font-size="90">Di</text> <text class="splash-text" x="350" y="66.25" font-size="90">Di</text>
<text class="splash-text" x="600" y="66.25" font-size="90">C</text> <text class="splash-text" x="600" y="66.25" font-size="90">C</text>
<text class="splash-text" x="850" y="66.25" font-size="90">S</text> <text class="splash-text" x="850" y="66.25" font-size="90">S</text>
<!-- Controller --> <!-- Controller -->
<rect x="325" y="350" width="300" height="168.75" rx="8" ry="8" class="splash-control-monitor" /> <rect
<rect x="335" y="390" width="135" height="120" rx="8" ry="8" class="splash-other-button" /> x="325"
<rect x="480" y="390" width="135" height="55" rx="8" ry="8" class="splash-other-button" /> y="350"
<rect x="480" y="455" width="135" height="55" rx="8" ry="8" class="splash-start-button" /> width="300"
height="168.75"
rx="8"
ry="8"
class="splash-control-monitor"
/>
<rect
x="335"
y="390"
width="135"
height="120"
rx="8"
ry="8"
class="splash-other-button"
/>
<rect
x="480"
y="390"
width="135"
height="55"
rx="8"
ry="8"
class="splash-other-button"
/>
<rect
x="480"
y="455"
width="135"
height="55"
rx="8"
ry="8"
class="splash-start-button"
/>
<!-- Window Controls --> <!-- Window Controls -->
<path class="window-controls" d="M 600 360 L 615 375" /> <path class="window-controls" d="M 600 360 l 15 15" />
<path class="window-controls" d="M 600 375 L 615 360" /> <path class="window-controls" d="M 600 375 l 15 -15" />
<path class="window-controls" fill="none" d="M 575 360 H 590 V 375 H 575 V 360" /> <path
<path class="window-controls" d="M 550 375 H 565" /> class="window-controls"
fill="none"
d="M 575 360 h 15 v 15 h -15 v -15"
/>
<path class="window-controls" d="M 550 375 h 15" />
</svg>
<svg class="cursor" width="50" height="50" viewBox="0 0 24 24" x="510" y="480" aria-hidden="true"> <span id="version-label" aria-label="Version">%%APP-VERSION%%</span>
<g stroke="#ffffff" fill="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path stroke="#000000" d="M 6.5 10 H 18 V 19 H 6" /> <div class="fade-in">
<path d="M22 14a8 8 0 0 1-8 8" /> <div
<path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2" /> class="cursor-x"
<path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1" /> style="
<path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10" /> position: absolute;
<path left: calc(50cqw + var(--mouse-start-x));
d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15" /> top: calc(50cqh + var(--mouse-start-y));
</g> "
</svg> >
</svg> <svg class="cursor-y" width="50" height="50" viewBox="0 0 24 24">
<g
stroke="#ffffff"
fill="#000000"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="#000000" d="M 6.5 10 H 18 V 19 H 6" />
<path d="M22 14a8 8 0 0 1-8 8" />
<path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2" />
<path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1" />
<path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10" />
<path
d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"
/>
</g>
</svg>
</div>
</div>
</div> </div>
<style> <style>
:root { :root {
--splash-fade-out-delay: 0s; --splash-fade-out-delay: 0s;
--splash-fade-out-state: running; --splash-fade-out-state: running;
--base-stroke: #444444; --base-stroke: #444444;
--base-stroke-active: #109e00; --base-stroke-active: #109e00;
--splash-bg: oklch(21.6% 0.006 56.043); --splash-bg: oklch(21.6% 0.006 56.043);
--monitor-dark: #000000; --monitor-dark: #000000;
--monitor-active: #ffffff; --monitor-active: #ffffff;
--window-controls: #cccccc; --window-controls: #cccccc;
--start-button-inactive: #cccccc; --start-button-inactive: #cccccc;
--start-button-hover: #77a3b1; --start-button-hover: #77a3b1;
--start-button-active: #2c819b; --start-button-active: #2c819b;
--other-button: oklch(55.3% 0.013 58.071); --other-button: oklch(55.3% 0.013 58.071);
--splash-control-monitor: oklch(44.4% 0.011 73.639); --splash-control-monitor: oklch(44.4% 0.011 73.639);
--stroke-strength: 8; --version-color: oklch(55.3% 0.013 58.071);
--dash: 16;
--gap: 20;
}
--mouse-size: 50px;
--mouse-bounce-delay: 5s;
--mouse-start-x: calc((35 * 100vw) / 1920);
--mouse-start-y: calc((60 * 100vh) / 1080);
#splash { --dur-x: 16s;
position: fixed; --dur-y: 9s;
inset: 0;
background: var(--splash-bg);
color: white;
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
/* animation: splash-fade 1s ease 4s forwards; */
height: 100vh;
width: 100vw;
animation-name: splash-fade; --stroke-strength: 8;
animation-duration: 1s; --dash: 16;
animation-timing-function: ease; --gap: 20;
animation-fill-mode: forwards; }
animation-delay: var(--splash-fade-out-delay);
animation-play-state: var(--splash-fade-out-state);
}
#splash-svg { #version-label {
max-height: 50vh; position: absolute;
max-width: 80vw; right: 1rem;
opacity: 0; top: 1rem;
animation: fade-in 1s ease 500ms forwards; display: block;
} color: var(--version-color);
padding: 0.4rem 0.8rem;
font-size: 1.4rem;
text-align: right;
}
.splash-monitor { #splash {
aspect-ratio: 16/9; position: fixed;
rx: 8; inset: 0;
ry: 8; background: var(--splash-bg);
width: 200; color: white;
fill: var(--monitor-dark); display: flex;
} align-items: center;
justify-content: center;
z-index: 9999;
height: 100vh;
width: 100vw;
.splash-control-monitor { animation-name: splash-fade;
fill: var(--splash-control-monitor); animation-duration: 1s;
} animation-timing-function: ease;
animation-fill-mode: forwards;
animation-delay: var(--splash-fade-out-delay);
animation-play-state: var(--splash-fade-out-state);
}
.splash-other-button { #splash-svg {
fill: var(--other-button); max-height: 50vh;
} max-width: 80vw;
transform: translateY(-12cqh);
}
.splash-stroke, .fade-in {
.splash-stroke-active { opacity: 0;
fill: none; animation: fade-in 1s ease 500ms forwards;
stroke-linecap: round; }
stroke-linejoin: round;
stroke-width: var(--stroke-strength);
stroke-dasharray: var(--dash) var(--gap);
}
.window-controls { .splash-monitor {
stroke: var(--window-controls); aspect-ratio: 16/9;
stroke-width: 3; rx: 8;
} ry: 8;
width: 200;
fill: var(--monitor-dark);
}
.splash-stroke { .splash-control-monitor {
stroke: var(--base-stroke); fill: var(--splash-control-monitor);
} }
.splash-stroke-active { .splash-other-button {
stroke: var(--base-stroke-active); fill: var(--other-button);
} }
.splash-mask { .splash-stroke,
fill: none; .splash-stroke-active {
stroke: #fff; fill: none;
stroke-linecap: round; stroke-linecap: round;
stroke-width: var(--stroke-strength); stroke-linejoin: round;
stroke-dasharray: 100; stroke-width: var(--stroke-strength);
stroke-dashoffset: 100; stroke-dasharray: var(--dash) var(--gap);
animation: draw 1s ease-in-out 1.35s forwards; }
}
.splash-text { .window-controls {
text-anchor: middle; stroke: var(--window-controls);
dominant-baseline: middle; stroke-width: 3;
fill: var(--monitor-dark); }
user-select: none;
font-family: sans-serif;
}
.splash-monitor { .splash-stroke {
fill: var(--monitor-dark); stroke: var(--base-stroke);
animation: activate-monitor 0ms ease 2.35s forwards; }
}
.splash-start-button { .splash-stroke-active {
fill: var(--start-button-inactive); stroke: var(--base-stroke-active);
animation: start-button-hover-press 1s ease-in-out 450ms forwards; }
}
.cursor { .splash-mask {
animation: move-mouse 1s ease-in-out 0ms forwards; fill: none;
} stroke: #fff;
stroke-linecap: round;
stroke-width: var(--stroke-strength);
stroke-dasharray: 100;
stroke-dashoffset: 100;
animation: draw 1s ease-in-out 1.35s forwards;
}
@keyframes fade-in { .splash-text {
to { text-anchor: middle;
opacity: 1; dominant-baseline: middle;
} fill: var(--monitor-dark);
} user-select: none;
font-family: sans-serif;
}
@keyframes move-mouse { .splash-monitor {
0% { fill: var(--monitor-dark);
transform: translateX(-100px); animation: activate-monitor 0ms ease 2.35s forwards;
} }
50% { .splash-start-button {
transform: translateX(-100px); fill: var(--start-button-inactive);
} animation: start-button-hover-press 1s ease-in-out 450ms forwards;
}
100% { .cursor-x {
transform: translateX(0px); animation-name: move-mouse, mouse-bounceX;
} animation-duration: 1s, var(--dur-x);
} animation-delay: 0s, var(--mouse-bounce-delay);
animation-iteration-count: 1, infinite;
animation-direction: normal, normal;
animation-timing-function: ease-in-out, linear;
animation-fill-mode: both, none;
will-change: transform;
}
@keyframes start-button-hover-press { .cursor-y {
0% { animation-name: mouse-bounceY;
fill: var(--start-button-inactive); animation-duration: var(--dur-y);
} animation-delay: var(--mouse-bounce-delay);
animation-iteration-count: infinite;
animation-direction: normal;
animation-timing-function: linear;
animation-fill-mode: none;
will-change: transform;
}
30% { @keyframes fade-in {
fill: var(--start-button-inactive); to {
} opacity: 1;
}
}
40% { @keyframes move-mouse {
fill: var(--start-button-hover); 0% {
} transform: translateX(-100px);
}
70% { 50% {
fill: var(--start-button-hover); transform: translateX(-100px);
} }
80% { 100% {
fill: var(--start-button-active); transform: translateX(0px);
} }
}
90% { @keyframes mouse-bounceX {
fill: var(--start-button-active); 0% {
} transform: translateX(0);
}
100% { 26% {
fill: var(--start-button-hover); transform: translateX(calc(-50cqw - var(--mouse-start-x)));
} }
}
@keyframes draw { 76% {
to { transform: translateX(
stroke-dashoffset: 0; calc(50cqw - var(--mouse-size) - var(--mouse-start-x))
} );
} }
}
@keyframes activate-monitor { @keyframes mouse-bounceY {
to { 0% {
fill: var(--monitor-active); transform: translateY(0);
} }
}
@keyframes splash-fade { 27% {
to { transform: translateY(calc(-50cqh - var(--mouse-start-y)));
opacity: 0; }
visibility: hidden;
}
}
rect { 77% {
vector-effect: non-scaling-stroke; transform: translateY(
} calc(50cqh - var(--mouse-size) - var(--mouse-start-y))
);
}
}
/* verhindert, dass die Linien beim Skalieren dicker werden */ @keyframes start-button-hover-press {
.cursor * { 0% {
vector-effect: non-scaling-stroke; fill: var(--start-button-inactive);
} }
30% {
fill: var(--start-button-inactive);
}
40% {
fill: var(--start-button-hover);
}
70% {
fill: var(--start-button-hover);
}
80% {
fill: var(--start-button-active);
}
90% {
fill: var(--start-button-active);
}
100% {
fill: var(--start-button-hover);
}
}
@keyframes draw {
to {
stroke-dashoffset: 0;
}
}
@keyframes activate-monitor {
to {
fill: var(--monitor-active);
}
}
@keyframes splash-fade {
to {
opacity: 0;
visibility: hidden;
}
}
rect {
vector-effect: non-scaling-stroke;
}
/* verhindert, dass die Linien beim Skalieren dicker werden */
.cursor * {
vector-effect: non-scaling-stroke;
}
</style> </style>
<script>
const r =
Math.random() < 0.01
? 9 / 15.039473684
: 0.55 + (Math.random() - 0.5) * 0.18;
const tx = 13 + Math.random() * 5;
document.documentElement.style.setProperty("--dur-x", tx + "s");
document.documentElement.style.setProperty("--dur-y", tx * r + "s");
</script>
+1
View File
@@ -0,0 +1 @@
v0.0.17