Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"cordova-plugin-system": {},
"cordova-plugin-advanced-http": {
"ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
}
},
"com.foxdebug.acode.exec": {}
},
"platforms": [
"android"
Expand All @@ -61,6 +62,7 @@
"@types/url-parse": "^1.4.11",
"autoprefixer": "^10.4.19",
"babel-loader": "^9.1.3",
"com.foxdebug.acode.exec": "file:src/plugins/Executor",
"cordova-android": "^13.0.0",
"cordova-clipboard": "^1.3.0",
"cordova-plugin-advanced-http": "^3.3.1",
Expand Down Expand Up @@ -113,4 +115,4 @@
"yargs": "^17.7.2"
},
"browserslist": "cover 100%,not android < 5"
}
}
2 changes: 1 addition & 1 deletion res/android/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<item name="windowSplashScreenBackground">@color/ic_splash_background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="windowSplashScreenAnimationDuration">200</item>
<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>
<item name="postSplashScreenTheme">@style/Theme.AppCompat.DayNight.NoActionBar</item>
</style>
</resources>
2 changes: 2 additions & 0 deletions src/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { keydownState } from "handlers/keyboard";
import { initFileList } from "lib/fileList";
import NotificationManager from "lib/notificationManager";
import { addedFolder } from "lib/openFolder";
import Executor from "plugins/Executor";
import { getEncoding, initEncodings } from "utils/encodings";
import auth, { loginEvents } from "./auth";
import constants from "./constants";
Expand Down Expand Up @@ -88,6 +89,7 @@ async function Main() {
async function onDeviceReady() {
await initEncodings(); // important to load encodings before anything else


const isFreePackage = /(free)$/.test(BuildInfo.packageName);
const oldResolveURL = window.resolveLocalFileSystemURL;
const {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import fsOperation from "fileSystem";
import ThemeBuilder from "theme/builder";
import themes from "theme/list";
import { getSystemEditorTheme } from "theme/preInstalled";
import Url from "utils/Url";
import helpers from "utils/helpers";
import constants from "./constants";
import lang from "./lang";
import { isDeviceDarkTheme } from "./systemConfiguration";

/**
* @typedef {object} fileBrowserSettings
Expand Down Expand Up @@ -182,8 +184,10 @@ class Settings {
this.settingsFile = Url.join(DATA_STORAGE, "settings.json");

if (!IS_FREE_VERSION) {
this.#defaultSettings.appTheme = "ocean";
this.#defaultSettings.editorTheme = "ace/theme/dracula";
this.#defaultSettings.appTheme = "system";
this.#defaultSettings.editorTheme = getSystemEditorTheme(
isDeviceDarkTheme(),
);
}

this.#initialized = true;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/systemConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ export function getSystemConfiguration() {
cordova.exec(resolve, reject, "System", "get-configuration", []);
});
}

export function isDeviceDarkTheme() {
return window.matchMedia("(prefers-color-scheme: dark)").matches;
}
36 changes: 36 additions & 0 deletions src/palettes/changeTheme/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "./style.scss";
import palette from "components/palette";
import appSettings from "lib/settings";
import { isDeviceDarkTheme } from "lib/systemConfiguration";
import themes from "theme/list";
import { updateSystemTheme } from "theme/preInstalled";

export default function changeTheme(type = "editor") {
palette(
Expand Down Expand Up @@ -56,11 +58,45 @@ function generateHints(type) {
});
}

let previousDark = isDeviceDarkTheme();
const updateTimeMs = 2000;

let intervalId = setInterval(async () => {
if (appSettings.value.appTheme.toLowerCase() === "system") {
const isDark = isDeviceDarkTheme();
if (isDark !== previousDark) {
previousDark = isDark;
updateSystemTheme(isDark);
}
}
}, updateTimeMs);

function onselect(value) {
if (!value) return;

const selection = JSON.parse(value);

if (selection.theme === "system") {
// Start interval if not already started
if (!intervalId) {
intervalId = setInterval(async () => {
if (appSettings.value.appTheme.toLowerCase() === "system") {
const isDark = isDeviceDarkTheme();
if (isDark !== previousDark) {
previousDark = isDark;
updateSystemTheme(isDark);
}
}
}, updateTimeMs);
}
} else {
// Cancel interval if it's running
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
}

if (selection.type === "editor") {
editorManager.editor.setTheme(selection.theme);
appSettings.update(
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/Executor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function exec(cmd,success,failure) {
const ACTION = 'exec';
cordova.exec(success, failure, 'Executor', ACTION, [cmd]);
}

export default {
exec,
};
17 changes: 17 additions & 0 deletions src/plugins/Executor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "com.foxdebug.acode.exec",
"version": "1.0.0",
"description": "Execute linux commands",
"cordova": {
"id": "com.foxdebug.acode.exec",
"platforms": [
"android"
]
},
"keywords": [
"ecosystem:cordova",
"cordova-android"
],
"author": "",
"license": "ISC"
}
2 changes: 2 additions & 0 deletions src/plugins/Executor/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="com.foxdebug.acode.exec" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"><name>Executor</name><js-module name="Executor" src="www/Executor.js"><clobbers target="cordova.plugins.Executor" /></js-module><platform name="android"><config-file parent="/*" target="res/xml/config.xml"><feature name="Executor"><param name="android-package" value="com.foxdebug.acode.exec.Executor" /></feature></config-file><config-file parent="/*" target="AndroidManifest.xml"></config-file><source-file src="src/android/Executor.java" target-dir="src/com/foxdebug/acode/exec/Executor" /></platform></plugin>
77 changes: 77 additions & 0 deletions src/plugins/Executor/src/android/Executor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.foxdebug.acode.exec;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Executor extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
if ("exec".equals(action)) {
try {
String cmd = args.getString(0);
exec(cmd, callbackContext);
} catch (JSONException e) {
callbackContext.error("Invalid arguments");
}
} else {
callbackContext.error("Unknown action");
}
}
});

return true;
}

private void exec(String cmd, CallbackContext callbackContext) {
try {
if (cmd != null && !cmd.isEmpty()) {
Process process = Runtime.getRuntime().exec(cmd);

// Capture stdout
BufferedReader stdOutReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder stdOut = new StringBuilder();
String line;
while ((line = stdOutReader.readLine()) != null) {
stdOut.append(line).append("\n");
}

// Capture stderr
BufferedReader stdErrReader = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
StringBuilder stdErr = new StringBuilder();
while ((line = stdErrReader.readLine()) != null) {
stdErr.append(line).append("\n");
}

int exitCode = process.waitFor();
if (exitCode == 0) {
callbackContext.success(stdOut.toString().trim());
} else {
// Return stderr if command fails
String errorOutput = stdErr.toString().trim();
if (errorOutput.isEmpty()) {
errorOutput = "Command exited with code: " + exitCode;
}
callbackContext.error(errorOutput);
}
} else {
callbackContext.error("Expected one non-empty string argument.");
}
} catch (Exception e) {
e.printStackTrace();
callbackContext.error("Exception: " + e.getMessage());
}
}

}
5 changes: 5 additions & 0 deletions src/plugins/Executor/www/Executor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var exec = require('cordova/exec');

exports.coolMethod = function (arg0, success, error) {
exec(success, error, 'Executor', 'coolMethod', [arg0]);
};
14 changes: 10 additions & 4 deletions src/theme/list.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import fsOperation from "fileSystem";
import { isDeviceDarkTheme } from "lib/systemConfiguration";
import Url from "utils/Url";
import color from "utils/color";
import fonts from "../lib/fonts";
import settings from "../lib/settings";
import ThemeBuilder from "./builder";
import themes from "./preInstalled";
import themes, { updateSystemTheme } from "./preInstalled";

/** @type {Map<string, ThemeBuilder>} */
const appThemes = new Map();
let themeApplied = false;

function init() {
themes.forEach((theme) => add(theme));
(async () => {
updateSystemTheme(isDeviceDarkTheme());
})();
}

/**
Expand Down Expand Up @@ -68,7 +72,7 @@ function add(theme) {
* @param {string} id The name of the theme to apply
* @param {boolean} init Whether or not this is the first time the theme is being applied
*/
async function apply(id, init) {
export async function apply(id, init) {
if (!DOES_SUPPORT_THEME) {
id = "default";
}
Expand All @@ -91,7 +95,9 @@ async function apply(id, init) {

if (init && theme.preferredEditorTheme) {
update.editorTheme = theme.preferredEditorTheme;
editorManager.editor.setTheme(theme.preferredEditorTheme);
if (editorManager != null && editorManager.editor != null) {
editorManager.editor.setTheme(theme.preferredEditorTheme);
}
}

if (init && theme.preferredFont) {
Expand Down Expand Up @@ -129,7 +135,7 @@ async function apply(id, init) {
* Update a theme
* @param {ThemeBuilder} theme
*/
function update(theme) {
export function update(theme) {
if (!(theme instanceof ThemeBuilder)) return;
const oldTheme = get(theme.id);
if (!oldTheme) {
Expand Down
Loading
Loading