forked from mystiq/hydrogen-web
parent
d937b9b14b
commit
5b5c852401
1 changed files with 4 additions and 6 deletions
|
@ -21,7 +21,6 @@ import { exportSession, importSession, Export } from "./export";
|
||||||
import { schema } from "./schema";
|
import { schema } from "./schema";
|
||||||
import { detectWebkitEarlyCloseTxnBug } from "./quirks";
|
import { detectWebkitEarlyCloseTxnBug } from "./quirks";
|
||||||
import { ILogItem } from "../../../logging/types";
|
import { ILogItem } from "../../../logging/types";
|
||||||
import { LogLevel } from "../../../logging/LogFilter";
|
|
||||||
|
|
||||||
const sessionName = (sessionId: string) => `hydrogen_session_${sessionId}`;
|
const sessionName = (sessionId: string) => `hydrogen_session_${sessionId}`;
|
||||||
const openDatabaseWithSessionId = function(sessionId: string, idbFactory: IDBFactory, localStorage: IDOMStorage, log: ILogItem) {
|
const openDatabaseWithSessionId = function(sessionId: string, idbFactory: IDBFactory, localStorage: IDOMStorage, log: ILogItem) {
|
||||||
|
@ -33,7 +32,7 @@ interface ServiceWorkerHandler {
|
||||||
preventConcurrentSessionAccess: (sessionId: string) => Promise<void>;
|
preventConcurrentSessionAccess: (sessionId: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function requestPersistedStorage(log: ILogItem): Promise<boolean> {
|
async function requestPersistedStorage(): Promise<boolean> {
|
||||||
// don't assume browser so we can run in node with fake-idb
|
// don't assume browser so we can run in node with fake-idb
|
||||||
const glob = this;
|
const glob = this;
|
||||||
if (glob?.navigator?.storage?.persist) {
|
if (glob?.navigator?.storage?.persist) {
|
||||||
|
@ -43,8 +42,7 @@ async function requestPersistedStorage(log: ILogItem): Promise<boolean> {
|
||||||
await glob.document.requestStorageAccess();
|
await glob.document.requestStorageAccess();
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const item = log.log("requestStorageAccess threw an error:", LogLevel.Warn);
|
console.warn("requestStorageAccess threw an error:", err);
|
||||||
item.error = err;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,10 +65,10 @@ export class StorageFactory {
|
||||||
|
|
||||||
async create(sessionId: string, log: ILogItem): Promise<Storage> {
|
async create(sessionId: string, log: ILogItem): Promise<Storage> {
|
||||||
await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId);
|
await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId);
|
||||||
requestPersistedStorage(log).then(persisted => {
|
requestPersistedStorage().then(persisted => {
|
||||||
// Firefox lies here though, and returns true even if the user denied the request
|
// Firefox lies here though, and returns true even if the user denied the request
|
||||||
if (!persisted) {
|
if (!persisted) {
|
||||||
log.log("no persisted storage, database can be evicted by browser:", LogLevel.Warn);
|
console.warn("no persisted storage, database can be evicted by browser");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue