Fix the "clearing passwords in 45s" function
- Copied passwords in the extension are not cleaned.
This commit is contained in:
parent
f86a5eee65
commit
a4efe57db9
7 changed files with 66 additions and 13 deletions
55
pass/Helpers/SecurePasteboard.swift
Normal file
55
pass/Helpers/SecurePasteboard.swift
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// SecurePasteboard.swift
|
||||
// pass
|
||||
//
|
||||
// Created by Yishi Lin on 2017/7/27.
|
||||
// Copyright © 2017 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class SecurePasteboard {
|
||||
public static let shared = SecurePasteboard()
|
||||
private var backgroundTaskID: UIBackgroundTaskIdentifier? = nil
|
||||
|
||||
func copy(textToCopy: String?, expirationTime: Double = 45) {
|
||||
// copy to the pasteboard
|
||||
UIPasteboard.general.string = textToCopy ?? ""
|
||||
|
||||
// clean the pasteboard after expirationTime
|
||||
guard expirationTime > 0 else {
|
||||
return
|
||||
}
|
||||
|
||||
// exit the existing background task, if any
|
||||
if let backgroundTaskID = backgroundTaskID {
|
||||
UIApplication.shared.endBackgroundTask(backgroundTaskID)
|
||||
self.backgroundTaskID = nil
|
||||
}
|
||||
|
||||
backgroundTaskID = UIApplication.shared.beginBackgroundTask(expirationHandler: { [weak self] in
|
||||
guard let taskID = self?.backgroundTaskID else {
|
||||
return
|
||||
}
|
||||
if textToCopy == UIPasteboard.general.string {
|
||||
UIPasteboard.general.string = ""
|
||||
}
|
||||
UIApplication.shared.endBackgroundTask(taskID)
|
||||
})
|
||||
|
||||
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 = ""
|
||||
}
|
||||
if let backgroundTaskID = strongSelf.backgroundTaskID {
|
||||
UIApplication.shared.endBackgroundTask(backgroundTaskID)
|
||||
strongSelf.backgroundTaskID = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue