forked from mystiq/hydrogen-web
make it work
This commit is contained in:
parent
89139bba30
commit
f65db338cf
3 changed files with 13 additions and 13 deletions
|
@ -37,7 +37,7 @@ export class IDBLogger extends BaseLogger {
|
||||||
// TODO: add dirty flag when calling descend
|
// TODO: add dirty flag when calling descend
|
||||||
// TODO: also listen for unload just in case sync keeps on running after pagehide is fired?
|
// TODO: also listen for unload just in case sync keeps on running after pagehide is fired?
|
||||||
window.addEventListener("pagehide", this, false);
|
window.addEventListener("pagehide", this, false);
|
||||||
this._flushInterval = this._clock.createInterval(() => this._tryFlush(), flushInterval);
|
this._flushInterval = this._platform.clock.createInterval(() => this._tryFlush(), flushInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
@ -54,7 +54,7 @@ export class IDBLogger extends BaseLogger {
|
||||||
async _tryFlush() {
|
async _tryFlush() {
|
||||||
const db = await this._openDB();
|
const db = await this._openDB();
|
||||||
try {
|
try {
|
||||||
const txn = this.db.transaction(["logs"], "readwrite");
|
const txn = db.transaction(["logs"], "readwrite");
|
||||||
const logs = txn.objectStore("logs");
|
const logs = txn.objectStore("logs");
|
||||||
const amount = this._queuedItems.length;
|
const amount = this._queuedItems.length;
|
||||||
for(const i of this._queuedItems) {
|
for(const i of this._queuedItems) {
|
||||||
|
@ -118,9 +118,9 @@ export class IDBLogger extends BaseLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
async export() {
|
async export() {
|
||||||
const db = this._openDB();
|
const db = await this._openDB();
|
||||||
try {
|
try {
|
||||||
const txn = this.db.transaction(["logs"], "readonly");
|
const txn = db.transaction(["logs"], "readonly");
|
||||||
const logs = txn.objectStore("logs");
|
const logs = txn.objectStore("logs");
|
||||||
const items = await fetchResults(logs.openCursor(), () => false);
|
const items = await fetchResults(logs.openCursor(), () => false);
|
||||||
const sortedItems = items.concat(this._queuedItems).sort((a, b) => {
|
const sortedItems = items.concat(this._queuedItems).sort((a, b) => {
|
||||||
|
@ -135,9 +135,9 @@ export class IDBLogger extends BaseLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _removeItems(items) {
|
async _removeItems(items) {
|
||||||
const db = this._openDB();
|
const db = await this._openDB();
|
||||||
try {
|
try {
|
||||||
const txn = this.db.transaction(["logs"], "readwrite");
|
const txn = db.transaction(["logs"], "readwrite");
|
||||||
const logs = txn.objectStore("logs");
|
const logs = txn.objectStore("logs");
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const queuedIdx = this._queuedItems.findIndex(i => i.id === item.id);
|
const queuedIdx = this._queuedItems.findIndex(i => i.id === item.id);
|
||||||
|
|
|
@ -58,7 +58,7 @@ export class LogItem {
|
||||||
|
|
||||||
anonymize(value) {
|
anonymize(value) {
|
||||||
if (this._anonymize) {
|
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);
|
return this._platform.encoding.base64.encode(buffer);
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
|
@ -83,8 +83,8 @@ export class LogItem {
|
||||||
let error = null;
|
let error = null;
|
||||||
if (this._error) {
|
if (this._error) {
|
||||||
error = {
|
error = {
|
||||||
message: this._error.message,
|
|
||||||
stack: this._error.stack,
|
stack: this._error.stack,
|
||||||
|
name: this._error.name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -21,7 +21,7 @@ import {SessionInfoStorage} from "../../matrix/sessioninfo/localstorage/SessionI
|
||||||
import {SettingsStorage} from "./dom/SettingsStorage.js";
|
import {SettingsStorage} from "./dom/SettingsStorage.js";
|
||||||
import {Encoding} from "./utils/Encoding.js";
|
import {Encoding} from "./utils/Encoding.js";
|
||||||
import {OlmWorker} from "../../matrix/e2ee/OlmWorker.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 {RootView} from "./ui/RootView.js";
|
||||||
import {Clock} from "./dom/Clock.js";
|
import {Clock} from "./dom/Clock.js";
|
||||||
import {ServiceWorkerHandler} from "./dom/ServiceWorkerHandler.js";
|
import {ServiceWorkerHandler} from "./dom/ServiceWorkerHandler.js";
|
||||||
|
@ -85,9 +85,11 @@ export class Platform {
|
||||||
constructor(container, paths, cryptoExtras = null) {
|
constructor(container, paths, cryptoExtras = null) {
|
||||||
this._paths = paths;
|
this._paths = paths;
|
||||||
this._container = container;
|
this._container = container;
|
||||||
this.logger = new IDBLogger("hydrogen_logs", this);
|
this.settingsStorage = new SettingsStorage("hydrogen_setting_v1_");
|
||||||
this.encoding = new Encoding();
|
|
||||||
this.clock = new Clock();
|
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.history = new History();
|
||||||
this.onlineStatus = new OnlineStatus();
|
this.onlineStatus = new OnlineStatus();
|
||||||
this._serviceWorkerHandler = null;
|
this._serviceWorkerHandler = null;
|
||||||
|
@ -98,9 +100,7 @@ export class Platform {
|
||||||
this.crypto = new Crypto(cryptoExtras);
|
this.crypto = new Crypto(cryptoExtras);
|
||||||
this.storageFactory = new StorageFactory(this._serviceWorkerHandler);
|
this.storageFactory = new StorageFactory(this._serviceWorkerHandler);
|
||||||
this.sessionInfoStorage = new SessionInfoStorage("hydrogen_sessions_v1");
|
this.sessionInfoStorage = new SessionInfoStorage("hydrogen_sessions_v1");
|
||||||
this.settingsStorage = new SettingsStorage("hydrogen_setting_v1_");
|
|
||||||
this.estimateStorageUsage = estimateStorageUsage;
|
this.estimateStorageUsage = estimateStorageUsage;
|
||||||
this.random = Math.random;
|
|
||||||
if (typeof fetch === "function") {
|
if (typeof fetch === "function") {
|
||||||
this.request = createFetchRequest(this.clock.createTimeout);
|
this.request = createFetchRequest(this.clock.createTimeout);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue