0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-01 09:22:39 +00:00
VueTube/NUXT/plugins/vuetube.js
2022-05-02 16:01:48 +12:00

139 lines
3.3 KiB
JavaScript

//--- Modules/Imports ---//
import { Http } from "@capacitor-community/http";
import { StatusBar, Style } from "@capacitor/status-bar";
import { NavigationBar } from "@hugotomazi/capacitor-navigation-bar";
import constants from "./constants";
import { hexToRgb, rgbToHex, parseEmoji } from "./utils";
import { Haptics, ImpactStyle } from "@capacitor/haptics";
import Vue from "vue";
import backHandler from "./classes/backHander";
Vue.directive("emoji", {
inserted: function (el) {
const twemojiParse = parseEmoji(el.innerHTML);
if (twemojiParse) el.innerHTML = twemojiParse;
},
});
let backActions = new backHandler();
const module = {
//--- Get GitHub Commits ---//
commits: new Promise((resolve, reject) => {
Http.request({
method: "GET",
url: `${constants.URLS.VT_GITHUB}/commits`,
params: {},
})
.then((res) => {
resolve(res.data);
})
.catch((err) => {
reject(err);
});
}),
getRuns(item, callback) {
let url = `${constants.URLS.VT_GITHUB}/commits/${item.sha}/check-runs`;
Http.request({
method: "GET",
url: url,
params: {},
})
.then((res) => {
callback(res.data);
})
.catch((err) => {
callback(err);
});
},
haptics: {
async hapticsImpactHeavy(x) {
await Haptics.impact({ style: ImpactStyle.Heavy, duration: x });
},
async hapticsImpactMedium(x) {
await Haptics.impact({ style: ImpactStyle.Medium, duration: x });
},
async hapticsImpactLight(x) {
await Haptics.impact({ style: ImpactStyle.Light, duration: x });
},
async hapticsVibrate(x) {
await Haptics.vibrate(x);
},
},
statusBar: {
async hide() {
return await StatusBar.hide();
},
async show() {
return await StatusBar.show();
},
async setLight() {
return await StatusBar.setStyle({ style: Style.Light });
},
async setDark() {
return await StatusBar.setStyle({ style: Style.Dark });
},
async setTransparent() {
return StatusBar.setOverlaysWebView({ overlay: true });
},
async setBackground(color) {
return await StatusBar.setBackgroundColor({ color });
},
async setTheme(color, dark) {
dark
? StatusBar.setStyle({ style: Style.Dark })
: StatusBar.setStyle({ style: Style.Light });
StatusBar.setBackgroundColor({ color });
},
},
navigationBar: {
async hide() {
return await NavigationBar.hide();
},
async show() {
return await NavigationBar.show();
},
async setTheme(color, darkButtons) {
return await NavigationBar.setColor({ color, darkButtons });
},
async setTransparent() {
return NavigationBar.setTransparency({ isTransparent: true });
},
},
hexToRgb(hex) {
return hexToRgb(hex);
},
rgbToHex(r, g, b) {
return rgbToHex(r, g, b);
},
resetBackActions() {
backActions = new backHandler();
},
addBackAction(callback, condition = true) {
backActions.addAction(() => {
if (condition) {
callback();
return true
} else {
return false
}
});
},
back(listenerFunc) {
backActions.back(listenerFunc);
}
};
//--- Start ---//
export default ({ app }, inject) => {
inject("vuetube", module);
};