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