mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 17:07:08 +00:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
Generated
+2
-30
@@ -3,7 +3,6 @@
|
|||||||
"specifiers": {
|
"specifiers": {
|
||||||
"npm:@eslint/compat@^1.4.1": "1.4.1_eslint@9.39.2",
|
"npm:@eslint/compat@^1.4.1": "1.4.1_eslint@9.39.2",
|
||||||
"npm:@eslint/js@^9.39.2": "9.39.2",
|
"npm:@eslint/js@^9.39.2": "9.39.2",
|
||||||
"npm:@playwright/test@1.56.1": "1.56.1",
|
|
||||||
"npm:@sveltejs/adapter-auto@^6.1.1": "6.1.1_@sveltejs+kit@2.49.3__@sveltejs+vite-plugin-svelte@6.2.3___svelte@5.46.1____acorn@8.15.0___vite@7.3.1____sass-embedded@1.97.2____picomatch@4.0.3___sass-embedded@1.97.2__svelte@5.46.1___acorn@8.15.0__typescript@5.9.3__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__acorn@8.15.0__sass-embedded@1.97.2_@sveltejs+vite-plugin-svelte@6.2.3__svelte@5.46.1___acorn@8.15.0__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__sass-embedded@1.97.2_svelte@5.46.1__acorn@8.15.0_typescript@5.9.3_vite@7.3.1__sass-embedded@1.97.2__picomatch@4.0.3_sass-embedded@1.97.2",
|
"npm:@sveltejs/adapter-auto@^6.1.1": "6.1.1_@sveltejs+kit@2.49.3__@sveltejs+vite-plugin-svelte@6.2.3___svelte@5.46.1____acorn@8.15.0___vite@7.3.1____sass-embedded@1.97.2____picomatch@4.0.3___sass-embedded@1.97.2__svelte@5.46.1___acorn@8.15.0__typescript@5.9.3__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__acorn@8.15.0__sass-embedded@1.97.2_@sveltejs+vite-plugin-svelte@6.2.3__svelte@5.46.1___acorn@8.15.0__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__sass-embedded@1.97.2_svelte@5.46.1__acorn@8.15.0_typescript@5.9.3_vite@7.3.1__sass-embedded@1.97.2__picomatch@4.0.3_sass-embedded@1.97.2",
|
||||||
"npm:@sveltejs/adapter-static@^3.0.10": "3.0.10_@sveltejs+kit@2.49.3__@sveltejs+vite-plugin-svelte@6.2.3___svelte@5.46.1____acorn@8.15.0___vite@7.3.1____sass-embedded@1.97.2____picomatch@4.0.3___sass-embedded@1.97.2__svelte@5.46.1___acorn@8.15.0__typescript@5.9.3__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__acorn@8.15.0__sass-embedded@1.97.2_@sveltejs+vite-plugin-svelte@6.2.3__svelte@5.46.1___acorn@8.15.0__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__sass-embedded@1.97.2_svelte@5.46.1__acorn@8.15.0_typescript@5.9.3_vite@7.3.1__sass-embedded@1.97.2__picomatch@4.0.3_sass-embedded@1.97.2",
|
"npm:@sveltejs/adapter-static@^3.0.10": "3.0.10_@sveltejs+kit@2.49.3__@sveltejs+vite-plugin-svelte@6.2.3___svelte@5.46.1____acorn@8.15.0___vite@7.3.1____sass-embedded@1.97.2____picomatch@4.0.3___sass-embedded@1.97.2__svelte@5.46.1___acorn@8.15.0__typescript@5.9.3__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__acorn@8.15.0__sass-embedded@1.97.2_@sveltejs+vite-plugin-svelte@6.2.3__svelte@5.46.1___acorn@8.15.0__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__sass-embedded@1.97.2_svelte@5.46.1__acorn@8.15.0_typescript@5.9.3_vite@7.3.1__sass-embedded@1.97.2__picomatch@4.0.3_sass-embedded@1.97.2",
|
||||||
"npm:@sveltejs/kit@^2.49.3": "2.49.3_@sveltejs+vite-plugin-svelte@6.2.3__svelte@5.46.1___acorn@8.15.0__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__sass-embedded@1.97.2_svelte@5.46.1__acorn@8.15.0_typescript@5.9.3_vite@7.3.1__sass-embedded@1.97.2__picomatch@4.0.3_acorn@8.15.0_sass-embedded@1.97.2",
|
"npm:@sveltejs/kit@^2.49.3": "2.49.3_@sveltejs+vite-plugin-svelte@6.2.3__svelte@5.46.1___acorn@8.15.0__vite@7.3.1___sass-embedded@1.97.2___picomatch@4.0.3__sass-embedded@1.97.2_svelte@5.46.1__acorn@8.15.0_typescript@5.9.3_vite@7.3.1__sass-embedded@1.97.2__picomatch@4.0.3_acorn@8.15.0_sass-embedded@1.97.2",
|
||||||
@@ -369,13 +368,6 @@
|
|||||||
],
|
],
|
||||||
"scripts": true
|
"scripts": true
|
||||||
},
|
},
|
||||||
"@playwright/test@1.56.1": {
|
|
||||||
"integrity": "sha512-vSMYtL/zOcFpvJCW71Q/OEGQb7KYBPAdKh35WNSkaZA75JlAO8ED8UN6GUNTm3drWomcbcqRPFqQbLae8yBTdg==",
|
|
||||||
"dependencies": [
|
|
||||||
"playwright"
|
|
||||||
],
|
|
||||||
"bin": true
|
|
||||||
},
|
|
||||||
"@polka/url@1.0.0-next.29": {
|
"@polka/url@1.0.0-next.29": {
|
||||||
"integrity": "sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww=="
|
"integrity": "sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww=="
|
||||||
},
|
},
|
||||||
@@ -1374,11 +1366,6 @@
|
|||||||
"flatted@3.3.3": {
|
"flatted@3.3.3": {
|
||||||
"integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg=="
|
"integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg=="
|
||||||
},
|
},
|
||||||
"fsevents@2.3.2": {
|
|
||||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
|
||||||
"os": ["darwin"],
|
|
||||||
"scripts": true
|
|
||||||
},
|
|
||||||
"fsevents@2.3.3": {
|
"fsevents@2.3.3": {
|
||||||
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
||||||
"os": ["darwin"],
|
"os": ["darwin"],
|
||||||
@@ -1694,20 +1681,6 @@
|
|||||||
"picomatch@4.0.3": {
|
"picomatch@4.0.3": {
|
||||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q=="
|
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q=="
|
||||||
},
|
},
|
||||||
"playwright-core@1.56.1": {
|
|
||||||
"integrity": "sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ==",
|
|
||||||
"bin": true
|
|
||||||
},
|
|
||||||
"playwright@1.56.1": {
|
|
||||||
"integrity": "sha512-aFi5B0WovBHTEvpM3DzXTUaeN6eN0qWnTkKx4NQaH4Wvcmc153PdaY2UBdSYKaGYw+UyWXSVyxDUg5DoPEttjw==",
|
|
||||||
"dependencies": [
|
|
||||||
"playwright-core"
|
|
||||||
],
|
|
||||||
"optionalDependencies": [
|
|
||||||
"fsevents@2.3.2"
|
|
||||||
],
|
|
||||||
"bin": true
|
|
||||||
},
|
|
||||||
"postcss-load-config@3.1.4_postcss@8.5.6": {
|
"postcss-load-config@3.1.4_postcss@8.5.6": {
|
||||||
"integrity": "sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==",
|
"integrity": "sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
@@ -1942,7 +1915,7 @@
|
|||||||
"@rollup/rollup-win32-ia32-msvc",
|
"@rollup/rollup-win32-ia32-msvc",
|
||||||
"@rollup/rollup-win32-x64-gnu",
|
"@rollup/rollup-win32-x64-gnu",
|
||||||
"@rollup/rollup-win32-x64-msvc",
|
"@rollup/rollup-win32-x64-msvc",
|
||||||
"fsevents@2.3.3"
|
"fsevents"
|
||||||
],
|
],
|
||||||
"bin": true
|
"bin": true
|
||||||
},
|
},
|
||||||
@@ -2291,7 +2264,7 @@
|
|||||||
"tinyglobby"
|
"tinyglobby"
|
||||||
],
|
],
|
||||||
"optionalDependencies": [
|
"optionalDependencies": [
|
||||||
"fsevents@2.3.3"
|
"fsevents"
|
||||||
],
|
],
|
||||||
"optionalPeers": [
|
"optionalPeers": [
|
||||||
"sass-embedded"
|
"sass-embedded"
|
||||||
@@ -2335,7 +2308,6 @@
|
|||||||
"dependencies": [
|
"dependencies": [
|
||||||
"npm:@eslint/compat@^1.4.1",
|
"npm:@eslint/compat@^1.4.1",
|
||||||
"npm:@eslint/js@^9.39.2",
|
"npm:@eslint/js@^9.39.2",
|
||||||
"npm:@playwright/test@1.56.1",
|
|
||||||
"npm:@sveltejs/adapter-auto@^6.1.1",
|
"npm:@sveltejs/adapter-auto@^6.1.1",
|
||||||
"npm:@sveltejs/adapter-static@^3.0.10",
|
"npm:@sveltejs/adapter-static@^3.0.10",
|
||||||
"npm:@sveltejs/kit@^2.49.3",
|
"npm:@sveltejs/kit@^2.49.3",
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,11 @@
|
|||||||
"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.4.1",
|
"@eslint/compat": "^1.4.1",
|
||||||
"@eslint/js": "^9.39.2",
|
"@eslint/js": "^9.39.2",
|
||||||
"@playwright/test": "1.56.1",
|
|
||||||
"@sveltejs/adapter-auto": "^6.1.1",
|
"@sveltejs/adapter-auto": "^6.1.1",
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/kit": "^2.49.3",
|
"@sveltejs/kit": "^2.49.3",
|
||||||
|
|||||||
@@ -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'
|
|
||||||
});
|
|
||||||
@@ -51,9 +51,15 @@ export async function show_html(ip: string, html: string): Promise<void> {
|
|||||||
await request_display(ip, '/showHTML', options);
|
await request_display(ip, '/showHTML', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function show_website(ip: string, url: string): Promise<void> {
|
export async function open_website(ip: string, url: string): Promise<void> {
|
||||||
const command = `screen -dmS custom_website chromium-browser --user-data-dir=$(mktemp -d) --start-fullscreen --app="${url}"`;
|
const options = {
|
||||||
await run_shell_command(ip, command);
|
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(
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
open: false,
|
open: false,
|
||||||
snippet: null,
|
snippet: null,
|
||||||
title: '',
|
title: '',
|
||||||
title_class: '!text-xl',
|
title_class: '!text-xl'
|
||||||
});
|
});
|
||||||
let remove_display_name = $state('');
|
let remove_display_name = $state('');
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
title: 'Neuen Bildschirm Hinzufügen',
|
title: 'Neuen Bildschirm Hinzufügen',
|
||||||
title_icon: Monitor,
|
title_icon: Monitor,
|
||||||
title_class: '!text-xl',
|
title_class: '!text-xl',
|
||||||
window_class: 'w-3xl',
|
window_class: 'w-3xl'
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@
|
|||||||
title: 'Einstellungen',
|
title: 'Einstellungen',
|
||||||
title_icon: Settings,
|
title_icon: Settings,
|
||||||
title_class: '!text-xl',
|
title_class: '!text-xl',
|
||||||
window_class: 'w-3xl',
|
window_class: 'w-3xl'
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -143,7 +143,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
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@
|
|||||||
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'
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@
|
|||||||
snippet: about_popup,
|
snippet: about_popup,
|
||||||
title: 'Über PLG MuDiCS',
|
title: 'Über PLG MuDiCS',
|
||||||
title_icon: Info,
|
title_icon: Info,
|
||||||
title_class: '!text-xl',
|
title_class: '!text-xl'
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -182,8 +182,8 @@
|
|||||||
<div class="px-2">
|
<div class="px-2">
|
||||||
<h3 class="text-lg font-bold mt-4">Entwickler</h3>
|
<h3 class="text-lg font-bold mt-4">Entwickler</h3>
|
||||||
<p>
|
<p>
|
||||||
<a target="_blank" class="link" href="https://github.com/programmer-44">E44</a>
|
<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>,
|
<a target="_blank" class="link" href="https://codeberg.org/2mal3">2mal3</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3 class="text-lg font-bold mt-4">Lizenz</h3>
|
<h3 class="text-lg font-bold mt-4">Lizenz</h3>
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
show_blackscreen,
|
show_blackscreen,
|
||||||
shutdown,
|
shutdown,
|
||||||
startup,
|
startup,
|
||||||
show_website
|
show_html,
|
||||||
|
open_website
|
||||||
} from '$lib/ts/api_handler';
|
} from '$lib/ts/api_handler';
|
||||||
import {
|
import {
|
||||||
get_display_by_id,
|
get_display_by_id,
|
||||||
@@ -44,7 +45,7 @@
|
|||||||
let popup_content: PopupContent = $state({
|
let popup_content: PopupContent = $state({
|
||||||
open: false,
|
open: false,
|
||||||
snippet: null,
|
snippet: null,
|
||||||
title: ''
|
title: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
let current_text = $state('');
|
let current_text = $state('');
|
||||||
@@ -79,7 +80,7 @@
|
|||||||
snippet: website_popup,
|
snippet: website_popup,
|
||||||
title: 'Webseite Anzeigen',
|
title: 'Webseite Anzeigen',
|
||||||
window_class: 'w-xl',
|
window_class: 'w-xl',
|
||||||
title_icon: Globe
|
title_icon: Globe,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@
|
|||||||
open: true,
|
open: true,
|
||||||
snippet: ask_shutdown_popup,
|
snippet: ask_shutdown_popup,
|
||||||
title: 'Bildschirm Herunterfahren',
|
title: 'Bildschirm Herunterfahren',
|
||||||
title_icon: PowerOff
|
title_icon: PowerOff,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,10 +111,7 @@
|
|||||||
popup_content.open = false;
|
popup_content.open = false;
|
||||||
await run_on_all_selected_displays((d) => {
|
await run_on_all_selected_displays((d) => {
|
||||||
shutdown(d.ip); // no await here because we want to be fast
|
shutdown(d.ip); // no await here because we want to be fast
|
||||||
db.displays.update(d.id, {
|
db.displays.update(d.id, { status: 'app_offline', preview: { currently_updating: false, url: null} });
|
||||||
status: 'app_offline',
|
|
||||||
preview: { currently_updating: false, url: null }
|
|
||||||
});
|
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +144,9 @@
|
|||||||
|
|
||||||
async function send_website() {
|
async function send_website() {
|
||||||
popup_content.open = false;
|
popup_content.open = false;
|
||||||
await run_on_all_selected_displays((d) => show_website(d.ip, website_url));
|
await run_on_all_selected_displays((d) =>
|
||||||
|
open_website(d.ip, website_url)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -186,11 +186,11 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
{#snippet send_keys_popup()}
|
{#snippet send_keys_popup()}
|
||||||
<KeyInput {popup_close_function} />
|
<KeyInput {popup_close_function}/>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
{#snippet text_popup()}
|
{#snippet text_popup()}
|
||||||
<TipTapInput bind:text={current_text} />
|
<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">
|
||||||
@@ -218,7 +218,7 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
title="Vorherige Folie (Pfeil nach Links) [gedrückt halten möglich]"
|
title="Nächste Folie (Pfeil nach Rechts) [gedrückt halten möglich]"
|
||||||
class="px-9 bg-stone-700 {$selected_online_display_ids.length === 0
|
class="px-9 bg-stone-700 {$selected_online_display_ids.length === 0
|
||||||
? 'text-stone-500 cursor-not-allowed'
|
? '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"
|
: 'hover:bg-stone-600 active:bg-stone-500 cursor-pointer'} py-2 rounded-xl flex justify-center items-center transition-colors duration-200"
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
update_current_folder_on_selected_displays,
|
update_current_folder_on_selected_displays,
|
||||||
get_displays_where_path_not_exists,
|
get_displays_where_path_not_exists,
|
||||||
create_path_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';
|
||||||
@@ -69,7 +68,7 @@
|
|||||||
let popup_content: PopupContent = $state({
|
let popup_content: PopupContent = $state({
|
||||||
open: false,
|
open: false,
|
||||||
snippet: null,
|
snippet: null,
|
||||||
title: '',
|
title: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
let file_input: HTMLInputElement;
|
let file_input: HTMLInputElement;
|
||||||
@@ -119,7 +118,7 @@
|
|||||||
snippet: edit_file_name_popup,
|
snippet: edit_file_name_popup,
|
||||||
title: `${file_is_folder ? 'Ordner' : 'Datei'} umbenennen`,
|
title: `${file_is_folder ? 'Ordner' : 'Datei'} umbenennen`,
|
||||||
title_icon: FolderPlus,
|
title_icon: FolderPlus,
|
||||||
snippet_arg: extension,
|
snippet_arg: extension
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@
|
|||||||
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
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -142,7 +141,7 @@
|
|||||||
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
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -152,7 +151,9 @@
|
|||||||
current_folder_elements: Inode[]
|
current_folder_elements: Inode[]
|
||||||
) {
|
) {
|
||||||
if (current_selected_file_ids.length === 0 && current_folder_elements.length > 0) {
|
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));
|
current_selected_file_ids = current_folder_elements.map((inode) =>
|
||||||
|
get_file_primary_key(inode)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (current_selected_file_ids.length === 0) return;
|
if (current_selected_file_ids.length === 0) return;
|
||||||
// Mit For-Schleife über ausgewählte Elemente gehen
|
// Mit For-Schleife über ausgewählte Elemente gehen
|
||||||
@@ -276,8 +277,11 @@
|
|||||||
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_online_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 h-full rounded-2xl grid grid-rows-[2.5rem_1fr] min-h-0">
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[working-directory: 'frontend']
|
||||||
|
gen:
|
||||||
|
deno install
|
||||||
|
deno task build
|
||||||
|
|
||||||
|
dev: gen
|
||||||
|
go run *.go
|
||||||
+1
-1
@@ -64,7 +64,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
err = shared.OpenBrowserWindow("http://localhost:"+port, false, "control")
|
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)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package shared
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -6,35 +6,30 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"plg-mudics/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenBrowserWindow(url string, fullscreen bool, profile string) error {
|
func openBrowserWindow(url string) error {
|
||||||
bins := []string{"chromium", "chromium-browser"}
|
bins := []string{"chromium", "chromium-browser"}
|
||||||
|
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to determine user home directory: %w", err)
|
return fmt.Errorf("unable to determine user home directory: %w", err)
|
||||||
}
|
}
|
||||||
browserProfileDirPath := filepath.Join(home, ".local", "share", "plg-mudics", fmt.Sprintf("browser-%s", profile))
|
browserProfileDirPath := filepath.Join(home, ".local", "share", "plg-mudics", "browser-control")
|
||||||
if err := os.MkdirAll(browserProfileDirPath, os.ModePerm); err != nil {
|
if err := os.MkdirAll(browserProfileDirPath, os.ModePerm); err != nil {
|
||||||
return fmt.Errorf("failed to create local config directory: %w", err)
|
return fmt.Errorf("failed to create local config directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
fmt.Sprintf("--app=%s", url),
|
fmt.Sprintf("--app=%s", url),
|
||||||
"--autoplay-policy=no-user-gesture-required",
|
|
||||||
fmt.Sprintf("--user-data-dir=%s", browserProfileDirPath),
|
fmt.Sprintf("--user-data-dir=%s", browserProfileDirPath),
|
||||||
"--allow-running-insecure-content",
|
|
||||||
"--disable-features=XFrameOptions",
|
|
||||||
}
|
|
||||||
if fullscreen {
|
|
||||||
args = append(args, "--start-fullscreen")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errs := []string{}
|
errs := []string{}
|
||||||
for _, bin := range bins {
|
for _, bin := range bins {
|
||||||
cmd := exec.Command(bin, args...)
|
cmd := exec.Command(bin, args...)
|
||||||
commandOutput := RunShellCommand(cmd)
|
commandOutput := shared.RunShellCommand(cmd)
|
||||||
if commandOutput.ExitCode == 0 {
|
if commandOutput.ExitCode == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
+10
-3
@@ -1,9 +1,10 @@
|
|||||||
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/chromedp/chromedp v0.14.2
|
||||||
github.com/gabriel-vasile/mimetype v1.4.11
|
github.com/gabriel-vasile/mimetype v1.4.11
|
||||||
github.com/labstack/echo/v4 v4.15.0
|
github.com/labstack/echo/v4 v4.15.0
|
||||||
github.com/micmonay/keybd_event v1.1.2
|
github.com/micmonay/keybd_event v1.1.2
|
||||||
@@ -14,9 +15,15 @@ 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
|
||||||
@@ -27,7 +34,7 @@ require (
|
|||||||
golang.org/x/mod v0.30.0 // indirect
|
golang.org/x/mod v0.30.0 // indirect
|
||||||
golang.org/x/net v0.48.0 // indirect
|
golang.org/x/net v0.48.0 // indirect
|
||||||
golang.org/x/sync v0.19.0 // indirect
|
golang.org/x/sync v0.19.0 // indirect
|
||||||
golang.org/x/sys v0.39.0 // indirect
|
golang.org/x/sys v0.40.0 // indirect
|
||||||
golang.org/x/text v0.32.0 // indirect
|
golang.org/x/text v0.32.0 // indirect
|
||||||
golang.org/x/time v0.14.0 // indirect
|
golang.org/x/time v0.14.0 // indirect
|
||||||
golang.org/x/tools v0.39.0 // indirect
|
golang.org/x/tools v0.39.0 // indirect
|
||||||
|
|||||||
@@ -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,6 +24,14 @@ 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=
|
||||||
@@ -64,6 +80,8 @@ 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 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||||
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
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 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||||
|
|||||||
@@ -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, "display")
|
|
||||||
|
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,75 +0,0 @@
|
|||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"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":
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
fh.runningProgram = exec.Command("soffice", "--show", path, "--nologo", "--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
|
|
||||||
}
|
|
||||||
+21
-32
@@ -1,49 +1,21 @@
|
|||||||
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TakeScreenshot() (string, error) {
|
func TakeScreenshot() (string, error) {
|
||||||
tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix()))
|
tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix()))
|
||||||
|
|
||||||
@@ -106,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,148 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
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 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,112 @@
|
|||||||
|
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":
|
||||||
|
err = browser.Browser.OpenPDF(path)
|
||||||
|
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")
|
|
||||||
+27
-160
@@ -1,53 +1,27 @@
|
|||||||
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/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)
|
|
||||||
e.GET("/sse", sseRoute)
|
|
||||||
e.GET("/splash", func(ctx echo.Context) error {
|
|
||||||
html := shared.SplashScreenTemplate
|
|
||||||
html = strings.ReplaceAll(html, "%%APP-VERSION%%", version)
|
|
||||||
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())
|
||||||
apiGroup.GET("/ping", pingRoute)
|
apiGroup.GET("/ping", pingRoute)
|
||||||
@@ -55,6 +29,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 +44,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")
|
||||||
@@ -266,7 +162,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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -308,38 +207,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"})
|
||||||
@@ -358,13 +226,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{}{})
|
||||||
}
|
}
|
||||||
@@ -372,7 +239,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 {
|
||||||
@@ -415,24 +282,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()
|
|
||||||
if err != nil {
|
var request struct {
|
||||||
return fmt.Errorf("failed to close running program: %w", err)
|
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})
|
||||||
}
|
}
|
||||||
|
|
||||||
sseConnection <- ""
|
slog.Info("Opening url")
|
||||||
|
|
||||||
return nil
|
err = browser.Browser.OpenPage(request.URL)
|
||||||
}
|
|
||||||
|
|
||||||
func isPortFree(port int) bool {
|
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", port)
|
|
||||||
l, err := net.Listen("tcp", addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
slog.Error("Failed to open website", "url", request.URL, "error", err)
|
||||||
|
return ctx.JSON(http.StatusInternalServerError, shared.ErrorResponse{Description: "Failed to open website"})
|
||||||
}
|
}
|
||||||
_ = l.Close()
|
|
||||||
return true
|
return ctx.JSON(http.StatusOK, struct{}{})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -1,15 +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/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
|
||||||
|
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
|
||||||
|
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/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/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||||
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.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
|
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
|
||||||
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/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/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
|
||||||
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
|
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/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
@@ -92,21 +92,19 @@
|
|||||||
nushell
|
nushell
|
||||||
unzip
|
unzip
|
||||||
iputils
|
iputils
|
||||||
xreader
|
|
||||||
tree
|
tree
|
||||||
jq
|
jq
|
||||||
screen
|
|
||||||
|
|
||||||
# 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";
|
||||||
|
|||||||
+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
|
||||||
|
|||||||
@@ -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.1.1
|
v0.1.4
|
||||||
|
|||||||
Reference in New Issue
Block a user