Skip to content

Commit b51a460

Browse files
committed
fix: hotkeys to start fetch/pull/push directly not work on macOS (#657)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 356fb6f commit b51a460

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/Views/RepositoryToolbar.axaml.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
using Avalonia.Controls;
24
using Avalonia.Input;
35
using Avalonia.Interactivity;
@@ -45,22 +47,43 @@ private async void OpenConfigure(object sender, RoutedEventArgs e)
4547
private void Fetch(object _, RoutedEventArgs e)
4648
{
4749
var launcher = this.FindAncestorOfType<Launcher>();
48-
(DataContext as ViewModels.Repository)?.Fetch(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
49-
e.Handled = true;
50+
if (launcher is not null && DataContext is ViewModels.Repository repo)
51+
{
52+
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
53+
if (!startDirectly && OperatingSystem.IsMacOS())
54+
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
55+
56+
repo.Fetch(startDirectly);
57+
e.Handled = true;
58+
}
5059
}
5160

5261
private void Pull(object _, RoutedEventArgs e)
5362
{
5463
var launcher = this.FindAncestorOfType<Launcher>();
55-
(DataContext as ViewModels.Repository)?.Pull(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
56-
e.Handled = true;
64+
if (launcher is not null && DataContext is ViewModels.Repository repo)
65+
{
66+
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
67+
if (!startDirectly && OperatingSystem.IsMacOS())
68+
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
69+
70+
repo.Pull(startDirectly);
71+
e.Handled = true;
72+
}
5773
}
5874

5975
private void Push(object _, RoutedEventArgs e)
6076
{
6177
var launcher = this.FindAncestorOfType<Launcher>();
62-
(DataContext as ViewModels.Repository)?.Push(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
63-
e.Handled = true;
78+
if (launcher is not null && DataContext is ViewModels.Repository repo)
79+
{
80+
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
81+
if (!startDirectly && OperatingSystem.IsMacOS())
82+
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
83+
84+
repo.Push(startDirectly);
85+
e.Handled = true;
86+
}
6487
}
6588

6689
private void StashAll(object _, RoutedEventArgs e)

0 commit comments

Comments
 (0)