From c97b4a274c1e57ac7cb4531d4b1df26d1de5f522 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sun, 25 May 2025 11:37:00 +0530 Subject: [PATCH 1/9] feat. added system theme --- src/lib/systemConfiguration.js | 22 ++++++++++ src/palettes/changeTheme/index.js | 40 +++++++++++++++++ .../android/com/foxdebug/system/System.java | 18 ++++++++ src/theme/list.js | 2 +- src/theme/preInstalled.js | 44 +++++++++++++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) diff --git a/src/lib/systemConfiguration.js b/src/lib/systemConfiguration.js index 59dc59bd6..fbcdb6722 100644 --- a/src/lib/systemConfiguration.js +++ b/src/lib/systemConfiguration.js @@ -52,3 +52,25 @@ export function getSystemConfiguration() { cordova.exec(resolve, reject, "System", "get-configuration", []); }); } + + +export function isDeviceDarkTheme() { + return new Promise((resolve, reject) => { + if(window.cordova && typeof cordova.exec !== 'function'){ + resolve(true) + return + } + cordova.exec( + (result) => { + resolve(result.isDark); + }, + (error) => { + console.warn(error); + resolve(true); + }, + 'System', + 'getTheme', + [] + ); + }); +} \ No newline at end of file diff --git a/src/palettes/changeTheme/index.js b/src/palettes/changeTheme/index.js index 8e4ff873f..0ced6f977 100644 --- a/src/palettes/changeTheme/index.js +++ b/src/palettes/changeTheme/index.js @@ -2,6 +2,8 @@ import "./style.scss"; import palette from "components/palette"; import appSettings from "lib/settings"; import themes from "theme/list"; +import { updateSystemTheme } from "theme/preInstalled"; +import { isDeviceDarkTheme } from "lib/systemConfiguration"; export default function changeTheme(type = "editor") { palette( @@ -56,11 +58,49 @@ function generateHints(type) { }); } + + + + +let previousDark = await isDeviceDarkTheme(); +const updateTimeMs = 3000; + +let intervalId = setInterval(async () => { + if (appSettings.value.appTheme.toLowerCase() === "system") { + const isDark = await 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 = await 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( diff --git a/src/plugins/system/android/com/foxdebug/system/System.java b/src/plugins/system/android/com/foxdebug/system/System.java index fb4839dc1..7d6a21402 100644 --- a/src/plugins/system/android/com/foxdebug/system/System.java +++ b/src/plugins/system/android/com/foxdebug/system/System.java @@ -104,6 +104,24 @@ public boolean execute( final String arg5 = args.optString(4); final String arg6 = args.optString(5); + if (action.equals("getTheme")) { + JSONObject theme = new JSONObject(); + + boolean isDark = (cordova.getActivity().getResources().getConfiguration().uiMode + & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; + + try { + theme.put("isDark", isDark); + } catch (Exception e) { + callbackContext.error("Error setting 'isDark' JSON entry."); + return true; + } + + callbackContext.success(theme); + + return true; + } + switch (action) { case "get-webkit-info": case "file-action": diff --git a/src/theme/list.js b/src/theme/list.js index dfeea53ef..e63aa80dc 100644 --- a/src/theme/list.js +++ b/src/theme/list.js @@ -68,7 +68,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"; } diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index a3acefe5a..357e023d3 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -1,4 +1,7 @@ +import appSettings from "lib/settings"; import { createBuiltInTheme } from "./builder"; +import { apply } from "./list"; +import { isDeviceDarkTheme } from "lib/systemConfiguration"; const WHITE = "rgb(255, 255, 255)"; const BLACK = "rgb(0, 0, 0)"; @@ -164,11 +167,52 @@ light.linkTextColor = "rgb(104, 103, 149)"; light.borderColor = "rgb(153, 153, 153)"; light.popupIconColor = "rgb(51, 62, 89)"; +const system = createBuiltInTheme("System"); + +export function updateSystemTheme(darkTheme) { + if (darkTheme) { + system.primaryColor = "rgb(49, 49, 49)"; + system.primaryTextColor = WHITE; + system.darkenedPrimaryColor = "rgb(29, 29, 29)"; + system.secondaryColor = "rgb(37, 37, 37)"; + system.secondaryTextColor = WHITE; + system.activeColor = "rgb(51, 153, 255)"; + system.linkTextColor = "rgb(181, 180, 233)"; + system.borderColor = "rgba(230, 230, 230, 0.2)"; + system.popupIconColor = WHITE; + + system.preferredEditorTheme = "ace/theme/clouds_midnight"; + + system.popupBackgroundColor = "rgb(49, 49, 49)"; + system.popupTextColor = WHITE; + system.popupActiveColor = "rgb(255, 215, 0)"; + } else { + system.darkenedPrimaryColor = "rgb(153, 153, 153)"; + system.primaryColor = WHITE; + system.primaryTextColor = "rgb(51, 62, 89)"; + system.secondaryColor = WHITE; + system.secondaryTextColor = "rgb(51, 62, 89)"; + system.activeColor = "rgb(51, 153, 255)"; + system.linkTextColor = "rgb(104, 103, 149)"; + system.borderColor = "rgb(153, 153, 153)"; + system.popupIconColor = "rgb(51, 62, 89)"; + + system.preferredEditorTheme = "ace/theme/crimson_editor"; + } + + if (appSettings.value.appTheme.toLowerCase() === "system") { + apply(system.id, true); + } +} + +updateSystemTheme(await isDeviceDarkTheme()); + const custom = createBuiltInTheme("Custom"); custom.autoDarkened = true; export default [ createBuiltInTheme("default", "dark", "free"), + system, dark, oled, ocean, From e9132a8bde96258c1c6400e640a7c4a0f6289b75 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sun, 25 May 2025 11:39:44 +0530 Subject: [PATCH 2/9] format --- src/lib/systemConfiguration.js | 15 +++++++-------- src/palettes/changeTheme/index.js | 10 +++------- src/theme/preInstalled.js | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/lib/systemConfiguration.js b/src/lib/systemConfiguration.js index fbcdb6722..babb07bf4 100644 --- a/src/lib/systemConfiguration.js +++ b/src/lib/systemConfiguration.js @@ -53,12 +53,11 @@ export function getSystemConfiguration() { }); } - export function isDeviceDarkTheme() { return new Promise((resolve, reject) => { - if(window.cordova && typeof cordova.exec !== 'function'){ - resolve(true) - return + if (window.cordova && typeof cordova.exec !== "function") { + resolve(true); + return; } cordova.exec( (result) => { @@ -68,9 +67,9 @@ export function isDeviceDarkTheme() { console.warn(error); resolve(true); }, - 'System', - 'getTheme', - [] + "System", + "getTheme", + [], ); }); -} \ No newline at end of file +} diff --git a/src/palettes/changeTheme/index.js b/src/palettes/changeTheme/index.js index 0ced6f977..8d84939a9 100644 --- a/src/palettes/changeTheme/index.js +++ b/src/palettes/changeTheme/index.js @@ -1,9 +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"; -import { isDeviceDarkTheme } from "lib/systemConfiguration"; export default function changeTheme(type = "editor") { palette( @@ -58,10 +58,6 @@ function generateHints(type) { }); } - - - - let previousDark = await isDeviceDarkTheme(); const updateTimeMs = 3000; @@ -69,7 +65,7 @@ let intervalId = setInterval(async () => { if (appSettings.value.appTheme.toLowerCase() === "system") { const isDark = await isDeviceDarkTheme(); if (isDark !== previousDark) { - previousDark = isDark + previousDark = isDark; updateSystemTheme(isDark); } } @@ -87,7 +83,7 @@ function onselect(value) { if (appSettings.value.appTheme.toLowerCase() === "system") { const isDark = await isDeviceDarkTheme(); if (isDark !== previousDark) { - previousDark = isDark + previousDark = isDark; updateSystemTheme(isDark); } } diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index 357e023d3..3ed01ddb7 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -1,7 +1,7 @@ import appSettings from "lib/settings"; +import { isDeviceDarkTheme } from "lib/systemConfiguration"; import { createBuiltInTheme } from "./builder"; import { apply } from "./list"; -import { isDeviceDarkTheme } from "lib/systemConfiguration"; const WHITE = "rgb(255, 255, 255)"; const BLACK = "rgb(0, 0, 0)"; From c5fee1d286fe7617f1500420b958496bed12989a Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sun, 25 May 2025 15:29:03 +0530 Subject: [PATCH 3/9] fix. gray text color --- src/lib/systemConfiguration.js | 30 +++++++++++++++--------------- src/palettes/changeTheme/index.js | 2 +- src/theme/list.js | 7 +++++-- src/theme/preInstalled.js | 9 +++++++-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/lib/systemConfiguration.js b/src/lib/systemConfiguration.js index babb07bf4..3dbda3fb9 100644 --- a/src/lib/systemConfiguration.js +++ b/src/lib/systemConfiguration.js @@ -55,21 +55,21 @@ export function getSystemConfiguration() { export function isDeviceDarkTheme() { return new Promise((resolve, reject) => { - if (window.cordova && typeof cordova.exec !== "function") { - resolve(true); - return; + try { + cordova.exec( + (result) => { + resolve(result.isDark); + }, + (error) => { + console.warn(error); + resolve(false); + }, + "System", + "getTheme", + [], + ); + } catch (e) { + resolve(false); } - cordova.exec( - (result) => { - resolve(result.isDark); - }, - (error) => { - console.warn(error); - resolve(true); - }, - "System", - "getTheme", - [], - ); }); } diff --git a/src/palettes/changeTheme/index.js b/src/palettes/changeTheme/index.js index 8d84939a9..35bac676a 100644 --- a/src/palettes/changeTheme/index.js +++ b/src/palettes/changeTheme/index.js @@ -59,7 +59,7 @@ function generateHints(type) { } let previousDark = await isDeviceDarkTheme(); -const updateTimeMs = 3000; +const updateTimeMs = 2000; let intervalId = setInterval(async () => { if (appSettings.value.appTheme.toLowerCase() === "system") { diff --git a/src/theme/list.js b/src/theme/list.js index e63aa80dc..374e8ef14 100644 --- a/src/theme/list.js +++ b/src/theme/list.js @@ -4,7 +4,7 @@ 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} */ const appThemes = new Map(); @@ -12,6 +12,9 @@ let themeApplied = false; function init() { themes.forEach((theme) => add(theme)); + (async () => { + updateSystemTheme(await isDeviceDarkTheme()); + })(); } /** @@ -129,7 +132,7 @@ export 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) { diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index 3ed01ddb7..4ec144ce9 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -1,7 +1,8 @@ import appSettings from "lib/settings"; import { isDeviceDarkTheme } from "lib/systemConfiguration"; import { createBuiltInTheme } from "./builder"; -import { apply } from "./list"; +import { apply,update } from "./list"; +import restoreTheme from "lib/restoreTheme"; const WHITE = "rgb(255, 255, 255)"; const BLACK = "rgb(0, 0, 0)"; @@ -193,11 +194,15 @@ export function updateSystemTheme(darkTheme) { system.secondaryColor = WHITE; system.secondaryTextColor = "rgb(51, 62, 89)"; system.activeColor = "rgb(51, 153, 255)"; - system.linkTextColor = "rgb(104, 103, 149)"; + system.linkTextColor = BLACK; system.borderColor = "rgb(153, 153, 153)"; system.popupIconColor = "rgb(51, 62, 89)"; system.preferredEditorTheme = "ace/theme/crimson_editor"; + + system.popupBackgroundColor = WHITE; + system.popupTextColor = BLACK; + system.popupActiveColor = "rgb(255, 215, 0)"; } if (appSettings.value.appTheme.toLowerCase() === "system") { From d72dd7eeb1f661f00af17a4a24b1145740fc6b59 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sun, 25 May 2025 15:37:44 +0530 Subject: [PATCH 4/9] fix. gray text color --- src/theme/list.js | 1 + src/theme/preInstalled.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/theme/list.js b/src/theme/list.js index 374e8ef14..b5aedf04d 100644 --- a/src/theme/list.js +++ b/src/theme/list.js @@ -1,4 +1,5 @@ import fsOperation from "fileSystem"; +import { isDeviceDarkTheme } from "lib/systemConfiguration"; import Url from "utils/Url"; import color from "utils/color"; import fonts from "../lib/fonts"; diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index 4ec144ce9..61de20713 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -1,8 +1,8 @@ +import restoreTheme from "lib/restoreTheme"; import appSettings from "lib/settings"; import { isDeviceDarkTheme } from "lib/systemConfiguration"; import { createBuiltInTheme } from "./builder"; -import { apply,update } from "./list"; -import restoreTheme from "lib/restoreTheme"; +import { apply, update } from "./list"; const WHITE = "rgb(255, 255, 255)"; const BLACK = "rgb(0, 0, 0)"; From ff3f2ea1a2516fb92ccedf275d92995e93de9ad9 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Tue, 27 May 2025 12:54:05 +0530 Subject: [PATCH 5/9] fix. statusbar colors --- src/theme/list.js | 5 ++++- src/theme/preInstalled.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/theme/list.js b/src/theme/list.js index b5aedf04d..63d263c6c 100644 --- a/src/theme/list.js +++ b/src/theme/list.js @@ -95,7 +95,10 @@ export 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) { diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index 61de20713..21005fe31 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -3,6 +3,7 @@ import appSettings from "lib/settings"; import { isDeviceDarkTheme } from "lib/systemConfiguration"; import { createBuiltInTheme } from "./builder"; import { apply, update } from "./list"; +import color from "utils/color"; const WHITE = "rgb(255, 255, 255)"; const BLACK = "rgb(0, 0, 0)"; @@ -187,7 +188,9 @@ export function updateSystemTheme(darkTheme) { system.popupBackgroundColor = "rgb(49, 49, 49)"; system.popupTextColor = WHITE; system.popupActiveColor = "rgb(255, 215, 0)"; + system.type = "dark" } else { + system.type = "light" system.darkenedPrimaryColor = "rgb(153, 153, 153)"; system.primaryColor = WHITE; system.primaryTextColor = "rgb(51, 62, 89)"; @@ -206,7 +209,7 @@ export function updateSystemTheme(darkTheme) { } if (appSettings.value.appTheme.toLowerCase() === "system") { - apply(system.id, true); + apply(system.id, true); } } From 7498b53692ae1fb8012ce3110c34001e0d9f8726 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Tue, 27 May 2025 12:55:01 +0530 Subject: [PATCH 6/9] format --- src/theme/list.js | 3 +-- src/theme/preInstalled.js | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/theme/list.js b/src/theme/list.js index 63d263c6c..31152a98f 100644 --- a/src/theme/list.js +++ b/src/theme/list.js @@ -97,8 +97,7 @@ export async function apply(id, init) { update.editorTheme = theme.preferredEditorTheme; if (editorManager != null && editorManager.editor != null) { editorManager.editor.setTheme(theme.preferredEditorTheme); - } - + } } if (init && theme.preferredFont) { diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index 21005fe31..26c4ee43f 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -1,9 +1,9 @@ import restoreTheme from "lib/restoreTheme"; import appSettings from "lib/settings"; import { isDeviceDarkTheme } from "lib/systemConfiguration"; +import color from "utils/color"; import { createBuiltInTheme } from "./builder"; import { apply, update } from "./list"; -import color from "utils/color"; const WHITE = "rgb(255, 255, 255)"; const BLACK = "rgb(0, 0, 0)"; @@ -188,9 +188,9 @@ export function updateSystemTheme(darkTheme) { system.popupBackgroundColor = "rgb(49, 49, 49)"; system.popupTextColor = WHITE; system.popupActiveColor = "rgb(255, 215, 0)"; - system.type = "dark" + system.type = "dark"; } else { - system.type = "light" + system.type = "light"; system.darkenedPrimaryColor = "rgb(153, 153, 153)"; system.primaryColor = WHITE; system.primaryTextColor = "rgb(51, 62, 89)"; @@ -209,7 +209,7 @@ export function updateSystemTheme(darkTheme) { } if (appSettings.value.appTheme.toLowerCase() === "system") { - apply(system.id, true); + apply(system.id, true); } } From 99989f39bed23da47ffc1a2e75af3a59f8a5f606 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Thu, 29 May 2025 11:34:48 +0530 Subject: [PATCH 7/9] fix. allow webview to detect theme change --- package.json | 2 +- res/android/values/themes.xml | 2 +- src/lib/systemConfiguration.js | 14 ++------------ .../android/com/foxdebug/system/System.java | 18 ------------------ www/index.html | 10 +++++----- 5 files changed, 9 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index c8339ebea..681723b6e 100644 --- a/package.json +++ b/package.json @@ -113,4 +113,4 @@ "yargs": "^17.7.2" }, "browserslist": "cover 100%,not android < 5" -} +} \ No newline at end of file diff --git a/res/android/values/themes.xml b/res/android/values/themes.xml index 82bcebedc..bd2204411 100644 --- a/res/android/values/themes.xml +++ b/res/android/values/themes.xml @@ -4,6 +4,6 @@ @color/ic_splash_background @drawable/ic_launcher_foreground 200 - @style/Theme.AppCompat.NoActionBar + @style/Theme.AppCompat.DayNight.NoActionBar diff --git a/src/lib/systemConfiguration.js b/src/lib/systemConfiguration.js index 3dbda3fb9..2c925ab46 100644 --- a/src/lib/systemConfiguration.js +++ b/src/lib/systemConfiguration.js @@ -56,18 +56,8 @@ export function getSystemConfiguration() { export function isDeviceDarkTheme() { return new Promise((resolve, reject) => { try { - cordova.exec( - (result) => { - resolve(result.isDark); - }, - (error) => { - console.warn(error); - resolve(false); - }, - "System", - "getTheme", - [], - ); + var isDark = window.matchMedia("(prefers-color-scheme: dark)").matches; + resolve(isDark); } catch (e) { resolve(false); } diff --git a/src/plugins/system/android/com/foxdebug/system/System.java b/src/plugins/system/android/com/foxdebug/system/System.java index 7d6a21402..fb4839dc1 100644 --- a/src/plugins/system/android/com/foxdebug/system/System.java +++ b/src/plugins/system/android/com/foxdebug/system/System.java @@ -104,24 +104,6 @@ public boolean execute( final String arg5 = args.optString(4); final String arg6 = args.optString(5); - if (action.equals("getTheme")) { - JSONObject theme = new JSONObject(); - - boolean isDark = (cordova.getActivity().getResources().getConfiguration().uiMode - & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; - - try { - theme.put("isDark", isDark); - } catch (Exception e) { - callbackContext.error("Error setting 'isDark' JSON entry."); - return true; - } - - callbackContext.success(theme); - - return true; - } - switch (action) { case "get-webkit-info": case "file-action": diff --git a/www/index.html b/www/index.html index e4c0e5ec3..ae9aa7f4d 100644 --- a/www/index.html +++ b/www/index.html @@ -165,17 +165,17 @@ Acode - - - - - + + + + + From 3bd3b3b85e899b0630409550cc072ffe7ab40f70 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Thu, 29 May 2025 12:05:46 +0530 Subject: [PATCH 8/9] feat. make the system theme default (Closes #746) --- src/lib/settings.js | 6 ++++-- src/lib/systemConfiguration.js | 9 +-------- src/palettes/changeTheme/index.js | 6 +++--- src/theme/list.js | 2 +- src/theme/preInstalled.js | 21 ++++++++++++++------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/lib/settings.js b/src/lib/settings.js index 090bf94ab..63ee49ce5 100644 --- a/src/lib/settings.js +++ b/src/lib/settings.js @@ -5,6 +5,8 @@ import Url from "utils/Url"; import helpers from "utils/helpers"; import constants from "./constants"; import lang from "./lang"; +import { getSystemEditorTheme } from "theme/preInstalled"; +import { isDeviceDarkTheme } from "./systemConfiguration"; /** * @typedef {object} fileBrowserSettings @@ -182,8 +184,8 @@ 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; diff --git a/src/lib/systemConfiguration.js b/src/lib/systemConfiguration.js index 2c925ab46..91939d689 100644 --- a/src/lib/systemConfiguration.js +++ b/src/lib/systemConfiguration.js @@ -54,12 +54,5 @@ export function getSystemConfiguration() { } export function isDeviceDarkTheme() { - return new Promise((resolve, reject) => { - try { - var isDark = window.matchMedia("(prefers-color-scheme: dark)").matches; - resolve(isDark); - } catch (e) { - resolve(false); - } - }); + return window.matchMedia("(prefers-color-scheme: dark)").matches } diff --git a/src/palettes/changeTheme/index.js b/src/palettes/changeTheme/index.js index 35bac676a..be76c6fa7 100644 --- a/src/palettes/changeTheme/index.js +++ b/src/palettes/changeTheme/index.js @@ -58,12 +58,12 @@ function generateHints(type) { }); } -let previousDark = await isDeviceDarkTheme(); +let previousDark = isDeviceDarkTheme(); const updateTimeMs = 2000; let intervalId = setInterval(async () => { if (appSettings.value.appTheme.toLowerCase() === "system") { - const isDark = await isDeviceDarkTheme(); + const isDark = isDeviceDarkTheme(); if (isDark !== previousDark) { previousDark = isDark; updateSystemTheme(isDark); @@ -81,7 +81,7 @@ function onselect(value) { if (!intervalId) { intervalId = setInterval(async () => { if (appSettings.value.appTheme.toLowerCase() === "system") { - const isDark = await isDeviceDarkTheme(); + const isDark = isDeviceDarkTheme(); if (isDark !== previousDark) { previousDark = isDark; updateSystemTheme(isDark); diff --git a/src/theme/list.js b/src/theme/list.js index 31152a98f..0c8b308f8 100644 --- a/src/theme/list.js +++ b/src/theme/list.js @@ -14,7 +14,7 @@ let themeApplied = false; function init() { themes.forEach((theme) => add(theme)); (async () => { - updateSystemTheme(await isDeviceDarkTheme()); + updateSystemTheme(isDeviceDarkTheme()); })(); } diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index 26c4ee43f..3b776e080 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -171,6 +171,14 @@ light.popupIconColor = "rgb(51, 62, 89)"; const system = createBuiltInTheme("System"); +export function getSystemEditorTheme(darkTheme){ + if(darkTheme){ + return "ace/theme/clouds_midnight" + }else{ + return "ace/theme/crimson_editor" + } +} + export function updateSystemTheme(darkTheme) { if (darkTheme) { system.primaryColor = "rgb(49, 49, 49)"; @@ -183,8 +191,6 @@ export function updateSystemTheme(darkTheme) { system.borderColor = "rgba(230, 230, 230, 0.2)"; system.popupIconColor = WHITE; - system.preferredEditorTheme = "ace/theme/clouds_midnight"; - system.popupBackgroundColor = "rgb(49, 49, 49)"; system.popupTextColor = WHITE; system.popupActiveColor = "rgb(255, 215, 0)"; @@ -201,26 +207,27 @@ export function updateSystemTheme(darkTheme) { system.borderColor = "rgb(153, 153, 153)"; system.popupIconColor = "rgb(51, 62, 89)"; - system.preferredEditorTheme = "ace/theme/crimson_editor"; - system.popupBackgroundColor = WHITE; system.popupTextColor = BLACK; system.popupActiveColor = "rgb(255, 215, 0)"; } - if (appSettings.value.appTheme.toLowerCase() === "system") { + system.preferredEditorTheme = getSystemEditorTheme(darkTheme) + + if (appSettings !== undefined && appSettings.value !== undefined && appSettings.value.appTheme !== undefined && appSettings.value.appTheme.toLowerCase() === "system") { apply(system.id, true); } + } -updateSystemTheme(await isDeviceDarkTheme()); +updateSystemTheme(isDeviceDarkTheme()); const custom = createBuiltInTheme("Custom"); custom.autoDarkened = true; export default [ - createBuiltInTheme("default", "dark", "free"), system, + createBuiltInTheme("default", "dark", "free"), dark, oled, ocean, From f0833c85dc738ef5896b02d838cf7cdb3cccc07c Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Thu, 29 May 2025 12:06:56 +0530 Subject: [PATCH 9/9] format --- src/lib/settings.js | 6 ++++-- src/lib/systemConfiguration.js | 2 +- src/theme/preInstalled.js | 20 ++++++++++++-------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/lib/settings.js b/src/lib/settings.js index 63ee49ce5..391654494 100644 --- a/src/lib/settings.js +++ b/src/lib/settings.js @@ -1,11 +1,11 @@ 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 { getSystemEditorTheme } from "theme/preInstalled"; import { isDeviceDarkTheme } from "./systemConfiguration"; /** @@ -185,7 +185,9 @@ class Settings { if (!IS_FREE_VERSION) { this.#defaultSettings.appTheme = "system"; - this.#defaultSettings.editorTheme = getSystemEditorTheme(isDeviceDarkTheme()); + this.#defaultSettings.editorTheme = getSystemEditorTheme( + isDeviceDarkTheme(), + ); } this.#initialized = true; diff --git a/src/lib/systemConfiguration.js b/src/lib/systemConfiguration.js index 91939d689..24a3180b7 100644 --- a/src/lib/systemConfiguration.js +++ b/src/lib/systemConfiguration.js @@ -54,5 +54,5 @@ export function getSystemConfiguration() { } export function isDeviceDarkTheme() { - return window.matchMedia("(prefers-color-scheme: dark)").matches + return window.matchMedia("(prefers-color-scheme: dark)").matches; } diff --git a/src/theme/preInstalled.js b/src/theme/preInstalled.js index 3b776e080..f66704819 100644 --- a/src/theme/preInstalled.js +++ b/src/theme/preInstalled.js @@ -171,11 +171,11 @@ light.popupIconColor = "rgb(51, 62, 89)"; const system = createBuiltInTheme("System"); -export function getSystemEditorTheme(darkTheme){ - if(darkTheme){ - return "ace/theme/clouds_midnight" - }else{ - return "ace/theme/crimson_editor" +export function getSystemEditorTheme(darkTheme) { + if (darkTheme) { + return "ace/theme/clouds_midnight"; + } else { + return "ace/theme/crimson_editor"; } } @@ -212,12 +212,16 @@ export function updateSystemTheme(darkTheme) { system.popupActiveColor = "rgb(255, 215, 0)"; } - system.preferredEditorTheme = getSystemEditorTheme(darkTheme) + system.preferredEditorTheme = getSystemEditorTheme(darkTheme); - if (appSettings !== undefined && appSettings.value !== undefined && appSettings.value.appTheme !== undefined && appSettings.value.appTheme.toLowerCase() === "system") { + if ( + appSettings !== undefined && + appSettings.value !== undefined && + appSettings.value.appTheme !== undefined && + appSettings.value.appTheme.toLowerCase() === "system" + ) { apply(system.id, true); } - } updateSystemTheme(isDeviceDarkTheme());