@@ -16,6 +16,7 @@ import constants from "./constants";
1616import EditorFile from "./editorFile" ;
1717import openFolder , { addedFolder } from "./openFolder" ;
1818import appSettings from "./settings" ;
19+ import path from "path-browserify" ;
1920
2021/**@type {Server } */
2122let webServer ;
@@ -259,6 +260,7 @@ async function run(
259260 if ( pathName ) {
260261 url = Url . join ( addedFolder [ 0 ] . url , reqPath ) ;
261262 file = editorManager . getFile ( url , "uri" ) ;
263+
262264 } else if ( ! activeFile . uri ) {
263265 file = activeFile ;
264266 }
@@ -495,10 +497,53 @@ async function run(
495497 * Opens the preview in browser
496498 */
497499 function openBrowser ( ) {
500+ console . log ( "Path name" , pathName ) ;
501+ console . log ( "Filename" , filename ) ;
502+
503+ //get the project url
504+ let rootFolder = addedFolder [ 0 ] . url
505+
506+ if ( rootFolder === "content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome" ) {
507+ rootFolder = "content://com.termux.documents/tree/%2Fdata%2Fdata%2Fcom.termux%2Ffiles%2Fhome::/data/data/com.termux/files/home/"
508+ }
509+
510+ //remove the project prefix from the file parent path name
511+ //this will give us the path relative to the project folder
498512 /** @type {string } */
499- const filePath = pathName + filename ;
500- let path = removePrefix ( removePrefix ( filePath , addedFolder [ 0 ] . url ) , "/" ) ;
513+ let filePath = removePrefix ( pathName , rootFolder )
514+
515+ if ( ! rootFolder . includes ( "::" ) ) {
516+ filePath = pathName . split ( "::" ) [ 1 ] ;
517+ }
518+
519+
520+ console . log ( "Root" , rootFolder )
521+ console . log ( "File parent" , pathName )
522+
523+ //add the filename to the path
524+ //this will give us the full path to the file relative to the project folder
525+ if ( filePath . endsWith ( "/" ) ) {
526+ filePath += filename ;
527+ } else {
528+ filePath = filePath + "/" + filename ;
529+ }
530+
531+ console . log ( addedFolder [ 0 ] )
532+
533+ console . log ( "File path" , filePath ) ;
534+
535+ let path = removePrefix ( removePrefix ( removePrefix ( filePath , rootFolder ) , "primary:" + addedFolder [ 0 ] . title ) , "/" )
536+
537+ //path = pathName.split("::")[0]+path
538+
539+
540+
541+ console . log ( "Path" , path ) ;
542+
543+
501544 const src = `http://localhost:${ port } /${ path } ` ;
545+
546+ console . log ( "Src" , src ) ;
502547 if ( target === "browser" ) {
503548 system . openInBrowser ( src ) ;
504549 return ;
0 commit comments