[🔨] 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 {
|
class Flow {
|
||||||
apps: Apps = {}
|
apps: App[] = []
|
||||||
|
|
||||||
appList = [
|
appList = [
|
||||||
'settings',
|
'settings',
|
||||||
'music',
|
'music',
|
||||||
|
|
@ -20,7 +19,7 @@ class Flow {
|
||||||
const app = new ImportedApp()
|
const app = new ImportedApp()
|
||||||
|
|
||||||
window.preloader.setStatus(`importing default apps\n${appPath}`)
|
window.preloader.setStatus(`importing default apps\n${appPath}`)
|
||||||
this.apps[app.pkg] = app
|
this.add(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.wm.launcher.style.opacity = '0'
|
window.wm.launcher.style.opacity = '0'
|
||||||
|
|
@ -29,16 +28,16 @@ class Flow {
|
||||||
|
|
||||||
window.preloader.setStatus('adding apps to app launcher...')
|
window.preloader.setStatus('adding apps to app launcher...')
|
||||||
|
|
||||||
for (const pkg in window.flow.apps) {
|
this.apps.forEach((app) => {
|
||||||
window.preloader.setStatus(`adding apps to app launcher\n${window.flow.apps[pkg].name}`)
|
window.preloader.setStatus(`adding apps to app launcher\n${app.name}`)
|
||||||
const app = document.createElement('app')
|
const appElement = document.createElement('app')
|
||||||
app.onclick = async () => {
|
appElement.onclick = async () => {
|
||||||
await window.flow.openApp(pkg)
|
await window.flow.openApp(app.pkg)
|
||||||
window.wm.toggleLauncher()
|
window.wm.toggleLauncher()
|
||||||
}
|
}
|
||||||
app.innerHTML = `<img src="${window.flow.apps[pkg].icon}"><div>${window.flow.apps[pkg].name}</div>`
|
appElement.innerHTML = `<img src="${app.icon}"><div>${app.name}</div>`
|
||||||
window.wm.launcher.querySelector('apps')?.appendChild(app)
|
window.wm.launcher.querySelector('apps')?.appendChild(appElement)
|
||||||
}
|
})
|
||||||
|
|
||||||
document.body.appendChild(window.wm.windowArea)
|
document.body.appendChild(window.wm.windowArea)
|
||||||
document.body.appendChild(window.wm.launcher)
|
document.body.appendChild(window.wm.launcher)
|
||||||
|
|
@ -46,9 +45,19 @@ class Flow {
|
||||||
await window.preloader.setDone('apps')
|
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> {
|
async openApp (pkg: string, data?: any): Promise<void> {
|
||||||
const win = this.apps[pkg].open(data)
|
const app = this.apps.find(x => x.pkg === pkg)
|
||||||
const event = new CustomEvent('app_opened', { detail: { app: this.apps[pkg], win: await win } })
|
const win = app?.open(data)
|
||||||
|
const event = new CustomEvent('app_opened', { detail: { app, win: await win } })
|
||||||
window.dispatchEvent(event)
|
window.dispatchEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue