1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-30 13:03:53 +01: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; startProcessReload: () => void;
cancelProcessReload: () => void; cancelProcessReload: () => void;
clearClipboard: (clipboardValue: string, timeoutMs?: number) => 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 { export class SystemService implements SystemServiceAbstraction {
private reloadInterval: any = null; private reloadInterval: any = null;
private clearClipboardTimeout: any = null; private clearClipboardTimeout: any = null;
private clearClipboardTimeoutFunction: () => Promise<any> = null;
constructor(private storageService: StorageService, private lockService: LockService, constructor(private storageService: StorageService, private lockService: LockService,
private messagingService: MessagingService, private platformUtilsService: PlatformUtilsService, private messagingService: MessagingService, private platformUtilsService: PlatformUtilsService,
@ -63,12 +64,22 @@ export class SystemService implements SystemServiceAbstraction {
if (timeoutMs == null) { if (timeoutMs == null) {
timeoutMs = clearSeconds * 1000; timeoutMs = clearSeconds * 1000;
} }
this.clearClipboardTimeout = setTimeout(async () => { this.clearClipboardTimeoutFunction = async () => {
const clipboardValueNow = await this.platformUtilsService.readFromClipboard(); const clipboardValueNow = await this.platformUtilsService.readFromClipboard();
if (clipboardValue === clipboardValueNow) { if (clipboardValue === clipboardValueNow) {
this.platformUtilsService.copyToClipboard(''); this.platformUtilsService.copyToClipboard('');
} }
};
this.clearClipboardTimeout = setTimeout(async () => {
await this.clearPendingClipboard();
}, timeoutMs); }, timeoutMs);
}); });
} }
async clearPendingClipboard() {
if (this.clearClipboardTimeoutFunction != null) {
await this.clearClipboardTimeoutFunction();
this.clearClipboardTimeoutFunction = null;
}
}
} }