Revision: 29489
          http://sourceforge.net/p/bibdesk/svn/29489
Author:   hofman
Date:     2025-08-28 14:52:13 +0000 (Thu, 28 Aug 2025)
Log Message:
-----------
keep modification counter in download manager and reload download page only 
when it is changed

Modified Paths:
--------------
    trunk/bibdesk/BDSKDownloadManager.h
    trunk/bibdesk/BDSKDownloadManager.m
    trunk/bibdesk/de.lproj/WebGroupDownloads.html
    trunk/bibdesk/en.lproj/WebGroupDownloads.html
    trunk/bibdesk/fr.lproj/WebGroupDownloads.html

Modified: trunk/bibdesk/BDSKDownloadManager.h
===================================================================
--- trunk/bibdesk/BDSKDownloadManager.h 2025-08-27 22:41:25 UTC (rev 29488)
+++ trunk/bibdesk/BDSKDownloadManager.h 2025-08-28 14:52:13 UTC (rev 29489)
@@ -49,6 +49,7 @@
 
 @interface BDSKDownloadManager : NSObject <WebDownloadDelegate> {
     NSMutableArray *downloads;
+    NSInteger modification;
 }
 
 @property (class, nonatomic, readonly) BDSKDownloadManager *sharedManager;
@@ -58,6 +59,8 @@
 @property (nonatomic) BOOL removeFinishedDownloads;
 @property (nonatomic) BOOL removeFailedDownloads;
 
+@property (nonatomic, readonly) NSInteger modification;
+
 - (void)clear;
 - (void)cancel:(NSUInteger)uniqueID;
 - (void)remove:(NSUInteger)uniqueID;

Modified: trunk/bibdesk/BDSKDownloadManager.m
===================================================================
--- trunk/bibdesk/BDSKDownloadManager.m 2025-08-27 22:41:25 UTC (rev 29488)
+++ trunk/bibdesk/BDSKDownloadManager.m 2025-08-28 14:52:13 UTC (rev 29489)
@@ -61,7 +61,7 @@
 
 @implementation BDSKDownloadManager
 
-@synthesize downloads;
+@synthesize downloads, modification;
 @dynamic removeFinishedDownloads, removeFailedDownloads;
 
 + (BDSKDownloadManager *)sharedManager {
@@ -98,6 +98,7 @@
 - (void)addDownload:(id)download {
     [download setDelegate:self];
     [downloads addObject:[[BDSKWebDownload alloc] initWithDownload:download 
URL:[[download originalRequest] URL]]];
+    ++modification;
 }
 
 - (BDSKWebDownload *)webDownloadForDownload:(id)download {
@@ -122,6 +123,7 @@
         if ([[downloads objectAtIndex:i] status] != 0)
             [downloads removeObjectAtIndex:i];
     }
+    ++modification;
 }
 
 - (void)cancel:(NSUInteger)uniqueID {
@@ -130,8 +132,10 @@
 
 - (void)remove:(NSUInteger)uniqueID {
     BDSKWebDownload *webDownload = [self downloadWithUniqueID:uniqueID];
-    if (webDownload)
+    if (webDownload) {
         [downloads removeObject:webDownload];
+        ++modification;
+    }
 }
 
 + (NSString *)webScriptNameForSelector:(SEL)aSelector {
@@ -148,12 +152,12 @@
 }
  
 + (BOOL)isKeyExcludedFromWebScript:(const char *)aKey {
-    return 0 != strcmp(aKey, "removeFinishedDownloads") && 0 != strcmp(aKey, 
"removeFailedDownloads");
+    return 0 != strcmp(aKey, "removeFinishedDownloads") && 0 != strcmp(aKey, 
"removeFailedDownloads") && 0 != strcmp(aKey, "modification");
 }
 
 // This is necessary for web scripting to check the key for exposure, 
otherwise it will only check the ivar names instead
 - (NSArray *)attributeKeys {
-    return @[@"removeFinishedDownloads", @"removeFailedDownloads"];
+    return @[@"removeFinishedDownloads", @"removeFailedDownloads", 
@"modification"];
 }
 
 - (NSString *)fontFamilyName { return [[NSFont systemFontOfSize:0.0] 
familyName]; }
@@ -162,6 +166,7 @@
 
 - (void)downloadDidBegin:(NSURLDownload *)download {
     [downloads addObject:[[BDSKWebDownload alloc] initWithDownload:download 
URL:[[download request] URL]]];
+    ++modification;
 }
 
 - (void)downloadDidFinish:(id)download {
@@ -170,6 +175,7 @@
     
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKRemoveFinishedDownloadsKey] && webDownload)
         [downloads removeObject:webDownload];
+    ++modification;
 }
 
 - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error {
@@ -178,6 +184,7 @@
     
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKRemoveFailedDownloadsKey] && webDownload)
         [downloads removeObject:webDownload];
+    ++modification;
     
     if ([[error domain] isEqualToString:NSURLErrorDomain] && [error code] == 
NSURLErrorCancelled)
         return;
@@ -231,6 +238,7 @@
     
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKRemoveFailedDownloadsKey] && webDownload)
         [downloads removeObject:webDownload];
+    ++modification;
     
     if ([[error domain] isEqualToString:NSURLErrorDomain] && [error code] == 
NSURLErrorCancelled)
         return;

Modified: trunk/bibdesk/de.lproj/WebGroupDownloads.html
===================================================================
--- trunk/bibdesk/de.lproj/WebGroupDownloads.html       2025-08-27 22:41:25 UTC 
(rev 29488)
+++ trunk/bibdesk/de.lproj/WebGroupDownloads.html       2025-08-28 14:52:13 UTC 
(rev 29489)
@@ -43,8 +43,8 @@
 
        </script>
        </head>
-       <body onload="setTimeout('location.reload()',5000)">
-       
+    <body onload="setInterval('if (downloads.modification != <$modification/>) 
{ location.reload() }',1000)">
+
                <$downloads?>
                <form>
                        <table class="downloads" id="downloads">

Modified: trunk/bibdesk/en.lproj/WebGroupDownloads.html
===================================================================
--- trunk/bibdesk/en.lproj/WebGroupDownloads.html       2025-08-27 22:41:25 UTC 
(rev 29488)
+++ trunk/bibdesk/en.lproj/WebGroupDownloads.html       2025-08-28 14:52:13 UTC 
(rev 29489)
@@ -43,7 +43,7 @@
 
        </script>
        </head>
-    <body onload="setTimeout('location.reload()',5000)">
+    <body onload="setInterval('if (downloads.modification != <$modification/>) 
{ location.reload() }',1000)">
 
                <$downloads?>
                <form>

Modified: trunk/bibdesk/fr.lproj/WebGroupDownloads.html
===================================================================
--- trunk/bibdesk/fr.lproj/WebGroupDownloads.html       2025-08-27 22:41:25 UTC 
(rev 29488)
+++ trunk/bibdesk/fr.lproj/WebGroupDownloads.html       2025-08-28 14:52:13 UTC 
(rev 29489)
@@ -43,7 +43,7 @@
 
        </script>
        </head>
-    <body onload="setTimeout('location.reload()',5000)">
+    <body onload="setInterval('if (downloads.modification != <$modification/>) 
{ location.reload() }',1000)">
 
                <$downloads?>
                <form>

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to