switch to invokes instead of emits

This commit is contained in:
Joseph Montanaro
2022-12-13 16:50:44 -08:00
parent 48269855e5
commit 9055fa41aa
11 changed files with 91 additions and 40 deletions

View File

@ -7,11 +7,15 @@
const dispatch = createEventDispatcher();
async function approve() {
if (appState.credentialStatus === 'unlocked') {
let status = await invoke('get-session-status');
if (status === 'unlocked') {
dispatch('navigate', {target: 'ShowApproved'});
}
else if (status === 'locked') {
dispatch('navigate', {target: 'Unlock'})
}
else {
dispatch('navigate', {target: 'Unlock'});
dispatch('navigate', {target: 'EnterCredentials'});
}
}

View File

@ -8,10 +8,9 @@
onMount(async () => {
// will block until a request comes in
let req = await appState.pendingRequests.get();
console.log(req);
appState.currentRequest = req;
console.log('Got credentials request from queue.');
console.log(appState);
console.log('Got credentials request from queue:');
console.log(req);
dispatch('navigate', {target: 'Approve'});
});
</script>

View File

@ -1,13 +1,18 @@
<script>
import { createEventDispatcher } from 'svelte';
import { onMount, createEventDispatcher } from 'svelte';
import { emit } from '@tauri-apps/api/event';
import { invoke } from '@tauri-apps/api/tauri';
export let appState;
var p = emit('request-response', {response: 'approved', requestId: 1});
console.log('event emitted');
console.log(p);
appState.currentRequest = null;
onMount(async () => {
let response = {
id: appState.currentRequest.id,
approval: 'Approved',
}
await invoke('respond', {response});
appState.currentRequest = null;
});
const dispatch = createEventDispatcher();
window.setTimeout(() => dispatch('navigate', {target: 'Home'}), 3000);

View File

@ -1,11 +1,18 @@
<script>
import { createEventDispatcher } from 'svelte';
import { onMount, createEventDispatcher } from 'svelte';
import { emit } from '@tauri-apps/api/event';
import { invoke } from '@tauri-apps/api/tauri';
export let appState;
emit('request-response', {response: 'denied', requestId: 1});
appState.currentRequest = null;
onMount(async () => {
let response = {
id: appState.currentRequest.id,
approval: 'Denied',
}
await invoke('respond', {response});
appState.currentRequest = null;
});
const dispatch = createEventDispatcher();
window.setTimeout(() => dispatch('navigate', {target: 'Home'}), 3000);

View File

@ -9,16 +9,12 @@
let passphrase = '';
async function unlock() {
console.log('invoking unlock command.')
let res = await invoke('unlock', {passphrase});
if (res) {
appState.credentialStatus = 'unlocked';
console.log('Unlock successful!');
if (appState.currentRequest) {
dispatch('navigate', {target: 'ShowApproved'});
}
try {
await invoke('unlock', {passphrase});
}
else {
// indicate decryption failed
catch (e) {
console.log('Unlock error:', e);
}
}
</script>