armcord/src/extensions/plugin.ts

21 lines
791 B
TypeScript
Raw Normal View History

2022-03-04 17:53:18 +00:00
import * as fs from "fs";
import {app, session} from "electron";
2021-12-24 21:56:49 +00:00
const userDataPath = app.getPath("userData");
const pluginFolder = userDataPath + "/plugins/";
if (!fs.existsSync(pluginFolder)) {
fs.mkdirSync(pluginFolder);
console.log("Created missing plugin folder");
2022-03-04 17:53:18 +00:00
}
2021-12-24 21:56:49 +00:00
app.whenReady().then(() => {
2022-03-04 17:53:18 +00:00
fs.readdirSync(pluginFolder).forEach((file) => {
try {
const manifest = fs.readFileSync(`${userDataPath}/plugins/${file}/manifest.json`, "utf8");
var pluginFile = JSON.parse(manifest);
session.defaultSession.loadExtension(`${userDataPath}/plugins/${file}`);
console.log(`%cLoaded ${pluginFile.name} made by ${pluginFile.author}`, "color:red");
} catch (err) {
console.error(err);
}
});
2021-12-24 21:56:49 +00:00
});