Skip to content

Commit 52bf3a5

Browse files
feat. added system theme (#1321)
* feat. added system theme * format * fix. gray text color * fix. gray text color * fix. statusbar colors * format * fix. allow webview to detect theme change * feat. make the system theme default (Closes #746) * format --------- Co-authored-by: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com>
1 parent 2052411 commit 52bf3a5

File tree

8 files changed

+126
-13
lines changed

8 files changed

+126
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@
113113
"yargs": "^17.7.2"
114114
},
115115
"browserslist": "cover 100%,not android < 5"
116-
}
116+
}

res/android/values/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<item name="windowSplashScreenBackground">@color/ic_splash_background</item>
55
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
66
<item name="windowSplashScreenAnimationDuration">200</item>
7-
<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>
7+
<item name="postSplashScreenTheme">@style/Theme.AppCompat.DayNight.NoActionBar</item>
88
</style>
99
</resources>

src/lib/settings.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import fsOperation from "fileSystem";
22
import ThemeBuilder from "theme/builder";
33
import themes from "theme/list";
4+
import { getSystemEditorTheme } from "theme/preInstalled";
45
import Url from "utils/Url";
56
import helpers from "utils/helpers";
67
import constants from "./constants";
78
import lang from "./lang";
9+
import { isDeviceDarkTheme } from "./systemConfiguration";
810

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

184186
if (!IS_FREE_VERSION) {
185-
this.#defaultSettings.appTheme = "ocean";
186-
this.#defaultSettings.editorTheme = "ace/theme/dracula";
187+
this.#defaultSettings.appTheme = "system";
188+
this.#defaultSettings.editorTheme = getSystemEditorTheme(
189+
isDeviceDarkTheme(),
190+
);
187191
}
188192

189193
this.#initialized = true;

src/lib/systemConfiguration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ export function getSystemConfiguration() {
5252
cordova.exec(resolve, reject, "System", "get-configuration", []);
5353
});
5454
}
55+
56+
export function isDeviceDarkTheme() {
57+
return window.matchMedia("(prefers-color-scheme: dark)").matches;
58+
}

src/palettes/changeTheme/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import "./style.scss";
22
import palette from "components/palette";
33
import appSettings from "lib/settings";
4+
import { isDeviceDarkTheme } from "lib/systemConfiguration";
45
import themes from "theme/list";
6+
import { updateSystemTheme } from "theme/preInstalled";
57

68
export default function changeTheme(type = "editor") {
79
palette(
@@ -56,11 +58,45 @@ function generateHints(type) {
5658
});
5759
}
5860

