|
| 1 | +#include <CoreGraphics/CoreGraphics.h> |
1 | 2 | #include <Foundation/Foundation.h> |
2 | | -#include <MacTypes.h> |
3 | 3 | #import <notify.h> |
4 | 4 | #import <UIKit/UIKit.h> |
5 | 5 | #import "TrollSpeed-Swift.h" |
@@ -236,6 +236,10 @@ - (void)loadView |
236 | 236 | [_authorLabel.bottomAnchor constraintEqualToAnchor:_settingsButton.topAnchor constant:-20], |
237 | 237 | ]]; |
238 | 238 |
|
| 239 | + UITapGestureRecognizer *authorTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAuthorLabel:)]; |
| 240 | + [_authorLabel setUserInteractionEnabled:YES]; |
| 241 | + [_authorLabel addGestureRecognizer:authorTapGesture]; |
| 242 | + |
239 | 243 | [self reloadMainButtonState]; |
240 | 244 | } |
241 | 245 |
|
@@ -408,14 +412,47 @@ - (void)setUsesRotation:(BOOL)usesRotation |
408 | 412 | - (void)reloadMainButtonState |
409 | 413 | { |
410 | 414 | _isHUDActive = IsHUDEnabled(); |
| 415 | + |
| 416 | + static NSAttributedString *hintAttributedString = nil; |
| 417 | + static NSAttributedString *githubAttributedString = nil; |
| 418 | + static dispatch_once_t onceToken; |
| 419 | + dispatch_once(&onceToken, ^{ |
| 420 | + NSDictionary *defaultAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:14]}; |
| 421 | + |
| 422 | + NSString *hintText = NSLocalizedString(@"You can quit this app now.\nThe HUD will persist on your screen.", nil); |
| 423 | + hintAttributedString = [[NSAttributedString alloc] initWithString:hintText attributes:defaultAttributes]; |
| 424 | + |
| 425 | + NSTextAttachment *githubIcon = [NSTextAttachment textAttachmentWithImage:[UIImage imageNamed:@"github-mark-white"]]; |
| 426 | + [githubIcon setBounds:CGRectMake(0, 0, 14, 14)]; |
| 427 | + |
| 428 | + NSAttributedString *githubIconText = [NSAttributedString attributedStringWithAttachment:githubIcon]; |
| 429 | + NSMutableAttributedString *githubIconTextFull = [[NSMutableAttributedString alloc] initWithAttributedString:githubIconText]; |
| 430 | + [githubIconTextFull appendAttributedString:[[NSAttributedString alloc] initWithString:@" " attributes:defaultAttributes]]; |
| 431 | + |
| 432 | + NSString *githubText = NSLocalizedString(@"Made with ♥ by @Lessica and @jmpews", nil); |
| 433 | + NSMutableAttributedString *githubAttributedText = [[NSMutableAttributedString alloc] initWithString:githubText attributes:defaultAttributes]; |
| 434 | + |
| 435 | + // replace all "@" with github icon |
| 436 | + NSRange atRange = [githubAttributedText.string rangeOfString:@"@"]; |
| 437 | + while (atRange.location != NSNotFound) { |
| 438 | + [githubAttributedText replaceCharactersInRange:atRange withAttributedString:githubIconTextFull]; |
| 439 | + atRange = [githubAttributedText.string rangeOfString:@"@"]; |
| 440 | + } |
| 441 | + |
| 442 | + githubAttributedString = githubAttributedText; |
| 443 | + }); |
| 444 | + |
411 | 445 | [UIView transitionWithView:self.backgroundView duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ |
412 | 446 | [_mainButton setTitle:(_isHUDActive ? NSLocalizedString(@"Exit HUD", nil) : NSLocalizedString(@"Open HUD", nil)) forState:UIControlStateNormal]; |
413 | | - [_authorLabel setText:(_isHUDActive ? NSLocalizedString(@"You can quit this app now.\nThe HUD will persist on your screen.", nil) : NSLocalizedString(@"Made with ♥ by @i_82 and @jmpews", nil))]; |
| 447 | + [_authorLabel setAttributedText:(_isHUDActive ? hintAttributedString : githubAttributedString)]; |
414 | 448 | } completion:nil]; |
415 | 449 | } |
416 | 450 |
|
417 | 451 | - (void)presentTopCenterMostHints |
418 | 452 | { |
| 453 | + if (!_isHUDActive) { |
| 454 | + return; |
| 455 | + } |
419 | 456 | [_authorLabel setText:NSLocalizedString(@"Tap that button on the center again,\nto toggle ON/OFF “Dynamic Island” mode.", nil)]; |
420 | 457 | } |
421 | 458 |
|
@@ -450,6 +487,16 @@ - (void)tapView:(UITapGestureRecognizer *)sender |
450 | 487 | os_log_debug(OS_LOG_DEFAULT, "- [RootViewController tapView:%{public}@]: %{public}@", sender, NSStringFromCGPoint([sender locationInView:self.backgroundView])); |
451 | 488 | } |
452 | 489 |
|
| 490 | +- (void)tapAuthorLabel:(UITapGestureRecognizer *)sender |
| 491 | +{ |
| 492 | + if (_isHUDActive) { |
| 493 | + return; |
| 494 | + } |
| 495 | + NSString *repoURLString = @"https://github.com/Lessica/TrollSpeed"; |
| 496 | + NSURL *repoURL = [NSURL URLWithString:repoURLString]; |
| 497 | + [[UIApplication sharedApplication] openURL:repoURL options:@{} completionHandler:nil]; |
| 498 | +} |
| 499 | + |
453 | 500 | - (void)tapTopLeftButton:(UIButton *)sender |
454 | 501 | { |
455 | 502 | os_log_debug(OS_LOG_DEFAULT, "- [RootViewController tapTopLeftButton:%{public}@]", sender); |
|
0 commit comments