Fix issues with OTP notification (#517)

* Use "Beta" since this is what Apple uses too
* Actually copy the OTP if the option is set
* Shorten notification text to make it fit to smaller screens
* Set notification center delegate before app launches
* Fix SwiftFormat issue fixed with version 0.48.12
This commit is contained in:
Danny Mösch 2021-10-04 02:20:22 +02:00 committed by GitHub
parent 32b7c9b635
commit 3eea063d61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 10 deletions

View file

@ -34,6 +34,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
perform(#selector(postSearchNotification), with: nil, afterDelay: 0.4)
}
}
UNUserNotificationCenter.current().delegate = NotificationCenterDispatcher.shared
return true
}

View file

@ -99,7 +99,6 @@ class PasswordNavigationViewController: UIViewController {
options: []
)
notificationCenter.setNotificationCategories([otpCategory])
notificationCenter.delegate = NotificationCenterDispatcher.shared
}
override func viewWillAppear(_ animated: Bool) {

View file

@ -225,7 +225,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
@objc
func alertTextFieldDidChange(_ sender: UITextField) {
// check whether we should enable the Save button in setPasscodeLockAlert
if let setPasscodeLockAlert = self.setPasscodeLockAlert,
if let setPasscodeLockAlert = setPasscodeLockAlert,
let setPasscodeLockAlertTextFields0 = setPasscodeLockAlert.textFields?[0],
let setPasscodeLockAlertTextFields1 = setPasscodeLockAlert.textFields?[1] {
if sender == setPasscodeLockAlertTextFields0 || sender == setPasscodeLockAlertTextFields1 {

View file

@ -23,10 +23,10 @@
"None" = "Kein valides Token";
"ExpiresIn" = "(läuft in %ds ab)";
"OTPForPassword" = "Einmalpasswort für %@";
"OTPForPasswordCopied" = "Einmalpasswort für %@ kopiert";
"OTPHasBeenCopied" = "... wurde in die Zwischenablage kopiert";
"CopyToPasteboard" = "In Zwischenablage kopieren";
"AutoCopyOTP" = "OTPs automatisch kopieren";
"AutoCopyOTPExplanation." = "Nachdem Login und Passwort automatisch in die vorgesehenen Felder gefüllt wurden, wird eine Benachrichtigung mit dem aktuellen Einmalpasswort angezeigt. Dieses kann in die Zwischenablage kopiert werden. Ist diese Option aktiviert, geschieht das Kopieren automatisch.";
"AutoCopyOTPExplanation." = "Nachdem Login und Passwort automatisch in die vorgesehenen Felder eingefügt wurden, wird eine Benachrichtigung mit dem aktuellen Einmalpasswort angezeigt. Dieses kann in die Zwischenablage kopiert werden. Ist diese Option aktiviert, geschieht das Kopieren automatisch.";
// General (error) messages
"Error" = "Fehler";
@ -46,7 +46,7 @@
"PasswordGeneratorFlavor" = "Art";
"RememberPgpKeyPassphrase" = "GPG-Schlüssel-Passwort merken";
"RememberGitCredentialPassphrase" = "Git-Server-Passwort merken";
"EnableGPGID" = "Berücksichtige .gpg-id Dateien (experimentell)";
"EnableGPGID" = "Berücksichtige .gpg-id Dateien (Beta)";
"ShowFolders" = "Ordner anzeigen";
"HidePasswordImages" = "Favicons verstecken";
"HidePasswordImagesExplanation." = "Favicons werden basierend auf der assoziierten URL geladen und in Passworteinträgen angezeigt. Aktiviere diese Option, um das Laden dieser Bilder zu unterbinden und sie nicht anzuzeigen.";

View file

@ -23,7 +23,7 @@
"None" = "None";
"ExpiresIn" = "(expires in %ds)";
"OTPForPassword" = "One-time password for %@";
"OTPForPasswordCopied" = "One-time password for %@ copied";
"OTPHasBeenCopied" = "... has been copied to the pasteboard";
"CopyToPasteboard" = "Copy to pasteboard";
"AutoCopyOTP" = "Automatically Copy OTPs";
"AutoCopyOTPExplanation." = "After username and password have been auto-filled into a form by Pass, a notification is shown with the current one-time password which can be copied to the pasteboard. Enabling this option automatically copies the current one-time password.";
@ -46,7 +46,7 @@
"PasswordGeneratorFlavor" = "Style";
"RememberPgpKeyPassphrase" = "Remember PGP Key Passphrase";
"RememberGitCredentialPassphrase" = "Remember Git Credential Passphrase";
"EnableGPGID" = "Enable .gpg-id (Experiment)";
"EnableGPGID" = "Enable .gpg-id (Beta)";
"ShowFolders" = "Show Folders";
"HidePasswordImages" = "Hide Password Images";
"HidePasswordImagesExplanation." = "Associated favicon images are loaded and shown based upon the URL associated with an entry. Enable this option to hide these images and prevent them from being loaded.";

View file

@ -28,10 +28,11 @@ public class NotificationCenterDispatcher: NSObject, UNUserNotificationCenterDel
return
}
let content = UNMutableNotificationContent()
content.title = "OTPForPassword".localize(password.name)
if Defaults.autoCopyOTP {
content.title = "OTPForPasswordCopied".localize(password.name)
content.body = "OTPHasBeenCopied".localize()
UIPasteboard.general.string = otp
} else {
content.title = "OTPForPassword".localize(password.name)
content.body = otp
content.categoryIdentifier = Globals.otpNotificationCategory
content.userInfo = [

View file

@ -17,7 +17,7 @@ class Parser {
init(plainText: String) {
let splittedPlainText = plainText.splitByNewline()
firstLine = splittedPlainText.first!
self.firstLine = splittedPlainText.first!
self.additionsSection = splittedPlainText[1...].joined(separator: "\n")
self.purgedAdditionalLines = splittedPlainText[1...].filter { !$0.isEmpty }
}