mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
[PM-26731] Add feature flag for chromium importers with ABE (#16926)
* Add missing browser to SUPPORTED_BROWSERS in windows.rs These were previously removed due to needing ABE support * Add feature flag for chromium importer with ABE * Fix tests for windows * Run cargo fmt --------- Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
aa12700ebc
commit
bbfdb60c34
@@ -1,9 +1,11 @@
|
||||
import { map, Observable } from "rxjs";
|
||||
import { combineLatest, map, Observable } from "rxjs";
|
||||
|
||||
import { ClientType, DeviceType } from "@bitwarden/common/enums";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { SemanticLogger } from "@bitwarden/common/tools/log";
|
||||
import { SystemServiceProvider } from "@bitwarden/common/tools/providers";
|
||||
|
||||
import { ImporterMetadata, Importers, ImportersMetadata } from "../metadata";
|
||||
import { DataLoader, ImporterMetadata, Importers, ImportersMetadata, Loader } from "../metadata";
|
||||
import { ImportType } from "../models/import-options";
|
||||
import { availableLoaders } from "../util";
|
||||
|
||||
@@ -13,8 +15,13 @@ export class DefaultImportMetadataService implements ImportMetadataServiceAbstra
|
||||
protected importers: ImportersMetadata = Importers;
|
||||
private logger: SemanticLogger;
|
||||
|
||||
private chromiumWithABE$: Observable<boolean>;
|
||||
|
||||
constructor(protected system: SystemServiceProvider) {
|
||||
this.logger = system.log({ type: "ImportMetadataService" });
|
||||
this.chromiumWithABE$ = this.system.configService.getFeatureFlag$(
|
||||
FeatureFlag.ChromiumImporterWithABE,
|
||||
);
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
@@ -23,13 +30,13 @@ export class DefaultImportMetadataService implements ImportMetadataServiceAbstra
|
||||
|
||||
metadata$(type$: Observable<ImportType>): Observable<ImporterMetadata> {
|
||||
const client = this.system.environment.getClientType();
|
||||
const capabilities$ = type$.pipe(
|
||||
map((type) => {
|
||||
const capabilities$ = combineLatest([type$, this.chromiumWithABE$]).pipe(
|
||||
map(([type, enabled]) => {
|
||||
if (!this.importers) {
|
||||
return { type, loaders: [] };
|
||||
}
|
||||
|
||||
const loaders = availableLoaders(this.importers, type, client);
|
||||
const loaders = this.availableLoaders(this.importers, type, client, enabled);
|
||||
|
||||
if (!loaders || loaders.length === 0) {
|
||||
return { type, loaders: [] };
|
||||
@@ -48,4 +55,33 @@ export class DefaultImportMetadataService implements ImportMetadataServiceAbstra
|
||||
|
||||
return capabilities$;
|
||||
}
|
||||
|
||||
/** Determine the available loaders for the given import type and client, considering feature flags and environments */
|
||||
private availableLoaders(
|
||||
importers: ImportersMetadata,
|
||||
type: ImportType,
|
||||
client: ClientType,
|
||||
enabled: boolean,
|
||||
): DataLoader[] | undefined {
|
||||
let loaders = availableLoaders(importers, type, client);
|
||||
let includeABE = false;
|
||||
|
||||
if (enabled && (type === "bravecsv" || type === "chromecsv" || type === "edgecsv")) {
|
||||
try {
|
||||
const device = this.system.environment.getDevice();
|
||||
const isWindowsDesktop = device === DeviceType.WindowsDesktop;
|
||||
if (isWindowsDesktop) {
|
||||
includeABE = true;
|
||||
}
|
||||
} catch {
|
||||
includeABE = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If the browser is unsupported, remove the chromium loader
|
||||
if (!includeABE) {
|
||||
loaders = loaders?.filter((loader) => loader !== Loader.chromium);
|
||||
}
|
||||
return loaders;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user