From 1181d320bbaac1e1c7f2feee9802189455e51e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Thu, 23 Jan 2020 21:34:31 -0300 Subject: [PATCH 1/4] ErrorService (Sentry) --- lib/main.dart | 10 +++++++- lib/screens/splash_screen/updater.dart | 5 ++-- lib/services/backup.dart | 9 ++++--- lib/services/error.dart | 35 ++++++++++++++++++++++++++ lib/services/requests.dart | 22 ++++++++-------- lib/utils/notifiers.dart | 4 ++- pubspec.lock | 14 +++++++++++ pubspec.yaml | 1 + 8 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 lib/services/error.dart diff --git a/lib/main.dart b/lib/main.dart index 3c08aca..999b62a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,11 @@ +import 'dart:async'; + import 'package:animu/screens/browse.dart'; import 'package:animu/screens/saved_animes.dart'; import 'package:animu/screens/settings/settings.dart'; import 'package:animu/screens/splash_screen/splash_screen.dart'; import 'package:animu/services/backup.dart'; +import 'package:animu/services/error.dart'; import 'package:animu/utils/notifiers.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_analytics/observer.dart'; @@ -18,7 +21,12 @@ class TabInfo { TabInfo(this.title, this.icon, this.widget); } -void main() => runApp(MyApp()); +void main() { + runZoned( + () => runApp(MyApp()), + onError: ErrorService.report, + ); +} class MyApp extends StatelessWidget { @override diff --git a/lib/screens/splash_screen/updater.dart b/lib/screens/splash_screen/updater.dart index 7a69c01..cc925bf 100644 --- a/lib/screens/splash_screen/updater.dart +++ b/lib/screens/splash_screen/updater.dart @@ -1,3 +1,4 @@ +import 'package:animu/services/error.dart'; import 'package:animu/widgets/dialog_button.dart'; import 'package:flutter/material.dart'; import 'package:ota_update/ota_update.dart'; @@ -37,8 +38,8 @@ class _UpdaterState extends State { }); }, ); - } catch (e) { - print('Failed to make OTA update. Details: $e'); + } catch (e, s) { + ErrorService.report(e, s); } } diff --git a/lib/services/backup.dart b/lib/services/backup.dart index f344cc3..516c1ad 100644 --- a/lib/services/backup.dart +++ b/lib/services/backup.dart @@ -1,3 +1,4 @@ +import 'package:animu/services/error.dart'; import 'package:animu/services/requests.dart'; import 'package:animu/utils/helpers.dart'; import 'package:animu/utils/models.dart'; @@ -47,8 +48,8 @@ class BackupService { } } return await user; - } catch (e) { - print(e); + } catch (e, s) { + ErrorService.report(e, s); return null; } } @@ -57,8 +58,8 @@ class BackupService { try { await _auth.signOut(); return true; - } catch (e) { - print(e); + } catch (e, s) { + ErrorService.report(e, s); return false; } } diff --git a/lib/services/error.dart b/lib/services/error.dart new file mode 100644 index 0000000..173620f --- /dev/null +++ b/lib/services/error.dart @@ -0,0 +1,35 @@ +import 'package:sentry/sentry.dart'; + +class ErrorService { + static final _sentry = SentryClient( + dsn: 'https://c67cfc459f304dac8f043c3bad519336@sentry.io/1898336', + ); + + static bool get isInDebugMode { + // Assume you're in production mode. + bool inDebugMode = false; + + // Assert expressions are only evaluated during development. They are ignored + // in production. Therefore, this code only sets `inDebugMode` to true + // in a development environment. + assert(inDebugMode = true); + + return inDebugMode; + } + + static void report(Object e, StackTrace s) { + try { + if (isInDebugMode) { + print(e); + } else { + _sentry.captureException( + exception: e, + stackTrace: s, + ); + } + } catch (sentryError) { + print('Sending report to sentry.io failed: $sentryError'); + print('Original error: $e'); + } + } +} diff --git a/lib/services/requests.dart b/lib/services/requests.dart index 20dc23a..ccd4017 100644 --- a/lib/services/requests.dart +++ b/lib/services/requests.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:animu/services/error.dart'; import 'package:animu/utils/models.dart'; import 'package:dio/dio.dart'; import 'package:graphql/client.dart'; @@ -40,8 +41,9 @@ class RequestsService { }, ); return response.data['episodeSources']; - } catch (e) { - return await getEpisodeSources(animeSlug: animeSlug, episode: episode); + } catch (e, s) { + ErrorService.report(e, s); + return null; } } @@ -75,8 +77,8 @@ class RequestsService { ), ), ); - } catch (e) { - print(e); + } catch (e, s) { + ErrorService.report(e, s); return null; } } @@ -87,8 +89,8 @@ class RequestsService { await new Dio().get(url.replaceFirst('embed.php', 'check.php')); return response.data; - } catch (e) { - print(e); + } catch (e, s) { + ErrorService.report(e, s); return null; } } @@ -113,8 +115,8 @@ class RequestsService { return new List.from( animes.map((map) => Anime.fromMap(map)), ); - } catch (e) { - print(e); + } catch (e, s) { + ErrorService.report(e, s); return null; } } @@ -139,8 +141,8 @@ class RequestsService { ); return Anime.fromMap(response.data['anime']); - } catch (e) { - print(e); + } catch (e, s) { + ErrorService.report(e, s); return null; } } diff --git a/lib/utils/notifiers.dart b/lib/utils/notifiers.dart index 535545d..89bd5f9 100644 --- a/lib/utils/notifiers.dart +++ b/lib/utils/notifiers.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:animu/services/error.dart'; import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; @@ -38,7 +39,8 @@ class VLCNotifier with ChangeNotifier { }), ); return jsonDecode(response.data); - } catch (e) { + } catch (e, s) { + ErrorService.report(e, s); return null; } } diff --git a/pubspec.lock b/pubspec.lock index bf1e706..2c3d2ba 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -583,6 +583,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.5" + sentry: + dependency: "direct main" + description: + name: sentry + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0+1" share: dependency: "direct main" description: @@ -686,6 +693,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" + usage: + dependency: transitive + description: + name: usage + url: "https://pub.dartlang.org" + source: hosted + version: "3.4.1" uuid_enhanced: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 42648b9..9a785cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: provider: ^4.0.2 pub_semver: ^1.4.2 screen: ^0.0.5 + sentry: ^3.0.0+1 share: ^0.6.3+5 video_player: ^0.10.5+2 From 9c282365bfbf215b36267e93349a18909025110e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Thu, 23 Jan 2020 21:40:10 -0300 Subject: [PATCH 2/4] Global --- lib/screens/settings/about.dart | 3 ++- lib/screens/splash_screen/splash_screen.dart | 3 ++- lib/services/error.dart | 5 ++--- lib/services/requests.dart | 4 ++-- lib/utils/global.dart | 7 +++++++ 5 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 lib/utils/global.dart diff --git a/lib/screens/settings/about.dart b/lib/screens/settings/about.dart index 7ee8f64..59c24b6 100644 --- a/lib/screens/settings/about.dart +++ b/lib/screens/settings/about.dart @@ -1,3 +1,4 @@ +import 'package:animu/utils/global.dart'; import 'package:flutter/material.dart'; import 'package:package_info/package_info.dart'; import 'package:share/share.dart'; @@ -41,7 +42,7 @@ class About extends StatelessWidget { onPressed: () { Share.share( (shareMessages..shuffle()).first + - '\nDescargá Animú en https://animu.juanm04.com', + '\nDescargá Animú en ${Global.appUrl}', ); }, ), diff --git a/lib/screens/splash_screen/splash_screen.dart b/lib/screens/splash_screen/splash_screen.dart index e3be2eb..2a14f15 100644 --- a/lib/screens/splash_screen/splash_screen.dart +++ b/lib/screens/splash_screen/splash_screen.dart @@ -1,4 +1,5 @@ import 'package:animu/screens/splash_screen/updater.dart'; +import 'package:animu/utils/global.dart'; import 'package:animu/utils/models.dart'; import 'package:animu/utils/watching_states.dart'; import 'package:connectivity/connectivity.dart'; @@ -43,7 +44,7 @@ class _SplashScreenState extends State { Future checkUpdates() async { var dio = new Dio(); var response = await dio - .get('https://api.github.com/repos/JuanM04/animu/releases/latest'); + .get('https://api.github.com/repos/${Global.repo}/releases/latest'); Map lastRelease = response.data; diff --git a/lib/services/error.dart b/lib/services/error.dart index 173620f..98916e5 100644 --- a/lib/services/error.dart +++ b/lib/services/error.dart @@ -1,9 +1,8 @@ +import 'package:animu/utils/global.dart'; import 'package:sentry/sentry.dart'; class ErrorService { - static final _sentry = SentryClient( - dsn: 'https://c67cfc459f304dac8f043c3bad519336@sentry.io/1898336', - ); + static final _sentry = SentryClient(dsn: Global.errorsDSN); static bool get isInDebugMode { // Assume you're in production mode. diff --git a/lib/services/requests.dart b/lib/services/requests.dart index ccd4017..da0cd92 100644 --- a/lib/services/requests.dart +++ b/lib/services/requests.dart @@ -1,13 +1,13 @@ import 'dart:convert'; import 'package:animu/services/error.dart'; +import 'package:animu/utils/global.dart'; import 'package:animu/utils/models.dart'; import 'package:dio/dio.dart'; import 'package:graphql/client.dart'; class RequestsService { - static final _httpLink = - HttpLink(uri: 'https://animeflv.juanm04.com/graphql'); + static final _httpLink = HttpLink(uri: Global.requestsEndpoint); static final _client = GraphQLClient( cache: InMemoryCache(), link: _httpLink, diff --git a/lib/utils/global.dart b/lib/utils/global.dart new file mode 100644 index 0000000..6e8d510 --- /dev/null +++ b/lib/utils/global.dart @@ -0,0 +1,7 @@ +class Global { + static final appUrl = 'https://animu.juanm04.com'; + static final requestsEndpoint = 'https://animeflv.juanm04.com/graphql'; + static final errorsDSN = + 'https://c67cfc459f304dac8f043c3bad519336@sentry.io/1898336'; + static final repo = 'JuanM04/animu'; +} From 25b7eb95723f1988ec8e29408707f0b889adeaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Thu, 23 Jan 2020 21:43:42 -0300 Subject: [PATCH 3/4] GOOGLE_SERVICES as base64 --- .github/workflows/build.yaml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9baced9..caa6cbc 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,7 +20,7 @@ jobs: with: flutter-version: 1.12.13+hotfix.5 - name: Google services - run: echo $GOOGLE_SERVICES > android/app/google-services.json + run: echo $GOOGLE_SERVICES | base64 --decode > android/app/google-services.json env: GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }} - run: flutter pub get diff --git a/README.md b/README.md index 4066fc6..85f1238 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Tengo problemas, no me peguen. ## Setup 1. Agregar `android/app/google-services.json` de Firebase. Firebase debe tener las aplicaciones `com.juanm04.animu` y `com.juanm04.animu.dev` con las llaves de desarrollo SHA -2. Agregar el `google-services.json` a modo de secreto al repositorio de GitHub. +2. Agregar el `google-services.json` a modo de secreto al repositorio de GitHub (`cat android/app/google-services.json | base64 | xclip -selection clipboard`). 3. Ejecturar `flutter pub get`. ## To-do From 01da375d9401c1715f4ec34fe1ef5253c1a254a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Thu, 23 Jan 2020 21:44:59 -0300 Subject: [PATCH 4/4] Bump-it! --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 9a785cf..b31173a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: Ver anime sin complicaciones. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.8.1 +version: 0.8.2 environment: sdk: ">=2.6.0 <3.0.0"