Skip to content

Commit f3fa914

Browse files
committed
fix(tox_kill): kill Tox properly. Close #20 (#103)
* fix(tox_kill): kill Tox properly. Close #20 * If disconnect is called, let's stop the Tox iteration * The call tox_kill()
1 parent 23f679a commit f3fa914

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/MainWindow.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ public class Ricin.MainWindow : Gtk.ApplicationWindow {
707707
~MainWindow () {
708708
this.tox.save_data ();
709709
this.settings.save_settings ();
710+
this.tox.disconnect ();
710711
//this.tox.handle = null;
711712
//this.tox = null;
712713
}

src/Ricin.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ public class Ricin.Ricin : Gtk.Application {
22
const string GETTEXT_PACKAGE = "ricin";
33
public static const string APP_NAME = "Ricin";
44
public static const string APP_SUMMARY = _("<b>Ricin</b> aims to be a <i>secure, lightweight, hackable and fully-customizable</i> chat client using the awesome and open-source <b>ToxCore</b> library.");
5-
public static const string APP_VERSION = "0.0.6";
5+
public static const string APP_VERSION = "0.0.6.1";
66
public static const string RES_BASE_PATH = "/chat/tox/ricin/";
77

88
private string default_theme = "dark"; // Will be overrided by settings.

src/Wrapper.vala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ namespace Tox {
6565
private string? profile = null;
6666
internal Gdk.Pixbuf? avatar = null;
6767

68+
// Used to kill tox.
69+
private bool must_stop = false;
70+
6871
public string username {
6972
owned get {
7073
uint8[] chars = new uint8[this.handle.self_get_name_size ()];
@@ -365,12 +368,21 @@ namespace Tox {
365368
this.bootstrap.begin ();
366369
}
367370

371+
public void disconnect () {
372+
this.must_stop = true;
373+
this.handle.kill ();
374+
}
375+
368376
public void run_loop () {
369377
this.schedule_loop_iteration ();
370378
}
371379

372380
private void schedule_loop_iteration () {
373381
Timeout.add (this.handle.iteration_interval (), () => {
382+
if (this.must_stop) {
383+
return true;
384+
}
385+
374386
this.handle.iterate ();
375387
this.schedule_loop_iteration ();
376388
//return Source.REMOVE;

vapis/libtoxcore.vapi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,15 @@ namespace ToxCore {
998998
*/
999999
public Tox (Options? options = null, out ERR_NEW? error = null);
10001000

1001+
/**
1002+
* Releases all resources associated with the Tox instance and disconnects from
1003+
* the network.
1004+
*
1005+
* After calling this function, the Tox pointer becomes invalid. No other
1006+
* functions can be called, and the pointer value can no longer be read.
1007+
*/
1008+
public void kill ();
1009+
10011010
/**
10021011
* @param friend_number The friend number of the friend whose name changed.
10031012
* @param name A byte array containing the same data as

0 commit comments

Comments
 (0)