Handle download errors

This commit is contained in:
Paul Chote
2010-11-25 12:36:14 +13:00
parent 6f66a19b18
commit 2fe7e10750
4 changed files with 66 additions and 37 deletions

View File

@@ -49,6 +49,7 @@ static JSBridge *SharedInstance;
@"startDownload", NSStringFromSelector(@selector(startDownload:)),
@"cancelDownload", NSStringFromSelector(@selector(cancelDownload:)),
@"downloadStatus", NSStringFromSelector(@selector(downloadStatus:)),
@"downloadError", NSStringFromSelector(@selector(downloadError:)),
@"bytesCompleted", NSStringFromSelector(@selector(bytesCompleted:)),
@"bytesTotal", NSStringFromSelector(@selector(bytesTotal:)),
nil] retain];
@@ -67,12 +68,6 @@ static JSBridge *SharedInstance;
[super dealloc];
}
- (void)notifyDownloadProgress:(Download *)download
{
[[[controller webView] windowScriptObject] evaluateWebScript:
[NSString stringWithFormat:@"downloadProgressed('%@')",[download key]]];
}
#pragma mark JS API methods
- (BOOL)launchMod:(NSString *)aMod
@@ -119,6 +114,15 @@ static JSBridge *SharedInstance;
return [d status];
}
- (NSString *)downloadError:(NSString *)key
{
Download *d = [controller downloadWithKey:key];
if (d == nil)
return @"";
return [d error];
}
- (BOOL)startDownload:(NSString *)key
{
Download *d = [controller downloadWithKey:key];
@@ -143,6 +147,13 @@ static JSBridge *SharedInstance;
return (d == nil) ? -1 : [d bytesTotal];
}
- (void)notifyDownloadProgress:(Download *)download
{
[[[controller webView] windowScriptObject] evaluateWebScript:
[NSString stringWithFormat:@"downloadProgressed('%@')",[download key]]];
}
- (void)log:(NSString *)message
{
NSLog(@"js: %@",message);