Functioning UI
This commit is contained in:
@@ -3,11 +3,8 @@ import { EncryptionIntents, ProtectedActions } from 'snjs';
|
||||
|
||||
export class ArchiveManager {
|
||||
/* @ngInject */
|
||||
constructor(lockManager, application, authManager, modelManager, privilegesManager) {
|
||||
constructor(lockManager, application) {
|
||||
this.lockManager = lockManager;
|
||||
this.authManager = authManager;
|
||||
modelManager = modelManager;
|
||||
this.privilegesManager = privilegesManager;
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
@@ -16,7 +13,7 @@ export class ArchiveManager {
|
||||
*/
|
||||
/** @public */
|
||||
async downloadBackup(encrypted) {
|
||||
return this.downloadBackupOfItems(modelManager.allItems, encrypted);
|
||||
return this.downloadBackupOfItems(this.application.modelManager.allItems, encrypted);
|
||||
}
|
||||
|
||||
/** @public */
|
||||
@@ -39,7 +36,7 @@ export class ArchiveManager {
|
||||
});
|
||||
};
|
||||
|
||||
if (await this.privilegesManager.actionRequiresPrivilege(ProtectedActions.ManageBackups)) {
|
||||
if (await this.application.privilegesManager.actionRequiresPrivilege(ProtectedActions.ManageBackups)) {
|
||||
this.godService.presentPrivilegesModal(ProtectedActions.ManageBackups, () => {
|
||||
run();
|
||||
});
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
export class DatabaseManager {
|
||||
/* @ngInject */
|
||||
constructor(alertManager) {
|
||||
this.locked = true;
|
||||
this.alertManager = alertManager;
|
||||
}
|
||||
|
||||
displayOfflineAlert() {
|
||||
var message = "There was an issue loading your offline database. This could happen for two reasons:";
|
||||
message += "\n\n1. You're in a private window in your browser. We can't save your data without access to the local database. Please use a non-private window.";
|
||||
message += "\n\n2. You have two windows of the app open at the same time. Please close any other app instances and reload the page.";
|
||||
this.alertManager.alert({text: message});
|
||||
}
|
||||
|
||||
setLocked(locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
async openDatabase({onUpgradeNeeded} = {}) {
|
||||
if(this.locked) {
|
||||
return;
|
||||
}
|
||||
|
||||
const request = window.indexedDB.open("standardnotes", 1);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
request.onerror = (event) => {
|
||||
if(event.target.errorCode) {
|
||||
this.alertManager.alert({text: "Offline database issue: " + event.target.errorCode});
|
||||
} else {
|
||||
this.displayOfflineAlert();
|
||||
}
|
||||
console.error("Offline database issue:", event);
|
||||
resolve(null);
|
||||
};
|
||||
|
||||
request.onsuccess = (event) => {
|
||||
const db = event.target.result;
|
||||
db.onversionchange = function(event) {
|
||||
db.close();
|
||||
};
|
||||
db.onerror = function(errorEvent) {
|
||||
console.error("Database error: " + errorEvent.target.errorCode);
|
||||
};
|
||||
resolve(db);
|
||||
};
|
||||
|
||||
request.onblocked = (event) => {
|
||||
console.error("Request blocked error:", event.target.errorCode);
|
||||
};
|
||||
|
||||
request.onupgradeneeded = (event) => {
|
||||
const db = event.target.result;
|
||||
db.onversionchange = function(event) {
|
||||
db.close();
|
||||
};
|
||||
|
||||
// Create an objectStore for this database
|
||||
const objectStore = db.createObjectStore("items", { keyPath: "uuid" });
|
||||
objectStore.createIndex("uuid", "uuid", { unique: true });
|
||||
objectStore.transaction.oncomplete = function(event) {
|
||||
// Ready to store values in the newly created objectStore.
|
||||
if(db.version === 1 && onUpgradeNeeded) {
|
||||
onUpgradeNeeded();
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async getAllModels() {
|
||||
const db = await this.openDatabase();
|
||||
const objectStore = db.transaction("items").objectStore("items");
|
||||
const items = [];
|
||||
return new Promise(async (resolve, reject) => {
|
||||
objectStore.openCursor().onsuccess = (event) => {
|
||||
const cursor = event.target.result;
|
||||
if (cursor) {
|
||||
items.push(cursor.value);
|
||||
cursor.continue();
|
||||
} else {
|
||||
resolve(items);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async saveModel(item) {
|
||||
this.saveModels([item]);
|
||||
}
|
||||
|
||||
async saveModels(items) {
|
||||
const showGenericError = (error) => {
|
||||
this.alertManager.alert({text: `Unable to save changes locally due to an unknown system issue. Issue Code: ${error.code} Issue Name: ${error.name}.`});
|
||||
};
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if(items.length === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
const db = await this.openDatabase();
|
||||
const transaction = db.transaction("items", "readwrite");
|
||||
transaction.oncomplete = (event) => {};
|
||||
transaction.onerror = function(event) {
|
||||
console.error("Transaction error:", event.target.errorCode);
|
||||
showGenericError(event.target.error);
|
||||
};
|
||||
transaction.onblocked = function(event) {
|
||||
console.error("Transaction blocked error:", event.target.errorCode);
|
||||
showGenericError(event.target.error);
|
||||
};
|
||||
transaction.onabort = function(event) {
|
||||
console.error("Offline saving aborted:", event);
|
||||
const error = event.target.error;
|
||||
if(error.name == "QuotaExceededError") {
|
||||
this.alertManager.alert({text: "Unable to save changes locally because your device is out of space. Please free up some disk space and try again, otherwise, your data may end up in an inconsistent state."});
|
||||
} else {
|
||||
showGenericError(error);
|
||||
}
|
||||
reject(error);
|
||||
};
|
||||
|
||||
const itemObjectStore = transaction.objectStore("items");
|
||||
|
||||
const putItem = async (item) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = itemObjectStore.put(item);
|
||||
request.onerror = (event) => {
|
||||
console.error("DB put error:", event.target.error);
|
||||
resolve();
|
||||
};
|
||||
request.onsuccess = resolve;
|
||||
});
|
||||
};
|
||||
|
||||
for(const item of items) {
|
||||
await putItem(item);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
async deleteModel(item) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const db = await this.openDatabase();
|
||||
const request = db.transaction("items", "readwrite").objectStore("items").delete(item.uuid);
|
||||
request.onsuccess = (event) => {
|
||||
resolve();
|
||||
};
|
||||
request.onerror = (event) => {
|
||||
reject();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async clearAllModels() {
|
||||
const deleteRequest = window.indexedDB.deleteDatabase("standardnotes");
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
deleteRequest.onerror = function(event) {
|
||||
console.error("Error deleting database.");
|
||||
resolve();
|
||||
};
|
||||
|
||||
deleteRequest.onsuccess = function(event) {
|
||||
resolve();
|
||||
};
|
||||
|
||||
deleteRequest.onblocked = function(event) {
|
||||
console.error("Delete request blocked");
|
||||
this.alertManager.alert({text: "Your browser is blocking Standard Notes from deleting the local database. Make sure there are no other open windows of this app and try again. If the issue persists, please manually delete app data to sign out."});
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import angular from 'angular';
|
||||
|
||||
export class GodService {
|
||||
|
||||
/* @ngInject */
|
||||
constructor(
|
||||
$rootScope,
|
||||
@@ -14,7 +13,7 @@ export class GodService {
|
||||
}
|
||||
|
||||
async checkForSecurityUpdate() {
|
||||
if (this.offline()) {
|
||||
if (this.application.noAccount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export { AlertManager } from './alertManager';
|
||||
export { ArchiveManager } from './archiveManager';
|
||||
export { DatabaseManager } from './databaseManager';
|
||||
export { DesktopManager } from './desktopManager';
|
||||
export { GodService } from './godService';
|
||||
export { KeyboardManager } from './keyboardManager';
|
||||
export { NativeExtManager } from './nativeExtManager';
|
||||
export { LockManager } from './lockManager';
|
||||
export { NativeExtManager } from './nativeExtManager';
|
||||
export { PreferencesManager } from './preferencesManager';
|
||||
export { StatusManager } from './statusManager';
|
||||
export { ThemeManager } from './themeManager';
|
||||
export { AlertManager } from './alertManager';
|
||||
export { PreferencesManager } from './preferencesManager';
|
||||
|
||||
@@ -34,10 +34,7 @@ export class LockManager {
|
||||
}
|
||||
|
||||
async setAutoLockInterval(interval) {
|
||||
return this.application.setValue(
|
||||
STORAGE_KEY_AUTOLOCK_INTERVAL,
|
||||
JSON.stringify(interval),
|
||||
);
|
||||
return this.application.setValue(STORAGE_KEY_AUTOLOCK_INTERVAL, interval);
|
||||
}
|
||||
|
||||
async getAutoLockInterval() {
|
||||
@@ -45,7 +42,7 @@ export class LockManager {
|
||||
STORAGE_KEY_AUTOLOCK_INTERVAL,
|
||||
);
|
||||
if(interval) {
|
||||
return JSON.parse(interval);
|
||||
return interval;
|
||||
} else {
|
||||
return LOCK_INTERVAL_NONE;
|
||||
}
|
||||
@@ -93,10 +90,11 @@ export class LockManager {
|
||||
];
|
||||
}
|
||||
|
||||
documentVisibilityChanged(visible) {
|
||||
async documentVisibilityChanged(visible) {
|
||||
if(visible) {
|
||||
const locked = await this.application.isPasscodeLocked();
|
||||
if(
|
||||
!this.isLocked() &&
|
||||
!locked &&
|
||||
this.lockAfterDate &&
|
||||
new Date() > this.lockAfterDate
|
||||
) {
|
||||
|
||||
@@ -15,10 +15,8 @@ export class NativeExtManager {
|
||||
this.resolveExtensionsManager();
|
||||
this.resolveBatchManager();
|
||||
|
||||
appState.addObserver(async (eventName) => {
|
||||
if (eventName === AppStateEvents.ApplicationReady) {
|
||||
await this.initialize();
|
||||
}
|
||||
application.onReady(() => {
|
||||
this.initialize();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,8 @@ export class PreferencesManager {
|
||||
) {
|
||||
this.application = application;
|
||||
this.appState = appState;
|
||||
appState.addObserver(async (eventName) => {
|
||||
if (eventName === AppStateEvents.ApplicationReady) {
|
||||
await this.initialize();
|
||||
}
|
||||
application.onReady(() => {
|
||||
this.initialize();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
import { SNTheme, StorageValueModes, EncryptionIntents } from 'snjs';
|
||||
import { ContentTypes, StorageValueModes, EncryptionIntents } from 'snjs';
|
||||
import { AppStateEvents } from '@/state';
|
||||
|
||||
const CACHED_THEMES_KEY = 'cachedThemes';
|
||||
@@ -16,9 +16,16 @@ export class ThemeManager {
|
||||
this.desktopManager = desktopManager;
|
||||
this.activeThemes = [];
|
||||
this.registerObservers();
|
||||
if (!desktopManager.isDesktop) {
|
||||
this.activateCachedThemes();
|
||||
}
|
||||
application.onReady(() => {
|
||||
if (!desktopManager.isDesktop) {
|
||||
this.activateCachedThemes();
|
||||
}
|
||||
});
|
||||
appState.addObserver((eventName, data) => {
|
||||
if (eventName === AppStateEvents.DesktopExtsReady) {
|
||||
this.activateCachedThemes();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async activateCachedThemes() {
|
||||
@@ -30,11 +37,6 @@ export class ThemeManager {
|
||||
}
|
||||
|
||||
registerObservers() {
|
||||
this.appState.addObserver((eventName, data) => {
|
||||
if (eventName === AppStateEvents.DesktopExtsReady) {
|
||||
this.activateCachedThemes();
|
||||
}
|
||||
});
|
||||
this.desktopManager.registerUpdateObserver((component) => {
|
||||
// Reload theme if active
|
||||
if (component.active && component.isTheme()) {
|
||||
@@ -112,10 +114,9 @@ export class ThemeManager {
|
||||
});
|
||||
return processedPayload;
|
||||
}));
|
||||
const data = JSON.stringify(mapped);
|
||||
return this.application.setValue(
|
||||
CACHED_THEMES_KEY,
|
||||
data,
|
||||
mapped,
|
||||
StorageValueModes.Nonwrapped
|
||||
);
|
||||
}
|
||||
@@ -133,10 +134,15 @@ export class ThemeManager {
|
||||
StorageValueModes.Nonwrapped
|
||||
);
|
||||
if (cachedThemes) {
|
||||
const parsed = JSON.parse(cachedThemes);
|
||||
return parsed.map((theme) => {
|
||||
return new SNTheme(theme);
|
||||
});
|
||||
const themes = [];
|
||||
for(const cachedTheme of cachedThemes) {
|
||||
const theme = await this.application.createItem({
|
||||
contentType: ContentTypes.Theme,
|
||||
content: cachedTheme.content
|
||||
});
|
||||
themes.push(theme);
|
||||
}
|
||||
return themes;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user