50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import { createApp } from 'vue'
|
|
import { createPinia } from 'pinia'
|
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
import App from './App.vue'
|
|
import AuthView from './views/AuthView.vue'
|
|
import DeviceView from './views/DeviceView.vue'
|
|
import ContactsView from './views/ContactsView.vue'
|
|
import ChatView from './views/ChatView.vue'
|
|
import GroupView from './views/GroupView.vue'
|
|
import FavoritesView from './views/FavoritesView.vue'
|
|
import PreferencesView from './views/PreferencesView.vue'
|
|
import SecurityView from './views/SecurityView.vue'
|
|
import { initializePreferences } from './preferences'
|
|
import Workspace from './views/Workspace.vue'
|
|
import { useSession } from './session'
|
|
import { incomingGroupInvite, parseGroupInvite } from './chat/group-invites'
|
|
import './style.css'
|
|
|
|
initializePreferences()
|
|
const pinia = createPinia()
|
|
const router = createRouter({
|
|
history: createWebHashHistory(),
|
|
routes: [
|
|
{ path: '/', redirect: '/devices' },
|
|
{ path: '/login', component: AuthView },
|
|
{ path: '/', component: Workspace, children: [
|
|
{ path: 'devices', component: DeviceView },
|
|
{ path: 'contacts', component: ContactsView },
|
|
{ path: 'chat/:user?', component: ChatView },
|
|
{ path: 'groups/:id?', component: GroupView },
|
|
{ path: 'favorites', component: FavoritesView },
|
|
{ path: 'settings', component: PreferencesView },
|
|
{ path: 'security', component: SecurityView },
|
|
] },
|
|
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
|
],
|
|
})
|
|
|
|
router.beforeEach((to) => {
|
|
const signedIn = Boolean(useSession(pinia).identity)
|
|
if (to.path === '/groups' && typeof to.query.invite === 'string') {
|
|
incomingGroupInvite.value = parseGroupInvite(to.query.invite)
|
|
return { path: signedIn ? '/groups' : '/login', replace: true }
|
|
}
|
|
if (!signedIn && to.path !== '/login') return '/login'
|
|
if (signedIn && to.path === '/login') return '/devices'
|
|
})
|
|
|
|
createApp(App).use(pinia).use(router).mount('#app')
|