Skip to content

Commit 1f8d7d1

Browse files
authored
Merge branch 'Acode-Foundation:main' into patch-6
2 parents 6ccabff + 00adec3 commit 1f8d7d1

6 files changed

Lines changed: 130 additions & 21 deletions

File tree

config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
<preference name="AndroidLaunchMode" value="singleTask" />
3333
<preference name="prerendered-icon" value="false" />
3434
<preference name="androidxEnabled" value="true" />
35+
<preference name="GradlePluginKotlinEnabled" value="true" />
3536
<preference name="android-targetSdkVersion" value="35" />
3637

37-
38+
3839
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
3940
<application android:networkSecurityConfig="@xml/network_security_config" />
4041
<application android:hardwareAccelerated="true" />

src/lib/acode.js

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ import KeyboardEvent from "utils/keyboardEvent";
4545
import Url from "utils/Url";
4646
import constants from "./constants";
4747

48+
const { Fold } = ace.require("ace/edit_session/fold");
49+
const { Range } = ace.require("ace/range");
50+
4851
export default class Acode {
4952
#modules = {};
5053
#pluginsInit = {};
@@ -475,19 +478,28 @@ export default class Acode {
475478

476479
async format(selectIfNull = true) {
477480
const file = editorManager.activeFile;
481+
if (!file?.session) return;
482+
478483
const name = (file.session.getMode().$id || "").split("/").pop();
479484
const formatterId = appSettings.value.formatter[name];
480485
const formatter = this.#formatter.find(({ id }) => id === formatterId);
481486

482-
await formatter?.format();
483-
484-
if (!formatter && selectIfNull) {
487+
if (!formatter) {
488+
if (!selectIfNull) {
489+
toast(strings["please select a formatter"]);
490+
return;
491+
}
485492
formatterSettings(name);
486493
this.#afterSelectFormatter(name);
487494
return;
488495
}
489-
if (!formatter && !selectIfNull) {
490-
toast(strings["please select a formatter"]);
496+
497+
const foldsSnapshot = this.#captureFoldState(file.session);
498+
499+
try {
500+
await formatter.format();
501+
} finally {
502+
this.#restoreFoldState(file.session, foldsSnapshot);
491503
}
492504
}
493505

@@ -506,6 +518,77 @@ export default class Acode {
506518
return fsOperation(file);
507519
}
508520

521+
#captureFoldState(session) {
522+
if (!session?.getAllFolds) return null;
523+
return this.#serializeFolds(session.getAllFolds());
524+
}
525+
526+
#restoreFoldState(session, folds) {
527+
if (!session || !Array.isArray(folds) || !folds.length) return;
528+
529+
try {
530+
const foldObjects = this.#parseSerializableFolds(folds);
531+
if (!foldObjects.length) return;
532+
session.removeAllFolds?.();
533+
session.addFolds?.(foldObjects);
534+
} catch (error) {
535+
console.warn("Failed to restore folds after formatting:", error);
536+
}
537+
}
538+
539+
#serializeFolds(folds) {
540+
if (!Array.isArray(folds) || !folds.length) return null;
541+
542+
return folds
543+
.map((fold) => {
544+
if (!fold?.range) return null;
545+
const { start, end } = fold.range;
546+
if (!start || !end) return null;
547+
548+
return {
549+
range: {
550+
start: { row: start.row, column: start.column },
551+
end: { row: end.row, column: end.column },
552+
},
553+
placeholder: fold.placeholder,
554+
ranges: this.#serializeFolds(fold.ranges || []),
555+
};
556+
})
557+
.filter(Boolean);
558+
}
559+
560+
#parseSerializableFolds(folds) {
561+
if (!Array.isArray(folds) || !folds.length) return [];
562+
563+
return folds
564+
.map((fold) => {
565+
const { range, placeholder, ranges } = fold;
566+
const { start, end } = range || {};
567+
if (!start || !end) return null;
568+
569+
try {
570+
const foldInstance = new Fold(
571+
new Range(start.row, start.column, end.row, end.column),
572+
placeholder,
573+
);
574+
575+
if (Array.isArray(ranges) && ranges.length) {
576+
const subFolds = this.#parseSerializableFolds(ranges);
577+
if (subFolds.length) {
578+
foldInstance.subFolds = subFolds;
579+
foldInstance.ranges = subFolds;
580+
}
581+
}
582+
583+
return foldInstance;
584+
} catch (error) {
585+
console.warn("Failed to parse fold:", error);
586+
return null;
587+
}
588+
})
589+
.filter(Boolean);
590+
}
591+
509592
newEditorFile(filename, options) {
510593
new EditorFile(filename, options);
511594
}

src/lib/settings.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,10 @@ class Settings {
185185
if (this.#initialized) return;
186186
this.settingsFile = Url.join(DATA_STORAGE, "settings.json");
187187

188-
if (!IS_FREE_VERSION) {
189-
this.#defaultSettings.appTheme = "system";
190-
this.#defaultSettings.editorTheme = getSystemEditorTheme(
191-
isDeviceDarkTheme(),
192-
);
193-
}
188+
this.#defaultSettings.appTheme = "system";
189+
this.#defaultSettings.editorTheme = getSystemEditorTheme(
190+
isDeviceDarkTheme(),
191+
);
194192

