mirror of
https://github.com/onionshare/onionshare.git
synced 2025-08-14 09:05:57 -04:00
created a working web gui with message passing
This commit is contained in:
parent
0f53d45489
commit
d3c4bb3e93
6 changed files with 91 additions and 77 deletions
|
@ -1,34 +1,17 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<style type="text/css">
|
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
background-color: #FFC4D5;
|
|
||||||
color: #000000;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 30px;
|
|
||||||
margin: 0;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
h1 .skull {
|
|
||||||
font-size: 40px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #FF0048;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<script>
|
|
||||||
function send(msg) {
|
|
||||||
document.title = "null";
|
|
||||||
document.title = msg;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1><span class="skull">☠</span> filename.zip</h1>
|
<h1><span class="skull">☠</span> <span id="basename">...</span></h1>
|
||||||
<p id="uptime-value"></p>
|
<div id="url-wrapper">
|
||||||
</body>
|
<div id="url-header">Give this URL to the person you're sending the file to:</div>
|
||||||
|
<div id="url"></div>
|
||||||
|
</div>
|
||||||
|
<div id="output">...</div>
|
||||||
|
|
||||||
|
<script src="jquery-1.11.1.min.js"></script>
|
||||||
|
<script src="onionshare.js"></script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
4
onionshare_gui/jquery-1.11.1.min.js
vendored
Normal file
4
onionshare_gui/jquery-1.11.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
9
onionshare_gui/onionshare.js
Normal file
9
onionshare_gui/onionshare.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
function send(msg) {
|
||||||
|
document.title = "null";
|
||||||
|
document.title = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_basename(basename) {
|
||||||
|
$('#basename').html(basename);
|
||||||
|
}
|
||||||
|
|
|
@ -10,12 +10,21 @@ class Global(object):
|
||||||
cls.quit = True
|
cls.quit = True
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not webgui.select_file():
|
filename, basename = webgui.select_file()
|
||||||
|
if not filename:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# open the window, launching webkit browser
|
||||||
webgui.start_gtk_thread()
|
webgui.start_gtk_thread()
|
||||||
browser, web_recv, web_send = webgui.sync_gtk_msg(webgui.launch_browser)(quit_function=Global.set_quit)
|
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
|
||||||
|
time.sleep(0.1)
|
||||||
|
web_send("set_basename('{0}')".format(basename))
|
||||||
|
|
||||||
|
# main loop
|
||||||
last_second = time.time()
|
last_second = time.time()
|
||||||
uptime_seconds = 1
|
uptime_seconds = 1
|
||||||
clicks = 0
|
clicks = 0
|
||||||
|
@ -28,27 +37,10 @@ def main():
|
||||||
msg = json.loads(msg)
|
msg = json.loads(msg)
|
||||||
again = True
|
again = True
|
||||||
|
|
||||||
if msg == "got-a-click":
|
# check msg for messages from the browser
|
||||||
clicks += 1
|
# use web_send() to send javascript to the browser
|
||||||
web_send('document.getElementById("messages").innerHTML = %s' %
|
|
||||||
to_json('%d clicks so far' % clicks))
|
if not again:
|
||||||
# If you are using jQuery, you can do this instead:
|
|
||||||
# web_send('$("#messages").text(%s)' %
|
|
||||||
# to_json('%d clicks so far' % clicks))
|
|
||||||
|
|
||||||
if current_time - last_second >= 1.0:
|
|
||||||
web_send('document.getElementById("uptime-value").innerHTML = %s' %
|
|
||||||
json.dumps('%d' % uptime_seconds))
|
|
||||||
# If you are using jQuery, you can do this instead:
|
|
||||||
# web_send('$("#uptime-value").text(%s)'
|
|
||||||
# % to_json('%d' % uptime_seconds))
|
|
||||||
uptime_seconds += 1
|
|
||||||
last_second += 1.0
|
|
||||||
|
|
||||||
|
|
||||||
if again:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
def my_quit_wrapper(fun):
|
def my_quit_wrapper(fun):
|
||||||
|
|
42
onionshare_gui/style.css
Normal file
42
onionshare_gui/style.css
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
body {
|
||||||
|
background-color: #222222;
|
||||||
|
color: #aaffaa;
|
||||||
|
font-family: monospace;
|
||||||
|
width: 400px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
background-color: #FFC4D5;
|
||||||
|
color: #000000;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 30px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 10px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
h1 .skull {
|
||||||
|
font-size: 40px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #FF0048;
|
||||||
|
}
|
||||||
|
#url-wrapper {
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#url-header {
|
||||||
|
font-size: 14px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
color: #666666;
|
||||||
|
}
|
||||||
|
#url {
|
||||||
|
word-wrap: break-word;
|
||||||
|
font-size: 30px;
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
|
#output {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
|
@ -3,13 +3,11 @@
|
||||||
import time, Queue, thread, gtk, gobject, os, sys, webkit
|
import time, Queue, thread, gtk, gobject, os, sys, webkit
|
||||||
|
|
||||||
def select_file():
|
def select_file():
|
||||||
global filename, basename
|
|
||||||
|
|
||||||
# was a filename passed in as an argument?
|
# was a filename passed in as an argument?
|
||||||
if len(sys.argv) >= 2:
|
if len(sys.argv) >= 2:
|
||||||
filename = sys.argv[1]
|
filename = sys.argv[1]
|
||||||
basename = os.path.basename(filename)
|
basename = os.path.basename(filename)
|
||||||
return True
|
return filename, basename
|
||||||
|
|
||||||
# choose a file
|
# choose a file
|
||||||
canceled = False
|
canceled = False
|
||||||
|
@ -25,7 +23,9 @@ def select_file():
|
||||||
canceled = True
|
canceled = True
|
||||||
chooser.destroy()
|
chooser.destroy()
|
||||||
|
|
||||||
return not canceled
|
if canceled:
|
||||||
|
return False, False
|
||||||
|
return filename, basename
|
||||||
|
|
||||||
def async_gtk_msg(fun):
|
def async_gtk_msg(fun):
|
||||||
def worker((function, args, kwargs)):
|
def worker((function, args, kwargs)):
|
||||||
|
@ -44,43 +44,27 @@ def sync_gtk_msg(fun):
|
||||||
|
|
||||||
def fun2(*args, **kwargs):
|
def fun2(*args, **kwargs):
|
||||||
class R: result = NoResult
|
class R: result = NoResult
|
||||||
gobject.idle_add(callable=worker, user_data=(R, fun, args, kwargs))
|
gobject.idle_add(worker, (R, fun, args, kwargs))
|
||||||
while R.result is NoResult: time.sleep(0.01)
|
while R.result is NoResult: time.sleep(0.01)
|
||||||
return R.result
|
return R.result
|
||||||
|
|
||||||
return fun2
|
return fun2
|
||||||
|
|
||||||
def launch_browser(quit_function=None, echo=True):
|
def launch_window(title='OnionShare', quit_function=None, echo=True):
|
||||||
window = gtk.Window()
|
window = gtk.Window()
|
||||||
|
window.set_title(title)
|
||||||
browser = webkit.WebView()
|
browser = webkit.WebView()
|
||||||
|
|
||||||
box = gtk.VBox(homogeneous=False, spacing=0)
|
box = gtk.VBox(homogeneous=False, spacing=0)
|
||||||
window.add(box)
|
window.add(box)
|
||||||
|
|
||||||
if quit_function is not None:
|
if quit_function is not None:
|
||||||
# file > quit menu
|
|
||||||
file_menu = gtk.Menu()
|
|
||||||
quit_item = gtk.MenuItem('Quit')
|
|
||||||
accel_group = gtk.AccelGroup()
|
|
||||||
quit_item.add_accelerator('activate', accel_group, ord('Q'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
|
|
||||||
window.add_accel_group(accel_group)
|
|
||||||
file_menu.append(quit_item)
|
|
||||||
quit_item.connect('activate', quit_function)
|
|
||||||
quit_item.show()
|
|
||||||
menu_bar = gtk.MenuBar()
|
|
||||||
menu_bar.show()
|
|
||||||
file_item = gtk.MenuItem('File')
|
|
||||||
file_item.show()
|
|
||||||
file_item.set_submenu(file_menu)
|
|
||||||
menu_bar.append(file_item)
|
|
||||||
|
|
||||||
box.pack_start(menu_bar, expand=False, fill=True, padding=0)
|
|
||||||
|
|
||||||
window.connect('destroy', quit_function)
|
window.connect('destroy', quit_function)
|
||||||
|
|
||||||
box.pack_start(browser, expand=True, fill=True, padding=0)
|
box.pack_start(browser, expand=True, fill=True, padding=0)
|
||||||
|
|
||||||
window.set_default_size(400, 400)
|
window.set_default_size(600, 600)
|
||||||
|
window.set_resizable(False)
|
||||||
window.show_all()
|
window.show_all()
|
||||||
|
|
||||||
message_queue = Queue.Queue()
|
message_queue = Queue.Queue()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue