Prompt user when quitting with active downloads. Remove js debug logging.
This commit is contained in:
@@ -195,8 +195,31 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
|
|||||||
|
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
||||||
{
|
{
|
||||||
// Todo: show a sheet if downloads are in progress
|
int count = 0;
|
||||||
return NSTerminateNow;
|
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
|
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
||||||
|
|||||||
@@ -114,6 +114,10 @@
|
|||||||
{
|
{
|
||||||
status = @"ERROR";
|
status = @"ERROR";
|
||||||
error = @"Download Cancelled";
|
error = @"Download Cancelled";
|
||||||
|
|
||||||
|
[[NSFileManager defaultManager] removeItemAtPath:filename error:NULL];
|
||||||
|
bytesCompleted = bytesTotal = -1;
|
||||||
|
|
||||||
[[JSBridge sharedInstance] notifyDownloadProgress:self];
|
[[JSBridge sharedInstance] notifyDownloadProgress:self];
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
name:NSFileHandleReadCompletionNotification
|
name:NSFileHandleReadCompletionNotification
|
||||||
|
|||||||
@@ -124,20 +124,13 @@
|
|||||||
function refreshSections()
|
function refreshSections()
|
||||||
{
|
{
|
||||||
var installed = packagesInstalled();
|
var installed = packagesInstalled();
|
||||||
window.external.log("installed: "+installed);
|
|
||||||
|
|
||||||
document.getElementById("buttons-install").style.display = (installed == 0) ? "" : "none";
|
document.getElementById("buttons-install").style.display = (installed == 0) ? "" : "none";
|
||||||
document.getElementById("buttons-upgrade").style.display = (installed == 1) ? "" : "none";
|
document.getElementById("buttons-upgrade").style.display = (installed == 1) ? "" : "none";
|
||||||
document.getElementById("buttons-play").style.display = (installed == 2) ? "" : "none";
|
document.getElementById("buttons-play").style.display = (installed == 2) ? "" : "none";
|
||||||
|
|
||||||
window.external.log("installed: "+installed);
|
|
||||||
// Select the correct subsection
|
|
||||||
if (installed == 0)
|
if (installed == 0)
|
||||||
{
|
{
|
||||||
//var url = "http://localhost/~paul/cnc-packages.zip";
|
window.external.registerDownload("cnc-packages", "http://open-ra.org/get-dependency.php?file=cnc-packages", "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");
|
|
||||||
refreshDownloadButtons();
|
refreshDownloadButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,23 +141,24 @@
|
|||||||
document.getElementById("download-downloading").style.display = "none";
|
document.getElementById("download-downloading").style.display = "none";
|
||||||
document.getElementById("download-extract").style.display = "none";
|
document.getElementById("download-extract").style.display = "none";
|
||||||
document.getElementById("download-error").style.display = "none";
|
document.getElementById("download-error").style.display = "none";
|
||||||
|
|
||||||
// status can be NOT_REGISTERED, AVAILABLE, DOWNLOADING, COMPLETE, ERROR
|
// status can be NOT_REGISTERED, AVAILABLE, DOWNLOADING, COMPLETE, ERROR
|
||||||
var status = window.external.downloadStatus("cnc-packages");
|
var status = window.external.downloadStatus("cnc-packages");
|
||||||
window.external.log("status: "+status);
|
|
||||||
|
|
||||||
// Download complete, offer button to extract it
|
// Download complete, offer button to extract it
|
||||||
if (status == "COMPLETE")
|
if (status == "COMPLETE")
|
||||||
document.getElementById("download-extract").style.display = "";
|
{
|
||||||
|
document.getElementById("download-extract").style.display = "";
|
||||||
|
}
|
||||||
// Show the download progress
|
// Show the download progress
|
||||||
else if (status == "DOWNLOADING")
|
else if (status == "DOWNLOADING")
|
||||||
|
{
|
||||||
document.getElementById("download-downloading").style.display = "";
|
document.getElementById("download-downloading").style.display = "";
|
||||||
|
}
|
||||||
// Show the download button
|
// Show the download button
|
||||||
else if (status == "AVAILABLE")
|
else if (status == "AVAILABLE")
|
||||||
|
{
|
||||||
document.getElementById("download-available").style.display = "";
|
document.getElementById("download-available").style.display = "";
|
||||||
|
}
|
||||||
else if (status == "ERROR")
|
else if (status == "ERROR")
|
||||||
{
|
{
|
||||||
var message = window.external.downloadError("cnc-packages");
|
var message = window.external.downloadError("cnc-packages");
|
||||||
@@ -180,19 +174,15 @@
|
|||||||
|
|
||||||
var total = window.external.bytesTotal(file);
|
var total = window.external.bytesTotal(file);
|
||||||
var downloaded = window.external.bytesCompleted(file);
|
var downloaded = window.external.bytesCompleted(file);
|
||||||
window.external.log(file+" = total: "+total+" downloaded: "+downloaded);
|
|
||||||
|
|
||||||
if (downloaded > 0)
|
if (downloaded > 0)
|
||||||
{
|
{
|
||||||
var multiplier = 1/1048576.0;
|
var multiplier = 1/1048576.0;
|
||||||
total = (total*multiplier).toPrecision(2);
|
total = (total*multiplier).toPrecision(2);
|
||||||
downloaded = (downloaded*multiplier).toPrecision(2);
|
downloaded = (downloaded*multiplier).toPrecision(2);
|
||||||
|
|
||||||
document.getElementById("download-status").value = downloaded+"/"+total+" MB";
|
document.getElementById("download-status").value = downloaded+"/"+total+" MB";
|
||||||
}
|
}
|
||||||
refreshDownloadButtons();
|
refreshDownloadButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="onLoad();">
|
<body onload="onLoad();">
|
||||||
|
|||||||
Reference in New Issue
Block a user