diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 155a0082..b9ca254b 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -73,10 +73,11 @@ def download(): chunk = fp.read(102400) if chunk == '': done = True - yield chunk - - # tell GUI the progress - add_request(REQUEST_PROGRESS, path, { 'id':download_id, 'bytes':fp.tell() }) + else: + yield chunk + + # tell GUI the progress + add_request(REQUEST_PROGRESS, path, { 'id':download_id, 'bytes':fp.tell() }) fp.close() r = Response(generate()) diff --git a/onionshare/strings.json b/onionshare/strings.json index c1f01918..741ee04e 100644 --- a/onionshare/strings.json +++ b/onionshare/strings.json @@ -14,7 +14,9 @@ "download_started": "Download started", "download_finished": "Download finished", "other_page_loaded": "Other page has been loaded", - "tails_requires_root": "You must run OnionShare as root in Tails" + "tails_requires_root": "You must run OnionShare as root in Tails", + "close_on_finish": "Close automatically", + "close_countdown": "Closing in {0} seconds..." }, "no": { "punching_a_hole": "Ã…pner port i brannmuren.", "closing_hole": "Lukker port i brannmuren.", diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index dc84b4f2..330ee87b 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -1,6 +1,8 @@ import onionshare, webapp import threading, gtk, gobject, webkit, os, sys, subprocess +window = gtk.Window() + def alert(msg, type=gtk.MESSAGE_INFO): dialog = gtk.MessageDialog( parent=None, @@ -43,10 +45,12 @@ def select_file(strings): return filename, basename def start_webapp(webapp_port, onionshare_port, filename, onion_host): + global window webapp.onionshare = onionshare webapp.onionshare_port = onionshare_port webapp.filename = filename webapp.onion_host = onion_host + webapp.window = window webapp.app.run(port=webapp_port) def launch_window(webapp_port, onionshare_port): @@ -55,7 +59,7 @@ def launch_window(webapp_port, onionshare_port): onionshare.tails_close_port(webapp_port) gtk.main_quit() - window = gtk.Window() + global window window.set_title('OnionShare') window.resize(520, 400) window.set_resizable(False) diff --git a/onionshare_gui/static/onionshare.js b/onionshare_gui/static/onionshare.js index 27a1b603..2ee12346 100644 --- a/onionshare_gui/static/onionshare.js +++ b/onionshare_gui/static/onionshare.js @@ -44,6 +44,22 @@ $(function(){ // is the download complete? if(r.data.bytes == onionshare.filesize) { $('#download-'+r.data.id).html(onionshare.strings['download_finished']); + + // close on finish? + if($('#close-on-finish').is(':checked')) { + function close_countdown(i) { + $('#close-countdown').html(onionshare.strings['close_countdown'].replace('{0}', i)); + if(i == 0) { + // close program + $.ajax({ url: '/close' }); + } else { + // continue countdown + setTimeout(function(){ close_countdown(i-1) }, 1000); + } + } + update($('').attr('id', 'close-countdown')); + close_countdown(3); + } } // still in progress else { @@ -71,6 +87,7 @@ $(function(){ $('#basename').html(onionshare.basename); $('#filesize .label').html(onionshare.strings['filesize']+':'); $('#filehash .label').html(onionshare.strings['sha1_checksum']+':'); + $('#close-on-finish-wrapper label').html(onionshare.strings['close_on_finish']); $('#loading .calculating').html(onionshare.strings['calculating_sha1']); // after getting the initial info, start the onionshare server diff --git a/onionshare_gui/static/style.css b/onionshare_gui/static/style.css index 5fcd03d5..af292047 100644 --- a/onionshare_gui/static/style.css +++ b/onionshare_gui/static/style.css @@ -46,6 +46,16 @@ body { font-weight: bold; font-size: 12px; } +#metadata #close-on-finish-wrapper { + margin-bottom: 10px; +} +#metadata #close-on-finish-wrapper input { + cursor: pointer; +} +#metadata #close-on-finish-wrapper label { + cursor: pointer; + font-size: 12px; +} ul#log { float: left; @@ -88,6 +98,10 @@ ul#log li#loading .calculating { font-style: italic; font-size: 12px; } +ul#log #close-countdown { + font-weight: bold; + font-style: italic; +} .button { -moz-box-shadow:inset 0px 1px 0px 0px #d197fe; diff --git a/onionshare_gui/templates/index.html b/onionshare_gui/templates/index.html index d0fe467c..8b285a62 100644 --- a/onionshare_gui/templates/index.html +++ b/onionshare_gui/templates/index.html @@ -16,6 +16,10 @@ +
+ +
diff --git a/onionshare_gui/webapp.py b/onionshare_gui/webapp.py index b82c5f87..257017e7 100644 --- a/onionshare_gui/webapp.py +++ b/onionshare_gui/webapp.py @@ -1,10 +1,11 @@ from flask import Flask, render_template -import threading, json, os, gtk +import threading, json, os, gtk, gobject onionshare = None onionshare_port = None filename = None onion_host = None +window = None clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) url = None @@ -66,3 +67,9 @@ def check_for_requests(): return json.dumps(events) +@app.route("/close") +def close(): + global window + gobject.timeout_add(1000, window.destroy) + return '' +