Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
overskul committed Dec 29, 2024
1 parent 51e83e4 commit d69a300
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 46 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "better-github-dark",
"version": "1.0.0",
"description": "Better GitHub Dark is a Acode plugin Editor theme for more beautiful colors",
"version": "1.1.0",
"description": "Better GitHub Dark is a Acode plugin Editor theme based on GitHub Dark theme",
"main": "dist/main.js",
"repository": "https://github.com/NezitX/acode-better-github-dark.git",
"author": "NezitX",
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id":"x.better.githubdark",
"name":"Better Github Dark",
"main":"./main.js",
"version":"1.0.0",
"version":"1.1.0",
"readme":"readme.md",
"icon":"./assets/better-githubdark-icon.png",
"minVersionCode" : 290,
Expand Down
13 changes: 10 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
![image](https://raw.githubusercontent.com/NezitX/acode-better-github-dark/refs/heads/main/assets/better-githubdark-logo.png)

Better GitHub Dark is a [Acode Plugin](https://acode.app/plugin-docs/) theme based on [Ace](https://ace.c9.io/) GitHub Dark theme.
![GitHub Repo Shield](https://img.shields.io/github/repo-size/NezitX/acode-better-github-dark?color=pink&label=Size&style=for-the-badge)
![License](https://img.shields.io/github/license/NezitX/acode-better-github-dark?color=pink&style=for-the-badge)
![GitHub Stars](https://img.shields.io/github/stars/NezitX/acode-better-github-dark?color=pink&style=for-the-badge)
![Version](https://img.shields.io/github/v/release/NezitX/acode-better-github-dark?color=pink&style=for-the-badge)

<div align="center">
<p>Better GitHub Dark is a <a href="https://acode.app/">Acode</a> plugin theme based on <a href="https://ace.c9.io/">Ace</a> GitHub Dark theme.</p>
</div>

## Preview
![image](https://raw.githubusercontent.com/NezitX/acode-better-github-dark/refs/heads/main/assets/example.png)

## Note
this project is fork from [acode editorTheme template](https://github.com/legendSabbir/acode-editorTheme-template/) thanks for the template.
## License
this plugin is under [MIT LICENSE](./LICENSE)
111 changes: 72 additions & 39 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,126 @@ import style from "./style.scss";

const settings = acode.require("settings");
const { editor } = editorManager;
const themesList = ace.require("ace/ext/themelist").themes;

const THEME_NAME = "better-github-dark";
const THEME_IS_DARK = true;

// Define theme CSS first
ace.define(
`ace/theme/${THEME_NAME}.css`,
["require", "exports", "module"],
function (require, exports, module) {
(require, exports, module) => {
module.exports = style;
}
);

// Simplified theme definition
ace.define(
`ace/theme/${THEME_NAME}`,
[
"require",
"exports",
"module",
`ace/theme/${THEME_NAME}.css`,
"ace/lib/dom"
],
function (require, exports, module) {
["require", "exports", "module", "ace/lib/dom"],
(require, exports, module) => {
const dom = require("ace/lib/dom");

exports.isDark = THEME_IS_DARK;
exports.cssClass = `ace-${THEME_NAME}`;
exports.cssText = require(`./${THEME_NAME}.css`);
const dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass, false);
exports.cssText = style;

// Use setTimeout to defer DOM manipulation
setTimeout(() => {
dom.importCssString(exports.cssText, exports.cssClass, false);
}, 0);
}
);

(function () {
window.require([`ace/theme/${THEME_NAME}`], function (m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();

class BetterGithubDark {
async init() {
constructor() {
this.onThemeChange = this.onThemeChange.bind(this);
this.initialized = false;
}

async init($page, cacheFile, cacheFileUrl) {
if (this.initialized) return;

try {
ace.require("ace/ext/themelist").themes.push({
caption: THEME_NAME.split("-")
.map(name => name[0].toUpperCase() + name.slice(1))
.join(" "),
theme: "ace/theme/" + THEME_NAME,
// Add theme to the list
const themeCaption = THEME_NAME.split("-")
.map(name => name[0].toUpperCase() + name.slice(1))
.join(" ");

const themeEntry = {
caption: themeCaption,
theme: `ace/theme/${THEME_NAME}`,
isDark: THEME_IS_DARK
});
};

if (!themesList.some(theme => theme.theme === themeEntry.theme)) {
themesList.push(themeEntry);
}

// Set theme if it's currently selected
const currentTheme = settings.get("editorTheme");
if (currentTheme === THEME_NAME)
editor.setTheme("ace/theme/" + THEME_NAME);
settings.on("update", this.onThemeChange.bind(this));
if (currentTheme === THEME_NAME) {
// Defer theme setting
setTimeout(() => {
editor.setTheme(`ace/theme/${THEME_NAME}`);
}, 0);
}

// Add event listener
settings.on("update", this.onThemeChange);
this.initialized = true;
} catch (error) {
console.error(error);
console.error("Theme initialization error:", error);
acode.alert("Warning", "Please restart acode");
}
}

async destroy() {
if (!this.initialized) return;

settings.off("update", this.onThemeChange);

const themeIndex = themesList.findIndex(
t => t.theme === `ace/theme/${THEME_NAME}`
);

if (themeIndex !== -1) {
themesList.splice(themeIndex, 1);
}

this.initialized = false;
}

onThemeChange(value) {
if (typeof value !== "string") return;

let themeName = value;
if (value.startsWith("ace/theme/"))
themeName = value?.replace("ace/theme/", "");
if (value.startsWith("ace/theme/")) {
themeName = value.replace("ace/theme/", "");
}

editor.setTheme(`ace/theme/${themeName}`);
settings.update({ editorTheme: themeName });
// Defer theme setting
setTimeout(() => {
editor.setTheme(`ace/theme/${themeName}`);
settings.update({ editorTheme: themeName });
}, 0);
}
}

// Plugin initialization
if (window.acode) {
const betterGithubDark = new BetterGithubDark();

acode.setPluginInit(
plugin.id,
async (baseUrl, $page, { cacheFileUrl, cacheFile }) => {
if (!baseUrl.endsWith("/")) baseUrl += "/";

betterGithubDark.baseUrl = baseUrl;
betterGithubDark.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
await betterGithubDark.init($page, cacheFile, cacheFileUrl);
}
);

acode.setPluginUnmount(plugin.id, () => {
betterGithubDark.destroy();
});
}
}
2 changes: 1 addition & 1 deletion src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ $theme-colors: (
background-color: transparent;
color: map.get($theme-colors, "warning");
}
}
}

0 comments on commit d69a300

Please sign in to comment.