@@ -125,17 +125,17 @@ async function run(
125125 }
126126
127127 function startConsole ( ) {
128- runConsole ( ) ;
129- start ( ) ;
130- }
131-
132- function runConsole ( ) {
133128 if ( ! isConsole ) EXECUTING_SCRIPT = activeFile . filename ;
134129 isConsole = true ;
135130 target = "inapp" ;
136131 filename = "console.html" ;
132+
133+ //this extra www is incorrect because asset_directory itself has www
134+ //but keeping it in case something depends on it
137135 pathName = `${ ASSETS_DIRECTORY } www/` ;
138136 port = constants . CONSOLE_PORT ;
137+
138+ start ( ) ;
139139 }
140140
141141 function start ( ) {
@@ -177,7 +177,6 @@ async function run(
177177 const reqId = req . requestId ;
178178 let reqPath = req . path . substring ( 1 ) ;
179179
180- console . log ( req ) ;
181180 if ( ! reqPath || ( reqPath . endsWith ( "/" ) && reqPath . length === 1 ) ) {
182181 reqPath = getRelativePath ( ) ;
183182 }
@@ -253,12 +252,12 @@ async function run(
253252 let file = activeFile . SAFMode === "single" ? activeFile : null ;
254253
255254 if ( pathName ) {
256- const projectFolder = addedFolder [ 0 ]
255+ const projectFolder = addedFolder [ 0 ] ;
257256
258257 //set the root folder to the file parent if no project folder is set
259258 let rootFolder = pathName ;
260259 if ( projectFolder !== undefined ) {
261- rootFolder = projectFolder . url
260+ rootFolder = projectFolder . url ;
262261 }
263262 const query = url . split ( "?" ) [ 1 ] ;
264263
@@ -536,15 +535,14 @@ async function run(
536535
537536 function getRelativePath ( ) {
538537 //get the project url
539- const projectFolder = addedFolder [ 0 ]
538+ const projectFolder = addedFolder [ 0 ] ;
540539
541540 //set the root folder to the file parent if no project folder is set
542541 let rootFolder = pathName ;
543542 if ( projectFolder !== undefined ) {
544- rootFolder = projectFolder . url
543+ rootFolder = projectFolder . url ;
545544 }
546545
547-
548546 //parent of the file
549547 let filePath = pathName ;
550548
@@ -557,7 +555,6 @@ async function run(
557555 "content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome::/data/data/com.termux/files/home/" ;
558556 }
559557
560-
561558 //remove the query string if present this is needs to be removed because the url is not valid
562559 if ( rootFolder . startsWith ( "ftp:" ) || rootFolder . startsWith ( "sftp:" ) ) {
563560 if ( rootFolder . includes ( "?" ) ) {
@@ -589,14 +586,12 @@ async function run(
589586 console . error ( e ) ;
590587 }
591588
592- console . log ( "rootFolder" , rootFolder ) ;
593- console . log ( "filePath" , temp ) ;
594-
595- if ( rootFolder . startsWith ( "content://com.android.externalstorage.documents" ) ) {
596- temp = filePath + "/" + filename ;
589+ if (
590+ rootFolder . startsWith ( "content://com.android.externalstorage.documents" )
591+ ) {
592+ temp = filePath + "/" + filename ;
597593 }
598594
599-
600595 //subtract the root folder from the file path to get relative path
601596 const path = removePrefix ( removePrefix ( temp , rootFolder ) , "/" ) ;
602597
@@ -607,16 +602,21 @@ async function run(
607602 * Opens the preview in browser
608603 */
609604 function openBrowser ( ) {
610- const path = getRelativePath ( ) ;
605+ let url = `http://localhost:${ port } /` ;
606+ if ( pathName . startsWith ( ASSETS_DIRECTORY ) ) {
607+ url += filename ;
608+ } else {
609+ url += getRelativePath ( ) ;
610+ }
611611
612- const src = `http://localhost: ${ port } / ${ path } ` ;
612+ console . log ( url ) ;
613613
614614 if ( target === "browser" ) {
615- system . openInBrowser ( src ) ;
615+ system . openInBrowser ( url ) ;
616616 return ;
617617 }
618618
619- browser . open ( src , isConsole ) ;
619+ browser . open ( url , isConsole ) ;
620620 }
621621}
622622
0 commit comments