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

74 lines
1.6 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;
Filesystem.readdir({
path: fs.plugins,
directory: APP_DIRECTORY,
})
.then(res => {
resolve(res);
})
.catch(err => {
reject(err);
});
}),
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,
});
2022-07-12 20:05:54 +00:00
resolve();
});
},
2022-07-12 20:05:54 +00:00
async removePlugin(name) {
await ensureStructure;
new Promise(async (resolve, reject) => {
await Filesystem.deleteFile({
path: fs.plugins + name,
directory: APP_DIRECTORY,
});
resolve();
});
},
};
//--- Start ---//
export default ({ app }, inject) => {
inject("tppl", module);
};