1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

clearPendingClipboard function

This commit is contained in:
Kyle Spearrin 2019-02-27 11:56:17 -05:00
parent b9267c521d
commit 62e9c75357
2 changed files with 13 additions and 1 deletions

View File

@ -2,4 +2,5 @@ export abstract class SystemService {
startProcessReload: () => void;
cancelProcessReload: () => void;
clearClipboard: (clipboardValue: string, timeoutMs?: number) => void;
clearPendingClipboard: () => Promise<any>;
}

View File

@ -11,6 +11,7 @@ import { Utils } from '../misc/utils';
export class SystemService implements SystemServiceAbstraction {
private reloadInterval: any = null;
private clearClipboardTimeout: any = null;
private clearClipboardTimeoutFunction: () => Promise<any> = null;
constructor(private storageService: StorageService, private lockService: LockService,
private messagingService: MessagingService, private platformUtilsService: PlatformUtilsService,
@ -63,12 +64,22 @@ export class SystemService implements SystemServiceAbstraction {
if (timeoutMs == null) {
timeoutMs = clearSeconds * 1000;
}
this.clearClipboardTimeout = setTimeout(async () => {
this.clearClipboardTimeoutFunction = async () => {
const clipboardValueNow = await this.platformUtilsService.readFromClipboard();
if (clipboardValue === clipboardValueNow) {
this.platformUtilsService.copyToClipboard('');
}
};
this.clearClipboardTimeout = setTimeout(async () => {
await this.clearPendingClipboard();
}, timeoutMs);
});
}
async clearPendingClipboard() {
if (this.clearClipboardTimeoutFunction != null) {
await this.clearClipboardTimeoutFunction();
this.clearClipboardTimeoutFunction = null;
}
}
}