-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
DonationWindowController.m
106 lines (92 loc) · 4.23 KB
/
DonationWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// DonationWindowController.m
// MAL Updater OS X
//
// Created by 桐間紗路 on 2017/01/03.
//
//
#import "DonationWindowController.h"
#import "PatreonLicenseManager.h"
#import "Utility.h"
@interface DonationWindowController ()
@property (strong) IBOutlet NSButton *patreonlicense;
@end
@implementation DonationWindowController
@synthesize name;
@synthesize key;
- (instancetype)init {
self = [super initWithWindowNibName:@"DonationWindow"];
if(!self)
return nil;
return self;
}
- (void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
- (IBAction)validate:(id)sender {
if (_patreonlicense.state) {
[self performpatreonvalidation];
}
else {
[self performregularvalidation];
}
}
- (void)performpatreonvalidation {
[[PatreonLicenseManager sharedInstance] validateLicense:name.stringValue withLicenseKey:key.stringValue withCompletion:^(bool success, bool error) {
if (success && !error) {
[Utility showsheetmessage:NSLocalizedString(@"Registered",nil) explaination:NSLocalizedString(@"Thank you for donating. The donation reminder will no longer appear and exclusive features are unlocked.",nil) window:nil];
[[PatreonLicenseManager sharedInstance] storeLicense:name.stringValue withLicenseKey:key.stringValue];
//Close Window
[self.window orderOut:self];
}
else {
[Utility showsheetmessage:@"Invalid Donation Key" explaination:@"Make sure you entered the name and license key exactly shown on the Patreon License Portal." window:self.window];
}
}];
}
- (void)performregularvalidation {
if (name.stringValue.length > 0 && key.stringValue.length>0) {
// Check donation key
[Utility checkDonationKey:key.stringValue name:name.stringValue completion:^(int success) {
if (success == 1) {
[Utility showsheetmessage:NSLocalizedString(@"Registered",nil) explaination:NSLocalizedString(@"Thank you for donating. The donation reminder will no longer appear and exclusive features are unlocked.",nil) window:nil];
// Add to the preferences
[[NSUserDefaults standardUserDefaults] setObject:name.stringValue forKey:@"donor"];
[[NSUserDefaults standardUserDefaults] setObject:key.stringValue forKey:@"donatekey"];
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:@"donated"];
//Close Window
[self.window orderOut:self];
}
else if (success == 2) {
[Utility showsheetmessage:NSLocalizedString(@"No Internet",nil) explaination:NSLocalizedString(@"Make sure you are connected to the internet and try again.",nil) window:self.window];
}
else {
[Utility showsheetmessage:NSLocalizedString(@"Invalid Key",nil) explaination:NSLocalizedString(@"Please make sure you copied the name and key exactly from the email.",nil) window:self.window];
}
}];
}
else {
[Utility showsheetmessage:NSLocalizedString(@"Missing Information",nil) explaination:NSLocalizedString(@"Please type in the name and key exactly from the email and try again.",nil) window:self.window];
}
}
- (IBAction)cancel:(id)sender{
[self.window orderOut:self];
}
- (IBAction)purchasedonationlicense:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://softwareateliershiori.onfastspring.com/hachidori-mal-sync-donation-license"]];
}
- (IBAction)donate:(id)sender{
// Show Donation Page
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://malupdaterosx.moe/donate/"]];
}
- (IBAction)lookupkey:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://malupdaterosx.moe/hachidori/lostkey.php"]];
}
- (IBAction)becomepatron:(id)sender {
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:@"https://www.patreon.com/bePatron?c=677182"]];
}
- (IBAction)openpatreonlicenseportal:(id)sender {
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:@"https://patreonlicensing.malupdaterosx.moe"]];
}
@end