Skip to content

Commit

Permalink
patch: show errors for drive backup
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkrieger committed Feb 6, 2023
1 parent 167ef95 commit 719a278
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 45 deletions.
40 changes: 20 additions & 20 deletions android/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ GEM
artifactory (3.0.15)
atomos (0.1.3)
aws-eventstream (1.2.0)
aws-partitions (1.640.0)
aws-sdk-core (3.158.0)
aws-partitions (1.670.0)
aws-sdk-core (3.168.3)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.58.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sdk-kms (1.60.0)
aws-sdk-core (~> 3, >= 3.165.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.114.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sdk-s3 (1.117.2)
aws-sdk-core (~> 3, >= 3.165.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.5.2)
Expand All @@ -36,7 +36,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dotenv (2.8.1)
emoji_regex (3.2.3)
excon (0.93.0)
excon (0.94.0)
faraday (1.10.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
Expand Down Expand Up @@ -66,7 +66,7 @@ GEM
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.2.6)
fastlane (2.210.1)
fastlane (2.211.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -106,9 +106,9 @@ GEM
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.28.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-core (0.9.0)
google-apis-androidpublisher_v3 (0.31.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-core (0.9.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
Expand All @@ -117,10 +117,10 @@ GEM
retriable (>= 2.0, < 4.a)
rexml
webrick
google-apis-iamcredentials_v1 (0.15.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-playcustomapp_v1 (0.11.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-iamcredentials_v1 (0.16.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-playcustomapp_v1 (0.12.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-storage_v1 (0.19.0)
google-apis-core (>= 0.9.0, < 2.a)
google-cloud-core (1.6.0)
Expand All @@ -129,15 +129,15 @@ GEM
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.3.0)
google-cloud-storage (1.43.0)
google-cloud-storage (1.44.0)
addressable (~> 2.8)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
google-apis-storage_v1 (~> 0.19.0)
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (1.2.0)
googleauth (1.3.0)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
Expand All @@ -148,7 +148,7 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
httpclient (2.8.3)
jmespath (1.6.1)
jmespath (1.6.2)
json (2.6.2)
jwt (2.5.0)
memoist (0.16.2)
Expand Down
41 changes: 21 additions & 20 deletions ios/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ GEM
artifactory (3.0.15)
atomos (0.1.3)
aws-eventstream (1.2.0)
aws-partitions (1.640.0)
aws-sdk-core (3.158.0)
aws-partitions (1.670.0)
aws-sdk-core (3.168.3)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.58.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sdk-kms (1.60.0)
aws-sdk-core (~> 3, >= 3.165.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.114.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sdk-s3 (1.117.2)
aws-sdk-core (~> 3, >= 3.165.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.5.2)
Expand All @@ -36,7 +36,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dotenv (2.8.1)
emoji_regex (3.2.3)
excon (0.93.0)
excon (0.94.0)
faraday (1.10.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
Expand Down Expand Up @@ -66,7 +66,7 @@ GEM
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.2.6)
fastlane (2.210.1)
fastlane (2.211.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -106,9 +106,9 @@ GEM
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.28.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-core (0.9.0)
google-apis-androidpublisher_v3 (0.31.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-core (0.9.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
Expand All @@ -117,10 +117,10 @@ GEM
retriable (>= 2.0, < 4.a)
rexml
webrick
google-apis-iamcredentials_v1 (0.15.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-playcustomapp_v1 (0.11.0)
google-apis-core (>= 0.9.0, < 2.a)
google-apis-iamcredentials_v1 (0.16.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-playcustomapp_v1 (0.12.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-storage_v1 (0.19.0)
google-apis-core (>= 0.9.0, < 2.a)
google-cloud-core (1.6.0)
Expand All @@ -129,15 +129,15 @@ GEM
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.3.0)
google-cloud-storage (1.43.0)
google-cloud-storage (1.44.0)
addressable (~> 2.8)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
google-apis-storage_v1 (~> 0.19.0)
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (1.2.0)
googleauth (1.3.0)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
Expand All @@ -148,7 +148,7 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
httpclient (2.8.3)
jmespath (1.6.1)
jmespath (1.6.2)
json (2.6.2)
jwt (2.5.0)
memoist (0.16.2)
Expand Down Expand Up @@ -210,6 +210,7 @@ GEM

PLATFORMS
universal-darwin-21
universal-darwin-22
x86_64-darwin-19

DEPENDENCIES
Expand Down
3 changes: 1 addition & 2 deletions ios/fastlane/metadata/en-US/release_notes.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Don't delete all backups if there's only one left
- Provide maximum line count for text input
- Show snackbar when uploading backup
15 changes: 14 additions & 1 deletion lib/repositories/drive_backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io' as IO;
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:flutter_archive/flutter_archive.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:googleapis/drive/v3.dart';
Expand All @@ -12,6 +13,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:tuple/tuple.dart';

import '../consts.dart';
import '../globals.dart';

GoogleSignIn googleSignIn = GoogleSignIn(scopes: [DriveApi.driveAppdataScope]);

Expand All @@ -37,8 +39,12 @@ Future<DriveApi?> getDrive() async {
bool backingUp = false;

/// Back up if you can
Future<void> ifShouldBackup() async {
Future<void> tryBackup() async {
final sp = await SharedPreferences.getInstance();

// to debug:
// sp.setInt(lastBackupKey, 0);

final lastBackup = sp.getInt(lastBackupKey);
final shouldBackup = sp.getBool(driveEnabledKey) ?? false;
if (shouldBackup) {
Expand All @@ -60,6 +66,7 @@ Future<void> ifShouldBackup() async {
0)) {
Sentry.addBreadcrumb(Breadcrumb(
message: "Initiating auto back up", timestamp: DateTime.now()));
print("Backing up");
await makeBackup();
}

Expand Down Expand Up @@ -150,6 +157,8 @@ Future<void> makeBackup() async {
final tmpZip = IO.File(
"${tmpDir.path}/voice_outliner-${DateTime.now().millisecondsSinceEpoch}.zip");
try {
snackbarKey.currentState?.showSnackBar(
const SnackBar(content: Text("Backing up to Google Drive...")));
await ZipFile.createFromDirectory(
sourceDir: docsDir,
zipFile: tmpZip,
Expand All @@ -167,8 +176,12 @@ Future<void> makeBackup() async {
sp.setInt(lastBackupKey, DateTime.now().millisecondsSinceEpoch);
Sentry.addBreadcrumb(
Breadcrumb(message: "Done backing up", timestamp: DateTime.now()));
snackbarKey.currentState?.showSnackBar(
const SnackBar(content: Text("✅ Backed up")));
} catch (e, tr) {
print(e);
snackbarKey.currentState?.showSnackBar(
SnackBar(content: Text("Error during backup: $e")));
Sentry.captureException(e, stackTrace: tr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/state/outline_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class OutlinesModel extends ChangeNotifier {
showCompleted = prefs.getBool(showCompletedKey) ?? true;
allowRetranscription = prefs.getBool(allowRetranscriptionKey) ?? false;
await loadOutlines();
await ifShouldBackup();
await tryBackup();
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# 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: 1.26.2+106
version: 1.26.4+108

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit 719a278

Please sign in to comment.