mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-17 06:30:50 +01:00
add notifications
This commit is contained in:
@ -14,6 +14,7 @@ const logoFileName = 'icon.svg'
|
||||
|
||||
export const useExtensionsStore = defineStore('extensionsStore', () => {
|
||||
const availableExtensions = ref<IHaexHubExtensionLink[]>([])
|
||||
const { addNotificationAsync } = useNotificationStore()
|
||||
|
||||
const extensionLinks = computed<ISidebarItem[]>(() =>
|
||||
availableExtensions.value
|
||||
@ -78,6 +79,7 @@ export const useExtensionsStore = defineStore('extensionsStore', () => {
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
addNotificationAsync({ type: 'error', text: JSON.stringify(error) })
|
||||
//throw error //new Error(`Keine Leseberechtigung für Ordner ${extensionDirectory}`);
|
||||
}
|
||||
}
|
||||
@ -176,6 +178,7 @@ export const useExtensionsStore = defineStore('extensionsStore', () => {
|
||||
*/
|
||||
return manifest
|
||||
} catch (error) {
|
||||
addNotificationAsync({ type: 'error', text: JSON.stringify(error) })
|
||||
console.error('ERROR readManifestFileAsync', error)
|
||||
}
|
||||
}
|
||||
@ -218,7 +221,12 @@ export const useExtensionsStore = defineStore('extensionsStore', () => {
|
||||
})
|
||||
|
||||
console.log('insert extensions', res)
|
||||
addNotificationAsync({
|
||||
type: 'success',
|
||||
text: `${manifest.name} wurde installiert`,
|
||||
})
|
||||
} catch (error) {
|
||||
addNotificationAsync({ type: 'error', text: JSON.stringify(error) })
|
||||
throw error
|
||||
/*
|
||||
const resourcePath = await resourceDir();
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
export interface IHaexNotication {
|
||||
title: string
|
||||
description?: string
|
||||
icon?: string
|
||||
image?: string
|
||||
alt?: string
|
||||
date: Date
|
||||
}
|
||||
|
||||
export const useNotificationStore = defineStore('notificationStore', () => {
|
||||
const notifications = ref<IHaexNotication[]>([
|
||||
{
|
||||
title: 'huhu',
|
||||
alt: 'test',
|
||||
description: 'Ganz was tolles',
|
||||
image: 'https://cdn.flyonui.com/fy-assets/avatar/avatar-1.png',
|
||||
date: new Date(),
|
||||
},
|
||||
])
|
||||
|
||||
return {
|
||||
notifications,
|
||||
}
|
||||
})
|
||||
@ -59,7 +59,9 @@ export const useLastVaultStore = defineStore('lastVaultStore', () => {
|
||||
await syncLastVaultsAsync()
|
||||
}
|
||||
|
||||
const test = async () => console.log('test')
|
||||
return {
|
||||
test,
|
||||
addVaultAsync,
|
||||
syncLastVaultsAsync,
|
||||
lastVaults,
|
||||
|
||||
@ -1 +1,103 @@
|
||||
export const useNotificationStore = defineStore('notificationStore', () => {})
|
||||
import { eq } from 'drizzle-orm'
|
||||
import {
|
||||
haexNotifications,
|
||||
type InsertHaexNotifications,
|
||||
} from '~~/src-tauri/database/schemas/vault'
|
||||
import {
|
||||
channels,
|
||||
isPermissionGranted,
|
||||
requestPermission,
|
||||
sendNotification,
|
||||
} from '@tauri-apps/plugin-notification'
|
||||
|
||||
export interface IHaexNotification {
|
||||
id: string
|
||||
title: string | null
|
||||
text?: string | null
|
||||
icon?: string | null
|
||||
image?: string | null
|
||||
alt?: string | null
|
||||
date: string | null
|
||||
type?: 'error' | 'success' | 'warning' | 'info' | null
|
||||
}
|
||||
|
||||
export const useNotificationStore = defineStore('notificationStore', () => {
|
||||
const isNotificationAllowed = ref<boolean>(false)
|
||||
|
||||
const requestNotificationPermissionAsync = async () => {
|
||||
console.log('requestNotificationPermissionAsync')
|
||||
const permission = await requestPermission()
|
||||
console.log('got permission', permission)
|
||||
isNotificationAllowed.value = permission === 'granted'
|
||||
sendNotification({
|
||||
title: 'Tauri',
|
||||
body: 'Tauri is awesome!',
|
||||
icon: 'dialog-information',
|
||||
})
|
||||
/* const existingChannels = await channels()
|
||||
console.log('existingChannels', existingChannels) */
|
||||
}
|
||||
const test = async () => console.log('test')
|
||||
const checkNotificationAsync = async () => {
|
||||
isNotificationAllowed.value = await isPermissionGranted()
|
||||
return isNotificationAllowed.value
|
||||
}
|
||||
|
||||
const notifications = ref<IHaexNotification[]>([])
|
||||
|
||||
const readNotificationsAsync = async (read: boolean = false) => {
|
||||
const { currentVault } = storeToRefs(useVaultStore())
|
||||
notifications.value = await currentVault.value.drizzle
|
||||
.select()
|
||||
.from(haexNotifications)
|
||||
.where(eq(haexNotifications.read, read))
|
||||
console.log('readNotificationsAsync', notifications.value)
|
||||
}
|
||||
|
||||
const addNotificationAsync = async (
|
||||
notification: Partial<InsertHaexNotifications>,
|
||||
) => {
|
||||
const { currentVault } = storeToRefs(useVaultStore())
|
||||
try {
|
||||
const _notification: InsertHaexNotifications = {
|
||||
id: crypto.randomUUID(),
|
||||
type: notification.type || 'info',
|
||||
alt: notification.alt,
|
||||
date: new Date().toUTCString(),
|
||||
icon: notification.icon,
|
||||
image: notification.image,
|
||||
read: notification.read || false,
|
||||
text: notification.text ?? '',
|
||||
title: notification.title ?? '',
|
||||
}
|
||||
|
||||
await currentVault.value.drizzle
|
||||
.insert(haexNotifications)
|
||||
.values(_notification)
|
||||
|
||||
await readNotificationsAsync()
|
||||
|
||||
if (!isNotificationAllowed.value) {
|
||||
const permission = await requestPermission()
|
||||
isNotificationAllowed.value = permission === 'granted'
|
||||
}
|
||||
|
||||
if (isNotificationAllowed.value) {
|
||||
sendNotification({
|
||||
title: _notification.title!,
|
||||
body: _notification.text!,
|
||||
})
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
return {
|
||||
notifications,
|
||||
isNotificationAllowed,
|
||||
checkNotificationAsync,
|
||||
addNotificationAsync,
|
||||
readNotificationsAsync,
|
||||
requestNotificationPermissionAsync,
|
||||
test,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user