mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 17:07:08 +00:00
Compare commits
115 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2bfa1afd4 | |||
| 7dd6cb60f1 | |||
| 41d8c4755a | |||
| 21cb07a465 | |||
| 2dc46c186e | |||
| 2dd390e815 | |||
| 87eaf90c12 | |||
| 3174010e83 | |||
| ec7c3b407c | |||
| 2dcf5a7758 | |||
| 5ecf2da8a9 | |||
| a49b842a4c | |||
| a3d444df20 | |||
| fb31f732af | |||
| 5ea7ff3ce0 | |||
| a827a3e588 | |||
| 9284a8f72a | |||
| d969c041d0 | |||
| 0a9d3af3eb | |||
| b6150fdab0 | |||
| b6c637649f | |||
| a7582851b4 | |||
| 919bba7c2e | |||
| 64b8fcffe2 | |||
| 9e0d8762d9 | |||
| 07c8d7ea3d | |||
| aedd9fce44 | |||
| e74356f9a6 | |||
| 136bba25fe | |||
| 9b70e9aae9 | |||
| 79d122ded7 | |||
| 18d150c767 | |||
| 71f152ef2a | |||
| cbbf50e5a4 | |||
| 934dd42866 | |||
| d2add33a7c | |||
| b4f9215fd4 | |||
| 666f04e3c6 | |||
| eea15c558f | |||
| 9a4e2d4919 | |||
| 1138842269 | |||
| c7bf6fa6f7 | |||
| befa83131b | |||
| c865dbeeae | |||
| a5ee1b28d9 | |||
| 9e325566c5 | |||
| 168576db81 | |||
| 3a30aca1dc | |||
| f2a648b429 | |||
| 203e48c31c | |||
| 8b878b183b | |||
| a38827da54 | |||
| 25c0fe2b4b | |||
| c96b8fe7e4 | |||
| 671c74f25d | |||
| 4d5d9849da | |||
| c8e21a64bf | |||
| 2711d89f22 | |||
| c09e4b2d8d | |||
| 209080db22 | |||
| 4acbc96a58 | |||
| 99643f8029 | |||
| ef7dfa49fe | |||
| 7cfa56a906 | |||
| 63c7cea4ca | |||
| 0e87ca3ae1 | |||
| d61ef0fe94 | |||
| 5d1f3e2d20 | |||
| 6dfb29bbd1 | |||
| 49410bf372 | |||
| 5d22f62a6e | |||
| a31080c602 | |||
| ea3cbcb8c6 | |||
| a0cf45c8dc | |||
| 97d2608adf | |||
| 36d2887247 | |||
| 1e9148bff2 | |||
| 346e511bb4 | |||
| 54e10b98e2 | |||
| 83eaf34475 | |||
| b251e8951f | |||
| 31cb614958 | |||
| 8fb9f5b9db | |||
| d13fd347ac | |||
| 922b47bd1e | |||
| b57ea762bf | |||
| c171706d96 | |||
| 6d5aa9041f | |||
| c2d9a2b049 | |||
| f84a7c0520 | |||
| 7f6891ecff | |||
| d63fc5cac4 | |||
| 12f4ec7d6c | |||
| 86f23077ea | |||
| 47d462ba76 | |||
| 5533696aad | |||
| ac68939abd | |||
| d6bafd4e6f | |||
| ce28a1f771 | |||
| 7632229704 | |||
| b5e997e675 | |||
| ca08d6fb6a | |||
| 4ab8f43295 | |||
| fc59b576b5 | |||
| e2a9558d3f | |||
| 662bcb3b8d | |||
| 9044262ab6 | |||
| 6c654e295c | |||
| a2bbf19fee | |||
| 246549acdf | |||
| 80cee15576 | |||
| 1c59b40971 | |||
| 548f8ccba8 | |||
| 5b93250e22 | |||
| 5ca2487598 |
+11
@@ -1,2 +1,13 @@
|
|||||||
.aider*
|
.aider*
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
/display/internal/pdfjs/node_modules/*
|
||||||
|
|
||||||
|
!/display/internal/pdfjs/node_modules/pdfjs-dist/
|
||||||
|
/display/internal/pdfjs/node_modules/pdfjs-dist/*
|
||||||
|
|
||||||
|
!/display/internal/pdfjs/node_modules/pdfjs-dist/build/
|
||||||
|
/display/internal/pdfjs/node_modules/pdfjs-dist/build/*
|
||||||
|
|
||||||
|
!/display/internal/pdfjs/node_modules/pdfjs-dist/build/pdf.min.mjs
|
||||||
|
!/display/internal/pdfjs/node_modules/pdfjs-dist/build/pdf.worker.min.mjs
|
||||||
Executable
BIN
Binary file not shown.
Generated
+288
-291
File diff suppressed because it is too large
Load Diff
@@ -1,39 +0,0 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
|
||||||
|
|
||||||
test('page loads', async ({ page }) => {
|
|
||||||
await page.goto('/');
|
|
||||||
await expect(page.getByText('PLG MuDiCS')).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('page loads without problems', async ({ page }) => {
|
|
||||||
await page.goto('/');
|
|
||||||
await expect(page.getByText('PLG MuDiCS')).toBeVisible();
|
|
||||||
await expect(page.getByTestId('notification')).not.toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('diplay click shows files', async ({ page }) => {
|
|
||||||
await page.goto('/');
|
|
||||||
await page.getByTestId('display').click();
|
|
||||||
await expect(page.getByTestId('inode').first()).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('show text', async ({ page }) => {
|
|
||||||
await page.goto('/');
|
|
||||||
await page.getByTestId('display').click();
|
|
||||||
|
|
||||||
const controlButton = page.getByText('Text anzeigen');
|
|
||||||
await expect(controlButton).toBeVisible();
|
|
||||||
await controlButton.click();
|
|
||||||
|
|
||||||
const textPopup = page.getByTestId('text-popup');
|
|
||||||
await expect(textPopup).toBeVisible();
|
|
||||||
const textArea = textPopup.getByRole('textbox');
|
|
||||||
await expect(textArea).toBeVisible();
|
|
||||||
await textArea.fill('Hello, world!');
|
|
||||||
|
|
||||||
const submitButton = textPopup.locator('button').filter({ hasText: 'Text anzeigen' });
|
|
||||||
await submitButton.click();
|
|
||||||
await expect(
|
|
||||||
page.locator('[data-testid="notification"]:not(:has-text("Fehler 500"))')
|
|
||||||
).not.toBeVisible();
|
|
||||||
});
|
|
||||||
@@ -5,9 +5,6 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate deno install
|
|
||||||
//go:generate deno task build
|
|
||||||
|
|
||||||
//go:embed all:build
|
//go:embed all:build
|
||||||
var buildDir embed.FS
|
var buildDir embed.FS
|
||||||
|
|
||||||
|
|||||||
Generated
+963
-1196
File diff suppressed because it is too large
Load Diff
@@ -11,45 +11,42 @@
|
|||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
"lint": "eslint . && prettier --check .",
|
"lint": "eslint . && prettier --check .",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write ."
|
||||||
"test:e2e": "playwright test",
|
|
||||||
"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",
|
"@sveltejs/adapter-auto": "^6.1.1",
|
||||||
"@sveltejs/adapter-auto": "^6.0.0",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/adapter-static": "^3.0.9",
|
"@sveltejs/kit": "^2.49.3",
|
||||||
"@sveltejs/kit": "^2.22.0",
|
"@sveltejs/vite-plugin-svelte": "^6.2.3",
|
||||||
"@sveltejs/vite-plugin-svelte": "^6.0.0",
|
"@tailwindcss/vite": "^4.1.18",
|
||||||
"@tailwindcss/vite": "^4.0.0",
|
"@tiptap/extension-placeholder": "^3.15.3",
|
||||||
"@tiptap/extension-placeholder": "^3.11.0",
|
"eslint": "^9.39.2",
|
||||||
"eslint": "^9.18.0",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-config-prettier": "^10.0.1",
|
"eslint-plugin-svelte": "^3.14.0",
|
||||||
"eslint-plugin-svelte": "^3.0.0",
|
"globals": "^16.5.0",
|
||||||
"globals": "^16.0.0",
|
"prettier": "^3.7.4",
|
||||||
"prettier": "^3.4.2",
|
"prettier-plugin-svelte": "^3.4.1",
|
||||||
"prettier-plugin-svelte": "^3.3.3",
|
"sass-embedded": "^1.97.2",
|
||||||
"sass-embedded": "^1.93.3",
|
"svelte": "^5.46.1",
|
||||||
"svelte": "^5.0.0",
|
|
||||||
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import { defineConfig } from '@playwright/test';
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
fullyParallel: true,
|
|
||||||
webServer: {
|
|
||||||
command: 'deno task build && deno task preview',
|
|
||||||
port: 4173
|
|
||||||
},
|
|
||||||
testDir: 'e2e'
|
|
||||||
});
|
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { get_shifted_color } from '$lib/ts/stores/ui_behavior';
|
import { get_shifted_color } from '$lib/ts/stores/ui_behavior';
|
||||||
import type { MenuOption } from '$lib/ts/types';
|
import type { MenuOption } from '$lib/ts/types';
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
menu_options?: MenuOption[];
|
menu_options?: MenuOption[];
|
||||||
menu_class?: string;
|
menu_class?: string;
|
||||||
div_class?: string;
|
div_class?: string;
|
||||||
children?: any;
|
children: Snippet;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let menu_shown = $state(false);
|
let menu_shown = $state(false);
|
||||||
@@ -158,14 +159,14 @@
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#each menu_options as option}
|
{#each menu_options as option, i (i)}
|
||||||
<button
|
<button
|
||||||
disabled={option.disabled ?? false}
|
disabled={option.disabled ?? false}
|
||||||
class="bg-white/15 {option.disabled
|
class="bg-white/15 {option.disabled
|
||||||
? 'text-stone-500 cursor-not-allowed'
|
? 'text-stone-500 cursor-not-allowed'
|
||||||
: 'hover:bg-white/35 active:bg-white/60 cursor-pointer ' +
|
: 'hover:bg-white/35 active:bg-white/60 cursor-pointer ' +
|
||||||
option.class} rounded-lg p-2 transition-colors duration-200 select-none flex flex-row gap-2 items-center"
|
option.class} rounded-lg p-2 transition-colors duration-200 select-none flex flex-row gap-2 items-center"
|
||||||
onclick={async (e) => {
|
onclick={async () => {
|
||||||
if (option.on_select) await option.on_select();
|
if (option.on_select) await option.on_select();
|
||||||
close_menu();
|
close_menu();
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -3,45 +3,44 @@
|
|||||||
import {
|
import {
|
||||||
dnd_flip_duration_ms,
|
dnd_flip_duration_ms,
|
||||||
get_selectable_color_classes,
|
get_selectable_color_classes,
|
||||||
is_display_drag,
|
is_display_drag
|
||||||
is_group_drag
|
|
||||||
} from '$lib/ts/stores/ui_behavior';
|
} from '$lib/ts/stores/ui_behavior';
|
||||||
import { cubicOut } from 'svelte/easing';
|
|
||||||
import { flip } from 'svelte/animate';
|
|
||||||
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 { 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 { 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, display_version: string|undefined) => MenuOption[];
|
||||||
close_pinned_display: () => void;
|
close_pinned_display: () => void;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
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 +48,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 +83,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 +91,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 { 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, display_version: string|undefined) => 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, $display?.version)}
|
||||||
>
|
>
|
||||||
<Menu />
|
<Menu />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { add_upload } from '$lib/ts/file_transfer_handler';
|
||||||
|
import { selected_online_display_ids } from '$lib/ts/stores/displays';
|
||||||
|
import { current_file_path } from '$lib/ts/stores/files';
|
||||||
|
import HighlightedText from './HighlightedText.svelte';
|
||||||
|
|
||||||
|
let { className } = $props();
|
||||||
|
|
||||||
|
let drop_zone: HTMLDivElement | undefined;
|
||||||
|
|
||||||
|
let is_dragging = $state(false);
|
||||||
|
let is_dragging_over_drop_zone = $state(false);
|
||||||
|
let is_dragging_multiple_files = $state(false);
|
||||||
|
|
||||||
|
let drag_counter = 0;
|
||||||
|
|
||||||
|
function contains_files(event: DragEvent): boolean {
|
||||||
|
return Array.from(event.dataTransfer?.types ?? []).includes('Files');
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_drag_vars(): void {
|
||||||
|
drag_counter = 0;
|
||||||
|
is_dragging = false;
|
||||||
|
is_dragging_over_drop_zone = false;
|
||||||
|
is_dragging_multiple_files = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_inside_drop_zone(event: DragEvent): boolean {
|
||||||
|
if (!drop_zone) return false;
|
||||||
|
|
||||||
|
const rect = drop_zone.getBoundingClientRect();
|
||||||
|
|
||||||
|
return (
|
||||||
|
event.clientX >= rect.left &&
|
||||||
|
event.clientX <= rect.right &&
|
||||||
|
event.clientY >= rect.top &&
|
||||||
|
event.clientY <= rect.bottom
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_window_drag_enter(event: DragEvent): void {
|
||||||
|
if (!contains_files(event)) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
drag_counter += 1;
|
||||||
|
is_dragging = true;
|
||||||
|
is_dragging_multiple_files =
|
||||||
|
(event.dataTransfer?.items.length ?? 0) > 1;
|
||||||
|
|
||||||
|
if (event.dataTransfer) {
|
||||||
|
event.dataTransfer.dropEffect = 'copy';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_window_drag_over(event: DragEvent): void {
|
||||||
|
if (!contains_files(event)) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
is_dragging = true;
|
||||||
|
is_dragging_multiple_files =
|
||||||
|
(event.dataTransfer?.items.length ?? 0) > 1;
|
||||||
|
|
||||||
|
is_dragging_over_drop_zone =
|
||||||
|
$selected_online_display_ids.length > 0 &&
|
||||||
|
is_inside_drop_zone(event);
|
||||||
|
|
||||||
|
if (event.dataTransfer) {
|
||||||
|
event.dataTransfer.dropEffect = 'copy';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_window_drag_leave(event: DragEvent): void {
|
||||||
|
if (!contains_files(event) && !is_dragging) return;
|
||||||
|
|
||||||
|
drag_counter = Math.max(0, drag_counter - 1);
|
||||||
|
|
||||||
|
if (drag_counter === 0) {
|
||||||
|
reset_drag_vars();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_window_drop_capture(event: DragEvent): void {
|
||||||
|
if (!contains_files(event)) return;
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_window_drop(event: DragEvent): void {
|
||||||
|
if (!contains_files(event)) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
reset_drag_vars();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handle_drop_zone_drop(
|
||||||
|
event: DragEvent
|
||||||
|
): Promise<void> {
|
||||||
|
if (!contains_files(event)) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
const may_import =
|
||||||
|
$selected_online_display_ids.length > 0 &&
|
||||||
|
is_inside_drop_zone(event);
|
||||||
|
|
||||||
|
const items = Array.from(event.dataTransfer?.items ?? []);
|
||||||
|
|
||||||
|
reset_drag_vars();
|
||||||
|
|
||||||
|
if (!may_import) return;
|
||||||
|
|
||||||
|
const transfer = new DataTransfer();
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.kind !== 'file') continue;
|
||||||
|
|
||||||
|
const file = item.getAsFile();
|
||||||
|
const entry = item.webkitGetAsEntry?.();
|
||||||
|
|
||||||
|
if (file && (!entry || entry.isFile)) {
|
||||||
|
transfer.items.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transfer.files.length === 0) return;
|
||||||
|
|
||||||
|
await add_upload(
|
||||||
|
transfer.files,
|
||||||
|
$selected_online_display_ids,
|
||||||
|
$current_file_path
|
||||||
|
);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window
|
||||||
|
ondragenter={handle_window_drag_enter}
|
||||||
|
ondragover={handle_window_drag_over}
|
||||||
|
ondragleave={handle_window_drag_leave}
|
||||||
|
ondrop={handle_window_drop}
|
||||||
|
ondropcapture={handle_window_drop_capture}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="fixed {is_dragging
|
||||||
|
? 'bg-black/50 opacity-100'
|
||||||
|
: 'opacity-0'} pointer-events-none p-10 z-1000 inset-0 transition-all duration-100 flex items-center justify-center text-xl text-white font-bold select-none"
|
||||||
|
>
|
||||||
|
{$selected_online_display_ids.length === 0
|
||||||
|
? 'Für das Hochladen von Dateien müssen erreichbare Displays ausgewählt werden!'
|
||||||
|
: ''}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
bind:this={drop_zone}
|
||||||
|
aria-hidden="true"
|
||||||
|
ondrop={handle_drop_zone_drop}
|
||||||
|
class="{className} absolute p-6 inset-0 flex z-1001 justify-center items-center transition-all duration-200 {$selected_online_display_ids.length >
|
||||||
|
0 && is_dragging
|
||||||
|
? 'opacity-100'
|
||||||
|
: 'opacity-0 pointer-events-none'} {is_dragging_over_drop_zone
|
||||||
|
? 'bg-stone-500'
|
||||||
|
: 'bg-stone-700'}"
|
||||||
|
>
|
||||||
|
<p class="text-lg pointer-events-none">
|
||||||
|
Hier {is_dragging_multiple_files ? 'Dateien' : 'Datei'} ablegen, um sie auf {$selected_online_display_ids.length ===
|
||||||
|
1
|
||||||
|
? 'dem ausgewählten Display'
|
||||||
|
: 'den ausgewählten Displays'} in den Pfad <HighlightedText
|
||||||
|
className="transition-colors duration-200"
|
||||||
|
bg={is_dragging_over_drop_zone ? 'bg-stone-550' : 'bg-stone-750'}
|
||||||
|
>{$current_file_path}</HighlightedText
|
||||||
|
> hochzuladen
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type { Snippet } from "svelte";
|
||||||
|
|
||||||
let {
|
let {
|
||||||
children,
|
children,
|
||||||
bg = 'bg-stone-750',
|
bg = 'bg-stone-750',
|
||||||
fg = 'text-stone-200',
|
fg = 'text-stone-200',
|
||||||
className = ''
|
className = ''
|
||||||
}: {
|
}: {
|
||||||
children: any;
|
children: Snippet;
|
||||||
bg?: string;
|
bg?: string;
|
||||||
fg?: string;
|
fg?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ArrowRight, Ban, FileIcon, Folder, Play } from 'lucide-svelte';
|
import { ArrowRight, Ban, FileIcon, Folder, Play, TriangleAlert } from 'lucide-svelte';
|
||||||
import {
|
import {
|
||||||
current_height,
|
current_height,
|
||||||
get_selectable_color_classes,
|
get_selectable_color_classes,
|
||||||
@@ -10,73 +10,79 @@
|
|||||||
supported_file_type_icon,
|
supported_file_type_icon,
|
||||||
type Inode,
|
type Inode,
|
||||||
get_file_primary_key,
|
get_file_primary_key,
|
||||||
type FileOnDisplay,
|
type FileTransferTask,
|
||||||
type FileLoadingData
|
is_folder
|
||||||
} from '$lib/ts/types';
|
} from '$lib/ts/types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
is_selected,
|
is_selected,
|
||||||
select,
|
select,
|
||||||
selected_display_ids,
|
|
||||||
selected_file_ids
|
selected_file_ids
|
||||||
} from '$lib/ts/stores/select';
|
} from '$lib/ts/stores/select';
|
||||||
import {
|
import {
|
||||||
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 {
|
||||||
|
run_on_all_selected_displays,
|
||||||
|
selected_online_display_ids
|
||||||
|
} 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 { add_sync_recursively, 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();
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const s = $selected_file_ids;
|
const f = file;
|
||||||
missing_colliding_displays_ids = liveQuery(() => get_missing_colliding_display_ids(file, s));
|
const s = $selected_online_display_ids;
|
||||||
|
missing_colliding_displays_ids = liveQuery(() => get_missing_colliding_display_ids(f, s));
|
||||||
});
|
});
|
||||||
|
|
||||||
let loading_data:
|
let colliding_warning: boolean = $derived(
|
||||||
| Observable<{
|
!!$missing_colliding_displays_ids && $missing_colliding_displays_ids.colliding.length !== 0
|
||||||
is_loading: boolean;
|
);
|
||||||
total_percentage: number;
|
|
||||||
total_seconds_until_finish: number;
|
let file_size: Observable<number> | undefined = $state();
|
||||||
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 file_transfer_task_list: FileTransferTask[] | null = $derived(
|
||||||
|
Object.hasOwn($file_transfer_tasks, file_primary_key)
|
||||||
|
? $file_transfer_tasks[file_primary_key]
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
let loading_finished = $state(false);
|
let loading_finished = $state(false);
|
||||||
|
let previous_loading_state = $state(false);
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!loading_data) return;
|
const ftt = file_transfer_task_list;
|
||||||
let prev: boolean | undefined;
|
if (previous_loading_state && !ftt) {
|
||||||
const sub = loading_data.subscribe((v) => {
|
|
||||||
if (prev === true && v.is_loading === false) {
|
|
||||||
loading_finished = true;
|
loading_finished = true;
|
||||||
setTimeout(() => (loading_finished = false), 200);
|
setTimeout(() => (loading_finished = false), 200);
|
||||||
}
|
}
|
||||||
prev = v.is_loading;
|
previous_loading_state = !!ftt;
|
||||||
});
|
|
||||||
return () => sub.unsubscribe();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let thumbnail_url = liveQuery(() => get_thumbnail_url(get_file_primary_key(file)));
|
let thumbnail_url = liveQuery(() => get_thumbnail_url(file_primary_key));
|
||||||
let date_mapping: Observable<Record<string, Date>> = liveQuery(() =>
|
let date_mapping: Observable<Record<string, Date>> = liveQuery(() =>
|
||||||
get_date_mapping(get_file_primary_key(file))
|
get_date_mapping(file_primary_key)
|
||||||
);
|
);
|
||||||
|
|
||||||
const is_folder = file.type === 'inode/directory';
|
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 +141,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_list) 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,21 +149,26 @@
|
|||||||
|
|
||||||
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_list) 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_list) 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 if (
|
||||||
|
!!$missing_colliding_displays_ids &&
|
||||||
|
$missing_colliding_displays_ids.missing.length !== 0
|
||||||
|
) {
|
||||||
|
await add_sync_recursively(get_file_primary_key(file), $selected_online_display_ids, true);
|
||||||
} else {
|
} else {
|
||||||
const path_to_file = $current_file_path + file.name;
|
const path_to_file = $current_file_path + file.name;
|
||||||
await run_on_all_selected_displays((d) => open_file(d.ip, path_to_file));
|
await run_on_all_selected_displays((d) => open_file(d.ip, path_to_file));
|
||||||
@@ -169,11 +180,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_list) {
|
||||||
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 +196,7 @@
|
|||||||
|
|
||||||
if (not_interactable) {
|
if (not_interactable) {
|
||||||
out += ' rounded-lg';
|
out += ' rounded-lg';
|
||||||
} else if ($loading_data?.is_loading) {
|
} else if (file_transfer_task_list) {
|
||||||
out += ' rounded-r-lg';
|
out += ' rounded-r-lg';
|
||||||
} else {
|
} else {
|
||||||
out += ' rounded-r-lg cursor-pointer';
|
out += ' rounded-r-lg cursor-pointer';
|
||||||
@@ -194,49 +205,45 @@
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function get_loading_data(
|
function get_total_percentage(ftt_list: FileTransferTask[]): number {
|
||||||
file_primary_key: string,
|
|
||||||
selected_display_ids: string[]
|
|
||||||
): Promise<{
|
|
||||||
is_loading: boolean;
|
|
||||||
total_percentage: number;
|
|
||||||
total_seconds_until_finish: number;
|
|
||||||
display_data: FileLoadingData[];
|
|
||||||
}> {
|
|
||||||
const file_on_display_data: FileOnDisplay[] = await db.files_on_display
|
|
||||||
.where('file_primary_key')
|
|
||||||
.equals(file_primary_key)
|
|
||||||
.filter((e) => selected_display_ids.includes(e.display_id))
|
|
||||||
.toArray();
|
|
||||||
if (file_on_display_data.length === 0) {
|
|
||||||
return {
|
|
||||||
is_loading: true,
|
|
||||||
total_percentage: 0,
|
|
||||||
total_seconds_until_finish: -1,
|
|
||||||
display_data: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const display_data = [];
|
|
||||||
let is_loading = false;
|
|
||||||
let percentage_sum = 0;
|
let percentage_sum = 0;
|
||||||
let total_seconds_until_finish = 0;
|
for (const ftt of ftt_list) {
|
||||||
for (const fod of file_on_display_data) {
|
percentage_sum += get_percentage(ftt);
|
||||||
if (!!fod.loading_data) {
|
}
|
||||||
if (!is_loading) is_loading = true;
|
return Math.round(percentage_sum / ftt_list.length);
|
||||||
percentage_sum += fod.loading_data.percentage;
|
}
|
||||||
total_seconds_until_finish += fod.loading_data.seconds_until_finish;
|
|
||||||
display_data.push(fod.loading_data);
|
|
||||||
|
function get_percentage(ftt: FileTransferTask): number {
|
||||||
|
let total_percentage: number;
|
||||||
|
if (ftt.data.type === 'upload') {
|
||||||
|
total_percentage = ftt.loading_data.percentage;
|
||||||
} else {
|
} else {
|
||||||
percentage_sum += 100;
|
const percentage_array = ftt.data.destination_display_data.map(
|
||||||
|
(dd) => dd.loading_data.percentage
|
||||||
|
);
|
||||||
|
total_percentage =
|
||||||
|
(ftt.loading_data.percentage + percentage_array.reduce((total, n) => total + n, 0)) /
|
||||||
|
(1 + percentage_array.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Math.min(total_percentage, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function get_size_recursively(file: Inode): Promise<number> {
|
||||||
|
if (is_folder(file)) {
|
||||||
|
const folder_elements = await get_folder_elements(
|
||||||
|
file.path + file.name + '/',
|
||||||
|
$selected_online_display_ids
|
||||||
|
);
|
||||||
|
let out: number = 0;
|
||||||
|
for (const el of folder_elements) {
|
||||||
|
out += await get_size_recursively(el);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} else {
|
||||||
|
return file.size;
|
||||||
}
|
}
|
||||||
let total_percentage = percentage_sum / display_data.length;
|
|
||||||
return {
|
|
||||||
is_loading,
|
|
||||||
total_percentage,
|
|
||||||
total_seconds_until_finish,
|
|
||||||
display_data
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -249,28 +256,38 @@
|
|||||||
{#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) || colliding_warning}
|
||||||
title={!is_folder && get_file_type(file) === null ? 'Dateityp nicht unterstützt' : ''}
|
title={!file_is_folder && get_file_type(file) === null
|
||||||
className="flex rounded-l-lg rounded-r-none {is_folder
|
? 'Dateityp nicht unterstützt'
|
||||||
|
: colliding_warning
|
||||||
|
? 'Dateien kollidieren auf verschiedenen Bildschirmen'
|
||||||
|
: ''}
|
||||||
|
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={colliding_warning
|
||||||
!is_folder && get_file_type(file) !== null,
|
? 'bg-red-400'
|
||||||
|
: get_selectable_color_classes(
|
||||||
|
!file_is_folder && get_file_type(file) !== null,
|
||||||
{
|
{
|
||||||
bg: true
|
bg: true
|
||||||
},
|
},
|
||||||
-50
|
-50
|
||||||
)}
|
)}
|
||||||
hover_bg={get_selectable_color_classes(
|
hover_bg={colliding_warning
|
||||||
!is_folder,
|
? 'bg-red-500'
|
||||||
|
: get_selectable_color_classes(
|
||||||
|
!file_is_folder,
|
||||||
{
|
{
|
||||||
bg: true
|
bg: true
|
||||||
},
|
},
|
||||||
50
|
50
|
||||||
)}
|
)}
|
||||||
active_bg={get_selectable_color_classes(
|
active_bg={colliding_warning
|
||||||
!is_folder,
|
? 'bg-red-500'
|
||||||
|
: get_selectable_color_classes(
|
||||||
|
!file_is_folder,
|
||||||
{
|
{
|
||||||
bg: true
|
bg: true
|
||||||
},
|
},
|
||||||
@@ -281,14 +298,16 @@
|
|||||||
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 get_file_type(file) === null}
|
||||||
<RefreshPlay className="size-full" />
|
|
||||||
{:else if get_file_type(file) !== null}
|
|
||||||
<Play class="size-full" strokeWidth="3" />
|
|
||||||
{:else}
|
|
||||||
<Ban class="size-full" strokeWidth="3" />
|
<Ban class="size-full" strokeWidth="3" />
|
||||||
|
{:else if colliding_warning}
|
||||||
|
<TriangleAlert class="size-full" strokeWidth="3" />
|
||||||
|
{:else if !!$missing_colliding_displays_ids && $missing_colliding_displays_ids.missing.length !== 0}
|
||||||
|
<RefreshPlay className="size-full" />
|
||||||
|
{:else}
|
||||||
|
<Play class="size-full" strokeWidth="3" />
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -302,17 +321,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_list}
|
||||||
<!-- <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_list)}%;`}
|
||||||
></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,43 +346,16 @@
|
|||||||
{/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}
|
|
||||||
<Button
|
|
||||||
className="h-8 aspect-square transition-colors duration-200 !p-1.5 text-stone-100"
|
|
||||||
bg="bg-red-500"
|
|
||||||
click_function={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TriangleAlert class="size-full" />
|
|
||||||
</Button>
|
|
||||||
{:else if get_display_ids_where_file_is_missing($current_file_path, file, $selected_display_ids, $all_files)[0].length !== 0}
|
|
||||||
<Button
|
|
||||||
className="h-8 aspect-square transition-colors duration-200 !p-1.5"
|
|
||||||
bg="bg-transparent"
|
|
||||||
hover_bg={get_selectable_color_classes(false, {
|
|
||||||
bg: true
|
|
||||||
})}
|
|
||||||
active_bg={get_selectable_color_classes(false, {
|
|
||||||
bg: true
|
|
||||||
})}
|
|
||||||
click_function={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<RefreshCcwDot class="size-full" />
|
|
||||||
</Button>
|
|
||||||
{/if} -->
|
|
||||||
<div
|
<div
|
||||||
class="w-14 content-center text-center select-none text-xs whitespace-nowrap"
|
class="w-14 content-center text-center select-none text-xs whitespace-nowrap"
|
||||||
title={get_created_info($date_mapping, true)}
|
title={get_created_info($date_mapping, true)}
|
||||||
@@ -374,25 +364,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 } 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="popup 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();
|
||||||
|
|||||||
@@ -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' };
|
||||||
@@ -36,7 +40,7 @@ export async function send_keyboard_input(
|
|||||||
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' },
|
||||||
@@ -47,6 +51,17 @@ export async function show_html(ip: string, html: string) {
|
|||||||
await request_display(ip, '/showHTML', options);
|
await request_display(ip, '/showHTML', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function open_website(ip: string, url: string): Promise<void> {
|
||||||
|
const options = {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: { 'content-type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
url: url
|
||||||
|
})
|
||||||
|
};
|
||||||
|
await request_display(ip, '/openWebsite', options);
|
||||||
|
}
|
||||||
|
|
||||||
export async function get_file_data(
|
export async function get_file_data(
|
||||||
ip: string,
|
ip: string,
|
||||||
path: string
|
path: string
|
||||||
@@ -69,9 +84,11 @@ export async function get_file_data(
|
|||||||
`;
|
`;
|
||||||
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 null;
|
if (!raw_response.ok || !raw_response.json) return null;
|
||||||
|
if (!raw_response.ok) return null;
|
||||||
|
if (handle_shell_error(ip, raw_response, command, true)) return null;
|
||||||
|
|
||||||
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.stdout.trim() === '') return null;
|
||||||
if (handle_shell_error(ip, json_response, command, true)) return null;
|
|
||||||
|
|
||||||
const response: FileInfo[] = json_response.stdout
|
const response: FileInfo[] = json_response.stdout
|
||||||
.trim()
|
.trim()
|
||||||
@@ -91,6 +108,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;
|
||||||
@@ -99,31 +117,21 @@ export async function get_file_data(
|
|||||||
export async function get_file_tree_data(ip: string, path: string): Promise<TreeElement[] | null> {
|
export async function get_file_tree_data(ip: string, path: string): Promise<TreeElement[] | null> {
|
||||||
const command = `cd ".${path}" && tree -Js`;
|
const command = `cd ".${path}" && tree -Js`;
|
||||||
const raw_response = await run_shell_command(ip, command);
|
const raw_response = await run_shell_command(ip, command);
|
||||||
|
if (!raw_response.ok) return null;
|
||||||
|
if (handle_shell_error(ip, raw_response, command, true)) return null;
|
||||||
|
|
||||||
if (!raw_response.ok || !raw_response.json) return null;
|
|
||||||
const json_response = raw_response.json as ShellCommandResponse;
|
const json_response = raw_response.json as ShellCommandResponse;
|
||||||
if (handle_shell_error(ip, json_response, command, true)) return null;
|
|
||||||
|
|
||||||
const tree_element: TreeElement | null = JSON.parse(json_response.stdout.trim())[0] || null;
|
const tree_element: TreeElement | null = JSON.parse(json_response.stdout.trim())[0] || null;
|
||||||
|
|
||||||
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) return;
|
||||||
const json_response = raw_response.json as ShellCommandResponse;
|
handle_shell_error(ip, raw_response, command, true);
|
||||||
handle_shell_error(ip, json_response, command, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function rename_file(
|
export async function rename_file(
|
||||||
@@ -135,9 +143,8 @@ export async function rename_file(
|
|||||||
const command: string = `cd ".${path}" && mv "${old_file_name}" "${new_file_name}"`;
|
const command: string = `cd ".${path}" && mv "${old_file_name}" "${new_file_name}"`;
|
||||||
|
|
||||||
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) return;
|
||||||
const json_response = raw_response.json as ShellCommandResponse;
|
handle_shell_error(ip, raw_response, command, true);
|
||||||
handle_shell_error(ip, json_response, command, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function delete_files(
|
export async function delete_files(
|
||||||
@@ -150,9 +157,8 @@ export async function delete_files(
|
|||||||
command += ` && rm -r "${file_name}"`;
|
command += ` && rm -r "${file_name}"`;
|
||||||
}
|
}
|
||||||
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) return;
|
||||||
const json_response = raw_response.json as ShellCommandResponse;
|
handle_shell_error(ip, raw_response, command, true);
|
||||||
handle_shell_error(ip, json_response, command, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function show_blackscreen(ip: string): Promise<void> {
|
export async function show_blackscreen(ip: string): Promise<void> {
|
||||||
@@ -177,15 +183,21 @@ export async function get_thumbnail_blob(ip: string, path_to_file: string): Prom
|
|||||||
return raw_response.blob;
|
return raw_response.blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ping_ip(ip: string): Promise<DisplayStatus> {
|
export async function ping_ip(ip: string): Promise<{ status: DisplayStatus; version?: string }> {
|
||||||
const raw_response = await request_control(`/ping?ip=${ip}`, { method: 'GET' });
|
const raw_response = await request_control(`/ping?ip=${ip}`, { method: 'GET' });
|
||||||
if (!raw_response.ok || !raw_response.json) return null;
|
if (!raw_response.ok || !raw_response.json) return { status: null };
|
||||||
|
|
||||||
const status = raw_response.json.status;
|
const raw_status = raw_response.json.status;
|
||||||
if (typeof status === 'string') {
|
if (typeof raw_status === 'string') {
|
||||||
return to_display_status(status);
|
const status = to_display_status(raw_status);
|
||||||
|
const version = raw_response.json.version;
|
||||||
|
if (typeof version === 'string') {
|
||||||
|
return { status, version };
|
||||||
|
} else {
|
||||||
|
return { status };
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
return { status: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function request_display(
|
async function request_display(
|
||||||
@@ -195,14 +207,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,9 +241,6 @@ async function request(
|
|||||||
): Promise<RequestResponse> {
|
): Promise<RequestResponse> {
|
||||||
try {
|
try {
|
||||||
const cache_buster = `${url.includes('?') ? '&' : '?'}=${Date.now()}`;
|
const cache_buster = `${url.includes('?') ? '&' : '?'}=${Date.now()}`;
|
||||||
if (dev) {
|
|
||||||
console.debug('Sending request: ', url + cache_buster, 'with', options.body ?? 'none');
|
|
||||||
}
|
|
||||||
const response = await fetch(url + cache_buster, options);
|
const response = await fetch(url + cache_buster, options);
|
||||||
if (response.ok || supress_error_handling_http_codes.includes(response.status)) {
|
if (response.ok || supress_error_handling_http_codes.includes(response.status)) {
|
||||||
const contentType = response.headers.get('content-type') || '';
|
const contentType = response.headers.get('content-type') || '';
|
||||||
@@ -226,9 +251,6 @@ async function request(
|
|||||||
} else {
|
} else {
|
||||||
const json: Record<string, unknown> = await response.json();
|
const json: Record<string, unknown> = await response.json();
|
||||||
request_response = { ok: response.ok, http_code: response.status, json: json };
|
request_response = { ok: response.ok, http_code: response.status, json: json };
|
||||||
if (dev) {
|
|
||||||
console.debug(request_response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return request_response;
|
return request_response;
|
||||||
}
|
}
|
||||||
@@ -242,12 +264,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}`);
|
||||||
@@ -258,11 +285,21 @@ async function request(
|
|||||||
|
|
||||||
function handle_shell_error(
|
function handle_shell_error(
|
||||||
ip: string,
|
ip: string,
|
||||||
shell_response: ShellCommandResponse,
|
response: RequestResponse,
|
||||||
shell_command: string,
|
shell_command: string,
|
||||||
command_includs_cd: boolean
|
command_includs_cd: boolean,
|
||||||
|
response_type: 'json' | 'blob' = 'json'
|
||||||
): boolean {
|
): boolean {
|
||||||
if (shell_response.exitCode !== 0) {
|
if (
|
||||||
|
(response_type === 'json' && !response.json) ||
|
||||||
|
(response_type === 'blob' && !response.blob)
|
||||||
|
) {
|
||||||
|
const error_string = `Did not receive ${response_type}: ${JSON.stringify(response)}`;
|
||||||
|
console.error(error_string);
|
||||||
|
notifications.push('error', `Fehler in API-Shell`, `${ip}\n${shell_command}\n${error_string}`);
|
||||||
|
return true;
|
||||||
|
} else if (response.json && response.json.exitCode !== 0) {
|
||||||
|
const shell_response = response.json as ShellCommandResponse;
|
||||||
if (
|
if (
|
||||||
command_includs_cd &&
|
command_includs_cd &&
|
||||||
shell_response.stderr &&
|
shell_response.stderr &&
|
||||||
@@ -276,12 +313,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,8 +332,12 @@ async function run_shell_command(ip: string, command: string): Promise<RequestRe
|
|||||||
return await request_display(ip, '/shellCommand', options);
|
return await request_display(ip, '/shellCommand', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function shutdown(ip: string): Promise<RequestResponse> {
|
export async function shutdown(ip: string): Promise<boolean> {
|
||||||
return await run_shell_command(ip, 'xfce4-session-logout --halt');
|
const command = 'xfce4-session-logout --halt';
|
||||||
|
const raw_response = await run_shell_command(ip, command);
|
||||||
|
if (!raw_response.ok) return false;
|
||||||
|
if (handle_shell_error(ip, raw_response, command, true)) return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startup(mac: string): Promise<RequestResponse> {
|
export async function startup(mac: string): Promise<RequestResponse> {
|
||||||
|
|||||||
@@ -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, run_on_all_selected_displays } 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,
|
||||||
@@ -17,9 +20,30 @@ import {
|
|||||||
type ShortDisplay
|
type ShortDisplay
|
||||||
} 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';
|
||||||
|
import { open_file } from './api_handler';
|
||||||
|
|
||||||
|
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[] = [];
|
|
||||||
|
function add_file_transfer_task(file_primary_key: string, new_task: FileTransferTask) {
|
||||||
|
file_transfer_tasks.update((tasks) => {
|
||||||
|
if (Object.hasOwn(tasks, file_primary_key)) {
|
||||||
|
tasks[file_primary_key].push(new_task);
|
||||||
|
return tasks;
|
||||||
|
} else {
|
||||||
|
return { ...tasks, [file_primary_key]: [new_task] };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function add_upload(
|
export async function add_upload(
|
||||||
file_list: FileList,
|
file_list: FileList,
|
||||||
@@ -27,9 +51,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 +69,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.hasOwn(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 +82,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 +97,73 @@ 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
|
||||||
};
|
};
|
||||||
|
add_file_transfer_task(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[],
|
||||||
|
open_file_afterwards: boolean = false
|
||||||
|
) {
|
||||||
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
|
||||||
|
})),
|
||||||
|
open_file_afterwards_on_display_ids: open_file_afterwards ? selected_display_ids : []
|
||||||
},
|
},
|
||||||
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
|
||||||
});
|
};
|
||||||
|
|
||||||
|
add_file_transfer_task(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,15 +235,19 @@ 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,
|
||||||
|
list_index: number
|
||||||
|
): Promise<void> {
|
||||||
const task_data = task.data;
|
const task_data = task.data;
|
||||||
if (task_data.type !== 'upload' || !task_data.file)
|
if (task_data.type !== 'upload' || !task_data.file)
|
||||||
return console.warn('Task cancelled: wrong task type:', task);
|
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, list_index, task, task_data.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sync(task: FileTransferTask) {
|
export async function sync(file_primary_key: string, task: FileTransferTask, list_index: number) {
|
||||||
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 =
|
||||||
@@ -213,7 +255,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.'
|
||||||
);
|
);
|
||||||
@@ -226,7 +269,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 });
|
||||||
@@ -239,21 +282,39 @@ 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, list_index, value.byteLength, start_time);
|
||||||
await writable.write(value);
|
await writable.write(value);
|
||||||
}
|
}
|
||||||
await writable.close();
|
await writable.close();
|
||||||
|
|
||||||
|
finish_loading_data(file_primary_key, list_index);
|
||||||
|
|
||||||
// 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,
|
||||||
|
list_index,
|
||||||
|
task,
|
||||||
|
temp_file,
|
||||||
|
current_short_display.display
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await dir.removeEntry(temp_name);
|
await dir.removeEntry(temp_name);
|
||||||
|
|
||||||
|
// open file, if required
|
||||||
|
if (task.data.open_file_afterwards_on_display_ids.length !== 0) {
|
||||||
|
const path_to_file = task.path + task.file_name;
|
||||||
|
await run_on_all_selected_displays(
|
||||||
|
(d) => open_file(d.ip, path_to_file),
|
||||||
|
true,
|
||||||
|
task.data.open_file_afterwards_on_display_ids
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
show_error(task, String(e));
|
show_general_error(file_primary_key, task, String(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,8 +323,7 @@ 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')
|
if (!file_data || is_folder(file_data.file)) return console.warn('Download cancelled: is folder');
|
||||||
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)}`;
|
||||||
@@ -286,57 +346,76 @@ 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_list = tasks[current_file_id];
|
||||||
|
|
||||||
|
for (const [list_index, current_task] of current_task_list.entries()) {
|
||||||
if (current_task.data.type === 'upload') {
|
if (current_task.data.type === 'upload') {
|
||||||
await upload(current_task);
|
await upload(current_file_id, current_task, list_index);
|
||||||
} else if (current_task.data.type === 'sync') {
|
} else if (current_task.data.type === 'sync') {
|
||||||
await sync(current_task);
|
await sync(current_file_id, current_task, list_index);
|
||||||
|
}
|
||||||
|
delete_current_task_if_needed(current_file_id);
|
||||||
}
|
}
|
||||||
tasks.shift(); // Remove current_task from tasks
|
|
||||||
}
|
}
|
||||||
is_processing = false;
|
is_processing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete_current_task_if_needed(current_file_id: string) {
|
||||||
|
file_transfer_tasks.update((all_tasks) => {
|
||||||
|
const next = { ...all_tasks };
|
||||||
|
const current_tasks = next[current_file_id];
|
||||||
|
if (current_tasks.length !== 1) {
|
||||||
|
if (current_tasks.find((t) => t.loading_data.percentage !== 100)) {
|
||||||
|
return next; // not all tasks are finished -> do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete next[current_file_id];
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function upload_file_via_xhr(
|
async function upload_file_via_xhr(
|
||||||
|
file_primary_key: string,
|
||||||
|
list_index: number,
|
||||||
task: FileTransferTask,
|
task: FileTransferTask,
|
||||||
current_short_display: ShortDisplay,
|
current_file: File,
|
||||||
current_file: File
|
destination_short_display: ShortDisplay | null = null
|
||||||
) {
|
) {
|
||||||
const start_time = new Date();
|
const start_time = new Date();
|
||||||
const loading_type = task.data.type === 'upload' ? 'upload' : 'sync_upload';
|
|
||||||
|
|
||||||
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(
|
update_current_loading_data(
|
||||||
loading_type,
|
file_primary_key,
|
||||||
task,
|
list_index,
|
||||||
e.loaded,
|
e.loaded,
|
||||||
start_time,
|
start_time,
|
||||||
current_short_display.id
|
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();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -344,21 +423,22 @@ async function upload_file_via_xhr(
|
|||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
// set loading_data to 100%
|
// set loading_data to 100%
|
||||||
await db.files_on_display.update([current_short_display.id, task.file_primary_key], {
|
finish_loading_data(
|
||||||
date_created: new Date(),
|
file_primary_key,
|
||||||
loading_data: null
|
list_index,
|
||||||
});
|
destination_short_display ? destination_short_display.id : null
|
||||||
|
);
|
||||||
// Generate Thumbnail if not done already
|
// Generate Thumbnail if not done already
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const inode_element: Inode | undefined = await db.files.get(
|
const inode_element: Inode | undefined = await db.files.get(
|
||||||
JSON.parse(task.file_primary_key) as [string, string, number, string]
|
JSON.parse(file_primary_key) as [string, string, number, string]
|
||||||
);
|
);
|
||||||
if (!!inode_element && inode_element.thumbnail === null) {
|
if (!!inode_element && inode_element.thumbnail === null) {
|
||||||
await generate_thumbnail(task.display.ip, task.path, inode_element);
|
await generate_thumbnail(task.display.ip, task.path, inode_element);
|
||||||
}
|
}
|
||||||
}, 10);
|
}, 10);
|
||||||
} else {
|
} else {
|
||||||
await show_error(task, `HTTP ${xhr.status}`);
|
await show_general_error(file_primary_key, task, `HTTP ${xhr.status}`);
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
@@ -368,30 +448,89 @@ async function upload_file_via_xhr(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function update_current_loading_data(
|
function finish_loading_data(
|
||||||
type: FileLoadingData['type'],
|
file_primary_key: string,
|
||||||
task: FileTransferTask,
|
list_index: number,
|
||||||
|
destination_display_id: string | null = null
|
||||||
|
) {
|
||||||
|
file_transfer_tasks.update((tasks) => {
|
||||||
|
const current_loading_data = {
|
||||||
|
percentage: 100,
|
||||||
|
bytes_per_second: 0,
|
||||||
|
seconds_until_finish: 0
|
||||||
|
};
|
||||||
|
const new_task_list = tasks[file_primary_key].map((task, index) =>
|
||||||
|
index === list_index
|
||||||
|
? get_updated_task(current_loading_data, destination_display_id, task)
|
||||||
|
: task
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...tasks,
|
||||||
|
[file_primary_key]: new_task_list
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_current_loading_data(
|
||||||
|
file_primary_key: string,
|
||||||
|
list_index: number,
|
||||||
current_bytes: number,
|
current_bytes: number,
|
||||||
start_time: Date,
|
start_time: Date,
|
||||||
other_display_id: string | null = null
|
destination_display_id: string | null = null
|
||||||
) {
|
) {
|
||||||
|
file_transfer_tasks.update((tasks) => {
|
||||||
|
const task = tasks[file_primary_key][list_index];
|
||||||
|
if (!task) return tasks;
|
||||||
|
|
||||||
const current_percentage = Math.min(
|
const current_percentage = Math.min(
|
||||||
task.bytes_total > 0 ? Math.round((current_bytes / task.bytes_total) * 100) : 1,
|
task.bytes_total > 0 ? Math.round((current_bytes / task.bytes_total) * 100) : 1,
|
||||||
99
|
99
|
||||||
); // calculate percantage, but maximum value is 99%
|
);
|
||||||
const prognosed_data = get_prognosed_data(start_time, current_bytes, task.bytes_total);
|
const prognosed_data = get_prognosed_data(start_time, current_bytes, task.bytes_total);
|
||||||
|
|
||||||
await db.files_on_display.update(
|
const current_loading_data: FileLoadingData = {
|
||||||
[other_display_id ? other_display_id : task.display.id, task.file_primary_key],
|
|
||||||
{
|
|
||||||
loading_data: {
|
|
||||||
type,
|
|
||||||
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
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
const new_task_list = tasks[file_primary_key].map((task, index) =>
|
||||||
|
index === list_index
|
||||||
|
? get_updated_task(current_loading_data, destination_display_id, task)
|
||||||
|
: task
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...tasks,
|
||||||
|
[file_primary_key]: new_task_list
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
@@ -406,7 +545,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(
|
||||||
@@ -415,12 +558,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`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,34 +1,75 @@
|
|||||||
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 { db } from './database';
|
import { db } from './database';
|
||||||
|
import { update_changed_directories } from './stores/files';
|
||||||
|
|
||||||
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[] = [];
|
||||||
await db.files.clear();
|
|
||||||
await db.files_on_display.clear();
|
export async function on_app_start() {
|
||||||
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();
|
||||||
|
for (const display of not_loading_displays) {
|
||||||
|
await update_display_status(display);
|
||||||
}
|
}
|
||||||
if (new_status !== display.status) {
|
}
|
||||||
display.status = new_status;
|
|
||||||
|
export async function update_display_status(display: Display): Promise<DisplayStatus> {
|
||||||
|
const resp = await ping_ip(display.ip);
|
||||||
|
if (resp.version && display.version !== resp.version) {
|
||||||
|
display.version = resp.version;
|
||||||
await db.displays.put(display); // save
|
await db.displays.put(display); // save
|
||||||
}
|
}
|
||||||
|
if (resp.status === null && display.status !== null) return null;
|
||||||
|
if (resp.status !== display.status) {
|
||||||
|
let run_on_display_start = false;
|
||||||
|
// status change
|
||||||
|
if (resp.status === 'app_offline') {
|
||||||
|
loading_display_ids.push(display.id);
|
||||||
|
} else {
|
||||||
|
remove_display_from_loading_displays(display.id);
|
||||||
|
if (resp.status === 'app_online') {
|
||||||
|
run_on_display_start = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display.status = resp.status;
|
||||||
|
await db.displays.put(display); // save
|
||||||
|
if (run_on_display_start) await on_display_start(display);
|
||||||
|
}
|
||||||
|
return resp.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_changed_directories(display);
|
||||||
await screenshot_loop(display.id);
|
screenshot_loop(display.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,34 @@
|
|||||||
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 { 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);
|
||||||
|
const current_online_display_ids = value.map((d) => d.id);
|
||||||
|
selected_online_display_ids.set(get(selected_display_ids).filter((id) => current_online_display_ids.includes(id)));
|
||||||
|
});
|
||||||
|
|
||||||
|
export const selected_online_display_ids: Writable<string[]> = writable<string[]>([]);
|
||||||
|
|
||||||
|
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();
|
||||||
@@ -17,8 +40,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;
|
||||||
@@ -30,7 +53,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,
|
||||||
@@ -39,7 +62,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(
|
||||||
@@ -47,11 +72,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) {
|
||||||
@@ -63,6 +96,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(
|
||||||
@@ -104,7 +138,14 @@ 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) {
|
||||||
|
setTimeout(async () => {
|
||||||
|
let settings = get(preview_settings);
|
||||||
|
if (settings.mode === 'never') return;
|
||||||
|
|
||||||
|
const initial_retry_count = settings.retry_count.now;
|
||||||
|
const retry_seconds = get(preview_settings).retry_seconds.now;
|
||||||
|
|
||||||
const display = await db.displays.get(display_id);
|
const display = await db.displays.get(display_id);
|
||||||
if (!display || display.preview.currently_updating) return;
|
if (!display || display.preview.currently_updating) return;
|
||||||
|
|
||||||
@@ -115,9 +156,14 @@ export async function screenshot_loop(display_id: string, initial_retry_count: n
|
|||||||
|
|
||||||
let retry_count = initial_retry_count;
|
let retry_count = initial_retry_count;
|
||||||
while (retry_count > 0) {
|
while (retry_count > 0) {
|
||||||
retry_count -= 1;
|
settings = get(preview_settings);
|
||||||
|
if (settings.mode === 'never') break;
|
||||||
|
if (settings.mode !== 'always') retry_count -= 1;
|
||||||
|
|
||||||
const new_blob = await get_screenshot(display.ip);
|
const new_blob = await get_screenshot(display.ip);
|
||||||
|
settings = get(preview_settings);
|
||||||
|
if (settings.mode === 'never') break;
|
||||||
|
|
||||||
if (!new_blob) {
|
if (!new_blob) {
|
||||||
display.preview = { currently_updating: false, url: null };
|
display.preview = { currently_updating: false, url: null };
|
||||||
await db.displays.update(display.id, { preview: display.preview });
|
await db.displays.update(display.id, { preview: display.preview });
|
||||||
@@ -136,30 +182,36 @@ export async function screenshot_loop(display_id: string, initial_retry_count: n
|
|||||||
retry_count = initial_retry_count;
|
retry_count = initial_retry_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 2000)); // sleep 2s
|
await new Promise((resolve) => setTimeout(resolve, retry_seconds * 1000)); // sleep
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
run_function: (display: Display) => void | Promise<void>,
|
run_function: (display: Display) => void | Promise<void>,
|
||||||
update_screenshot_afterwards: boolean = true,
|
update_screenshot_afterwards: boolean = true,
|
||||||
ignore_offline: boolean = true
|
display_ids: string[] | null = null
|
||||||
) {
|
) {
|
||||||
|
if (!display_ids) display_ids = get(selected_online_display_ids);
|
||||||
const maybe_displays: (Display | null)[] = await Promise.all(
|
const maybe_displays: (Display | null)[] = await Promise.all(
|
||||||
// fails when only a single promis fails
|
// fails when only a single promis fails
|
||||||
get(selected_display_ids).map(async (id) => await get_display_by_id(id))
|
display_ids.map(async (id) => await get_display_by_id(id))
|
||||||
);
|
);
|
||||||
const displays: Display[] = maybe_displays.filter((d): d is Display => d !== null);
|
const displays: Display[] = maybe_displays.filter((d): d is Display => d !== null);
|
||||||
|
|
||||||
Promise.all(
|
await Promise.all(
|
||||||
displays.map(async (display) => {
|
displays.map(async (display) => {
|
||||||
if (!display || (ignore_offline && display.status === 'host_offline')) return;
|
if (!display) 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);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -169,27 +221,59 @@ 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
setTimeout(add_testing_displays, 0);
|
setTimeout(add_testing_displays, 0);
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
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,
|
||||||
type TreeElement
|
type TreeElement
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { get_display_by_id } from './displays';
|
import { get_display_by_id, online_displays, selected_online_display_ids } 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>('/');
|
||||||
|
|
||||||
@@ -24,17 +26,19 @@ export async function change_file_path(new_path: string) {
|
|||||||
|
|
||||||
deactivate_old_thumbnail_urls();
|
deactivate_old_thumbnail_urls();
|
||||||
|
|
||||||
const displays = await db.displays.toArray();
|
for (const display of get(online_displays)) {
|
||||||
|
await update_changed_directories(display, new_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const display of displays) {
|
export async function update_changed_directories(display: Display, path: string = '/') {
|
||||||
const changed_paths = await get_changed_directory_paths(display, new_path);
|
const changed_paths = await get_changed_directory_paths(display, path);
|
||||||
if (!changed_paths) continue;
|
if (!changed_paths) return;
|
||||||
console.debug('Update file system from', display.name, ':', changed_paths);
|
console.debug('Update file system from', display.name, ':', changed_paths);
|
||||||
for (const path of changed_paths) {
|
for (const path of changed_paths) {
|
||||||
await update_folder_elements_recursively(display, path);
|
await update_folder_elements_recursively(display, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export async function delete_and_deselect_unique_files_from_display(display_id: string) {
|
export async function delete_and_deselect_unique_files_from_display(display_id: string) {
|
||||||
const files_on_display = await db.files_on_display
|
const files_on_display = await db.files_on_display
|
||||||
@@ -42,16 +46,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() {
|
||||||
@@ -70,7 +96,10 @@ export async function update_current_folder_on_selected_displays() {
|
|||||||
});
|
});
|
||||||
const current_path = get(current_file_path);
|
const current_path = get(current_file_path);
|
||||||
|
|
||||||
for (const display of await db.displays.where('id').anyOf(get(selected_display_ids)).toArray()) {
|
for (const display of await db.displays
|
||||||
|
.where('id')
|
||||||
|
.anyOf(get(selected_online_display_ids))
|
||||||
|
.toArray()) {
|
||||||
await update_folder_elements_recursively(display, current_path);
|
await update_folder_elements_recursively(display, current_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,13 +112,19 @@ export async function get_missing_colliding_display_ids(
|
|||||||
|
|
||||||
const colliding: string[] = [];
|
const colliding: string[] = [];
|
||||||
const colliding_files = await db.files
|
const colliding_files = await db.files
|
||||||
.where('[path+name]')
|
.where('name')
|
||||||
.equals([file.path, file.name])
|
.equals(file.name)
|
||||||
.filter((e) => e.size !== file.size || e.type !== file.type)
|
.filter((e) => e.path === file.path && e.size !== file.size)
|
||||||
.toArray();
|
.toArray();
|
||||||
for (const colliding_file of colliding_files) {
|
for (const colliding_file of colliding_files) {
|
||||||
colliding.push(
|
colliding.push(
|
||||||
...(await get_display_ids_where_file_is_missing(colliding_file, selected_display_ids))
|
...(
|
||||||
|
await db.files_on_display
|
||||||
|
.where('file_primary_key')
|
||||||
|
.equals(get_file_primary_key(colliding_file))
|
||||||
|
.filter((fod) => selected_display_ids.includes(fod.display_id))
|
||||||
|
.toArray()
|
||||||
|
).map((fod) => fod.display_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,12 +146,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 +159,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);
|
||||||
@@ -204,16 +237,27 @@ async function get_recursive_changed_directory_paths(
|
|||||||
return has_changed;
|
return has_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function update_folder_elements_recursively(
|
async function update_folder_elements_recursively(
|
||||||
display: Display,
|
display: Display,
|
||||||
file_path: string = '/'
|
file_path: string = '/'
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
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 loading_file_ids = Object.keys(get(file_transfer_tasks));
|
||||||
|
const loading_file_keys_without_size = (
|
||||||
|
await db.files.bulkGet(
|
||||||
|
loading_file_ids.map((string_id) => JSON.parse(string_id) as [string, string, number, string])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.filter((f) => !!f)
|
||||||
|
.map((f) => JSON.stringify([f.path, f.name, f.type]));
|
||||||
|
|
||||||
|
// Filter new files, which aren't currently uploading
|
||||||
const existing_files_on_display_in_path: FileOnDisplay[] = await db.files_on_display
|
const existing_files_on_display_in_path: FileOnDisplay[] = await db.files_on_display
|
||||||
.where('display_id')
|
.where('display_id')
|
||||||
.equals(display.id)
|
.equals(display.id)
|
||||||
|
.filter((f) => !loading_file_ids.includes(f.file_primary_key))
|
||||||
.toArray();
|
.toArray();
|
||||||
const existing_file_keys_on_display_in_path: [string, string, number, string][] =
|
const existing_file_keys_on_display_in_path: [string, string, number, string][] =
|
||||||
existing_files_on_display_in_path.map(
|
existing_files_on_display_in_path.map(
|
||||||
@@ -225,17 +269,14 @@ export async function update_folder_elements_recursively(
|
|||||||
.filter((e) => e.path === file_path)
|
.filter((e) => e.path === file_path)
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
const existing_files_with_loading_state: { folder_element: Inode; is_loading: boolean }[] =
|
const diff = get_folder_elements_difference(existing_files, new_folder_elements);
|
||||||
existing_files.map((folder_element) => ({
|
|
||||||
folder_element,
|
|
||||||
is_loading: !!existing_files_on_display_in_path.find(
|
|
||||||
(e) => e.file_primary_key === get_file_primary_key(folder_element)
|
|
||||||
)?.loading_data
|
|
||||||
}));
|
|
||||||
|
|
||||||
const diff = get_folder_elements_difference(
|
// Filter new files, which aren't currently uploading -> don't compare size
|
||||||
existing_files_with_loading_state,
|
diff.new = diff.new.filter(
|
||||||
new_folder_elements
|
(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) {
|
||||||
@@ -245,12 +286,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 + '/'
|
||||||
@@ -268,30 +308,28 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_folder_elements_difference(
|
function get_folder_elements_difference(
|
||||||
old_elements: { folder_element: Inode; is_loading: boolean }[],
|
old_elements: Inode[],
|
||||||
new_elements: { folder_element: Inode; date_created: Date }[]
|
new_elements: { folder_element: Inode; date_created: Date }[]
|
||||||
): { deleted: Inode[]; new: { folder_element: Inode; date_created: Date }[] } {
|
): { deleted: Inode[]; new: { folder_element: Inode; date_created: Date }[] } {
|
||||||
const old_keys = new Set(old_elements.map((e) => get_file_primary_key(e.folder_element)));
|
const old_keys = new Set(old_elements.map((e) => get_file_primary_key(e)));
|
||||||
const new_keys = new Set(new_elements.map((e) => get_file_primary_key(e.folder_element)));
|
const new_keys = new Set(new_elements.map((e) => get_file_primary_key(e.folder_element)));
|
||||||
|
|
||||||
const only_in_old = old_elements
|
const only_in_old = old_elements.filter((e) => !new_keys.has(get_file_primary_key(e)));
|
||||||
.filter((e) => !new_keys.has(get_file_primary_key(e.folder_element)) && !e.is_loading)
|
|
||||||
.map((e) => e.folder_element);
|
|
||||||
const only_in_new = new_elements.filter(
|
const only_in_new = new_elements.filter(
|
||||||
(e) => !old_keys.has(get_file_primary_key(e.folder_element))
|
(e) => !old_keys.has(get_file_primary_key(e.folder_element))
|
||||||
);
|
);
|
||||||
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][] = (
|
||||||
@@ -300,7 +338,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);
|
||||||
@@ -308,8 +346,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;
|
||||||
@@ -344,7 +382,7 @@ export async function get_file_by_id(
|
|||||||
export async function run_for_selected_files_on_selected_displays(
|
export async function run_for_selected_files_on_selected_displays(
|
||||||
action: (ip: string, file_names: string[]) => Promise<void>
|
action: (ip: string, file_names: string[]) => Promise<void>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const display_id of get(selected_display_ids)) {
|
for (const display_id of get(selected_online_display_ids)) {
|
||||||
const file_key_strings_on_display: string[] = (
|
const file_key_strings_on_display: string[] = (
|
||||||
await db.files_on_display.where('display_id').equals(display_id).toArray()
|
await db.files_on_display.where('display_id').equals(display_id).toArray()
|
||||||
).map((e) => e.file_primary_key);
|
).map((e) => e.file_primary_key);
|
||||||
@@ -368,37 +406,23 @@ export async function run_for_selected_files_on_selected_displays(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function create_folder_on_all_selected_displays(
|
export async function create_path_on_all_selected_displays(
|
||||||
folder_name: string,
|
|
||||||
path: string,
|
path: string,
|
||||||
selected_display_ids: string[]
|
selected_display_ids: string[]
|
||||||
): Promise<void> {
|
) {
|
||||||
const path_parts = path
|
const displays_without_path = await get_displays_where_path_not_exists(
|
||||||
.slice(1, path.length - 1)
|
path,
|
||||||
.split('/')
|
selected_display_ids
|
||||||
.filter((e) => e.length !== 0);
|
);
|
||||||
let remaining_display_ids = [...selected_display_ids];
|
if (displays_without_path.length === 0) return;
|
||||||
|
for (const display of displays_without_path) {
|
||||||
const getDisplaysForPath = async (currentPath: string): Promise<Display[]> => {
|
await create_path(display.ip, path);
|
||||||
if (currentPath === '/') {
|
|
||||||
const displays = await db.displays.bulkGet(remaining_display_ids);
|
|
||||||
return displays.filter((d): d is Display => !!d);
|
|
||||||
}
|
|
||||||
return get_displays_where_path_exists(currentPath, remaining_display_ids, false);
|
|
||||||
};
|
|
||||||
|
|
||||||
for (let depth = path_parts.length; depth >= 0 && remaining_display_ids.length; depth--) {
|
|
||||||
const currentPath = depth === 0 ? '/' : `/${path_parts.slice(0, depth).join('/')}/`;
|
|
||||||
|
|
||||||
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) {
|
||||||
|
await update_changed_directories(display);
|
||||||
}
|
}
|
||||||
|
}, 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,4 +1,5 @@
|
|||||||
import { writable, type Writable } from 'svelte/store';
|
import { get, writable, type Writable } from 'svelte/store';
|
||||||
|
import { online_displays, selected_online_display_ids } from './displays';
|
||||||
|
|
||||||
export const selected_file_ids: Writable<string[]> = writable<string[]>([]); // JSON.stringify([string, string, number, string])
|
export const selected_file_ids: Writable<string[]> = writable<string[]>([]); // JSON.stringify([string, string, number, string])
|
||||||
export const selected_display_ids: Writable<string[]> = writable<string[]>([]);
|
export const selected_display_ids: Writable<string[]> = writable<string[]>([]);
|
||||||
@@ -19,6 +20,11 @@ export function select(
|
|||||||
}
|
}
|
||||||
return all_ids;
|
return all_ids;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (selected_ids === selected_display_ids) {
|
||||||
|
const current_online_display_ids = get(online_displays).map((d) => d.id);
|
||||||
|
selected_online_display_ids.set(get(selected_display_ids).filter((id) => current_online_display_ids.includes(id)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function is_selected(id: string, selected_ids: string[]): boolean {
|
export function is_selected(id: string, selected_ids: string[]): boolean {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -6,26 +8,48 @@ 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 pinned_display_id: Writable<string | null> = writable<string | null>(null);
|
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 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) => {
|
||||||
@@ -34,8 +58,12 @@ export function change_height(key: 'display' | 'file', factor: number) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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',
|
||||||
|
current_height_array: Record<string, number>,
|
||||||
|
factor: number
|
||||||
|
): number {
|
||||||
|
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) {
|
if (new_size > heights_options[key].max || new_size < heights_options[key].min) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -43,9 +71,6 @@ export function next_height_step_size(key: 'display' | 'file', current_height_ar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 } = {},
|
||||||
|
|||||||
@@ -33,39 +33,41 @@ 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;
|
||||||
|
}[];
|
||||||
|
open_file_afterwards_on_display_ids: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -94,6 +96,7 @@ export type Display = {
|
|||||||
group_id: string;
|
group_id: string;
|
||||||
name: string;
|
name: string;
|
||||||
status: DisplayStatus;
|
status: DisplayStatus;
|
||||||
|
version?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DisplayGroup = {
|
export type DisplayGroup = {
|
||||||
@@ -101,6 +104,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 +128,19 @@ export type MenuOption = {
|
|||||||
|
|
||||||
export type PopupContent = {
|
export type PopupContent = {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
snippet: Snippet<[string]> | null;
|
snippet: Snippet<[string]> | Snippet<[]> | null;
|
||||||
snippet_arg?: string;
|
snippet_arg?: string;
|
||||||
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 +150,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';
|
||||||
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -100,7 +100,7 @@ export function display_status_to_info(status: DisplayStatus): string {
|
|||||||
return 'Lädt';
|
return 'Lädt';
|
||||||
case 'host_offline':
|
case 'host_offline':
|
||||||
return 'Offline';
|
return 'Offline';
|
||||||
case null:
|
default:
|
||||||
return '???';
|
return '???';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,3 +113,12 @@ export function get_sanitized_file_url(file_path: string, is_preview = false) {
|
|||||||
|
|
||||||
return `/file/${is_preview ? 'preview/' : ''}${[...pathSegments].join('/')}`;
|
return `/file/${is_preview ? 'preview/' : ''}${[...pathSegments].join('/')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let keyboard_queue = Promise.resolve();
|
||||||
|
|
||||||
|
export function add_to_keyboard_queue(task: () => Promise<void>) {
|
||||||
|
keyboard_queue = keyboard_queue.then(task).catch((err) => {
|
||||||
|
console.error('Error in input queue:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
{#if !dev}
|
{#if !dev}
|
||||||
|
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
||||||
{@html versionSplashScreen}
|
{@html versionSplashScreen}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,41 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Monitor, Plus, Radio, Settings, Trash2, Menu } from 'lucide-svelte';
|
import {
|
||||||
|
Monitor,
|
||||||
|
Plus,
|
||||||
|
Radio,
|
||||||
|
Settings,
|
||||||
|
Trash2,
|
||||||
|
Menu,
|
||||||
|
ChevronDown,
|
||||||
|
SquareCheckBig,
|
||||||
|
Square,
|
||||||
|
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';
|
||||||
|
import version from './../../../../shared/version.txt?raw';
|
||||||
|
|
||||||
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))$/;
|
||||||
@@ -29,8 +45,7 @@
|
|||||||
open: false,
|
open: false,
|
||||||
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 +70,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;
|
||||||
if (!!existing_display_id) {
|
let display: Display | null = null;
|
||||||
await edit_display_data(existing_display_id, ip, mac, name);
|
if (existing_display_id) {
|
||||||
|
display = await edit_display_data(existing_display_id, ip, mac, name);
|
||||||
} else {
|
} else {
|
||||||
const status = await ping_ip(text_inputs_valid.ip.value);
|
const resp = await ping_ip(text_inputs_valid.ip.value);
|
||||||
await add_display(ip, mac, name, status);
|
display = await add_display(ip, mac, name, resp.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 +116,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'
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,8 +142,7 @@
|
|||||||
snippet_arg: display_id,
|
snippet_arg: display_id,
|
||||||
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
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,14 +160,70 @@
|
|||||||
snippet_arg: display_id,
|
snippet_arg: display_id,
|
||||||
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>
|
||||||
|
|
||||||
|
<!-- eslint-disable-next-line @typescript-eslint/no-unused-vars -->
|
||||||
|
{#snippet about_popup(_: string)}
|
||||||
|
<div class="px-2">
|
||||||
|
<p>
|
||||||
|
{version}
|
||||||
|
</p>
|
||||||
|
<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?
|
||||||
@@ -142,7 +252,7 @@
|
|||||||
title="Anzeigename"
|
title="Anzeigename"
|
||||||
placeholder="z.B. Beamer vorne links"
|
placeholder="z.B. Beamer vorne links"
|
||||||
is_valid_function={async (input: string) => {
|
is_valid_function={async (input: string) => {
|
||||||
if (!!existing_display_id) {
|
if (existing_display_id) {
|
||||||
if (input === (await get_display_by_id(existing_display_id))?.name)
|
if (input === (await get_display_by_id(existing_display_id))?.name)
|
||||||
return [true, 'Gültiger Name'];
|
return [true, 'Gültiger Name'];
|
||||||
}
|
}
|
||||||
@@ -172,11 +282,11 @@
|
|||||||
className="px-4 gap-2"
|
className="px-4 gap-2"
|
||||||
bg="bg-stone-750"
|
bg="bg-stone-750"
|
||||||
click_function={async () => {
|
click_function={async () => {
|
||||||
const status = await ping_ip(text_inputs_valid.ip.value);
|
const resp = await ping_ip(text_inputs_valid.ip.value);
|
||||||
notifications.push(
|
notifications.push(
|
||||||
'info',
|
'info',
|
||||||
`Ping '${text_inputs_valid.ip.value}'`,
|
`Ping '${text_inputs_valid.ip.value}'`,
|
||||||
`Aktueller Zustand: ${display_status_to_info(status)}`
|
`Aktueller Zustand: ${display_status_to_info(resp.status)}`
|
||||||
);
|
);
|
||||||
}}><Radio /> Ping</Button
|
}}><Radio /> Ping</Button
|
||||||
>
|
>
|
||||||
@@ -206,7 +316,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<Button
|
<Button
|
||||||
disabled={!all_text_inputs_valid()}
|
disabled={!all_text_inputs_valid()}
|
||||||
className="{!!existing_display_id ? 'px-4' : 'pl-3 pr-4 gap-2'} font-bold"
|
className="{existing_display_id ? 'px-4' : 'pl-3 pr-4 gap-2'} font-bold"
|
||||||
bg="bg-stone-650"
|
bg="bg-stone-650"
|
||||||
click_function={async () => {
|
click_function={async () => {
|
||||||
await finalize_add_edit_display(existing_display_id);
|
await finalize_add_edit_display(existing_display_id);
|
||||||
@@ -220,6 +330,52 @@
|
|||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
|
{#snippet settings_popup()}
|
||||||
|
<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]">
|
<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>
|
||||||
@@ -229,12 +385,18 @@
|
|||||||
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
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -9,23 +9,50 @@
|
|||||||
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,
|
||||||
|
open_website
|
||||||
|
} from '$lib/ts/api_handler';
|
||||||
|
import {
|
||||||
|
get_display_by_id,
|
||||||
|
run_on_all_selected_displays,
|
||||||
|
selected_online_display_ids
|
||||||
|
} 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';
|
||||||
|
import { add_to_keyboard_queue } from '$lib/ts/utils';
|
||||||
|
import { onMount } from '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('');
|
||||||
|
|
||||||
|
const key_pressed = $state({
|
||||||
|
ArrowRight: false,
|
||||||
|
ArrowLeft: false
|
||||||
});
|
});
|
||||||
|
|
||||||
function popup_close_function() {
|
function popup_close_function() {
|
||||||
@@ -36,9 +63,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 +73,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,21 +103,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shutdown_action() {
|
async function shutdown_action() {
|
||||||
popup_content.open = false;
|
popup_content.open = false;
|
||||||
await run_on_all_selected_displays((d) => {
|
await run_on_all_selected_displays(async (d) => {
|
||||||
shutdown(d.ip); // no await here because we want to be fast
|
if (await shutdown(d.ip)) {
|
||||||
db.displays.update(d.id, { status: 'app_offline' });
|
db.displays.update(d.id, {
|
||||||
|
status: 'app_offline',
|
||||||
|
preview: { currently_updating: false, url: null }
|
||||||
|
});
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,29 +132,110 @@
|
|||||||
db.displays.update(d.id, { status: 'app_offline' });
|
db.displays.update(d.id, { status: 'app_offline' });
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
false
|
$selected_display_ids
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) =>
|
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, [{ key, action }]));
|
||||||
send_keyboard_input(d.ip, [{ key, action: 'press' }])
|
|
||||||
);
|
|
||||||
setTimeout(
|
|
||||||
async () =>
|
|
||||||
await run_on_all_selected_displays((d) =>
|
|
||||||
send_keyboard_input(d.ip, [{ key, action: 'release' }])
|
|
||||||
),
|
|
||||||
10
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
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) => open_website(d.ip, website_url));
|
||||||
|
}
|
||||||
|
|
||||||
|
function has_open_popup(): boolean {
|
||||||
|
return document.querySelector('.popup') !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_key(
|
||||||
|
event: KeyboardEvent,
|
||||||
|
key: 'ArrowRight' | 'ArrowLeft',
|
||||||
|
action: 'press' | 'release'
|
||||||
|
) {
|
||||||
|
if (event.key === key) {
|
||||||
|
const current_press_state: boolean = key_pressed[key];
|
||||||
|
if (
|
||||||
|
(action === 'press' && (current_press_state === true || has_open_popup())) ||
|
||||||
|
(action === 'release' && current_press_state === false)
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
|
key_pressed[key] = !current_press_state;
|
||||||
|
add_to_keyboard_queue(async () => {
|
||||||
|
await run_on_all_selected_displays(
|
||||||
|
(d) => send_keyboard_input(d.ip, [{ key, action }]),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_remove_event_listeners(
|
||||||
|
add_remove_function: (type: string, listener: (e: KeyboardEvent) => void) => void
|
||||||
|
) {
|
||||||
|
const actions = {
|
||||||
|
keydown: 'press',
|
||||||
|
keyup: 'release'
|
||||||
|
} as const;
|
||||||
|
const keys = ['ArrowRight', 'ArrowLeft'] as const;
|
||||||
|
|
||||||
|
for (const [action_type, action_value] of Object.entries(actions)) {
|
||||||
|
for (const key of keys) {
|
||||||
|
add_remove_function(action_type, (e: KeyboardEvent) => handle_key(e, key, action_value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
add_remove_event_listeners(window.addEventListener);
|
||||||
|
return () => {
|
||||||
|
add_remove_event_listeners(window.removeEventListener);
|
||||||
|
};
|
||||||
|
});
|
||||||
</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,55 +243,80 @@
|
|||||||
{/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 {key_pressed.ArrowLeft
|
||||||
disabled={$selected_display_ids.length === 0}
|
? 'bg-stone-500'
|
||||||
click_function={async () => {
|
: 'bg-stone-700'} {$selected_online_display_ids.length === 0
|
||||||
await send_single_key_press('VK_LEFT');
|
? 'text-stone-500 cursor-not-allowed'
|
||||||
}}><ArrowBigLeft /></Button
|
: '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_online_display_ids.length === 0 || key_pressed.ArrowLeft}
|
||||||
|
onmousedown={() => {
|
||||||
|
add_to_keyboard_queue(async () => await send_single_key_press('ArrowLeft', 'press'));
|
||||||
|
}}
|
||||||
|
onmouseup={() => {
|
||||||
|
add_to_keyboard_queue(
|
||||||
|
async () => await send_single_key_press('ArrowLeft', 'release')
|
||||||
|
);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<ArrowBigLeft />
|
||||||
title="Nächste Folie (Pfeil nach Rechts)"
|
</button>
|
||||||
className="px-9"
|
|
||||||
disabled={$selected_display_ids.length === 0}
|
<button
|
||||||
click_function={async () => {
|
title="Nächste Folie (Pfeil nach Rechts) [gedrückt halten möglich]"
|
||||||
await send_single_key_press('VK_RIGHT');
|
class="px-9 {key_pressed.ArrowRight
|
||||||
}}><ArrowBigRight /></Button
|
? 'bg-stone-500 cursor-not-allowed'
|
||||||
|
: `bg-stone-700 ${
|
||||||
|
$selected_online_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_online_display_ids.length === 0 || key_pressed.ArrowRight}
|
||||||
|
onmousedown={() => {
|
||||||
|
add_to_keyboard_queue(async () => await send_single_key_press('ArrowRight', 'press'));
|
||||||
|
}}
|
||||||
|
onmouseup={() => {
|
||||||
|
add_to_keyboard_queue(
|
||||||
|
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={$selected_online_display_ids.length === 0}
|
||||||
|
><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={$selected_online_display_ids.length === 0}
|
||||||
|
click_function={show_website_popup}><Globe /> Webseite Anzeigen</Button
|
||||||
|
>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className="px-3 flex gap-3 w-75 justify-normal"
|
||||||
|
disabled={$selected_online_display_ids.length === 0}
|
||||||
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
|
||||||
@@ -179,40 +324,38 @@
|
|||||||
|
|
||||||
<div class="flex flex-row justify-normal">
|
<div class="flex flex-row justify-normal">
|
||||||
<Button className="rounded-r-none pl-3 flex gap-3 grow w-65 justify-normal" disabled>
|
<Button className="rounded-r-none pl-3 flex gap-3 grow w-65 justify-normal" disabled>
|
||||||
<TrafficCone /> Fallback-Bild anzeigen
|
<TrafficCone /> Fallback-Bild Anzeigen
|
||||||
</Button>
|
</Button>
|
||||||
<Button className="rounded-l-none flex grow-0 w-10" disabled><ChevronDown /></Button>
|
<Button className="rounded-l-none flex grow-0 w-10" disabled><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={$selected_online_display_ids.length === 0}
|
||||||
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 === 'on' || $selected_display_ids.length === 0}
|
disabled={$all_display_states === 'on' || $selected_display_ids.length === 0}
|
||||||
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' || $selected_online_display_ids.length === 0}
|
||||||
click_function={ask_shutdonw}
|
click_function={ask_shutdown}
|
||||||
>
|
>
|
||||||
<PowerOff /> PC herunterfahren</Button
|
<PowerOff /> Bildschirm Herunterfahren</Button
|
||||||
>
|
>
|
||||||
{/await}
|
|
||||||
</div>
|
</div>
|
||||||
<Button className="px-3 flex gap-3 w-full xl:w-75 justify-normal" disabled>
|
<Button className="px-3 flex gap-3 w-full xl:w-75 justify-normal" disabled>
|
||||||
<SquareTerminal />
|
<SquareTerminal />
|
||||||
Shell-Befehl ausführen
|
Shell-Befehl Ausführen
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { fade, scale } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
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,
|
||||||
current_height,
|
current_height,
|
||||||
dnd_flip_duration_ms,
|
dnd_flip_duration_ms,
|
||||||
|
get_selectable_color_classes,
|
||||||
is_display_drag,
|
is_display_drag,
|
||||||
is_group_drag,
|
is_group_drag,
|
||||||
next_height_step_size,
|
next_height_step_size,
|
||||||
@@ -19,13 +22,11 @@
|
|||||||
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 { History, Menu, Pencil, PinOff, Trash2, VideoOff, ZoomIn, ZoomOut } from 'lucide-svelte';
|
||||||
import { Menu, Pencil, PinOff, 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, type IPaneSizingEvent } 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';
|
||||||
|
|
||||||
@@ -43,12 +44,21 @@
|
|||||||
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;
|
||||||
const sdi = $selected_display_ids;
|
const sdi = $selected_display_ids;
|
||||||
all_groups_selected = liveQuery(() => all_selected(d || [], sdi));
|
all_groups_selected = liveQuery(() => d.length !== 0 && all_selected(d || [], sdi));
|
||||||
});
|
});
|
||||||
|
|
||||||
let last_pinned_pane_size: number = 45;
|
let last_pinned_pane_size: number = 45;
|
||||||
@@ -59,8 +69,13 @@
|
|||||||
pinned_pane_size = 0;
|
pinned_pane_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_display_menu_options(display_id: string): MenuOption[] {
|
function get_display_menu_options(display_id: string, display_version: string|undefined): MenuOption[] {
|
||||||
return [
|
return [
|
||||||
|
{
|
||||||
|
icon: History,
|
||||||
|
name: display_version ?? "Version unbekannt",
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: Pencil,
|
icon: Pencil,
|
||||||
name: 'Bildschirm bearbeiten',
|
name: 'Bildschirm bearbeiten',
|
||||||
@@ -98,7 +113,7 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_splitpane_resize(e: any) {
|
function handle_splitpane_resize(e: CustomEvent<IPaneSizingEvent[]>) {
|
||||||
if (e.detail[0].size === 0) {
|
if (e.detail[0].size === 0) {
|
||||||
$pinned_display_id = null;
|
$pinned_display_id = null;
|
||||||
pinned_pane_size = last_pinned_pane_size;
|
pinned_pane_size = last_pinned_pane_size;
|
||||||
@@ -156,7 +171,7 @@
|
|||||||
click_function={(e) => {
|
click_function={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
menu_options={get_display_menu_options($pinned_display_id)}
|
menu_options={get_display_menu_options($pinned_display_id, $pinned_display?.version)}
|
||||||
>
|
>
|
||||||
<Menu />
|
<Menu />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -203,17 +218,28 @@
|
|||||||
</span>
|
</span>
|
||||||
<div class="flex flex-row gap-1">
|
<div class="flex flex-row gap-1">
|
||||||
<button
|
<button
|
||||||
class="min-w-40 px-4 rounded-xl cursor-pointer duration-200 transition-colors bg-stone-600"
|
disabled={$display_groups?.length === 0}
|
||||||
|
class="min-w-40 px-4 rounded-xl duration-200 transition-colors {$display_groups?.length ===
|
||||||
|
0
|
||||||
|
? 'text-stone-500 cursor-not-allowed'
|
||||||
|
: 'cursor-pointer'} {get_selectable_color_classes($all_groups_selected || false, {
|
||||||
|
bg: true,
|
||||||
|
hover: $display_groups?.length !== 0,
|
||||||
|
active: $display_groups?.length !== 0,
|
||||||
|
text: true
|
||||||
|
})}"
|
||||||
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
|
||||||
title="Bildschirme größer darstellen"
|
title="Bildschirme größer darstellen"
|
||||||
className="aspect-square p-1.5! pr-1! rounded-r-none"
|
className="aspect-square p-1.5! pr-1! rounded-r-none"
|
||||||
bg="bg-stone-600"
|
bg="bg-stone-600"
|
||||||
disabled={!Boolean(next_height_step_size('display', $current_height, 1))}
|
disabled={!next_height_step_size('display', $current_height, 1)}
|
||||||
click_function={() => {
|
click_function={() => {
|
||||||
change_height('display', 1);
|
change_height('display', 1);
|
||||||
}}
|
}}
|
||||||
@@ -224,7 +250,7 @@
|
|||||||
title="Bildschirme kleiner darstellen"
|
title="Bildschirme kleiner darstellen"
|
||||||
className="aspect-square p-1.5! pl-1! rounded-l-none"
|
className="aspect-square p-1.5! pl-1! rounded-l-none"
|
||||||
bg="bg-stone-600"
|
bg="bg-stone-600"
|
||||||
disabled={!Boolean(next_height_step_size('display', $current_height, -1))}
|
disabled={!next_height_step_size('display', $current_height, -1)}
|
||||||
click_function={() => {
|
click_function={() => {
|
||||||
change_height('display', -1);
|
change_height('display', -1);
|
||||||
}}
|
}}
|
||||||
@@ -234,26 +260,8 @@
|
|||||||
</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"
|
|
||||||
use:dragHandleZone={{
|
|
||||||
items: $display_groups || [],
|
|
||||||
type: 'group',
|
|
||||||
flipDurationMs: dnd_flip_duration_ms,
|
|
||||||
dropFromOthersDisabled: true,
|
|
||||||
dropTargetStyle: { outline: 'none' }
|
|
||||||
}}
|
|
||||||
onconsider={async (e: CustomEvent) => {
|
|
||||||
$is_group_drag = true;
|
|
||||||
await set_new_display_group_order(e.detail.items);
|
|
||||||
}}
|
|
||||||
onfinalize={async (e: CustomEvent) => {
|
|
||||||
await set_new_display_group_order(e.detail.items);
|
|
||||||
$is_group_drag = false;
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{#if ($display_groups || []).length === 0}
|
|
||||||
<div class="text-stone-500 px-10 py-6 leading-relaxed text-center">
|
<div class="text-stone-500 px-10 py-6 leading-relaxed text-center">
|
||||||
Es wurden noch keine Bildschirme hinzugefügt. Klicke oben rechts auf
|
Es wurden noch keine Bildschirme hinzugefügt. Klicke oben rechts auf
|
||||||
<HighlightedText fg="text-stone-450" className="p-1!">
|
<HighlightedText fg="text-stone-450" className="p-1!">
|
||||||
@@ -263,22 +271,39 @@
|
|||||||
<HighlightedText fg="text-stone-450">Neuen Bildschirm hinzufügen</HighlightedText>.
|
<HighlightedText fg="text-stone-450">Neuen Bildschirm hinzufügen</HighlightedText>.
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each $display_groups || [] as display_group (display_group.id)}
|
<div
|
||||||
<!-- Each Group -->
|
class="min-h-full p-2 flex flex-col gap-4"
|
||||||
<section
|
use:dragHandleZone={{
|
||||||
out:scale={{ duration: dnd_flip_duration_ms, easing: cubicOut }}
|
items: $local_displays,
|
||||||
animate:flip={{ duration: dnd_flip_duration_ms, easing: cubicOut }}
|
type: 'group',
|
||||||
class="outline-none"
|
flipDurationMs: dnd_flip_duration_ms,
|
||||||
|
dropFromOthersDisabled: true,
|
||||||
|
dropTargetStyle: { outline: 'none' }
|
||||||
|
}}
|
||||||
|
onconsider={(e: CustomEvent) => {
|
||||||
|
$is_group_drag = true;
|
||||||
|
$local_displays = e.detail.items;
|
||||||
|
}}
|
||||||
|
onfinalize={async (e: CustomEvent) => {
|
||||||
|
$local_displays = e.detail.items;
|
||||||
|
await update_db_displays();
|
||||||
|
$is_group_drag = false;
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
|
{#each $local_displays as display_id_group (display_id_group.id)}
|
||||||
|
<!-- Each Group -->
|
||||||
|
<section class="outline-none">
|
||||||
|
<!-- out:scale={{ duration: dnd_flip_duration_ms, easing: cubicOut }}
|
||||||
|
animate:flip={{ duration: dnd_flip_duration_ms, easing: cubicOut }} -->
|
||||||
<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>
|
||||||
|
|||||||
@@ -11,23 +11,28 @@
|
|||||||
ZoomIn,
|
ZoomIn,
|
||||||
ZoomOut
|
ZoomOut
|
||||||
} from 'lucide-svelte';
|
} from 'lucide-svelte';
|
||||||
import { change_height, current_height, next_height_step_size } from '$lib/ts/stores/ui_behavior';
|
import {
|
||||||
|
change_height,
|
||||||
|
current_height,
|
||||||
|
get_selectable_color_classes,
|
||||||
|
next_height_step_size
|
||||||
|
} from '$lib/ts/stores/ui_behavior';
|
||||||
import Button from '$lib/components/Button.svelte';
|
import Button from '$lib/components/Button.svelte';
|
||||||
import PathBar from './PathBar.svelte';
|
import PathBar from './PathBar.svelte';
|
||||||
import { selected_display_ids, selected_file_ids } from '$lib/ts/stores/select';
|
import { select, 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_path_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 +42,9 @@
|
|||||||
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 { selected_online_display_ids } from '$lib/ts/stores/displays';
|
||||||
|
import FileDropZone from '$lib/components/FileDropZone.svelte';
|
||||||
|
|
||||||
let current_name: string = $state('');
|
let current_name: string = $state('');
|
||||||
let current_valid: boolean = $state(false);
|
let current_valid: boolean = $state(false);
|
||||||
@@ -48,25 +55,37 @@
|
|||||||
const s = $selected_file_ids;
|
const s = $selected_file_ids;
|
||||||
selected_files = liveQuery(() => get_selected_files(s));
|
selected_files = liveQuery(() => get_selected_files(s));
|
||||||
});
|
});
|
||||||
|
let all_files_selected: boolean = $state(false);
|
||||||
|
$effect(() => {
|
||||||
|
const fe = $current_folder_elements;
|
||||||
|
const sfe_id = $selected_file_ids;
|
||||||
|
if (fe && sfe_id && fe.length !== 0) {
|
||||||
|
all_files_selected =
|
||||||
|
fe.length === sfe_id.length &&
|
||||||
|
!fe.find((inode) => !sfe_id.includes(get_file_primary_key(inode)));
|
||||||
|
}
|
||||||
|
});
|
||||||
let current_folder_elements: Observable<Inode[]> | undefined = $state();
|
let current_folder_elements: Observable<Inode[]> | undefined = $state();
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const path = $current_file_path,
|
const path = $current_file_path,
|
||||||
display_ids = $selected_display_ids;
|
display_ids = $selected_online_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';
|
if (s.length !== 1) return false;
|
||||||
})
|
const inode = await get_file_by_id(s[0]);
|
||||||
})
|
if (!inode) return false;
|
||||||
|
return !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;
|
||||||
@@ -76,7 +95,7 @@
|
|||||||
const results = await Promise.all(selected_file_ids.map((id) => get_file_by_id(id)));
|
const results = await Promise.all(selected_file_ids.map((id) => get_file_by_id(id)));
|
||||||
return results.filter((element) => element !== null);
|
return results.filter((element) => element !== null);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error('Error on generating selected_files');
|
console.error('Error on generating selected_files', e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,11 +106,8 @@
|
|||||||
|
|
||||||
async function create_new_folder() {
|
async function create_new_folder() {
|
||||||
popup_close_function();
|
popup_close_function();
|
||||||
await create_folder_on_all_selected_displays(
|
const path_with_folder_name = ($current_file_path += current_name.trim() + '/');
|
||||||
current_name.trim(),
|
await create_path_on_all_selected_displays(path_with_folder_name, $selected_online_display_ids);
|
||||||
$current_file_path,
|
|
||||||
$selected_display_ids
|
|
||||||
);
|
|
||||||
await update_current_folder_on_selected_displays();
|
await update_current_folder_on_selected_displays();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,17 +126,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 +143,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_online_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
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -144,10 +158,39 @@
|
|||||||
open: true,
|
open: true,
|
||||||
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 toggle_all_selected_files(current_files: Inode[]) {
|
||||||
|
let action: 'select' | 'deselect';
|
||||||
|
if (all_files_selected === false) {
|
||||||
|
action = 'select';
|
||||||
|
} else {
|
||||||
|
action = 'deselect';
|
||||||
|
}
|
||||||
|
for (const file of current_files) {
|
||||||
|
await select(selected_file_ids, get_file_primary_key(file), action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sync_selected_files(
|
||||||
|
current_selected_file_ids: string[],
|
||||||
|
selected_display_ids: string[],
|
||||||
|
current_folder_elements: Inode[]
|
||||||
|
) {
|
||||||
|
if (current_selected_file_ids.length === 0 && current_folder_elements.length > 0) {
|
||||||
|
current_selected_file_ids = current_folder_elements.map((inode) =>
|
||||||
|
get_file_primary_key(inode)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (current_selected_file_ids.length === 0) return;
|
||||||
|
// Mit For-Schleife über ausgewählte Elemente gehen
|
||||||
|
for (const file_id of current_selected_file_ids) {
|
||||||
|
await select(selected_file_ids, file_id, 'deselect');
|
||||||
|
await add_sync_recursively(file_id, selected_display_ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet new_folder_popup()}
|
{#snippet new_folder_popup()}
|
||||||
@@ -158,7 +201,7 @@
|
|||||||
> existiert nicht auf {display_names_where_path_does_not_exist.length === 1
|
> existiert nicht auf {display_names_where_path_does_not_exist.length === 1
|
||||||
? 'dem Bildschirm'
|
? 'dem Bildschirm'
|
||||||
: 'den Bildschirmen'}
|
: 'den Bildschirmen'}
|
||||||
{#each display_names_where_path_does_not_exist as display_name, i}
|
{#each display_names_where_path_does_not_exist as display_name, i (i)}
|
||||||
{#if i !== 0}
|
{#if i !== 0}
|
||||||
,
|
,
|
||||||
{/if}
|
{/if}
|
||||||
@@ -232,8 +275,8 @@
|
|||||||
<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, i (i)}
|
||||||
<InodeElement {file} not_interactable />
|
<InodeElement {file} not_interactable />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
@@ -263,21 +306,40 @@
|
|||||||
bind:this={file_input}
|
bind:this={file_input}
|
||||||
multiple
|
multiple
|
||||||
accept={get_accepted_file_type_string()}
|
accept={get_accepted_file_type_string()}
|
||||||
onchange={(e) =>
|
onchange={async (e) => {
|
||||||
add_upload((e.target as HTMLInputElement).files!, $selected_display_ids, $current_file_path)}
|
const target = e.target as HTMLInputElement;
|
||||||
|
await add_upload(target.files!, $selected_online_display_ids, $current_file_path);
|
||||||
|
target.value = '';
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="bg-stone-800 h-full rounded-2xl grid grid-rows-[2.5rem_1fr] min-h-0">
|
<div class="bg-stone-800 size-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 gap-1">
|
||||||
|
<button
|
||||||
|
disabled={$current_folder_elements?.length === 0}
|
||||||
|
class="min-w-40 px-4 rounded-xl duration-200 transition-colors {$current_folder_elements?.length ===
|
||||||
|
0
|
||||||
|
? 'text-stone-500 cursor-not-allowed'
|
||||||
|
: 'cursor-pointer'} {get_selectable_color_classes(all_files_selected, {
|
||||||
|
bg: true,
|
||||||
|
hover: $current_folder_elements?.length !== 0,
|
||||||
|
active: $current_folder_elements?.length !== 0,
|
||||||
|
text: true
|
||||||
|
})}"
|
||||||
|
onclick={async () => await toggle_all_selected_files($current_folder_elements ?? [])}
|
||||||
|
>
|
||||||
|
<span>{all_files_selected ? 'Alle Abwählen' : 'Alle Auswählen'}</span>
|
||||||
|
</button>
|
||||||
<div class="flex flex-row">
|
<div class="flex flex-row">
|
||||||
<Button
|
<Button
|
||||||
title="Dateien größer darstellen"
|
title="Dateien größer darstellen"
|
||||||
className="aspect-square p-1.5! pr-1! rounded-r-none"
|
className="aspect-square p-1.5! pr-1! rounded-r-none"
|
||||||
bg="bg-stone-600"
|
bg="bg-stone-600"
|
||||||
disabled={!Boolean(next_height_step_size('file', $current_height, 1))}
|
disabled={!next_height_step_size('file', $current_height, 1)}
|
||||||
click_function={() => {
|
click_function={() => {
|
||||||
change_height('file', 1);
|
change_height('file', 1);
|
||||||
}}
|
}}
|
||||||
@@ -288,7 +350,7 @@
|
|||||||
title="Dateien kleiner darstellen"
|
title="Dateien kleiner darstellen"
|
||||||
className="aspect-square p-1.5! pl-1! rounded-l-none"
|
className="aspect-square p-1.5! pl-1! rounded-l-none"
|
||||||
bg="bg-stone-600"
|
bg="bg-stone-600"
|
||||||
disabled={!Boolean(next_height_step_size('file', $current_height, -1))}
|
disabled={!next_height_step_size('file', $current_height, -1)}
|
||||||
click_function={() => {
|
click_function={() => {
|
||||||
change_height('file', -1);
|
change_height('file', -1);
|
||||||
}}
|
}}
|
||||||
@@ -297,6 +359,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="flex flex-col gap-2 p-2 overflow-hidden relative rounded-b-2xl">
|
<div class="flex flex-col gap-2 p-2 overflow-hidden relative rounded-b-2xl">
|
||||||
<div class="flex flex-col gap-2 p-2 bg-stone-750 rounded-xl">
|
<div class="flex flex-col gap-2 p-2 bg-stone-750 rounded-xl">
|
||||||
<PathBar />
|
<PathBar />
|
||||||
@@ -306,7 +369,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={$selected_online_display_ids.length === 0}><FolderPlus /></Button
|
||||||
>
|
>
|
||||||
<div class="border border-stone-700 my-1"></div>
|
<div class="border border-stone-700 my-1"></div>
|
||||||
<Button
|
<Button
|
||||||
@@ -315,19 +378,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={$selected_online_display_ids.length === 0}><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_online_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_online_display_ids,
|
||||||
|
$current_folder_elements ?? []
|
||||||
|
)}
|
||||||
|
disabled={$selected_online_display_ids.length === 0}
|
||||||
><RefreshCcw />
|
><RefreshCcw />
|
||||||
<span class="hidden 2xl:flex">Synchronisieren</span>
|
<span class="hidden 2xl:flex">Synchronisieren</span>
|
||||||
</Button>
|
</Button>
|
||||||
@@ -341,7 +411,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={$selected_online_display_ids.length === 0}
|
||||||
>
|
>
|
||||||
<ClipboardPaste />
|
<ClipboardPaste />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -363,9 +433,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="min-h-0 h-full overflow-y-auto overflow-x-hidden bg-stone-750 rounded-xl">
|
|
||||||
|
<div
|
||||||
|
class="min-h-0 size-full overflow-y-auto overflow-x-hidden bg-stone-750 rounded-xl relative"
|
||||||
|
>
|
||||||
|
<FileDropZone className="rounded-xl size-full" />
|
||||||
<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 $selected_online_display_ids.length === 0}
|
||||||
<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>
|
||||||
|
|||||||
@@ -1,70 +1,87 @@
|
|||||||
<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, Option } from 'lucide-svelte';
|
||||||
|
import Button from '$lib/components/Button.svelte';
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
import { add_to_keyboard_queue } from '$lib/ts/utils';
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
const action: 'press' | 'release' = key_down ? 'press' : 'release';
|
if (e.repeat) return;
|
||||||
|
await on_key(id, key_down);
|
||||||
add_to_last_keys(action.toUpperCase() + ' ' + e.code);
|
|
||||||
|
|
||||||
await run_on_all_selected_displays(
|
|
||||||
(d) => send_keyboard_input(d.ip, [{ key: id, action }]),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function release_all_pressed_keys() {
|
async function on_key(key: string, key_down: boolean) {
|
||||||
|
if (key_down) {
|
||||||
|
if (current_keys.includes(key)) return;
|
||||||
|
current_keys.push(key);
|
||||||
|
} else {
|
||||||
|
const index = current_keys.indexOf(key);
|
||||||
|
if (index === -1) return;
|
||||||
|
current_keys.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const action: 'press' | 'release' = key_down ? 'press' : 'release';
|
||||||
|
|
||||||
|
add_to_last_keys(action.toUpperCase() + ' ' + key);
|
||||||
|
add_to_keyboard_queue(async () => {
|
||||||
|
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, [{ key, action }]), true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
add_to_keyboard_queue(async () => {
|
||||||
(d) => send_keyboard_input(d.ip, inputs),
|
await run_on_all_selected_displays((d) => send_keyboard_input(d.ip, inputs), true);
|
||||||
true
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
release_all_pressed_keys();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-row gap-2 overflow-hidden h-full">
|
||||||
<div
|
<div
|
||||||
role="textbox"
|
role="textbox"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
@@ -79,11 +96,11 @@
|
|||||||
}}
|
}}
|
||||||
onblur={async () => {
|
onblur={async () => {
|
||||||
active = false;
|
active = false;
|
||||||
await release_all_pressed_keys();
|
release_all_pressed_keys();
|
||||||
}}
|
}}
|
||||||
onkeydown={(e) => on_key(e, true)}
|
onkeydown={(e) => on_keyboard_input(e, true)}
|
||||||
onkeyup={(e) => on_key(e, false)}
|
onkeyup={(e) => on_keyboard_input(e, false)}
|
||||||
class="relative flex justify-center items-center h-15 w-full cursor-pointer rounded-xl transition-colors duration-200 select-none {get_selectable_color_classes(
|
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,
|
active,
|
||||||
{
|
{
|
||||||
bg: true,
|
bg: true,
|
||||||
@@ -94,13 +111,65 @@
|
|||||||
)}"
|
)}"
|
||||||
>
|
>
|
||||||
{active ? 'Erfassung aktiv' : 'Hier für Erfassung klicken'}
|
{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">
|
</div>
|
||||||
{#each last_keys as key (key.id)}
|
<div
|
||||||
<span
|
class="relative flex flex-col gap-1 text-sm w-40 p-2 bg-stone-750 rounded-xl overflow-hidden h-full"
|
||||||
animate:flip={{ duration: 200 }}
|
|
||||||
in:fade={{ duration: 200 }}
|
|
||||||
out:fade={{ duration: 500 }}>{key.key}</span
|
|
||||||
>
|
>
|
||||||
|
{#each last_keys as item (item.id)}
|
||||||
|
<span
|
||||||
|
class="flex flex-row gap-2 {item.key.split(' ')[0] === 'PRESS'
|
||||||
|
? 'text-sky-600'
|
||||||
|
: 'text-lime-600'}"
|
||||||
|
animate:flip={{ duration: 120 }}
|
||||||
|
in:fade={{ duration: 120 }}
|
||||||
|
out:fade={{ duration: 200 }}
|
||||||
|
>
|
||||||
|
{#if item.key.split(' ')[0] === 'PRESS'}
|
||||||
|
<ArrowDownToLine />
|
||||||
|
{:else}
|
||||||
|
<ArrowUpFromLine />
|
||||||
|
{/if}
|
||||||
|
{item.key.split(' ').at(-1)}
|
||||||
|
</span>
|
||||||
{/each}
|
{/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>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
Highlighter,
|
Highlighter,
|
||||||
Italic,
|
Italic,
|
||||||
PaintBucket,
|
PaintBucket,
|
||||||
QrCode,
|
|
||||||
Strikethrough
|
Strikethrough
|
||||||
} from 'lucide-svelte';
|
} from 'lucide-svelte';
|
||||||
import Button from '$lib/components/Button.svelte';
|
import Button from '$lib/components/Button.svelte';
|
||||||
@@ -20,6 +19,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 +71,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,20 +133,22 @@
|
|||||||
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>
|
||||||
|
|
||||||
{#each Object.values(color_states) as color_state}
|
{#each Object.values(color_states) as color_state, i (i)}
|
||||||
<input type="color" bind:this={color_state.el} bind:value={color_state.value} class="hidden" />
|
<input type="color" bind:this={color_state.el} bind:value={color_state.value} class="hidden" />
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
@@ -161,9 +162,9 @@
|
|||||||
|
|
||||||
<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">
|
||||||
{#each text_edit_options as edit_row}
|
{#each text_edit_options as edit_row, i (i)}
|
||||||
<div class="flex flex-row gap-1">
|
<div class="flex flex-row gap-1">
|
||||||
{#each edit_row as option}
|
{#each edit_row as option, j (j)}
|
||||||
<div class="flex flex-row">
|
<div class="flex flex-row">
|
||||||
<button
|
<button
|
||||||
title={option.title}
|
title={option.title}
|
||||||
@@ -216,7 +217,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>
|
||||||
|
|
||||||
|
|||||||
@@ -216,6 +216,6 @@ module.exports = {
|
|||||||
'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
@@ -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
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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=
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[working-directory: 'frontend']
|
||||||
|
gen:
|
||||||
|
deno install
|
||||||
|
deno task build
|
||||||
|
|
||||||
|
dev: gen
|
||||||
|
go run *.go
|
||||||
+28
-5
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -64,7 +65,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
err = shared.OpenBrowserWindow("http://localhost:"+port, false, false)
|
err = openBrowserWindow("http://localhost:" + port)
|
||||||
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)
|
||||||
@@ -77,23 +78,45 @@ 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)
|
client := http.Client{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Get("http://" + ip + ":1323/api/ping")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.JSON(http.StatusOK, PingResponse{Status: "app_offline"})
|
return ctx.JSON(http.StatusOK, PingResponse{Status: "app_offline"})
|
||||||
}
|
}
|
||||||
conn.Close()
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return ctx.JSON(http.StatusOK, PingResponse{Status: "app_offline"})
|
||||||
|
}
|
||||||
|
|
||||||
return ctx.JSON(http.StatusOK, PingResponse{Status: "app_online"})
|
var appPing AppPingResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&appPing); err != nil {
|
||||||
|
return ctx.JSON(http.StatusOK, PingResponse{
|
||||||
|
Status: "app_offline",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.JSON(http.StatusOK, PingResponse{
|
||||||
|
Status: "app_online",
|
||||||
|
Version: appPing.Version,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppPingResponse struct {
|
||||||
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PingResponse struct {
|
type PingResponse struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
Version string `json:"version"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"plg-mudics/shared"
|
||||||
|
)
|
||||||
|
|
||||||
|
func openBrowserWindow(url string) error {
|
||||||
|
bins := []string{"chromium", "chromium-browser"}
|
||||||
|
|
||||||
|
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", "browser-control")
|
||||||
|
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),
|
||||||
|
fmt.Sprintf("--user-data-dir=%s", browserProfileDirPath),
|
||||||
|
"--disable-features=Translate",
|
||||||
|
}
|
||||||
|
|
||||||
|
errs := []string{}
|
||||||
|
for _, bin := range bins {
|
||||||
|
cmd := exec.Command(bin, args...)
|
||||||
|
commandOutput := shared.RunShellCommand(cmd)
|
||||||
|
if commandOutput.ExitCode == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
errs = append(errs, commandOutput.Stderr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New("failed to open browser window: " + fmt.Sprint(errs))
|
||||||
|
}
|
||||||
@@ -62,6 +62,12 @@ Even when the command itself fails.
|
|||||||
|
|
||||||
The screenshot as binary in the response body.
|
The screenshot as binary in the response body.
|
||||||
|
|
||||||
|
## PATCH `/openWebsite`
|
||||||
|
|
||||||
|
### Request Body
|
||||||
|
|
||||||
|
- `url`: string
|
||||||
|
|
||||||
## POST `/file/<path>` - Upload File
|
## POST `/file/<path>` - Upload File
|
||||||
|
|
||||||
### Responses
|
### Responses
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package browser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/chromedp/chromedp"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Browser BrowserType = BrowserType{}
|
||||||
|
|
||||||
|
type BrowserType struct {
|
||||||
|
Ctx context.Context
|
||||||
|
Cancel context.CancelFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BrowserType) Init() error {
|
||||||
|
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", "browser-display")
|
||||||
|
if err := os.MkdirAll(browserProfileDirPath, os.ModePerm); err != nil {
|
||||||
|
return fmt.Errorf("failed to create local config directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := []chromedp.ExecAllocatorOption{
|
||||||
|
chromedp.Flag("headless", false),
|
||||||
|
chromedp.Flag("app", "http://example.com"), // app mode prevents a few unwanted features of chrome, the start url is directly overwritten
|
||||||
|
chromedp.Flag("start-fullscreen", true),
|
||||||
|
chromedp.Flag("hide-scrollbars", true),
|
||||||
|
chromedp.Flag("allow-file-access-from-files", true),
|
||||||
|
chromedp.Flag("user-data-dir", browserProfileDirPath),
|
||||||
|
chromedp.Flag("autoplay-policy", "no-user-gesture-required"),
|
||||||
|
}
|
||||||
|
|
||||||
|
initCtx, _ := chromedp.NewExecAllocator(context.Background(), opts...)
|
||||||
|
b.Ctx, b.Cancel = chromedp.NewContext(initCtx)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BrowserType) OpenPage(url string) error {
|
||||||
|
err := chromedp.Run(b.Ctx, chromedp.Navigate(url))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("navigate to URL: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yes, we need that trick with creating a temp file and not directly sending html since
|
||||||
|
// chrome only allows us to access local files via other local files
|
||||||
|
func (b *BrowserType) OpenHTML(html string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
tempFile, err := os.CreateTemp("", "mudics-*.html")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create tempfile: %w", err)
|
||||||
|
}
|
||||||
|
defer func() { _ = tempFile.Close() }()
|
||||||
|
|
||||||
|
_, err = tempFile.WriteString(html)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not write to tempfile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = chromedp.Run(b.Ctx, chromedp.Navigate("file://"+tempFile.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("navigate to URL: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BrowserType) OpenPDF(path string) error {
|
||||||
|
err := b.OpenPage("file://" + path + "#toolbar=0&view=Fit")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open PDF: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
+19
-12
@@ -1,36 +1,43 @@
|
|||||||
module plg-mudics/display
|
module plg-mudics/display
|
||||||
|
|
||||||
go 1.24.4
|
go 1.25
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/a-h/templ v0.3.960
|
github.com/a-h/templ v0.3.977
|
||||||
github.com/labstack/echo/v4 v4.13.4
|
github.com/chromedp/chromedp v0.14.2
|
||||||
|
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 (
|
||||||
github.com/a-h/parse v0.0.0-20250122154542-74294addb73e // indirect
|
github.com/a-h/parse v0.0.0-20250122154542-74294addb73e // indirect
|
||||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d // indirect
|
||||||
|
github.com/chromedp/sysutil v1.1.0 // indirect
|
||||||
github.com/cli/browser v1.3.0 // indirect
|
github.com/cli/browser v1.3.0 // indirect
|
||||||
github.com/fatih/color v1.16.0 // indirect
|
github.com/fatih/color v1.16.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e // indirect
|
||||||
|
github.com/gobwas/httphead v0.1.0 // indirect
|
||||||
|
github.com/gobwas/pool v0.2.1 // indirect
|
||||||
|
github.com/gobwas/ws v1.4.0 // indirect
|
||||||
github.com/labstack/gommon v0.4.2 // indirect
|
github.com/labstack/gommon v0.4.2 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
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.40.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
|
||||||
|
|||||||
@@ -2,10 +2,18 @@ github.com/a-h/parse v0.0.0-20250122154542-74294addb73e h1:HjVbSQHy+dnlS6C3XajZ6
|
|||||||
github.com/a-h/parse v0.0.0-20250122154542-74294addb73e/go.mod h1:3mnrkvGpurZ4ZrTDbYU84xhwXW2TjTKShSwjRi2ihfQ=
|
github.com/a-h/parse v0.0.0-20250122154542-74294addb73e/go.mod h1:3mnrkvGpurZ4ZrTDbYU84xhwXW2TjTKShSwjRi2ihfQ=
|
||||||
github.com/a-h/templ v0.3.960 h1:trshEpGa8clF5cdI39iY4ZrZG8Z/QixyzEyUnA7feTM=
|
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/a-h/templ v0.3.960/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo=
|
||||||
|
github.com/a-h/templ v0.3.977 h1:kiKAPXTZE2Iaf8JbtM21r54A8bCNsncrfnokZZSrSDg=
|
||||||
|
github.com/a-h/templ v0.3.977/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo=
|
||||||
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d h1:ZtA1sedVbEW7EW80Iz2GR3Ye6PwbJAJXjv7D74xG6HU=
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d/go.mod h1:NItd7aLkcfOA/dcMXvl8p1u+lQqioRMq/SqDp71Pb/k=
|
||||||
|
github.com/chromedp/chromedp v0.14.2 h1:r3b/WtwM50RsBZHMUm9fsNhhzRStTHrKdr2zmwbZSzM=
|
||||||
|
github.com/chromedp/chromedp v0.14.2/go.mod h1:rHzAv60xDE7VNy/MYtTUrYreSc0ujt2O1/C3bzctYBo=
|
||||||
|
github.com/chromedp/sysutil v1.1.0 h1:PUFNv5EcprjqXZD9nJb9b/c9ibAbxiYo4exNWZyipwM=
|
||||||
|
github.com/chromedp/sysutil v1.1.0/go.mod h1:WiThHUdltqCNKGc4gaU50XgYjwjYIhKWoHGPTUfWTJ8=
|
||||||
github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo=
|
github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo=
|
||||||
github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEfBTk=
|
github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEfBTk=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
@@ -16,10 +24,20 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
|
|||||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.11 h1:AQvxbp830wPhHTqc1u7nzoLT+ZFxGY7emj5DR5DYFik=
|
github.com/gabriel-vasile/mimetype v1.4.11 h1:AQvxbp830wPhHTqc1u7nzoLT+ZFxGY7emj5DR5DYFik=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.11/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
github.com/gabriel-vasile/mimetype v1.4.11/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||||
|
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e h1:Lf/gRkoycfOBPa42vU2bbgPurFong6zXeFtPoxholzU=
|
||||||
|
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e/go.mod h1:uNVvRXArCGbZ508SxYYTC5v1JWoz2voff5pm25jU1Ok=
|
||||||
|
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||||
|
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||||
|
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||||
|
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||||
|
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
|
||||||
|
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
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 +54,45 @@ 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/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||||
|
golang.org/x/sys v0.40.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=
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package pdfjs
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed node_modules/pdfjs-dist/build/pdf.min.mjs
|
||||||
|
//go:embed node_modules/pdfjs-dist/build/pdf.worker.min.mjs
|
||||||
|
var Files embed.FS
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"nodeModulesDir": "manual",
|
||||||
|
"nodeModulesLinker": "hoisted",
|
||||||
|
"imports": {
|
||||||
|
"pdfjs-dist": "npm:pdfjs-dist@6.0.227"
|
||||||
|
},
|
||||||
|
"tasks": {
|
||||||
|
"install": "deno install --frozen"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+90
@@ -0,0 +1,90 @@
|
|||||||
|
{
|
||||||
|
"version": "5",
|
||||||
|
"specifiers": {
|
||||||
|
"npm:pdfjs-dist@6.0.227": "6.0.227"
|
||||||
|
},
|
||||||
|
"npm": {
|
||||||
|
"@napi-rs/canvas-android-arm64@1.0.0": {
|
||||||
|
"integrity": "sha512-3hNKJObUK7JsCF9aJlVCs1J0/KE/gGfZNeK8MO1ge6bB3aicr5walGme9t9No1f/oyk9GgvdAT/rjSdsx3gbIw==",
|
||||||
|
"os": ["android"],
|
||||||
|
"cpu": ["arm64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-darwin-arm64@1.0.0": {
|
||||||
|
"integrity": "sha512-ZIja19/BiGz2puhki+WUYSRriwFeFJ8Mi9eK3hZdSS85w4Y60cuEAJVhMCfKwswQkKkUtrnzdKMBuO7TupvexA==",
|
||||||
|
"os": ["darwin"],
|
||||||
|
"cpu": ["arm64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-darwin-x64@1.0.0": {
|
||||||
|
"integrity": "sha512-hImggWc82jqZVpEsFR9S7PE9OQYjq/H/D7vwCGB6X1jRH+UVBP1+1niJTPBOat1B154T6GKK7/kcFtoWgjgFzQ==",
|
||||||
|
"os": ["darwin"],
|
||||||
|
"cpu": ["x64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-linux-arm-gnueabihf@1.0.0": {
|
||||||
|
"integrity": "sha512-hlJRy6d+kWLKVOG/+1rEvNQVURZ0DxxRPJsLmEWwhwiXZUJc0BF5o9esALHSEP4CoJK4wChRtj3hnyBgVx2oWA==",
|
||||||
|
"os": ["linux"],
|
||||||
|
"cpu": ["arm"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-linux-arm64-gnu@1.0.0": {
|
||||||
|
"integrity": "sha512-5Hru4T3RXkosRQafcjelv7AUzw9mXqmGYsxnzeDDOWveFCJyEPMSJltvGCM+jfH98seOCbfwm9KyFg6Jm5FhAA==",
|
||||||
|
"os": ["linux"],
|
||||||
|
"cpu": ["arm64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-linux-arm64-musl@1.0.0": {
|
||||||
|
"integrity": "sha512-LTUl9jS8WsLSUGaxQZKQkxfluOJRpgvBuxxdM4pYcjib+di8AU4OzQc6+L6SzGMLcKc9H0RAjojRatBhTMqYdg==",
|
||||||
|
"os": ["linux"],
|
||||||
|
"cpu": ["arm64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-linux-riscv64-gnu@1.0.0": {
|
||||||
|
"integrity": "sha512-Iz931SAZf+WVDzpjk52Q3ffW3zw0YflFwEZMgs036Wfu1kX/LrwT9wGjsuSqyduqefUkl91/vTdAjn8hQu5ezA==",
|
||||||
|
"os": ["linux"],
|
||||||
|
"cpu": ["riscv64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-linux-x64-gnu@1.0.0": {
|
||||||
|
"integrity": "sha512-pFEQ5eFK4JusgN1K6KkO9DKP/Hi1WMJOkF8Ch03/khTc4bFbCKkCCsJG4YcOMOW9bI4XbT2/eMAWxhO0xaWgPA==",
|
||||||
|
"os": ["linux"],
|
||||||
|
"cpu": ["x64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-linux-x64-musl@1.0.0": {
|
||||||
|
"integrity": "sha512-jnvr8NrLHiZ3NCiOKWqDbkI4Ah+QDrqtZ+sddPZBltEb1mQ2coSvCSJYfict+oAwcm0c970oTmVySpjKP/lnaA==",
|
||||||
|
"os": ["linux"],
|
||||||
|
"cpu": ["x64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-win32-arm64-msvc@1.0.0": {
|
||||||
|
"integrity": "sha512-y2j9/Gfd5joqiqxdP/L1smqjQ+uAx3C4N0EC7bDHrnZEEH8ToM/OC5p3uHvtj4Lq591aHj+ArL01UDLNwT5HgQ==",
|
||||||
|
"os": ["win32"],
|
||||||
|
"cpu": ["arm64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas-win32-x64-msvc@1.0.0": {
|
||||||
|
"integrity": "sha512-qwdhh9N6Gge/hC4pL9S1tQp0iKwhSl/dYjg7+RGp9k26iRGRi5MqqUyKGOXIWli0zOcuy5Y2wIH/jk2ry6i/jA==",
|
||||||
|
"os": ["win32"],
|
||||||
|
"cpu": ["x64"]
|
||||||
|
},
|
||||||
|
"@napi-rs/canvas@1.0.0": {
|
||||||
|
"integrity": "sha512-Jqxcy1XOIqj+lH9sl1GT+il6GR3uQv13vI2mrwubP3uT8Olak2ClDrK2RnxlQKjwv8BRr4b3ug0YR7c6hBX8wg==",
|
||||||
|
"optionalDependencies": [
|
||||||
|
"@napi-rs/canvas-android-arm64",
|
||||||
|
"@napi-rs/canvas-darwin-arm64",
|
||||||
|
"@napi-rs/canvas-darwin-x64",
|
||||||
|
"@napi-rs/canvas-linux-arm-gnueabihf",
|
||||||
|
"@napi-rs/canvas-linux-arm64-gnu",
|
||||||
|
"@napi-rs/canvas-linux-arm64-musl",
|
||||||
|
"@napi-rs/canvas-linux-riscv64-gnu",
|
||||||
|
"@napi-rs/canvas-linux-x64-gnu",
|
||||||
|
"@napi-rs/canvas-linux-x64-musl",
|
||||||
|
"@napi-rs/canvas-win32-arm64-msvc",
|
||||||
|
"@napi-rs/canvas-win32-x64-msvc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"pdfjs-dist@6.0.227": {
|
||||||
|
"integrity": "sha512-/P6M4SXw+70waMVLUM7rdRtvo+dEzqE1t6W/zQNvBETo2MaRa5rrvCcAYdfWGiUzadTgM0lJmRApUrW0d9zgKg==",
|
||||||
|
"optionalDependencies": [
|
||||||
|
"@napi-rs/canvas"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"workspace": {
|
||||||
|
"dependencies": [
|
||||||
|
"npm:pdfjs-dist@6.0.227"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
File diff suppressed because one or more lines are too long
+29
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
|||||||
|
gen:
|
||||||
|
go tool templ generate
|
||||||
|
|
||||||
|
dev: gen
|
||||||
|
go run *.go
|
||||||
+12
-7
@@ -4,13 +4,11 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"plg-mudics/display/browser"
|
||||||
"plg-mudics/display/pkg"
|
"plg-mudics/display/pkg"
|
||||||
"plg-mudics/display/web"
|
"plg-mudics/display/web"
|
||||||
"plg-mudics/shared"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go tool templ generate
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -19,16 +17,23 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to get storage path", "error", err)
|
slog.Error("Failed to get storage path", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
port := "1323"
|
port := "1323"
|
||||||
|
|
||||||
// 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(shared.Version, port)
|
go web.StartWebServer(port)
|
||||||
err = shared.OpenBrowserWindow("http://localhost:"+port, true, true)
|
|
||||||
|
err = browser.Browser.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to open browser window", "error", err)
|
slog.Error("Initialize browser", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
err = pkg.OpenStartScreen()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Open start screen", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer browser.Browser.Cancel()
|
||||||
|
<-browser.Browser.Ctx.Done()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"plg-mudics/shared"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
|
||||||
)
|
|
||||||
|
|
||||||
var FileHandler fileHandler = fileHandler{}
|
|
||||||
|
|
||||||
type fileHandler struct {
|
|
||||||
runningProgram *exec.Cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fh *fileHandler) OpenFile(path string) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
mType, err := mimetype.DetectFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to detect mime type: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tempDirPath, err := os.MkdirTemp("", "plg-mudics-program-profile-")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create temporary profile directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = fh.CloseRunningProgram()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch mType.String() {
|
|
||||||
case "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.oasis.opendocument.presentation":
|
|
||||||
fh.runningProgram = exec.Command("soffice", "--show", path, "--nologo", "--view", "--norestore", fmt.Sprintf("-env:UserInstallation=file://%s", tempDirPath))
|
|
||||||
case "application/pdf":
|
|
||||||
fh.runningProgram = exec.Command("xreader", path, "--presentation")
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unsupported file type: %s", mType.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
fh.runningProgram.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
|
||||||
|
|
||||||
result := shared.RunShellCommandNonBlocking(fh.runningProgram)
|
|
||||||
if result.ExitCode != 0 {
|
|
||||||
return fmt.Errorf("could not open pdf: %s (%d)", result.Stderr, result.ExitCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fh *fileHandler) CloseRunningProgram() error {
|
|
||||||
if fh.runningProgram == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
err := syscall.Kill(-fh.runningProgram.Process.Pid, syscall.SIGTERM)
|
|
||||||
fh.runningProgram = nil
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
@@ -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,
|
||||||
|
}
|
||||||
@@ -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,
|
|
||||||
}
|
|
||||||
+22
-75
@@ -1,93 +1,23 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"plg-mudics/display/browser"
|
||||||
"plg-mudics/shared"
|
"plg-mudics/shared"
|
||||||
|
|
||||||
"github.com/micmonay/keybd_event"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDeviceIp() (string, error) {
|
|
||||||
addrs, err := net.InterfaceAddrs()
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to get network interfaces: %w", err)
|
|
||||||
}
|
|
||||||
for _, addr := range addrs {
|
|
||||||
ipNet, ok := addr.(*net.IPNet)
|
|
||||||
if ok && !ipNet.IP.IsLoopback() && ipNet.IP.To4() != nil {
|
|
||||||
return ipNet.IP.String(), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", fmt.Errorf("no suitable IP address found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDeviceMac() (string, error) {
|
|
||||||
interfaces, err := net.Interfaces()
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to get network interfaces: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, interf := range interfaces {
|
|
||||||
mac := interf.HardwareAddr.String()
|
|
||||||
if mac != "" {
|
|
||||||
return mac, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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.jpg", time.Now().Unix()))
|
||||||
|
|
||||||
cmds := []*exec.Cmd{
|
cmds := []*exec.Cmd{
|
||||||
exec.Command("gnome-screenshot", "-f", tempFilePath),
|
exec.Command("gnome-screenshot", "-f", tempFilePath),
|
||||||
@@ -148,3 +78,20 @@ func ResolveStorageFilePath(pathParam string) (string, bool, error) {
|
|||||||
|
|
||||||
return fullPath, true, nil
|
return fullPath, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ShowHTML(html string) error {
|
||||||
|
ResetView()
|
||||||
|
|
||||||
|
var templateBuffer bytes.Buffer
|
||||||
|
_ = htmlTemplate(html).Render(context.Background(), &templateBuffer)
|
||||||
|
err := browser.Browser.OpenHTML(templateBuffer.String())
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResetView() {
|
||||||
|
err := fileHandler.closeRunningProgram()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to close running program", "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,310 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
templ basicTemplate() {
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>PLG MuDiCS Display</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--background-color: black;
|
||||||
|
--foreground-color: oklch(92.3% 0.003 48.717);
|
||||||
|
--font-size: 5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
/* centers horizontally */
|
||||||
|
align-items: center;
|
||||||
|
/* centers vertically */
|
||||||
|
width: 100vw;
|
||||||
|
/* Viewport width */
|
||||||
|
height: 100vh;
|
||||||
|
/* Viewport height */
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: var(--background-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';
|
||||||
|
cursor: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
video,
|
||||||
|
img {
|
||||||
|
width: 100vw;
|
||||||
|
/* Viewport width */
|
||||||
|
height: 100vh;
|
||||||
|
/* Viewport height */
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
p,
|
||||||
|
li {
|
||||||
|
font-size: var(--font-size);
|
||||||
|
line-height: 1.2;
|
||||||
|
text-wrap: balance;
|
||||||
|
max-width: 90vw;
|
||||||
|
word-break: break-word;
|
||||||
|
margin: 0 0 calc(var(--font-size) * 0.4) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul,
|
||||||
|
ol {
|
||||||
|
padding-left: calc(var(--font-size)*1.5);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<bod>
|
||||||
|
{ children... }
|
||||||
|
</bod>
|
||||||
|
</html>
|
||||||
|
}
|
||||||
|
|
||||||
|
templ videoTemplate(path string) {
|
||||||
|
@basicTemplate() {
|
||||||
|
<video autoplay>
|
||||||
|
<source src={ "file://" + path } type="video/mp4"/>
|
||||||
|
</video>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templ htmlTemplate(html string) {
|
||||||
|
@basicTemplate() {
|
||||||
|
@templ.Raw(html)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templ imageTemplate(path string) {
|
||||||
|
@basicTemplate() {
|
||||||
|
<img src={ "file://" + path }/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templ deviceInfoTemplate(ip string, mac string, showQR bool) {
|
||||||
|
@basicTemplate() {
|
||||||
|
<div style="width: 100vw; height: 100vh; display: flex; flex-direction: row; justify-content: space-between;">
|
||||||
|
<div
|
||||||
|
style="display: flex; flex-direction: column; gap: 1rem; justify-content: end; padding: 2rem; font-size: 4rem;"
|
||||||
|
>
|
||||||
|
{ ip }
|
||||||
|
<span style="text-transform: uppercase;">{ mac }</span>
|
||||||
|
</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>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--splash-bg: transparent !important;
|
||||||
|
--splash-fade-out-state: paused !important;
|
||||||
|
--background-color: oklch(21.6% 0.006 56.043);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templ pdfTemplate(path string, serverOrigin string) {
|
||||||
|
@basicTemplate() {
|
||||||
|
<base href={ serverOrigin + "/" }/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
id="pdf"
|
||||||
|
data-src={ "api/file/" + strings.Split(path, "/.local/share/plg-mudics/display")[1] }
|
||||||
|
data-lib="static/pdfjs/pdf.min.mjs"
|
||||||
|
data-worker="static/pdfjs/pdf.worker.min.mjs"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html,body,#pdf {
|
||||||
|
margin:0;
|
||||||
|
width:100%;
|
||||||
|
height:100%;
|
||||||
|
overflow:hidden;
|
||||||
|
background:#000;
|
||||||
|
}
|
||||||
|
#pdf {
|
||||||
|
display:grid;
|
||||||
|
place-items:center;
|
||||||
|
}
|
||||||
|
#pdf canvas {
|
||||||
|
grid-area:1/1;
|
||||||
|
display:block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
const host=document.querySelector("#pdf");
|
||||||
|
const resolve=x=>new URL(x,document.baseURI).href;
|
||||||
|
|
||||||
|
const P=await import(resolve(host.dataset.lib));
|
||||||
|
P.GlobalWorkerOptions.workerSrc=resolve(host.dataset.worker);
|
||||||
|
|
||||||
|
const pdf=await P.getDocument({
|
||||||
|
url:resolve(host.dataset.src),
|
||||||
|
useWasm:false
|
||||||
|
}).promise;
|
||||||
|
|
||||||
|
const cache=new Map();
|
||||||
|
let currentPage=1;
|
||||||
|
let wantedPage=1;
|
||||||
|
let requestNumber=0;
|
||||||
|
|
||||||
|
function renderPage(number) {
|
||||||
|
if(cache.has(number)) return cache.get(number);
|
||||||
|
|
||||||
|
const promise=(async()=>{
|
||||||
|
const page=await pdf.getPage(number);
|
||||||
|
const original=page.getViewport({scale:1});
|
||||||
|
const scale=Math.min(
|
||||||
|
innerWidth/original.width,
|
||||||
|
innerHeight/original.height
|
||||||
|
);
|
||||||
|
|
||||||
|
// Use 1 on old hardware. Raise to 1.5 for sharper output.
|
||||||
|
const pixelRatio=1;
|
||||||
|
const viewport=page.getViewport({
|
||||||
|
scale:scale*pixelRatio
|
||||||
|
});
|
||||||
|
|
||||||
|
const canvas=document.createElement("canvas");
|
||||||
|
canvas.width=Math.ceil(viewport.width);
|
||||||
|
canvas.height=Math.ceil(viewport.height);
|
||||||
|
canvas.style.width=`${viewport.width/pixelRatio}px`;
|
||||||
|
canvas.style.height=`${viewport.height/pixelRatio}px`;
|
||||||
|
|
||||||
|
const task=page.render({
|
||||||
|
canvasContext:canvas.getContext("2d"),
|
||||||
|
viewport
|
||||||
|
});
|
||||||
|
|
||||||
|
await task.promise;
|
||||||
|
return canvas;
|
||||||
|
})().catch(error=>{
|
||||||
|
cache.delete(number);
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
|
||||||
|
cache.set(number,promise);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function show(number) {
|
||||||
|
wantedPage=Math.max(1,Math.min(pdf.numPages,number));
|
||||||
|
const request=++requestNumber;
|
||||||
|
const canvas=await renderPage(wantedPage);
|
||||||
|
|
||||||
|
// Ignore an obsolete result after multiple fast key presses.
|
||||||
|
if(request!==requestNumber) return;
|
||||||
|
|
||||||
|
// The new canvas is already completely rendered.
|
||||||
|
host.replaceChildren(canvas);
|
||||||
|
currentPage=wantedPage;
|
||||||
|
|
||||||
|
pruneCache();
|
||||||
|
preloadNeighbours();
|
||||||
|
}
|
||||||
|
|
||||||
|
function preloadNeighbours() {
|
||||||
|
const page=currentPage;
|
||||||
|
|
||||||
|
requestIdleCallback(async()=>{
|
||||||
|
if(page+1<=pdf.numPages) {
|
||||||
|
await renderPage(page+1);
|
||||||
|
}
|
||||||
|
if(page-1>=1) {
|
||||||
|
await renderPage(page-1);
|
||||||
|
}
|
||||||
|
},{timeout:250});
|
||||||
|
}
|
||||||
|
|
||||||
|
function pruneCache() {
|
||||||
|
const keep=new Set([
|
||||||
|
currentPage-1,
|
||||||
|
currentPage,
|
||||||
|
currentPage+1
|
||||||
|
]);
|
||||||
|
|
||||||
|
for(const [number,promise] of cache) {
|
||||||
|
if(keep.has(number)) continue;
|
||||||
|
|
||||||
|
cache.delete(number);
|
||||||
|
promise.then(canvas=>{
|
||||||
|
if(!canvas.isConnected) {
|
||||||
|
canvas.width=0;
|
||||||
|
canvas.height=0;
|
||||||
|
}
|
||||||
|
}).catch(()=>{});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addEventListener("keydown",event=>{
|
||||||
|
if(event.key==="ArrowRight") {
|
||||||
|
event.preventDefault();
|
||||||
|
show(wantedPage+1);
|
||||||
|
} else if(event.key==="ArrowLeft") {
|
||||||
|
event.preventDefault();
|
||||||
|
show(wantedPage-1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addEventListener("resize",()=>{
|
||||||
|
cache.clear();
|
||||||
|
show(currentPage);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.pdfViewer={
|
||||||
|
page:()=>currentPage,
|
||||||
|
count:()=>pdf.numPages,
|
||||||
|
show
|
||||||
|
};
|
||||||
|
|
||||||
|
await show(1);
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
templ startScreenTemplate(splashScreenHtml string, ip string, mac string, qrPath string) {
|
||||||
|
@basicTemplate() {
|
||||||
|
<div style="width: 100vw; height: 100vh; display: flex; flex-direction: row; justify-content: space-between;">
|
||||||
|
<div
|
||||||
|
style="display: flex; flex-direction: column; gap: 1rem; justify-content: end; padding: 2rem; font-size: 4rem;"
|
||||||
|
>
|
||||||
|
{ ip }
|
||||||
|
<span style="text-transform: uppercase;">{ mac }</span>
|
||||||
|
</div>
|
||||||
|
if qrPath != "" {
|
||||||
|
<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={ "file://" + qrPath }
|
||||||
|
alt="QR-Code"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
@templ.Raw(splashScreenHtml)
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--splash-bg: transparent !important;
|
||||||
|
--splash-fade-out-state: paused !important;
|
||||||
|
--background-color: oklch(21.6% 0.006 56.043);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"plg-mudics/shared"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
|
|
||||||
|
"plg-mudics/display/browser"
|
||||||
|
)
|
||||||
|
|
||||||
|
var fileHandler fileHandlerType = fileHandlerType{}
|
||||||
|
|
||||||
|
type fileHandlerType struct {
|
||||||
|
runningProgram *exec.Cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenFile(path string) error {
|
||||||
|
ResetView()
|
||||||
|
|
||||||
|
mType, err := mimetype.DetectFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("detect mime type of file %q: %w", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch mType.String() {
|
||||||
|
case "video/mp4":
|
||||||
|
var templateBuffer bytes.Buffer
|
||||||
|
_ = videoTemplate(path).Render(context.Background(), &templateBuffer)
|
||||||
|
err = browser.Browser.OpenHTML(templateBuffer.String())
|
||||||
|
case "image/jpeg", "image/png", "image/gif":
|
||||||
|
var templateBuffer bytes.Buffer
|
||||||
|
_ = imageTemplate(path).Render(context.Background(), &templateBuffer)
|
||||||
|
err = browser.Browser.OpenHTML(templateBuffer.String())
|
||||||
|
case "application/pdf":
|
||||||
|
var templateBuffer bytes.Buffer
|
||||||
|
err = pdfTemplate(path, "http://127.0.0.1:1323").Render(context.Background(), &templateBuffer)
|
||||||
|
if err == nil {
|
||||||
|
err = browser.Browser.OpenHTML(templateBuffer.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
case "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.oasis.opendocument.presentation":
|
||||||
|
err = fileHandler.openFileWithApp(path)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unsupported file type: %s", mType.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fh *fileHandlerType) openFileWithApp(path string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
mType, err := mimetype.DetectFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to detect mime type: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch mType.String() {
|
||||||
|
case "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.oasis.opendocument.presentation":
|
||||||
|
err = fh.openLibreoffice(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unsupported file type: %s", mType.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
fh.runningProgram.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||||
|
|
||||||
|
result := shared.RunShellCommandNonBlocking(fh.runningProgram)
|
||||||
|
if result.ExitCode != 0 {
|
||||||
|
return fmt.Errorf("could not open pdf: %s (%d)", result.Stderr, result.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fh *fileHandlerType) openLibreoffice(path string) error {
|
||||||
|
// yes, we need this weird workaround to delete lock files since libreoffice
|
||||||
|
// doesn't expose an option to ignore them or prevent their creation
|
||||||
|
// the --view argument for some reason doesn't work with --show
|
||||||
|
parent := filepath.Dir(path)
|
||||||
|
cmd := exec.Command("find", parent, "-name", ".~lock*", "-type", "f", "-delete")
|
||||||
|
result := shared.RunShellCommand(cmd)
|
||||||
|
if result.ExitCode != 0 {
|
||||||
|
slog.Warn("could not remove lock files", "path", parent, "stderr", result.Stderr, "exitCode", result.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
tempDirPath, err := os.MkdirTemp("", "plg-mudics-program-profile-")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create temporary profile directory: %w", err)
|
||||||
|
}
|
||||||
|
fh.runningProgram = exec.Command("soffice", "--show", path, "--nologo", "--norestore", fmt.Sprintf("-env:UserInstallation=file://%s", tempDirPath))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fh *fileHandlerType) closeRunningProgram() error {
|
||||||
|
if fh.runningProgram == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err := syscall.Kill(-fh.runningProgram.Process.Pid, syscall.SIGTERM)
|
||||||
|
fh.runningProgram = nil
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"image/color"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"plg-mudics/shared"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"plg-mudics/display/browser"
|
||||||
|
|
||||||
|
"github.com/skip2/go-qrcode"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OpenStartScreen() error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
raw := shared.RawSplashScreenTemplate
|
||||||
|
html := strings.ReplaceAll(raw, "%%APP-VERSION%%", shared.Version)
|
||||||
|
|
||||||
|
ip, err := getDeviceIp()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("get device IP: %w", err)
|
||||||
|
}
|
||||||
|
mac, err := getDeviceMac()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("get device MAC address: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
port := 8080
|
||||||
|
showQrCode := !isPortFree(port)
|
||||||
|
qrCodePath := ""
|
||||||
|
if showQrCode {
|
||||||
|
qrCodePath, err = generateQRCode(fmt.Sprintf("http://%s:%d", ip, port))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("generate QR code: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var templateBuffer bytes.Buffer
|
||||||
|
_ = startScreenTemplate(html, ip, mac, qrCodePath).Render(context.Background(), &templateBuffer)
|
||||||
|
err = browser.Browser.OpenHTML(templateBuffer.String())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open start screen in browser: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDeviceIp() (string, error) {
|
||||||
|
addrs, err := net.InterfaceAddrs()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to get network interfaces: %w", err)
|
||||||
|
}
|
||||||
|
for _, addr := range addrs {
|
||||||
|
ipNet, ok := addr.(*net.IPNet)
|
||||||
|
if ok && !ipNet.IP.IsLoopback() && ipNet.IP.To4() != nil {
|
||||||
|
return ipNet.IP.String(), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("no suitable IP address found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func isPortFree(port int) bool {
|
||||||
|
addr := fmt.Sprintf("127.0.0.1:%d", port)
|
||||||
|
l, err := net.Listen("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_ = l.Close()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDeviceMac() (string, error) {
|
||||||
|
interfaces, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to get network interfaces: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, interf := range interfaces {
|
||||||
|
mac := interf.HardwareAddr.String()
|
||||||
|
if mac != "" {
|
||||||
|
return mac, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("no suitable MAC address found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateQRCode(data string) (string, error) {
|
||||||
|
qr, err := qrcode.New(data, qrcode.Medium)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("could not generate qr code: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
qr.DisableBorder = true
|
||||||
|
qr.ForegroundColor = color.RGBA{R: 0x1c, G: 0x19, B: 0x17, A: 0xff}
|
||||||
|
qr.BackgroundColor = color.RGBA{R: 0xe7, G: 0xe5, B: 0xe4, A: 0xff}
|
||||||
|
|
||||||
|
png, err := qr.PNG(-1)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("could not render qr code: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.CreateTemp("", "mudics-qr-code-*.png")
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("could not save qr code: %w", err)
|
||||||
|
}
|
||||||
|
defer func() { _ = file.Close() }()
|
||||||
|
|
||||||
|
_, err = file.Write(png)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("could not write qr code to file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return file.Name(), nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
meta {
|
||||||
|
name: openWebsite
|
||||||
|
type: http
|
||||||
|
seq: 10
|
||||||
|
}
|
||||||
|
|
||||||
|
patch {
|
||||||
|
url: 127.0.0.1:1323/api/openWebsite
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"url": "https://example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
import (
|
|
||||||
"embed"
|
|
||||||
"io/fs"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:embed all:static
|
|
||||||
var staticDir embed.FS
|
|
||||||
|
|
||||||
// BuildDirFS contains the embedded dist directory files (without the "build" prefix)
|
|
||||||
var StaticDirFS, _ = fs.Sub(staticDir, "static")
|
|
||||||
+38
-176
@@ -1,52 +1,34 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
shared "plg-mudics/shared"
|
shared "plg-mudics/shared"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
"github.com/skip2/go-qrcode"
|
|
||||||
|
|
||||||
|
"plg-mudics/display/browser"
|
||||||
|
"plg-mudics/display/internal/pdfjs"
|
||||||
"plg-mudics/display/pkg"
|
"plg-mudics/display/pkg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string
|
func StartWebServer(port string) {
|
||||||
var sseConnection chan string
|
|
||||||
|
|
||||||
func StartWebServer(v string, port string) {
|
|
||||||
version = v
|
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
e.GET("/", indexRoute)
|
pdfJSGroup := e.Group("/static/pdfjs")
|
||||||
e.GET("/sse", sseRoute)
|
pdfJSGroup.Use(middleware.CORS())
|
||||||
e.GET("/splash", func(ctx echo.Context) error {
|
pdfJSGroup.StaticFS(
|
||||||
html := shared.SplashScreenTemplate
|
"/",
|
||||||
html = strings.ReplaceAll(html, "%%APP-VERSION%%", version)
|
echo.MustSubFS(pdfjs.Files, "node_modules/pdfjs-dist/build"),
|
||||||
return ctx.HTML(http.StatusOK, html)
|
)
|
||||||
})
|
|
||||||
e.GET("/qr", qrRoute)
|
|
||||||
|
|
||||||
staticGroup := e.Group("/static")
|
|
||||||
staticGroup.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
|
||||||
Filesystem: http.FS(StaticDirFS),
|
|
||||||
HTML5: true,
|
|
||||||
}))
|
|
||||||
|
|
||||||
apiGroup := e.Group("/api")
|
apiGroup := e.Group("/api")
|
||||||
apiGroup.Use(middleware.CORS())
|
apiGroup.Use(middleware.CORS())
|
||||||
@@ -55,6 +37,7 @@ func StartWebServer(v string, port string) {
|
|||||||
apiGroup.PATCH("/keyboardInput", keyboardInputRoute)
|
apiGroup.PATCH("/keyboardInput", keyboardInputRoute)
|
||||||
apiGroup.PATCH("/showHTML", showHTMLRoute)
|
apiGroup.PATCH("/showHTML", showHTMLRoute)
|
||||||
apiGroup.PATCH("/takeScreenshot", takeScreenshotRoute)
|
apiGroup.PATCH("/takeScreenshot", takeScreenshotRoute)
|
||||||
|
apiGroup.PATCH("/openWebsite", openWebsiteRoute)
|
||||||
|
|
||||||
fileGroup := apiGroup.Group("/file")
|
fileGroup := apiGroup.Group("/file")
|
||||||
fileGroup.Use(extractFilePathMiddleware)
|
fileGroup.Use(extractFilePathMiddleware)
|
||||||
@@ -69,85 +52,6 @@ func StartWebServer(v string, port string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexRoute(ctx echo.Context) error {
|
|
||||||
return indexTemplate().Render(ctx.Request().Context(), ctx.Response().Writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sseRoute(ctx echo.Context) error {
|
|
||||||
slog.Info("SSE client connected")
|
|
||||||
|
|
||||||
w := ctx.Response()
|
|
||||||
w.Header().Set("Content-Type", "text/event-stream")
|
|
||||||
w.Header().Set("Cache-Control", "no-cache")
|
|
||||||
w.Header().Set("Connection", "keep-alive")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
flusher, _ := w.Writer.(http.Flusher)
|
|
||||||
|
|
||||||
sseConnection = make(chan string)
|
|
||||||
|
|
||||||
// init display
|
|
||||||
ip, err := pkg.GetDeviceIp()
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("Failed to get device IP address", "error", err)
|
|
||||||
}
|
|
||||||
mac, err := pkg.GetDeviceMac()
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("Failed to get device MAC address", "error", err)
|
|
||||||
}
|
|
||||||
showQR := !isPortFree(8080)
|
|
||||||
var status bytes.Buffer
|
|
||||||
deviceInfoTemplate(ip, mac, showQR).Render(context.Background(), &status)
|
|
||||||
connectedEvent := Event{
|
|
||||||
Data: status.Bytes(),
|
|
||||||
}
|
|
||||||
connectedEvent.MarshalTo(w)
|
|
||||||
flusher.Flush()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Request().Context().Done():
|
|
||||||
slog.Info("SSE client disconnected")
|
|
||||||
sseConnection = nil
|
|
||||||
return nil
|
|
||||||
|
|
||||||
case event := <-sseConnection:
|
|
||||||
rawEvent := Event{
|
|
||||||
Event: []byte(""),
|
|
||||||
Data: []byte(event),
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := rawEvent.MarshalTo(w); err != nil {
|
|
||||||
slog.Warn("Error writing to client", "error", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
flusher.Flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func qrRoute(c echo.Context) error {
|
|
||||||
data := c.QueryParam("data")
|
|
||||||
if data == "" {
|
|
||||||
return c.String(http.StatusBadRequest, "missing data")
|
|
||||||
}
|
|
||||||
|
|
||||||
qr, err := qrcode.New(data, qrcode.Medium)
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusInternalServerError, "could not generate qr")
|
|
||||||
}
|
|
||||||
|
|
||||||
qr.DisableBorder = true
|
|
||||||
qr.ForegroundColor = color.RGBA{R: 0x1c, G: 0x19, B: 0x17, A: 0xff}
|
|
||||||
qr.BackgroundColor = color.RGBA{R: 0xe7, G: 0xe5, B: 0xe4, A: 0xff}
|
|
||||||
|
|
||||||
png, err := qr.PNG(-1)
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusInternalServerError, "could not encode png")
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Blob(http.StatusOK, "image/png", png)
|
|
||||||
}
|
|
||||||
|
|
||||||
func extractFilePathMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
func extractFilePathMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(ctx echo.Context) error {
|
return func(ctx echo.Context) error {
|
||||||
raw := ctx.Param("path")
|
raw := ctx.Param("path")
|
||||||
@@ -216,12 +120,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
|
||||||
@@ -231,7 +129,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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -272,7 +170,10 @@ func uploadFileRoute(ctx echo.Context) error {
|
|||||||
slog.Error("Failed to close file", "file", fullPath, "error", fileCloseErr)
|
slog.Error("Failed to close file", "file", fullPath, "error", fileCloseErr)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(fullPath)
|
err = os.Remove(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
slog.Warn("could not remove broken file", "file", fullPath, "error", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -301,14 +202,7 @@ func downloadFileRoute(ctx echo.Context) error {
|
|||||||
|
|
||||||
slog.Info("Serving file for download", "path", fullPath)
|
slog.Info("Serving file for download", "path", fullPath)
|
||||||
|
|
||||||
file, err := os.Open(fullPath)
|
return ctx.Attachment(fullPath, filepath.Base(fullPath))
|
||||||
if err != nil {
|
|
||||||
slog.Error("Failed to open file", "file", fullPath, "error", err)
|
|
||||||
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to open file"})
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
return ctx.Stream(http.StatusOK, "application/octet-stream", file)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func openFileRoute(ctx echo.Context) error {
|
func openFileRoute(ctx echo.Context) error {
|
||||||
@@ -321,38 +215,7 @@ func openFileRoute(ctx echo.Context) error {
|
|||||||
return ctx.JSON(http.StatusNotFound, shared.ErrorResponse{Description: "File not found"})
|
return ctx.JSON(http.StatusNotFound, shared.ErrorResponse{Description: "File not found"})
|
||||||
}
|
}
|
||||||
|
|
||||||
if sseConnection == nil {
|
err = pkg.OpenFile(fullPath)
|
||||||
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Cant connect to display browser client"})
|
|
||||||
}
|
|
||||||
|
|
||||||
err = resetView()
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("Failed to reset view", "error", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mType, err := mimetype.DetectFile(fullPath)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("Failed to detect mime type", "file", pathParam, "error", err)
|
|
||||||
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to detect file type"})
|
|
||||||
}
|
|
||||||
|
|
||||||
switch mType.String() {
|
|
||||||
case "video/mp4":
|
|
||||||
var templateBuffer bytes.Buffer
|
|
||||||
videoTemplate(pathParam).Render(context.Background(), &templateBuffer)
|
|
||||||
|
|
||||||
sseConnection <- templateBuffer.String()
|
|
||||||
case "image/jpeg", "image/png", "image/gif":
|
|
||||||
var templateBuffer bytes.Buffer
|
|
||||||
imageTemplate(pathParam).Render(context.Background(), &templateBuffer)
|
|
||||||
sseConnection <- templateBuffer.String()
|
|
||||||
case "application/pdf", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.oasis.opendocument.presentation":
|
|
||||||
err = pkg.FileHandler.OpenFile(fullPath)
|
|
||||||
default:
|
|
||||||
slog.Info("Unsupported file type", "type", mType)
|
|
||||||
return ctx.JSON(http.StatusUnsupportedMediaType, shared.ErrorResponse{Description: "Unsupported file type: " + mType.String()})
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to open file", "file", pathParam, "error", err)
|
slog.Error("Failed to open file", "file", pathParam, "error", err)
|
||||||
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to open file"})
|
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to open file"})
|
||||||
@@ -371,13 +234,12 @@ func showHTMLRoute(ctx echo.Context) error {
|
|||||||
return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: shared.BadRequestDescription})
|
return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: shared.BadRequestDescription})
|
||||||
}
|
}
|
||||||
|
|
||||||
err := resetView()
|
err := pkg.ShowHTML(request.HTML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to reset view", "error", err)
|
slog.Error("Failed to open html", "error", err)
|
||||||
|
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to open html"})
|
||||||
}
|
}
|
||||||
|
|
||||||
sseConnection <- request.HTML
|
|
||||||
|
|
||||||
slog.Info("HTML content sent to client")
|
slog.Info("HTML content sent to client")
|
||||||
return ctx.JSON(http.StatusOK, struct{}{})
|
return ctx.JSON(http.StatusOK, struct{}{})
|
||||||
}
|
}
|
||||||
@@ -385,7 +247,7 @@ func showHTMLRoute(ctx echo.Context) error {
|
|||||||
func pingRoute(ctx echo.Context) error {
|
func pingRoute(ctx echo.Context) error {
|
||||||
return ctx.JSON(http.StatusOK, struct {
|
return ctx.JSON(http.StatusOK, struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
}{Version: version})
|
}{Version: shared.Version})
|
||||||
}
|
}
|
||||||
|
|
||||||
func takeScreenshotRoute(ctx echo.Context) error {
|
func takeScreenshotRoute(ctx echo.Context) error {
|
||||||
@@ -428,24 +290,24 @@ func previewRoute(ctx echo.Context) error {
|
|||||||
return ctx.File(outputFilePath)
|
return ctx.File(outputFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset previous file views so they dont collide with the new one
|
func openWebsiteRoute(ctx echo.Context) error {
|
||||||
func resetView() error {
|
var err error
|
||||||
err := pkg.FileHandler.CloseRunningProgram()
|
|
||||||
|
var request struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
if err := ctx.Bind(&request); err != nil {
|
||||||
|
slog.Error("Failed to parse website input", "error", err)
|
||||||
|
return ctx.JSON(http.StatusBadRequest, shared.ErrorResponse{Description: shared.BadRequestDescription})
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Opening url")
|
||||||
|
|
||||||
|
err = browser.Browser.OpenPage(request.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to close running program: %w", err)
|
slog.Error("Failed to open website", "url", request.URL, "error", err)
|
||||||
|
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to open website"})
|
||||||
}
|
}
|
||||||
|
|
||||||
sseConnection <- ""
|
return ctx.JSON(http.StatusOK, struct{}{})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isPortFree(port int) bool {
|
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", port)
|
|
||||||
l, err := net.Listen("tcp", addr)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
_ = l.Close()
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
templ indexTemplate() {
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
||||||
<title>PLG MuDiCS Display</title>
|
|
||||||
<script src="/static/htmx.min.js"></script>
|
|
||||||
<script src="/static/htmx-ext-sse.min.js"></script>
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--background-color: black;
|
|
||||||
--foreground-color: oklch(92.3% 0.003 48.717);
|
|
||||||
--font-size: 5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
/* centers horizontally */
|
|
||||||
align-items: center;
|
|
||||||
/* centers vertically */
|
|
||||||
width: 100vw;
|
|
||||||
/* Viewport width */
|
|
||||||
height: 100vh;
|
|
||||||
/* Viewport height */
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
overflow: hidden;
|
|
||||||
background-color: var(--background-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';
|
|
||||||
cursor: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
video,
|
|
||||||
img,
|
|
||||||
iframe {
|
|
||||||
width: 100vw;
|
|
||||||
/* Viewport width */
|
|
||||||
height: 100vh;
|
|
||||||
/* Viewport height */
|
|
||||||
object-fit: contain;
|
|
||||||
}
|
|
||||||
|
|
||||||
p,
|
|
||||||
li {
|
|
||||||
font-size: var(--font-size);
|
|
||||||
line-height: 1.2;
|
|
||||||
text-wrap: balance;
|
|
||||||
max-width: 90vw;
|
|
||||||
word-break: break-word;
|
|
||||||
margin: 0 0 calc(var(--font-size) * 0.4) 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul,
|
|
||||||
ol {
|
|
||||||
padding-left: calc(var(--font-size)*1.5);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<script>
|
|
||||||
document.addEventListener('keydown', function (event) {
|
|
||||||
if (event.code === 'Space') {
|
|
||||||
event.preventDefault();
|
|
||||||
var video = document.querySelector('video');
|
|
||||||
if (video) {
|
|
||||||
if (video.paused) {
|
|
||||||
video.play();
|
|
||||||
} else {
|
|
||||||
video.pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<bod>
|
|
||||||
<div hx-get="/splash" hx-trigger="load"></div>
|
|
||||||
<main hx-ext="sse" sse-connect="/sse" sse-swap="message"></main>
|
|
||||||
</bod>
|
|
||||||
</html>
|
|
||||||
}
|
|
||||||
|
|
||||||
templ videoTemplate(path string) {
|
|
||||||
<video autoplay>
|
|
||||||
<source src={ "/api/file/" + path } type="video/mp4"/>
|
|
||||||
</video>
|
|
||||||
}
|
|
||||||
|
|
||||||
templ imageTemplate(path string) {
|
|
||||||
<img src={ "/api/file/" + path }/>
|
|
||||||
}
|
|
||||||
|
|
||||||
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="display: flex; flex-direction: column; gap: 1rem; justify-content: end; padding: 2rem; font-size: 4rem;"
|
|
||||||
>
|
|
||||||
{ ip }
|
|
||||||
<span style="text-transform: uppercase;">{ mac }</span>
|
|
||||||
</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>
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--splash-bg: transparent !important;
|
|
||||||
--splash-fade-out-state: paused !important;
|
|
||||||
--background-color: oklch(21.6% 0.006 56.043);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Event represents Server-Sent Event.
|
|
||||||
// SSE explanation: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format
|
|
||||||
type Event struct {
|
|
||||||
// ID is used to set the EventSource object's last event ID value.
|
|
||||||
ID []byte
|
|
||||||
// Data field is for the message. When the EventSource receives multiple consecutive lines
|
|
||||||
// that begin with data:, it concatenates them, inserting a newline character between each one.
|
|
||||||
// Trailing newlines are removed.
|
|
||||||
Data []byte
|
|
||||||
// Event is a string identifying the type of event described. If this is specified, an event
|
|
||||||
// will be dispatched on the browser to the listener for the specified event name; the website
|
|
||||||
// source code should use addEventListener() to listen for named events. The onmessage handler
|
|
||||||
// is called if no event name is specified for a message.
|
|
||||||
Event []byte
|
|
||||||
// Retry is the reconnection time. If the connection to the server is lost, the browser will
|
|
||||||
// wait for the specified time before attempting to reconnect. This must be an integer, specifying
|
|
||||||
// the reconnection time in milliseconds. If a non-integer value is specified, the field is ignored.
|
|
||||||
Retry []byte
|
|
||||||
// Comment line can be used to prevent connections from timing out; a server can send a comment
|
|
||||||
// periodically to keep the connection alive.
|
|
||||||
Comment []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalTo marshals Event to given Writer
|
|
||||||
func (ev *Event) MarshalTo(w io.Writer) error {
|
|
||||||
// Marshalling part is taken from: https://github.com/r3labs/sse/blob/c6d5381ee3ca63828b321c16baa008fd6c0b4564/http.go#L16
|
|
||||||
if len(ev.Data) == 0 && len(ev.Comment) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ev.Data) > 0 {
|
|
||||||
if _, err := fmt.Fprintf(w, "id: %s\n", ev.ID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
sd := bytes.Split(ev.Data, []byte("\n"))
|
|
||||||
for i := range sd {
|
|
||||||
if _, err := fmt.Fprintf(w, "data: %s\n", sd[i]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ev.Event) > 0 {
|
|
||||||
if _, err := fmt.Fprintf(w, "event: %s\n", ev.Event); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ev.Retry) > 0 {
|
|
||||||
if _, err := fmt.Fprintf(w, "retry: %s\n", ev.Retry); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ev.Comment) > 0 {
|
|
||||||
if _, err := fmt.Fprintf(w, ": %s\n", ev.Comment); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := fmt.Fprint(w, "\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
(function(){var g;htmx.defineExtension("sse",{init:function(e){g=e;if(htmx.createEventSource==undefined){htmx.createEventSource=t}},getSelectors:function(){return["[sse-connect]","[data-sse-connect]","[sse-swap]","[data-sse-swap]"]},onEvent:function(e,t){var r=t.target||t.detail.elt;switch(e){case"htmx:beforeCleanupElement":var n=g.getInternalData(r);var s=n.sseEventSource;if(s){g.triggerEvent(r,"htmx:sseClose",{source:s,type:"nodeReplaced"});n.sseEventSource.close()}return;case"htmx:afterProcessNode":i(r)}}});function t(e){return new EventSource(e,{withCredentials:true})}function a(n){if(g.getAttributeValue(n,"sse-swap")){var s=g.getClosestMatch(n,v);if(s==null){return null}var e=g.getInternalData(s);var a=e.sseEventSource;var t=g.getAttributeValue(n,"sse-swap");var r=t.split(",");for(var i=0;i<r.length;i++){const u=r[i].trim();const c=function(e){if(l(s)){return}if(!g.bodyContains(n)){a.removeEventListener(u,c);return}if(!g.triggerEvent(n,"htmx:sseBeforeMessage",e)){return}f(n,e.data);g.triggerEvent(n,"htmx:sseMessage",e)};g.getInternalData(n).sseEventListener=c;a.addEventListener(u,c)}}if(g.getAttributeValue(n,"hx-trigger")){var s=g.getClosestMatch(n,v);if(s==null){return null}var e=g.getInternalData(s);var a=e.sseEventSource;var o=g.getTriggerSpecs(n);o.forEach(function(t){if(t.trigger.slice(0,4)!=="sse:"){return}var r=function(e){if(l(s)){return}if(!g.bodyContains(n)){a.removeEventListener(t.trigger.slice(4),r)}htmx.trigger(n,t.trigger,e);htmx.trigger(n,"htmx:sseMessage",e)};g.getInternalData(n).sseEventListener=r;a.addEventListener(t.trigger.slice(4),r)})}}function i(e,t){if(e==null){return null}if(g.getAttributeValue(e,"sse-connect")){var r=g.getAttributeValue(e,"sse-connect");if(r==null){return}n(e,r,t)}a(e)}function n(r,e,n){var s=htmx.createEventSource(e);s.onerror=function(e){g.triggerErrorEvent(r,"htmx:sseError",{error:e,source:s});if(l(r)){return}if(s.readyState===EventSource.CLOSED){n=n||0;n=Math.max(Math.min(n*2,128),1);var t=n*500;window.setTimeout(function(){i(r,n)},t)}};s.onopen=function(e){g.triggerEvent(r,"htmx:sseOpen",{source:s});if(n&&n>0){const t=r.querySelectorAll("[sse-swap], [data-sse-swap], [hx-trigger], [data-hx-trigger]");for(let e=0;e<t.length;e++){a(t[e])}n=0}};g.getInternalData(r).sseEventSource=s;var t=g.getAttributeValue(r,"sse-close");if(t){s.addEventListener(t,function(){g.triggerEvent(r,"htmx:sseClose",{source:s,type:"message"});s.close()})}}function l(e){if(!g.bodyContains(e)){var t=g.getInternalData(e).sseEventSource;if(t!=undefined){g.triggerEvent(e,"htmx:sseClose",{source:t,type:"nodeMissing"});t.close();return true}}return false}function f(t,r){g.withExtensions(t,function(e){r=e.transformResponse(r,null,t)});var e=g.getSwapSpecification(t);var n=g.getTarget(t);g.swap(n,r,e,{contextElement:t})}function v(e){return g.getInternalData(e).sseEventSource!=null}})();
|
|
||||||
Vendored
-1
File diff suppressed because one or more lines are too long
@@ -11,20 +11,13 @@
|
|||||||
in {
|
in {
|
||||||
devShells."x86_64-linux".default = pkgs.mkShell {
|
devShells."x86_64-linux".default = pkgs.mkShell {
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
|
gcc
|
||||||
libreoffice
|
libreoffice
|
||||||
ungoogled-chromium
|
ungoogled-chromium
|
||||||
xreader
|
|
||||||
imagemagick
|
imagemagick
|
||||||
ffmpeg
|
ffmpeg
|
||||||
ghostscript
|
|
||||||
gnome-screenshot
|
gnome-screenshot
|
||||||
|
|
||||||
playwright-driver.browsers
|
|
||||||
];
|
];
|
||||||
|
|
||||||
PLAYWRIGHT_BROWSERS_PATH = pkgs.playwright-driver.browsers;
|
|
||||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "true";
|
|
||||||
PW_DISABLE_TS_ESM = "true";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-14
@@ -1,24 +1,25 @@
|
|||||||
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/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
|
||||||
github.com/a-h/templ v0.3.960/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo=
|
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/mdlayher/raw v0.0.0-20190313224157-43dbcdd7739d h1:rjAS0af7FIYCScTtEU5KjIldC6qVaEScUJhABHC+ccM=
|
||||||
|
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
|
||||||
|
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
|
||||||
|
github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po=
|
||||||
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 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
|
||||||
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 h1:E2/AqCUMZGgd73TQkxUMcMla25GB9i/5HOdLr+uH7Vo=
|
||||||
|
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 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
|
||||||
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
|
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
|
||||||
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=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
+13
-3
@@ -92,20 +92,19 @@
|
|||||||
nushell
|
nushell
|
||||||
unzip
|
unzip
|
||||||
iputils
|
iputils
|
||||||
xreader
|
|
||||||
tree
|
tree
|
||||||
jq
|
jq
|
||||||
|
|
||||||
# Libraries
|
# Libraries
|
||||||
imagemagick
|
imagemagick
|
||||||
ffmpeg
|
ffmpeg
|
||||||
ghostscript
|
|
||||||
];
|
];
|
||||||
|
|
||||||
home-manager.users.mudics = {
|
home-manager.users.mudics = {
|
||||||
xfconf.settings = {
|
xfconf.settings = {
|
||||||
xfce4-power-manager."xfce4-power-manager/dpms-enabled" = false;
|
xfce4-power-manager."xfce4-power-manager/dpms-enabled" = false;
|
||||||
xfce4-screensaver."saver/enabled" = false;
|
xfce4-screensaver."saver/enabled" = false;
|
||||||
|
displays.Notify = 0; # disable popup when connecting new display
|
||||||
};
|
};
|
||||||
|
|
||||||
home.stateVersion = "25.05";
|
home.stateVersion = "25.05";
|
||||||
@@ -116,7 +115,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";
|
||||||
@@ -152,6 +151,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 - -"
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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."
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//go:embed splash_screen.html
|
//go:embed splash_screen.html
|
||||||
var SplashScreenTemplate string
|
var RawSplashScreenTemplate string
|
||||||
|
|
||||||
//go:embed version.txt
|
//go:embed version.txt
|
||||||
var versionNotTrimmed string
|
var versionNotTrimmed string
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
{
|
|
||||||
"Escape": "VK_ESC",
|
|
||||||
"Digit1": "VK_1",
|
|
||||||
"Digit2": "VK_2",
|
|
||||||
"Digit3": "VK_3",
|
|
||||||
"Digit4": "VK_4",
|
|
||||||
"Digit5": "VK_5",
|
|
||||||
"Digit6": "VK_6",
|
|
||||||
"Digit7": "VK_7",
|
|
||||||
"Digit8": "VK_8",
|
|
||||||
"Digit9": "VK_9",
|
|
||||||
"Digit0": "VK_0",
|
|
||||||
"KeyQ": "VK_Q",
|
|
||||||
"KeyW": "VK_W",
|
|
||||||
"KeyE": "VK_E",
|
|
||||||
"KeyR": "VK_R",
|
|
||||||
"KeyT": "VK_T",
|
|
||||||
"KeyY": "VK_Y",
|
|
||||||
"KeyU": "VK_U",
|
|
||||||
"KeyI": "VK_I",
|
|
||||||
"KeyO": "VK_O",
|
|
||||||
"KeyP": "VK_P",
|
|
||||||
"KeyA": "VK_A",
|
|
||||||
"KeyS": "VK_S",
|
|
||||||
"KeyD": "VK_D",
|
|
||||||
"KeyF": "VK_F",
|
|
||||||
"KeyG": "VK_G",
|
|
||||||
"KeyH": "VK_H",
|
|
||||||
"KeyJ": "VK_J",
|
|
||||||
"KeyK": "VK_K",
|
|
||||||
"KeyL": "VK_L",
|
|
||||||
"KeyZ": "VK_Z",
|
|
||||||
"KeyX": "VK_X",
|
|
||||||
"KeyC": "VK_C",
|
|
||||||
"KeyV": "VK_V",
|
|
||||||
"KeyB": "VK_B",
|
|
||||||
"KeyN": "VK_N",
|
|
||||||
"KeyM": "VK_M",
|
|
||||||
"F1": "VK_F1",
|
|
||||||
"F2": "VK_F2",
|
|
||||||
"F3": "VK_F3",
|
|
||||||
"F4": "VK_F4",
|
|
||||||
"F5": "VK_F5",
|
|
||||||
"F6": "VK_F6",
|
|
||||||
"F7": "VK_F7",
|
|
||||||
"F8": "VK_F8",
|
|
||||||
"F9": "VK_F9",
|
|
||||||
"F10": "VK_F10",
|
|
||||||
"F11": "VK_F11",
|
|
||||||
"F12": "VK_F12",
|
|
||||||
"F13": "VK_F13",
|
|
||||||
"F14": "VK_F14",
|
|
||||||
"F15": "VK_F15",
|
|
||||||
"F16": "VK_F16",
|
|
||||||
"F17": "VK_F17",
|
|
||||||
"F18": "VK_F18",
|
|
||||||
"F19": "VK_F19",
|
|
||||||
"F20": "VK_F20",
|
|
||||||
"F21": "VK_F21",
|
|
||||||
"F22": "VK_F22",
|
|
||||||
"F23": "VK_F23",
|
|
||||||
"F24": "VK_F24",
|
|
||||||
"NumLock": "VK_NUMLOCK",
|
|
||||||
"ScrollLock": "VK_SCROLLLOCK",
|
|
||||||
"CapsLock": "VK_CAPSLOCK",
|
|
||||||
"Minus": "VK_SP2",
|
|
||||||
"Equal": "VK_SP3",
|
|
||||||
"Backspace": "VK_BACKSPACE",
|
|
||||||
"Tab": "VK_TAB",
|
|
||||||
"BracketLeft": "VK_SP4",
|
|
||||||
"BracketRight": "VK_SP5",
|
|
||||||
"Enter": "VK_ENTER",
|
|
||||||
"Semicolon": "VK_SP6",
|
|
||||||
"Quote": "VK_SP7",
|
|
||||||
"Backquote": "VK_SP1",
|
|
||||||
"Backslash": "VK_SP8",
|
|
||||||
"Comma": "VK_SP9",
|
|
||||||
"Period": "VK_SP10",
|
|
||||||
"Slash": "VK_SP11",
|
|
||||||
"IntlBackslash": "VK_SP12",
|
|
||||||
"NumpadMultiply": "VK_KPASTERISK",
|
|
||||||
"NumpadDivide": "VK_KPSLASH",
|
|
||||||
"NumpadAdd": "VK_KPPLUS",
|
|
||||||
"NumpadSubtract": "VK_KPMINUS",
|
|
||||||
"NumpadDecimal": "VK_KPDOT",
|
|
||||||
"NumpadEnter": "VK_KPENTER",
|
|
||||||
"Space": "VK_SPACE",
|
|
||||||
"Numpad0": "VK_KP0",
|
|
||||||
"Numpad1": "VK_KP1",
|
|
||||||
"Numpad2": "VK_KP2",
|
|
||||||
"Numpad3": "VK_KP3",
|
|
||||||
"Numpad4": "VK_KP4",
|
|
||||||
"Numpad5": "VK_KP5",
|
|
||||||
"Numpad6": "VK_KP6",
|
|
||||||
"Numpad7": "VK_KP7",
|
|
||||||
"Numpad8": "VK_KP8",
|
|
||||||
"Numpad9": "VK_KP9",
|
|
||||||
"PageUp": "VK_PAGEUP",
|
|
||||||
"PageDown": "VK_PAGEDOWN",
|
|
||||||
"End": "VK_END",
|
|
||||||
"Home": "VK_HOME",
|
|
||||||
"ArrowLeft": "VK_LEFT",
|
|
||||||
"ArrowUp": "VK_UP",
|
|
||||||
"ArrowRight": "VK_RIGHT",
|
|
||||||
"ArrowDown": "VK_DOWN",
|
|
||||||
"PrintScreen": "VK_PRINT",
|
|
||||||
"Insert": "VK_INSERT",
|
|
||||||
"Delete": "VK_DELETE",
|
|
||||||
"Help": "VK_HELP",
|
|
||||||
"BrowserBack": "VK_BACK",
|
|
||||||
"Pause": "VK_PAUSE",
|
|
||||||
"Lang1": "VK_HANGUEL",
|
|
||||||
"Lang2": "VK_HANJA"
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package shared
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
func OpenBrowserWindow(url string, fullscreen bool, temp bool) error {
|
|
||||||
bins := []string{"chromium", "chromium-browser"}
|
|
||||||
|
|
||||||
args := []string{fmt.Sprintf("--app=%s", url), "--autoplay-policy=no-user-gesture-required"}
|
|
||||||
if 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{}
|
|
||||||
for _, bin := range bins {
|
|
||||||
cmd := exec.Command(bin, args...)
|
|
||||||
commandOutput := RunShellCommand(cmd)
|
|
||||||
if commandOutput.ExitCode == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
errs = append(errs, commandOutput.Stderr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.New("failed to open browser window: " + fmt.Sprint(errs))
|
|
||||||
}
|
|
||||||
+40
-13
@@ -170,15 +170,8 @@
|
|||||||
|
|
||||||
<span id="version-label" aria-label="Version">%%APP-VERSION%%</span>
|
<span id="version-label" aria-label="Version">%%APP-VERSION%%</span>
|
||||||
|
|
||||||
<div class="fade-in">
|
<div class="fade-in cursor-layer" aria-hidden="true">
|
||||||
<div
|
<div class="cursor-x">
|
||||||
class="cursor-x"
|
|
||||||
style="
|
|
||||||
position: absolute;
|
|
||||||
left: calc(50cqw + var(--mouse-start-x));
|
|
||||||
top: calc(50cqh + var(--mouse-start-y));
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<svg class="cursor-y" width="50" height="50" viewBox="0 0 24 24">
|
<svg class="cursor-y" width="50" height="50" viewBox="0 0 24 24">
|
||||||
<g
|
<g
|
||||||
stroke="#ffffff"
|
stroke="#ffffff"
|
||||||
@@ -223,8 +216,6 @@
|
|||||||
|
|
||||||
--mouse-size: 50px;
|
--mouse-size: 50px;
|
||||||
--mouse-bounce-delay: 5s;
|
--mouse-bounce-delay: 5s;
|
||||||
--mouse-start-x: calc((35 * 100vw) / 1920);
|
|
||||||
--mouse-start-y: calc((60 * 100vh) / 1080);
|
|
||||||
|
|
||||||
--dur-x: 16s;
|
--dur-x: 16s;
|
||||||
--dur-y: 9s;
|
--dur-y: 9s;
|
||||||
@@ -254,8 +245,12 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
height: 100vh;
|
|
||||||
width: 100vw;
|
width: 100dvw;
|
||||||
|
height: 100dvh;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
container: splash / size;
|
||||||
|
|
||||||
animation-name: splash-fade;
|
animation-name: splash-fade;
|
||||||
animation-duration: 1s;
|
animation-duration: 1s;
|
||||||
@@ -342,7 +337,23 @@
|
|||||||
animation: start-button-hover-press 1s ease-in-out 450ms forwards;
|
animation: start-button-hover-press 1s ease-in-out 450ms forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cursor-layer {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
--mouse-start-x: calc(100cqw * 35 / 1920);
|
||||||
|
--mouse-start-y: calc(100cqh * 60 / 1080);
|
||||||
|
}
|
||||||
|
|
||||||
.cursor-x {
|
.cursor-x {
|
||||||
|
position: absolute;
|
||||||
|
left: calc(50cqw + var(--mouse-start-x));
|
||||||
|
top: calc(50cqh + var(--mouse-start-y));
|
||||||
|
width: var(--mouse-size);
|
||||||
|
height: var(--mouse-size);
|
||||||
|
|
||||||
animation-name: move-mouse, mouse-bounceX;
|
animation-name: move-mouse, mouse-bounceX;
|
||||||
animation-duration: 1s, var(--dur-x);
|
animation-duration: 1s, var(--dur-x);
|
||||||
animation-delay: 0s, var(--mouse-bounce-delay);
|
animation-delay: 0s, var(--mouse-bounce-delay);
|
||||||
@@ -354,6 +365,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cursor-y {
|
.cursor-y {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
|
||||||
animation-name: mouse-bounceY;
|
animation-name: mouse-bounceY;
|
||||||
animation-duration: var(--dur-y);
|
animation-duration: var(--dur-y);
|
||||||
animation-delay: var(--mouse-bounce-delay);
|
animation-delay: var(--mouse-bounce-delay);
|
||||||
@@ -364,6 +379,10 @@
|
|||||||
will-change: transform;
|
will-change: transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cursor-y * {
|
||||||
|
vector-effect: non-scaling-stroke;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes fade-in {
|
@keyframes fade-in {
|
||||||
to {
|
to {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
@@ -398,6 +417,10 @@
|
|||||||
calc(50cqw - var(--mouse-size) - var(--mouse-start-x))
|
calc(50cqw - var(--mouse-size) - var(--mouse-start-x))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes mouse-bounceY {
|
@keyframes mouse-bounceY {
|
||||||
@@ -414,6 +437,10 @@
|
|||||||
calc(50cqh - var(--mouse-size) - var(--mouse-start-y))
|
calc(50cqh - var(--mouse-size) - var(--mouse-start-y))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes start-button-hover-press {
|
@keyframes start-button-hover-press {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
".odp": {
|
".odp": {
|
||||||
"display_name": "ODP",
|
"display_name": "ODP",
|
||||||
"mime_type": "application/vnd.oasis.opendocument.presentation"
|
"mime_type": ".odp"
|
||||||
},
|
},
|
||||||
".pdf": {
|
".pdf": {
|
||||||
"display_name": "PDF",
|
"display_name": "PDF",
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
v0.0.11
|
v0.1.7
|
||||||
Reference in New Issue
Block a user