Skip to content

Commit 5aed795

Browse files
author
Ajit Kumar
committed
Refactor API calls to use fetch instead of ajax and update configuration imports
- Replaced ajax calls with fetch in sponsor, sponsors, and themeSetting pages. - Updated constants import to config in various files for better configuration management. - Improved error handling for API responses. - Adjusted logic for premium theme checks based on new config settings. - Enhanced cookie management in the Authenticator plugin for better security. - Fixed minor typos and improved code readability across multiple files.
1 parent 0455f86 commit 5aed795

91 files changed

Lines changed: 1795 additions & 1470 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
22
"editor.formatOnSave": true,
3-
"autoimport.doubleQuotes": false,
4-
"java.configuration.updateBuildConfiguration": "disabled",
53
"prettier.requireConfig": true,
6-
"javascript.format.enable": true,
4+
"js/ts.format.enabled": true,
75
"editor.defaultFormatter": "esbenp.prettier-vscode",
86
"prettier.tabWidth": 2,
97
"prettier.useTabs": false,
10-
"javascript.format.semicolons": "insert",
8+
"js/ts.format.semicolons": "insert",
119
"[scss]": {
1210
"editor.defaultFormatter": "vscode.css-language-features"
1311
},
@@ -27,6 +25,13 @@
2725
"attr_quotes": "single"
2826
}
2927
},
28+
"[javascript]": {
29+
"editor.defaultFormatter": "biomejs.biome"
30+
},
31+
"editor.codeActionsOnSave": {
32+
"quickFix.biome": "explicit",
33+
"source.organizeImports.biome": "explicit"
34+
},
3035
"cSpell.words": [
3136
"abap",
3237
"Acode",
@@ -126,6 +131,7 @@
126131
"flac",
127132
"Flix",
128133
"floobits",
134+
"FOXBIZ",
129135
"Foxdebug",
130136
"freemarker",
131137
"gamemaker",
@@ -370,10 +376,9 @@
370376
"wtest",
371377
"wxml",
372378
"wxss",
379+
"xhrs",
380+
"XMLHTTP",
373381
"xquery",
374382
"Zeek"
375-
],
376-
"[javascript]": {
377-
"editor.defaultFormatter": "biomejs.biome"
378-
}
383+
]
379384
}

biome.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@
3939
},
4040
"files": {
4141
"includes": [
42-
"**/src/**/*",
43-
"**/utils/**/*.js",
44-
"!**/www/build/**/*",
45-
"**/www/res/**/*.css",
46-
"**/src/plugins/terminal/**",
47-
"!**/ace-builds",
48-
"!**/src/plugins/**/*",
49-
"!**/plugins/**/*",
50-
"!**/hooks/**/*",
51-
"!**/fastlane/**/*",
52-
"!**/res/**/*",
53-
"!**/platforms/**/*"
42+
"src/**/*.js",
43+
"utils/**/*.js",
44+
"!src/lang/**/*.json",
45+
"!src/plugins/**/*.js",
46+
"!www/**/*",
47+
"!plugins/**/*",
48+
"!hooks/**/*",
49+
"!fastlane/**/*",
50+
"!platforms/**/*"
5451
]
5552
}
5653
}

bun.lock

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

jsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"exclude": ["**/node_modules", "**/platforms", "**/www", "www/js/ace/**/*"],
33
"compilerOptions": {
4-
"baseUrl": "./src",
54
"paths": {
6-
"*": ["*"]
5+
"*": ["./src/*"]
76
}
87
},
98
"include": ["src/**/*"],

