From 9d7689f578f0e5b3e5165aa375215aaad78e1123 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 29 May 2014 23:23:40 -0400 Subject: [PATCH] starting to build onionshare functionality into GUI --- onionshare/onionshare.py | 1 + onionshare_gui/html/index.html | 2 +- onionshare_gui/html/onionshare.js | 15 ++++++++++----- onionshare_gui/html/style.css | 7 +++++-- onionshare_gui/onionshare_gui.py | 25 +++++++++++++++++++------ 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 18731fef..8b5d55d6 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -76,6 +76,7 @@ def load_strings(default="en"): lang = lc[:2] if lang in translated: strings = translated[lang] + return strings def file_crunching(filename): # calculate filehash, file size diff --git a/onionshare_gui/html/index.html b/onionshare_gui/html/index.html index 902a1145..281897b5 100644 --- a/onionshare_gui/html/index.html +++ b/onionshare_gui/html/index.html @@ -9,7 +9,7 @@
Give this URL to the person you're sending the file to:
-
...
+
diff --git a/onionshare_gui/html/onionshare.js b/onionshare_gui/html/onionshare.js index 1381db1b..24031dee 100644 --- a/onionshare_gui/html/onionshare.js +++ b/onionshare_gui/html/onionshare.js @@ -3,11 +3,16 @@ function send(msg) { document.title = msg; } -function set_basename(basename) { +function init(basename, strings) { $('#basename').html(basename); -} - -function set_strings(strings) { - strings = JSON.parse(strings) $('#give-this-url').html(strings['give_this_url']) } + +function set_url(url) { + $('#url').html(url); + $('#url-wrapper').slideDown(200); +} + +function update(msg) { + $('#output').append($('

').html(msg)) +} diff --git a/onionshare_gui/html/style.css b/onionshare_gui/html/style.css index cc426180..efd8ac59 100644 --- a/onionshare_gui/html/style.css +++ b/onionshare_gui/html/style.css @@ -2,7 +2,8 @@ body { background-color: #222222; color: #aaffaa; font-family: monospace; - width: 400px; + width: 600px; + height: 500px; margin: 0 auto; padding: 0; } @@ -33,10 +34,12 @@ h1 .skull { } #url { word-wrap: break-word; - font-size: 30px; + font-size: 25px; color: #000000; } #output { padding: 10px; + word-wrap: break-word; + overflow: auto; } diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index f04ab275..b9630aed 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -14,19 +14,32 @@ def main(): if not filename: return - # initialize onionshare - onionshare.load_strings() - # open the window, launching webkit browser webgui.start_gtk_thread() browser, web_recv, web_send = webgui.sync_gtk_msg(webgui.launch_window)( title="OnionShare | {0}".format(basename), quit_function=Global.set_quit) - # send the browser initial data + # wait for window to render time.sleep(0.1) - web_send("set_basename('{0}')".format(basename)) - web_send("set_strings('{0}')".format(json.dumps(onionshare.strings))) + + # initialize onionshare + strings = onionshare.load_strings() + web_send("init('{0}', {1});".format(basename, json.dumps(strings))) + + web_send("update('{0}')".format(strings['calculating_sha1'])) + filehash, filesize = onionshare.file_crunching(filename) + port = onionshare.choose_port() + + web_send("update('{0}')".format(strings['connecting_ctrlport'].format(port))) + onion_host = onionshare.start_hidden_service(port) + + # punch a hole in the firewall + onionshare.tails_open_port(port) + + url = 'http://{0}/{1}'.format(onion_host, onionshare.slug) + web_send("update('{0}')".format('Secret URL is {0}'.format(url))) + web_send("set_url('{0}')".format(url)); # main loop last_second = time.time()