[Pkg-privacy-commits] [torbrowser-launcher] 19/476: got progress bar working, downloading file in chunks

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:21:19 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository torbrowser-launcher.

commit 76662476225c38f42cceeb8006daa552b3f55c05
Author: Micah Lee <micahflee at riseup.net>
Date:   Mon Feb 11 11:08:45 2013 -0800

    got progress bar working, downloading file in chunks
---
 src/torbrowser-launcher | 55 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 9 deletions(-)

diff --git a/src/torbrowser-launcher b/src/torbrowser-launcher
index bfa82e1..1cf38b8 100755
--- a/src/torbrowser-launcher
+++ b/src/torbrowser-launcher
@@ -71,15 +71,54 @@ const TorBrowserLauncher = new Lang.Class({
       label: "Download"
     });
     this._button_download.connect('clicked', Lang.bind(this, function(){
-      // start downloading
-      that._statusbar.set_label('Starting download');
+      that._statusbar.set_label('Downloading Tor Browser Bundle');
+
+      function file_size(bytes) {
+        if(bytes < 1024) {
+          return ''+bytes+' bytes';
+        }
+        let kb = bytes / 1024;
+        kb = Math.floor(kb);
+        if(kb < 1024) {
+          return ''+kb+'kb';
+        }
+        let mb = kb / 1024;
+        mb = Math.floor(mb * 100) / 100;
+        return ''+mb+'mb';
+      }
+
+      var total_size;
+      var bytes_so_far = 0;
+
+      // create an http message
       var request = Soup.Message.new('GET', this._tarball_url);
+
+      // grab the content-length from the headers
+      request.connect('got_headers', Lang.bind(this, function(message){
+        total_size = message.response_headers.get_content_length()
+      }));
+      
+      // update progress bar with each chunk
+      request.connect('got_chunk', Lang.bind(this, function(message, chunk){
+        //let [data, length] = chunk.get_data();
+        bytes_so_far += chunk.length;
+
+        if(total_size) {
+          let fraction = bytes_so_far / total_size;
+          let percent = Math.floor(fraction * 100);
+          that._progress_bar.set_fraction(fraction);
+          that._statusbar.set_label("Downloaded "+percent+"% ("+file_size(bytes_so_far)+" / "+file_size(total_size)+")");
+        }
+        //print('got chunk '+length);
+      }));
+      
       that._httpSession.queue_message(request, function(_httpSession, message) {
         if(message.status_code !== 200) {
-          that._statusbar.set_label('Download finished');
+          that._statusbar.set_label('Download failed: '+message.status_code);
           return;
         }
-        that._statusbar.set_label('Download returned status '+message.status_code);
+        that._progress_bar.set_fraction(1);
+        that._statusbar.set_label('Download finished');
       });
     }));
 
@@ -92,9 +131,7 @@ const TorBrowserLauncher = new Lang.Class({
     }));
 
     // status bar
-    this._statusbar = new Gtk.Label({
-      label: ''
-    });
+    this._statusbar = new Gtk.Label({ });
 
     // attach everything to the grid
     this._grid.attach(this._label, 0, 0, 2, 1);
@@ -160,8 +197,8 @@ if(GLib.file_test(tbb_start, GLib.FileTest.IS_EXECUTABLE)) {
     print('Already downloaded');
   } else {
     // run the application
-    //var tarball_url = 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename;
-    var tarball_url = 'http://127.0.0.1/'+tarball_filename;
+    var tarball_url = 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename;
+    //var tarball_url = 'http://127.0.0.1/'+tarball_filename;
     let app = new TorBrowserLauncher(tbb_version, tarball_path, tarball_url);
     app.application.run(ARGV);
   }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/torbrowser-launcher.git



More information about the Pkg-privacy-commits mailing list