Skip to content

Commit b41bab6

Browse files
committed
Fix configuration saving
1 parent 45f7748 commit b41bab6

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

SimpleDnsCrypt/ViewModels/MainViewModel.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public DnscryptProxyConfiguration DnscryptProxyConfiguration
377377
}
378378
}
379379

380-
public void SaveDnsCryptConfiguration()
380+
public async void SaveDnsCryptConfiguration()
381381
{
382382
IsSavingConfiguration = true;
383383
try
@@ -386,25 +386,35 @@ public void SaveDnsCryptConfiguration()
386386
DnscryptProxyConfigurationManager.DnscryptProxyConfiguration = _dnscryptProxyConfiguration;
387387
if (DnscryptProxyConfigurationManager.SaveConfiguration())
388388
{
389-
DnscryptProxyConfigurationManager.LoadConfiguration();
389+
//DnscryptProxyConfigurationManager.LoadConfiguration();
390390
_dnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration;
391+
IsWorkingOnService = true;
391392
if (DnsCryptProxyManager.IsDnsCryptProxyInstalled())
392393
{
393394
if (DnsCryptProxyManager.IsDnsCryptProxyRunning())
394395
{
395-
DnsCryptProxyManager.Restart();
396+
await Task.Run(() => { DnsCryptProxyManager.Restart(); }).ConfigureAwait(false);
397+
await Task.Delay(Global.ServiceRestartTime).ConfigureAwait(false);
396398
}
397399
else
398400
{
399-
DnsCryptProxyManager.Start();
401+
await Task.Run(() => { DnsCryptProxyManager.Start(); }).ConfigureAwait(false);
402+
await Task.Delay(Global.ServiceStartTime).ConfigureAwait(false);
400403
}
401404
}
402405
}
403406
_isResolverRunning = DnsCryptProxyManager.IsDnsCryptProxyRunning();
404407
NotifyOfPropertyChange(() => IsResolverRunning);
405408
}
406-
catch(Exception) { }
407-
IsSavingConfiguration = false;
409+
catch (Exception)
410+
{
411+
412+
}
413+
finally
414+
{
415+
IsSavingConfiguration = false;
416+
IsWorkingOnService = false;
417+
}
408418
}
409419

410420
/// <summary>

SimpleDnsCrypt/Views/MainView.xaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
<TabItem.Content>
6363
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
6464
<Border BorderThickness="1" Background="#198AB328" Padding="10,10" Margin="0,0,0,0"
65-
MinHeight="75">
65+
MinHeight="75"
66+
IsEnabled="{Binding IsSavingConfiguration, Converter={StaticResource ReverseBoolToEnabledConverter}}">
6667
<Border.BorderBrush>
6768
<DrawingBrush Viewport="0,0,8,8" ViewportUnits="Absolute" TileMode="Tile"
6869
Opacity="0.4">
@@ -144,7 +145,6 @@
144145
VerticalAlignment="Bottom" HorizontalAlignment="Right"
145146
Content="{lex:Loc Key=default_settings_apply_settings}"
146147
Cursor="Hand"
147-
IsEnabled="{Binding IsSavingConfiguration, Converter={StaticResource ReverseBoolToEnabledConverter}}"
148148
Style="{DynamicResource AccentedSquareButtonStyle}" />
149149
</Grid>
150150
</UniformGrid>
@@ -390,7 +390,8 @@
390390
Foreground="#FF8ab329"
391391
HorizontalAlignment="Left"
392392
VerticalAlignment="Center" />
393-
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0" Margin="5,0,0,3">
393+
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0"
394+
Margin="5,0,0,3">
394395
<TextBlock Text="{lex:Loc Key=resolvers_available_resolvers_header}"
395396
TextWrapping="Wrap" VerticalAlignment="Center"
396397
Foreground="#FF8ab329" FontSize="20"
@@ -403,7 +404,8 @@
403404
</TextBlock>
404405
</StackPanel>
405406
<Button x:Name="SaveLocalServers" Grid.Column="2" Grid.Row="0"
406-
Cursor="Hand" IsEnabled="{Binding Resolvers.Count, Converter={StaticResource IntegerToBoolConverter}}"
407+
Cursor="Hand"
408+
IsEnabled="{Binding Resolvers.Count, Converter={StaticResource IntegerToBoolConverter}}"
407409
Content="{lex:Loc Key=default_settings_apply_settings}"
408410
Width="Auto" HorizontalAlignment="Right"
409411
Style="{DynamicResource AccentedSquareButtonStyle}" />
@@ -445,7 +447,8 @@
445447
<RowDefinition Height="350" />
446448
</Grid.RowDefinitions>
447449
<ScrollViewer VerticalScrollBarVisibility="Auto" Margin="0,5,0,0">
448-
<ItemsControl ItemsSource="{Binding Resolvers}" IsEnabled="True" Margin="0">
450+
<ItemsControl ItemsSource="{Binding Resolvers}" IsEnabled="True"
451+
Margin="0">
449452
<ItemsControl.ItemsPanel>
450453
<ItemsPanelTemplate>
451454
<UniformGrid Columns="3" />
@@ -476,8 +479,9 @@
476479
</ItemsControl.ItemTemplate>
477480
</ItemsControl>
478481
</ScrollViewer>
479-
<TextBlock Foreground="#FF575757" Text="No resolvers have been loaded yet" Visibility="{Binding Resolvers.Count, Converter={StaticResource IntegerToVisibilityConverter}}"
480-
HorizontalAlignment="Center" VerticalAlignment="Center"/>
482+
<TextBlock Foreground="#FF575757" Text="No resolvers have been loaded yet"
483+
Visibility="{Binding Resolvers.Count, Converter={StaticResource IntegerToVisibilityConverter}}"
484+
HorizontalAlignment="Center" VerticalAlignment="Center" />
481485
</Grid>
482486
</StackPanel>
483487
</Border>

0 commit comments

Comments
 (0)