Status manager and footer status
This commit is contained in:
@@ -24,7 +24,7 @@ angular.module('app')
|
||||
})
|
||||
.controller('FooterCtrl', function ($rootScope, authManager, modelManager, $timeout, dbManager,
|
||||
syncManager, storageManager, passcodeManager, componentManager, singletonManager, nativeExtManager,
|
||||
privilegesManager) {
|
||||
privilegesManager, statusManager) {
|
||||
|
||||
authManager.checkForSecurityUpdate().then((available) => {
|
||||
this.securityUpdateAvailable = available;
|
||||
@@ -34,22 +34,28 @@ angular.module('app')
|
||||
this.securityUpdateAvailable = authManager.securityUpdateAvailable;
|
||||
})
|
||||
|
||||
statusManager.addStatusObserver((string) => {
|
||||
$timeout(() => {
|
||||
this.arbitraryStatusMessage = string;
|
||||
})
|
||||
})
|
||||
|
||||
$rootScope.$on("did-begin-local-backup", () => {
|
||||
$timeout(() => {
|
||||
this.arbitraryStatusMessage = "Saving local backup...";
|
||||
this.backupStatus = statusManager.addStatusFromString("Saving local backup...");
|
||||
})
|
||||
});
|
||||
|
||||
$rootScope.$on("did-finish-local-backup", (event, data) => {
|
||||
$timeout(() => {
|
||||
if(data.success) {
|
||||
this.arbitraryStatusMessage = "Successfully saved backup.";
|
||||
this.backupStatus = statusManager.replaceStatusWithString(this.backupStatus, "Successfully saved backup.");
|
||||
} else {
|
||||
this.arbitraryStatusMessage = "Unable to save local backup.";
|
||||
this.backupStatus = statusManager.replaceStatusWithString(this.backupStatus, "Unable to save local backup.");
|
||||
}
|
||||
|
||||
$timeout(() => {
|
||||
this.arbitraryStatusMessage = null;
|
||||
this.backupStatus = statusManager.removeStatus(this.backupStatus);
|
||||
}, 2000)
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
angular.module('app')
|
||||
.controller('HomeCtrl', function ($scope, $location, $rootScope, $timeout, modelManager,
|
||||
dbManager, syncManager, authManager, themeManager, passcodeManager, storageManager, migrationManager,
|
||||
privilegesManager) {
|
||||
privilegesManager, statusManager) {
|
||||
|
||||
storageManager.initialize(passcodeManager.hasPasscode(), authManager.isEphemeralSession());
|
||||
|
||||
@@ -32,41 +32,24 @@ angular.module('app')
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
function load() {
|
||||
// pass keys to storageManager to decrypt storage
|
||||
// Update: Wait, why? passcodeManager already handles this.
|
||||
// storageManager.setKeys(passcodeManager.keys());
|
||||
|
||||
openDatabase();
|
||||
// Retrieve local data and begin sycing timer
|
||||
initiateSync();
|
||||
}
|
||||
|
||||
if(passcodeManager.isLocked()) {
|
||||
$scope.needsUnlock = true;
|
||||
} else {
|
||||
load();
|
||||
}
|
||||
|
||||
$scope.onSuccessfulUnlock = function() {
|
||||
$timeout(() => {
|
||||
$scope.needsUnlock = false;
|
||||
load();
|
||||
})
|
||||
}
|
||||
|
||||
function openDatabase() {
|
||||
dbManager.setLocked(false);
|
||||
dbManager.openDatabase(null, function() {
|
||||
// new database, delete syncToken so that items can be refetched entirely from server
|
||||
syncManager.clearSyncToken();
|
||||
syncManager.sync();
|
||||
})
|
||||
}
|
||||
|
||||
function initiateSync() {
|
||||
const initiateSync = () => {
|
||||
authManager.loadInitialData();
|
||||
|
||||
this.syncStatusObserver = syncManager.registerSyncStatusObserver((status) => {
|
||||
if(status.retrievedCount > 20) {
|
||||
var text = `Downloading ${status.retrievedCount} items. Keep app open.`
|
||||
this.syncStatus = statusManager.replaceStatusWithString(this.syncStatus, text);
|
||||
this.showingDownloadStatus = true;
|
||||
} else if(this.showingDownloadStatus) {
|
||||
this.showingDownloadStatus = false;
|
||||
var text = "Download Complete.";
|
||||
this.syncStatus = statusManager.replaceStatusWithString(this.syncStatus, text);
|
||||
setTimeout(() => {
|
||||
this.syncStatus = statusManager.removeStatus(this.syncStatus);
|
||||
}, 2000);
|
||||
}
|
||||
})
|
||||
|
||||
syncManager.setKeyRequestHandler(async () => {
|
||||
let offline = authManager.offline();
|
||||
let auth_params = offline ? passcodeManager.passcodeAuthParams() : await authManager.getAuthParams();
|
||||
@@ -98,11 +81,22 @@ angular.module('app')
|
||||
}
|
||||
});
|
||||
|
||||
syncManager.loadLocalItems().then(() => {
|
||||
let encryptionEnabled = authManager.user || passcodeManager.hasPasscode();
|
||||
this.syncStatus = statusManager.addStatusFromString(encryptionEnabled ? "Decrypting items..." : "Loading items...");
|
||||
|
||||
let incrementalCallback = (current, total) => {
|
||||
let notesString = `${current}/${total} items...`
|
||||
this.syncStatus = statusManager.replaceStatusWithString(this.syncStatus, encryptionEnabled ? `Decrypting ${notesString}` : `Loading ${notesString}`);
|
||||
}
|
||||
|
||||
syncManager.loadLocalItems(incrementalCallback).then(() => {
|
||||
$timeout(() => {
|
||||
$rootScope.$broadcast("initial-data-loaded"); // This needs to be processed first before sync is called so that singletonManager observers function properly.
|
||||
// Perform integrity check on first sync
|
||||
syncManager.sync({performIntegrityCheck: true});
|
||||
this.syncStatus = statusManager.replaceStatusWithString(this.syncStatus, "Syncing...");
|
||||
syncManager.sync({performIntegrityCheck: true}).then(() => {
|
||||
this.syncStatus = statusManager.removeStatus(this.syncStatus);
|
||||
})
|
||||
// refresh every 30s
|
||||
setInterval(function () {
|
||||
syncManager.sync();
|
||||
@@ -119,6 +113,38 @@ angular.module('app')
|
||||
})
|
||||
}
|
||||
|
||||
function load() {
|
||||
// pass keys to storageManager to decrypt storage
|
||||
// Update: Wait, why? passcodeManager already handles this.
|
||||
// storageManager.setKeys(passcodeManager.keys());
|
||||
|
||||
openDatabase();
|
||||
// Retrieve local data and begin sycing timer
|
||||
initiateSync();
|
||||
}
|
||||
|
||||
if(passcodeManager.isLocked()) {
|
||||
$scope.needsUnlock = true;
|
||||
} else {
|
||||
load();
|
||||
}
|
||||
|
||||
$scope.onSuccessfulUnlock = function() {
|
||||
$timeout(() => {
|
||||
$scope.needsUnlock = false;
|
||||
load();
|
||||
})
|
||||
}
|
||||
|
||||
function openDatabase() {
|
||||
dbManager.setLocked(false);
|
||||
dbManager.openDatabase(null, function() {
|
||||
// new database, delete syncToken so that items can be refetched entirely from server
|
||||
syncManager.clearSyncToken();
|
||||
syncManager.sync();
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
Editor Callbacks
|
||||
*/
|
||||
|
||||
67
app/assets/javascripts/app/services/statusManager.js
Normal file
67
app/assets/javascripts/app/services/statusManager.js
Normal file
@@ -0,0 +1,67 @@
|
||||
class StatusManager {
|
||||
|
||||
constructor() {
|
||||
this.statuses = [];
|
||||
this.observers = [];
|
||||
}
|
||||
|
||||
statusFromString(string) {
|
||||
return {string: string};
|
||||
}
|
||||
|
||||
replaceStatusWithString(status, string) {
|
||||
this.removeStatus(status);
|
||||
return this.addStatusFromString(string);
|
||||
}
|
||||
|
||||
addStatusFromString(string) {
|
||||
return this.addStatus(this.statusFromString(string));
|
||||
}
|
||||
|
||||
addStatus(status) {
|
||||
if(typeof status !== "object") {
|
||||
console.error("Attempting to set non-object status", status);
|
||||
return;
|
||||
}
|
||||
|
||||
this.statuses.push(status);
|
||||
this.notifyObservers();
|
||||
return status;
|
||||
}
|
||||
|
||||
removeStatus(status) {
|
||||
_.pull(this.statuses, status);
|
||||
this.notifyObservers();
|
||||
return null;
|
||||
}
|
||||
|
||||
getStatusString() {
|
||||
let result = "";
|
||||
this.statuses.forEach((status, index) => {
|
||||
if(index > 0) {
|
||||
result += " ";
|
||||
}
|
||||
result += status.string;
|
||||
})
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
notifyObservers() {
|
||||
for(let observer of this.observers) {
|
||||
observer(this.getStatusString());
|
||||
}
|
||||
}
|
||||
|
||||
addStatusObserver(callback) {
|
||||
this.observers.push(callback);
|
||||
}
|
||||
|
||||
removeStatusObserver(callback) {
|
||||
_.pull(this.statuses, callback);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
angular.module('app').service('statusManager', StatusManager);
|
||||
3744
package-lock.json
generated
3744
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user