Confirm before close if the websocket is still open

This commit is contained in:
Florian Mounier
2014-01-31 15:37:54 +01:00
parent 3b94bab145
commit a6de5eb22e
4 changed files with 20 additions and 3 deletions

View File

@@ -59,6 +59,8 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
print('User %s not found' % user)
else:
self.user = user
butterfly_dir = os.getcwd()
try:
os.chdir(self.path or self.pw.pw_dir)
except:
@@ -76,7 +78,7 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
env["COLORTERM"] = "butterfly"
env["LOCATION"] = "http://%s:%d/" % (
tornado.options.options.host, tornado.options.options.port)
env["BUTTERFLY_DIR"] = os.getcwd()
env["BUTTERFLY_DIR"] = butterfly_dir
env["SHELL"] = self.pw.pw_shell or '/bin/sh'
env["PATH"] = '%s:%s' % (os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', 'bin')), env.get("PATH"))

View File

@@ -1,5 +1,6 @@
term = ws = null
cols = rows = null
quit = false
$ = document.querySelectorAll.bind(document)
ws_url = 'ws://' + document.location.host + '/ws' + location.pathname
@@ -26,12 +27,17 @@ ws.onclose = ->
if term
term.destroy()
console.log "WebSocket closed", arguments
quit = true
open('','_self').close()
ws.onerror = -> console.log "WebSocket error", arguments
ws.onmessage = (event) ->
term.write event.data
addEventListener 'beforeunload', ->
if not quit
'This will exit the terminal session'
addEventListener 'resize', resize = ->
main = $('main')[0]
fake_term = document.createElement('div')

View File

@@ -1,10 +1,12 @@
// Generated by CoffeeScript 1.6.3
var $, cols, resize, rows, term, ws, ws_url;
var $, cols, quit, resize, rows, term, ws, ws_url;
term = ws = null;
cols = rows = null;
quit = false;
$ = document.querySelectorAll.bind(document);
ws_url = 'ws://' + document.location.host + '/ws' + location.pathname;
@@ -34,6 +36,7 @@ ws.onclose = function() {
term.destroy();
}
console.log("WebSocket closed", arguments);
quit = true;
return open('', '_self').close();
};
@@ -45,6 +48,12 @@ ws.onmessage = function(event) {
return term.write(event.data);
};
addEventListener('beforeunload', function() {
if (!quit) {
return 'This will exit the terminal session';
}
});
addEventListener('resize', resize = function() {
var eh, ew, fake_term, fake_term_div, fake_term_line, main, main_bb;
main = $('main')[0];

2
dev.py
View File

@@ -10,7 +10,7 @@ commands = [
'coffee -wcb -j butterfly/static/javascripts/main.js ' +
' '.join(glob('butterfly/static/coffees/*.coffee')),
'compass watch butterfly/static',
'python butterfly.py ' + ' '.join(sys.argv[1:])
'python butterfly.server.py ' + ' '.join(sys.argv[1:])
]