Skip to content

Commit 3dde89a

Browse files
fix. support internal storage and termux
1 parent 4298564 commit 3dde89a

File tree

3 files changed

+124
-55
lines changed

3 files changed

+124
-55
lines changed

package-lock.json

Lines changed: 76 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@types/url-parse": "^1.4.11",
6262
"autoprefixer": "^10.4.19",
6363
"babel-loader": "^9.1.3",
64-
"cordova-android": "^13.0.0",
64+
"cordova-android": "^14.0.0",
6565
"cordova-clipboard": "^1.3.0",
6666
"cordova-plugin-advanced-http": "^3.3.1",
6767
"cordova-plugin-browser": "file:src/plugins/browser",

src/lib/run.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import constants from "./constants";
1616
import EditorFile from "./editorFile";
1717
import openFolder, { addedFolder } from "./openFolder";
1818
import appSettings from "./settings";
19+
import path from "path-browserify";
1920

2021
/**@type {Server} */
2122
let 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

Comments
 (0)