Add accessibility identifiers to debug log popups.

This commit is contained in:
Matthew Chen 2019-03-20 10:56:45 -04:00
parent 81508e9d02
commit f37a3059fa
4 changed files with 102 additions and 42 deletions

View file

@ -555,16 +555,22 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
uint32_t screenLockTimeout = (uint32_t)round(timeoutValue.doubleValue); uint32_t screenLockTimeout = (uint32_t)round(timeoutValue.doubleValue);
NSString *screenLockTimeoutString = [self formatScreenLockTimeout:screenLockTimeout useShortFormat:NO]; NSString *screenLockTimeoutString = [self formatScreenLockTimeout:screenLockTimeout useShortFormat:NO];
[controller addAction:[UIAlertAction actionWithTitle:screenLockTimeoutString UIAlertAction *action =
style:UIAlertActionStyleDefault [UIAlertAction actionWithTitle:screenLockTimeoutString
handler:^(UIAlertAction *action) { style:UIAlertActionStyleDefault
[OWSScreenLock.sharedManager handler:^(UIAlertAction *ignore) {
setScreenLockTimeout:screenLockTimeout]; [OWSScreenLock.sharedManager setScreenLockTimeout:screenLockTimeout];
}]]; }];
action.accessibilityIdentifier = [NSString stringWithFormat:@"settings.privacy.timeout.%@", timeoutValue];
[controller addAction:action];
} }
[controller addAction:[OWSAlerts cancelAction]]; [controller addAction:[OWSAlerts cancelAction]];
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController]; UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
[fromViewController presentViewController:controller animated:YES completion:nil]; [fromViewController presentViewController:controller
animated:YES
completion:^{
[controller applyAccessibilityIdentifiers];
}];
} }
- (NSString *)formatScreenLockTimeout:(NSInteger)value useShortFormat:(BOOL)useShortFormat - (NSString *)formatScreenLockTimeout:(NSInteger)value useShortFormat:(BOOL)useShortFormat

View file

