2014-05-29 21:05:30 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import onionshare, webgui
|
|
|
|
import signal, os, time, json
|
|
|
|
|
|
|
|
class Global(object):
|
|
|
|
quit = False
|
|
|
|
@classmethod
|
|
|
|
def set_quit(cls, *args, **kwargs):
|
|
|
|
cls.quit = True
|
|
|
|
|
|
|
|
def main():
|
2014-05-29 22:31:28 -04:00
|
|
|
filename, basename = webgui.select_file()
|
|
|
|
if not filename:
|
2014-05-29 21:05:30 -04:00
|
|
|
return
|
|
|
|
|
2014-05-29 22:53:35 -04:00
|
|
|
# initialize onionshare
|
|
|
|
onionshare.load_strings()
|
|
|
|
|
2014-05-29 22:31:28 -04:00
|
|
|
# open the window, launching webkit browser
|
2014-05-29 21:05:30 -04:00
|
|
|
webgui.start_gtk_thread()
|
2014-05-29 22:31:28 -04:00
|
|
|
browser, web_recv, web_send = webgui.sync_gtk_msg(webgui.launch_window)(
|
|
|
|
title="OnionShare | {0}".format(basename),
|
|
|
|
quit_function=Global.set_quit)
|
2014-05-29 21:05:30 -04:00
|
|
|
|
2014-05-29 22:31:28 -04:00
|
|
|
# send the browser initial data
|
|
|
|
time.sleep(0.1)
|
|
|
|
web_send("set_basename('{0}')".format(basename))
|
2014-05-29 22:53:35 -04:00
|
|
|
web_send("set_strings('{0}')".format(json.dumps(onionshare.strings)))
|
2014-05-29 22:31:28 -04:00
|
|
|
|
|
|
|
# main loop
|
2014-05-29 21:05:30 -04:00
|
|
|
last_second = time.time()
|
|
|
|
uptime_seconds = 1
|
|
|
|
clicks = 0
|
|
|
|
while not Global.quit:
|
|
|
|
|
|
|
|
current_time = time.time()
|
|
|
|
again = False
|
|
|
|
msg = web_recv()
|
|
|
|
if msg:
|
|
|
|
msg = json.loads(msg)
|
|
|
|
again = True
|
|
|
|
|
2014-05-29 22:31:28 -04:00
|
|
|
# check msg for messages from the browser
|
|
|
|
# use web_send() to send javascript to the browser
|
2014-05-29 22:53:35 -04:00
|
|
|
|
2014-05-29 22:31:28 -04:00
|
|
|
if not again:
|
2014-05-29 21:05:30 -04:00
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
def my_quit_wrapper(fun):
|
|
|
|
signal.signal(signal.SIGINT, Global.set_quit)
|
|
|
|
def fun2(*args, **kwargs):
|
|
|
|
try:
|
|
|
|
x = fun(*args, **kwargs) # equivalent to "apply"
|
|
|
|
finally:
|
|
|
|
kill_gtk_thread()
|
|
|
|
Global.set_quit()
|
|
|
|
return x
|
|
|
|
return fun2
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|