From 62e9c75357b211db6de769d8592224fc846638aa Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 27 Feb 2019 11:56:17 -0500 Subject: [PATCH] clearPendingClipboard function --- src/abstractions/system.service.ts | 1 + src/services/system.service.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/abstractions/system.service.ts b/src/abstractions/system.service.ts index cf4f3e31333..c8948bc11b8 100644 --- a/src/abstractions/system.service.ts +++ b/src/abstractions/system.service.ts @@ -2,4 +2,5 @@ export abstract class SystemService { startProcessReload: () => void; cancelProcessReload: () => void; clearClipboard: (clipboardValue: string, timeoutMs?: number) => void; + clearPendingClipboard: () => Promise; } diff --git a/src/services/system.service.ts b/src/services/system.service.ts index 310dfacb4df..1e492c077f5 100644 --- a/src/services/system.service.ts +++ b/src/services/system.service.ts @@ -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 = 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; + } + } }