running async startup work in a separate thread, and design tweaks

This commit is contained in:
Micah Lee 2014-05-30 23:12:52 -04:00
parent 23f9a577fe
commit 906eeccb54
5 changed files with 37 additions and 23 deletions

View File

@ -4,7 +4,7 @@
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
</head>
<body>
<h1><span id="basename">...</span></h1>
<h1><span id="basename"></span></h1>
<div id="output"></div>
<button class="button" id="copy-button">Copy URL</button>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -4,7 +4,7 @@ function send(msg) {
}
function init(basename, strings) {
$('#basename').html(basename);
$('#basename').html(basename).show();
}
function url_is_set() {
@ -16,7 +16,8 @@ function url_is_set() {
}
function update(msg) {
$('#output').append($('<p></p>').html(msg))
var $line = $('<p></p>').append(msg);
$('#output').append($line);
// scroll to bottom
$('#output').scrollTop($('#output').height());

View File

@ -2,7 +2,7 @@ body {
background-color: #ffffff;
color: #000000;
font-family: arial;
width: 650px;
width: 550px;
height: 300px;
margin: 0 auto;
padding: 0;
@ -28,6 +28,7 @@ p {
word-wrap: break-word;
height: 260px;
overflow: auto;
font-family: monospace;
}
.button {
@ -75,3 +76,11 @@ p {
right: 20px;
bottom: 10px;
}
.loader {
width: 21px;
height: 20px;
background-image: url('loader.gif');
background-position: top left;
background-repeat: no-repeat;
}

View File

@ -61,6 +61,7 @@ def main():
except onionshare.NoTor as e:
alert(e.args[0], gtk.MESSAGE_ERROR)
return
onionshare.tails_open_port(port)
# select file to share
filename, basename = select_file(strings)
@ -80,14 +81,11 @@ def main():
clipboard.set_text(url)
web_send("update('{0}')".format('Copied secret URL to clipboard.'))
# startup
def startup():
# the async nature of things requires startup to be split into multiple functions
def startup_async():
global url
web_send("init('{0}', {1});".format(basename, json.dumps(strings)))
web_send("update('{0}')".format(strings['calculating_sha1']))
filehash, filesize = onionshare.file_crunching(filename)
onionshare.set_file_info(filename, filehash, filesize)
onionshare.tails_open_port(port)
url = 'http://{0}/{1}'.format(onion_host, onionshare.slug)
web_send("update('{0}')".format(strings['give_this_url'].replace('\'', '\\\'')))
web_send("update('<strong>{0}</strong>')".format(url))
@ -96,11 +94,17 @@ def main():
# clipboard needs a bit of time before copying url
gobject.timeout_add(500, set_clipboard)
# start the web server
web_thread = thread.start_new_thread(onionshare.app.run, (), {"port": port})
def startup_sync():
web_send("init('{0}', {1});".format(basename, json.dumps(strings)))
web_send("update('{0}')".format(strings['calculating_sha1']))
# webview needs a bit of time before receiving data
gobject.timeout_add(100, startup)
# run other startup in the background
thread_crunch = thread.start_new_thread(startup_async, ())
# start the web server
thread_web = thread.start_new_thread(onionshare.app.run, (), {"port": port})
gobject.timeout_add(100, startup_sync)
# main loop
last_second = time.time()