From 5780cc23c233500ac0ebb0bb52dbc0fe3acbb610 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Sat, 8 Oct 2022 17:00:18 -0400 Subject: [PATCH] Fix freezing api and add updater css --- .travis.yml | 31 ----------------------------- renderer/src/index.js | 6 +++++- renderer/src/modules/api/data.js | 29 +++++++++++++++++++-------- renderer/src/modules/api/dom.js | 21 ++++++++++++++----- renderer/src/modules/api/patcher.js | 29 +++++++++++++++++++++------ renderer/src/styles/ui/updater.css | 23 +++++++++++++++++++++ 6 files changed, 88 insertions(+), 51 deletions(-) delete mode 100644 .travis.yml create mode 100644 renderer/src/styles/ui/updater.css diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 64e56fa3..00000000 --- a/.travis.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/renderer/src/index.js b/renderer/src/index.js index 65173ca5..674b2d6d 100644 --- a/renderer/src/index.js +++ b/renderer/src/index.js @@ -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 diff --git a/renderer/src/modules/api/data.js b/renderer/src/modules/api/data.js index b72f873f..00734d45 100644 --- a/renderer/src/modules/api/data.js +++ b/renderer/src/modules/api/data.js @@ -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; \ No newline at end of file diff --git a/renderer/src/modules/api/dom.js b/renderer/src/modules/api/dom.js index b496e786..b30f1351 100644 --- a/renderer/src/modules/api/dom.js +++ b/renderer/src/modules/api/dom.js @@ -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; \ No newline at end of file diff --git a/renderer/src/modules/api/patcher.js b/renderer/src/modules/api/patcher.js index 00cf1363..fc8526a5 100644 --- a/renderer/src/modules/api/patcher.js +++ b/renderer/src/modules/api/patcher.js @@ -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} 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; \ No newline at end of file diff --git a/renderer/src/styles/ui/updater.css b/renderer/src/styles/ui/updater.css new file mode 100644 index 00000000..816e699c --- /dev/null +++ b/renderer/src/styles/ui/updater.css @@ -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; +} \ No newline at end of file