armcord/src/extensions/plugin.ts

21 lines
774 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`;
2021-12-24 21:56:49 +00:00
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(`${pluginFolder}/${file}/manifest.json`, "utf8");
const pluginFile = JSON.parse(manifest);
session.defaultSession.loadExtension(`${pluginFolder}/${file}`);
2022-11-19 17:23:28 +00:00
console.log(`[Mod loader] Loaded ${pluginFile.name} made by ${pluginFile.author}`);
2022-03-04 17:53:18 +00:00
} catch (err) {
console.error(err);
}
});
2021-12-24 21:56:49 +00:00
});