mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-17 06:30:50 +01:00
extensions fixed
This commit is contained in:
@ -8,16 +8,7 @@ import type {
|
||||
} from '~/types/haexhub'
|
||||
import type { ExtensionPreview } from '@bindings/ExtensionPreview'
|
||||
import type { ExtensionPermissions } from '~~/src-tauri/bindings/ExtensionPermissions'
|
||||
|
||||
interface ExtensionInfoResponse {
|
||||
keyHash: string
|
||||
name: string
|
||||
fullId: string
|
||||
version: string
|
||||
displayName: string | null
|
||||
namespace: string | null
|
||||
allowedOrigin: string
|
||||
}
|
||||
import type { ExtensionInfoResponse } from '~~/src-tauri/bindings/ExtensionInfoResponse'
|
||||
|
||||
/* const manifestFileName = 'manifest.json'
|
||||
const logoFileName = 'icon.svg' */
|
||||
@ -130,8 +121,10 @@ export const useExtensionsStore = defineStore('extensionsStore', () => {
|
||||
name: ext.displayName || ext.name,
|
||||
version: ext.version,
|
||||
author: ext.namespace,
|
||||
icon: null,
|
||||
enabled: true,
|
||||
icon: ext.icon,
|
||||
enabled: ext.enabled,
|
||||
description: ext.description,
|
||||
homepage: ext.homepage,
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Extensions:', error)
|
||||
@ -192,54 +185,6 @@ export const useExtensionsStore = defineStore('extensionsStore', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/* const installAsync = async (extensionDirectory: string | null) => {
|
||||
try {
|
||||
if (!extensionDirectory)
|
||||
throw new Error('Kein Ordner für Erweiterung angegeben')
|
||||
const manifestPath = await join(extensionDirectory, manifestFileName)
|
||||
const manifest = (await JSON.parse(
|
||||
await readTextFile(manifestPath),
|
||||
)) as IHaexHubExtensionManifest
|
||||
|
||||
const destination = await getExtensionPathAsync(
|
||||
manifest.id,
|
||||
manifest.version,
|
||||
)
|
||||
|
||||
await checkSourceExtensionDirectoryAsync(extensionDirectory)
|
||||
|
||||
await invoke('copy_directory', {
|
||||
source: extensionDirectory,
|
||||
destination,
|
||||
})
|
||||
|
||||
const logoFilePath = await join(destination, logoFileName)
|
||||
const logo = await readTextFile(logoFilePath)
|
||||
|
||||
const { currentVault } = storeToRefs(useVaultStore())
|
||||
const res = await currentVault.value?.drizzle
|
||||
.insert(haexExtensions)
|
||||
.values({
|
||||
id: manifest.id,
|
||||
name: manifest.name,
|
||||
author: manifest.author,
|
||||
enabled: true,
|
||||
url: manifest.url,
|
||||
version: manifest.version,
|
||||
icon: logo,
|
||||
})
|
||||
|
||||
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 removeExtensionAsync = async (extensionId: string, version: string) => {
|
||||
try {
|
||||
await invoke('remove_extension', {
|
||||
@ -356,70 +301,6 @@ export const useExtensionsStore = defineStore('extensionsStore', () => {
|
||||
})
|
||||
return preview.value
|
||||
}
|
||||
/* const readManifestFileAsync = async (
|
||||
extensionId: string,
|
||||
version: string,
|
||||
) => {
|
||||
try {
|
||||
if (!(await isExtensionInstalledAsync({ id: extensionId, version })))
|
||||
return null
|
||||
|
||||
const extensionPath = await getExtensionPathAsync(
|
||||
extensionId,
|
||||
`${version}`,
|
||||
)
|
||||
const manifestPath = await join(extensionPath, manifestFileName)
|
||||
const manifest = (await JSON.parse(
|
||||
await readTextFile(manifestPath),
|
||||
)) as IHaexHubExtensionManifest
|
||||
|
||||
return manifest
|
||||
} catch (error) {
|
||||
addNotificationAsync({ type: 'error', text: JSON.stringify(error) })
|
||||
console.error('ERROR readManifestFileAsync', error)
|
||||
}
|
||||
} */
|
||||
|
||||
/* const extensionEntry = computedAsync(
|
||||
async () => {
|
||||
try {
|
||||
|
||||
|
||||
if (!currentExtension.value?.id || !currentExtension.value.version) {
|
||||
console.log('extension id or entry missing', currentExtension.value)
|
||||
return '' // "no mani: " + currentExtension.value;
|
||||
}
|
||||
|
||||
const extensionPath = await getExtensionPathAsync(
|
||||
currentExtension.value?.id,
|
||||
currentExtension.value?.version,
|
||||
) //await join(await resourceDir(), currentExtension.value.. extensionDir, entryFileName);
|
||||
|
||||
console.log('extensionEntry extensionPath', extensionPath)
|
||||
const manifest = await readManifestFileAsync(
|
||||
currentExtension.value.id,
|
||||
currentExtension.value.version,
|
||||
)
|
||||
|
||||
if (!manifest) return '' //"no manifest readable";
|
||||
|
||||
//const entryPath = await join(extensionPath, manifest.entry)
|
||||
|
||||
const hexName = stringToHex(
|
||||
JSON.stringify({
|
||||
id: currentExtension.value.id,
|
||||
version: currentExtension.value.version,
|
||||
}),
|
||||
)
|
||||
|
||||
return `haex-extension://${hexName}`
|
||||
} catch (error) {
|
||||
console.error('ERROR extensionEntry', error)
|
||||
}
|
||||
},
|
||||
null,
|
||||
{ lazy: true },
|
||||
) */
|
||||
|
||||
return {
|
||||
availableExtensions,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// stores/extensions/tabs.ts
|
||||
import type { IHaexHubExtension } from '~/types/haexhub'
|
||||
import { getExtensionWindow } from '~/composables/extensionMessageHandler'
|
||||
|
||||
interface ExtensionTab {
|
||||
extension: IHaexHubExtension
|
||||
@ -40,6 +41,12 @@ export const useExtensionTabsStore = defineStore('extensionTabsStore', () => {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if extension is enabled
|
||||
if (!extension.enabled) {
|
||||
console.warn(`Extension ${extensionId} ist deaktiviert und kann nicht geöffnet werden`)
|
||||
return
|
||||
}
|
||||
|
||||
// Bereits geöffnet? Nur aktivieren
|
||||
if (openTabs.value.has(extensionId)) {
|
||||
setActiveTab(extensionId)
|
||||
@ -78,8 +85,25 @@ export const useExtensionTabsStore = defineStore('extensionTabsStore', () => {
|
||||
// Zeige neuen Tab
|
||||
const newTab = openTabs.value.get(extensionId)
|
||||
if (newTab) {
|
||||
const now = Date.now()
|
||||
const inactiveDuration = now - newTab.lastAccessed
|
||||
const TEN_MINUTES = 10 * 60 * 1000
|
||||
|
||||
// Reload iframe if inactive for more than 10 minutes
|
||||
if (inactiveDuration > TEN_MINUTES && newTab.iframe) {
|
||||
console.log(`[TabStore] Reloading extension ${extensionId} after ${Math.round(inactiveDuration / 1000)}s inactivity`)
|
||||
const currentSrc = newTab.iframe.src
|
||||
newTab.iframe.src = 'about:blank'
|
||||
// Small delay to ensure reload
|
||||
setTimeout(() => {
|
||||
if (newTab.iframe) {
|
||||
newTab.iframe.src = currentSrc
|
||||
}
|
||||
}, 50)
|
||||
}
|
||||
|
||||
newTab.isVisible = true
|
||||
newTab.lastAccessed = Date.now()
|
||||
newTab.lastAccessed = now
|
||||
activeTabId.value = extensionId
|
||||
}
|
||||
}
|
||||
@ -113,8 +137,12 @@ export const useExtensionTabsStore = defineStore('extensionTabsStore', () => {
|
||||
}
|
||||
|
||||
const broadcastToAllTabs = (message: unknown) => {
|
||||
openTabs.value.forEach(({ iframe }) => {
|
||||
iframe?.contentWindow?.postMessage(message, '*')
|
||||
openTabs.value.forEach(({ extension }) => {
|
||||
// Use sandbox-compatible window reference
|
||||
const win = getExtensionWindow(extension.id)
|
||||
if (win) {
|
||||
win.postMessage(message, '*')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user