Skip to content

Commit

Permalink
Improve synchronisation of the pairing code message.
Browse files Browse the repository at this point in the history
We did send the code to the server and showed the code at the same time.
This will let the user enter the code before we managed to connect. Now
we show a "connecting..." message first and only show the code when we
conencted.
See OpenRoberta/robertalab-ev3dev#30
  • Loading branch information
ensonic committed Jun 26, 2018
1 parent a930c82 commit 3bc3c89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/controller/OpenRobertaController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace BrickManager {
chvt (tty_num);
} else {
debug ("connection established, closing the dialog");
OpenRobertaWindow.close_pairing_code_dialog ();
OpenRobertaWindow.close_connection_dialog ();
// remember selected server
config.set_string ("Common", "SelectedServer",
open_roberta_window.selected_server);
Expand All @@ -168,7 +168,7 @@ namespace BrickManager {
open_roberta_window.connected = false;
if (message == "disconnected") {
debug ("connection failed, closing the dialog");
OpenRobertaWindow.close_pairing_code_dialog ();
OpenRobertaWindow.close_connection_dialog ();
}
}
}
Expand All @@ -186,8 +186,13 @@ namespace BrickManager {
void on_server_connect (string address) {
try {
open_roberta_window.selected_server = address;
var code = service.connect ("http://" + address);
OpenRobertaWindow.show_pairing_code_dialog (code);
OpenRobertaWindow.show_connection_dialog ("Connect to server", "Connecting ...");
Idle.add (() => {
var code = service.connect ("http://" + address);
OpenRobertaWindow.close_connection_dialog ();
OpenRobertaWindow.show_connection_dialog ("Pairing code", code);
return Source.REMOVE;
});
} catch (IOError err) {
warning ("%s", err.message);
}
Expand Down
8 changes: 4 additions & 4 deletions src/view/OpenRobertaWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ namespace BrickManager {
dialog.show ();
}

public static void show_pairing_code_dialog (string code) {
var label = new Label (code) {
public static void show_connection_dialog (string title, string message) {
var label = new Label (message) {
margin_top = 12,
font = Fonts.get_big ()
};
pin_dialog = new MessageDialog.with_content ("Pairing code", label);
pin_dialog = new MessageDialog.with_content (title, label);
ulong pin_dialog_closed_id = 0;
pin_dialog_closed_id = pin_dialog.closed.connect (() => {
pin_dialog.disconnect (pin_dialog_closed_id);
Expand All @@ -174,7 +174,7 @@ namespace BrickManager {
pin_dialog.show ();
}

public static void close_pairing_code_dialog () {
public static void close_connection_dialog () {
if (pin_dialog != null) {
pin_dialog.close ();
}
Expand Down

0 comments on commit 3bc3c89

Please sign in to comment.