This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAdvancedPrefController.m
125 lines (111 loc) · 3.87 KB
/
AdvancedPrefController.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// AdvancedPrefController.m
// MAL Updater OS X
//
// Created by Tail Red on 3/21/15.
//
//
#import "AdvancedPrefController.h"
#import "Utility.h"
#import <EasyNSURLConnection/EasyNSURLConnection.h>
#import <DetectionKit/DetectionKit.h>
@interface AdvancedPrefController ()
@end
@implementation AdvancedPrefController
@synthesize APIUrl;
@synthesize appdelegate;
@synthesize kodicheck;
@synthesize testapibtn;
@synthesize testprogressindicator;
- (id)init
{
return [super initWithNibName:@"AdvancedPrefController" bundle:nil];
}
- (id)initwithAppDelegate:(MAL_Updater_OS_XAppDelegate *)adelegate{
appdelegate = adelegate;
return [super initWithNibName:@"AdvancedPrefController" bundle:nil];
}
#pragma mark -
#pragma mark MASPreferencesViewController
- (NSString *)identifier
{
return @"AdvancedPreferences";
}
- (NSImage *)toolbarItemImage
{
return [NSImage imageNamed:NSImageNameAdvanced];
}
- (NSString *)toolbarItemLabel
{
return NSLocalizedString(@"Advanced", @"Toolbar item name for the Advanced preference pane");
}
- (IBAction)getHelp:(id)sender{
//Show Help
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://github.com/chikorita157/malupdaterosx-cocoa/wiki/Advanced-Options"]];
}
- (IBAction)testapi:(id)sender
{
[testprogressindicator setHidden:NO];
[testprogressindicator startAnimation:nil];
[testapibtn setEnabled:NO];
dispatch_queue_t queue = dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
//Load API URL
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//Set URL
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/2.1/animelist/chikorita157", [defaults objectForKey:@"MALAPIURL"]]];
EasyNSURLConnection *request = [[EasyNSURLConnection alloc] initWithURL:url];
[Utility setUserAgent:request];
//Ignore Cookies
[request setUseCookies:NO];
//Test API
[request startRequest];
// Get Status Code
long statusCode = [request getStatusCode];
dispatch_async(dispatch_get_main_queue(), ^{
switch (statusCode) {
case 200:
[Utility showsheetmessage:@"API Test Successful" explaination:[NSString stringWithFormat:@"HTTP Code: %li", statusCode] window: self.view.window];
break;
default:
[Utility showsheetmessage:@"API Test Unsuccessful" explaination:[NSString stringWithFormat:@"HTTP Code: %li", statusCode] window:self.view.window];
break;
}
[testprogressindicator setHidden:YES];
[testprogressindicator stopAnimation:nil];
[testapibtn setEnabled:YES];
});
});
}
- (IBAction)resetapiurl:(id)sender
{
//Reset Unofficial MAL API URL
#ifdef oss
APIUrl.stringValue = @"http://localhost:8000";
#else
APIUrl.stringValue = @"https://malapi.malupdaterosx.moe";
#endif
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults] ;
[defaults setObject:APIUrl.stringValue forKey:@"MALAPIURL"];
[appdelegate.MALEngine changenotifierhostname];
}
- (void)controlTextDidChange:(NSNotification *)notification {
NSTextField *textfield = notification.object;
MyAnimeList *malengine = appdelegate.MALEngine;
if ([textfield.identifier isEqualToString:@"kodihost"]) {
[malengine.detection setKodiReachAddress:textfield.stringValue];
}
}
- (IBAction)setKodiReach:(id)sender{
MyAnimeList *malengine = appdelegate.MALEngine;
if (kodicheck.state == 0) {
// Turn off reachability notification for Kodi
[malengine.detection setKodiReach:false];
}
else {
// Turn on reachability notification for Kodi
[malengine.detection setKodiReach:true];
}
}
@end