[PM-6426] Implementing systemClearClipboard using TaskScheduler
This commit is contained in:
parent
b165849cd9
commit
0444489053
|
@ -850,6 +850,7 @@ export default class MainBackground {
|
||||||
this.autofillSettingsService,
|
this.autofillSettingsService,
|
||||||
this.vaultTimeoutSettingsService,
|
this.vaultTimeoutSettingsService,
|
||||||
this.biometricStateService,
|
this.biometricStateService,
|
||||||
|
this.taskSchedulerService,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Other fields
|
// Other fields
|
||||||
|
|
|
@ -66,6 +66,7 @@ import { GlobalState } from "@bitwarden/common/platform/models/domain/global-sta
|
||||||
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
|
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
|
||||||
import { ContainerService } from "@bitwarden/common/platform/services/container.service";
|
import { ContainerService } from "@bitwarden/common/platform/services/container.service";
|
||||||
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
|
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
|
||||||
|
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service";
|
||||||
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
|
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
|
||||||
import {
|
import {
|
||||||
DerivedStateProvider,
|
DerivedStateProvider,
|
||||||
|
@ -97,6 +98,7 @@ import BrowserLocalStorageService from "../../platform/services/browser-local-st
|
||||||
import BrowserMessagingPrivateModePopupService from "../../platform/services/browser-messaging-private-mode-popup.service";
|
import BrowserMessagingPrivateModePopupService from "../../platform/services/browser-messaging-private-mode-popup.service";
|
||||||
import BrowserMessagingService from "../../platform/services/browser-messaging.service";
|
import BrowserMessagingService from "../../platform/services/browser-messaging.service";
|
||||||
import { BrowserStateService } from "../../platform/services/browser-state.service";
|
import { BrowserStateService } from "../../platform/services/browser-state.service";
|
||||||
|
import { BrowserTaskSchedulerService } from "../../platform/services/browser-task-scheduler.service";
|
||||||
import I18nService from "../../platform/services/i18n.service";
|
import I18nService from "../../platform/services/i18n.service";
|
||||||
import { ForegroundPlatformUtilsService } from "../../platform/services/platform-utils/foreground-platform-utils.service";
|
import { ForegroundPlatformUtilsService } from "../../platform/services/platform-utils/foreground-platform-utils.service";
|
||||||
import { ForegroundDerivedStateProvider } from "../../platform/state/foreground-derived-state.provider";
|
import { ForegroundDerivedStateProvider } from "../../platform/state/foreground-derived-state.provider";
|
||||||
|
@ -464,6 +466,14 @@ const safeProviders: SafeProvider[] = [
|
||||||
useClass: UserNotificationSettingsService,
|
useClass: UserNotificationSettingsService,
|
||||||
deps: [StateProvider],
|
deps: [StateProvider],
|
||||||
}),
|
}),
|
||||||
|
safeProvider({
|
||||||
|
provide: TaskSchedulerService,
|
||||||
|
useExisting: BrowserTaskSchedulerService,
|
||||||
|
}),
|
||||||
|
safeProvider({
|
||||||
|
provide: BrowserTaskSchedulerService,
|
||||||
|
deps: [LogService, StateProvider],
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
@ -45,6 +45,7 @@ import { GlobalState } from "@bitwarden/common/platform/models/domain/global-sta
|
||||||
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
|
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
|
||||||
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
|
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
|
||||||
import { SystemService } from "@bitwarden/common/platform/services/system.service";
|
import { SystemService } from "@bitwarden/common/platform/services/system.service";
|
||||||
|
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service";
|
||||||
import { GlobalStateProvider, StateProvider } from "@bitwarden/common/platform/state";
|
import { GlobalStateProvider, StateProvider } from "@bitwarden/common/platform/state";
|
||||||
// eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage
|
// eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage
|
||||||
import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@bitwarden/common/platform/state/storage/memory-storage.service";
|
import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@bitwarden/common/platform/state/storage/memory-storage.service";
|
||||||
|
@ -168,6 +169,7 @@ const safeProviders: SafeProvider[] = [
|
||||||
AutofillSettingsServiceAbstraction,
|
AutofillSettingsServiceAbstraction,
|
||||||
VaultTimeoutSettingsService,
|
VaultTimeoutSettingsService,
|
||||||
BiometricStateService,
|
BiometricStateService,
|
||||||
|
TaskSchedulerService,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
|
@ -247,6 +249,10 @@ const safeProviders: SafeProvider[] = [
|
||||||
provide: DesktopAutofillSettingsService,
|
provide: DesktopAutofillSettingsService,
|
||||||
deps: [StateProvider],
|
deps: [StateProvider],
|
||||||
}),
|
}),
|
||||||
|
safeProvider({
|
||||||
|
provide: TaskSchedulerService,
|
||||||
|
deps: [],
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
@ -147,6 +147,7 @@ import { MigrationRunner } from "@bitwarden/common/platform/services/migration-r
|
||||||
import { NoopNotificationsService } from "@bitwarden/common/platform/services/noop-notifications.service";
|
import { NoopNotificationsService } from "@bitwarden/common/platform/services/noop-notifications.service";
|
||||||
import { StateService } from "@bitwarden/common/platform/services/state.service";
|
import { StateService } from "@bitwarden/common/platform/services/state.service";
|
||||||
import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider";
|
import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider";
|
||||||
|
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service";
|
||||||
import { ValidationService } from "@bitwarden/common/platform/services/validation.service";
|
import { ValidationService } from "@bitwarden/common/platform/services/validation.service";
|
||||||
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
|
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
|
||||||
import {
|
import {
|
||||||
|
@ -1069,6 +1070,10 @@ const safeProviders: SafeProvider[] = [
|
||||||
useClass: DefaultOrganizationManagementPreferencesService,
|
useClass: DefaultOrganizationManagementPreferencesService,
|
||||||
deps: [StateProvider],
|
deps: [StateProvider],
|
||||||
}),
|
}),
|
||||||
|
safeProvider({
|
||||||
|
provide: TaskSchedulerService,
|
||||||
|
deps: [],
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
function encryptServiceFactory(
|
function encryptServiceFactory(
|
||||||
|
|
|
@ -9,7 +9,9 @@ import { MessagingService } from "../abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "../abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "../abstractions/platform-utils.service";
|
||||||
import { StateService } from "../abstractions/state.service";
|
import { StateService } from "../abstractions/state.service";
|
||||||
import { SystemService as SystemServiceAbstraction } from "../abstractions/system.service";
|
import { SystemService as SystemServiceAbstraction } from "../abstractions/system.service";
|
||||||
|
import { TaskSchedulerService } from "../abstractions/task-scheduler.service";
|
||||||
import { BiometricStateService } from "../biometrics/biometric-state.service";
|
import { BiometricStateService } from "../biometrics/biometric-state.service";
|
||||||
|
import { ScheduledTaskNames } from "../enums/scheduled-task-name.enum";
|
||||||
import { Utils } from "../misc/utils";
|
import { Utils } from "../misc/utils";
|
||||||
|
|
||||||
export class SystemService implements SystemServiceAbstraction {
|
export class SystemService implements SystemServiceAbstraction {
|
||||||
|
@ -25,6 +27,7 @@ export class SystemService implements SystemServiceAbstraction {
|
||||||
private autofillSettingsService: AutofillSettingsServiceAbstraction,
|
private autofillSettingsService: AutofillSettingsServiceAbstraction,
|
||||||
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
private vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
||||||
private biometricStateService: BiometricStateService,
|
private biometricStateService: BiometricStateService,
|
||||||
|
private taskSchedulerService: TaskSchedulerService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async startProcessReload(authService: AuthService): Promise<void> {
|
async startProcessReload(authService: AuthService): Promise<void> {
|
||||||
|
@ -94,25 +97,25 @@ export class SystemService implements SystemServiceAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearClipboard(clipboardValue: string, timeoutMs: number = null): Promise<void> {
|
async clearClipboard(clipboardValue: string, timeoutMs: number = null): Promise<void> {
|
||||||
if (this.clearClipboardTimeout != null) {
|
let taskTimeoutInMs = timeoutMs;
|
||||||
clearTimeout(this.clearClipboardTimeout);
|
await this.taskSchedulerService.clearScheduledTask({
|
||||||
this.clearClipboardTimeout = null;
|
taskName: ScheduledTaskNames.systemClearClipboardTimeout,
|
||||||
}
|
timeoutId: this.clearClipboardTimeout,
|
||||||
|
});
|
||||||
|
|
||||||
if (Utils.isNullOrWhitespace(clipboardValue)) {
|
if (Utils.isNullOrWhitespace(clipboardValue)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clearClipboardDelay = await firstValueFrom(
|
if (!taskTimeoutInMs) {
|
||||||
|
const clearClipboardDelayInSeconds = await firstValueFrom(
|
||||||
this.autofillSettingsService.clearClipboardDelay$,
|
this.autofillSettingsService.clearClipboardDelay$,
|
||||||
);
|
);
|
||||||
|
taskTimeoutInMs = clearClipboardDelayInSeconds ? clearClipboardDelayInSeconds * 1000 : null;
|
||||||
if (clearClipboardDelay == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeoutMs == null) {
|
if (!taskTimeoutInMs) {
|
||||||
timeoutMs = clearClipboardDelay * 1000;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearClipboardTimeoutFunction = async () => {
|
this.clearClipboardTimeoutFunction = async () => {
|
||||||
|
@ -122,9 +125,11 @@ export class SystemService implements SystemServiceAbstraction {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.clearClipboardTimeout = setTimeout(async () => {
|
this.clearClipboardTimeout = this.taskSchedulerService.setTimeout(
|
||||||
await this.clearPendingClipboard();
|
() => this.clearPendingClipboard(),
|
||||||
}, timeoutMs);
|
taskTimeoutInMs,
|
||||||
|
ScheduledTaskNames.systemClearClipboardTimeout,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearPendingClipboard() {
|
async clearPendingClipboard() {
|
||||||
|
|
Loading…
Reference in New Issue