2023-04-24 22:18:55 -07:00
< script >
2023-04-25 22:10:14 -07:00
import { invoke } from '@tauri-apps/api/tauri';
2023-04-30 10:52:46 -07:00
import { type } from '@tauri-apps/api/os';
2023-04-25 22:10:14 -07:00
import { appState } from '../lib/state.js';
2023-04-24 22:18:55 -07:00
import Nav from '../ui/Nav.svelte';
import Link from '../ui/Link.svelte';
2023-04-25 22:10:14 -07:00
import ErrorAlert from '../ui/ErrorAlert.svelte';
2023-09-09 06:30:19 -07:00
import { Setting , ToggleSetting , NumericSetting , FileSetting , TextSetting } from '../ui/settings';
2023-04-25 22:10:14 -07:00
2023-04-28 22:34:50 -07:00
import { fly } from 'svelte/transition';
import { backInOut } from 'svelte/easing';
2023-04-28 14:33:23 -07:00
let error = null;
2023-04-25 22:10:14 -07:00
async function save() {
2023-04-28 14:33:23 -07:00
try {
await invoke('save_config', { config : $appState.config } );
}
catch (e) {
error = e;
$appState.config = await invoke('get_config');
}
2023-04-25 22:10:14 -07:00
}
2023-04-30 10:52:46 -07:00
let osType = '';
type().then(t => osType = t);
2023-09-09 06:30:19 -07:00
console.log($appState.config.terminal);
window.term = $appState.config.terminal;
2023-04-24 22:18:55 -07:00
< / script >
2023-04-28 22:34:50 -07:00
< Nav >
2023-09-09 06:30:19 -07:00
< h1 slot = "title" class = "text-2xl font-bold" > Settings< / h1 >
2023-04-28 22:34:50 -07:00
< / Nav >
2023-04-24 22:18:55 -07:00
2023-04-25 22:10:14 -07:00
{ #await invoke ( 'get_config' ) then config }
2023-09-09 06:30:19 -07:00
< div class = "max-w-lg mx-auto mt-1.5 p-4" >
2023-04-28 22:34:50 -07:00
<!-- <h2 class="text - 2xl font - bold text - center">Settings</h2> -->
2023-04-24 22:18:55 -07:00
2023-09-09 06:30:19 -07:00
< div class = "divider mt-0 mb-8" >
< h2 class = "text-xl font-bold" > General< / h2 >
< / div >
< ToggleSetting title = "Start on login" divider = { false } bind:value= { $appState . config . start_on_login } on:update = { save } >
2023-04-27 14:24:08 -07:00
< svelte:fragment slot = "description" >
Start Creddy when you log in to your computer.
< / svelte:fragment >
< / ToggleSetting >
2023-04-25 22:10:14 -07:00
< ToggleSetting title = "Start minimized" bind:value = { $appState . config . start_minimized } on:update= { save } >
< svelte:fragment slot = "description" >
Minimize to the system tray at startup.
< / svelte:fragment >
< / ToggleSetting >
< NumericSetting title = "Re-hide delay" bind:value = { $appState . config . rehide_ms } min= { 0 } unit = "Milliseconds" on:update = { save } >
< svelte:fragment slot = "description" >
How long to wait after a request is approved/denied before minimizing
the window to tray. Only applicable if the window was minimized
to tray before the request was received.
< / svelte:fragment >
< / NumericSetting >
2023-04-30 10:52:46 -07:00
< NumericSetting
title="Listen port"
bind:value={ $appState . config . listen_port }
min={ osType === 'Windows_NT' ? 1 : 0 }
on:update={ save }
>
2023-04-26 17:06:37 -07:00
< svelte:fragment slot = "description" >
Listen for credentials requests on this port.
(Should be used with < code > $AWS_CONTAINER_CREDENTIALS_FULL_URI< / code > )
< / svelte:fragment >
< / NumericSetting >
2023-04-25 22:10:14 -07:00
< Setting title = "Update credentials" >
< Link slot = "input" target = "EnterCredentials" >
2023-04-24 22:18:55 -07:00
< button class = "btn btn-sm btn-primary" > Update< / button >
< / Link >
2023-04-25 22:10:14 -07:00
< svelte:fragment slot = "description" >
Update or re-enter your encrypted credentials.
< / svelte:fragment >
< / Setting >
2023-09-09 06:30:19 -07:00
< div class = "divider mt-10 mb-8" >
< h2 class = "text-xl font-bold" > Terminal< / h2 >
< / div >
< FileSetting
title="Emulator"
divider={ false }
bind:value={ $appState . config . terminal . exec }
on:update={ save }
>
< svelte:fragment slot = "description" >
Choose your preferred terminal emulator (e.g. < code > gnome-terminal< / code > , < code > wt.exe< / code > .) May be an absolute path or an executable discoverable on < code > $PATH< / code > .
< / svelte:fragment >
< / FileSetting >
2023-04-24 22:18:55 -07:00
< / div >
2023-04-25 22:10:14 -07:00
{ /await }
2023-04-28 14:33:23 -07:00
{ #if error }
2023-04-28 22:34:50 -07:00
< div transition:fly = {{ y : 100 , easing : backInOut , duration : 400 }} class="toast" >
< div class = "alert alert-error no-animation" >
2023-04-28 14:33:23 -07:00
< div >
< span > { error } </ span >
< / div >
< div >
< button class = "btn btn-sm btn-alert-error" on:click = {() => error = null } > Ok</button >
< / div >
< / div >
< / div >
{ /if }