wip: notifications

This commit is contained in:
Nikolai Giman
2026-03-22 20:01:05 +01:00
parent 5c4859743e
commit c403673f4d
108 changed files with 5662 additions and 582 deletions
@@ -1,10 +1,12 @@
import { watch, type Ref } from 'vue'
import { useCollaborationStore } from '@/stores/collaboration.store'
import { useGoalListsStore } from '@/stores/goal-lists.store'
import { useKanbanStore } from '@/stores/kanban.store'
import { useTagsStore } from '@/stores/tag.store'
export function useProjectDataLoader(projectId: Ref<number>) {
const collaborationStore = useCollaborationStore()
const goalListsStore = useGoalListsStore()
const kanbanStore = useKanbanStore()
const tagsStore = useTagsStore()
@@ -15,6 +17,7 @@ export function useProjectDataLoader(projectId: Ref<number>) {
Promise.all([
kanbanStore.fetchStatuses(id),
collaborationStore.fetchCollaborationUsersForGoal(id),
goalListsStore.fetchLists(id),
])
}
}, { immediate: true })
@@ -0,0 +1,59 @@
import { ref } from 'vue'
import { Capacitor } from '@capacitor/core'
import { FirebaseMessaging } from '@capacitor-firebase/messaging'
import { $tvApi } from '@/plugins/axios'
import { useNotificationsStore } from '@/stores/notifications.store'
import { useRouter } from 'vue-router'
import { ALL_TASKS_LIST_ID } from 'taskview-api'
const registered = ref(false)
let initialized = false
export function usePushNotifications() {
const supported = Capacitor.isNativePlatform()
const router = useRouter()
async function init() {
console.log('-------------------------------- init push notifications --------------------------------')
if (initialized || !supported) return
initialized = true
const permission = await FirebaseMessaging.requestPermissions()
if (permission.receive !== 'granted') return
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
const { token } = await FirebaseMessaging.getToken()
if (token) {
const platform = Capacitor.getPlatform() as 'android' | 'ios'
await $tvApi.notifications.registerDevice(token, platform, timezone)
registered.value = true
}
FirebaseMessaging.addListener('tokenReceived', async ({ token }) => {
const platform = Capacitor.getPlatform() as 'android' | 'ios'
await $tvApi.notifications.registerDevice(token, platform, timezone)
registered.value = true
})
FirebaseMessaging.addListener('notificationReceived', (_notification) => {
const notificationsStore = useNotificationsStore()
notificationsStore.fetchNotifications(true)
})
FirebaseMessaging.addListener('notificationActionPerformed', (action) => {
const data = action.notification.data as Record<string, string> | undefined
if (data?.taskId && data?.goalId) {
router.push({
name: 'user',
params: {
projectId: data.goalId,
listId: data.goalListId || ALL_TASKS_LIST_ID,
taskId: data.taskId,
},
})
}
})
}
return { supported, registered, init }
}
+44 -41
View File
@@ -1,3 +1,4 @@
// @ts-nocheck
import { Preferences } from '@capacitor/preferences'
import { SplashScreen } from '@capacitor/splash-screen'
import { type BundleInfo, CapacitorUpdater } from '@capgo/capacitor-updater'
@@ -21,61 +22,63 @@ function isNewerVersion(server: string, current: string): boolean {
}
export async function useUpdater(canUpdate: boolean = false) {
try {
const BRANCH_MODE: 'prod' | 'dev' = (await $ls.getValue('update_loading')) === 'dev' ? 'dev' : 'prod'
console.log(canUpdate);
return;
// try {
// const BRANCH_MODE: 'prod' | 'dev' = (await $ls.getValue('update_loading')) === 'dev' ? 'dev' : 'prod'
const updateInfo = await $api.get<AppResponse<{ version: string; file: string; branch: 'prod' | 'dev' }[]>>(
`${useTaskViewMainUrl()}/module/updates/info`,
)
// const updateInfo = await $api.get<AppResponse<{ version: string; file: string; branch: 'prod' | 'dev' }[]>>(
// `${useTaskViewMainUrl()}/module/updates/info`,
// )
const { value: currentVersion } = await Preferences.get({ key: 'app_version' })
// const { value: currentVersion } = await Preferences.get({ key: 'app_version' })
const last = updateInfo.data.response.find((i) => i.branch === BRANCH_MODE)
// const last = updateInfo.data.response.find((i) => i.branch === BRANCH_MODE)
console.log('branch', BRANCH_MODE)
// console.log('branch', BRANCH_MODE)
if (!last) {
console.log('[Update] No new updates for this branch.', BRANCH_MODE)
return
}
// if (!last) {
// console.log('[Update] No new updates for this branch.', BRANCH_MODE)
// return
// }
console.log('currentVersion', currentVersion, 'updateInfo', last)
// console.log('currentVersion', currentVersion, 'updateInfo', last)
if (!currentVersion || isNewerVersion(last.version, currentVersion) || (version && version?.version !== last.version)) {
console.log('[Update] Downloading new version:', last.version)
// if (!currentVersion || isNewerVersion(last.version, currentVersion) || (version && version?.version !== last.version)) {
// console.log('[Update] Downloading new version:', last.version)
version = await CapacitorUpdater.download({
version: last.version,
url: `${useTaskViewMainUrl()}/module/updates/download?branch=${BRANCH_MODE}`,
})
} else {
console.log('[Update] No new updates need to download.')
}
// version = await CapacitorUpdater.download({
// version: last.version,
// url: `${useTaskViewMainUrl()}/module/updates/download?branch=${BRANCH_MODE}`,
// })
// } else {
// console.log('[Update] No new updates need to download.')
// }
if (canUpdate && version) {
try {
console.log('[Update] New version available:', last.version)
// if (canUpdate && version) {
// try {
// console.log('[Update] New version available:', last.version)
SplashScreen.show()
// SplashScreen.show()
console.log('[Update] Version:', version)
// console.log('[Update] Version:', version)
await CapacitorUpdater.next(version)
// await CapacitorUpdater.next(version)
await Preferences.set({ key: 'app_version', value: last.version })
// await Preferences.set({ key: 'app_version', value: last.version })
await CapacitorUpdater.set(version)
// await CapacitorUpdater.set(version)
console.log('[set version]', last.version)
// console.log('[set version]', last.version)
console.log('[Update] Update applied. Will take effect after restart.')
} catch (err: unknown) {
console.log(err)
} finally {
SplashScreen.hide()
}
}
} catch (err) {
console.warn('[Update] Error checking for update:', err)
}
// console.log('[Update] Update applied. Will take effect after restart.')
// } catch (err: unknown) {
// console.log(err)
// } finally {
// SplashScreen.hide()
// }
// }
// } catch (err) {
// console.warn('[Update] Error checking for update:', err)
// }
}