@@ -317,7 +317,12 @@ public class Network.WifiInterface : Network.WidgetNMInterface {
317317
318318 wifi_dialog. response. connect ((response) = > {
319319 if (response == Gtk . ResponseType . OK ) {
320- connect_to_network. begin (wifi_dialog);
320+ // Can't re-use connection because we need credentials etc
321+ NM . Device device;
322+ NM . AccessPoint ? access_point = null ;
323+ var dialog_connection = wifi_dialog. get_connection (out device, out access_point);
324+
325+ connect_to_network. begin (dialog_connection, device, access_point);
321326 }
322327
323328 wifi_dialog. destroy ();
@@ -374,7 +379,11 @@ public class Network.WifiInterface : Network.WidgetNMInterface {
374379
375380 hidden_dialog. response. connect ((response) = > {
376381 if (response == Gtk . ResponseType . OK ) {
377- connect_to_network. begin (hidden_dialog);
382+ NM . Device device;
383+ NM . AccessPoint ? access_point = null ;
384+ var dialog_connection = hidden_dialog. get_connection (out device, out access_point);
385+
386+ connect_to_network. begin (dialog_connection, device, access_point);
378387 }
379388
380389 hidden_dialog. destroy ();
@@ -383,50 +392,40 @@ public class Network.WifiInterface : Network.WidgetNMInterface {
383392 hidden_dialog. present ();
384393 }
385394
386- private async void connect_to_network (NMA . WifiDialog wifi_dialog ) {
395+ private async void connect_to_network (NM . Connection connection , NM . Device device , NM . AccessPoint ? access_point ) {
387396 NM . Connection ? fuzzy = null ;
388- NM . Device dialog_device;
389- NM . AccessPoint ? dialog_ap = null ;
390- var dialog_connection = wifi_dialog. get_connection (out dialog_device, out dialog_ap);
391-
392397 nm_client. get_connections (). foreach ((possible) = > {
393- if (dialog_connection . compare (possible, NM . SettingCompareFlags . FUZZY | NM . SettingCompareFlags . IGNORE_ID )) {
398+ if (connection . compare (possible, NM . SettingCompareFlags . FUZZY | NM . SettingCompareFlags . IGNORE_ID )) {
394399 fuzzy = possible;
395400 }
396401 });
397402
398- string ? path = null ;
399- if (dialog_ap != null ) {
400- path = dialog_ap. get_path ();
401- }
403+ string ? path = access_point? . get_path ();
402404
403405 if (fuzzy != null ) {
404406 try {
405407 yield nm_client. activate_connection_async (fuzzy, wifi_device, path, null );
406408 } catch (Error error) {
407409 critical (error. message);
408410 }
409- } else {
410- string ? mode = null ;
411- unowned NM . SettingWireless setting_wireless = dialog_connection. get_setting_wireless ();
412- if (setting_wireless != null ) {
413- mode = setting_wireless. get_mode ();
414- }
415411
416- if (mode == " adhoc" ) {
417- NM . SettingConnection connection_setting = dialog_connection. get_setting_connection ();
418- if (connection_setting == null ) {
419- connection_setting = new NM .SettingConnection ();
420- }
412+ return ;
413+ }
421414
422- dialog_connection. add_setting (connection_setting);
415+ unowned var setting_wireless = connection. get_setting_wireless ();
416+ if (setting_wireless != null && setting_wireless. get_mode () == " adhoc" ) {
417+ var connection_setting = connection. get_setting_connection ();
418+ if (connection_setting == null ) {
419+ connection_setting = new NM .SettingConnection ();
423420 }
424421
425- try {
426- yield nm_client. add_and_activate_connection_async (dialog_connection, dialog_device, path, null );
427- } catch (Error error) {
428- critical (error. message);
429- }
422+ connection. add_setting (connection_setting);
423+ }
424+
425+ try {
426+ yield nm_client. add_and_activate_connection_async (connection, device, path, null );
427+ } catch (Error error) {
428+ critical (error. message);
430429 }
431430 }
432431
0 commit comments