195193
this.#initialized = true;
196194

src/plugins/terminal/src/android/AlpineDocumentProvider.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Cursor queryRoots(String[] projection) {
6060
MatrixCursor result = new MatrixCursor(
6161
projection != null ? projection : DEFAULT_ROOT_PROJECTION
6262
);
63-
String applicationName = "Acode";
63+
String applicationName = getApplicationLabel();
6464

6565
MatrixCursor.RowBuilder row = result.newRow();
6666
row.add(DocumentsContract.Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR));
@@ -75,7 +75,7 @@ public Cursor queryRoots(String[] projection) {
7575
row.add(DocumentsContract.Root.COLUMN_TITLE, applicationName);
7676
row.add(DocumentsContract.Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
7777
row.add(DocumentsContract.Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace());
78-
row.add(DocumentsContract.Root.COLUMN_ICON, R.mipmap.ic_launcher);
78+
row.add(DocumentsContract.Root.COLUMN_ICON, resolveLauncherIcon());
7979
return result;
8080
}
8181

@@ -364,4 +364,22 @@ private static String getMimeType(File file) {
364364
return "application/octet-stream";
365365
}
366366
}
367+
private int resolveLauncherIcon() {
368+
Context context = getContext();
369+
if (context == null) return android.R.mipmap.sym_def_app_icon;
370+
int icon = context.getResources().getIdentifier("ic_launcher", "mipmap", context.getPackageName());
371+
return icon != 0 ? icon : android.R.mipmap.sym_def_app_icon;
372+
}
373+
374+
private String getApplicationLabel() {
375+
Context context = getContext();
376+
if (context == null) return "Acode";
377+
PackageManager pm = context.getPackageManager();
378+
try {
379+
CharSequence label = pm.getApplicationLabel(context.getApplicationInfo());
380+
return label != null ? label.toString() : "Acode";
381+
} catch (Exception ignored) {
382+
return "Acode";
383+
}
384+
}
367385
}

src/plugins/terminal/src/android/TerminalService.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import android.os.PowerManager;
1717
import android.os.RemoteException;
1818
import androidx.core.app.NotificationCompat;
19-
import com.foxdebug.acode.R;
2019
import java.io.BufferedReader;
2120
import java.io.IOException;
2221
import java.io.InputStream;
@@ -360,13 +359,15 @@ private void updateNotification() {
360359
String contentText = "Executor service" + (isWakeLockHeld ? " (wakelock held)" : "");
361360
String wakeLockButtonText = isWakeLockHeld ? "Release Wake Lock" : "Acquire Wake Lock";
362361

362+
int notificationIcon = resolveDrawableId("ic_notification", "ic_launcher_foreground", "ic_launcher");
363+
363364
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
364365
.setContentTitle("Acode Service")
365366
.setContentText(contentText)
366-
.setSmallIcon(R.drawable.ic_launcher_foreground)
367+
.setSmallIcon(notificationIcon)
367368
.setOngoing(true)
368-
.addAction(R.drawable.ic_launcher_foreground, wakeLockButtonText, wakeLockPendingIntent)
369-
.addAction(R.drawable.ic_launcher_foreground, "Exit", exitPendingIntent)
369+
.addAction(notificationIcon, wakeLockButtonText, wakeLockPendingIntent)
370+
.addAction(notificationIcon, "Exit", exitPendingIntent)
370371
.build();
371372

372373
startForeground(1, notification);
@@ -390,4 +391,12 @@ public void onDestroy() {
390391
clientMessengers.clear();
391392
threadPool.shutdown();
392393
}
393-
}
394+
395+
private int resolveDrawableId(String... names) {
396+
for (String name : names) {
397+
int id = getResources().getIdentifier(name, "drawable", getPackageName());
398+
if (id != 0) return id;
399+
}
400+
return android.R.drawable.sym_def_app_icon;
401+
}
402+
}

utils/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const exec = promisify(require("node:child_process").exec);
8585
`cordova plugin add cordova-plugin-consent@2.4.0 --save`,
8686
);
8787
await exec(
88-
`cordova plugin add admob-plus-cordova@1.28.0 --save --variable APP_ID_ANDROID="${AD_APP_ID}" --variable PLAY_SERVICES_VERSION="21.5.0"`,
88+
`cordova plugin add admob-plus-cordova@2.0.0-alpha.19 --save --variable APP_ID_ANDROID="${AD_APP_ID}" --variable PLAY_SERVICES_VERSION="23.2.0"`,
8989
);
9090
console.log("DONE! Installing admob-plus-cordova");
9191
} else {
@@ -96,7 +96,7 @@ const exec = promisify(require("node:child_process").exec);
9696
}
9797

9898
console.log(`|--- Reinstalling platform ---|`);
99-
const { stderr } = await exec(`yarn clean`);
99+
const { stderr } = await exec(`npm run clean`);
100100
if (stderr) console.error(stderr);
101101
else console.log("DONE! Reinstalling platform");
102102
})(),

0 commit comments

Comments
 (0)