11const { HLWrite } = require ( "../filesystem/hl_operations/hl_write" ) ;
22const { LLMkdir } = require ( "../filesystem/ll_operations/ll_mkdir" ) ;
33const { LLRead } = require ( "../filesystem/ll_operations/ll_read" ) ;
4- const { NodePathSelector, NodeChildSelector , RootNodeSelector } = require ( "../filesystem/node/selectors" ) ;
4+ const { NodePathSelector } = require ( "../filesystem/node/selectors" ) ;
55const { Endpoint } = require ( "../util/expressutil" ) ;
66const { buffer_to_stream } = require ( "../util/streamutil" ) ;
77const BaseService = require ( "./BaseService" ) ;
88
99const ICON_SIZES = [ 16 , 32 , 64 , 128 , 256 , 512 ] ;
1010
11+ /**
12+ * AppIconService handles icon generation and serving for apps.
13+ *
14+ * This is done by listening to the `app.new-icon` event which is
15+ * dispatched by AppES. `sharp` is used to resize the images to
16+ * pre-selected sizees in the `ICON_SIZES` constant defined above.
17+ *
18+ * Icons are stored in and served from the `/system/app_icons`
19+ * directory. If the system user does not have this directory,
20+ * it will be created in the consolidation boot phase after
21+ * UserService emits the `user.system-user-ready` event on the
22+ * service container event bus.
23+ */
1124class AppIconService extends BaseService {
1225 static MODULES = {
1326 sharp : require ( 'sharp' ) ,
1427 }
1528
29+ /**
30+ * AppIconService listens to this event to register the
31+ * endpoint /app-icon/:app_uid/:size which serves the
32+ * app icon at the requested size.
33+ */
1634 async [ '__on_install.routes' ] ( _ , { app } ) {
1735 Endpoint ( {
1836 route : '/app-icon/:app_uid/:size' ,
@@ -46,6 +64,10 @@ class AppIconService extends BaseService {
4664 } ) . attach ( app ) ;
4765 }
4866
67+ /**
68+ * Returns an FSNodeContext instance for the app icons
69+ * directory.
70+ */
4971 async get_app_icons ( ) {
5072 if ( this . dir_app_icons ) {
5173 return this . dir_app_icons ;
@@ -59,6 +81,11 @@ class AppIconService extends BaseService {
5981 this . dir_app_icons = dir_app_icons ;
6082 }
6183
84+ /**
85+ * AppIconService listens to this event to create the
86+ * `/system/app_icons` directory if it does not exist,
87+ * and then to register the event listener for `app.new-icon`.
88+ */
6289 async [ '__on_user.system-user-ready' ] ( ) {
6390 const svc_su = this . services . get ( 'su' ) ;
6491 const svc_fs = this . services . get ( 'filesystem' ) ;
@@ -83,14 +110,6 @@ class AppIconService extends BaseService {
83110 // Listen for new app icons
84111 const svc_event = this . services . get ( 'event' ) ;
85112 svc_event . on ( 'app.new-icon' , async ( _ , data ) => {
86- // for ( let i=0; i < 10; i++ ) {
87- // console.log('\x1B[36;1m--- app icon ---\x1B[0m');
88- // }
89- // console.log('INFO', {
90- // event: 'app.new-icon',
91- // uid: data.app_uid,
92- // });
93-
94113 // Writing icons as the system user
95114 const icon_jobs = [ ] ;
96115 for ( const size of ICON_SIZES ) {
0 commit comments