Skip to content

Commit b106e83

Browse files
lacksfishrubensayshi
authored andcommitted
more backup options for iOS.
enabled filesharing and persistent storage for iOS, migrate sqlite files to non shared location. notify user once a day if backup has not been saved.
1 parent 4ce66fa commit b106e83

File tree

13 files changed

+323
-132
lines changed

13 files changed

+323
-132
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ platforms/android/.gradle/2.2.1/taskArtifacts/*
1212

1313
platforms/ios/BlockTrail Wallet.xcodeproj/project.xcworkspace/xcuserdata/*
1414
platforms/ios/BlockTrail Wallet.xcodeproj/xcuserdata/*
15+
platforms/ios/BlockTrail Wallet.xcodeproj/project.xcworkspace/xcshareddata/*
1516
platforms/ios/CordovaLib/CordovaLib.xcodeproj/xcuserdata/*

config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<platform name="ios">
3030
<preference name="AutoHideSplashScreen" value="false"/>
3131
<preference name="ShowSplashScreenSpinner" value="false"/>
32+
<preference name="iosPersistentFileLocation" value="Compatibility"/>
3233
</platform>
3334
<platform name="browser">
3435
<preference name="SplashScreen" value="resources/android/splash/drawable-port-xhdpi-screen.png"/>

platforms/ios/BlockTrail Wallet/BlockTrail Wallet-Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,7 @@
265265
<string>fbauth2</string>
266266
<string>fbshareextension</string>
267267
</array>
268+
<key>UIFileSharingEnabled</key>
269+
<string>YES</string>
268270
</dict>
269271
</plist>

platforms/ios/BlockTrail Wallet/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,5 @@
172172
<preference name="orientation" value="portrait" />
173173
<preference name="AutoHideSplashScreen" value="false" />
174174
<preference name="ShowSplashScreenSpinner" value="false" />
175+
<preference name="iosPersistentFileLocation" value="Compatibility" />
175176
</widget>

src/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
</script>
2828

2929
<script>
30-
ionic.Platform.ready(function() {
31-
console.log('Ionic Platform ready');
32-
angular.bootstrap(document.body, ["blocktrail.wallet"]);
30+
document.addEventListener("deviceready", function() {
31+
console.log('deviceready');
32+
angular.bootstrap(document.getElementById("bootstrapper"), ["blocktrail.wallet-bootstrapper"]);
3333
}, false);
3434
</script>
3535
</head>
@@ -44,6 +44,8 @@
4444
</div>
4545
</div>
4646
</ion-nav-view>
47+
48+
<div id="bootstrapper"></div>
4749
</body>
4850

4951
<script>

src/js/app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ angular.module('blocktrail.wallet').run(
124124
}
125125
});
126126

127-
128127
if (CONFIG.DEBUGLIBS) {
129128
blocktrailSDK.debug.enable('*,-pouchdb:*');
130129
} else {

src/js/bootstrap-app.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
angular.module('blocktrail.wallet-bootstrapper', [
2+
'ngCordova',
3+
NG_CORDOVA_MOCKS ? 'ngCordovaMocks' : null
4+
].filter(function filterNull(r) { return !!r; }));
5+
6+
angular.module('blocktrail.wallet-bootstrapper').run(function ($q, $cordovaFile) {
7+
var DBs = ['apprate', 'contacts', 'currency-rates-cache', 'history', 'settings', 'tx-cache', 'wallet-cache', 'launch'];
8+
9+
ionic.Platform.ready(function () {
10+
$q.when(ionic.Platform.isIOS())
11+
.then(function (isIOS) {
12+
if (isIOS) {
13+
var sourceDir = cordova.file.documentsDirectory;
14+
var destDir = cordova.file.applicationStorageDirectory + "Library/LocalDatabase";
15+
16+
return $cordovaFile.checkFile(sourceDir, "_pouch_launch").then(function () {
17+
return $cordovaFile.checkFile(destDir, "_pouch_launch").then(function () {
18+
console.log(destDir + "_pouch_launch: already exists");
19+
}).catch(function () {
20+
// If not found in destination (-> exception thrown), we can start moving files
21+
return $q.all(DBs.map(function (resource) {
22+
var fileName = "_pouch_" + resource;
23+
24+
return $cordovaFile.checkFile(sourceDir, "_pouch_" + resource)
25+
.then(function (success) {
26+
return $cordovaFile.copyFile(sourceDir, fileName, destDir, fileName)
27+
.then(function () {
28+
return $cordovaFile.removeFile(sourceDir, fileName)
29+
.then(function () {
30+
console.log(fileName, "success");
31+
});
32+
});
33+
}).catch(function () {
34+
console.log(fileName + ": not found1")
35+
});
36+
}));
37+
})
38+
}).catch(function () {
39+
console.log(sourceDir + "_pouch_launch: not found2")
40+
});
41+
} else {
42+
return;
43+
}
44+
})
45+
.then(function() {
46+
// bootstrap the real wallet
47+
console.log('bootstraping the wallet');
48+
angular.bootstrap(document.body, ["blocktrail.wallet"]);
49+
});
50+
});
51+
});

src/js/controllers/SettingsControllers.js

Lines changed: 110 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
angular.module('blocktrail.wallet')
22
.controller('SettingsCtrl', function($scope, $rootScope, $q, sdkService, launchService, settingsService,
3-
Wallet, Contacts, storageService, $cordovaDialogs, $ionicLoading,
3+
Wallet, Contacts, storageService, $cordovaDialogs, $ionicLoading, $cordovaFile,
44
$translate, $timeout, $state, $log, $analytics, CONFIG, AppRateService, $cordovaToast) {
55
$scope.appControl = {
66
syncing: false,
@@ -388,12 +388,38 @@ angular.module('blocktrail.wallet')
388388
$cordovaDialogs.alert(err.toString(), $translate.instant('FAILED').sentenceCase(), $translate.instant('OK'));
389389
}
390390
});
391-
} else {
392-
$cordovaDialogs.alert(
393-
$translate.instant('MSG_BACKUP_SAVED_ALREADY').sentenceCase(),
394-
$translate.instant('SETTINGS_BACKUP_COMPLETE').sentenceCase(),
395-
$translate.instant('OK')
396-
);
391+
} else { // If backup has not been saved
392+
settingsService.$isLoaded().then(function() {
393+
394+
var dialogMessage = 'MSG_BACKUP_SAVED_ALREADY';
395+
396+
var backupSettings = {
397+
path: window.cordova ? (ionic.Platform.isAndroid() ? cordova.file.externalDataDirectory : cordova.file.documentsDirectory) : null,
398+
filename: 'btc-wallet-backup-' + $scope.defaultWallet + '.pdf'
399+
};
400+
401+
// Check if backup.pdf is still on the phone, notify accordingly
402+
$cordovaFile.checkFile(backupSettings.path, backupSettings.filename).then(function (success) {
403+
if (ionic.Platform.isIOS()) {
404+
dialogMessage = 'MSG_BACKUP_SAVED_PERSISTENT_IOS';
405+
} else {
406+
dialogMessage = 'MSG_BACKUP_SAVED_PERSISTENT_ANDROID';
407+
}
408+
409+
return Promise.resolve();
410+
}).catch(function() {
411+
$log.log("checking for backup PDF failed");
412+
}).then(function () {
413+
return $cordovaDialogs.alert(
414+
$translate.instant(dialogMessage).sentenceCase(),
415+
$translate.instant('SETTINGS_BACKUP_COMPLETE').sentenceCase(),
416+
$translate.instant('OK')
417+
)
418+
}).then(function() {
419+
$btBackButtonDelegate.goBack();
420+
return false;
421+
});
422+
});
397423
}
398424
};
399425

@@ -868,14 +894,22 @@ angular.module('blocktrail.wallet')
868894
$ionicActionSheet, $log, $cordovaFileOpener2, $cordovaFile, sdkService, $cordovaEmailComposer,
869895
launchService, settingsService, $timeout) {
870896
if (!backupInfo) {
871-
$cordovaDialogs.alert(
872-
$translate.instant('MSG_BACKUP_SAVED_ALREADY').sentenceCase(),
873-
$translate.instant('SETTINGS_BACKUP_COMPLETE').sentenceCase(),
874-
$translate.instant('OK')
875-
).then(function() {
876-
$btBackButtonDelegate.goBack();
897+
settingsService.$isLoaded().then(function() {
898+
899+
$log.log(settingsService.backupSavedPersistent, ionic.Platform.isIOS());
900+
901+
var dialogMessage = (settingsService.backupSavedPersistent && ionic.Platform.isIOS())
902+
? 'MSG_BACKUP_SAVED_PERSISTENT' : 'MSG_BACKUP_SAVED_ALREADY';
903+
904+
$cordovaDialogs.alert(
905+
$translate.instant(dialogMessage).sentenceCase(),
906+
$translate.instant('SETTINGS_BACKUP_COMPLETE').sentenceCase(),
907+
$translate.instant('OK')
908+
).then(function() {
909+
$btBackButtonDelegate.goBack();
910+
});
911+
return false;
877912
});
878-
return false;
879913
}
880914

881915
$scope.appControl = {
@@ -914,10 +948,11 @@ angular.module('blocktrail.wallet')
914948
inputMode: 'M',
915949
image: true
916950
};
951+
917952
$scope.backupSettings = {
918953
//NB: on android fileOpener2 only works with SD storage (i.e. non-private storage)
919-
path: window.cordova ? (ionic.Platform.isAndroid() ? cordova.file.externalDataDirectory : cordova.file.dataDirectory) : null,
920-
filename: 'btc-wallet-backup.pdf',
954+
path: window.cordova ? (ionic.Platform.isAndroid() ? cordova.file.externalDataDirectory : cordova.file.documentsDirectory) : null,
955+
filename: 'btc-wallet-backup-' + backupInfo.identifier + '.pdf',
921956
replace: true
922957
};
923958

@@ -926,13 +961,8 @@ angular.module('blocktrail.wallet')
926961
//Temporary handling of a bug in iOS with the $cordovaFileOpener2
927962
var optionButtons = [
928963
{ text: $translate.instant('BACKUP_EMAIL_PDF') },
929-
{ text: $translate.instant('BACKUP_CREATE_PDF') },
964+
{ text: $translate.instant('BACKUP_OPEN_PDF') }
930965
];
931-
if (ionic.Platform.isIOS()) {
932-
optionButtons = [
933-
{ text: $translate.instant('BACKUP_EMAIL_PDF') },
934-
];
935-
}
936966

937967
$scope.hideExportOptions = $ionicActionSheet.show({
938968
buttons: optionButtons,
@@ -987,6 +1017,7 @@ angular.module('blocktrail.wallet')
9871017
return $cordovaFile.writeFile($scope.backupSettings.path, $scope.backupSettings.filename, buffer, $scope.backupSettings.replace);
9881018
})
9891019
.then(function(result) {
1020+
// Options for saving
9901021
if (index == 0) {
9911022
//email the backup pdf
9921023
var options = {
@@ -1001,33 +1032,52 @@ angular.module('blocktrail.wallet')
10011032
var deferred = $q.defer();
10021033

10031034
//check that emails can be sent (try with normal mail, can't do attachments with gmail)
1004-
cordova.plugins.email.isAvailable(function(isAvailable) {
1035+
cordova.plugins.email.isAvailable(function (isAvailable) {
10051036
$log.debug('is email supported? ' + isAvailable);
10061037
if (isAvailable) {
10071038
$scope.appControl.saveButtonClicked = true;
1008-
cordova.plugins.email.open(options, function(result) {
1039+
cordova.plugins.email.open(options, function (result) {
10091040
deferred.resolve(result);
10101041
});
10111042
} else {
10121043
//no mail support...sad times :(
10131044
$cordovaDialogs.alert(
1014-
$translate.instant('MSG_EMAIL_NOT_SETUP').sentenceCase(),
1015-
$translate.instant('SORRY').sentenceCase(),
1045+
$translate.instant('MSG_EMAIL_NOT_SETUP'),
1046+
$translate.instant('SORRY'),
10161047
$translate.instant('OK')
1017-
).then(function() {
1018-
deferred.reject('NO_EMAIL');
1019-
});
1048+
);
10201049
}
10211050
});
10221051

10231052
return deferred.promise;
10241053

10251054
} else if (index == 1) {
1026-
//export the backup to PDF for user to handle
1027-
//call an intent or similar service to allow user decide what to do with PDF
1028-
$log.debug('opening file ' + $scope.backupSettings.path + $scope.backupSettings.filename);
1029-
$scope.appControl.saveButtonClicked = true;
1030-
return $cordovaFileOpener2.open($scope.backupSettings.path + $scope.backupSettings.filename, 'application/pdf');
1055+
var msg = 'BACKUP_EXPORT_PDF_ANDROID_INFO';
1056+
if (ionic.Platform.isIOS()) {
1057+
msg = 'BACKUP_EXPORT_PDF_IOS_INFO';
1058+
}
1059+
1060+
return $cordovaDialogs.alert(
1061+
$translate.instant(msg),
1062+
$translate.instant('IMPORTANT'),
1063+
$translate.instant('OK')
1064+
).then(function () {
1065+
$log.debug('opening file ' + $scope.backupSettings.path + $scope.backupSettings.filename);
1066+
1067+
if (ionic.Platform.isIOS()) {
1068+
cordova.plugins.disusered.open($scope.backupSettings.path + $scope.backupSettings.filename,
1069+
function () {
1070+
$scope.appControl.saveButtonClicked = true;
1071+
},
1072+
function (err) {
1073+
console.log(err.message, err);
1074+
}
1075+
);
1076+
} else {
1077+
$scope.appControl.saveButtonClicked = true;
1078+
return $cordovaFileOpener2.open($scope.backupSettings.path + $scope.backupSettings.filename, 'application/pdf');
1079+
}
1080+
});
10311081
}
10321082
})
10331083
.then(function() {
@@ -1068,19 +1118,33 @@ angular.module('blocktrail.wallet')
10681118
settingsService.$isLoaded().then(function() {
10691119
settingsService.backupSaved = true;
10701120
settingsService.backupSkipped = false;
1071-
settingsService.$store();
1121+
return settingsService.$store();
1122+
}).then(function () {
1123+
$cordovaDialogs.confirm(
1124+
$translate.instant("BACKUP_OPTION_KEEP_ON_PHONE"),
1125+
$translate.instant("IMPORTANT"),
1126+
[
1127+
$translate.instant("YES"),
1128+
$translate.instant("NO")
1129+
])
1130+
.then(function (dialogResult) {
1131+
1132+
if (dialogResult == 1) {
1133+
settingsService.backupSavedPersistent = true;
1134+
1135+
console.log('keeping backup');
1136+
$scope.backupSettings.keepBackup = true;
1137+
return settingsService.$store();
1138+
} else {
1139+
console.log('not keeping backup');
1140+
//delete the temporary backup file if created
1141+
return $cordovaFile.removeFile($scope.backupSettings.path, $scope.backupSettings.filename);
1142+
}
1143+
})
1144+
.then(function () {
1145+
$btBackButtonDelegate.goBack();
1146+
});
10721147
});
1073-
1074-
//delete the temporary backup file if created
1075-
$cordovaFile.removeFile($scope.backupSettings.path, $scope.backupSettings.filename)
1076-
.then(function() {
1077-
$log.debug('deleted file ' + $scope.backupSettings.path + $scope.backupSettings.filename);
1078-
}, function(err) {
1079-
$log.debug('unable to delete temp wallet backup file' + err);
1080-
});
1081-
1082-
//onwards to phone number and contacts setup
1083-
$btBackButtonDelegate.goBack();
10841148
})
10851149
.catch(function(err) {
10861150
console.error(err);

0 commit comments

Comments
 (0)