package-lock.json

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

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"com.foxdebug.acode.rk.exec.terminal": {},
4242
"com.foxdebug.acode.rk.customtabs": {},
4343
"com.foxdebug.acode.rk.plugin.plugincontext": {},
44-
"com.foxdebug.acode.rk.auth": {},
45-
"cordova-plugin-system": {}
44+
"cordova-plugin-system": {},
45+
"com.foxdebug.acode.rk.auth": {}
4646
},
4747
"platforms": [
4848
"android"
@@ -137,7 +137,6 @@
137137
"@codemirror/state": "^6.6.0",
138138
"@codemirror/theme-one-dark": "^6.1.3",
139139
"@codemirror/view": "^6.40.0",
140-
"@deadlyjack/ajax": "^1.2.6",
141140
"@emmetio/codemirror6-plugin": "^0.4.0",
142141
"@lezer/highlight": "^1.2.3",
143142
"@ungap/custom-elements": "^1.3.0",

src/cm/lsp/serverLauncher.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const STATUS_FAILED: InstallStatus = "failed";
3535

3636
const AXS_BINARY = "$PREFIX/axs";
3737

38+
let alreadyInformed = false;
39+
3840
function getTerminalRequiredMessage(): string {
3941
return (
4042
strings?.terminal_required_message_for_lsp ??
@@ -1081,7 +1083,12 @@ export async function ensureServerRunning(
10811083
} catch {}
10821084
if (!isTerminalInstalled) {
10831085
const message = getTerminalRequiredMessage();
1084-
alert(strings?.error, message);
1086+
1087+
if (!alreadyInformed){
1088+
alreadyInformed = true;
1089+
alert(strings?.error, message);
1090+
}
1091+
10851092
const unavailable: LspError = new Error(message);
10861093
unavailable.code = "LSP_SERVER_UNAVAILABLE";
10871094
throw unavailable;

src/components/sidebar/index.js

Lines changed: 92 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@ import toast from "components/toast";
33
import Ref from "html-tag-js/ref";
44
import actionStack from "lib/actionStack";
55
import auth, { loginEvents } from "lib/auth";
6-
import constants from "lib/constants";
6+
import config from "lib/config";
77

8+
/**
9+
* @typedef {object} SideBar
10+
* @extends HTMLElement
11+
* @property {function():void} hide
12+
* @property {function():void} toggle
13+
* @property {function():void} onshow
14+
*/
15+
16+
/**@type {HTMLElement} */
817
let $sidebar;
918
/**@type {Array<(el:HTMLElement)=>boolean>} */
1019
let preventSlideTests = [];
@@ -14,14 +23,6 @@ const events = {
1423
hide: [],
1524
};
1625

17-
/**
18-
* @typedef {object} SideBar
19-
* @extends HTMLElement
20-
* @property {function():void} hide
21-
* @property {function():void} toggle
22-
* @property {function():void} onshow
23-
*/
24-
2526
/**
2627
* Create a sidebar
2728
* @param {HTMLElement} [$container] - the element that will contain the sidebar
@@ -31,7 +32,7 @@ const events = {
3132
function create($container, $toggler) {
3233
let { innerWidth } = window;
3334

34-
const START_THRESHOLD = constants.SIDEBAR_SLIDE_START_THRESHOLD_PX; //Point where to start swipe
35+
const START_THRESHOLD = config.SIDEBAR_SLIDE_START_THRESHOLD_PX; //Point where to start swipe
3536
const MIN_WIDTH = 200; //Min width of the side bar
3637
const MAX_WIDTH = () => innerWidth * 0.7; //Max width of the side bar
3738
const resizeBar = Ref();
@@ -103,36 +104,53 @@ function create($container, $toggler) {
103104

104105
async function handleUserIconClick(e) {
105106
try {
106-
const isLoggedIn = await auth.isLoggedIn();
107-
108-
if (!isLoggedIn) {
109-
auth.openLoginUrl();
107+
const user = await auth.getLoggedInUser();
108+
109+
if (!user) {
110+
CustomTabs.open(
111+
`${config.BASE_URL}/login?redirect=app`,
112+
{ showTitle: true },
113+
() => {},
114+
() => {},
115+
);
110116
} else {
111-
toggleUserMenu();
117+
const menu = userContextMenu.el;
118+
const isActive = menu.classList.toggle("active");
119+
120+
if (isActive) {
121+
const menuName = userContextMenu.el.querySelector(".user-menu-name");
122+
const menuEmail =
123+
userContextMenu.el.querySelector(".user-menu-email");
124+
125+
if (menuName) {
126+
menuName.content = (
127+
<div style={{ display: "flex" }}>
128+
{Boolean(user.verified) && (
129+
<span className="icon verified"></span>
130+
)}
131+
{user.name}
132+
{Boolean(user.acode_pro) && <span className="badge">Pro</span>}
133+
</div>
134+
);
135+
}
136+
137+
if (menuEmail) {
138+
menuEmail.textContent = user.email || "";
139+
}
140+
141+
setTimeout(() => {
142+
document.addEventListener("click", handleClickOutside);
143+
}, 10);
144+
} else {
145+
document.removeEventListener("click", handleClickOutside);
146+
}
112147
}
113148
} catch (error) {
114149
console.error("Error checking login status:", error);
115150
toast("Error checking login status", 3000);
116151
}
117152
}
118153

119-
function toggleUserMenu() {
120-
const menu = userContextMenu.el;
121-
const isActive = menu.classList.toggle("active");
122-
123-
if (isActive) {
124-
// Populate user info
125-
updateUserMenuInfo();
126-
127-
// Add click outside listener
128-
setTimeout(() => {
129-
document.addEventListener("click", handleClickOutside);
130-
}, 10);
131-
} else {
132-
document.removeEventListener("click", handleClickOutside);
133-
}
134-
}
135-
136154
function handleClickOutside(e) {
137155
if (
138156
!userContextMenu.el.contains(e.target) &&
@@ -144,23 +162,6 @@ function create($container, $toggler) {
144162
}
145163
}
146164

147-
async function updateUserMenuInfo() {
148-
try {
149-
const userInfo = await auth.getUserInfo();
150-
if (userInfo) {
151-
const menuName = userContextMenu.el.querySelector(".user-menu-name");
152-
const menuEmail = userContextMenu.el.querySelector(".user-menu-email");
153-
menuName.textContent = userInfo.name || "Anonymous";
154-
if (userInfo.isAdmin) {
155-
menuName.innerHTML += ' <span class="badge">Admin</span>';
156-
}
157-
menuEmail.textContent = userInfo.email || "";
158-
}
159-
} catch (error) {
160-
console.error("Error fetching user info:", error);
161-
}
162-
}
163-
164165
async function handleLogout() {
165166
try {
166167
const success = await auth.logout();
@@ -178,8 +179,6 @@ function create($container, $toggler) {
178179
}
179180

180181
async function updateSidebarAvatar() {
181-
const avatarUrl = await auth.getAvatar();
182-
// Remove existing icon or avatar
183182
const existingIcon = userAvatar.el.querySelector(".icon");
184183
const existingAvatar = userAvatar.el.querySelector(".avatar");
185184

@@ -190,20 +189,59 @@ function create($container, $toggler) {
190189
existingAvatar.remove();
191190
}
192191

193-
if (avatarUrl?.startsWith("data:") || avatarUrl?.startsWith("http")) {
194-
// Create and add avatar image
192+
const user = await auth.getLoggedInUser();
193+
194+
if (user) {
195+
const avatarUrl = user.github
196+
? `https://avatars.githubusercontent.com/${user.github}`
197+
: generateInitialsAvatar(user.name);
195198
const avatarImg = document.createElement("img");
196199
avatarImg.className = "avatar";
197200
avatarImg.src = avatarUrl;
198201
userAvatar.append(avatarImg);
199202
} else {
200-
// Fallback to default icon
201203
const defaultIcon = document.createElement("span");
202204
defaultIcon.className = "icon account_circle";
203205
userAvatar.append(defaultIcon);
204206
}
205207
}
206208

209+
function generateInitialsAvatar(name) {
210+
const nameParts = name.split(" ");
211+
const initials =
212+
nameParts.length >= 2
213+
? `${nameParts[0][0]}${nameParts[1][0]}`.toUpperCase()
214+
: nameParts[0][0].toUpperCase();
215+
216+
const canvas = document.createElement("canvas");
217+
canvas.width = 100;
218+
canvas.height = 100;
219+
const ctx = canvas.getContext("2d");
220+
221+
const colors = [
222+
"#2196F3",
223+
"#9C27B0",
224+
"#E91E63",
225+
"#009688",
226+
"#4CAF50",
227+
"#FF9800",
228+
];
229+
ctx.fillStyle =
230+
colors[
231+
name.split("").reduce((acc, char) => acc + char.charCodeAt(0), 0) %
232+
colors.length
233+
];
234+
ctx.fillRect(0, 0, 100, 100);
235+
236+
ctx.fillStyle = "#ffffff";
237+
ctx.font = "bold 40px Arial";
238+
ctx.textAlign = "center";
239+
ctx.textBaseline = "middle";
240+
ctx.fillText(initials, 50, 50);
241+
242+
return canvas.toDataURL();
243+
}
244+
207245
function onWindowResize() {
208246
clearTimeout(resizeTimeout);
209247
resizeTimeout = setTimeout(() => {

0 commit comments

Comments
 (0)