Skip to content

Commit

Permalink
1.1.1 - Fix potential issues with the app crashing on rare occasions …
Browse files Browse the repository at this point in the history
…because NSMutableArray ivar used in EasyNSURLConnection is not thread safe, so locking has been added to prevent a crash. Also, fixed some minor bugs with the episode check when searching and the Find Unrecognized Title not showing up in the menu.
  • Loading branch information
chikorita157 committed Feb 8, 2015
1 parent e655eeb commit 28a8fed
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
6 changes: 4 additions & 2 deletions AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ -(void)firetimer:(NSTimer *)aTimer {
[self generateShareMenu];
}
}
if (status == 51) {
//Show option to find title
[findtitle setHidden:false];
}
// Enable Menu Items
scrobbleractive = false;
[updatenow setEnabled:YES];
Expand Down Expand Up @@ -592,8 +596,6 @@ -(IBAction)showCorrectionSearchWindow:(id)sender{
//Get last scrobbled title
[fsdialog setSearchField:[haengine getLastScrobbledTitle]];
}
// Set search field to search for the last scrobbled detected title
[fsdialog setSearchField:[haengine getLastScrobbledTitle]];
if (isVisible) {
[self disableUpdateItems]; //Prevent user from opening up another modal window if access from Status Window
[NSApp beginSheet:[fsdialog window]
Expand Down
14 changes: 7 additions & 7 deletions Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -290,7 +290,7 @@
<outlet property="correcttoolbaritem" destination="q9Q-0H-wSc" id="2bQ-jw-mDj"/>
<outlet property="epiformatter" destination="2hd-2h-QFD" id="6K0-Y4-yOj"/>
<outlet property="episodefield" destination="KPI-Zr-e4Y" id="uSW-Ej-q4r"/>
<outlet property="findtitle" destination="CfJ-0Z-4TJ" id="aEc-VV-5Mb"/>
<outlet property="findtitle" destination="CfJ-0Z-4TJ" id="uhY-rw-nZ8"/>
<outlet property="img" destination="gfr-73-DLn" id="iLO-3a-xch"/>
<outlet property="isPrivate" destination="08J-G1-ibd" id="SgD-vy-2Kq"/>
<outlet property="lastupdateheader" destination="wRW-vV-uul" id="Aoh-J1-uYk"/>
Expand Down Expand Up @@ -400,10 +400,10 @@
<rect key="frame" x="0.0" y="0.0" width="223" height="133"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="207" height="82"/>
<size key="minSize" width="192" height="82"/>
<size key="maxSize" width="463" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="207" height="82"/>
<size key="minSize" width="192" height="82"/>
<size key="maxSize" width="463" height="10000000"/>
</textView>
</subviews>
Expand Down Expand Up @@ -531,10 +531,10 @@ Gw
<rect key="frame" x="0.0" y="0.0" width="269" height="188"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="289" height="188"/>
<size key="minSize" width="274" height="188"/>
<size key="maxSize" width="463" height="10000000"/>
<color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="289" height="188"/>
<size key="minSize" width="274" height="188"/>
<size key="maxSize" width="463" height="10000000"/>
</textView>
</subviews>
Expand Down
12 changes: 12 additions & 0 deletions EasyNSURLConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ -(NSError *)getError{
#pragma mutators
-(void)addHeader:(id)object
forKey:(NSString *)key{
NSLock * lock = [NSLock new]; // NSMutableArray is not Thread Safe, lock before performing operation
[lock lock];
if (formdata == nil) {
//Initalize Header Data Array
headers = [[NSMutableArray alloc] init];
}
[headers addObject:[NSDictionary dictionaryWithObjectsAndKeys:object,key, nil]];
[lock unlock]; //Finished operation, unlock
}
-(void)addFormData:(id)object
forKey:(NSString *)key{
NSLock * lock = [NSLock new]; // NSMutableArray is not Thread Safe, lock before performing operation
[lock lock];
if (formdata == nil) {
//Initalize Form Data Array
formdata = [[NSMutableArray alloc] init];
}
[formdata addObject:[NSDictionary dictionaryWithObjectsAndKeys:object,key, nil]];
[lock unlock]; //Finished operation, unlock
}
-(void)setUserAgent:(NSString *)string{
useragent = [NSString stringWithFormat:@"%@",string];
Expand All @@ -78,13 +84,16 @@ -(void)startRequest{
[request setTimeoutInterval:15];
// Set User Agent
[request setValue:useragent forHTTPHeaderField:@"User-Agent"];
NSLock * lock = [NSLock new]; // NSMutableArray is not Thread Safe, lock before performing operation
[lock lock];
// Set Other headers, if any
if (headers != nil) {
for (NSDictionary *d in headers ) {
//Set any headers
[request setValue:[[d allValues] objectAtIndex:0]forHTTPHeaderField:[[d allKeys] objectAtIndex:0]];
}
}
[lock unlock];
NSError * rerror = nil;
responsedata = [NSURLConnection sendSynchronousRequest:request
returningResponse:&rresponse
Expand All @@ -111,6 +120,8 @@ -(void)startFormRequest{
[request setValue:useragent forHTTPHeaderField:@"User-Agent"];
// Set Timeout
[request setTimeoutInterval:15];
NSLock * lock = [NSLock new]; // NSMutableArray is not Thread Safe, lock before performing operation
[lock lock];
//Set Post Data
[request setHTTPBody:[self encodeArraywithDictionaries:formdata]];
// Set Other headers, if any
Expand All @@ -120,6 +131,7 @@ -(void)startFormRequest{
[request setValue:[[d allValues] objectAtIndex:0]forHTTPHeaderField:[[d allKeys] objectAtIndex:0]];
}
}
[lock unlock];
NSError * rerror;
responsedata = [NSURLConnection sendSynchronousRequest:request
returningResponse:&rresponse
Expand Down
15 changes: 9 additions & 6 deletions GeneralPrefController.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ -(IBAction)updateAutoExceptions:(id)sender{

dispatch_async(queue, ^{
// In a queue, download latest Auto Exceptions JSON, disable button until done and show progress wheel
[updateexceptionsbtn setEnabled:NO];
[updateexceptionschk setEnabled:NO];
[indicator startAnimation:self];
dispatch_async(dispatch_get_main_queue(), ^{
[updateexceptionsbtn setEnabled:NO];
[updateexceptionschk setEnabled:NO];
[indicator startAnimation:self];});
[AutoExceptions updateAutoExceptions];
[indicator stopAnimation:self];
[updateexceptionsbtn setEnabled:YES];
[updateexceptionschk setEnabled:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[indicator stopAnimation:self];
[updateexceptionsbtn setEnabled:YES];
[updateexceptionschk setEnabled:YES];
});
dispatch_release(queue);
});

Expand Down
4 changes: 2 additions & 2 deletions Hachidori-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<string>1.1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.1</string>
<string>1.1.1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.entertainment</string>
<key>LSMinimumSystemVersion</key>
Expand Down
11 changes: 10 additions & 1 deletion Hachidori.m
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,16 @@ -(NSString *)findaniid:(NSData *)ResponseData searchterm:(NSString *) term{
}
}
//Return titleid if episode is valid
if ([searchentry objectForKey:@"episode_count"] == [NSNull null] || ([[NSString stringWithFormat:@"%@",[searchentry objectForKey:@"episode_count"]] intValue] >= [DetectedEpisode intValue])) {
int episodecount;
if ([searchentry objectForKey:@"episode_count"] == [NSNull null]) {
// No episode Count, set episode count to zero
episodecount = 0;
}
else{
//Set Episode Count
episodecount = [[NSString stringWithFormat:@"%@", [searchentry objectForKey:@"episode_count"]] intValue];
}
if (episodecount == 0 || ( episodecount >= [DetectedEpisode intValue])) {
NSLog(@"Valid Episode Count");
if (sortedArray.count == 1 || DetectedSeason >= 2){
// Only Result, return
Expand Down
Binary file not shown.

0 comments on commit 28a8fed

Please sign in to comment.