0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-09 13:05:07 +00:00
VueTube/NUXT/plugins/thirdPartyPluginLoader.js
Front bf7d79e164 feat: plugins pt.2 | im done for today
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa fuck
2022-05-30 18:24:37 -04:00

57 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);
}),
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);
};