mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
[PM-6383] Migrate clearClipboard account setting to autofill settings service (#8022)
* migrate clearClipboard account setting to autofill settings state provider * replace state service get/set clearClipboard with autofill settings service equivalents * PR suggestions cleanup
This commit is contained in:
@@ -81,8 +81,6 @@ export abstract class StateService<T extends Account = Account> {
|
||||
setHasPremiumPersonally: (value: boolean, options?: StorageOptions) => Promise<void>;
|
||||
setHasPremiumFromOrganization: (value: boolean, options?: StorageOptions) => Promise<void>;
|
||||
getHasPremiumFromOrganization: (options?: StorageOptions) => Promise<boolean>;
|
||||
getClearClipboard: (options?: StorageOptions) => Promise<number>;
|
||||
setClearClipboard: (value: number, options?: StorageOptions) => Promise<void>;
|
||||
getConvertAccountToKeyConnector: (options?: StorageOptions) => Promise<boolean>;
|
||||
setConvertAccountToKeyConnector: (value: boolean, options?: StorageOptions) => Promise<void>;
|
||||
/**
|
||||
|
||||
@@ -201,7 +201,6 @@ export class AccountProfile {
|
||||
export class AccountSettings {
|
||||
autoConfirmFingerPrints?: boolean;
|
||||
biometricUnlock?: boolean;
|
||||
clearClipboard?: number;
|
||||
defaultUriMatch?: UriMatchType;
|
||||
disableBadgeCounter?: boolean;
|
||||
disableGa?: boolean;
|
||||
|
||||
@@ -462,27 +462,6 @@ export class StateService<
|
||||
);
|
||||
}
|
||||
|
||||
async getClearClipboard(options?: StorageOptions): Promise<number> {
|
||||
return (
|
||||
(
|
||||
await this.getAccount(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()),
|
||||
)
|
||||
)?.settings?.clearClipboard ?? null
|
||||
);
|
||||
}
|
||||
|
||||
async setClearClipboard(value: number, options?: StorageOptions): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()),
|
||||
);
|
||||
account.settings.clearClipboard = value;
|
||||
await this.saveAccount(
|
||||
account,
|
||||
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()),
|
||||
);
|
||||
}
|
||||
|
||||
async getConvertAccountToKeyConnector(options?: StorageOptions): Promise<boolean> {
|
||||
return (
|
||||
await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions()))
|
||||
|
||||
@@ -3,6 +3,7 @@ import { firstValueFrom, timeout } from "rxjs";
|
||||
import { VaultTimeoutSettingsService } from "../../abstractions/vault-timeout/vault-timeout-settings.service";
|
||||
import { AuthService } from "../../auth/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "../../auth/enums/authentication-status";
|
||||
import { AutofillSettingsServiceAbstraction } from "../../autofill/services/autofill-settings.service";
|
||||
import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum";
|
||||
import { MessagingService } from "../abstractions/messaging.service";
|
||||
import { PlatformUtilsService } from "../abstractions/platform-utils.service";
|
||||
@@ -20,6 +21,7 @@ export class SystemService implements SystemServiceAbstraction {
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private reloadCallback: () => Promise<void> = null,
|
||||
private stateService: StateService,
|
||||
private autofillSettingsService: AutofillSettingsServiceAbstraction,
|
||||
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
||||
) {}
|
||||
|
||||
@@ -93,26 +95,33 @@ export class SystemService implements SystemServiceAbstraction {
|
||||
clearTimeout(this.clearClipboardTimeout);
|
||||
this.clearClipboardTimeout = null;
|
||||
}
|
||||
|
||||
if (Utils.isNullOrWhitespace(clipboardValue)) {
|
||||
return;
|
||||
}
|
||||
await this.stateService.getClearClipboard().then((clearSeconds) => {
|
||||
if (clearSeconds == null) {
|
||||
return;
|
||||
|
||||
const clearClipboardDelay = await firstValueFrom(
|
||||
this.autofillSettingsService.clearClipboardDelay$,
|
||||
);
|
||||
|
||||
if (clearClipboardDelay == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeoutMs == null) {
|
||||
timeoutMs = clearClipboardDelay * 1000;
|
||||
}
|
||||
|
||||
this.clearClipboardTimeoutFunction = async () => {
|
||||
const clipboardValueNow = await this.platformUtilsService.readFromClipboard();
|
||||
if (clipboardValue === clipboardValueNow) {
|
||||
this.platformUtilsService.copyToClipboard("", { clearing: true });
|
||||
}
|
||||
if (timeoutMs == null) {
|
||||
timeoutMs = clearSeconds * 1000;
|
||||
}
|
||||
this.clearClipboardTimeoutFunction = async () => {
|
||||
const clipboardValueNow = await this.platformUtilsService.readFromClipboard();
|
||||
if (clipboardValue === clipboardValueNow) {
|
||||
this.platformUtilsService.copyToClipboard("", { clearing: true });
|
||||
}
|
||||
};
|
||||
this.clearClipboardTimeout = setTimeout(async () => {
|
||||
await this.clearPendingClipboard();
|
||||
}, timeoutMs);
|
||||
});
|
||||
};
|
||||
|
||||
this.clearClipboardTimeout = setTimeout(async () => {
|
||||
await this.clearPendingClipboard();
|
||||
}, timeoutMs);
|
||||
}
|
||||
|
||||
async clearPendingClipboard() {
|
||||
|
||||
Reference in New Issue
Block a user