Merge pull request #30 from yishilin14/master
clear pasteboard after 45 seconds (#25 issue)
This commit is contained in:
commit
5c7fb97dbb
4 changed files with 16 additions and 4 deletions
|
|
@ -252,7 +252,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
|
||||
override func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) {
|
||||
if action == #selector(copy(_:)) {
|
||||
UIPasteboard.general.string = tableData[indexPath.section].item[indexPath.row].content
|
||||
Utils.copyToPasteboard(textToCopy: tableData[indexPath.section].item[indexPath.row].content)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
|||
do {
|
||||
decryptedPassword = try password.decrypt()!
|
||||
DispatchQueue.main.async {
|
||||
UIPasteboard.general.string = decryptedPassword?.password
|
||||
Utils.copyToPasteboard(textToCopy: decryptedPassword?.password)
|
||||
SVProgressHUD.showSuccess(withStatus: "Password Copied")
|
||||
SVProgressHUD.dismiss(withDelay: 0.6)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,6 +113,18 @@ class Utils {
|
|||
print(error)
|
||||
}
|
||||
}
|
||||
static func copyToPasteboard(textToCopy: String?, expirationTime: Double = 45) {
|
||||
guard textToCopy != nil else {
|
||||
return
|
||||
}
|
||||
UIPasteboard.general.string = textToCopy
|
||||
DispatchQueue.global(qos: .background).asyncAfter(deadline: DispatchTime.now() + expirationTime) {
|
||||
let pasteboardString: String? = UIPasteboard.general.string
|
||||
if textToCopy == pasteboardString {
|
||||
UIPasteboard.general.string = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://gist.github.com/NikolaiRuhe/eeb135d20c84a7097516
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class LabelTableViewCell: UITableViewCell {
|
|||
}
|
||||
|
||||
override func copy(_ sender: Any?) {
|
||||
UIPasteboard.general.string = cellData?.content
|
||||
Utils.copyToPasteboard(textToCopy: cellData?.content)
|
||||
}
|
||||
|
||||
func revealPassword(_ sender: Any?) {
|
||||
|
|
@ -79,7 +79,7 @@ class LabelTableViewCell: UITableViewCell {
|
|||
}
|
||||
|
||||
func openLink(_ sender: Any?) {
|
||||
UIPasteboard.general.string = password?.password
|
||||
Utils.copyToPasteboard(textToCopy: password?.password)
|
||||
UIApplication.shared.open(URL(string: cellData!.content)!, options: [:], completionHandler: nil)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue