From f65db338cf78be83178e702196e7dcdce5006d0c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 12 Feb 2021 18:05:39 +0100 Subject: [PATCH] make it work --- src/logging/IDBLogger.js | 12 ++++++------ src/logging/LogItem.js | 4 ++-- src/platform/web/Platform.js | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/logging/IDBLogger.js b/src/logging/IDBLogger.js index 155d186a..40237399 100644 --- a/src/logging/IDBLogger.js +++ b/src/logging/IDBLogger.js @@ -37,7 +37,7 @@ export class IDBLogger extends BaseLogger { // TODO: add dirty flag when calling descend // TODO: also listen for unload just in case sync keeps on running after pagehide is fired? window.addEventListener("pagehide", this, false); - this._flushInterval = this._clock.createInterval(() => this._tryFlush(), flushInterval); + this._flushInterval = this._platform.clock.createInterval(() => this._tryFlush(), flushInterval); } dispose() { @@ -54,7 +54,7 @@ export class IDBLogger extends BaseLogger { async _tryFlush() { const db = await this._openDB(); try { - const txn = this.db.transaction(["logs"], "readwrite"); + const txn = db.transaction(["logs"], "readwrite"); const logs = txn.objectStore("logs"); const amount = this._queuedItems.length; for(const i of this._queuedItems) { @@ -118,9 +118,9 @@ export class IDBLogger extends BaseLogger { } async export() { - const db = this._openDB(); + const db = await this._openDB(); try { - const txn = this.db.transaction(["logs"], "readonly"); + const txn = db.transaction(["logs"], "readonly"); const logs = txn.objectStore("logs"); const items = await fetchResults(logs.openCursor(), () => false); const sortedItems = items.concat(this._queuedItems).sort((a, b) => { @@ -135,9 +135,9 @@ export class IDBLogger extends BaseLogger { } async _removeItems(items) { - const db = this._openDB(); + const db = await this._openDB(); try { - const txn = this.db.transaction(["logs"], "readwrite"); + const txn = db.transaction(["logs"], "readwrite"); const logs = txn.objectStore("logs"); for (const item of items) { const queuedIdx = this._queuedItems.findIndex(i => i.id === item.id); diff --git a/src/logging/LogItem.js b/src/logging/LogItem.js index a63aacbb..02a0b941 100644 --- a/src/logging/LogItem.js +++ b/src/logging/LogItem.js @@ -58,7 +58,7 @@ export class LogItem { anonymize(value) { if (this._anonymize) { - const buffer = this._platform.crypto.digest("SHA-256", value); + const buffer = this._platform.crypto.digest("SHA-256", this._platform.encoding.utf8.encode(value)); return this._platform.encoding.base64.encode(buffer); } else { return value; @@ -83,8 +83,8 @@ export class LogItem { let error = null; if (this._error) { error = { - message: this._error.message, stack: this._error.stack, + name: this._error.name }; } return { diff --git a/src/platform/web/Platform.js b/src/platform/web/Platform.js index e5300779..7bd81471 100644 --- a/src/platform/web/Platform.js +++ b/src/platform/web/Platform.js @@ -21,7 +21,7 @@ import {SessionInfoStorage} from "../../matrix/sessioninfo/localstorage/SessionI import {SettingsStorage} from "./dom/SettingsStorage.js"; import {Encoding} from "./utils/Encoding.js"; import {OlmWorker} from "../../matrix/e2ee/OlmWorker.js"; -import {IDBLogger} from "../../logs/IDBLogger.js"; +import {IDBLogger} from "../../logging/IDBLogger.js"; import {RootView} from "./ui/RootView.js"; import {Clock} from "./dom/Clock.js"; import {ServiceWorkerHandler} from "./dom/ServiceWorkerHandler.js"; @@ -85,9 +85,11 @@ export class Platform { constructor(container, paths, cryptoExtras = null) { this._paths = paths; this._container = container; - this.logger = new IDBLogger("hydrogen_logs", this); - this.encoding = new Encoding(); + this.settingsStorage = new SettingsStorage("hydrogen_setting_v1_"); this.clock = new Clock(); + this.encoding = new Encoding(); + this.random = Math.random; + this.logger = new IDBLogger({name: "hydrogen_logs", platform: this}); this.history = new History(); this.onlineStatus = new OnlineStatus(); this._serviceWorkerHandler = null; @@ -98,9 +100,7 @@ export class Platform { this.crypto = new Crypto(cryptoExtras); this.storageFactory = new StorageFactory(this._serviceWorkerHandler); this.sessionInfoStorage = new SessionInfoStorage("hydrogen_sessions_v1"); - this.settingsStorage = new SettingsStorage("hydrogen_setting_v1_"); this.estimateStorageUsage = estimateStorageUsage; - this.random = Math.random; if (typeof fetch === "function") { this.request = createFetchRequest(this.clock.createTimeout); } else {