Re-do plugin/theme loading. Move plugins/themes to userdata

This commit is contained in:
smartfridge 2021-06-30 14:42:36 +02:00
parent 1d84e24825
commit 0aa6e1399c
19 changed files with 820 additions and 436 deletions

View file

@ -101,7 +101,7 @@ function createWindow() {
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow();
require("./utils/csp.js");
//require("./utils/csp.js");
require("./utils/plugin.js");
session
.fromPartition("some-partition")

953
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -18,6 +18,7 @@
"electron-context-menu": "^3.0.0",
"electron-localshortcut": "^3.2.1",
"electron-store": "^8.0.0",
"unzipper": "^0.10.1",
"v8-compile-cache": "^2.3.0"
},
"devDependencies": {

View file

@ -1,17 +1,57 @@
const fs = require("fs");
const { app, session } = require("electron");
const pluginFolder = __dirname + "/plugins/";
const electron = require("electron");
const userDataPath = (electron.app || electron.remote.app).getPath("userData");
const pluginFolder = userDataPath + "/plugins/";
if (!fs.existsSync(pluginFolder)) {
fs.mkdirSync(pluginFolder);
console.log("Created plugin folder")
try {
console.log("Attempting to download GooseMod Extension")
const https = require("https");
function download(url, dest, cb) {
const file = fs.createWriteStream(dest);
const request = https
.get(url, function (response) {
response.pipe(file);
file.on("finish", function () {
file.close(cb); // close() is async, call cb after close completes.
});
})
.on("error", function (err) {
// Handle errors
fs.unlink(dest); // Delete the file async. (But we don't check the result)
if (cb) cb(err.message);
});
}
// Download latest archive from GitHub to temp folder
const dest = userDataPath + "/Cache/GooseMod.zip";
const url =
"https://codeload.github.com/GooseMod/Extension/zip/refs/heads/main";
download(url, dest, function () {
console.log("Downloaded, attempting to install.");
const unzip = require("unzipper")
fs.createReadStream(dest).pipe(unzip.Extract({ path: pluginFolder }));
console.log("Success! GooseMod will start on next session!")
});
}
catch (e){
console.error(`GooseMod failed to download. Error: ${e}`)
}
}
app.whenReady().then(() => {
fs.readdirSync(pluginFolder).forEach((file) => {
console.log(file);
try {
const manifest = fs.readFileSync(
`${__dirname}/plugins/${file}/manifest.json`,
`${userDataPath}/plugins/${file}/manifest.json`,
"utf8"
);
var pluginFile = JSON.parse(manifest);
console.log(pluginFile);
session.defaultSession.loadExtension(`${__dirname}\\plugins\\${file}`);
session.defaultSession.loadExtension(`${userDataPath}/plugins/${file}`);
console.log(
`%cLoaded ${pluginFile.name} made by ${pluginFile.author}`,
"color:red"

View file

@ -1 +0,0 @@
web-ext-artifacts

View file

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2021 GooseMod
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,17 +0,0 @@
<h1 align="center">
<sub>
<img src="https://raw.githubusercontent.com/GooseMod/Extension/main/icons/48.png" height="38" width="38">
</sub>
GooseMod for Web
</h1>
<p align="center">
<a href="https://addons.mozilla.org/addon/goosemod-for-web/"><img src="https://user-images.githubusercontent.com/585534/107280546-7b9b2a00-6a26-11eb-8f9f-f95932f4bfec.png" alt="Get GooseMod for Web for Firefox"></a>
<a href="https://chrome.google.com/webstore/detail/goosemod-for-web/clgkdcccmbjmjdbdgcigpocfkkjeaeld"><img src="https://user-images.githubusercontent.com/585534/107280622-91a8ea80-6a26-11eb-8d07-77c548b28665.png" alt="Get GooseMod for Web for Chromium"></a>
</p>
***
<p align="center">
<strong>A light, secure, and easy to use Discord mod; now in your browser.</strong>
</p>

View file

@ -1,32 +0,0 @@
const cspAllowAll = [
'connect-src',
'style-src',
'img-src',
'font-src'
];
chrome.webRequest.onHeadersReceived.addListener(({ responseHeaders, url }) => {
let csp = responseHeaders.find((x) => x.name === 'content-security-policy');
if (csp) {
for (let p of cspAllowAll) {
csp.value = csp.value.replace(`${p}`, `${p} * blob: data:`); // * does not include data: URIs
}
// Fix Discord's broken CSP which disallows unsafe-inline due to having a nonce (which they don't even use?)
csp.value = csp.value.replace(/'nonce-.*?' /, '');
}
return {
responseHeaders
};
},
{
urls: [
'*://*.discord.com/*'
]
},
['blocking', 'responseHeaders']
);

View file

@ -1,49 +0,0 @@
const inject = async () => {
console.log('[GooseMod for Web] Injecting...');
// Re-define localStorage as Discord removes it
function getLocalStoragePropertyDescriptor() {
const frame = document.createElement('frame');
frame.src = 'about:blank';
document.body.appendChild(frame);
let r = Object.getOwnPropertyDescriptor(frame.contentWindow, 'localStorage');
frame.remove();
return r;
}
Object.defineProperty(window, 'localStorage', getLocalStoragePropertyDescriptor());
console.log('[GooseMod for Web] Redefined localStorage');
const branchURLs = {
'release': 'https://api.goosemod.com/inject.js',
'dev': 'https://updates.goosemod.com/guapi/goosemod/dev'
};
const branch = localStorage.getItem('goosemodUntetheredBranch') || 'release';
console.log('[GooseMod for ArmCord] Branch =', branch);
console.log('[GooseMod for ArmCord] JS Url =', branchURLs[branch]);
const js = await (await fetch(branchURLs[branch])).text(); // JSON.parse(localStorage.getItem('goosemodCoreJSCache'));
const el = document.createElement('script');
el.appendChild(document.createTextNode(js));
document.body.appendChild(el);
console.log('[GooseMod for ArmCord] Injected fetched JS');
};
// Delay actual injection to fix FF issues
let el = document.createElement('script');
el.appendChild(document.createTextNode(`(${inject.toString()})()`));
document.body.appendChild(el);

View file

@ -1,37 +0,0 @@
{
"name": "GooseMod for ArmCord",
"description": "A light, secure, and easy to use Discord mod; now in your browser.",
"version": "1.1.0",
"author": "GooseMod Team",
"homepage_url": "https://goosemod.com",
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"matches": ["*://*.discord.com/*"],
"js": ["content.js"]
}
],
"permissions": [
"webRequest",
"webRequestBlocking",
"*://*.discord.com/*"
],
"manifest_version": 2,
"browser_specific_settings": {
"gecko": {
"id": "invalid@goosemod.com"
}
}
}

View file

@ -1,18 +1,23 @@
const fs = require("fs");
const {shell} = require('electron');
const electron = require("electron");
const ArmCord = require("./ArmCord.js");
const themeFolder = __dirname + "/themes/";
const userDataPath = (electron.app || electron.remote.app).getPath("userData");
const themeFolder = userDataPath + "/themes/";
if (!fs.existsSync(themeFolder)) {
fs.mkdirSync(themeFolder);
console.log("Created theme folder");
}
window.addEventListener("DOMContentLoaded", () => {
console.log("Theme Module Loaded");
fs.readdirSync(themeFolder).forEach((file) => {
console.log(file);
try {
const manifest = fs.readFileSync(`${__dirname}/themes/${file}/manifest.json`, "utf8");
const manifest = fs.readFileSync(`${userDataPath}/themes/${file}/manifest.json`, "utf8");
var themeFile = JSON.parse(manifest);
console.log(themeFile.theme);
console.log(themeFile)
const theme = fs.readFileSync(`${__dirname}/themes/${file}/${themeFile.theme}`, "utf8");
const theme = fs.readFileSync(`${userDataPath}/themes/${file}/${themeFile.theme}`, "utf8");
if (themeFile.theme.endsWith(".scss")) {
console.log(
`%cCouldn't load ${themeFile.name} made by ${themeFile.author}. ArmCord doesn't support SCSS files! If you want to have this theme ported, feel free to reach out https://discord.gg/F25bc4RYDt `,
@ -27,7 +32,7 @@ window.addEventListener("DOMContentLoaded", () => {
console.error(err);
}
});
document.getElementById("open-themes-btn").onclick = function () {shell.openPath(`${__dirname}/themes`);};
document.getElementById("open-themes-btn").onclick = function () {shell.openPath(`${userDataPath}/themes`);};
document.getElementsByClassName("back-btn")[0].onclick = function () {
if (document.getElementById("ac-channel").innerHTML == "stable") {
window.location.href = "https://discord.com/app";

View file

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2021 GooseNest
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,3 +0,0 @@
# GT-RevertRebrand ArmCord
Reverts Discord's 2021 rebrand (font, colors, reactions, mentions, loading screen, home icon, reply ping color, and more)

View file

@ -1,9 +0,0 @@
/**
* @name Revert Rebrand
* @author GooseNest
* @description Reverts Discord's 2021 rebrand (font, colors, reactions, mentions, loading screen, home icon, reply ping color, and more)
* @invite neMncS2
* @version 3.0
*/
@import url('https://Goose-Nest.github.io/GT-RevertRebrand/src/main.css');

View file

@ -1,8 +0,0 @@
{
"name": "Revert Rebrand",
"description": "Reverts Discord's 2021 rebrand (font, colors, reactions, mentions, loading screen, home icon, reply ping color, and more)",
"version": "3.0",
"author": "GooseNest",
"license": "MIT",
"theme": "RevertRebrand.theme.css"
}

View file

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2021 GooseNest
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,3 +0,0 @@
# GT-RevertRebrand ArmCord
Reverts Discord's 2021 rebrand (font, colors, reactions, mentions, loading screen, home icon, reply ping color, and more)

View file

@ -1,9 +0,0 @@
/**
* @name Revert Rebrand
* @author GooseNest
* @description Reverts Discord's 2021 rebrand (font, colors, reactions, mentions, loading screen, home icon, reply ping color, and more)
* @invite neMncS2
* @version 3.0
*/
@import url('https://Goose-Nest.github.io/GT-RevertRebrand/src/main.css');

View file

@ -1,8 +0,0 @@
{
"name": "Test Theme",
"description": "A test description (For theme seperation)",
"version": "3.0",
"author": "KayoticCarnige",
"license": "MIT",
"theme": "RevertRebrand.theme.css"
}