work on stuff
This commit is contained in:
parent
6f9cd6b471
commit
a8aafa1519
@ -3,7 +3,8 @@ CREATE TABLE credentials (
|
||||
access_key_id TEXT NOT NULL,
|
||||
secret_key_enc BLOB NOT NULL,
|
||||
salt BLOB NOT NULL,
|
||||
nonce BLOB NOT NULL
|
||||
nonce BLOB NOT NULL,
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE config (
|
||||
|
@ -67,3 +67,10 @@ pub fn get_config(app_state: State<'_, AppState>) -> AppConfig {
|
||||
let config = app_state.config.read().unwrap();
|
||||
config.clone()
|
||||
}
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
pub fn save_config(config: AppConfig, app_state: State<'_, AppState>) {
|
||||
let mut prev_config = app_state.config.write().unwrap();
|
||||
*prev_config = config;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ fn main() {
|
||||
ipc::get_session_status,
|
||||
ipc::save_credentials,
|
||||
ipc::get_config,
|
||||
ipc::save_config,
|
||||
])
|
||||
.setup(|app| {
|
||||
APP.set(app.handle()).unwrap();
|
||||
|
@ -91,7 +91,7 @@ impl AppState {
|
||||
}
|
||||
|
||||
async fn load_creds(pool: &SqlitePool) -> Result<Session, SetupError> {
|
||||
let res = sqlx::query!("SELECT * FROM credentials")
|
||||
let res = sqlx::query!("SELECT * FROM credentials ORDER BY created_at desc")
|
||||
.fetch_optional(pool)
|
||||
.await?;
|
||||
let row = match res {
|
||||
@ -122,6 +122,10 @@ impl AppState {
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
// do this first so that if it fails we don't save bad credentials
|
||||
self.new_session(&key_id, &secret_key).await?;
|
||||
|
||||
let salt = pwhash::gen_salt();
|
||||
let mut key_buf = [0; secretbox::KEYBYTES];
|
||||
pwhash::derive_key_interactive(&mut key_buf, passphrase.as_bytes(), &salt).unwrap();
|
||||
@ -133,8 +137,8 @@ impl AppState {
|
||||
|
||||
|
||||
sqlx::query(
|
||||
"INSERT INTO credentials (access_key_id, secret_key_enc, salt, nonce)
|
||||
VALUES (?, ?, ?, ?)"
|
||||
"INSERT INTO credentials (access_key_id, secret_key_enc, salt, nonce, created_at)
|
||||
VALUES (?, ?, ?, ?, strftime('%s'))"
|
||||
)
|
||||
.bind(&key_id)
|
||||
.bind(&secret_key_enc)
|
||||
@ -143,8 +147,6 @@ impl AppState {
|
||||
.execute(&self.pool)
|
||||
.await?;
|
||||
|
||||
self.new_session(&key_id, &secret_key).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -3,16 +3,20 @@ import { emit, listen } from '@tauri-apps/api/event';
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
|
||||
import { appState } from './lib/state.js';
|
||||
import { currentView } from './lib/routing.js';
|
||||
import { navigate, currentView } from './lib/routing.js';
|
||||
|
||||
|
||||
invoke('get_config').then(config => $appState.config = config);
|
||||
|
||||
listen('credentials-request', (tauriEvent) => {
|
||||
$appState.pendingRequests.put(tauriEvent.payload);
|
||||
});
|
||||
|
||||
// can't set this in routing.js directly for some reason
|
||||
if (!$currentView) {
|
||||
navigate('Home');
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<svelte:component
|
||||
this="{$currentView}"
|
||||
/>
|
||||
<!-- <svelte:component this="{VIEWS['./views/ShowApproved.svelte'].default}" bind:appState="{appState}" /> -->
|
||||
<svelte:component this="{$currentView}" />
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { writable, derived } from 'svelte/store';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
|
||||
const VIEWS = import.meta.glob('../views/*.svelte', {eager: true});
|
||||
|
||||
|
||||
export let currentView = writable();
|
||||
|
||||
export function navigate(viewName) {
|
||||
@ -10,4 +9,6 @@ export function navigate(viewName) {
|
||||
currentView.set(view);
|
||||
}
|
||||
|
||||
navigate('Home');
|
||||
export function getView(viewName) {
|
||||
return VIEWS[`../views/${viewName}.svelte`].default;
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
import { navigate } from '../lib/routing.js';
|
||||
import { navigate, currentView } from '../lib/routing.js';
|
||||
|
||||
export let target;
|
||||
export let hotkey = null;
|
||||
@ -28,8 +26,12 @@
|
||||
if (alt && !event.altKey) return;
|
||||
if (shift && !event.shiftKey) return;
|
||||
|
||||
if (event.code === hotkey) click();
|
||||
if (hotkey === 'Enter' && event.code === 'NumpadEnter') click();
|
||||
if (event.code === hotkey) {
|
||||
click();
|
||||
}
|
||||
else if (hotkey === 'Enter' && event.code === 'NumpadEnter') {
|
||||
click();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
13
src/ui/Setting.svelte
Normal file
13
src/ui/Setting.svelte
Normal file
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
export let title;
|
||||
</script>
|
||||
|
||||
|
||||
<div class="divider"></div>
|
||||
<div class="grid grid-cols-2 items-center">
|
||||
<h3 class="text-lg font-bold">{title}</h3>
|
||||
<slot name="input"></slot>
|
||||
</div>
|
||||
<p class="mt-3">
|
||||
<slot name="description"></slot>
|
||||
</p>
|
@ -15,33 +15,28 @@
|
||||
$appState.currentRequest = req;
|
||||
navigate('Approve');
|
||||
});
|
||||
|
||||
let status = 'unknown';
|
||||
onMount(async() => {
|
||||
status = await invoke('get_session_status');
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
<Nav />
|
||||
|
||||
{#if status === 'locked'}
|
||||
<div class="flex flex-col h-screen justify-center items-center space-y-4">
|
||||
<img src="/static/padlock-closed.svg" alt="An unlocked padlock" class="w-32" />
|
||||
{#await invoke('get_session_status') then status}
|
||||
{#if status === 'locked'}
|
||||
<img src="/static/padlock-closed.svg" alt="A locked padlock" class="w-32" />
|
||||
<h2 class="text-2xl font-bold">Creddy is locked</h2>
|
||||
<Link target="Unlock">
|
||||
<button class="btn btn-primary">Unlock</button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{:else if status === 'unlocked'}
|
||||
<div class="flex flex-col h-screen justify-center items-center space-y-4">
|
||||
<img src="/static/padlock-open.svg" alt="An unlocked padlock" class="w-24" />
|
||||
<h2 class="text-2xl font-bold">Waiting for requests</h2>
|
||||
</div>
|
||||
|
||||
{:else if status === 'empty'}
|
||||
<Link target="EnterCredentials">
|
||||
<button class="btn btn-primary">Enter Credentials</button>
|
||||
</Link>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
@ -1,18 +1,39 @@
|
||||
<script>
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
window.invoke = invoke;
|
||||
|
||||
import { appState } from '../lib/state.js';
|
||||
import Nav from '../ui/Nav.svelte';
|
||||
import Link from '../ui/Link.svelte';
|
||||
import Setting from '../ui/Setting.svelte';
|
||||
import ErrorAlert from '../ui/ErrorAlert.svelte';
|
||||
|
||||
async function save() {
|
||||
try {
|
||||
await invoke('save_config', {config: $appState.config});
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<Nav />
|
||||
|
||||
{#await invoke('get_config') then config}
|
||||
<div class="mx-auto mt-3 max-w-md">
|
||||
<h2 class="text-2xl font-bold text-center">Settings</h2>
|
||||
|
||||
<Setting title="Start minimized">
|
||||
<input slot="input" type="checkbox" bind:checked="{$appState.config.start_minimized}" class="justify-self-end toggle toggle-success" />
|
||||
<svelte:fragment slot="description">Minimize to the system tray at startup.</svelte:fragment>
|
||||
</Setting>
|
||||
|
||||
<div class="divider"></div>
|
||||
<div class="grid grid-cols-2 items-center">
|
||||
<h3 class="text-lg font-bold">Start minimized</h3>
|
||||
<input type="checkbox" class="justify-self-end toggle toggle-success" />
|
||||
<input type="checkbox" bind:checked="{$appState.config.start_minimized}" class="justify-self-end toggle toggle-success" />
|
||||
</div>
|
||||
<p class="mt-3">Minimize to the system tray at startup.</p>
|
||||
|
||||
@ -20,8 +41,8 @@
|
||||
<div class="grid grid-cols-2 items-center">
|
||||
<h3 class="text-lg font-bold">Re-hide delay</h3>
|
||||
<div class="justify-self-end">
|
||||
<span class="mr-2">(Seconds)</span>
|
||||
<input type="text" class="input input-sm input-bordered text-right max-w-[4rem]" />
|
||||
<span class="mr-2">(Milliseconds)</span>
|
||||
<input type="text" bind:value="{$appState.config.rehide_ms}" class="input input-sm input-bordered text-right max-w-[4rem]" />
|
||||
</div>
|
||||
</div>
|
||||
<p class="mt-3">
|
||||
@ -40,5 +61,5 @@
|
||||
</div>
|
||||
</div>
|
||||
<p class="mt-3">Update or re-enter your encrypted credentials.</p>
|
||||
|
||||
</div>
|
||||
{/await}
|
||||
|
@ -44,14 +44,13 @@
|
||||
<div class="flex flex-col h-screen items-center justify-center m-auto max-w-lg">
|
||||
<ErrorAlert>
|
||||
{error}
|
||||
<svelte:fragment slot="buttons">
|
||||
<Link target="Home">
|
||||
<button
|
||||
slot="buttons"
|
||||
class="btn btn-sm bg-transparent hover:bg-[#cd5a5a] border border-error-content text-error-content"
|
||||
>
|
||||
<button class="btn btn-sm bg-transparent hover:bg-[#cd5a5a] border border-error-content text-error-content">
|
||||
Ok
|
||||
</button>
|
||||
</Link>
|
||||
</svelte:fragment>
|
||||
</ErrorAlert>
|
||||
</div>
|
||||
{:else if success}
|
||||
|
@ -36,14 +36,13 @@
|
||||
<div class="flex flex-col h-screen items-center justify-center m-auto max-w-lg">
|
||||
<ErrorAlert>
|
||||
{error}
|
||||
<svelte:fragment slot="buttons">
|
||||
<Link target="Home">
|
||||
<button
|
||||
slot="buttons"
|
||||
class="btn btn-sm bg-transparent hover:bg-[#cd5a5a] border border-error-content text-error-content"
|
||||
>
|
||||
<button class="btn btn-sm bg-transparent hover:bg-[#cd5a5a] border border-error-content text-error-content" on:click="{() => navigate('Home')}">
|
||||
Ok
|
||||
</button>
|
||||
</Link>
|
||||
</svelte:fragment>
|
||||
</ErrorAlert>
|
||||
</div>
|
||||
{:else}
|
||||
|
Loading…
x
Reference in New Issue
Block a user