creddy/src/views/Approve.svelte

80 lines
2.7 KiB
Svelte
Raw Normal View History

2022-08-14 13:27:41 -07:00
<script>
import { invoke } from '@tauri-apps/api/tauri';
2023-04-24 12:05:11 -07:00
import { fly } from 'svelte/transition';
import { expoIn } from 'svelte/easing';
2023-04-24 12:05:11 -07:00
import { navigate } from '../lib/routing.js';
2022-12-28 15:48:25 -08:00
import Icon from '../ui/Icon.svelte';
2022-12-22 19:53:14 -08:00
export let appState;
2022-08-14 13:27:41 -07:00
2022-11-23 17:11:44 -08:00
async function approve() {
2022-12-13 21:50:34 -08:00
let status = await invoke('get_session_status');
2022-12-13 16:50:44 -08:00
if (status === 'unlocked') {
2023-04-24 12:05:11 -07:00
navigate('ShowApproved');
}
2022-12-13 16:50:44 -08:00
else if (status === 'locked') {
2023-04-24 12:05:11 -07:00
navigate('Unlock');
2022-12-13 16:50:44 -08:00
}
else {
2023-04-24 12:05:11 -07:00
navigate('EnterCredentials');
}
2022-11-23 17:11:44 -08:00
}
function deny() {
2023-04-24 12:05:11 -07:00
navigate('ShowDenied');
2022-11-23 17:11:44 -08:00
}
2022-12-19 15:26:44 -08:00
function handleHotkey(event) {
if (event.shiftKey && (event.code === 'Enter' || event.code === 'NumpadEnter')) {
approve();
}
2022-12-21 14:49:01 -08:00
else if (event.code === 'Escape') {
deny();
}
2022-12-19 15:26:44 -08:00
}
2022-08-14 13:27:41 -07:00
2023-04-23 22:29:12 -07:00
var appName = null;
console.log(appName);
if (appState.currentRequest.clients.length === 1) {
let path = appState.currentRequest.clients[0].exe;
let m = path.match(/\/([^/]+?$)|\\([^\\]+?$)/);
appName = m[1] || m[2];
}
</script>
2022-12-19 15:26:44 -08:00
2022-08-14 13:27:41 -07:00
2023-04-23 22:29:12 -07:00
<svelte:window on:keydown={handleHotkey} />
2023-04-24 12:05:11 -07:00
<!-- <div
out:fly="{{x: '-100vw', duration: 200, easing: expoIn}}"
class="flex flex-col space-y-4 p-4 m-auto max-w-max h-screen justify-center"
> -->
2023-04-23 22:29:12 -07:00
<div class="flex flex-col space-y-4 p-4 m-auto max-w-max h-screen justify-center">
<!-- <div class="p-4 rounded-box border-2 border-neutral-content"> -->
<div class="space-y-1 mb-4">
<h2 class="text-xl font-bold">{appName ? `"${appName}"` : 'An appplication'} would like to access your AWS credentials.</h2>
{#each appState.currentRequest.clients as client}
<p>Path: {client ? client.exe : 'Unknown'}</p>
<p>PID: {client ? client.pid : 'Unknown'}</p>
{/each}
</div>
2023-04-23 22:29:12 -07:00
<div class="grid grid-cols-2">
<button class="btn btn-error justify-self-start" on:click={deny}>
Deny
&nbsp;
<!-- <kbd class="kbd kbd-xs bg-error border-base-100">Esc</kbd> -->
<kbd class="normal-case px-1 py-0.5 rounded border border-neutral">Esc</kbd>
</button>
<button class="btn btn-success justify-self-end" on:click={approve}>
Approve
&nbsp;
<kbd class="normal-case px-1 py-0.5 rounded border border-neutral">Shift</kbd>
<span class="mx-0.5">+</span>
<kbd class="normal-case px-1 py-0.5 rounded border border-neutral">Enter</kbd>
</button>
</div>
<!-- </div> -->
</div>