Expose remote vault pairing in sync plugin

This commit is contained in:
mirivlad 2026-07-17 04:11:12 +08:00
parent 9904d4a962
commit 126d90cd68
4 changed files with 31 additions and 2 deletions

View File

@ -13,6 +13,7 @@
let connectionOk = null
let serverUrl = ''
let vaultId = ''
let username = ''
let password = ''
let syncInterval = 5
@ -44,6 +45,7 @@
const saved = await api.settings.read()
if (saved) {
serverUrl = saved.serverUrl || ''
vaultId = saved.vaultId || ''
username = saved.username || ''
autoSync = !!saved.autoSync
syncInterval = saved.syncInterval || 5
@ -56,6 +58,7 @@
settings = await syncAPI().status()
if (settings) {
if (settings.serverUrl) serverUrl = settings.serverUrl
if (settings.vaultId) vaultId = settings.vaultId
if (settings.syncInterval != null) syncInterval = settings.syncInterval
if (settings.syncInterval > 0) autoSync = true
if (settings.lastError) console.warn('[verstak.sync] last sync failed:', settings.lastError)
@ -78,7 +81,7 @@
resultMsg = ''
try {
if (api?.settings?.writeAll) {
await api.settings.writeAll({ serverUrl, username, autoSync, syncInterval })
await api.settings.writeAll({ serverUrl, vaultId, username, autoSync, syncInterval })
}
await syncAPI().setInterval(autoSync ? syncInterval : 0)
resultMsg = tr('ui.settingsSaved', null, 'Settings saved.')
@ -112,7 +115,7 @@
errorMsg = ''
connectionResult = ''
try {
await syncAPI().configure(serverUrl, username, password)
await syncAPI().configure(serverUrl, username, password, vaultId)
connectionResult = tr('ui.connectedSuccessfully', null, 'Connected successfully.')
connectionOk = true
username = ''
@ -235,6 +238,11 @@
{tr('ui.lastSyncError', null, 'The last synchronization did not finish. Try again.')}
</div>
{/if}
{#if settings && settings.lastWarning && !errorMsg}
<div style="padding:0.5rem 0.75rem;margin-bottom:0.75rem;background:rgba(245,158,11,0.1);border:1px solid rgba(245,158,11,0.3);border-radius:6px;color:#f59e0b;font-size:0.85rem;">
{tr('ui.unresolvedFilesWarning', null, 'Some files are not synchronized yet. Resolve the file warning and run sync again.')}
</div>
{/if}
<div style="background:#16213e;border:1px solid #0f3460;border-radius:8px;padding:1rem 1.25rem;margin-bottom:1rem;">
<h3 style="margin:0 0 0.75rem;color:#e0e0f0;font-size:0.95rem;">{tr('ui.server', null, 'Server')}</h3>
@ -244,6 +252,12 @@
<input id="sync-server-url" type="text" style={INPUT_STYLE} on:focus={e => e.target.style.cssText = INPUT_FOCUS_STYLE} on:blur={e => e.target.style.cssText = INPUT_STYLE} bind:value={serverUrl} placeholder="https://example.com" />
</div>
<div style="margin-bottom:0.75rem;">
<label for="sync-vault-id" style="display:block;color:#a0a0b8;font-size:0.85rem;margin-bottom:0.35rem;">{tr('ui.remoteVaultId', null, 'Remote vault ID (optional)')}</label>
<input id="sync-vault-id" type="text" style={INPUT_STYLE} on:focus={e => e.target.style.cssText = INPUT_FOCUS_STYLE} on:blur={e => e.target.style.cssText = INPUT_STYLE} bind:value={vaultId} />
<div style="color:#a0a0b8;font-size:0.78rem;margin-top:0.3rem;">{tr('ui.remoteVaultHint', null, 'Leave empty for this vault. Enter an existing remote vault ID to restore it on this device.')}</div>
</div>
<div style="margin-bottom:0.75rem;">
<label for="sync-username" style="display:block;color:#a0a0b8;font-size:0.85rem;margin-bottom:0.35rem;">{tr('ui.username', null, 'Username')}</label>
<input id="sync-username" type="text" style={INPUT_STYLE} on:focus={e => e.target.style.cssText = INPUT_FOCUS_STYLE} on:blur={e => e.target.style.cssText = INPUT_STYLE} bind:value={username} />

View File

@ -24,9 +24,12 @@
"ui.keyReset": "Sync key reset. Connect again to pair this device.",
"ui.syncConflicts": "Sync conflicts",
"ui.lastSyncError": "The last synchronization did not finish. Try again.",
"ui.unresolvedFilesWarning": "Some files are not synchronized yet. Resolve the file warning and run sync again.",
"ui.syncConflictItem": "A synchronization conflict needs attention.",
"ui.server": "Server",
"ui.serverUrl": "Server URL",
"ui.remoteVaultId": "Remote vault ID (optional)",
"ui.remoteVaultHint": "Leave empty for this vault. Enter an existing remote vault ID to restore it on this device.",
"ui.username": "Username",
"ui.password": "Password",
"ui.testConnection": "Test Connection",

View File

@ -24,9 +24,12 @@
"ui.keyReset": "Ключ синхронизации сброшен. Подключитесь снова, чтобы связать устройство.",
"ui.syncConflicts": "Конфликты синхронизации",
"ui.lastSyncError": "Последняя синхронизация не завершилась. Повторите попытку.",
"ui.unresolvedFilesWarning": "Некоторые файлы ещё не синхронизированы. Устраните предупреждение по файлу и повторите синхронизацию.",
"ui.syncConflictItem": "Конфликт синхронизации требует внимания.",
"ui.server": "Сервер",
"ui.serverUrl": "URL сервера",
"ui.remoteVaultId": "ID удалённого хранилища (необязательно)",
"ui.remoteVaultHint": "Оставьте пустым для этого хранилища. Укажите ID существующего удалённого хранилища, чтобы восстановить его на этом устройстве.",
"ui.username": "Имя пользователя",
"ui.password": "Пароль",
"ui.testConnection": "Проверить подключение",

View File

@ -27,5 +27,14 @@ if (!source.includes('conflictDetails')) {
if (!source.includes('Sync conflicts')) {
throw new Error('SyncSettings must label the conflict details section');
}
if (!source.includes('syncAPI().configure(serverUrl, username, password, vaultId)')) {
throw new Error('SyncSettings must pass the optional remote vault ID during pairing');
}
if (!source.includes('settings.lastWarning')) {
throw new Error('SyncSettings must render unresolved scanner warnings');
}
if (!source.includes("tr('ui.remoteVaultHint'")) {
throw new Error('SyncSettings must explain remote vault restoration');
}
console.log('sync plugin smoke passed');