Skip to content

Commit 0028145

Browse files
committed
Update utility functions and theme handling
Use acode api for font related stuff instead of custom download and saving
1 parent f8f6e71 commit 0028145

File tree

5 files changed

+517
-680
lines changed

5 files changed

+517
-680
lines changed

dist/main.js

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

src/AcodeX.js

Lines changed: 126 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,123 @@ const loader = acode.require("loader");
5353
const DialogBox = acode.require("dialogBox");
5454
const pageComponent = acode.require("page");
5555
const actionStack = acode.require("actionStack");
56+
const acodeFonts = acode.require("fonts");
5657

5758
const { clipboard } = cordova.plugins;
5859

60+
const FONT_CDN_BASE =
61+
"https://cdn.jsdelivr.net/gh/bajrangCoder/acode-plugin-acodex@main/fonts/";
62+
63+
const TERMINAL_FONTS = [
64+
{
65+
name: "Fira Code Bold Nerd Font",
66+
url: `${FONT_CDN_BASE}Fira Code Bold Nerd Font.ttf`,
67+
format: "truetype",
68+
weight: "bold",
69+
style: "normal",
70+
},
71+
{
72+
name: "Fira Code Medium Nerd Font",
73+
url: `${FONT_CDN_BASE}Fira Code Medium Nerd Font Complete Mono.ttf`,
74+
format: "truetype",
75+
weight: "normal",
76+
style: "normal",
77+
},
78+
{
79+
name: "JetBrains Mono Bold Nerd Font",
80+
url: `${FONT_CDN_BASE}JetBrains Mono Bold Nerd Font Complete.ttf`,
81+
format: "truetype",
82+
weight: "bold",
83+
style: "normal",
84+
},
85+
{
86+
name: "JetBrains Mono Medium Nerd Font",
87+
url: `${FONT_CDN_BASE}JetBrains Mono Medium Nerd Font Complete.ttf`,
88+
format: "truetype",
89+
weight: "normal",
90+
style: "normal",
91+
},
92+
{
93+
name: "VictorMonoNerdFont Bold",
94+
url: `${FONT_CDN_BASE}VictorMonoNerdFont-Bold.ttf`,
95+
format: "truetype",
96+
weight: "bold",
97+
style: "normal",
98+
},
99+
{
100+
name: "VictorMonoNerdFont BoldItalic",
101+
url: `${FONT_CDN_BASE}VictorMonoNerdFont-BoldItalic.ttf`,
102+
format: "truetype",
103+
weight: "bold",
104+
style: "italic",
105+
},
106+
{
107+
name: "VictorMonoNerdFont Medium",
108+
url: `${FONT_CDN_BASE}VictorMonoNerdFont-Medium.ttf`,
109+
format: "truetype",
110+
weight: "normal",
111+
style: "normal",
112+
},
113+
{
114+
name: "VictorMonoNerdFont Italic",
115+
url: `${FONT_CDN_BASE}VictorMonoNerdFont-Italic.ttf`,
116+
format: "truetype",
117+
weight: "normal",
118+
style: "italic",
119+
},
120+
{
121+
name: "SauceCodeProNerdFont Bold",
122+
url: `${FONT_CDN_BASE}SauceCodeProNerdFont-Bold.ttf`,
123+
format: "truetype",
124+
weight: "bold",
125+
style: "normal",
126+
},
127+
{
128+
name: "SauceCodeProNerdFont Medium",
129+
url: `${FONT_CDN_BASE}SauceCodeProNerdFont-Medium.ttf`,
130+
format: "truetype",
131+
weight: "normal",
132+
style: "normal",
133+
},
134+
{
135+
name: "MesloLGS NF Bold Italic",
136+
url: `${FONT_CDN_BASE}MesloLGS NF Bold Italic.ttf`,
137+
format: "truetype",
138+
weight: "bold",
139+
style: "italic",
140+
},
141+
{
142+
name: "MesloLGS NF Bold",
143+
url: `${FONT_CDN_BASE}MesloLGS NF Bold.ttf`,
144+
format: "truetype",
145+
weight: "bold",
146+
style: "normal",
147+
},
148+
{
149+
name: "MesloLGS NF Italic",
150+
url: `${FONT_CDN_BASE}MesloLGS NF Italic.ttf`,
151+
format: "truetype",
152+
weight: "normal",
153+
style: "italic",
154+
},
155+
];
156+
157+
function registerTerminalFonts() {
158+
if (typeof acodeFonts?.add !== "function") return;
159+
160+
TERMINAL_FONTS.forEach(({ name, url, format, weight, style }) => {
161+
if (acodeFonts?.has?.(name)) return;
162+
const fontUrl = encodeURI(url);
163+
const fontFace = `@font-face {
164+
font-family: '${name}';
165+
src: url('${fontUrl}') format('${format}');
166+
font-weight: ${weight};
167+
font-style: ${style};
168+
}`;
169+
acodeFonts.add(name, fontFace);
170+
});
171+
}
172+
59173
export default class AcodeX {
60174
// constants for draggable Terminal panel
61175
isDragging = false;
@@ -92,12 +206,7 @@ export default class AcodeX {
92206

93207
async init($page, cacheFile, cacheFileUrl) {
94208
try {
95-
if (!(await fsOperation(`${window.DATA_STORAGE}acodex_fonts`).exists())) {
96-
helpers.downloadFont(fsOperation, loader);
97-
}
98-
const baseFontUrl = window.IS_FREE_VERSION
99-
? "https://localhost/__cdvfile_sdcard__/Android/data/com.foxdebug.acodefree/files/acodex_fonts/"
100-
: "https://localhost/__cdvfile_sdcard__/Android/data/com.foxdebug.acode/files/acodex_fonts/";
209+
registerTerminalFonts();
101210
this.xtermCss = tag("link", {
102211
rel: "stylesheet",
103212
href: `${this.baseUrl}xterm.css`,
@@ -106,11 +215,8 @@ export default class AcodeX {
106215
rel: "stylesheet",
107216
href: `${this.baseUrl}main.css`,
108217
});
109-
this.$fontStyleSheet = tag("style", {
110-
textContent: helpers.fontsStyleSheetStr(baseFontUrl),
111-
});
112218
this._loadCustomFontStyleSheet();
113-
document.head.append(this.xtermCss, this.$style, this.$fontStyleSheet);
219+
document.head.append(this.xtermCss, this.$style);
114220
// add command in command Palette for opening and closing terminal
115221
editorManager.editor.commands.addCommand({
116222
name: "acodex:open_terminal",
@@ -969,6 +1075,7 @@ export default class AcodeX {
9691075
this.$terminalContainer.style.height = `${termContainerHeight}px`;
9701076
this.$terminalContent.style.width = "100%";
9711077
this.$terminalContent.style.height = `calc(100% - ${this.$terminalContainer.offsetHeight}px)`;
1078+
await acodeFonts.loadFont(this.settings.fontFamily);
9721079

9731080
if (this.settings.transparency) {
9741081
this.$terminalContainer.style.background = "transparent";
@@ -2330,7 +2437,9 @@ export default class AcodeX {
23302437
text: "Font Family",
23312438
value: this.settings.fontFamily,
23322439
info: "The font family used to render text.",
2333-
select: FONTS_LIST,
2440+
get select() {
2441+
return acodeFonts.getNames();
2442+
},
23342443
},
23352444
{
23362445
index: 4,
@@ -2525,7 +2634,7 @@ export default class AcodeX {
25252634
];
25262635
}
25272636

2528-
settingsSaveCallback(key, value) {
2637+
async settingsSaveCallback(key, value) {
25292638
switch (key) {
25302639
case "customFontStyleSheet":
25312640
this.setCustomFontFile();
@@ -2557,6 +2666,11 @@ export default class AcodeX {
25572666
appSettings.update();
25582667
break;
25592668
case "fontFamily":
2669+
try {
2670+
await acodeFonts.loadFont(value);
2671+
} catch (error) {
2672+
console.warn(`Failed to load font ${value}:`, error);
2673+
}
25602674
if (this.$terminal) {
25612675
this.$terminal.options.fontFamily = value;
25622676
this.$terminal.refresh(0, this.$terminal.rows - 1);

src/utils/constants.js

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const appSettings = acode.require("settings");
2-
31
// ai models logo
42
acode.addIcon("deepseek", "https://raw.githubusercontent.com/deepseek-ai/DeepSeek-Coder/main/pictures/home.png");
53
acode.addIcon("chatgpt", "https://upload.wikimedia.org/wikipedia/commons/0/04/ChatGPT_logo.svg");
@@ -55,85 +53,9 @@ export const THEME_LIST = [
5553
"siduckOneDark",
5654
"snazzy",
5755
"xterm",
56+
"wal",
5857
"custom",
5958
];
60-
export const FONTS_LIST = [
61-
[
62-
appSettings.get("editorFont"),
63-
"Default Editor Font",
64-
"file file_type_font",
65-
true,
66-
],
67-
[
68-
"Fira Code Bold Nerd Font",
69-
"Fira Code Bold Nerd Font",
70-
"file file_type_font",
71-
true,
72-
],
73-
[
74-
"Fira Code Medium Nerd Font",
75-
"Fira Code Medium Nerd Font",
76-
"file file_type_font",
77-
true,
78-
],
79-
[
80-
"JetBrains Mono Bold Nerd Font",
81-
"JetBrains Mono Bold Nerd Font",
82-
"file file_type_font",
83-
true,
84-
],
85-
[
86-
"JetBrains Mono Medium Nerd Font",
87-
"JetBrains Mono Medium Nerd Font",
88-
"file file_type_font",
89-
true,
90-
],
91-
[
92-
"VictorMonoNerdFont Bold",
93-
"VictorMonoNerdFont Bold",
94-
"file file_type_font",
95-
true,
96-
],
97-
[
98-
"VictorMonoNerdFont BoldItalic",
99-
"VictorMonoNerdFont BoldItalic",
100-
"file file_type_font",
101-
true,
102-
],
103-
[
104-
"VictorMonoNerdFont Medium",
105-
"VictorMonoNerdFont Medium",
106-
"file file_type_font",
107-
true,
108-
],
109-
[
110-
"VictorMonoNerdFont Italic",
111-
"VictorMonoNerdFont Italic",
112-
"file file_type_font",
113-
true,
114-
],
115-
[
116-
"SauceCodeProNerdFont Bold",
117-
"SauceCodeProNerdFont Bold",
118-
"file file_type_font",
119-
true,
120-
],
121-
[
122-
"SauceCodeProNerdFont Medium",
123-
"SauceCodeProNerdFont Medium",
124-
"file file_type_font",
125-
true,
126-
],
127-
[
128-
"MesloLGS NF Bold Italic",
129-
"MesloLGS NF Bold Italic",
130-
"file file_type_font",
131-
true,
132-
],
133-
["MesloLGS NF Bold", "MesloLGS NF Bold", "file file_type_font", true],
134-
["MesloLGS NF Italic", "MesloLGS NF Italic", "file file_type_font", true],
135-
["MesloLGS NF Regular", "MesloLGS NF Regular", "file file_type_font", true],
136-
];
13759

13860
export const AI_MODEL = "deepseek";
13961
export const AVAILABLE_AI_MODELS = [
@@ -161,4 +83,4 @@ export const AVAILABLE_AI_MODELS = [
16183
"icon phone_android",
16284
true
16385
]
164-
];
86+
];

0 commit comments

Comments
 (0)