mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
Fix browser profiles not loading on import format change (#16357)
Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
57d6e3843f
commit
8e2f27d82b
@@ -1,7 +1,16 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
// FIXME: Update this file to be type safe and remove this and next line
|
||||||
// @ts-strict-ignore
|
// @ts-strict-ignore
|
||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angular/core";
|
import {
|
||||||
|
Component,
|
||||||
|
effect,
|
||||||
|
EventEmitter,
|
||||||
|
input,
|
||||||
|
Input,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
Output,
|
||||||
|
} from "@angular/core";
|
||||||
import {
|
import {
|
||||||
AsyncValidatorFn,
|
AsyncValidatorFn,
|
||||||
ControlContainer,
|
ControlContainer,
|
||||||
@@ -27,6 +36,8 @@ import {
|
|||||||
|
|
||||||
import { ImportType } from "../../models";
|
import { ImportType } from "../../models";
|
||||||
|
|
||||||
|
type ProfileOption = { id: string; name: string };
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "import-chrome",
|
selector: "import-chrome",
|
||||||
templateUrl: "import-chrome.component.html",
|
templateUrl: "import-chrome.component.html",
|
||||||
@@ -57,13 +68,12 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
profileList: { id: string; name: string }[] = [];
|
profileList: ProfileOption[] = [];
|
||||||
|
|
||||||
|
format = input.required<ImportType>();
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
format: ImportType;
|
onLoadProfilesFromBrowser: (browser: string) => Promise<ProfileOption[]>;
|
||||||
|
|
||||||
@Input()
|
|
||||||
onLoadProfilesFromBrowser: (browser: string) => Promise<any[]>;
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
onImportFromBrowser: (browser: string, profile: string) => Promise<any[]>;
|
onImportFromBrowser: (browser: string, profile: string) => Promise<any[]>;
|
||||||
@@ -75,12 +85,16 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
private controlContainer: ControlContainer,
|
private controlContainer: ControlContainer,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
) {}
|
) {
|
||||||
|
effect(async () => {
|
||||||
|
this.profileList = await this.onLoadProfilesFromBrowser(this.getBrowserName(this.format()));
|
||||||
|
// FIXME: Add error handling and display when profiles could not be loaded/retrieved
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
this._parentFormGroup = this.controlContainer.control as FormGroup;
|
this._parentFormGroup = this.controlContainer.control as FormGroup;
|
||||||
this._parentFormGroup.addControl("chromeOptions", this.formGroup);
|
this._parentFormGroup.addControl("chromeOptions", this.formGroup);
|
||||||
this.profileList = await this.onLoadProfilesFromBrowser(this.getBrowserName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
@@ -96,7 +110,7 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
return async () => {
|
return async () => {
|
||||||
try {
|
try {
|
||||||
const logins = await this.onImportFromBrowser(
|
const logins = await this.onImportFromBrowser(
|
||||||
this.getBrowserName(),
|
this.getBrowserName(this.format()),
|
||||||
this.formGroup.controls.profile.value,
|
this.formGroup.controls.profile.value,
|
||||||
);
|
);
|
||||||
if (logins.length === 0) {
|
if (logins.length === 0) {
|
||||||
@@ -130,14 +144,14 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getBrowserName(): string {
|
private getBrowserName(format: ImportType): string {
|
||||||
if (this.format === "edgecsv") {
|
if (format === "edgecsv") {
|
||||||
return "Microsoft Edge";
|
return "Microsoft Edge";
|
||||||
} else if (this.format === "operacsv") {
|
} else if (format === "operacsv") {
|
||||||
return "Opera";
|
return "Opera";
|
||||||
} else if (this.format === "bravecsv") {
|
} else if (format === "bravecsv") {
|
||||||
return "Brave";
|
return "Brave";
|
||||||
} else if (this.format === "vivaldicsv") {
|
} else if (format === "vivaldicsv") {
|
||||||
return "Vivaldi";
|
return "Vivaldi";
|
||||||
}
|
}
|
||||||
return "Chrome";
|
return "Chrome";
|
||||||
|
|||||||
Reference in New Issue
Block a user