Browse Source

Add isPaused and canResume

Cheng Zhao 8 years ago
parent
commit
dcad25c98c

+ 15 - 0
atom/browser/api/atom_api_download_item.cc

@@ -102,10 +102,18 @@ void DownloadItem::Pause() {
   download_item_->Pause();
 }
 
+bool DownloadItem::IsPaused() const {
+  return download_item_->IsPaused();
+}
+
 void DownloadItem::Resume() {
   download_item_->Resume();
 }
 
+bool DownloadItem::CanResume() const {
+  return download_item_->CanResume();
+}
+
 void DownloadItem::Cancel() {
   download_item_->Cancel(true);
   download_item_->Remove();
@@ -148,6 +156,10 @@ content::DownloadItem::DownloadState DownloadItem::GetState() const {
   return download_item_->GetState();
 }
 
+bool DownloadItem::IsDone() const {
+  return download_item_->IsDone();
+}
+
 void DownloadItem::SetSavePath(const base::FilePath& path) {
   save_path_ = path;
 }
@@ -162,7 +174,9 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
   mate::ObjectTemplateBuilder(isolate, prototype)
       .MakeDestroyable()
       .SetMethod("pause", &DownloadItem::Pause)
+      .SetMethod("isPaused", &DownloadItem::IsPaused)
       .SetMethod("resume", &DownloadItem::Resume)
+      .SetMethod("canResume", &DownloadItem::CanResume)
       .SetMethod("cancel", &DownloadItem::Cancel)
       .SetMethod("getReceivedBytes", &DownloadItem::GetReceivedBytes)
       .SetMethod("getTotalBytes", &DownloadItem::GetTotalBytes)
@@ -172,6 +186,7 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("getContentDisposition", &DownloadItem::GetContentDisposition)
       .SetMethod("getURL", &DownloadItem::GetURL)
       .SetMethod("getState", &DownloadItem::GetState)
+      .SetMethod("isDone", &DownloadItem::IsDone)
       .SetMethod("setSavePath", &DownloadItem::SetSavePath)
       .SetMethod("getSavePath", &DownloadItem::GetSavePath);
 }

+ 3 - 0
atom/browser/api/atom_api_download_item.h

@@ -27,7 +27,9 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
                              v8::Local<v8::ObjectTemplate> prototype);
 
   void Pause();
+  bool IsPaused() const;
   void Resume();
+  bool CanResume() const;
   void Cancel();
   int64_t GetReceivedBytes() const;
   int64_t GetTotalBytes() const;
@@ -37,6 +39,7 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
   std::string GetContentDisposition() const;
   const GURL& GetURL() const;
   content::DownloadItem::DownloadState GetState() const;
+  bool IsDone() const;
   void SetSavePath(const base::FilePath& path);
   base::FilePath GetSavePath() const;
 

+ 8 - 0
docs/api/download-item.md

@@ -78,10 +78,18 @@ routine to determine the save path(Usually prompts a save dialog).
 
 Pauses the download.
 
+### `downloadItem.isPaused()`
+
+Returns whether the download is paused.
+
 ### `downloadItem.resume()`
 
 Resumes the download that has been paused.
 
+### `downloadItem.canResume()`
+
+Resumes whether the download can resume.
+
 ### `downloadItem.cancel()`
 
 Cancels the download operation.