Fix freezing api and add updater css

This commit is contained in:
Zack Rauen 2022-10-08 17:00:18 -04:00
parent 32bf2be211
commit 5780cc23c2
6 changed files with 88 additions and 51 deletions

View File

@ -1,31 +0,0 @@
language: node_js
node_js:
- "node"
git:
autocrlf: true
branches:
only:
- development
install:
- npm ci
script:
- npm run lint-prod
- npm run test-prod
- npm run deploy
before_deploy: "echo 'node_modules' > .gitignore"
deploy:
provider: pages
skip_cleanup: true
github_token: $TRAVIS_ACCESS
keep_history: true
local_dir: .
name: BetterDiscord Deployment
target_branch: gh-pages-development
on:
branch: development

View File

@ -6,7 +6,11 @@ import BdApi from "./modules/api/index";
// Perform some setup
secure();
window.BdApi = BdApi;
Object.defineProperty(window, "BdApi", {
value: BdApi,
writable: false,
configurable: false
});
window.global = window;
// Add loading icon at the bottom right

View File

@ -8,11 +8,11 @@ import DataStore from "../datastore";
*/
class Data {
#callerName = "";
constructor(callerName) {
if (!callerName) return;
this.save = this.save.bind(this, callerName);
this.load = this.load.bind(this, callerName);
this.delete = this.delete.bind(this, callerName);
this.#callerName = callerName;
}
/**
@ -24,6 +24,11 @@ class Data {
* @returns
*/
save(pluginName, key, data) {
if (this.#callerName) {
data = key;
key = pluginName;
pluginName = this.#callerName;
}
return DataStore.setPluginData(pluginName, key, data);
}
@ -34,8 +39,12 @@ class Data {
* @param {string} key Which piece of data to load
* @returns {any} The stored data
*/
load(pluginName, key, data) {
return DataStore.setPluginData(pluginName, key, data);
load(pluginName, key) {
if (this.#callerName) {
key = pluginName;
pluginName = this.#callerName;
}
return DataStore.getPluginData(pluginName, key);
}
/**
@ -44,12 +53,16 @@ class Data {
* @param {string} pluginName Name of the plugin deleting data
* @param {string} key Which piece of data to delete
*/
delete(pluginName, key, data) {
return DataStore.setPluginData(pluginName, key, data);
delete(pluginName, key) {
if (this.#callerName) {
key = pluginName;
pluginName = this.#callerName;
}
return DataStore.deletePluginData(pluginName, key);
}
}
Object.freeze(Data);
Object.freeze(Data.prototype);
export default Data;

View File

@ -14,10 +14,11 @@ class DOM {
/** Document/window height */
get screenHeight() {return Math.max(document.documentElement.clientHeight, window.innerHeight || 0);}
#callerName = "";
constructor(callerName) {
if (!callerName) return;
this.addStyle = this.addStyle.bind(this, callerName);
this.removeStyle = this.removeStyle.bind(this, callerName);
this.#callerName = callerName;
}
/**
@ -27,10 +28,14 @@ class DOM {
* @param {string} css CSS to apply to the document
*/
addStyle(id, css) {
if (arguments.length === 3) {
if (this.#callerName && arguments.length === 2) {
id = arguments[1];
css = arguments[2];
}
else if (this.#callerName) {
css = id;
id = this.#callerName;
}
DOMManager.injectStyle(id, css);
}
@ -41,7 +46,13 @@ class DOM {
* @param {string} id ID uses for the style element
*/
removeStyle(id) {
if (arguments.length === 2) id = arguments[1];
if (this.#callerName && arguments.length === 1) {
id = arguments[1];
}
else if (this.#callerName) {
id = this.#callerName;
}
DOMManager.removeStyle(id);
}
@ -97,5 +108,5 @@ class DOM {
}
Object.freeze(DOM);
Object.freeze(DOM.prototype);
export default DOM;

View File

@ -10,13 +10,10 @@ import {default as MainPatcher} from "../patcher";
*/
class Patcher {
#callerName = "";
constructor(callerName) {
if (!callerName) return;
this.before = this.before.bind(this, callerName);
this.instead = this.instead.bind(this, callerName);
this.after = this.after.bind(this, callerName);
this.getPatchesByCaller = this.getPatchesByCaller.bind(this, callerName);
this.unpatchAll = this.unpatchAll.bind(this, callerName);
this.#callerName = callerName;
}
/**
@ -29,6 +26,12 @@ class Patcher {
* @returns {function} Function that cancels the original patch.
*/
before(caller, moduleToPatch, functionName, callback) {
if (this.#callerName) {
callback = functionName;
functionName = moduleToPatch;
moduleToPatch = caller;
caller = this.#callerName;
}
return MainPatcher.pushChildPatch(caller, moduleToPatch, functionName, callback, {type: "before"});
}
@ -42,6 +45,12 @@ class Patcher {
* @returns {function} Function that cancels the original patch.
*/
instead(caller, moduleToPatch, functionName, callback) {
if (this.#callerName) {
callback = functionName;
functionName = moduleToPatch;
moduleToPatch = caller;
caller = this.#callerName;
}
return MainPatcher.pushChildPatch(caller, moduleToPatch, functionName, callback, {type: "instead"});
}
@ -55,6 +64,12 @@ class Patcher {
* @returns {function} Function that cancels the original patch.
*/
after(caller, moduleToPatch, functionName, callback) {
if (this.#callerName) {
callback = functionName;
functionName = moduleToPatch;
moduleToPatch = caller;
caller = this.#callerName;
}
return MainPatcher.pushChildPatch(caller, moduleToPatch, functionName, callback, {type: "after"});
}
@ -64,6 +79,7 @@ class Patcher {
* @returns {Array<function>} Array of all the patch objects.
*/
getPatchesByCaller(caller) {
if (this.#callerName) caller = this.#callerName;
if (typeof(caller) !== "string") return Logger.err("BdApi.Patcher", "Parameter 0 of getPatchesByCaller must be a string representing the caller");
return MainPatcher.getPatchesByCaller(caller);
}
@ -73,11 +89,12 @@ class Patcher {
* @param {string} caller ID of the original patches
*/
unpatchAll(caller) {
if (this.#callerName) caller = this.#callerName;
if (typeof(caller) !== "string") return Logger.err("BdApi.Patcher", "Parameter 0 of unpatchAll must be a string representing the caller");
MainPatcher.unpatchAll(caller);
}
}
Object.freeze(Patcher);
Object.freeze(Patcher.prototype);
export default Patcher;

View File

@ -0,0 +1,23 @@
.bd-filled-checkmark {
background: #43B581;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
padding: 3px;
}
.bd-empty-updates {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: var(--header-primary);
font-weight: 500;
font-size: 16px;
}
.bd-empty-updates svg {
fill: #43B581;
margin-bottom: 20px;
}