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';
|
2023-04-24 12:05:11 -07:00
|
|
|
import { invoke } from '@tauri-apps/api/tauri';
|
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
|
|
|
|
|
|
|
|
2023-04-26 13:05:51 -07:00
|
|
|
$views = import.meta.glob('./views/*.svelte', {eager: true});
|
|
|
|
navigate('Home');
|
|
|
|
|
2023-04-25 22:10:14 -07:00
|
|
|
invoke('get_config').then(config => $appState.config = config);
|
2024-02-06 20:27:51 -08:00
|
|
|
invoke('get_session_status').then(status => $appState.credentialStatus = status);
|
|
|
|
getVersion().then(version => $appState.appVersion = version);
|
2023-04-25 22:10:14 -07:00
|
|
|
|
2022-11-27 22:03:15 -08:00
|
|
|
listen('credentials-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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-09-11 16:00:58 -07:00
|
|
|
listen('launch-terminal-request', async (tauriEvent) => {
|
|
|
|
if ($appState.currentRequest === null) {
|
|
|
|
let status = await invoke('get_session_status');
|
|
|
|
if (status === 'locked') {
|
|
|
|
navigate('Unlock');
|
|
|
|
}
|
|
|
|
else if (status === 'empty') {
|
|
|
|
navigate('EnterCredentials');
|
|
|
|
}
|
|
|
|
// else, session is unlocked, so do nothing
|
|
|
|
// (although we shouldn't even get the event in that case)
|
|
|
|
}
|
2023-09-14 15:04:25 -07:00
|
|
|
});
|
|
|
|
|
2024-02-06 20:27:51 -08:00
|
|
|
listen('locked', () => {
|
|
|
|
$appState.credentialStatus = 'locked';
|
|
|
|
});
|
|
|
|
|
2023-09-14 15:04:25 -07:00
|
|
|
invoke('get_setup_errors')
|
|
|
|
.then(errs => {
|
|
|
|
$appState.setupErrors = errs.map(e => ({msg: e, show: true}));
|
|
|
|
});
|
2023-09-11 16:00:58 -07:00
|
|
|
|
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')}
|
|
|
|
/>
|
|
|
|
|
2023-04-25 22:10:14 -07:00
|
|
|
<svelte:component this="{$currentView}" />
|