[🔨] Change apps list into array
This commit is contained in:
parent
22ecf8bf7b
commit
8b9e11183d
1 changed files with 23 additions and 14 deletions
37
src/flow.ts
37
src/flow.ts
|
|
@ -1,8 +1,7 @@
|
|||
import { Apps } from './types.ts'
|
||||
import { App } from './types.ts'
|
||||
|
||||
class Flow {
|
||||
apps: Apps = {}
|
||||
|
||||
apps: App[] = []
|
||||
appList = [
|
||||
'settings',
|
||||
'music',
|
||||
|
|
@ -20,7 +19,7 @@ class Flow {
|
|||
const app = new ImportedApp()
|
||||
|
||||
window.preloader.setStatus(`importing default apps\n${appPath}`)
|
||||
this.apps[app.pkg] = app
|
||||
this.add(app)
|
||||
}
|
||||
|
||||
window.wm.launcher.style.opacity = '0'
|
||||
|
|
@ -29,16 +28,16 @@ class Flow {
|
|||
|
||||
window.preloader.setStatus('adding apps to app launcher...')
|
||||
|
||||
for (const pkg in window.flow.apps) {
|
||||
window.preloader.setStatus(`adding apps to app launcher\n${window.flow.apps[pkg].name}`)
|
||||
const app = document.createElement('app')
|
||||
app.onclick = async () => {
|
||||
await window.flow.openApp(pkg)
|
||||
this.apps.forEach((app) => {
|
||||
window.preloader.setStatus(`adding apps to app launcher\n${app.name}`)
|
||||
const appElement = document.createElement('app')
|
||||
appElement.onclick = async () => {
|
||||
await window.flow.openApp(app.pkg)
|
||||
window.wm.toggleLauncher()
|
||||
}
|
||||
app.innerHTML = `<img src="${window.flow.apps[pkg].icon}"><div>${window.flow.apps[pkg].name}</div>`
|
||||
window.wm.launcher.querySelector('apps')?.appendChild(app)
|
||||
}
|
||||
appElement.innerHTML = `<img src="${app.icon}"><div>${app.name}</div>`
|
||||
window.wm.launcher.querySelector('apps')?.appendChild(appElement)
|
||||
})
|
||||
|
||||
document.body.appendChild(window.wm.windowArea)
|
||||
document.body.appendChild(window.wm.launcher)
|
||||
|
|
@ -46,9 +45,19 @@ class Flow {
|
|||
await window.preloader.setDone('apps')
|
||||
}
|
||||
|
||||
add (app: App): void {
|
||||
if (this.apps.some(x => x.pkg === app.pkg)) {
|
||||
console.error(`Unable to register app; ${app.pkg} is already registered.`)
|
||||
return
|
||||
}
|
||||
|
||||
this.apps.push(app)
|
||||
}
|
||||
|
||||
async openApp (pkg: string, data?: any): Promise<void> {
|
||||
const win = this.apps[pkg].open(data)
|
||||
const event = new CustomEvent('app_opened', { detail: { app: this.apps[pkg], win: await win } })
|
||||
const app = this.apps.find(x => x.pkg === pkg)
|
||||
const win = app?.open(data)
|
||||
const event = new CustomEvent('app_opened', { detail: { app, win: await win } })
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue