2022-03-07 14:36:23 +00:00
//--- Modules/Imports ---//
2022-03-21 23:47:11 +00:00
import { Http } from "@capacitor-community/http" ;
import { StatusBar , Style } from "@capacitor/status-bar" ;
2022-03-23 00:37:17 +00:00
import { NavigationBar } from "@hugotomazi/capacitor-navigation-bar" ;
2022-03-21 23:47:11 +00:00
import constants from "./constants" ;
2022-04-13 10:15:26 +00:00
import { hexToRgb , rgbToHex , parseEmoji } from "./utils" ;
2022-03-31 23:33:39 +00:00
import { Haptics , ImpactStyle } from "@capacitor/haptics" ;
2022-04-13 10:15:26 +00:00
import Vue from "vue" ;
2022-05-02 04:01:48 +00:00
import backHandler from "./classes/backHander" ;
2022-04-13 10:15:26 +00:00
Vue . directive ( "emoji" , {
inserted : function ( el ) {
const twemojiParse = parseEmoji ( el . innerHTML ) ;
if ( twemojiParse ) el . innerHTML = twemojiParse ;
} ,
} ) ;
2022-03-07 14:36:23 +00:00
2022-05-03 11:07:40 +00:00
let backActions ;
2022-05-02 04:01:48 +00:00
2022-03-07 14:36:23 +00:00
const module = {
2022-03-21 23:47:11 +00:00
//--- 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 ) ;
} ) ;
} ) ,
2022-03-07 14:36:23 +00:00
2022-03-21 23:47:11 +00:00
getRuns ( item , callback ) {
let url = ` ${ constants . URLS . VT _GITHUB } /commits/ ${ item . sha } /check-runs ` ;
2022-03-17 05:57:28 +00:00
2022-03-21 23:47:11 +00:00
Http . request ( {
method : "GET" ,
url : url ,
params : { } ,
} )
. then ( ( res ) => {
callback ( res . data ) ;
} )
. catch ( ( err ) => {
callback ( err ) ;
} ) ;
} ,
2022-03-17 05:57:28 +00:00
2022-03-31 23:33:39 +00:00
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 ) ;
} ,
} ,
2022-03-21 23:47:11 +00:00
statusBar : {
async hide ( ) {
return await StatusBar . hide ( ) ;
2022-03-18 11:49:47 +00:00
} ,
2022-03-21 23:47:11 +00:00
async show ( ) {
return await StatusBar . show ( ) ;
2022-03-18 11:49:47 +00:00
} ,
2022-03-21 23:47:11 +00:00
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 ) {
2022-03-29 04:47:44 +00:00
return await StatusBar . setBackgroundColor ( { color } ) ;
2022-03-21 23:47:11 +00:00
} ,
2022-03-31 05:20:00 +00:00
async setTheme ( color , dark ) {
2022-03-31 04:22:24 +00:00
dark
? StatusBar . setStyle ( { style : Style . Dark } )
: StatusBar . setStyle ( { style : Style . Light } ) ;
2022-03-31 05:20:00 +00:00
StatusBar . setBackgroundColor ( { color } ) ;
2022-03-31 04:22:24 +00:00
} ,
2022-03-21 23:47:11 +00:00
} ,
2022-03-18 11:49:47 +00:00
2022-03-23 00:37:17 +00:00
navigationBar : {
async hide ( ) {
return await NavigationBar . hide ( ) ;
} ,
async show ( ) {
return await NavigationBar . show ( ) ;
} ,
2022-03-31 04:22:24 +00:00
async setTheme ( color , darkButtons ) {
2022-03-29 04:47:44 +00:00
return await NavigationBar . setColor ( { color , darkButtons } ) ;
} ,
async setTransparent ( ) {
return NavigationBar . setTransparency ( { isTransparent : true } ) ;
} ,
2022-03-23 00:37:17 +00:00
} ,
2022-03-21 23:47:11 +00:00
hexToRgb ( hex ) {
return hexToRgb ( hex ) ;
} ,
rgbToHex ( r , g , b ) {
return rgbToHex ( r , g , b ) ;
} ,
2022-05-02 04:01:48 +00:00
2022-05-03 11:07:40 +00:00
async launchBackHandling ( ) {
2022-05-02 04:01:48 +00:00
backActions = new backHandler ( ) ;
2022-05-03 11:07:40 +00:00
return true ;
2022-05-02 04:01:48 +00:00
} ,
2022-05-03 11:07:40 +00:00
resetBackActions ( ) {
backActions . reset ( ) ;
} ,
addBackAction ( action ) {
backActions . addAction ( action ) ;
2022-05-02 04:01:48 +00:00
} ,
back ( listenerFunc ) {
backActions . back ( listenerFunc ) ;
2022-05-03 11:07:40 +00:00
} ,
2022-05-05 12:28:32 +00:00
//--- Convert Time To Human Readable String ---//
2022-05-05 23:14:21 +00:00
humanTime ( seconds = 0 ) {
2022-05-05 12:28:32 +00:00
seconds = Math . floor ( seconds ) ; // Not doing this seems to break the calculation
let levels = [
Math . floor ( seconds / 31536000 ) , //Years
Math . floor ( ( seconds % 31536000 ) / 86400 ) , //Days
Math . floor ( ( ( seconds % 31536000 ) % 86400 ) / 3600 ) , //Hours
Math . floor ( ( ( ( seconds % 31536000 ) % 86400 ) % 3600 ) / 60 ) , //Minutes
( ( ( seconds % 31536000 ) % 86400 ) % 3600 ) % 60 , //Seconds
] ;
let returntext = new String ( ) ;
for ( const i in levels ) {
2022-05-05 21:22:35 +00:00
const num = levels [ i ] . toString ( ) . length == 1 ? "0" + levels [ i ] : levels [ i ] ; // If Number Is Single Digit, Add 0 In Front
2022-05-05 12:28:32 +00:00
2022-05-05 21:22:35 +00:00
returntext += ":" + num ;
2022-05-05 12:28:32 +00:00
}
while ( returntext . startsWith ( ":00" ) ) { returntext = returntext . substring ( 3 ) ; } // Remove Prepending 0s (eg. 00:00:00:01:00)
if ( returntext . startsWith ( ":0" ) ) { returntext = returntext . substring ( 2 ) ; } else { returntext = returntext . substring ( 1 ) ; } // Prevent Time Starting With 0 (eg. 01:00)
2022-05-05 23:14:21 +00:00
console . log ( "Human Time:" , returntext ) ;
2022-05-05 12:28:32 +00:00
return returntext ;
2022-05-05 23:14:21 +00:00
} ,
//--- End Convert Time To Human Readable String ---//
2022-03-21 23:47:11 +00:00
} ;
2022-03-07 14:36:23 +00:00
//--- Start ---//
export default ( { app } , inject ) => {
2022-03-21 23:47:11 +00:00
inject ( "vuetube" , module ) ;
} ;