@@ -3,17 +3,19 @@ import nullIcon from '../assets/icons/application-default-icon.svg'
3
3
4
4
class Flow {
5
5
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'
15
15
]
16
16
17
+ appList : string [ ] = [ ]
18
+
17
19
plugins : LoadedPlugin [ ] = [ ]
18
20
pluginList : string [ ] = [ ]
19
21
@@ -22,17 +24,22 @@ class Flow {
22
24
*/
23
25
private async initApps ( ) : Promise < void > {
24
26
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 ) )
31
38
} )
32
39
33
- for ( const appPath of this . appList ) {
40
+ for ( const appPath of this . defaultAppList ) {
34
41
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 ) => {
36
43
console . error ( e )
37
44
await window . preloader . setError ( 'apps' )
38
45
window . preloader . setStatus ( `unable to import ${ appPath } \n${ e . name } : ${ e . message } ` )
@@ -44,6 +51,23 @@ class Flow {
44
51
this . addApp ( app )
45
52
}
46
53
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
+
47
71
window . wm . launcher . style . opacity = '0'
48
72
window . wm . launcher . style . filter = 'blur(0px)'
49
73
window . wm . launcher . style . pointerEvents = 'none'
0 commit comments