Skip to content

Commit

Permalink
Add option to always ask user when no defaults match, fixes #74
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenn committed Apr 3, 2024
1 parent 7b6eb03 commit 8368dd2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/BrowserPicker.App/View/BrowserList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,11 @@
</Hyperlink>
</TextBlock>
<CheckBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" IsChecked="{Binding Configuration.Settings.AlwaysPrompt, UpdateSourceTrigger=PropertyChanged}" Content="Always ask" Foreground="White" />
<CheckBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Left" IsChecked="{Binding Configuration.AutoAddDefault}">
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="White" TextWrapping="Wrap" MaxWidth="320" MaxHeight="50">
<Run Text="Remember my choice for" />
<Run Text="{Binding Url.HostName}" />
</TextBlock>
</StackPanel>
<CheckBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Left" IsChecked="{Binding Configuration.AutoAddDefault}" Width="350">
<TextBlock Foreground="White" TextWrapping="Wrap" MaxHeight="50">
<Run Text="Remember my choice for" />
<Run Text="{Binding Url.HostName}" />
</TextBlock>
</CheckBox>
</Grid>
</Grid>
Expand Down
8 changes: 5 additions & 3 deletions src/BrowserPicker.App/View/Configuration.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@
</StackPanel.Resources>
<CheckBox Content="Turn off transparency" IsChecked="{Binding Settings.DisableTransparency}" Foreground="White" />
<CheckBox Content="Always show browser selection window" IsChecked="{Binding Settings.AlwaysPrompt}" Foreground="White" />
<CheckBox Content="Disable url resolution" IsChecked="{Binding Settings.DisableNetworkAccess}" Foreground="White" />
<CheckBox Content="Ignore defaults when browser is not running" IsChecked="{Binding Settings.AlwaysUseDefaults}" Foreground="White" Checked="CheckBox_Checked" />
<CheckBox Content="Update order in browser list based on usage" IsChecked="{Binding Settings.UseAutomaticOrdering}" Foreground="White" />
<StackPanel Orientation="Horizontal">
<CheckBox Content="When no default is configured matching the url, use:" IsChecked="{Binding Settings.UseFallbackDefault}" Foreground="White" />
<ComboBox
Expand All @@ -165,6 +162,11 @@
SelectedValue="{Binding Settings.DefaultBrowser}"
Height="22" Margin="5,-4,0,0" />
</StackPanel>
<CheckBox Content="Always ask when no default is matching url" IsChecked="{Binding Settings.AlwaysAskWithoutDefault}" Foreground="White" />
<CheckBox Content="Disable url resolution" IsChecked="{Binding Settings.DisableNetworkAccess}" Foreground="White" />
<CheckBox Content="Ignore defaults when browser is not running" IsChecked="{Binding Settings.AlwaysUseDefaults}" Foreground="White" Checked="CheckBox_Checked" />
<CheckBox Content="Update order in browser list based on usage" IsChecked="{Binding Settings.UseAutomaticOrdering}" Foreground="White" />

<CheckBox Content="Disallow network activity" Foreground="White" IsChecked="{Binding Settings.DisableNetworkAccess}" />
<StackPanel Margin="25,0,0,0">
<StackPanel.Style>
Expand Down
6 changes: 5 additions & 1 deletion src/BrowserPicker.App/ViewModel/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Initialize()
}

BrowserViewModel start = GetBrowserToLaunch(Url.UnderlyingTargetURL ?? Url.TargetURL);
if (Debugger.IsAttached)
if (Debugger.IsAttached && start != null)
{
Debug.WriteLine($"Skipping launch of browser {start.Model.Name} due to debugger being attached");
return;
Expand All @@ -87,6 +87,10 @@ internal BrowserViewModel GetBrowserToLaunch(string targetUrl)
{
return browser;
}
if (browser == null && Configuration.Settings.AlwaysAskWithoutDefault)
{
return null;
}
var active = Choices.Where(b => b.IsRunning && !b.Model.Disabled).ToList();
return active.Count == 1 ? active[0] : null;
}
Expand Down
1 change: 1 addition & 0 deletions src/BrowserPicker.App/ViewModel/ConfigurationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private sealed class DesignTimeSettings : IBrowserPickerConfiguration
{
public bool AlwaysPrompt { get; set; } = true;
public bool AlwaysUseDefaults { get; set; } = true;
public bool AlwaysAskWithoutDefault { get; set; }
public int UrlLookupTimeoutMilliseconds { get; set; } = 2000;
public bool UseAutomaticOrdering { get; set; } = true;
public bool DisableTransparency { get; set; } = true;
Expand Down
15 changes: 15 additions & 0 deletions src/BrowserPicker.Windows/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public bool AlwaysUseDefaults
set { Reg.Set(value); OnPropertyChanged(); }
}

public bool AlwaysAskWithoutDefault
{
get => Reg.Get<bool>();
set
{
Reg.Set(value);
OnPropertyChanged();
if (value && use_fallback_default)
{
UseFallbackDefault = false;
}
}
}

public int UrlLookupTimeoutMilliseconds
{
get => Reg.Get(2000);
Expand Down Expand Up @@ -93,6 +107,7 @@ public bool UseFallbackDefault

if (value)
{
AlwaysAskWithoutDefault = false;
use_fallback_default = true;
if (Defaults.All(d => d.Type != MatchType.Default))
{
Expand Down
5 changes: 5 additions & 0 deletions src/BrowserPicker/IBrowserPickerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public interface IBrowserPickerConfiguration : INotifyPropertyChanged, ILongRunn
/// </summary>
bool AlwaysUseDefaults { get; set; }

/// <summary>
/// When set to true and there is no matching default browser, the user choice prompt will be shown
/// </summary>
bool AlwaysAskWithoutDefault { get; set; }

/// <summary>
/// Timeout for resolving underlying url for an address
/// </summary>
Expand Down

0 comments on commit 8368dd2

Please sign in to comment.