diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 6504e85b..6779fd63 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -510,19 +510,30 @@ namespace SourceGit private void TryOpenRepository(string repo) { - if (string.IsNullOrEmpty(repo) || !Directory.Exists(repo)) - return; - - var test = new Commands.QueryRepositoryRootPath(repo).ReadToEnd(); - if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut)) + if (!string.IsNullOrEmpty(repo) && Directory.Exists(repo)) { - Dispatcher.UIThread.Invoke(() => + var test = new Commands.QueryRepositoryRootPath(repo).ReadToEnd(); + if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut)) { - var node = ViewModels.Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), null, false); - ViewModels.Welcome.Instance.Refresh(); - _launcher?.OpenRepositoryInTab(node, null); - }); + Dispatcher.UIThread.Invoke(() => + { + var node = ViewModels.Preferences.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), null, false); + ViewModels.Welcome.Instance.Refresh(); + _launcher?.OpenRepositoryInTab(node, null); + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: Views.Launcher wnd }) + wnd.BringToTop(); + }); + + return; + } } + + Dispatcher.UIThread.Invoke(() => + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: Views.Launcher launcher }) + launcher.BringToTop(); + }); } private void Check4Update(bool manually = false) diff --git a/src/Models/IpcChannel.cs b/src/Models/IpcChannel.cs index e46b6242..5a2b0d61 100644 --- a/src/Models/IpcChannel.cs +++ b/src/Models/IpcChannel.cs @@ -46,14 +46,19 @@ namespace SourceGit.Models using (var client = new NamedPipeClientStream(".", "SourceGitIPCChannel", PipeDirection.Out)) { client.Connect(1000); - if (client.IsConnected) + if (!client.IsConnected) + return; + + using (var writer = new StreamWriter(client)) { - using (var writer = new StreamWriter(client)) - { - writer.WriteLine(cmd); - writer.Flush(); - } + writer.WriteLine(cmd); + writer.Flush(); } + + if (OperatingSystem.IsWindows()) + client.WaitForPipeDrain(); + else + Thread.Sleep(1000); } } catch @@ -78,13 +83,18 @@ namespace SourceGit.Models { await _server.WaitForConnectionAsync(_cancellationTokenSource.Token); - var line = (await reader.ReadLineAsync(_cancellationTokenSource.Token))?.Trim(); - MessageReceived?.Invoke(line); + if (!_cancellationTokenSource.IsCancellationRequested) + { + var line = await reader.ReadToEndAsync(_cancellationTokenSource.Token); + MessageReceived?.Invoke(line?.Trim()); + } + _server.Disconnect(); } catch { - // IGNORE + if (!_cancellationTokenSource.IsCancellationRequested && _server.IsConnected) + _server.Disconnect(); } } } diff --git a/src/ViewModels/Preferences.cs b/src/ViewModels/Preferences.cs index 9395e0a7..fb310e51 100644 --- a/src/ViewModels/Preferences.cs +++ b/src/ViewModels/Preferences.cs @@ -18,9 +18,8 @@ namespace SourceGit.ViewModels if (_instance != null) return _instance; - _isLoading = true; _instance = Load(); - _isLoading = false; + _instance._isLoading = false; _instance.PrepareGit(); _instance.PrepareShellOrTerminal(); @@ -629,8 +628,8 @@ namespace SourceGit.ViewModels } private static Preferences _instance = null; - private static bool _isLoading = false; + private bool _isLoading = true; private bool _isReadonly = true; private string _locale = "en_US"; private string _theme = "Default"; diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 9ccec78c..1e64785a 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -67,6 +67,14 @@ namespace SourceGit.Views InitializeComponent(); } + public void BringToTop() + { + if (WindowState == WindowState.Minimized) + WindowState = _lastWindowState; + else + Activate(); + } + public bool HasKeyModifier(KeyModifiers modifier) { return _unhandledModifiers.HasFlag(modifier); @@ -92,6 +100,8 @@ namespace SourceGit.Views if (change.Property == WindowStateProperty) { + _lastWindowState = (WindowState)change.OldValue; + var state = (WindowState)change.NewValue!; if (!OperatingSystem.IsMacOS() && !UseSystemWindowFrame) CaptionHeight = new GridLength(state == WindowState.Maximized ? 30 : 38); @@ -291,5 +301,6 @@ namespace SourceGit.Views } private KeyModifiers _unhandledModifiers = KeyModifiers.None; + private WindowState _lastWindowState = WindowState.Normal; } }