From 2ff9cb997e7a0eb90592a887f8fc094742c9ee85 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 9 Apr 2022 15:06:35 +1200 Subject: [PATCH] feat: added toasts --- NUXT/plugins/innertube.js | 20 +++++++++++++++---- NUXT/plugins/utils.js | 3 +++ NUXT/plugins/youtube.js | 12 ++++++++--- android/app/capacitor.build.gradle | 1 + .../src/main/assets/capacitor.plugins.json | 4 ++++ android/capacitor.settings.gradle | 3 +++ ios/App/Podfile | 19 +++++++++--------- package.json | 1 + 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/NUXT/plugins/innertube.js b/NUXT/plugins/innertube.js index ef27b2d..89742d3 100644 --- a/NUXT/plugins/innertube.js +++ b/NUXT/plugins/innertube.js @@ -2,7 +2,7 @@ // https://www.youtube.com/youtubei/v1 import { Http } from "@capacitor-community/http"; -import { getBetweenStrings } from "./utils"; +import { getBetweenStrings, delay } from "./utils"; import rendererUtils from "./renderers"; import constants from "./constants"; @@ -44,11 +44,23 @@ class Innertube { this.ErrorCallback(html.data, true); this.ErrorCallback(err, true); } - if (this.retry_count >= 10) { - this.initAsync(); + if (this.retry_count < 10) { + this.retry_count += 1; + if (this.checkErrorCallback) + this.ErrorCallback( + `retry count: ${this.retry_count}`, + false, + `An error occurred while trying to init the innertube API. Retrial number: ${this.retry_count}/10` + ); + await delay(5000); + await this.initAsync(); } else { if (this.checkErrorCallback) - this.ErrorCallback("Failed to retrieve Innertube session", true); + this.ErrorCallback( + "Failed to retrieve Innertube session", + true, + "An error occurred while retrieving the innertube session. Check the Logs for more information." + ); } } } catch (error) { diff --git a/NUXT/plugins/utils.js b/NUXT/plugins/utils.js index 026c138..1613a4d 100644 --- a/NUXT/plugins/utils.js +++ b/NUXT/plugins/utils.js @@ -49,6 +49,8 @@ function linkParser(url) { return match && match[7].length == 11 ? match[7] : false; } +const delay = (ms) => new Promise((res) => setTimeout(res, ms)); + module.exports = { getBetweenStrings, hexToRgb, @@ -56,4 +58,5 @@ module.exports = { getCpn, getMutationByKey, linkParser, + delay, }; diff --git a/NUXT/plugins/youtube.js b/NUXT/plugins/youtube.js index 53fa021..0d16391 100644 --- a/NUXT/plugins/youtube.js +++ b/NUXT/plugins/youtube.js @@ -5,6 +5,7 @@ import constants from "./constants"; import rendererUtils from "./renderers"; import { Buffer } from "buffer"; import iconv from "iconv-lite"; +import { Toast } from "@capacitor/toast"; //--- Logger Function ---// function logger(func, data, isError = false) { @@ -74,9 +75,14 @@ let InnertubeAPI; const innertubeModule = { async getAPI() { if (!InnertubeAPI) { - InnertubeAPI = await Innertube.createAsync((message, isError) => { - logger(constants.LOGGER_NAMES.innertube, message, isError); - }); + InnertubeAPI = await Innertube.createAsync( + (message, isError, shortMessage) => { + logger(constants.LOGGER_NAMES.innertube, message, isError); + if (shortMessage) { + Toast.show({ text: shortMessage }); + } + } + ); } return InnertubeAPI; }, diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index 40f4113..57d16ef 100644 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -17,6 +17,7 @@ dependencies { implementation project(':capacitor-share') implementation project(':capacitor-splash-screen') implementation project(':capacitor-status-bar') + implementation project(':capacitor-toast') implementation project(':hugotomazi-capacitor-navigation-bar') } diff --git a/android/app/src/main/assets/capacitor.plugins.json b/android/app/src/main/assets/capacitor.plugins.json index 2f6bcbe..f4166c0 100644 --- a/android/app/src/main/assets/capacitor.plugins.json +++ b/android/app/src/main/assets/capacitor.plugins.json @@ -31,6 +31,10 @@ "pkg": "@capacitor/status-bar", "classpath": "com.capacitorjs.plugins.statusbar.StatusBarPlugin" }, + { + "pkg": "@capacitor/toast", + "classpath": "com.capacitorjs.plugins.toast.ToastPlugin" + }, { "pkg": "@hugotomazi/capacitor-navigation-bar", "classpath": "br.com.tombus.capacitor.plugin.navigationbar.NavigationBarPlugin" diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index 093d158..83b507b 100644 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -26,5 +26,8 @@ project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capa include ':capacitor-status-bar' project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android') +include ':capacitor-toast' +project(':capacitor-toast').projectDir = new File('../node_modules/@capacitor/toast/android') + include ':hugotomazi-capacitor-navigation-bar' project(':hugotomazi-capacitor-navigation-bar').projectDir = new File('../node_modules/@hugotomazi/capacitor-navigation-bar/android') diff --git a/ios/App/Podfile b/ios/App/Podfile index c5f1516..60892de 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -9,15 +9,16 @@ install! 'cocoapods', :disable_input_output_paths => true def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' - pod 'CapacitorCommunityHttp', :path => '../../node_modules/@capacitor-community/http' - pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app' - pod 'CapacitorBrowser', :path => '../../node_modules/@capacitor/browser' - pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device' - pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics' - pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share' - pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen' - pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar' - pod 'HugotomaziCapacitorNavigationBar', :path => '../../node_modules/@hugotomazi/capacitor-navigation-bar' + pod 'CapacitorCommunityHttp', :path => '..\..\node_modules\@capacitor-community\http' + pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app' + pod 'CapacitorBrowser', :path => '..\..\node_modules\@capacitor\browser' + pod 'CapacitorDevice', :path => '..\..\node_modules\@capacitor\device' + pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics' + pod 'CapacitorShare', :path => '..\..\node_modules\@capacitor\share' + pod 'CapacitorSplashScreen', :path => '..\..\node_modules\@capacitor\splash-screen' + pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar' + pod 'CapacitorToast', :path => '..\..\node_modules\@capacitor\toast' + pod 'HugotomaziCapacitorNavigationBar', :path => '..\..\node_modules\@hugotomazi\capacitor-navigation-bar' end target 'App' do diff --git a/package.json b/package.json index eb63cc0..450bd04 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "@capacitor/share": "^1.1.2", "@capacitor/splash-screen": "^1.2.2", "@capacitor/status-bar": "^1.0.8", + "@capacitor/toast": "^1.0.8", "@hugotomazi/capacitor-navigation-bar": "^1.1.1", "iconv-lite": "^0.6.3" }