enhance: bring window into view after receive IPC message

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-15 10:19:57 +08:00
parent e2da44c8fd
commit c4c04b8b01
No known key found for this signature in database
4 changed files with 53 additions and 22 deletions

View file

@ -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)

View file

@ -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();
}
}
}

View file

@ -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";

View file

@ -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;
}
}