mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Separate dir selection from import, better import button text
This allows us to show the 'import in progress' screen only when the user has successfully selected a directory. FREEBIE
This commit is contained in:
parent
0fbe43c2dc
commit
413fba80af
3 changed files with 47 additions and 46 deletions
|
@ -483,7 +483,7 @@
|
|||
"description": "One of two choices presented on the screen shown on first launch"
|
||||
},
|
||||
"installImport": {
|
||||
"message": "Set up with exported data",
|
||||
"message": "Set up with Chrome App export",
|
||||
"description": "One of two choices presented on the screen shown on first launch"
|
||||
},
|
||||
"installGetStartedButton": {
|
||||
|
|
57
js/backup.js
57
js/backup.js
|
@ -709,32 +709,34 @@
|
|||
return moment().format('YYYY MMM Do [at] h.mm.ss a');
|
||||
}
|
||||
|
||||
// directories returned and taken by backup/import are all string paths
|
||||
Whisper.Backup = {
|
||||
clearDatabase: function() {
|
||||
return openDatabase().then(function(idb_db) {
|
||||
return clearAllStores(idb_db);
|
||||
});
|
||||
},
|
||||
backupToDirectory: function() {
|
||||
getDirectoryForExport: function() {
|
||||
var options = {
|
||||
title: i18n('exportChooserTitle'),
|
||||
buttonLabel: i18n('exportButton'),
|
||||
};
|
||||
return getDirectory(options).then(function(directory) {
|
||||
var idb;
|
||||
var dir;
|
||||
return openDatabase().then(function(idb_db) {
|
||||
idb = idb_db;
|
||||
var name = 'Signal Export ' + getTimestamp();
|
||||
return createDirectory(directory, name);
|
||||
}).then(function(created) {
|
||||
dir = created;
|
||||
return exportNonMessages(idb, dir);
|
||||
}).then(function() {
|
||||
return exportConversations(idb, dir);
|
||||
}).then(function() {
|
||||
return dir;
|
||||
});
|
||||
return getDirectory(options);
|
||||
},
|
||||
backupToDirectory: function(directory) {
|
||||
var dir;
|
||||
var idb;
|
||||
return openDatabase().then(function(idb_db) {
|
||||
idb = idb_db;
|
||||
var name = 'Signal Export ' + getTimestamp();
|
||||
return createDirectory(directory, name);
|
||||
}).then(function(created) {
|
||||
dir = created;
|
||||
return exportNonMessages(idb, dir);
|
||||
}).then(function() {
|
||||
return exportConversations(idb, dir);
|
||||
}).then(function() {
|
||||
return dir;
|
||||
}).then(function(path) {
|
||||
console.log('done backing up!');
|
||||
return path;
|
||||
|
@ -746,21 +748,22 @@
|
|||
return Promise.reject(error);
|
||||
});
|
||||
},
|
||||
importFromDirectory: function() {
|
||||
getDirectoryForImport: function() {
|
||||
var options = {
|
||||
title: i18n('importChooserTitle'),
|
||||
buttonLabel: i18n('importButton'),
|
||||
};
|
||||
return getDirectory(options).then(function(directory) {
|
||||
var idb;
|
||||
return openDatabase().then(function(idb_db) {
|
||||
idb = idb_db;
|
||||
return importNonMessages(idb_db, directory);
|
||||
}).then(function() {
|
||||
return importConversations(idb, directory);
|
||||
}).then(function() {
|
||||
return directory;
|
||||
});
|
||||
return getDirectory(options);
|
||||
},
|
||||
importFromDirectory: function(directory) {
|
||||
var idb;
|
||||
return openDatabase().then(function(idb_db) {
|
||||
idb = idb_db;
|
||||
return importNonMessages(idb_db, directory);
|
||||
}).then(function() {
|
||||
return importConversations(idb, directory);
|
||||
}).then(function() {
|
||||
return directory;
|
||||
}).then(function(path) {
|
||||
console.log('done restoring from backup!');
|
||||
return path;
|
||||
|
|
|
@ -99,54 +99,52 @@
|
|||
this.trigger('cancel');
|
||||
},
|
||||
onImport: function() {
|
||||
Whisper.Backup.getDirectoryForImport().then(function(directory) {
|
||||
this.doImport(directory);
|
||||
}.bind(this), function(error) {
|
||||
if (error.name !== 'ChooseError') {
|
||||
console.log('Error choosing directory:', error && error.stack ? error.stack : error);
|
||||
}
|
||||
});
|
||||
},
|
||||
doImport: function(directory) {
|
||||
this.error = null;
|
||||
|
||||
this.state = State.IMPORTING;
|
||||
this.render();
|
||||
|
||||
var importLocation;
|
||||
|
||||
// Wait for prior database interaction to complete
|
||||
this.pending = this.pending.then(function() {
|
||||
// For resilience to interruptions, clear database both before import and after
|
||||
return Whisper.Backup.clearDatabase();
|
||||
}).then(function() {
|
||||
Whisper.Import.start();
|
||||
return Whisper.Backup.importFromDirectory();
|
||||
}).then(function(directory) {
|
||||
importLocation = directory;
|
||||
|
||||
return Whisper.Backup.importFromDirectory(directory);
|
||||
}).then(function() {
|
||||
// Catching in-memory cache up with what's in indexeddb now...
|
||||
// NOTE: this fires storage.onready, listened to across the app. We'll restart
|
||||
// to complete the install to start up cleanly with everything now in the DB.
|
||||
return storage.fetch();
|
||||
}).then(function() {
|
||||
// Clearing any migration-related state inherited from the Chome App
|
||||
// Clearing any migration-related state inherited from the Chrome App
|
||||
storage.remove('migrationState');
|
||||
storage.remove('migrationEnabled');
|
||||
storage.remove('migrationEverCompleted');
|
||||
storage.remove('migrationStorageLocation');
|
||||
|
||||
if (importLocation) {
|
||||
Whisper.Import.saveLocation(importLocation);
|
||||
}
|
||||
|
||||
Whisper.Import.saveLocation(directory);
|
||||
Whisper.Import.complete();
|
||||
|
||||
this.state = State.COMPLETE;
|
||||
this.render();
|
||||
}.bind(this)).catch(function(error) {
|
||||
if (error.name !== 'ChooseError') {
|
||||
this.error = error.message;
|
||||
console.log('Error importing:', error && error.stack ? error.stack : error);
|
||||
}
|
||||
console.log('Error importing:', error && error.stack ? error.stack : error);
|
||||
|
||||
this.error = error.message;
|
||||
this.state = null;
|
||||
this.render();
|
||||
|
||||
if (this.error) {
|
||||
return Whisper.Backup.clearDatabase();
|
||||
}
|
||||
return Whisper.Backup.clearDatabase();
|
||||
}.bind(this));
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue