2022-08-14 13:27:41 -07:00
|
|
|
<script>
|
2023-05-01 13:27:28 -07:00
|
|
|
import { onMount } from 'svelte';
|
2023-05-01 09:05:46 -07:00
|
|
|
import { listen } from '@tauri-apps/api/event';
|
2024-06-01 20:17:50 -04:00
|
|
|
import { invoke } from '@tauri-apps/api/core';
|
2024-02-06 20:27:51 -08:00
|
|
|
import { getVersion } from '@tauri-apps/api/app';
|
2022-11-27 22:03:15 -08:00
|
|
|
|
2024-01-21 13:46:39 -08:00
|
|
|
import { appState, acceptRequest, cleanupRequest } from './lib/state.js';
|
2023-04-26 13:05:51 -07:00
|
|
|
import { views, currentView, navigate } from './lib/routing.js';
|
2022-11-27 22:03:15 -08:00
|
|
|
|
2024-06-26 11:10:50 -04:00
|
|
|
import Approve from './views/Approve.svelte';
|
|
|
|
import CreatePassphrase from './views/CreatePassphrase.svelte';
|
|
|
|
import Unlock from './views/Unlock.svelte';
|
2022-11-27 22:03:15 -08:00
|
|
|
|
2024-06-26 11:10:50 -04:00
|
|
|
// set up app state
|
2023-04-25 22:10:14 -07:00
|
|
|
invoke('get_config').then(config => $appState.config = config);
|
2024-06-26 11:10:50 -04:00
|
|
|
invoke('get_session_status').then(status => $appState.sessionStatus = status);
|
2024-02-06 20:27:51 -08:00
|
|
|
getVersion().then(version => $appState.appVersion = version);
|
2024-06-26 11:10:50 -04:00
|
|
|
invoke('get_setup_errors')
|
|
|
|
.then(errs => {
|
|
|
|
$appState.setupErrors = errs.map(e => ({msg: e, show: true}));
|
|
|
|
});
|
|
|
|
|
2023-04-25 22:10:14 -07:00
|
|
|
|
2024-06-26 11:10:50 -04:00
|
|
|
// set up event handlers
|
|
|
|
listen('credential-request', (tauriEvent) => {
|
2023-04-25 08:49:00 -07:00
|
|
|
$appState.pendingRequests.put(tauriEvent.payload);
|
2022-11-27 22:03:15 -08:00
|
|
|
});
|
2023-05-01 13:27:28 -07:00
|
|
|
|
2024-01-21 13:46:39 -08:00
|
|
|
listen('request-cancelled', (tauriEvent) => {
|
|
|
|
const id = tauriEvent.payload;
|
|
|
|
if (id === $appState.currentRequest?.id) {
|
2024-02-07 13:03:12 -08:00
|
|
|
cleanupRequest();
|
2024-01-21 13:46:39 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const found = $appState.pendingRequests.find_remove(r => r.id === id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-06 20:27:51 -08:00
|
|
|
listen('locked', () => {
|
2024-06-26 11:10:50 -04:00
|
|
|
$appState.sessionStatus = 'locked';
|
2024-02-06 20:27:51 -08:00
|
|
|
});
|
|
|
|
|
2023-09-11 16:00:58 -07:00
|
|
|
|
2024-06-26 11:10:50 -04:00
|
|
|
// set up navigation
|
|
|
|
$views = import.meta.glob('./views/*.svelte', {eager: true});
|
|
|
|
navigate('Home');
|
|
|
|
|
|
|
|
|
|
|
|
// ready to rock and roll
|
2023-05-01 13:27:28 -07:00
|
|
|
acceptRequest();
|
2022-08-14 13:27:41 -07:00
|
|
|
</script>
|
|
|
|
|
2023-04-24 12:05:11 -07:00
|
|
|
|
2024-02-06 20:27:51 -08:00
|
|
|
<svelte:window
|
|
|
|
on:click={() => invoke('signal_activity')}
|
|
|
|
on:keydown={() => invoke('signal_activity')}
|
|
|
|
/>
|
|
|
|
|
2024-06-26 11:10:50 -04:00
|
|
|
|
|
|
|
{#if $appState.sessionStatus === 'empty'}
|
|
|
|
<!-- Empty state (no passphrase) takes precedence over everything -->
|
|
|
|
<CreatePassphrase />
|
|
|
|
{:else if $appState.currentRequest !== null}
|
|
|
|
<!-- if a request is pending, show approval flow (will include unlock if necessary) -->
|
|
|
|
<Approve />
|
|
|
|
{:else if $appState.sessionStatus === 'locked'}
|
|
|
|
<!-- if session is locked and no request is pending, show unlock screen -->
|
|
|
|
<Unlock />
|
|
|
|
{:else}
|
|
|
|
<!-- normal operation -->
|
|
|
|
<svelte:component this="{$currentView}" />
|
|
|
|
{/if}
|