Skip to content

Commit 9a3a611

Browse files
authored
Merge pull request #89 from Flow-Works/88-fix-flowos-apps
[🚑] Fixed FlowOS apps
2 parents 1e05eaf + df1fa6b commit 9a3a611

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

src/instances/Flow.ts

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import nullIcon from '../assets/icons/application-default-icon.svg'
33

44
class Flow {
55
apps: LoadedApp[] = []
6-
appList: string[] = [
7-
'../builtin/apps/settings.ts',
8-
'../builtin/apps/music.ts',
9-
'../builtin/apps/files.ts',
10-
'../builtin/apps/editor.ts',
11-
'../builtin/apps/info.ts',
12-
'../builtin/apps/manager.ts',
13-
'../builtin/apps/browser.ts',
14-
'../builtin/apps/store.ts'
6+
defaultAppList: string[] = [
7+
'settings',
8+
'music',
9+
'files',
10+
'editor',
11+
'info',
12+
'manager',
13+
'browser',
14+
'store'
1515
]
1616

17+
appList: string[] = []
18+
1719
plugins: LoadedPlugin[] = []
1820
pluginList: string[] = []
1921

@@ -22,17 +24,22 @@ class Flow {
2224
*/
2325
private async initApps (): Promise<void> {
2426
window.preloader.setPending('apps')
25-
window.preloader.setStatus('importing default apps...')
26-
27-
await (await window.fs.promises.readdir('/Applications')).forEach((file) => {
28-
window.fs.promises.readFile('/Applications/' + file).then(content => {
29-
this.appList.push(`data:text/javascript;base64,${btoa(content.toString())}`)
30-
}).catch(console.error)
27+
window.preloader.setStatus('importing apps...')
28+
29+
window.fs.exists('/Applications', (exists) => {
30+
if (!exists) window.fs.promises.mkdir('/Applications').catch(e => console.error(e))
31+
window.fs.promises.readdir('/Applications').then((list) => {
32+
list.forEach((file) => {
33+
window.fs.promises.readFile('/Applications/' + file).then(content => {
34+
this.appList.push(`data:text/javascript;base64,${btoa(content.toString())}`)
35+
}).catch((e) => console.error(e))
36+
})
37+
}).catch(e => console.error(e))
3138
})
3239

33-
for (const appPath of this.appList) {
40+
for (const appPath of this.defaultAppList) {
3441
window.preloader.setStatus(`importing default apps\n${appPath}`)
35-
const { default: ImportedApp } = await import(`${appPath}`).catch(async (e: Error) => {
42+
const { default: ImportedApp } = await import(`../builtin/apps/${appPath}.ts`).catch(async (e: Error) => {
3643
console.error(e)
3744
await window.preloader.setError('apps')
3845
window.preloader.setStatus(`unable to import ${appPath}\n${e.name}: ${e.message}`)
@@ -44,6 +51,23 @@ class Flow {
4451
this.addApp(app)
4552
}
4653

54+
if (this.appList.length > 0) {
55+
for (const appPath of this.appList) {
56+
window.preloader.setStatus(`importing appstore apps\n${appPath}`)
57+
58+
const { default: ImportedApp } = await import(/* @vite-ignore */ appPath).catch(async (e: Error) => {
59+
console.error(e)
60+
await window.preloader.setError('apps')
61+
window.preloader.setStatus(`unable to import ${appPath}\n${e.name}: ${e.message}`)
62+
})
63+
const app = new ImportedApp()
64+
app.builtin = false
65+
app.meta.icon = app.meta.icon ?? nullIcon
66+
67+
this.addApp(app)
68+
}
69+
}
70+
4771
window.wm.launcher.style.opacity = '0'
4872
window.wm.launcher.style.filter = 'blur(0px)'
4973
window.wm.launcher.style.pointerEvents = 'none'

0 commit comments

Comments
 (0)