mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-05 16:37:09 +00:00
feat(control): startup button
This commit is contained in:
@@ -199,7 +199,7 @@ async function request_control(
|
||||
api_route: string,
|
||||
options: { method: string; headers?: Record<string, string>; body?: string }
|
||||
): Promise<RequestResponse> {
|
||||
const url = `${window.location.origin}/api${api_route}`;
|
||||
const url = `http://127.0.0.1:8080/api${api_route}`;
|
||||
return await request(url, options);
|
||||
}
|
||||
|
||||
@@ -296,3 +296,11 @@ async function run_shell_command(ip: string, command: string): Promise<RequestRe
|
||||
export async function shutdown(ip: string): Promise<void> {
|
||||
await run_shell_command(ip, 'shutdown -h now');
|
||||
}
|
||||
|
||||
export async function startup(mac: string): Promise<void> {
|
||||
await request_control(`/wakeOnLan`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ mac_address: mac })
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import PopUp from '$lib/components/PopUp.svelte';
|
||||
import type { PopupContent } from '$lib/ts/types';
|
||||
import KeyInput from './KeyInput.svelte';
|
||||
import { send_keyboard_input, show_blackscreen, shutdown } from '$lib/ts/api_handler';
|
||||
import { send_keyboard_input, show_blackscreen, shutdown, startup } from '$lib/ts/api_handler';
|
||||
import { get_display_by_id, run_on_all_selected_displays } from '$lib/ts/stores/displays';
|
||||
import { selected_display_ids } from '$lib/ts/stores/select';
|
||||
import TipTapInput from './TipTapInput.svelte';
|
||||
@@ -84,6 +84,18 @@
|
||||
db.displays.update(d.id, { status: 'app_offline' });
|
||||
}, false);
|
||||
}
|
||||
|
||||
async function startup_action() {
|
||||
await run_on_all_selected_displays(
|
||||
async (d) => {
|
||||
if (!d.mac) return;
|
||||
startup(d.mac); // no await here because we want to be fast
|
||||
db.displays.update(d.id, { status: 'app_offline' });
|
||||
},
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet ask_shutdonw_popup()}
|
||||
@@ -169,6 +181,7 @@
|
||||
<Button
|
||||
className="px-3 flex gap-3 w-full xl:w-75 justify-normal"
|
||||
disabled={all === 'on' || $selected_display_ids.length === 0}
|
||||
click_function={startup_action}
|
||||
>
|
||||
<Power /> PC hochfahren
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user