0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-01 09:22:39 +00:00
VueTube/NUXT/plugins/thirdPartyPluginLoader.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

//--- Modules/Imports ---//
import { Filesystem, Directory, Encoding } from "@capacitor/filesystem";
import { fs } from "./constants";
//--- Set Up App Directory ---//
const APP_DIRECTORY = Directory.Data;
//--- Ensure Plugins Folder ---//
const ensureStructure = new Promise(async (resolve, reject) => {
try {
await Filesystem.mkdir({
directory: APP_DIRECTORY,
recursive: true,
path: fs.plugins,
});
} catch (e) {
/* Exists */
}
resolve();
});
const module = {
2022-05-30 17:54:29 +00:00
//--- List Plugins ---//
list: new Promise(async (resolve, reject) => {
await ensureStructure;
2022-05-30 17:54:29 +00:00
const plugins = await Filesystem.readdir({
path: fs.plugins,
directory: APP_DIRECTORY,
}).catch((err) => {
reject(err);
});
2022-05-30 17:54:29 +00:00
resolve(plugins);
}),
2022-05-31 14:01:40 +00:00
async addPlugin(content) {
await ensureStructure;
new Promise(async (resolve, reject) => {
const fileName = require("./utils").getCpn(); // Im not sure what this is actually meant for but im using it as a random string generator
console.log("Saving Plugin As" + fileName);
await Filesystem.writeFile({
path: fs.plugins + "/" + fileName + ".js",
directory: APP_DIRECTORY,
data: content,
encoding: Encoding.UTF8,
});
});
},
};
//--- Start ---//
export default ({ app }, inject) => {
inject("tppl", module);
};