@@ -801,19 +801,19 @@ async function extractAndRegisterCapabilities(appId, content) {
801801 let parser = new DOMParser ( ) ;
802802 let doc = parser . parseFromString ( content , "text/html" ) ;
803803
804- let metaTag = doc . querySelector ( 'meta[name="capabilities"]' ) ;
804+ const el = doc . querySelector ( 'script[type="application/json"][data-for="ntxSetup"]' )
805+ const setupScriptData = el ? JSON . parse ( el . textContent ) : false ;
805806 let capabilities = [ ] ;
806- if ( metaTag ) {
807- capabilities = metaTag . getAttribute ( "content" ) . split ( ',' ) . map ( s => s . trim ( ) ) ;
808- } else {
809- console . log ( `No capabilities: ${ appId } ` ) ;
807+ if ( setupScriptData ) {
808+ capabilities = setupScriptData [ "capabilities" ] ;
810809 }
810+
811811 let onlyDefPerms = false ;
812812 let totalperms = [ 'utility' , 'sysUI' ] ;
813- let metaTag2 = doc . querySelector ( 'meta[name= "permissions"]' ) ;
813+ let permsRegAvble = setupScriptData [ "permissions" ] ?. length > 0 ;
814814 let requestedperms = [ ] ;
815- if ( metaTag2 ) {
816- requestedperms = metaTag2 . getAttribute ( "content" ) . split ( ',' ) . map ( s => s . trim ( ) ) ;
815+ if ( permsRegAvble ) {
816+ requestedperms = setupScriptData [ "permissions" ] . map ( s => s . trim ( ) ) ;
817817 } else {
818818 console . log ( `No permissions: ${ appId } ` ) ;
819819 onlyDefPerms = true
@@ -832,6 +832,7 @@ async function extractAndRegisterCapabilities(appId, content) {
832832 onlyDefPerms = ( onlyDefPerms ) ? true : arraysEqualIgnoreOrder ( requestedperms , totalperms ) ;
833833
834834 let permissions = Array . from ( new Set ( [ ...totalperms , ...requestedperms ] ) ) ;
835+ let specialsFlags = setupScriptData [ "special-features" ] ;
835836
836837 if ( ! onlyDefPerms ) {
837838 let modal = gid ( "AppInstDia" ) ;
@@ -840,25 +841,21 @@ async function extractAndRegisterCapabilities(appId, content) {
840841 gid ( "app_inst_mod_app_name" ) . innerText = appName ;
841842 let listelement = gid ( "app_inst_mod_li" ) ;
842843 listelement . innerHTML = '' ;
843- if ( capabilities . length > 0 ) {
844- let handlerList = capabilities . filter ( c => ! c . startsWith ( '.' ) && c !== 'onStartup' ) . join ( ', ' ) ;
845- if ( handlerList ) {
846- let span = document . createElement ( "li" ) ;
847- span . innerHTML = `Function as ${ handlerList } ` ;
848- listelement . appendChild ( span ) ;
849- }
850-
851- let fileTypes = capabilities . filter ( c => c . startsWith ( '.' ) ) . join ( ', ' ) ;
844+ if ( capabilities ?. length > 0 ) {
845+ let fileTypes = capabilities . join ( ', ' ) ;
852846 if ( fileTypes ) {
853847 let span = document . createElement ( "li" ) ;
854848 span . innerHTML = `Open ${ fileTypes } by default` ;
855849 listelement . appendChild ( span ) ;
856850 }
857851
858- if ( capabilities . includes ( 'onStartup' ) ) {
859- let span = document . createElement ( "li" ) ;
860- span . innerHTML = "Run during startup" ;
861- listelement . appendChild ( span ) ;
852+ if ( specialsFlags ) {
853+ if ( specialsFlags . includes ( "onStartup" ) ) {
854+
855+ let span = document . createElement ( "li" ) ;
856+ span . innerHTML = "Run during startup" ;
857+ listelement . appendChild ( span ) ;
858+ }
862859 }
863860 }
864861
@@ -908,7 +905,7 @@ async function extractAndRegisterCapabilities(appId, content) {
908905 totalperms . push ( perm ) ;
909906 }
910907 } ) ;
911- await registerApp ( appId , capabilities ) ;
908+ await registerApp ( appId , capabilities , specialsFlags ) ;
912909
913910 let registry = { } ;
914911 registry . perms = totalperms ;
@@ -918,28 +915,31 @@ async function extractAndRegisterCapabilities(appId, content) {
918915 console . error ( "Error extracting and registering capabilities:" , error ) ;
919916 }
920917}
921- async function registerApp ( appId , capabilities ) {
922- for ( let rawCapability of capabilities ) {
923- let capability = rawCapability . trim ( ) ;
924- if ( capability === 'onStartup' ) continue ;
925- if ( capability . startsWith ( '.' ) ) {
926- fileTypeAssociations [ capability ] = [ appId ] ;
927- } else {
928- handlers [ capability ] = appId ;
918+ async function registerApp ( appId , capabilities , specialsFlags ) {
919+ if ( capabilities ?. length ) {
920+ for ( let rawCapability of capabilities ) {
921+ let capability = rawCapability . trim ( ) ;
922+ if ( capability . startsWith ( '.' ) ) {
923+ fileTypeAssociations [ capability ] = [ appId ] ;
924+ } else {
925+ handlers [ capability ] = appId ;
926+ }
929927 }
930928 }
929+
931930 await setSetting ( 'fileTypeAssociations' , fileTypeAssociations ) ;
932- await setSetting ( 'handlers' , handlers ) ;
933931
934- if ( capabilities . includes ( 'onStartup' ) ) {
935- let startupApps = await getSetting ( 'RunOnStartup' ) || [ ] ;
936- if ( ! startupApps . includes ( appId ) ) startupApps . push ( appId ) ;
937- await setSetting ( 'RunOnStartup' , startupApps ) ;
932+ if ( specialsFlags ) {
933+ if ( specialsFlags . includes ( "onStartup" ) ) {
934+ let startupApps = await getSetting ( 'RunOnStartup' ) || [ ] ;
935+ if ( ! startupApps . includes ( appId ) ) startupApps . push ( appId ) ;
936+ await setSetting ( 'RunOnStartup' , startupApps ) ;
937+ }
938938 }
939939
940940 if ( ! initialization )
941- notify ( await getFileNameByID ( appId ) + " installed" , "Registered " + capabilities . toString ( ) , "NovaOS System" ) ;
942- return capabilities . toString ( ) ;
941+ notify ( await getFileNameByID ( appId ) + " installed" , "Now handles " + capabilities ? .toString ( ) , "NovaOS System" ) ;
942+ return capabilities ? .toString ( ) || "" ;
943943}
944944
945945async function cleanupInvalidAssociations ( ) {
0 commit comments