Skip to content

Commit 68c5a44

Browse files
committed
rm comments
1 parent 76e949b commit 68c5a44

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

app/stores/app.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export const useAppStore = defineStore("app", () => {
6767
console.log(`[AppStore] Imported ${importedCount} stores`)
6868
}
6969

70-
// Extension loading system
7170
const loadedExtensions = ref(new Map())
7271
const extensionAPI = ref(null)
7372

@@ -77,7 +76,6 @@ export const useAppStore = defineStore("app", () => {
7776

7877
async function loadExtension(path) {
7978
try {
80-
// Check if already loaded by path
8179
if (loadedExtensions.value.has(path)) {
8280
console.warn(`[AppStore] Extension already loaded from this path: ${path}`)
8381
throw new Error('This extension file is already loaded')
@@ -89,32 +87,25 @@ export const useAppStore = defineStore("app", () => {
8987

9088
let finalURL = path
9189

92-
// For blob URLs, we need to rewrite imports to use available modules
9390
if (path.startsWith('blob:')) {
9491
const response = await fetch(path)
9592
let code = await response.text()
9693

97-
// Replace Vue imports - handle all patterns including multiline
9894
code = code.replace(
9995
/import\s+(?:{([^}]+)}|\*\s+as\s+(\w+)|(\w+))\s+from\s+["']vue["'];?/gs,
10096
(match, namedImports, namespaceImport, defaultImport) => {
10197
if (namedImports) {
102-
// Named imports: import { ref, computed } from 'vue'
103-
// Convert 'as' to ':' for object destructuring
10498
const converted = namedImports.replace(/\s+as\s+/g, ': ')
10599
return `const {${converted}} = window.__VUE_RUNTIME__;`
106100
} else if (namespaceImport) {
107-
// Namespace import: import * as Vue from 'vue'
108101
return `const ${namespaceImport} = window.__VUE_RUNTIME__;`
109102
} else if (defaultImport) {
110-
// Default import: import Vue from 'vue'
111103
return `const ${defaultImport} = window.__VUE_RUNTIME__;`
112104
}
113105
return match
114106
}
115107
)
116108

117-
// Replace Pinia imports
118109
code = code.replace(
119110
/import\s+(?:{([^}]+)}|\*\s+as\s+(\w+)|(\w+))\s+from\s+["']pinia["'];?/gs,
120111
(match, namedImports, namespaceImport, defaultImport) => {
@@ -130,34 +121,28 @@ export const useAppStore = defineStore("app", () => {
130121
}
131122
)
132123

133-
// Replace @geode/* imports - just comment them out for now
134124
code = code.replace(
135125
/import\s+[^;]+from\s+["']@geode\/[^"']+["'];?/gs,
136126
(match) => `/* ${match} */ // External dependency - resolved at runtime\n`
137127
)
138128

139-
// Replace @ogw_* imports
140129
code = code.replace(
141130
/import\s+[^;]+from\s+["']@ogw_[^"']+["'];?/gs,
142131
(match) => `/* ${match} */ // External dependency - resolved at runtime\n`
143132
)
144133

145134
console.log('[AppStore] Rewritten extension code preview:', code.substring(0, 800))
146135

147-
// Create new blob with rewritten code
148136
const newBlob = new Blob([code], { type: 'application/javascript' })
149137
finalURL = URL.createObjectURL(newBlob)
150138
}
151139

152-
// Dynamic import of the extension module
153-
const extensionModule = await import(/* @vite-ignore */ finalURL)
140+
const extensionModule = await import(finalURL)
154141

155-
// Clean up temporary blob URL
156142
if (finalURL !== path && finalURL.startsWith('blob:')) {
157143
URL.revokeObjectURL(finalURL)
158144
}
159145

160-
// Check for duplicate extension by name
161146
const extensionName = extensionModule.metadata?.name
162147
if (extensionName) {
163148
const alreadyLoaded = Array.from(loadedExtensions.value.values()).find(
@@ -169,17 +154,15 @@ export const useAppStore = defineStore("app", () => {
169154
}
170155
}
171156

172-
// Check if extension has an install function
173157
if (typeof extensionModule.install === 'function') {
174-
// Call install with the Extension API and the extension path
175158
await extensionModule.install(extensionAPI.value, path)
176159

177-
// Store the loaded extension
178160
const extensionData = {
179161
module: extensionModule,
180162
path,
181163
loadedAt: new Date().toISOString(),
182164
metadata: extensionModule.metadata || {},
165+
enabled: true,
183166
}
184167
loadedExtensions.value.set(path, extensionData)
185168

@@ -203,7 +186,6 @@ export const useAppStore = defineStore("app", () => {
203186
if (loadedExtensions.value.has(path)) {
204187
const extensionData = loadedExtensions.value.get(path)
205188

206-
// Call uninstall function if it exists
207189
if (extensionData.module && typeof extensionData.module.uninstall === 'function') {
208190
try {
209191
extensionData.module.uninstall(extensionAPI.value, path)
@@ -213,19 +195,44 @@ export const useAppStore = defineStore("app", () => {
213195
}
214196
}
215197

216-
// Clean up all tools registered by this extension
217198
if (extensionAPI.value) {
218199
extensionAPI.value.unregisterToolsByExtension(path)
219200
}
220201

221-
// Remove from loaded extensions
222202
loadedExtensions.value.delete(path)
223203
console.log(`[AppStore] Extension unloaded: ${path}`)
224204
return true
225205
}
226206
return false
227207
}
228208

209+
function toggleExtension(path) {
210+
if (loadedExtensions.value.has(path)) {
211+
const extensionData = loadedExtensions.value.get(path)
212+
extensionData.enabled = !extensionData.enabled
213+
console.log(`[AppStore] Extension ${extensionData.enabled ? 'enabled' : 'disabled'}: ${path}`)
214+
return extensionData.enabled
215+
}
216+
return false
217+
}
218+
219+
function setExtensionEnabled(path, enabled) {
220+
if (loadedExtensions.value.has(path)) {
221+
const extensionData = loadedExtensions.value.get(path)
222+
extensionData.enabled = enabled
223+
console.log(`[AppStore] Extension ${enabled ? 'enabled' : 'disabled'}: ${path}`)
224+
return true
225+
}
226+
return false
227+
}
228+
229+
function getExtensionEnabled(path) {
230+
if (loadedExtensions.value.has(path)) {
231+
return loadedExtensions.value.get(path).enabled
232+
}
233+
return false
234+
}
235+
229236
return {
230237
stores,
231238
registerStore,
@@ -236,5 +243,8 @@ export const useAppStore = defineStore("app", () => {
236243
loadExtension,
237244
getLoadedExtensions,
238245
unloadExtension,
246+
toggleExtension,
247+
setExtensionEnabled,
248+
getExtensionEnabled,
239249
}
240250
})

0 commit comments

Comments
 (0)