VueTube/NUXT/plugins/thirdPartyPluginLoader.js

68 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;
const ensureStructure = new Promise(async (resolve, reject) => {
/*
const perms = await Filesystem.checkPermissions();
if (perms.publicStorage !== "granted") {
perms = await Filesystem.requestPermissions();
}
// Legacy shit that isnt supported on android 10+ */
//--- Ensure Plugins Folder ---//
try {
await Filesystem.mkdir({
directory: APP_DIRECTORY, recursive: true,
path: fs.plugins,
});
} 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: fs.plugins,
2022-05-30 17:54:29 +00:00
directory: APP_DIRECTORY
});
2022-05-30 17:54:29 +00:00
resolve(plugins);
}),
debug(path) { return new Promise(async (resolve, reject) => {
if (await !ensureStructure) reject("Invalid Structure");
const plugins = await Filesystem.readdir({
path: path,
directory: APP_DIRECTORY
});
resolve(plugins);
})}
};
//--- Start ---//
export default ({ app }, inject) => {
inject("tppl", module);
};