[🚑] Fixed FlowOS apps

This commit is contained in:
ThinLiquid 2023-12-06 02:10:07 +00:00 committed by GitHub
parent 1e05eaf7f4
commit df1fa6b268
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,17 +3,19 @@ import nullIcon from '../assets/icons/application-default-icon.svg'
class Flow {
apps: LoadedApp[] = []
appList: string[] = [
'../builtin/apps/settings.ts',
'../builtin/apps/music.ts',
'../builtin/apps/files.ts',
'../builtin/apps/editor.ts',
'../builtin/apps/info.ts',
'../builtin/apps/manager.ts',
'../builtin/apps/browser.ts',
'../builtin/apps/store.ts'
defaultAppList: string[] = [
'settings',
'music',
'files',
'editor',
'info',
'manager',
'browser',
'store'
]
appList: string[] = []
plugins: LoadedPlugin[] = []
pluginList: string[] = []
@ -22,17 +24,22 @@ class Flow {
*/
private async initApps (): Promise<void> {
window.preloader.setPending('apps')
window.preloader.setStatus('importing default apps...')
window.preloader.setStatus('importing apps...')
await (await window.fs.promises.readdir('/Applications')).forEach((file) => {
window.fs.promises.readFile('/Applications/' + file).then(content => {
this.appList.push(`data:text/javascript;base64,${btoa(content.toString())}`)
}).catch(console.error)
window.fs.exists('/Applications', (exists) => {
if (!exists) window.fs.promises.mkdir('/Applications').catch(e => console.error(e))
window.fs.promises.readdir('/Applications').then((list) => {
list.forEach((file) => {
window.fs.promises.readFile('/Applications/' + file).then(content => {
this.appList.push(`data:text/javascript;base64,${btoa(content.toString())}`)
}).catch((e) => console.error(e))
})
}).catch(e => console.error(e))
})
for (const appPath of this.appList) {
for (const appPath of this.defaultAppList) {
window.preloader.setStatus(`importing default apps\n${appPath}`)
const { default: ImportedApp } = await import(`${appPath}`).catch(async (e: Error) => {
const { default: ImportedApp } = await import(`../builtin/apps/${appPath}.ts`).catch(async (e: Error) => {
console.error(e)
await window.preloader.setError('apps')
window.preloader.setStatus(`unable to import ${appPath}\n${e.name}: ${e.message}`)
@ -44,6 +51,23 @@ class Flow {
this.addApp(app)
}
if (this.appList.length > 0) {
for (const appPath of this.appList) {
window.preloader.setStatus(`importing appstore apps\n${appPath}`)
const { default: ImportedApp } = await import(/* @vite-ignore */ appPath).catch(async (e: Error) => {
console.error(e)
await window.preloader.setError('apps')
window.preloader.setStatus(`unable to import ${appPath}\n${e.name}: ${e.message}`)
})
const app = new ImportedApp()
app.builtin = false
app.meta.icon = app.meta.icon ?? nullIcon
this.addApp(app)
}
}
window.wm.launcher.style.opacity = '0'
window.wm.launcher.style.filter = 'blur(0px)'
window.wm.launcher.style.pointerEvents = 'none'