diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 715af807..37db2f84 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -1,4 +1,4 @@ -import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse +import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue from random import randint from functools import wraps @@ -37,21 +37,37 @@ def set_file_info(new_filename, new_filehash, new_filesize): filehash = new_filehash filesize = new_filesize +REQUEST_LOAD = 0 +REQUEST_DOWNLOAD = 1 +REQUEST_OTHER = 2 +request_q = Queue.Queue() + +def add_request(type): + global request_q + request_q.put({ + 'type': type, + 'path': request.path + }) + @app.route("/{0}".format(slug)) def index(): - global filename, filesize, filehash, slug, strings + global filename, filesize, filehash, slug, strings, REQUEST_LOAD + add_request(REQUEST_LOAD) return render_template_string(open('{0}/index.html'.format(os.path.dirname(__file__))).read(), slug=slug, filename=os.path.basename(filename), filehash=filehash, filesize=filesize, strings=strings) @app.route("/{0}/download".format(slug)) def download(): - global filename + global filename, request_q, REQUEST_DOWNLOAD + add_request(REQUEST_DOWNLOAD) dirname = os.path.dirname(filename) basename = os.path.basename(filename) return send_from_directory(dirname, basename, as_attachment=True) @app.errorhandler(404) def page_not_found(e): + global REQUEST_OTHER + add_request(REQUEST_OTHER) return render_template_string(open('{0}/404.html'.format(os.path.dirname(__file__))).read()) def get_hidden_service_dir(port): diff --git a/onionshare_gui/static/onionshare.js b/onionshare_gui/static/onionshare.js index e9d10125..09c3cc12 100644 --- a/onionshare_gui/static/onionshare.js +++ b/onionshare_gui/static/onionshare.js @@ -1,5 +1,5 @@ $(function(){ - onionshare = {} + var onionshare = {} function update($msg) { var $line = $('

').append($msg); @@ -17,12 +17,36 @@ $(function(){ $.ajax({ url: '/copy_url', success: function(data, textStatus, jqXHR){ - update('Copied secret URL to clipboard.'); + update('Copied secret URL to clipboard'); } }); } $('#copy-button').click(copy_to_clipboard); + var REQUEST_LOAD = 0; + var REQUEST_DOWNLOAD = 1; + var REQUEST_OTHER = 2; + function check_for_requests() { + $.ajax({ + url: '/check_for_requests', + success: function(data, textStatus, jqXHR){ + if(data != '') { + var r = JSON.parse(data); + if(r.type == REQUEST_LOAD) { + update($('').addClass('weblog').html('Download page loaded')); + } else if(r.type == REQUEST_DOWNLOAD) { + update($('').addClass('weblog').html('Download started')); + } else { + if(r.path != '/favicon.ico') + update($('').addClass('weblog-error').html('Other page has been loaded: {0}'.replace('{0}', r.path))); + } + } + + setTimeout(check_for_requests, 1000); + } + }); + } + // start onionshare $.ajax({ url: '/start_onionshare', @@ -39,6 +63,8 @@ $(function(){ copy_to_clipboard(); $('#copy-button').show(); + setTimeout(check_for_requests, 1000); + $('#loading').hide(); $('#content').show(); } diff --git a/onionshare_gui/static/style.css b/onionshare_gui/static/style.css index 3e94e720..9004c352 100644 --- a/onionshare_gui/static/style.css +++ b/onionshare_gui/static/style.css @@ -20,7 +20,7 @@ h1 { p { padding: 0; - margin: 0 0 .3em 0; + margin: 0 0 .5em 0; } #output { @@ -31,6 +31,16 @@ p { font-family: monospace; } +#output .weblog { + color: #009900; + font-weight: bold; +} + +#output .weblog-error { + color: #990000; + font-weight: bold; +} + .button { -moz-box-shadow:inset 0px 1px 0px 0px #f29c93; -webkit-box-shadow:inset 0px 1px 0px 0px #f29c93; @@ -77,14 +87,6 @@ p { bottom: 10px; } -.loader { - width: 21px; - height: 20px; - background-image: url('loader.gif'); - background-position: top left; - background-repeat: no-repeat; -} - #loading { width: 550px; height: 300px; diff --git a/onionshare_gui/webapp.py b/onionshare_gui/webapp.py index 8269685a..2e1522eb 100644 --- a/onionshare_gui/webapp.py +++ b/onionshare_gui/webapp.py @@ -44,3 +44,12 @@ def copy_url(): clipboard.set_text(url) return '' +@app.route("/check_for_requests") +def check_for_requests(): + global onionshare + try: + r = onionshare.request_q.get(False) + return json.dumps(r) + except onionshare.Queue.Empty: + return '' +