Changeset View
Changeset View
Standalone View
Standalone View
web/database/database-module-provider.js
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | this.initPromise = (async () => { | ||||
console.info('Database initialization success'); | console.info('Database initialization success'); | ||||
} catch (error) { | } catch (error) { | ||||
this.status = databaseStatuses.initError; | this.status = databaseStatuses.initError; | ||||
console.error(`Database initialization failure`, error); | console.error(`Database initialization failure`, error); | ||||
} | } | ||||
})(); | })(); | ||||
} | } | ||||
userLoggedIn(currentLoggedInUserID: ?string) { | initDBForLoggedInUser(currentLoggedInUserID: ?string) { | ||||
if (this.status === databaseStatuses.initSuccess) { | |||||
return; | |||||
} | |||||
if ( | if ( | ||||
this.status === databaseStatuses.notSupported && | this.status === databaseStatuses.notSupported && | ||||
isSQLiteSupported(currentLoggedInUserID) | isSQLiteSupported(currentLoggedInUserID) | ||||
) { | ) { | ||||
this.init(); | this.init(); | ||||
} | } | ||||
} | } | ||||
async clearSensitiveData(): Promise<void> { | |||||
this.status = databaseStatuses.notSupported; | |||||
await this.workerProxy.scheduleOnWorker({ | |||||
type: workerRequestMessageTypes.CLEAR_SENSITIVE_DATA, | |||||
}); | |||||
} | |||||
async isDatabaseSupported(): Promise<boolean> { | |||||
if (this.status === databaseStatuses.initInProgress) { | |||||
await this.initPromise; | |||||
} | |||||
return this.status === databaseStatuses.initSuccess; | |||||
} | |||||
async schedule( | async schedule( | ||||
payload: WorkerRequestMessage, | payload: WorkerRequestMessage, | ||||
): Promise<?WorkerResponseMessage> { | ): Promise<?WorkerResponseMessage> { | ||||
if (this.status === databaseStatuses.notSupported) { | if (this.status === databaseStatuses.notSupported) { | ||||
throw new Error('Database not supported'); | throw new Error('Database not supported'); | ||||
} | } | ||||
if (this.status === databaseStatuses.initInProgress) { | if (this.status === databaseStatuses.initInProgress) { | ||||
Show All 14 Lines |