Merge pull request #119 from Flow-Works/dev

[] Added better error handling at boot
This commit is contained in:
ThinLiquid 2024-01-10 14:01:26 +00:00 committed by GitHub
commit bd846cd028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,6 +31,8 @@ class Flow {
window.fs.promises.readdir('/Applications').then((list) => { window.fs.promises.readdir('/Applications').then((list) => {
list.forEach((file) => { list.forEach((file) => {
window.fs.promises.readFile('/Applications/' + file).then(content => { window.fs.promises.readFile('/Applications/' + file).then(content => {
if (!content.toString().endsWith('.js')) return
if (content.toString() === '') return
this.appList.push(`data:text/javascript;base64,${btoa(content.toString())}`) this.appList.push(`data:text/javascript;base64,${btoa(content.toString())}`)
}).catch((e) => console.error(e)) }).catch((e) => console.error(e))
}) })
@ -55,16 +57,18 @@ class Flow {
for (const appPath of this.appList) { for (const appPath of this.appList) {
window.preloader.setStatus(`importing appstore apps\n${appPath}`) window.preloader.setStatus(`importing appstore apps\n${appPath}`)
const { default: ImportedApp } = await import(/* @vite-ignore */ appPath).catch(async (e: Error) => { try {
const { default: ImportedApp } = await import(appPath)
const app = new ImportedApp()
app.builtin = false
app.meta.icon = app.meta.icon ?? nullIcon
this.addApp(app)
} catch (e: any) {
console.error(e) console.error(e)
await window.preloader.setError('apps') await window.preloader.setError('apps')
window.preloader.setStatus(`unable to import ${appPath}\n${e.name}: ${e.message}`) window.preloader.setStatus(`unable to import ${appPath}\n${(e as Error).name}: ${(e as Error).message}`)
}) }
const app = new ImportedApp()
app.builtin = false
app.meta.icon = app.meta.icon ?? nullIcon
this.addApp(app)
} }
} }