Skip to content

Commit

Permalink
Merge pull request #89 from Flow-Works/88-fix-flowos-apps
Browse files Browse the repository at this point in the history
[🚑] Fixed FlowOS apps
  • Loading branch information
ThinLiquid authored Dec 6, 2023
2 parents 1e05eaf + df1fa6b commit 9a3a611
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions src/instances/Flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []

Expand All @@ -22,17 +24,22 @@ class Flow {
*/
private async initApps (): Promise<void> {
window.preloader.setPending('apps')
window.preloader.setStatus('importing default 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.preloader.setStatus('importing apps...')

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}`)
Expand All @@ -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'
Expand Down

1 comment on commit 9a3a611

@vercel
Copy link

@vercel vercel bot commented on 9a3a611 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.