61+
let previousDark = isDeviceDarkTheme();
62+
const updateTimeMs = 2000;
63+
64+
let intervalId = setInterval(async () => {
65+
if (appSettings.value.appTheme.toLowerCase() === "system") {
66+
const isDark = isDeviceDarkTheme();
67+
if (isDark !== previousDark) {
68+
previousDark = isDark;
69+
updateSystemTheme(isDark);
70+
}
71+
}
72+
}, updateTimeMs);
73+
5974
function onselect(value) {
6075
if (!value) return;
6176

6277
const selection = JSON.parse(value);
6378

79+
if (selection.theme === "system") {
80+
// Start interval if not already started
81+
if (!intervalId) {
82+
intervalId = setInterval(async () => {
83+
if (appSettings.value.appTheme.toLowerCase() === "system") {
84+
const isDark = isDeviceDarkTheme();
85+
if (isDark !== previousDark) {
86+
previousDark = isDark;
87+
updateSystemTheme(isDark);
88+
}
89+
}
90+
}, updateTimeMs);
91+
}
92+
} else {
93+
// Cancel interval if it's running
94+
if (intervalId) {
95+
clearInterval(intervalId);
96+
intervalId = null;
97+
}
98+
}
99+
64100
if (selection.type === "editor") {
65101
editorManager.editor.setTheme(selection.theme);
66102
appSettings.update(

src/theme/list.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import fsOperation from "fileSystem";
2+
import { isDeviceDarkTheme } from "lib/systemConfiguration";
23
import Url from "utils/Url";
34
import color from "utils/color";
45
import fonts from "../lib/fonts";
56
import settings from "../lib/settings";
67
import ThemeBuilder from "./builder";
7-
import themes from "./preInstalled";
8+
import themes, { updateSystemTheme } from "./preInstalled";
89

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

1314
function init() {
1415
themes.forEach((theme) => add(theme));
16+
(async () => {
17+
updateSystemTheme(isDeviceDarkTheme());
18+
})();
1519
}
1620

1721
/**
@@ -68,7 +72,7 @@ function add(theme) {
6872
* @param {string} id The name of the theme to apply
6973
* @param {boolean} init Whether or not this is the first time the theme is being applied
7074
*/
71-
async function apply(id, init) {
75+
export async function apply(id, init) {
7276
if (!DOES_SUPPORT_THEME) {
7377
id = "default";
7478
}
@@ -91,7 +95,9 @@ async function apply(id, init) {
9195

9296
if (init && theme.preferredEditorTheme) {
9397
update.editorTheme = theme.preferredEditorTheme;
94-
editorManager.editor.setTheme(theme.preferredEditorTheme);
98+
if (editorManager != null && editorManager.editor != null) {
99+
editorManager.editor.setTheme(theme.preferredEditorTheme);
100+
}
95101
}
96102

97103
if (init && theme.preferredFont) {
@@ -129,7 +135,7 @@ async function apply(id, init) {
129135
* Update a theme
130136
* @param {ThemeBuilder} theme
131137
*/
132-
function update(theme) {
138+
export function update(theme) {
133139
if (!(theme instanceof ThemeBuilder)) return;
134140
const oldTheme = get(theme.id);
135141
if (!oldTheme) {

src/theme/preInstalled.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import restoreTheme from "lib/restoreTheme";
2+
import appSettings from "lib/settings";
3+
import { isDeviceDarkTheme } from "lib/systemConfiguration";
4+
import color from "utils/color";
15
import { createBuiltInTheme } from "./builder";
6+
import { apply, update } from "./list";
27

38
const WHITE = "rgb(255, 255, 255)";
49
const BLACK = "rgb(0, 0, 0)";
@@ -164,10 +169,68 @@ light.linkTextColor = "rgb(104, 103, 149)";
164169
light.borderColor = "rgb(153, 153, 153)";
165170
light.popupIconColor = "rgb(51, 62, 89)";
166171

172+
const system = createBuiltInTheme("System");
173+
174+
export function getSystemEditorTheme(darkTheme) {
175+
if (darkTheme) {
176+
return "ace/theme/clouds_midnight";
177+
} else {
178+
return "ace/theme/crimson_editor";
179+
}
180+
}
181+
182+
export function updateSystemTheme(darkTheme) {
183+
if (darkTheme) {
184+
system.primaryColor = "rgb(49, 49, 49)";
185+
system.primaryTextColor = WHITE;
186+
system.darkenedPrimaryColor = "rgb(29, 29, 29)";
187+
system.secondaryColor = "rgb(37, 37, 37)";
188+
system.secondaryTextColor = WHITE;
189+
system.activeColor = "rgb(51, 153, 255)";
190+
system.linkTextColor = "rgb(181, 180, 233)";
191+
system.borderColor = "rgba(230, 230, 230, 0.2)";
192+
system.popupIconColor = WHITE;
193+
194+
system.popupBackgroundColor = "rgb(49, 49, 49)";
195+
system.popupTextColor = WHITE;
196+
system.popupActiveColor = "rgb(255, 215, 0)";
197+
system.type = "dark";
198+
} else {
199+
system.type = "light";
200+
system.darkenedPrimaryColor = "rgb(153, 153, 153)";
201+
system.primaryColor = WHITE;
202+
system.primaryTextColor = "rgb(51, 62, 89)";
203+
system.secondaryColor = WHITE;
204+
system.secondaryTextColor = "rgb(51, 62, 89)";
205+
system.activeColor = "rgb(51, 153, 255)";
206+
system.linkTextColor = BLACK;
207+
system.borderColor = "rgb(153, 153, 153)";
208+
system.popupIconColor = "rgb(51, 62, 89)";
209+
210+
system.popupBackgroundColor = WHITE;
211+
system.popupTextColor = BLACK;
212+
system.popupActiveColor = "rgb(255, 215, 0)";
213+
}
214+
215+
system.preferredEditorTheme = getSystemEditorTheme(darkTheme);
216+
217+
if (
218+
appSettings !== undefined &&
219+
appSettings.value !== undefined &&
220+
appSettings.value.appTheme !== undefined &&
221+
appSettings.value.appTheme.toLowerCase() === "system"
222+
) {
223+
apply(system.id, true);
224+
}
225+
}
226+
227+
updateSystemTheme(isDeviceDarkTheme());
228+
167229
const custom = createBuiltInTheme("Custom");
168230
custom.autoDarkened = true;
169231

170232
export default [
233+
system,
171234
createBuiltInTheme("default", "dark", "free"),
172235
dark,
173236
oled,

www/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@
165165

166166
<title>Acode</title>
167167
<!--styles-->
168-
<link rel="stylesheet" href="./css/build/263.css">
169-
<link rel="stylesheet" href="./css/build/31.css">
170-
<link rel="stylesheet" href="./css/build/439.css">
171-
<link rel="stylesheet" href="./css/build/490.css">
172-
<link rel="stylesheet" href="./css/build/626.css">
173168
<link rel="stylesheet" href="./css/build/about.css">
174169
<link rel="stylesheet" href="./css/build/customTheme.css">
175170
<link rel="stylesheet" href="./css/build/donate.css">
176171
<link rel="stylesheet" href="./css/build/fileBrowser.css">
177172
<link rel="stylesheet" href="./css/build/main.css">
178173
<link rel="stylesheet" href="./css/build/plugins.css">
174+
<link rel="stylesheet" href="./css/build/src_pages_quickTools_quickTools_js.css">
175+
<link rel="stylesheet" href="./css/build/src_sidebarApps_extensions_index_js.css">
176+
<link rel="stylesheet" href="./css/build/src_sidebarApps_files_index_js.css">
177+
<link rel="stylesheet" href="./css/build/src_sidebarApps_notification_index_js.css">
178+
<link rel="stylesheet" href="./css/build/src_sidebarApps_searchInFiles_index_js.css">
179179
<link rel="stylesheet" href="./css/build/themeSetting.css">
180180
<!--styles_end-->
181181
</head>

0 commit comments

Comments
 (0)