mirror of https://github.com/oupson/FooTerm.git
Disconnect when closing tab
This commit is contained in:
parent
53427b3f7e
commit
df40cbf7a9
|
@ -37,7 +37,8 @@ namespace Footerm {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async void close () {
|
public async void close () {
|
||||||
|
yield this.terminal_pane.disconnect_from_server();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,13 @@ namespace Footerm {
|
||||||
[GtkChild]
|
[GtkChild]
|
||||||
private unowned Vte.Terminal terminal;
|
private unowned Vte.Terminal terminal;
|
||||||
|
|
||||||
private SSH2.Session<bool>? session;
|
private SSH2.Session<bool>? session = null;
|
||||||
private SSH2.Channel? channel;
|
private SSH2.Channel? channel = null;
|
||||||
private SocketConnection socket;
|
private SocketConnection? socket = null;
|
||||||
private IOChannel slave_channel;
|
private IOChannel? slave_channel = null;
|
||||||
|
private SocketSource? socket_source = null;
|
||||||
|
|
||||||
|
private Cancellable cancel = new Cancellable();
|
||||||
|
|
||||||
private Footerm.Model.Server? server;
|
private Footerm.Model.Server? server;
|
||||||
|
|
||||||
|
@ -47,6 +50,32 @@ namespace Footerm {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void disconnect_from_server() {
|
||||||
|
debug("Disconnecting ...");
|
||||||
|
if (this.session != null) {
|
||||||
|
this.socket_source.destroy();
|
||||||
|
this.socket_source = null;
|
||||||
|
|
||||||
|
this.slave_channel.shutdown(true);
|
||||||
|
this.slave_channel = null;
|
||||||
|
|
||||||
|
this.cancel.cancel();
|
||||||
|
this.session.blocking = true;
|
||||||
|
|
||||||
|
this.channel.close();
|
||||||
|
this.channel = null;
|
||||||
|
|
||||||
|
this.session.disconnect("Terminal pane was closed");
|
||||||
|
this.session = null;
|
||||||
|
|
||||||
|
yield this.socket.close_async(0, null);
|
||||||
|
|
||||||
|
this.socket = null;
|
||||||
|
|
||||||
|
this.server = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void configure_terminal() {
|
private void configure_terminal() {
|
||||||
this.terminal.set_enable_sixel(true);
|
this.terminal.set_enable_sixel(true);
|
||||||
this.terminal.char_size_changed.connect(() => {
|
this.terminal.char_size_changed.connect(() => {
|
||||||
|
@ -91,8 +120,7 @@ namespace Footerm {
|
||||||
throw GLib.IOError.from_errno(Posix.errno);
|
throw GLib.IOError.from_errno(Posix.errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var vte_pty = new Vte.Pty.foreign_sync(master_pty, this.cancel);
|
||||||
var vte_pty = new Vte.Pty.foreign_sync(master_pty, null);
|
|
||||||
this.terminal.set_pty(vte_pty);
|
this.terminal.set_pty(vte_pty);
|
||||||
|
|
||||||
this.slave_channel = new GLib.IOChannel.unix_new(slave_pty);
|
this.slave_channel = new GLib.IOChannel.unix_new(slave_pty);
|
||||||
|
@ -157,9 +185,9 @@ namespace Footerm {
|
||||||
this.create_pty();
|
this.create_pty();
|
||||||
|
|
||||||
var inner_socket = socket.get_socket();
|
var inner_socket = socket.get_socket();
|
||||||
var source = inner_socket.create_source(GLib.IOCondition.IN, null);
|
this.socket_source = inner_socket.create_source(GLib.IOCondition.IN, this.cancel);
|
||||||
source.set_callback(this.on_ssh_event);
|
this.socket_source.set_callback(this.on_ssh_event);
|
||||||
source.attach(null);
|
this.socket_source.attach(null);
|
||||||
|
|
||||||
slave_channel.add_watch(GLib.IOCondition.IN, this.on_slave_event);
|
slave_channel.add_watch(GLib.IOCondition.IN, this.on_slave_event);
|
||||||
}
|
}
|
||||||
|
@ -171,6 +199,10 @@ namespace Footerm {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.cancel.is_cancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ssize_t size = 0;
|
ssize_t size = 0;
|
||||||
var buffer = new uint8[1024];
|
var buffer = new uint8[1024];
|
||||||
|
@ -207,6 +239,7 @@ namespace Footerm {
|
||||||
var res = this.channel.write((uint8[]) buffer[0 : size]);
|
var res = this.channel.write((uint8[]) buffer[0 : size]);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warning("Channel write failed with %zu", res);
|
warning("Channel write failed with %zu", res);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
|
|
|
@ -42,9 +42,16 @@ namespace Footerm {
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool close_page (Adw.TabView tab_view, Adw.TabPage page) {
|
private bool close_page (Adw.TabView tab_view, Adw.TabPage page) {
|
||||||
// TODO CLOSE CONNEXION FOR PANE
|
if (!page.get_pinned ()) {
|
||||||
debug ("Close pane");
|
var child = (Footerm.Pane) page.get_child ();
|
||||||
tab_view.close_page_finish (page, !page.get_pinned ());
|
child.close.begin ((obj, res) => {
|
||||||
|
child.close.end (res);
|
||||||
|
tab_view.close_page_finish (page, true);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
tab_view.close_page_finish (page, false);
|
||||||
|
}
|
||||||
|
|
||||||
return Gdk.EVENT_STOP;
|
return Gdk.EVENT_STOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue