Fix #213: app now clears clipboard in 45s
This commit is contained in:
parent
a849b667dc
commit
3cc2182bc0
2 changed files with 11 additions and 22 deletions
|
|
@ -406,7 +406,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
decryptedPassword = try self.passwordStore.decrypt(passwordEntity: passwordEntity, requestPGPKeyPassphrase: self.requestPGPKeyPassphrase)
|
decryptedPassword = try self.passwordStore.decrypt(passwordEntity: passwordEntity, requestPGPKeyPassphrase: self.requestPGPKeyPassphrase)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SecurePasteboard.shared.copy(textToCopy: decryptedPassword?.password)
|
SecurePasteboard.shared.copy(textToCopy: decryptedPassword?.password)
|
||||||
SVProgressHUD.showSuccess(withStatus: "Password copied, and will be cleared in 45 seconds.")
|
SVProgressHUD.showSuccess(withStatus: "Password copied. We will clear the pasteboard in 45 seconds.")
|
||||||
SVProgressHUD.dismiss(withDelay: 0.6)
|
SVProgressHUD.dismiss(withDelay: 0.6)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import UIKit
|
||||||
|
|
||||||
class SecurePasteboard {
|
class SecurePasteboard {
|
||||||
public static let shared = SecurePasteboard()
|
public static let shared = SecurePasteboard()
|
||||||
private var backgroundTaskID: UIBackgroundTaskIdentifier? = nil
|
private var backgroundTaskID = UIBackgroundTaskInvalid
|
||||||
|
|
||||||
func copy(textToCopy: String?, expirationTime: Double = 45) {
|
func copy(textToCopy: String?, expirationTime: Double = 45) {
|
||||||
// copy to the pasteboard
|
// copy to the pasteboard
|
||||||
|
|
@ -23,32 +23,21 @@ class SecurePasteboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit the existing background task, if any
|
// exit the existing background task, if any
|
||||||
if let backgroundTaskID = backgroundTaskID {
|
if backgroundTaskID != UIBackgroundTaskInvalid {
|
||||||
UIApplication.shared.endBackgroundTask(backgroundTaskID)
|
UIApplication.shared.endBackgroundTask(UIBackgroundTaskInvalid)
|
||||||
self.backgroundTaskID = nil
|
self.backgroundTaskID = UIBackgroundTaskInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
backgroundTaskID = UIApplication.shared.beginBackgroundTask(expirationHandler: { [weak self] in
|
backgroundTaskID = UIApplication.shared.beginBackgroundTask(expirationHandler: { [weak self] in
|
||||||
guard let taskID = self?.backgroundTaskID else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if textToCopy == UIPasteboard.general.string {
|
|
||||||
UIPasteboard.general.string = ""
|
UIPasteboard.general.string = ""
|
||||||
}
|
UIApplication.shared.endBackgroundTask(UIBackgroundTaskInvalid)
|
||||||
UIApplication.shared.endBackgroundTask(taskID)
|
self?.backgroundTaskID = UIBackgroundTaskInvalid
|
||||||
})
|
})
|
||||||
|
|
||||||
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + expirationTime) { [weak self] in
|
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + expirationTime) { [weak self] in
|
||||||
guard let strongSelf = self else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if textToCopy == UIPasteboard.general.string {
|
|
||||||
UIPasteboard.general.string = ""
|
UIPasteboard.general.string = ""
|
||||||
}
|
UIApplication.shared.endBackgroundTask(UIBackgroundTaskInvalid)
|
||||||
if let backgroundTaskID = strongSelf.backgroundTaskID {
|
self?.backgroundTaskID = UIBackgroundTaskInvalid
|
||||||
UIApplication.shared.endBackgroundTask(backgroundTaskID)
|
|
||||||
strongSelf.backgroundTaskID = nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue