Prompt user when quitting with active downloads. Remove js debug logging.

This commit is contained in:
Paul Chote
2010-11-25 13:46:06 +13:00
parent 77a35fd132
commit efad699d4b
3 changed files with 37 additions and 20 deletions

View File

@@ -195,8 +195,31 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
// Todo: show a sheet if downloads are in progress
return NSTerminateNow;
int count = 0;
for (NSString *key in downloads)
if ([[(Download *)[downloads objectForKey:key] status] isEqualToString:@"DOWNLOADING"])
count++;
if (count == 0)
return NSTerminateNow;
NSString *format = count == 1 ? @"1 download is" : [NSString stringWithFormat:@"%d downloads are",count];
NSAlert *alert = [NSAlert alertWithMessageText:@"Are you sure you want to quit?"
defaultButton:@"Cancel"
alternateButton:@"Quit"
otherButton:nil
informativeTextWithFormat:@"%@ in progress and will be cancelled.", format];
[alert beginSheetModalForWindow:[webView window] modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:NULL];
return NSTerminateLater;
}
- (void)alertEnded:(NSAlert *)alert
code:(int)button
context:(void *)v
{
NSApplicationTerminateReply reply = (button == NSAlertDefaultReturn) ? NSTerminateCancel : NSTerminateNow;
[[NSApplication sharedApplication] replyToApplicationShouldTerminate:reply];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification

View File

@@ -114,6 +114,10 @@
{
status = @"ERROR";
error = @"Download Cancelled";
[[NSFileManager defaultManager] removeItemAtPath:filename error:NULL];
bytesCompleted = bytesTotal = -1;
[[JSBridge sharedInstance] notifyDownloadProgress:self];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSFileHandleReadCompletionNotification

View File

@@ -124,20 +124,13 @@
function refreshSections()
{
var installed = packagesInstalled();
window.external.log("installed: "+installed);
document.getElementById("buttons-install").style.display = (installed == 0) ? "" : "none";
document.getElementById("buttons-upgrade").style.display = (installed == 1) ? "" : "none";
document.getElementById("buttons-play").style.display = (installed == 2) ? "" : "none";
window.external.log("installed: "+installed);
// Select the correct subsection
if (installed == 0)
{
//var url = "http://localhost/~paul/cnc-packages.zip";
//var url = "http://localhost/~paul/cnc-packages.bogus";
var url = "http://open-ra.org/get-dependency.php?file=cnc-packages";
window.external.registerDownload("cnc-packages", url, "cnc-packages.zip");
window.external.registerDownload("cnc-packages", "http://open-ra.org/get-dependency.php?file=cnc-packages", "cnc-packages.zip");
refreshDownloadButtons();
}
}
@@ -148,23 +141,24 @@
document.getElementById("download-downloading").style.display = "none";
document.getElementById("download-extract").style.display = "none";
document.getElementById("download-error").style.display = "none";
// status can be NOT_REGISTERED, AVAILABLE, DOWNLOADING, COMPLETE, ERROR
var status = window.external.downloadStatus("cnc-packages");
window.external.log("status: "+status);
// Download complete, offer button to extract it
if (status == "COMPLETE")
document.getElementById("download-extract").style.display = "";
{
document.getElementById("download-extract").style.display = "";
}
// Show the download progress
else if (status == "DOWNLOADING")
{
document.getElementById("download-downloading").style.display = "";
}
// Show the download button
else if (status == "AVAILABLE")
{
document.getElementById("download-available").style.display = "";
}
else if (status == "ERROR")
{
var message = window.external.downloadError("cnc-packages");
@@ -180,19 +174,15 @@
var total = window.external.bytesTotal(file);
var downloaded = window.external.bytesCompleted(file);
window.external.log(file+" = total: "+total+" downloaded: "+downloaded);
if (downloaded > 0)
{
var multiplier = 1/1048576.0;
total = (total*multiplier).toPrecision(2);
downloaded = (downloaded*multiplier).toPrecision(2);
document.getElementById("download-status").value = downloaded+"/"+total+" MB";
}
refreshDownloadButtons();
}
</script>
</head>
<body onload="onLoad();">