Files
archy/aiui/packages/app/src/main.ts
T
archipelago 7ba3109b6d Add 'aiui/' from commit 'e30ac1d1069532fb6d652d87e2d4a2fe9d1b4773'
git-subtree-dir: aiui
git-subtree-mainline: 0c4826f8cc
git-subtree-split: e30ac1d106
2026-08-03 15:07:11 -04:00

77 lines
2.2 KiB
TypeScript

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createRouter, createWebHistory } from 'vue-router'
import App from './App.vue'
import './styles/main.css'
import { initializePlugins } from './plugins'
// PWA cache version — bump this when icons or critical assets change
const PWA_CACHE_VERSION = '2'
// Purge all service worker caches when version changes
;(async () => {
const key = 'aiui-cache-version'
const stored = localStorage.getItem(key)
if (stored !== PWA_CACHE_VERSION) {
localStorage.setItem(key, PWA_CACHE_VERSION)
if ('caches' in window) {
const names = await caches.keys()
await Promise.all(names.map((name) => caches.delete(name)))
}
if ('serviceWorker' in navigator) {
const registrations = await navigator.serviceWorker.getRegistrations()
await Promise.all(registrations.map((r) => r.unregister()))
}
if (stored !== null) {
// Only reload if this is an upgrade, not a fresh install
window.location.reload()
}
}
})()
// Capture embedded flag before router init (survives SPA navigation)
// Only embedded when explicitly requested via ?embedded param
const _embeddedFlag = new URLSearchParams(window.location.search).has('embedded')
;(window as unknown as Record<string, unknown>).__AIUI_EMBEDDED__ = _embeddedFlag
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'chat',
component: () => import('./pages/ChatPage.vue'),
},
{
path: '/guide',
name: 'guide',
component: () => import('./pages/GuidePage.vue'),
},
{
path: '/widget-demo',
name: 'widget-demo',
component: () => import('./pages/WidgetDemoPage.vue'),
},
{
path: '/browse',
name: 'file-browser',
component: () => import('./pages/BrowsePage.vue'),
},
{
path: '/view/:nostrAddr',
name: 'conversation-viewer',
component: () => import('./pages/ConversationViewerPage.vue'),
},
],
})
const app = createApp(App)
app.use(createPinia())
app.use(router)
initializePlugins().catch((err) => {
console.error('[AIUI] Failed to initialize plugins:', err)
})
app.mount('#app')