Skip to content

Commit

Permalink
Fix breakage of privacy mode shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenn committed Apr 3, 2024
1 parent fa1b254 commit 7b6eb03
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
18 changes: 12 additions & 6 deletions src/BrowserPicker.App/View/BrowserList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<DataTemplate DataType="viewModel:BrowserViewModel">
<Button Command="{Binding Select}" CommandParameter="{Binding Path=DataContext.Url.TargetURL,RelativeSource={RelativeSource AncestorType={x:Type ScrollViewer}}}" Margin="2">
<Button.Style>
<Style>
<Style TargetType="Button">
<Setter Property="UIElement.Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Model.Disabled}" Value="True">
Expand Down Expand Up @@ -170,16 +170,22 @@
<Trigger Property="IsEnabled" Value="False">
<Setter Property="UIElement.Visibility" Value="Collapsed" />
</Trigger>
<DataTrigger Binding="{Binding Path=DataContext.AltPressed, RelativeSource={RelativeSource AncestorType=UserControl}}">
<Setter Property="BorderBrush" Value="White" />
<Setter Property="BorderThickness" Value="1" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<Button.Template>
<ControlTemplate>
<Border Margin="10" Padding="10" Background="#22ffffff" Width="40" Height="40" CornerRadius="5">
<Border Margin="10" Padding="10" Background="#22ffffff" Width="40" Height="40" CornerRadius="5" BorderThickness="2">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding AltPressed}" Value="True">
<Setter Property="BorderBrush" Value="White" />
<Setter Property="BorderThickness" Value="1" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Image Source="{StaticResource PrivacyShield}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</ControlTemplate>
Expand Down
14 changes: 10 additions & 4 deletions src/BrowserPicker.App/View/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MainWindow()
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
{
ViewModel.AltPressed = Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);
}
}

private void MainWindow_OnKeyUp(object sender, KeyEventArgs e)
{
Expand All @@ -37,7 +37,7 @@ private void MainWindow_OnKeyUp(object sender, KeyEventArgs e)

int n;
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (e.Key)
switch (e.Key == Key.System ? e.SystemKey : e.Key)
{
case Key.Enter:
case Key.D1: n = 1; break;
Expand All @@ -58,8 +58,14 @@ private void MainWindow_OnKeyUp(object sender, KeyEventArgs e)
if (choices.Length < n)
return;

var privacy = Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);
choices[n - 1].Select.Execute(privacy);
if (ViewModel.AltPressed)
{
choices[n - 1].SelectPrivacy.Execute(null);
}
else
{
choices[n - 1].Select.Execute(null);
}
}
catch
{
Expand Down
11 changes: 11 additions & 0 deletions src/BrowserPicker.App/ViewModel/BrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public BrowserViewModel(BrowserModel model, ApplicationViewModel viewModel) : ba
{
model.PropertyChanged += Model_PropertyChanged;
parent_view_model = viewModel;
parent_view_model.PropertyChanged += OnParentViewModelChanged;
}

private void OnParentViewModelChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ApplicationViewModel.AltPressed))
{
OnPropertyChanged(nameof(AltPressed));
}
}

private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down Expand Up @@ -112,6 +121,8 @@ public bool IsRunning
}
}

public bool AltPressed => parent_view_model.AltPressed;

private bool CanLaunch(bool privacy)
{
return !string.IsNullOrWhiteSpace(parent_view_model.Url?.TargetURL) && !(privacy && Model.PrivacyArgs == null);
Expand Down

0 comments on commit 7b6eb03

Please sign in to comment.