refactored design

This commit is contained in:
2025-10-28 14:16:17 +01:00
parent 16b71d9ea8
commit ef225b281f
34 changed files with 2574 additions and 819 deletions

View File

@ -10,6 +10,7 @@ export type IWorkspace = SelectHaexWorkspaces
export const useWorkspaceStore = defineStore('workspaceStore', () => {
const vaultStore = useVaultStore()
const windowStore = useWindowManagerStore()
const { deviceId } = storeToRefs(useDeviceStore())
const { currentVault } = storeToRefs(vaultStore)
@ -31,10 +32,16 @@ export const useWorkspaceStore = defineStore('workspaceStore', () => {
return
}
if (!deviceId.value) {
console.error('Keine DeviceId vergeben')
return
}
try {
const items = await currentVault.value.drizzle
.select()
.from(haexWorkspaces)
.where(eq(haexWorkspaces.deviceId, deviceId.value))
.orderBy(asc(haexWorkspaces.position))
workspaces.value = items
@ -58,11 +65,16 @@ export const useWorkspaceStore = defineStore('workspaceStore', () => {
throw new Error('Kein Vault geöffnet')
}
if (!deviceId.value) {
return
}
try {
const newIndex = workspaces.value.length + 1
const newWorkspace = {
name: name || `Workspace ${newIndex}`,
position: workspaces.value.length,
deviceId: deviceId.value,
}
const result = await currentVault.value.drizzle

View File

@ -4,8 +4,18 @@ import {
platform as tauriPlatform,
} from '@tauri-apps/plugin-os'
export const useDeviceStore = defineStore('vaultInstanceStore', () => {
const deviceId = ref<string>()
const deviceIdKey = 'deviceId'
const defaultDeviceFileName = 'device.json'
export const useDeviceStore = defineStore('vaultDeviceStore', () => {
const deviceId = ref<string | undefined>('')
const syncDeviceIdAsync = async () => {
deviceId.value = await getDeviceIdAsync()
if (deviceId.value) return deviceId.value
deviceId.value = await setDeviceIdAsync()
}
const platform = computedAsync(() => tauriPlatform())
@ -15,7 +25,7 @@ export const useDeviceStore = defineStore('vaultInstanceStore', () => {
const getDeviceIdAsync = async () => {
const store = await getStoreAsync()
return store.get<string>('id')
return await store.get<string>(deviceIdKey)
}
const getStoreAsync = async () => {
@ -23,30 +33,19 @@ export const useDeviceStore = defineStore('vaultInstanceStore', () => {
public: { haexVault },
} = useRuntimeConfig()
return await load(haexVault.instanceFileName || 'instance.json')
return await load(haexVault.deviceFileName || defaultDeviceFileName)
}
const setDeviceIdAsync = async (id?: string) => {
const store = await getStoreAsync()
const _id = id || crypto.randomUUID()
await store.set('id', _id)
deviceId.value = _id
await store.set(deviceIdKey, _id)
return _id
}
const setDeviceIdIfNotExistsAsync = async () => {
const _deviceId = await getDeviceIdAsync()
if (_deviceId) {
deviceId.value = _deviceId
return deviceId.value
}
return await setDeviceIdAsync()
}
const isKnownDeviceAsync = async () => {
const { readDeviceNameAsync } = useVaultSettingsStore()
const deviceId = await getDeviceIdAsync()
return deviceId ? (await readDeviceNameAsync(deviceId)) || false : false
return !!(await readDeviceNameAsync(deviceId.value))
}
const readDeviceNameAsync = async (id?: string) => {
@ -99,12 +98,13 @@ export const useDeviceStore = defineStore('vaultInstanceStore', () => {
addDeviceNameAsync,
deviceId,
deviceName,
getDeviceIdAsync,
hostname,
isKnownDeviceAsync,
platform,
readDeviceNameAsync,
setDeviceIdAsync,
setDeviceIdIfNotExistsAsync,
syncDeviceIdAsync,
updateDeviceNameAsync,
}
})

View File

@ -118,9 +118,11 @@ export const useVaultSettingsStore = defineStore('vaultSettingsStore', () => {
.where(eq(schema.haexSettings.key, 'vaultName'))
}
const readDeviceNameAsync = async (id: string) => {
const readDeviceNameAsync = async (id?: string) => {
const { currentVault } = useVaultStore()
if (!id) return undefined
const deviceName =
await currentVault?.drizzle?.query.haexSettings.findFirst({
where: and(