mirror of
https://github.com/bitwarden/browser
synced 2025-12-29 14:43:31 +00:00
Improve SDK direct function usage (#13353)
* feat: initalize WASM/SDK directly after load * fix: default sdk service trying to set log level * feat: wait for sdk to load in sdk service * fix: add required disposable polyfills * feat: update sdk version * feat: replace rc-specific workaround with global polyfill * fix: sdk service tests
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import "core-js/proposals/explicit-resource-management";
|
||||
|
||||
import { filter, firstValueFrom, map, merge, Subject, timeout } from "rxjs";
|
||||
|
||||
import { CollectionService, DefaultCollectionService } from "@bitwarden/admin-console/common";
|
||||
@@ -1290,7 +1292,7 @@ export default class MainBackground {
|
||||
}
|
||||
this.containerService.attachToGlobal(self);
|
||||
|
||||
await this.sdkLoadService.load();
|
||||
await this.sdkLoadService.loadAndInit();
|
||||
// Only the "true" background should run migrations
|
||||
await this.stateService.init({ runMigrations: true });
|
||||
|
||||
|
||||
@@ -60,8 +60,10 @@ async function importModule(): Promise<GlobalWithWasmInit["initSdk"]> {
|
||||
return (globalThis as GlobalWithWasmInit).initSdk;
|
||||
}
|
||||
|
||||
export class BrowserSdkLoadService implements SdkLoadService {
|
||||
constructor(readonly logService: LogService) {}
|
||||
export class BrowserSdkLoadService extends SdkLoadService {
|
||||
constructor(readonly logService: LogService) {
|
||||
super();
|
||||
}
|
||||
|
||||
async load(): Promise<void> {
|
||||
const startTime = performance.now();
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
import "core-js/stable";
|
||||
import "core-js/proposals/explicit-resource-management";
|
||||
import "zone.js";
|
||||
|
||||
@@ -32,7 +32,7 @@ export class InitService {
|
||||
|
||||
init() {
|
||||
return async () => {
|
||||
await this.sdkLoadService.load();
|
||||
await this.sdkLoadService.loadAndInit();
|
||||
await this.stateService.init({ runMigrations: false }); // Browser background is responsible for migrations
|
||||
await this.i18nService.init();
|
||||
this.twoFactorService.init();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import "core-js/proposals/explicit-resource-management";
|
||||
|
||||
import { program } from "commander";
|
||||
|
||||
import { OssServeConfigurator } from "./oss-serve-configurator";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import * as sdk from "@bitwarden/sdk-internal";
|
||||
|
||||
export class CliSdkLoadService implements SdkLoadService {
|
||||
export class CliSdkLoadService extends SdkLoadService {
|
||||
async load(): Promise<void> {
|
||||
const module = await import("@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm");
|
||||
(sdk as any).init(module);
|
||||
|
||||
@@ -867,7 +867,7 @@ export class ServiceContainer {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.sdkLoadService.load();
|
||||
await this.sdkLoadService.loadAndInit();
|
||||
await this.storageService.init();
|
||||
await this.stateService.init();
|
||||
this.containerService.attachToGlobal(global);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import "core-js/proposals/explicit-resource-management";
|
||||
|
||||
import { enableProdMode } from "@angular/core";
|
||||
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export class InitService {
|
||||
|
||||
init() {
|
||||
return async () => {
|
||||
await this.sdkLoadService.load();
|
||||
await this.sdkLoadService.loadAndInit();
|
||||
await this.sshAgentService.init();
|
||||
this.nativeMessagingService.init();
|
||||
await this.stateService.init({ runMigrations: false }); // Desktop will run them in main process
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import "core-js/proposals/explicit-resource-management";
|
||||
|
||||
import * as path from "path";
|
||||
|
||||
import { app } from "electron";
|
||||
|
||||
@@ -42,7 +42,7 @@ export class InitService {
|
||||
|
||||
init() {
|
||||
return async () => {
|
||||
await this.sdkLoadService.load();
|
||||
await this.sdkLoadService.loadAndInit();
|
||||
await this.stateService.init();
|
||||
|
||||
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||
|
||||
@@ -18,7 +18,7 @@ const supported = (() => {
|
||||
return false;
|
||||
})();
|
||||
|
||||
export class WebSdkLoadService implements SdkLoadService {
|
||||
export class WebSdkLoadService extends SdkLoadService {
|
||||
async load(): Promise<void> {
|
||||
let module: any;
|
||||
if (supported) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import "core-js/stable";
|
||||
import "core-js/proposals/explicit-resource-management";
|
||||
import "zone.js";
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
|
||||
Reference in New Issue
Block a user