2022-02-22 10:05:21 +01:00
|
|
|
<script lang="ts">
|
2022-02-22 14:00:17 +01:00
|
|
|
import { onMount, onDestroy } from "svelte";
|
2022-02-22 12:02:56 +01:00
|
|
|
import { writable, get } from "svelte/store";
|
2022-02-22 10:05:21 +01:00
|
|
|
|
|
|
|
import ToggleSwitch from "~/lib/ToggleSwitch.svelte";
|
|
|
|
import InputField from "~/lib/InputField.svelte";
|
|
|
|
import KeyRecord from "~/lib/KeyRecord.svelte";
|
2022-02-22 12:02:56 +01:00
|
|
|
import { api, SettingsData } from "../lib/ipc";
|
2022-02-22 10:05:21 +01:00
|
|
|
|
2022-02-22 14:00:17 +01:00
|
|
|
const settings = writable<SettingsData | undefined>();
|
2022-02-22 12:02:56 +01:00
|
|
|
|
2022-02-22 14:00:17 +01:00
|
|
|
onMount(async () => {
|
|
|
|
await api.setShortcutsEnabled(false);
|
|
|
|
$settings = await api.getSettings();
|
2022-02-22 12:02:56 +01:00
|
|
|
});
|
2022-02-22 10:05:21 +01:00
|
|
|
|
2022-02-22 14:00:17 +01:00
|
|
|
onDestroy(async () => {
|
|
|
|
await api.setShortcutsEnabled(true);
|
2022-02-22 10:05:21 +01:00
|
|
|
});
|
|
|
|
|
2022-02-22 14:00:17 +01:00
|
|
|
async function saveShortcut(key: keyof SettingsData["shortcuts"], value: string) {
|
|
|
|
const shortcuts = get(settings)['shortcuts'] || { "camera_toggle": "", "mute_toggle": "" };
|
|
|
|
shortcuts[key] = value;
|
|
|
|
settings.update((s) => ({ ...s, shortcuts }));
|
|
|
|
await api.saveSetting("shortcuts", shortcuts);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveAutoLaunch(auto_launch_enabled: boolean) {
|
|
|
|
settings.update((s) => ({ ...s, auto_launch_enabled }));
|
|
|
|
await api.saveSetting("auto_launch_enabled", auto_launch_enabled);
|
2022-02-22 10:05:21 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="flex flex-col w-full h-full justify-center items-center">
|
|
|
|
<h1 class="text-gray-200 text-2xl mb-6">Settings</h1>
|
|
|
|
|
2022-02-22 14:00:17 +01:00
|
|
|
<div class="flex flex-col justify-start max-w-148">
|
|
|
|
{#if $settings}
|
2022-02-22 10:05:21 +01:00
|
|
|
<InputField
|
|
|
|
id="toggle-camera"
|
|
|
|
title="Toggle Mute"
|
|
|
|
description="Set a shortcut to turn your microphone on and off"
|
|
|
|
>
|
|
|
|
<KeyRecord
|
|
|
|
id="toggle-mute"
|
2022-02-22 14:00:17 +01:00
|
|
|
value={$settings.shortcuts.mute_toggle}
|
2022-02-22 10:05:21 +01:00
|
|
|
on:change={(e) => saveShortcut("mute_toggle", e.detail)}
|
|
|
|
/>
|
|
|
|
</InputField>
|
|
|
|
|
|
|
|
<InputField
|
|
|
|
id="toggle-camera"
|
|
|
|
title="Toggle Camera"
|
|
|
|
description="Set a shortcut to turn your camera on and off"
|
|
|
|
>
|
|
|
|
<KeyRecord
|
|
|
|
id="toggle-camera"
|
2022-02-22 14:00:17 +01:00
|
|
|
value={$settings.shortcuts.camera_toggle}
|
2022-02-22 10:05:21 +01:00
|
|
|
on:change={(e) => saveShortcut("camera_toggle", e.detail)}
|
|
|
|
/>
|
|
|
|
</InputField>
|
|
|
|
|
2022-02-22 14:00:17 +01:00
|
|
|
<InputField id="toggle-autostart" title="Toggle autostart">
|
|
|
|
<ToggleSwitch
|
2022-02-22 10:05:21 +01:00
|
|
|
id="toggle-autostart"
|
2022-02-22 14:00:17 +01:00
|
|
|
value={$settings.auto_launch_enabled}
|
2022-02-22 10:05:21 +01:00
|
|
|
title="Autostart WorkAdventure after your PC started"
|
2022-02-22 14:00:17 +01:00
|
|
|
on:change={(e) => saveAutoLaunch(e.detail)}
|
|
|
|
/>
|
|
|
|
</InputField>
|
|
|
|
|
|
|
|
<span class="mt-8 text-xs text-gray-200 max-w-128">Hint: Shortcuts are disabled while seeing this page</span>
|
|
|
|
{/if}
|
2022-02-22 10:05:21 +01:00
|
|
|
</div>
|
|
|
|
</div>
|