minor tweaks
This commit is contained in:
parent
e746963052
commit
913148a75a
@ -90,7 +90,7 @@ pub fn set_auto_launch(is_configured: bool) -> Result<(), SetupError> {
|
||||
|
||||
|
||||
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
|
||||
if cfg!(debug_assertions) {
|
||||
if cfg!(debug_assertions) && std::env::var("HOME").is_ok() {
|
||||
return Ok(PathBuf::from("./creddy.db"));
|
||||
}
|
||||
|
||||
|
@ -81,32 +81,6 @@ pub fn new(config: AppConfig, session: Session, server: Server, pool: SqlitePool
|
||||
}
|
||||
}
|
||||
|
||||
// pub async fn load(app_handle: AppHandle) -> Result<Self, SetupError> {
|
||||
// let conn_opts = SqliteConnectOptions::new()
|
||||
// .filename(config::get_or_create_db_path())
|
||||
// .create_if_missing(true);
|
||||
// let pool_opts = SqlitePoolOptions::new();
|
||||
|
||||
// let pool: SqlitePool = pool_opts.connect_with(conn_opts).await?;
|
||||
// sqlx::migrate!().run(&pool).await?;
|
||||
|
||||
// let creds = Self::load_creds(&pool).await?;
|
||||
// let conf = AppConfig::load(&pool).await?;
|
||||
// let server = Server::new(conf.listen_addr, conf.listen_port, app_handle)?;
|
||||
|
||||
// let state = AppState {
|
||||
// config: RwLock::new(conf),
|
||||
// session: RwLock::new(creds),
|
||||
// request_count: RwLock::new(0),
|
||||
// open_requests: RwLock::new(HashMap::new()),
|
||||
// bans: RwLock::new(HashSet::new()),
|
||||
// server: RwLock::new(server),
|
||||
// pool,
|
||||
// };
|
||||
|
||||
// Ok(state)
|
||||
// }
|
||||
|
||||
pub async fn load_creds(pool: &SqlitePool) -> Result<Session, SetupError> {
|
||||
let res = sqlx::query!("SELECT * FROM credentials ORDER BY created_at desc")
|
||||
.fetch_optional(pool)
|
||||
@ -313,9 +287,8 @@ pub fn new(config: AppConfig, session: Session, server: Server, pool: SqlitePool
|
||||
expiration,
|
||||
};
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
#[cfg(debug_assertions)]
|
||||
println!("Got new session:\n{}", serde_json::to_string(&session_creds).unwrap());
|
||||
}
|
||||
|
||||
*app_session = Session::Unlocked(session_creds);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { slide } from 'svelte/transition';
|
||||
|
||||
let extraClasses;
|
||||
let extraClasses = "";
|
||||
export {extraClasses as class};
|
||||
export let slideDuration = 150;
|
||||
let animationClass = "";
|
||||
|
@ -27,12 +27,10 @@
|
||||
<div class="flex flex-col h-screen items-center justify-center p-4 space-y-4">
|
||||
{#await invoke('get_session_status') then status}
|
||||
{#if status === 'locked'}
|
||||
<!-- <img src={closedPadlockUrl} alt="A locked padlock" class="w-32" /> -->
|
||||
|
||||
{@html vaultDoorSvg}
|
||||
|
||||
<h2 class="text-2xl font-bold">Creddy is locked</h2>
|
||||
<Link target="Unlock" class="w-64">
|
||||
<Link target="Unlock" hotkey="Enter" class="w-64">
|
||||
<button class="btn btn-primary w-full">Unlock</button>
|
||||
</Link>
|
||||
|
||||
@ -43,7 +41,7 @@
|
||||
{:else if status === 'empty'}
|
||||
{@html vaultDoorSvg}
|
||||
<h2 class="text-2xl font-bold">No credentials found</h2>
|
||||
<Link target="EnterCredentials" class="w-64">
|
||||
<Link target="EnterCredentials" hotkey="Enter" class="w-64">
|
||||
<button class="btn btn-primary w-full">Enter Credentials</button>
|
||||
</Link>
|
||||
{/if}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
import { appState } from '../lib/state.js';
|
||||
import { navigate } from '../lib/routing.js';
|
||||
@ -11,7 +12,14 @@
|
||||
let errorMsg = null;
|
||||
let alert;
|
||||
let passphrase = '';
|
||||
let loadTime = 0;
|
||||
async function unlock() {
|
||||
// The hotkey for navigating here from homepage is Enter, which also
|
||||
// happens to trigger the form submit event
|
||||
if (Date.now() - loadTime < 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
let r = await invoke('unlock', {passphrase});
|
||||
$appState.credentialStatus = 'unlocked';
|
||||
@ -37,6 +45,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
loadTime = Date.now();
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@ -47,6 +59,7 @@
|
||||
<ErrorAlert bind:this="{alert}">{errorMsg}</ErrorAlert>
|
||||
{/if}
|
||||
|
||||
<!-- svelte-ignore a11y-autofocus -->
|
||||
<input autofocus name="password" type="password" placeholder="correct horse battery staple" bind:value="{passphrase}" class="input input-bordered" />
|
||||
|
||||
<input type="submit" class="btn btn-primary" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user