WIP V improve UX [snapshot task 2]

Add the connections workspace (sidebar, editable slots, per-slot activity,
removal dialog with focus wrapping), remove the downloadable local HTML and
unreleased identity backup/restore, and start the 0.0.5 draft changelog.
Restore the released 0.0.3/0.0.4 changelog entries. Enable focus emulation
in browser checks so background tabs receive focus/blur events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-17 13:44:08 +02:00
1 parent 58c3e2af86
commit 5f8c6a1916
21 files changed
+879 -306

No files matched your search

+32 -43
View File
@@ -1,50 +1,49 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue';
import { clearIdentityStorage, createIdentity, loadIdentityState, saveIdentityState, exportBackup, importBackup, type IdentityState } from '../lib/identity.ts';
import { onActivated, onMounted, ref, shallowRef, watch } from 'vue';
import { clearIdentityStorage, createIdentity, loadIdentityState, saveIdentityState, type IdentityState } from '../lib/identity.ts';
import { asError } from '../lib/validation.ts';
const props = defineProps<{ disabled: boolean }>();
const props = defineProps<{ disabled: boolean; preferredDevice?: string }>();
const emit = defineEmits<{ change: [state: IdentityState, enabled: boolean, expected: string] }>();
const supported = (() => { try { return location.protocol !== 'file:' && isSecureContext && !!crypto.subtle && !!window.indexedDB; } catch { return false; } })();
const supported = (() => { try { return isSecureContext && !!crypto.subtle && !!window.indexedDB; } catch { return false; } })();
const state = shallowRef<IdentityState>({ identity: null, contacts: [] });
const enabled = ref(false), expected = ref(''), working = ref(false), loaded = ref(false);
const error = ref(''), password = ref(''), confirmReplace = ref(false);
const backupUrl = ref('');
onBeforeUnmount(() => { if (backupUrl.value) URL.revokeObjectURL(backupUrl.value); });
const error = ref(''), confirmDelete = ref(false);
watch([state, enabled, expected], () => emit('change', state.value, enabled.value, expected.value));
onMounted(async () => {
if (!supported) return;
try { state.value = await loadIdentityState(); loaded.value = true; }
try {
state.value = await loadIdentityState(); loaded.value = true;
if (props.preferredDevice && state.value.contacts.some(item => item.key === props.preferredDevice)) expected.value = props.preferredDevice;
}
catch (err) { error.value = asError(err).message; }
});
onActivated(async () => {
// Another slot may have changed the shared identity or contact list while
// this workspace was cached. Never interrupt an active session to refresh it.
if (!loaded.value || props.disabled) return;
try {
const next = await loadIdentityState();
if (props.disabled) return;
if (next.identity?.publicKey !== state.value.identity?.publicKey) enabled.value = false;
if (!next.contacts.some(item => item.key === expected.value)) expected.value = '';
if (!expected.value && props.preferredDevice && next.contacts.some(item => item.key === props.preferredDevice)) expected.value = props.preferredDevice;
if (next.revision !== state.value.revision) confirmDelete.value = false;
state.value = next;
} catch (err) { error.value = asError(err).message; }
});
async function store(next: IdentityState) {
state.value = await saveIdentityState(next, state.value.revision);
if (backupUrl.value) { URL.revokeObjectURL(backupUrl.value); backupUrl.value = ''; }
}
async function run(action: () => Promise<void>) {
if (props.disabled || working.value) return;
working.value = true; error.value = '';
try { await action(); } catch (err) { error.value = asError(err).message; }
finally { working.value = false; password.value = ''; }
finally { working.value = false; }
}
function recover() { void run(async () => { if (!confirmReplace.value) return; await clearIdentityStorage(); state.value = { identity: null, contacts: [] }; loaded.value = true; confirmReplace.value = false; }); }
function recover() { void run(async () => { if (!confirmDelete.value) return; await clearIdentityStorage(); state.value = { identity: null, contacts: [] }; loaded.value = true; confirmDelete.value = false; }); }
function create() { void run(async () => { await store({ identity: await createIdentity(), contacts: [] }); enabled.value = true; }); }
function remove(key: string) { void run(async () => { await store({ ...state.value, contacts: state.value.contacts.filter(item => item.key !== key) }); if (expected.value === key) expected.value = ''; }); }
function reset() { void run(async () => { if (!confirmReplace.value) return; await store({ identity: null, contacts: [] }); enabled.value = false; expected.value = ''; confirmReplace.value = false; }); }
function backup() { void run(async () => {
const data = await exportBackup(state.value, password.value);
if (backupUrl.value) URL.revokeObjectURL(backupUrl.value);
backupUrl.value = URL.createObjectURL(new Blob([data], { type: 'application/json' }));
}); }
function restore(event: Event) {
const input = event.target as HTMLInputElement, file = input.files?.[0]; input.value = '';
if (!file) return;
void run(async () => {
if (state.value.identity && !confirmReplace.value) throw new Error('Confirm replacement before restoring a backup.');
if (file.size > 100000) throw new Error('Backup is too large.');
const next = await importBackup(await file.text(), password.value);
await store(next); enabled.value = false; expected.value = ''; confirmReplace.value = false;
});
}
function reset() { void run(async () => { if (!confirmDelete.value) return; await store({ identity: null, contacts: [] }); enabled.value = false; expected.value = ''; confirmDelete.value = false; }); }
async function remember(key: string, name: string) {
if (!state.value.identity) throw new Error('Create a local identity first.');
const next = { ...state.value, contacts: [...state.value.contacts.filter(item => item.key !== key), { key, name }] };
@@ -59,10 +58,7 @@ async function refreshForConnection() {
enabled.value = false; expected.value = '';
}
if (!next.contacts.some(contact => contact.key === expected.value)) expected.value = '';
if (next.revision !== state.value.revision) {
if (backupUrl.value) URL.revokeObjectURL(backupUrl.value);
backupUrl.value = ''; confirmReplace.value = false; password.value = '';
}
if (next.revision !== state.value.revision) confirmDelete.value = false;
state.value = next; loaded.value = true; error.value = '';
return { identity: enabled.value ? next.identity : null, expected: expected.value };
} catch (err) {
@@ -76,7 +72,7 @@ defineExpose({ remember, refreshForConnection });
<template>
<details v-if="supported">
<summary>Remembered devices</summary>
<p class="status">Opt in to a device identity stored in this browser. Temporary connections remain available. Clearing site data loses your identity and contacts. Trusted app code is required: it can use and export this identity.</p>
<p class="status">Opt in to a device identity stored in this browser. Temporary connections remain available. Clearing site data loses your identity and contacts. Trusted app code is required: it can use this identity.</p>
<fieldset class="device-settings" :disabled="disabled || working || !loaded">
<button v-if="!state.identity" @click="create">Create device identity</button>
<template v-else>
@@ -89,19 +85,12 @@ defineExpose({ remember, refreshForConnection });
</select>
<ul aria-label="Remembered devices"><li v-for="contact in state.contacts" :key="contact.key">{{ contact.name }} <button @click="remove(contact.key)" :aria-label="'Forget ' + contact.name">Forget</button></li></ul>
</template>
<label for="backup-password">Backup password (at least 12 characters)</label>
<input id="backup-password" v-model="password" type="password" autocomplete="new-password" maxlength="1024" />
<button :disabled="!state.identity || password.length < 12" @click="backup">Create encrypted backup</button>
<a v-if="backupUrl" :href="backupUrl" download="hellcon-device-backup.json">Save encrypted backup</a>
<p class="status">A backup contains your identity and contacts. Keep its password separately. Restoring the same backup on another browser gives that browser the same identity.</p>
<label v-if="state.identity"><input v-model="confirmReplace" type="checkbox" /> Replace or delete this browser’s identity and contacts</label>
<label for="restore-identity">Restore encrypted backup</label>
<input id="restore-identity" type="file" accept="application/json,.json" :disabled="password.length < 12 || (!!state.identity && !confirmReplace)" @change="restore" />
<button v-if="state.identity" :disabled="!confirmReplace" @click="reset">Delete identity and contacts</button>
<label v-if="state.identity"><input v-model="confirmDelete" type="checkbox" /> Delete this browser’s identity and contacts</label>
<button v-if="state.identity" :disabled="!confirmDelete" @click="reset">Delete identity and contacts</button>
</fieldset>
<div v-if="!loaded && error">
<label><input v-model="confirmReplace" type="checkbox" :disabled="disabled || working" /> Delete unreadable device storage, including identity and contacts</label>
<button :disabled="disabled || working || !confirmReplace" @click="recover">Clear device storage</button>
<label><input v-model="confirmDelete" type="checkbox" :disabled="disabled || working" /> Delete unreadable device storage, including identity and contacts</label>
<button :disabled="disabled || working || !confirmDelete" @click="recover">Clear device storage</button>
</div>
<p v-if="error" role="alert" class="error">{{ error }}</p>
</details>