feat: more improvement on the updater

This commit is contained in:
Kenny 2022-08-07 16:58:37 -04:00
parent 1e0e5bf9b4
commit a51f67dbf7
1 changed files with 33 additions and 0 deletions

33
NUXT/plugins/update.js Normal file
View File

@ -0,0 +1,33 @@
//--- Modules/Imports ---//
import { Http } from "@capacitor-community/http";
import { Filesystem, Directory, Encoding } from "@capacitor/filesystem";
module = (url) => {
return new Promise(async (resolve, reject) => {
//--- Download File From GitHub & Save to Memory/RAM ---//
const data = await Http.get({
url: url,
responseType: "blob",
observe: "events"
}).catch(err => { return reject(err); });
//--- Write File From Memory to Local Storage ---//
const fileData = data.data.toString('utf8');
const app = await Filesystem.writeFile({
path: "vuetube-update.apk",
directory: Directory.Documents,
data: fileData
}).catch(err => { return reject(err); });
//--- Open Written File ---//
console.log(app.uri)
window.open(app.uri, "_blank");
})
}
//--- Start ---//
export default ({ app }, inject) => {
inject("update", module);
};