0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-22 19:25:16 +00:00
VueTube/NUXT/plugins/thirdPartyPluginLoader.js
Kenny 38d67fbf97 feat: Major Language Overhaul
Performance Optimisations, Fix Plugin Loader Bugs, Add More Translations, Fix Translation Related Bugs
2022-06-15 15:00:26 -04:00

59 lines
1.3 KiB
JavaScript

//--- 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 = {
//--- List Plugins ---//
list: new Promise(async (resolve, reject) => {
await ensureStructure;
const plugins = await Filesystem.readdir({
path: fs.plugins,
directory: APP_DIRECTORY
}).catch(err => { reject(err) })
resolve(plugins);
}),
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);
};