make it work

This commit is contained in:
Bruno Windels 2021-02-12 18:05:39 +01:00
parent 89139bba30
commit f65db338cf
3 changed files with 13 additions and 13 deletions

View file

@ -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);

View file

@ -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 {

View file

@ -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 {