2023-04-24 22:18:55 -07:00
< script >
2024-06-01 20:17:50 -04:00
import { invoke } from '@tauri-apps/api/core';
import { type } from '@tauri-apps/plugin-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-10 14:04:09 -07:00
import SettingsGroup from '../ui/settings/SettingsGroup.svelte';
import Keybind from '../ui/settings/Keybind.svelte';
2024-02-06 20:27:51 -08:00
import { Setting , ToggleSetting , NumericSetting , FileSetting , TextSetting , TimeSetting } 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
2023-10-08 22:06:30 -07:00
// make an independent copy so it can differ from the main config object
let config = JSON.parse(JSON.stringify($appState.config));
$: configModified = JSON.stringify(config) !== JSON.stringify($appState.config);
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 {
2023-10-08 22:06:30 -07:00
await invoke('save_config', { config } );
$appState.config = await invoke('get_config');
2023-04-28 14:33:23 -07:00
}
catch (e) {
error = e;
}
2023-04-25 22:10:14 -07:00
}
2023-09-11 16:18:05 -07:00
let osType = null;
type().then(t => osType = t);
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
2024-06-26 11:10:50 -04:00
< form on:submit | preventDefault = { save } >
< div class = "max-w-lg mx-auto my-1.5 p-4 space-y-16" >
< SettingsGroup name = "General" >
< ToggleSetting title = "Start on login" bind:value = { config . start_on_login } >
2024-02-06 20:27:51 -08:00
< svelte:fragment slot = "description" >
2024-06-26 11:10:50 -04:00
Start Creddy when you log in to your computer.
2024-02-06 20:27:51 -08:00
< / svelte:fragment >
2024-06-26 11:10:50 -04:00
< / ToggleSetting >
< ToggleSetting title = "Start minimized" bind:value = { config . start_minimized } >
< svelte:fragment slot = "description" >
Minimize to the system tray at startup.
< / svelte:fragment >
< / ToggleSetting >
< NumericSetting title = "Re-hide delay" bind:value = { config . rehide_ms } min= { 0 } unit = "Milliseconds" >
< 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 >
< ToggleSetting title = "Lock when idle" bind:value = { config . auto_lock } >
< svelte:fragment slot = "description" >
Automatically lock Creddy after a period of inactivity.
< / svelte:fragment >
< / ToggleSetting >
{ #if config . auto_lock }
< TimeSetting title = "Idle timeout" bind:seconds = { config . lock_after . secs } >
< svelte:fragment slot = "description" >
How long to wait before automatically locking.
< / svelte:fragment >
< / TimeSetting >
{ /if }
2024-06-28 06:25:55 -04:00
< Setting title = "Update passphrase" >
< Link slot = "input" target = "ChangePassphrase" >
2024-06-26 11:10:50 -04:00
< button type = "button" class = "btn btn-sm btn-primary" > Update< / button >
< / Link >
< svelte:fragment slot = "description" >
2024-06-28 06:25:55 -04:00
Change your master passphrase.
2024-06-26 11:10:50 -04:00
< / svelte:fragment >
< / Setting >
< FileSetting
title="Terminal emulator"
bind:value={ config . terminal . exec }
>
< svelte:fragment slot = "description" >
Choose your preferred terminal emulator (e.g. < code > gnome-terminal< / code > or < code > wt.exe< / code > .) May be an absolute path or an executable discoverable on < code > $PATH< / code > .
< / svelte:fragment >
< / FileSetting >
< / SettingsGroup >
< SettingsGroup name = "Hotkeys" >
< div class = "space-y-4" >
< p > Click on a keybinding to modify it. Use the checkbox to enable or disable a keybinding entirely.< / p >
< div class = "grid grid-cols-[auto_1fr_auto] gap-y-3 items-center" >
< Keybind description = "Show Creddy" bind:value = { config . hotkeys . show_window } / >
< Keybind description = "Launch terminal" bind:value = { config . hotkeys . launch_terminal } / >
< / div >
2023-09-10 14:04:09 -07:00
< / div >
2024-06-26 11:10:50 -04:00
< / SettingsGroup >
2023-09-09 06:30:19 -07:00
2024-06-26 11:10:50 -04:00
< p class = "text-sm text-right" >
Creddy { $appState . appVersion }
< / p >
< / div >
< / form >
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 >
2023-10-08 22:06:30 -07:00
{ :else if configModified }
< div transition:fly = {{ y : 100 , easing : backInOut , duration : 400 }} class="toast" >
< div class = "alert shadow-lg no-animation" >
< span > You have unsaved changes.< / span >
< div >
<!-- <button class="btn btn - sm btn - ghost">Cancel</button> -->
2024-01-23 10:58:39 -08:00
< button class = "btn btn-sm btn-primary" on:click = { save } > Save</button >
2023-10-08 22:06:30 -07:00
< / div >
< / div >
< / div >
2023-04-28 14:33:23 -07:00
{ /if }