VueTube/NUXT/plugins/thirdPartyPluginLoader.js

62 lines
1.2 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.Documents;
const ensureStructure = new Promise(async (resolve, reject) => {
const perms = await Filesystem.checkPermissions();
if (perms.publicStorage !== "granted") {
perms = await Filesystem.requestPermissions();
}
//--- Ensure Plugins Folder ---//
try {
await Filesystem.mkdir({
directory: APP_DIRECTORY, recursive: true,
path: fs.plugins,
});
} catch (e) { /* Exists */ }
//--- Ensure Temp Folder ---//
try {
await Filesystem.mkdir({
directory: APP_DIRECTORY, recursive: true,
path: fs.temp,
});
} catch (e) { /* Exists */ }
perms
? resolve(true)
: reject(false)
})
const module = {
2022-05-30 17:54:29 +00:00
//--- List Plugins ---//
list: new Promise(async (resolve, reject) => {
if (await !ensureStructure) reject("Invalid Structure");
2022-05-30 17:54:29 +00:00
const plugins = await Filesystem.readdir({
path: "vuetube/plugins/",
directory: APP_DIRECTORY
});
2022-05-30 17:54:29 +00:00
resolve(plugins);
2022-05-30 17:54:29 +00:00
})
};
//--- Start ---//
export default ({ app }, inject) => {
inject("tppl", module);
};