@ -319,17 +319,20 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_TITLE", @"Title of the debug log alert.") alertControllerWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_TITLE", @"Title of the debug log alert.")
message:NSLocalizedString(@"DEBUG_LOG_ALERT_MESSAGE", @"Message of the debug log alert.") message:NSLocalizedString(@"DEBUG_LOG_ALERT_MESSAGE", @"Message of the debug log alert.")
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction [alert
actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_EMAIL", addAction:[UIAlertAction
@"Label for the 'email debug log' option of the debug log alert.") actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_EMAIL",
style:UIAlertActionStyleDefault @"Label for the 'email debug log' option of the debug log alert.")
handler:^(UIAlertAction *action) { accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"send_email")
[Pastelog.sharedManager submitEmail:url]; style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[Pastelog.sharedManager submitEmail:url];
completion(); completion();
}]]; }]];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_COPY_LINK", [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_COPY_LINK",
@"Label for the 'copy link' option of the debug log alert.") @"Label for the 'copy link' option of the debug log alert.")
accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"copy_link")
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
UIPasteboard *pb = [UIPasteboard generalPasteboard]; UIPasteboard *pb = [UIPasteboard generalPasteboard];
@ -341,27 +344,32 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
[alert [alert
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_SELF", addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_SELF",
@"Label for the 'send to self' option of the debug log alert.") @"Label for the 'send to self' option of the debug log alert.")
accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"send_to_self")
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[Pastelog.sharedManager sendToSelf:url]; [Pastelog.sharedManager sendToSelf:url];
}]]; }]];
[alert addAction:[UIAlertAction [alert addAction:[UIAlertAction actionWithTitle:
actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD", NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SEND_TO_LAST_THREAD",
@"Label for the 'send to last thread' option of the debug log alert.") @"Label for the 'send to last thread' option of the debug log alert.")
style:UIAlertActionStyleDefault accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"send_to_last_thread")
handler:^(UIAlertAction *action) { style:UIAlertActionStyleDefault
[Pastelog.sharedManager sendToMostRecentThread:url]; handler:^(UIAlertAction *action) {
}]]; [Pastelog.sharedManager sendToMostRecentThread:url];
}]];
#endif #endif
[alert addAction:[UIAlertAction [alert
actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_BUG_REPORT", addAction:
@"Label for the 'Open a Bug Report' option of the debug log alert.") [UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_BUG_REPORT",
style:UIAlertActionStyleDefault @"Label for the 'Open a Bug Report' option of the debug log alert.")
handler:^(UIAlertAction *action) { accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"submit_bug_report")
[Pastelog.sharedManager prepareRedirection:url completion:completion]; style:UIAlertActionStyleDefault
}]]; handler:^(UIAlertAction *action) {
[Pastelog.sharedManager prepareRedirection:url completion:completion];
}]];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SHARE", [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SHARE",
@"Label for the 'Share' option of the debug log alert.") @"Label for the 'Share' option of the debug log alert.")
accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"share")
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[AttachmentSharing showShareUIForText:url.absoluteString [AttachmentSharing showShareUIForText:url.absoluteString
@ -370,7 +378,11 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
[alert addAction:[OWSAlerts cancelAction]]; [alert addAction:[OWSAlerts cancelAction]];
UIViewController *presentingViewController UIViewController *presentingViewController
= UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
[presentingViewController presentViewController:alert animated:NO completion:nil]; [presentingViewController presentViewController:alert
animated:NO
completion:^{
[alert applyAccessibilityIdentifiers];
}];
}]; }];
} }
@ -507,10 +519,15 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
message:message message:message
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"") [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"")
accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"ok")
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:nil]]; handler:nil]];
UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
[presentingViewController presentViewController:alert animated:NO completion:nil]; [presentingViewController presentViewController:alert
animated:NO
completion:^{
[alert applyAccessibilityIdentifiers];
}];
} }
#pragma mark Logs submission #pragma mark Logs submission
@ -561,18 +578,25 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
message:NSLocalizedString(@"DEBUG_LOG_GITHUB_ISSUE_ALERT_MESSAGE", message:NSLocalizedString(@"DEBUG_LOG_GITHUB_ISSUE_ALERT_MESSAGE",
@"Message of the alert before redirecting to GitHub Issues.") @"Message of the alert before redirecting to GitHub Issues.")
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction [alert
actionWithTitle:NSLocalizedString(@"OK", @"") addAction:[UIAlertAction
style:UIAlertActionStyleDefault actionWithTitle:NSLocalizedString(@"OK", @"")
handler:^(UIAlertAction *action) { accessibilityIdentifier:SUBVIEW_ACCESSIBILITY_IDENTIFIER(self, @"ok")
[UIApplication.sharedApplication style:UIAlertActionStyleDefault
openURL:[NSURL URLWithString:[[NSBundle mainBundle] handler:^(UIAlertAction *action) {
objectForInfoDictionaryKey:@"LOGS_URL"]]]; [UIApplication.sharedApplication
openURL:[NSURL
URLWithString:[[NSBundle mainBundle]
objectForInfoDictionaryKey:@"LOGS_URL"]]];
completion(); completion();
}]]; }]];
UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
[presentingViewController presentViewController:alert animated:NO completion:nil]; [presentingViewController presentViewController:alert
animated:NO
completion:^{
[alert applyAccessibilityIdentifiers];
}];
} }
- (void)sendToSelf:(NSURL *)url - (void)sendToSelf:(NSURL *)url

View file

@ -156,6 +156,17 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value);
@end @end
#pragma mark -
@interface UIAlertAction (OWS)
+ (instancetype)actionWithTitle:(nullable NSString *)title
accessibilityIdentifier:(nullable NSString *)accessibilityIdentifier
style:(UIAlertActionStyle)style
handler:(void (^__nullable)(UIAlertAction *action))handler;
@end
#pragma mark - Macros #pragma mark - Macros
CGFloat CGHairlineWidth(void); CGFloat CGHairlineWidth(void);

View file

@ -2,9 +2,10 @@
// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import "UIView+OWS.h"
#import "OWSMath.h" #import "OWSMath.h"
#import "UIView+OWS.h"
#import <SignalCoreKit/iOSVersions.h> #import <SignalCoreKit/iOSVersions.h>
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/AppContext.h> #import <SignalServiceKit/AppContext.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -594,6 +595,24 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
@end @end
#pragma mark -
@implementation UIAlertAction (OWS)
+ (instancetype)actionWithTitle:(nullable NSString *)title
accessibilityIdentifier:(nullable NSString *)accessibilityIdentifier
style:(UIAlertActionStyle)style
handler:(void (^__nullable)(UIAlertAction *action))handler
{
UIAlertAction *action = [UIAlertAction actionWithTitle:title style:style handler:handler];
action.accessibilityIdentifier = accessibilityIdentifier;
return action;
}
@end
#pragma mark -
CGFloat CGHairlineWidth() CGFloat CGHairlineWidth()
{ {
return 1.f / UIScreen.mainScreen.scale; return 1.f / UIScreen.mainScreen.scale;