diff --git a/src/background/service-worker.js b/src/background/service-worker.js index b8d5a4b..f0f35a0 100644 --- a/src/background/service-worker.js +++ b/src/background/service-worker.js @@ -472,6 +472,20 @@ api.alarms.onAlarm.addListener(async (alarm) => { const result = await SilentSendSync.performAutoSync(); if (result.pulled) { console.log('[Silent Send] Auto-sync pulled new data'); + // Broadcast decrypted data to all open content scripts so + // substitution works immediately without a page reload. + const mappings = await Storage.getMappings(); + const identity = await Storage.getIdentity(); + const settings = await Storage.getSettings(); + const allPatterns = [...BUILTIN_URL_PATTERNS]; + const customDomains = settings.customDomains || []; + for (const domain of customDomains) allPatterns.push(domain + '/*'); + for (const urlPattern of allPatterns) { + const tabs = await api.tabs.query({ url: urlPattern }).catch(() => []); + for (const tab of tabs) { + api.tabs.sendMessage(tab.id, { type: 'vault:unlocked', mappings, identity, settings }).catch(() => {}); + } + } } if (result.error) { console.warn('[Silent Send] Auto-sync error:', result.error); diff --git a/src/lib/storage.js b/src/lib/storage.js index 23b4122..ea9a7ef 100644 --- a/src/lib/storage.js +++ b/src/lib/storage.js @@ -226,7 +226,19 @@ const Storage = { }, async saveProfiles(profiles) { - await this._writeSecure(KEYS.IDENTITY, { profiles }, { ss_lastModified: Date.now() }); + // Only advance ss_lastModified if at least one profile contains real PII. + // Creating the default empty profile on a fresh install should not count + // as "this browser has data" — that would make the pull timestamp check + // think remote Gist data is stale and skip the import. + const hasRealData = (profiles || []).some(p => + (p.names || []).some(n => n.real?.trim()) || + (p.emails || []).some(e => e.real?.trim()) || + (p.usernames || []).some(u => u.real?.trim()) || + (p.phones || []).some(ph => ph.real?.trim()) || + p.catchAllEmail?.trim() + ); + const extras = hasRealData ? { ss_lastModified: Date.now() } : {}; + await this._writeSecure(KEYS.IDENTITY, { profiles }, extras); }, async addProfile(name) { diff --git a/src/lib/sync.js b/src/lib/sync.js index d01dbb0..2a62e64 100644 --- a/src/lib/sync.js +++ b/src/lib/sync.js @@ -751,7 +751,8 @@ const SilentSendSync = { } const json = await resp.json(); - await api.storage.local.set({ ss_gist_id: json.id }); + const now = Date.now(); + await api.storage.local.set({ ss_gist_id: json.id, ss_last_push_time: now, ss_last_push_source: 'gist' }); return { success: true, gistId: json.id }; } catch (e) { return { success: false, reason: e.message }; diff --git a/src/options/options.js b/src/options/options.js index 9123539..313aedf 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -161,11 +161,17 @@ document.addEventListener('DOMContentLoaded', async () => { // --- GitHub Gist sync --- // Restore saved token (session only — never persisted to storage) { - const stored = await api.storage.local.get(['ss_gist_id', 'ss_last_pull_time', 'ss_last_pull_source']); + const stored = await api.storage.local.get([ + 'ss_gist_id', 'ss_last_pull_time', 'ss_last_pull_source', + 'ss_last_push_time', 'ss_last_push_source', + ]); if (stored.ss_gist_id) { let status = `Gist ID: ${stored.ss_gist_id.slice(0, 12)}…`; + if (stored.ss_last_push_time && stored.ss_last_push_source === 'gist') { + status += ` · Pushed: ${new Date(stored.ss_last_push_time).toLocaleString()}`; + } if (stored.ss_last_pull_time && stored.ss_last_pull_source === 'gist') { - status += ` · Last pulled: ${new Date(stored.ss_last_pull_time).toLocaleString()}`; + status += ` · Pulled: ${new Date(stored.ss_last_pull_time).toLocaleString()}`; } setGistSyncStatus(status, 'ok'); }