diff --git a/README.md b/README.md
index f79bd5b..387c808 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,9 @@ In the addresses section fill in as many websites as you want the screensaver to
Passing in a negative time value e.g. `-1` will notify the screensaver to remain on that website indefinitely.
-Need some website ideas? Check out suggestions in the [examples](examples.md) section.
+Need some website ideas? Check out suggestions in the [examples](examples.json). (feel free to suggest others)
+
+The example file can also be used with the **fetch URLs** feature: `https://raw.githubusercontent.com/liquidx/webviewscreensaver/master/examples.json`
Local **absolute** paths can also be used as an address with or without the `file://` schema.
diff --git a/WebViewScreenSaver/Info.plist b/WebViewScreenSaver/Info.plist
index 033548d..218eb69 100644
--- a/WebViewScreenSaver/Info.plist
+++ b/WebViewScreenSaver/Info.plist
@@ -19,11 +19,11 @@
CFBundlePackageType
BNDL
CFBundleShortVersionString
- 2.3
+ 2.4
CFBundleSignature
????
CFBundleVersion
- 2.3
+ 2.4
NSPrincipalClass
WebViewScreenSaverView
diff --git a/WebViewScreenSaver/WVSSAddressListFetcher.h b/WebViewScreenSaver/WVSSAddressListFetcher.h
index a170788..93b90c3 100644
--- a/WebViewScreenSaver/WVSSAddressListFetcher.h
+++ b/WebViewScreenSaver/WVSSAddressListFetcher.h
@@ -21,6 +21,8 @@
#import
+extern NSExceptionName const WVSSInvalidArgumentException;
+
@protocol WVSSAddressListFetcherDelegate;
@interface WVSSAddressListFetcher : NSObject
diff --git a/WebViewScreenSaver/WVSSAddressListFetcher.m b/WebViewScreenSaver/WVSSAddressListFetcher.m
index 37f75fc..6a5ab35 100644
--- a/WebViewScreenSaver/WVSSAddressListFetcher.m
+++ b/WebViewScreenSaver/WVSSAddressListFetcher.m
@@ -20,6 +20,9 @@
//
#import "WVSSAddressListFetcher.h"
+#import "WVSSAddress.h"
+
+NSExceptionName const WVSSInvalidArgumentException = @"WVSSInvalidArgumentException";
@interface WVSSAddressListFetcher () {
NSURLSessionTask *_task;
@@ -46,7 +49,6 @@ - (id)initWithURL:(NSString *)url {
- (void)didFinishLoading:(NSData *)data error:(NSError *)error {
if (error != nil) {
- NSLog(@"Unable to fetch URLs: %@", error);
[self.delegate addressListFetcher:self didFailWithError:error];
return;
}
@@ -56,19 +58,52 @@ - (void)didFinishLoading:(NSData *)data error:(NSError *)error {
options:NSJSONReadingMutableContainers
error:&jsonError];
if (jsonError) {
- NSLog(@"Unable to read connection data: %@", jsonError);
[self.delegate addressListFetcher:self didFailWithError:jsonError];
return;
}
-
- if (![response isKindOfClass:[NSArray class]]) {
- NSLog(@"Expected array but got %@", [response class]);
- [self.delegate addressListFetcher:self didFailWithError:nil];
- return;
+
+ NSMutableArray *parsed = [[NSMutableArray alloc] init];
+
+ @try {
+ expectClass(response, NSArray.class);
+ for (NSDictionary *item in (NSArray *)response) {
+ expectClass(item, NSDictionary.class);
+
+ id url = item[@"url"];
+ id duration = item[@"duration"];
+
+ expectClass(url, NSString.class);
+ expectClass(duration, NSNumber.class);
+
+ [parsed addObject:[WVSSAddress addressWithURL:url
+ duration:[(NSNumber *)duration intValue]]];
+ }
+
+ [self.delegate addressListFetcher:self didFinishWithArray:parsed];
+ } @catch (NSException *exception) {
+ if ([exception.name isEqualToString:WVSSInvalidArgumentException]) {
+ NSError *error = [NSError errorWithDomain:WVSSInvalidArgumentException
+ code:-1
+ userInfo:@{NSLocalizedDescriptionKey: exception.reason}];
+ [self.delegate addressListFetcher:self didFailWithError:error];
+ } else {
+ [exception raise];
+ }
}
-
- [self.delegate addressListFetcher:self didFinishWithArray:response];
+
NSLog(@"fetching URLS finished");
}
+void expectClass(id target, Class aclass) {
+ if (![target isKindOfClass:aclass]) {
+ NSString *reason = [NSString stringWithFormat:@"Expected %@ but got %@",
+ NSStringFromClass(aclass),
+ NSStringFromClass([target class])];
+ NSException *exc = [NSException exceptionWithName:WVSSInvalidArgumentException
+ reason:reason
+ userInfo:nil];
+ [exc raise];
+ }
+}
+
@end
diff --git a/WebViewScreenSaver/WVSSConfigController.m b/WebViewScreenSaver/WVSSConfigController.m
index 568d9c2..58bba13 100644
--- a/WebViewScreenSaver/WVSSConfigController.m
+++ b/WebViewScreenSaver/WVSSConfigController.m
@@ -130,6 +130,7 @@ - (void)clearWebViewHistory {
#pragma mark -
- (void)addressListFetcher:(WVSSAddressListFetcher *)fetcher didFailWithError:(NSError *)error {
+ NSLog(@"URLs fetcher encountered issue: %@", error.localizedDescription);
}
- (void)addressListFetcher:(WVSSAddressListFetcher *)fetcher
diff --git a/examples.json b/examples.json
new file mode 100644
index 0000000..107a2b8
--- /dev/null
+++ b/examples.json
@@ -0,0 +1,15 @@
+[
+ { "url": "https://ykob.github.io/sketch-threejs/sketch/dna.html", "duration": 600},
+ { "url": "https://ykob.github.io/sketch-threejs/sketch/sun.html", "duration": 600},
+ { "url": "http://www.google.com/trends/hottrends/visualize?pn=p1", "duration": 600 },
+ { "url": "http://randomstreetview.com/#slideshow", "duration": 600 },
+ { "url": "http://mrdoob.com/lab/javascript/webgl/clouds/", "duration": 600 },
+ { "url": "http://mrdoob.com/lab/javascript/webgl/particles/magicdust.html", "duration": 600 },
+ { "url": "http://www.iamnop.com/particles/", "duration": 600 },
+ { "url": "http://www.airtightinteractive.com/demos/js/nebula/", "duration": 600 },
+ { "url": "http://alteredqualia.com/three/examples/webgl_cubes.html", "duration": 600 },
+ { "url": "http://akirodic.com/p/jellyfish/", "duration": 600 },
+ { "url": "http://matthew.wagerfield.com/flat-surface-shader/", "duration": 600 },
+ { "url": "http://codepen.io/ykob/full/zGpjeK/", "duration": 600 },
+ { "url": "http://www.aresluna.org/polish-tv-clock/", "duration": 600 }
+]
diff --git a/examples.md b/examples.md
deleted file mode 100644
index fdce44d..0000000
--- a/examples.md
+++ /dev/null
@@ -1,20 +0,0 @@
-This is a list of websites that look good as screensavers.
-Feel free to suggest others.
-
- - http://www.hellochar.com/flame?name=WebViewScreenSaver
- - http://www.google.com/trends/hottrends/visualize?pn=p1
- - http://globe.chromeexperiments.com/
- - http://clouds.chromeexperiments.com/
- - http://randomstreetview.com/#slideshow
- - http://oos.moxiecode.com/js_webgl/forest/index.html
- - http://oos.moxiecode.com/js_webgl/water_noise/
- - http://www.iamnop.com/particles/
- - http://mrdoob.com/lab/javascript/webgl/clouds/
- - http://mrdoob.com/lab/javascript/webgl/particles/magicdust.html
- - http://www.airtightinteractive.com/demos/js/nebula/
- - http://alteredqualia.com/three/examples/webgl_cubes.html
- - http://akirodic.com/p/jellyfish/
- - http://matthew.wagerfield.com/flat-surface-shader/
- - http://codepen.io/ykob/full/zGpjeK/
- - http://d-pixie.github.io/striped-clock/
- - http://www.aresluna.org/polish-tv-clock/
\ No newline at end of file