Skip to content

Commit 8e27bfd

Browse files
feat: native zip
1 parent 3420c70 commit 8e27bfd

17 files changed

Lines changed: 1321 additions & 184 deletions

package-lock.json

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"com.foxdebug.acode.rk.exec.proot": {},
4545
"cordova-plugin-iap": {},
4646
"com.foxdebug.acode.rk.customtabs": {},
47-
"cordova-plugin-system": {}
47+
"cordova-plugin-system": {},
48+
"com.foxdebug.acode.rk.zip": {}
4849
},
4950
"platforms": [
5051
"android"
@@ -98,6 +99,7 @@
9899
"cordova-plugin-system": "file:src/plugins/system",
99100
"cordova-plugin-websocket": "file:src/plugins/websocket",
100101
"css-loader": "^7.1.4",
102+
"JsZip-Java": "file:src/plugins/jszip-java",
101103
"mini-css-extract-plugin": "^2.10.2",
102104
"path-browserify": "^1.0.1",
103105
"postcss-loader": "^8.2.1",

src/lib/editorFile.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,8 +1285,9 @@ export default class EditorFile {
12851285
/**
12861286
* Sets syntax highlighting of the file.
12871287
* @param {string} [mode]
1288+
* @param {{ recommend?: boolean }} [options]
12881289
*/
1289-
setMode(mode) {
1290+
setMode(mode, options = {}) {
12901291
if (this.type !== "editor") return;
12911292
const event = createFileEvent(this);
12921293
this.#emit("changemode", event);
@@ -1309,7 +1310,9 @@ export default class EditorFile {
13091310
// Store mode info for later use when creating editor view
13101311
this.currentMode = mode;
13111312
this.currentLanguageExtension = modeInfo?.getExtension() || null;
1312-
maybeRecommendLanguageModeExtension(this, modeInfo);
1313+
if (options.recommend !== false) {
1314+
maybeRecommendLanguageModeExtension(this, modeInfo);
1315+
}
13131316

13141317
// sets file icon
13151318
this.#tab.lead(

src/lib/editorManager.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,7 @@ async function EditorManager($header, $body) {
17461746
editor,
17471747
readOnlyCompartment,
17481748
getFile,
1749+
reapplyActiveFile,
17491750
switchFile,
17501751
moveFileByPinnedState,
17511752
normalizePinnedTabOrder,
@@ -2944,6 +2945,12 @@ async function EditorManager($header, $body) {
29442945
toggleProblemButton();
29452946
}
29462947

2948+
function reapplyActiveFile() {
2949+
const file = manager.activeFile;
2950+
if (!file || file.type !== "editor" || !file.loaded || file.loading) return;
2951+
applyFileToEditor(file, { forceRecreate: true });
2952+
}
2953+
29472954
/**
29482955
* Initializes the file tab container.
29492956
*/

src/lib/installPlugin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import alert from "dialogs/alert";
33
import confirm from "dialogs/confirm";
44
import loader from "dialogs/loader";
55
import purchaseListener from "handlers/purchase";
6-
import JSZip from "jszip";
76
import helpers from "utils/helpers";
87
import Url from "utils/Url";
98
import config from "./config";
@@ -101,7 +100,7 @@ export default async function installPlugin(
101100
}
102101

103102
if (plugin) {
104-
const zip = new JSZip();
103+
const zip = new window.JSZip();
105104
await zip.loadAsync(plugin);
106105

107106
if (!zip.files["plugin.json"]) {

src/lib/languageModeRecommendations.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getModeForPath } from "cm/modelist";
12
import notificationManager from "lib/notificationManager";
23
import Path from "utils/Path";
34
import Url from "utils/Url";
@@ -98,9 +99,9 @@ class LanguageModeRecommendations {
9899
}
99100

100101
this.pendingKeywords.add(keyword);
101-
void this.showRecommendation(keyword)
102-
.then(() => {
103-
this.notifiedKeywords.add(keyword);
102+
void this.showRecommendation(keyword, filename)
103+
.then((shown) => {
104+
if (shown) this.notifiedKeywords.add(keyword);
104105
})
105106
.catch((error) => {
106107
console.warn("Failed to show extension recommendation.", error);
@@ -110,8 +111,12 @@ class LanguageModeRecommendations {
110111
});
111112
}
112113

113-
async showRecommendation(keyword) {
114+
async showRecommendation(keyword, filename) {
114115
const hasPlugins = await this.getPluginAvailability(keyword);
116+
// If a plugin registered the mode while the lookup was pending, suppress
117+
// this stale recommendation and leave the keyword eligible for future checks.
118+
if (!hasPlainTextFallback(getModeForPath(filename), filename)) return false;
119+
115120
const displayExt = `.${keyword}`;
116121

117122
if (hasPlugins) {
@@ -135,7 +140,7 @@ class LanguageModeRecommendations {
135140
},
136141
],
137142
});
138-
return;
143+
return true;
139144
}
140145

141146
const issueUrl = getIssueUrl(keyword);
@@ -159,6 +164,7 @@ class LanguageModeRecommendations {
159164
},
160165
],
161166
});
167+
return true;
162168
}
163169
}
164170

src/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ async function onDeviceReady() {
295295

296296
// Re-emit events for active file after plugins are loaded
297297
const { activeFile } = editorManager;
298+
for (const file of editorManager.files) {
299+
if (file?.type === "editor") {
300+
file.setMode(undefined, { recommend: false });
301+
}
302+
}
303+
editorManager.reapplyActiveFile();
298304
if (activeFile?.uri) {
299305
// Re-emit file-loaded event
300306
editorManager.emit("file-loaded", activeFile);

src/pages/fileBrowser/fileBrowser.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import confirm from "dialogs/confirm";
1212
import loader from "dialogs/loader";
1313
import prompt from "dialogs/prompt";
1414
import select from "dialogs/select";
15-
import JSZip from "jszip";
1615
import actionStack from "lib/actionStack";
1716
import checkFiles from "lib/checkFiles";
1817
import config from "lib/config";
@@ -302,7 +301,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
302301

303302
try {
304303
const zipContent = await fsOperation(zipFile).readFile();
305-
const zip = await JSZip.loadAsync(zipContent);
304+
const zip = await window.JSZip.loadAsync(zipContent);
306305
const targetDir = currentDir.url;
307306
const targetFs = fsOperation(targetDir);
308307

@@ -381,7 +380,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
381380
break;
382381
}
383382

384-
const zip = new JSZip();
383+
const zip = new window.JSZip();
385384
let loadingLoader = loader.create(
386385
strings["loading"],
387386
"Compressing files",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "native-zip",
3+
"version": "1.0.0",
4+
"description": "Zip utility",
5+
"cordova": {
6+
"id": "com.foxdebug.acode.rk.zip",
7+
"platforms": [
8+
"android"
9+
]
10+
},
11+
"keywords": [
12+
"ecosystem:cordova",
13+
"cordova-android"
14+
],
15+
"author": "@RohitKushvaha01",
16+
"license": "MIT"
17+
}

src/plugins/native-zip/plugin.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<plugin
3+
xmlns="http://apache.org/cordova/ns/plugins/1.0"
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
id="com.foxdebug.acode.rk.zip"
6+
version="1.0.0"
7+
>
8+
<name>NativeZip</name>
9+
10+
11+
<js-module name="NativeZip" src="www/NativeZip.js">
12+
<clobbers target="window.NativeZip" />
13+
</js-module>
14+
15+
16+
<platform name="android">
17+
<config-file parent="/*" target="res/xml/config.xml">
18+
<feature name="NativeZip">
19+
<param
20+
name="android-package"
21+
value="com.foxdebug.acode.rk.zip.NativeZip
22+
/>
23+
</feature>
24+
</config-file>
25+
26+
<source-file
27+
src="src/android/NativeZip.java"
28+
target-dir="src/com/foxdebug/acode/rk/zip"
29+
/>
30+
31+
</platform>
32+
</plugin>

0 commit comments

Comments
 (0)