123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- //
- // KMVerificationMessageViewController.m
- // PDF Reader Pro Edition
- //
- // Created by 王帅 on 2018/5/9.
- //
- #import "KMVerificationMessageViewController.h"
- #import <PDF_Reader_Pro-Swift.h>
- #import "VerificationManager.h"
- #import "AIInfoManager.h"
- #import "KMVerificationWindowController.h"
- #import "KMPurchaseCompareWindowController.h"
- #import "KMUnlockAlertViewController.h"
- #define kbottomGap 0
- @interface KMVerificationMessageViewController ()<
- NSPopoverDelegate>
- @property (strong) IBOutlet NSView *contendView;
- @property (strong) IBOutlet NSButton *freeTrialButton;
- @property (strong) IBOutlet NSButton *upgradButton;
- @property (nonatomic, strong) NSTrackingArea *trackingArea;
- @property (nonatomic, strong) NSPopover *popover;
- @property (nonatomic, assign) BOOL isPopoverShow;
- @property (nonatomic, assign) BOOL checkValue;
- @property (nonatomic, assign) BOOL stopPopOverHide;
- @property (nonatomic, strong) KMUnlockAlertViewController *testVC;
- @property (nonatomic, strong) KMTrialGuideWindowController *trialGuideWC;
- @property (nonatomic, strong) FreeTrialApplyWindowController *freeTrialApplyWC;
- @end
- @implementation KMVerificationMessageViewController
- #pragma mark Init Methods
- - (instancetype)init {
- if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
- #if VERSION_DMG
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(deviceActivateStatusChangeNotification:)
- name:kDeviceActivateStatusChangeNotification
- object:nil];
- #else
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
-
- #endif
- }
- return self;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- // if (self.trackingArea) {
- // [self.upgradButton removeTrackingArea:self.trackingArea];
- // }
-
- }
- #pragma mark Setter Methods
- - (void)loadView {
- [super loadView];
-
- // Do view setup here.
-
- self.freeTrialButton.wantsLayer = YES;
- self.freeTrialButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
- [self.freeTrialButton setTitleColor:[NSColor whiteColor]];
- [self.freeTrialButton setAlignment:NSTextAlignmentCenter];
-
- self.upgradButton.wantsLayer = YES;
- self.upgradButton.layer.masksToBounds = YES;
- self.upgradButton.layer.cornerRadius = 4.0;
- self.upgradButton.font = [NSFont SFProTextSemiboldFont:11];
- self.upgradButton.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
- [self.upgradButton setAlignment:NSTextAlignmentCenter];
-
- self.freeTrialButton.wantsLayer = YES;
- self.freeTrialButton.layer.masksToBounds = YES;
- self.freeTrialButton.layer.cornerRadius = 4.0;
- self.freeTrialButton.font = [NSFont SFProTextSemiboldFont:11];
-
- NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
- #if VERSION_DMG
- tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Upgrade to Permanent License with one time purchase", nil), NSLocalizedString(@"Complete the purchase in your web browser to get a license", nil)];
- #else
- tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil), NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil)];
- #endif
- self.upgradButton.toolTip = tTips;
- self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- [self.upgradButton setTitleColor:[NSColor whiteColor]];
- [self.upgradButton setAlignment:NSTextAlignmentCenter];
-
-
- [self reloadData];
- }
- - (void)reloadData {
-
- /*
- 未试用:申请试用 + 解锁完整版
- 试用中:试用剩余天数 + 解锁完整版
- 试用过期:解锁完整版
- 已激活:隐藏
-
- */
-
-
- #if VERSION_DMG
-
- if (self.trackingArea) {
- [self.upgradButton removeTrackingArea:self.trackingArea];
- }
-
- self.freeTrialButton.hidden = self.upgradButton.hidden = YES;
-
- if (ActivityStatusNone == [VerificationManager manager].status) {
- self.freeTrialButton.hidden = self.upgradButton.hidden = NO;
-
- self.freeTrialButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
- self.freeTrialButton.layer.backgroundColor = [NSColor colorWithRed:0.0/255.0 green:207.0/255.0 blue:133.0/255.0 alpha:1].CGColor;
- [self.freeTrialButton setTitleColor:[NSColor whiteColor]];
-
- self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- [self.upgradButton setAlignment:NSTextAlignmentCenter];
- [self.upgradButton setTitleColor:[NSColor whiteColor]];
-
- } else if (ActivityStatusTrial == [VerificationManager manager].status) {
- self.freeTrialButton.hidden = self.upgradButton.hidden = NO;
-
- NSDate *date = [NSDate date];
- NSDate *expireDate = [VerificationManager manager].detailInfo.expireDate;
- NSTimeInterval time = [expireDate timeIntervalSinceDate:date];
- int leftDays = ((int)time)/(3600*24);
-
- NSString *needShowString = [NSString stringWithFormat:NSLocalizedString(@"%d days left", nil),leftDays];
- self.freeTrialButton.title = needShowString;
- [self.freeTrialButton setTitleColor:[NSColor redColor]];
- self.freeTrialButton.layer.backgroundColor = [NSColor clearColor].CGColor;
-
- self.upgradButton.layer.backgroundColor = [NSColor colorWithRed:255.0/255.0 green:94.0/255.0 blue:44.0/255.0 alpha:1].CGColor;
- self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- [self.upgradButton setTitleColor:[NSColor whiteColor]];
- [self.upgradButton setAlignment:NSTextAlignmentCenter];
-
- // if (!self.trackingArea) {
- // self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.upgradButton.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
- // }
- // [self.upgradButton addTrackingArea:self.trackingArea];
- } else if (ActivityStatusTrialExpire == [VerificationManager manager].status) {
- self.upgradButton.hidden = NO;
-
- self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- [self.upgradButton setAlignment:NSTextAlignmentCenter];
- self.upgradButton.layer.backgroundColor = [NSColor clearColor].CGColor;
- [self.upgradButton setTitleColor:[NSColor whiteColor]];
-
- // if (!self.trackingArea) {
- // self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.upgradButton.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
- // }
- // [self.upgradButton addTrackingArea:self.trackingArea];
-
- } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
- self.upgradButton.hidden = NO;
-
- self.upgradButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- [self.upgradButton setTitleColor:[NSColor whiteColor]];
- self.upgradButton.layer.backgroundColor = [NSColor clearColor].CGColor;
- [self.upgradButton setAlignment:NSTextAlignmentCenter];
- } else if (ActivityStatusVerification == [VerificationManager manager].status) {
-
- } else {
-
- }
- #else
-
- #endif
- [self.freeTrialButton sizeToFit];
- [self.freeTrialButton setAlignment:NSTextAlignmentCenter];
- [self.upgradButton sizeToFit];
- [self.upgradButton setAlignment:NSTextAlignmentCenter];
-
- CGFloat totalWidth = 8;
-
- if (self.freeTrialButton.hidden == NO) {
- CGFloat buttonWidth = self.freeTrialButton.frame.size.width;
- buttonWidth += 10;
- self.freeTrialButton.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
- totalWidth += buttonWidth;
- totalWidth += 8;
- }
-
- if (self.upgradButton.hidden == NO) {
- NSRect btnRect = [self.upgradButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.upgradButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
- CGFloat buttonWidth = btnRect.size.width + 40;
- self.upgradButton.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
- totalWidth += buttonWidth;
- totalWidth += 8;
- }
-
- if (self.view.superview) {
- self.view.frame = CGRectMake(MAX(0, CGRectGetWidth(self.view.superview.frame)-totalWidth - 8), (CGRectGetHeight(self.view.superview.frame)-CGRectGetHeight(self.view.frame))/2., totalWidth, self.view.frame.size.height);
- } else {
- if (self.upgradButton.hidden) {
- self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.freeTrialButton.frame) + 20 ,self.view.frame.size.height);
- } else {
- self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.upgradButton.frame) ,self.view.frame.size.height);
- }
- }
- self.contendView.wantsLayer = true;
- self.contendView.layer.backgroundColor = NSColor.clearColor.CGColor;
-
- if (self.frameUpdateHandle) {
- self.frameUpdateHandle(self.view.frame);
- }
-
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
- }
- #pragma mark - Button Actions
- - (IBAction)freeTrialButtonAction:(NSButton *)sender {
- if (ActivityStatusNone != [VerificationManager manager].status) {
- return;
- }
- __weak typeof(self) weakSelf = self;
- if (!self.trialGuideWC) {
- self.trialGuideWC = [KMTrialGuideWindowController currentWC];
- }
- self.trialGuideWC.noEmailBlock = ^{
- [weakSelf.trialGuideWC close];
-
- [weakSelf showFreeTrialApplyWC];
- };
-
- self.trialGuideWC.shouldMinSizeAnimate = true;
- [self.trialGuideWC.window center];
- CGRect originalRect = self.trialGuideWC.window.frame;
- originalRect.size.width = 888;
- originalRect.size.height = 520;
- originalRect.origin.x = ([NSScreen mainScreen].frame.size.width - originalRect.size.width)/2.0;
- originalRect.origin.y = ([NSScreen mainScreen].frame.size.height - originalRect.size.height)/2.0;
-
- self.trialGuideWC.originalFrame = originalRect;
- CGRect rect = [self.view convertRect:self.upgradButton.frame toView:self.view.window.contentView];
- rect.origin.x = CGRectGetMaxX(self.view.window.frame) - self.upgradButton.frame.size.width - self.freeTrialButton.frame.size.width/2.0 - 15;
- rect.origin.y = CGRectGetMaxY(self.view.window.frame) - self.upgradButton.frame.size.height - 5;
- rect.size.width = 0;
- rect.size.height = 0;
-
- self.trialGuideWC.startFrame = rect;
-
- [self.trialGuideWC.window setFrame:rect display:YES];
- [self.trialGuideWC showWindow:nil];
-
- [self.trialGuideWC animateScaling];
- }
- - (void)showFreeTrialApplyWC {
- if (self.freeTrialApplyWC != nil) {
- self.freeTrialApplyWC = nil;
- }
- if (self.freeTrialApplyWC == nil) {
- self.freeTrialApplyWC = [[FreeTrialApplyWindowController alloc] init];
- }
- [self.freeTrialApplyWC.window center];
- [self.freeTrialApplyWC showWindow:nil];
- }
- - (IBAction)upgradeButtonAction:(id)sender {
- BOOL isFree = NO;
- __weak typeof(self) weakSelf = self;
- #if VERSION_DMG
- if (ActivityStatusNone == [VerificationManager manager].status ||
- ActivityStatusTrialExpire == [VerificationManager manager].status) {
-
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
- //
- // if (!self.testVC) {
- // self.testVC = [[KMUnlockAlertViewController alloc] init];
-
- // if (ActivityStatusNone == [VerificationManager manager].status) {
- // //弹出 试用弹窗UI优化-新用户试用路径 新UI 情况一 右上角按钮
- // KMPurchaseFirstTrialWindowController *firstTrialWC = [KMPurchaseFirstTrialWindowController currentFirstTrialWC];
- // firstTrialWC.buttonActionBlock = ^(KMPurchaseFirstTrialWindowController * _Nonnull ftWC, KMButton * _Nonnull btn, NSString * _Nonnull email, NSString * _Nonnull name) {
- // if (btn.tag == 10001) {
- // if (ActivityStatusNone == [VerificationManager manager].status ||
- // ActivityStatusTrialExpire == [VerificationManager manager].status) {
- //
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_SecondTrial"}];
- // [[VerificationManager manager] trialForDays:7
- // email:email?:[VerificationManager manager].email
- // name:name?:[VerificationManager manager].accountName
- // complention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
- // if (error ||
- // status != ActivityStatusTrial) {
- // NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Activation Error", nil)
- // defaultButton:NSLocalizedString(@"Try Again", nil)
- // alternateButton:nil
- // otherButton:nil
- // informativeTextWithFormat:NSLocalizedString(@"Failed to sign up for the free trial. Please make sure your internet connection is available and try again later.", nil), nil];
- // [alert runModal];
- // } else {
- // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialSuccess];
- // [vc showWindow:nil];
- // }
- // }];
- // [ftWC close];
- // } else {
- // [ftWC close];
- // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
- // vc.callback = ^{
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // };
- // [vc showWindow:nil];
- // }
- // } else if (btn.tag == 10002) {
- // NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor?utm_source=app_dmg&utm_medium=dmg_puw_free_trial"];
- // [[NSWorkspace sharedWorkspace] openURL:url];
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"PUW_Btn_UpgradeBuyNow"}];
- // } else if (btn.tag == 10003) {
- // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];//KMVerificationTypeActivate
- // [vc showWindow:nil];
- // [ftWC close];
- // }
- // };
- // [firstTrialWC.window center];
- // [firstTrialWC showWindow:nil];
- // } else if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
- // ActivityStatusTrial == [VerificationManager manager].status) {
- //// if ([VerificationManager manager].secondTrialEnabled) {
- //// if (!self.checkValue) {
- //// [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- //// }
- //// } else {
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"KMVerificationMessagePopShowNoti" object:nil];
- //
- // if (!self.testVC) {
- // self.testVC = [[KMUnlockAlertViewController alloc] init];
- // }
- // [self.testVC addtrackingAreaInfo];
- // self.testVC.callback = ^(NSInteger index) {
- // if (index == 1) {
- // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
- // [vc showWindow:nil];
- // } else if (index == 2) {
- // NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor"];
- //
- // [[NSWorkspace sharedWorkspace] openURL:url];
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"PUW" withProperties:@{@"PUW_Btn":@"Btn_PUW_BuyNow-Expire"}];
- //// KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_3"];
- //// [embeddedWC showWindow:nil];
- //// [[embeddedWC window] center];
- // }
- // };
- // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
- // if (mouseEnter) {
- // self.stopPopOverHide = YES;
- // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
- // ActivityStatusTrial == [VerificationManager manager].status) {
- // if (!self.popover.isShown) {
- // [self buttonAction:self.button];
- // }
- // }
- // } else {
- // self.stopPopOverHide = NO;
- // if (self.popover) {
- // [self.popover close];
- // }
- // [self.testVC removeTrackingAreaInfo];
- // }
- // };
- // NSPopover *popover = [[NSPopover alloc] init];
- // popover.delegate = self;
- // popover.contentViewController = self.testVC;
- // popover.animates = YES;
- // popover.behavior = NSPopoverBehaviorTransient;
- // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
- // self.popover = popover;
- // }
- // [self.testVC addtrackingAreaInfo];
- // self.testVC.callback = ^(NSInteger index) {
- // if (index == 1) {
- // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivate];
- // [vc showWindow:nil];
- // } else if (index == 2) {
- // NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor"];
- //
- // [[NSWorkspace sharedWorkspace] openURL:url];
- // }
- // };
- // self.testVC.mouseEventCall = ^(BOOL mouseEnter) {
- // if (mouseEnter) {
- // weakSelf.stopPopOverHide = YES;
- // if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
- // ActivityStatusTrial == [VerificationManager manager].status) {
- // if (!weakSelf.popover.isShown) {
- // [weakSelf upgradeButtonAction:weakSelf.upgradButton];
- // }
- // }
- // } else {
- // weakSelf.stopPopOverHide = NO;
- // if (weakSelf.popover) {
- // [weakSelf.popover close];
- // }
- // [weakSelf.testVC removeTrackingAreaInfo];
- // }
- // };
- // NSPopover *popover = [[NSPopover alloc] init];
- // popover.delegate = self;
- // popover.contentViewController = self.testVC;
- // popover.animates = YES;
- // popover.behavior = NSPopoverBehaviorTransient;
- // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
- // self.popover = popover;
-
-
- if (IAPProductsManager.defaultManager.isAvailableAllFunction == NO) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- }
- } else if (ActivityStatusTrial == [VerificationManager manager].status) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- } else if (ActivityStatusVerifExpire == [VerificationManager manager].status) {
- if (IAPProductsManager.defaultManager.isAvailableAllFunction == NO) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- }
- // KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateExpired];
- // [vc showWindow:nil];
- } else if (ActivityStatusVerification == [VerificationManager manager].status) {
- if ([VerificationManager manager].needUpgradeLicense) {
- NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor?product_code=product_2"];
- [[NSWorkspace sharedWorkspace] openURL:url];
- }
- } else {
- if ([VerificationManager manager].needUpgradeLicense) {
- NSURL *url = [NSURL URLWithString:@"https://www.pdfreaderpro.com/store/pdftecheditor?product_code=product_2"];
- [[NSWorkspace sharedWorkspace] openURL:url];
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_PDFtoOffice"}];
- } else {
- KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeNormal];
- [vc showWindow:nil];
- }
- }
- #else
- isFree = YES;
- #if VERSION_FREE
- if ([IAPProductsManager defaultManager].isAvailableAllFunction) {
- isFree = NO;
- }
- if (isFree) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- }
- #else
- if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
- // KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:0];
- KMToolCompareWindowController *vc = [KMToolCompareWindowController toolCompareWithToolType:KMCompareWithToolTypeConvert selectNum:0];
- [vc.window center];
- [vc showWindow:nil];
- }
- #endif
-
- #endif
- }
- #pragma mark - Private Method
- - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
- NSString *temp = nil;
- for (NSUInteger i = 0; i <string.length; i++) {
- temp = [string substringWithRange:NSMakeRange(i, 1)];
- if ([self isPureInt:temp]) {
- [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
- color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
- }
- }
- return attributedString;
- }
- - (BOOL)isPureInt:(NSString *)string {
- NSScanner *scan = [NSScanner scannerWithString:string];
- int value;
- return [scan scanInt:&value] && [scan isAtEnd];
- }
- - (IBAction)AIButtonAction:(NSButton *)sender {
- __block typeof(self) blockSelf = self;
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
- [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
-
- }];
- AIUserInfoController *controller = [[AIUserInfoController alloc] init];
- controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
- #if VERSION_DMG
- // NSURL *url = [NSURL URLWithString:Swift_oc_Tool.AIProduct_Link_OC];
- // [[NSWorkspace sharedWorkspace] openURL:url];
- // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
- // [embeddedWC showWindow:nil];
- // [[embeddedWC window] center];
- #else
-
- [[AIPurchaseWindowController currentWC] showWindow:nil];
- #endif
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
- };
- controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
- KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
- verifyVC.callback = ^{
- };
- [verifyVC showWindow:nil];
- };
-
- controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
- // if (!blockSelf.guideWindowVC) {
- // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
- // blockSelf.guideWindowVC = guideWindowVC;
- // }
- // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
- // [blockSelf.guideWindowVC showWindow:nil];
- // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
- // [blockSelf.guideWindowVC.window orderFront:nil];
- };
-
- NSPopover *popover = [[NSPopover alloc] init];
- popover.contentViewController = controller;
- popover.animates = YES;
- popover.behavior = NSPopoverBehaviorTransient;
- [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
- }
- #pragma mark - NSNotification Methods
- - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)IAPResultReceived:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)IAPPurchaseSuccess:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)IAPRestoreFinish:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- #pragma mark -Popover
- - (void)popoverDidClose:(NSNotification *)notification {
- self.stopPopOverHide = NO;
- }
-
- - (void)popoverShowNoti:(NSNotification *)noti {
- if (self.popover) {
- [self.popover close];
- self.stopPopOverHide = NO;
- }
- }
- - (void)popOverCloseAction {
- if (self.stopPopOverHide == NO) {
- if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
- ActivityStatusTrial == [VerificationManager manager].status) {
- if (self.popover.isShown) {
- [self.popover close];
- self.stopPopOverHide = NO;
- }
- }
- }
- }
- #pragma mark - Event
- - (void)mouseEntered:(NSEvent *)event {
- if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
- ActivityStatusTrial == [VerificationManager manager].status) {
- [[self class] cancelPreviousPerformRequestsWithTarget:self];
- if (!self.popover.isShown) {
- [self upgradeButtonAction:self.upgradButton];
- }
- }
- }
- - (void)mouseExited:(NSEvent *)event {
- [super mouseExited:event];
-
- [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
- }
- @end
|