diff --git a/src/App.axaml.cs b/src/App.axaml.cs index b4f93e38..3cb3909c 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -302,6 +302,11 @@ namespace SourceGit }); } + public static ViewModels.Launcher GetLauncer() + { + return Current is App app ? app._launcher : null; + } + public static ViewModels.Repository FindOpenedRepository(string repoPath) { if (Current is App app && app._launcher != null) diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index 7f03e0fd..641fd544 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -3,6 +3,8 @@ using System.ComponentModel.DataAnnotations; using System.IO; using System.Threading.Tasks; +using Avalonia.Threading; + namespace SourceGit.ViewModels { public class Clone : Popup @@ -51,28 +53,25 @@ namespace SourceGit.ViewModels set => SetProperty(ref _extraArgs, value); } - public Clone(Launcher launcher) + public Clone() { - _launcher = launcher; - _page = launcher.ActivePage; - View = new Views.Clone() { DataContext = this }; - App.GetClipboardTextAsync() - .ContinueWith(t => + + Task.Run(async () => + { + try { - if (t.IsFaulted) + var text = await App.GetClipboardTextAsync(); + if (Models.Remote.IsValidURL(text)) { - t.Exception.Handle(static _ => true); + Dispatcher.UIThread.Invoke(() => Remote = text); } - else if (t.IsCompleted) - { - var result = t.Result; - if (Models.Remote.IsValidURL(result)) - { - Remote = result; - } - } - }); + } + catch + { + // ignore + } + }); } public static ValidationResult ValidateRemote(string remote, ValidationContext _) @@ -131,15 +130,24 @@ namespace SourceGit.ViewModels { var normalizedPath = path.Replace("\\", "/"); var node = Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, null, true); - _launcher.OpenRepositoryInTab(node, _page); + var launcher = App.GetLauncer(); + var page = null as LauncherPage; + foreach (var one in launcher.Pages) + { + if (one.GetId() == HostPageId) + { + page = one; + break; + } + } + + launcher.OpenRepositoryInTab(node, page); }); return true; }); } - private readonly Launcher _launcher = null; - private readonly LauncherPage _page = null; private string _remote = string.Empty; private bool _useSSH = false; private string _sshKey = string.Empty; diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index a1bc0a46..8d6c423e 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -1,9 +1,7 @@ using System; -using Avalonia; using Avalonia.Collections; using Avalonia.Controls; -using Avalonia.Controls.ApplicationLifetimes; using CommunityToolkit.Mvvm.ComponentModel; @@ -50,23 +48,16 @@ namespace SourceGit.ViewModels return; } - if (PopupHost.CanCreatePopup() && - Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { DataContext: Launcher launcher } }) - { - PopupHost.ShowPopup(new Clone(launcher)); - } + if (PopupHost.CanCreatePopup()) + PopupHost.ShowPopup(new Clone()); } public void OpenTerminal() { if (!Preference.Instance.IsGitConfigured()) - { App.RaiseException(PopupHost.Active.GetId(), App.Text("NotConfigured")); - } else - { Native.OS.OpenTerminal(null); - } } public void ClearSearchFilter() @@ -96,12 +87,7 @@ namespace SourceGit.ViewModels openAll.Icon = App.CreateMenuIcon("Icons.Folder.Open"); openAll.Click += (_, e) => { - if (PopupHost.CanCreatePopup() && - Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { DataContext: Launcher launcher } }) - { - OpenAllInNode(launcher, node); - } - + OpenAllInNode(App.GetLauncer(), node); e.Handled = true; }; diff --git a/src/Views/Blame.axaml b/src/Views/Blame.axaml index 9265b0d6..b7b23e82 100644 --- a/src/Views/Blame.axaml +++ b/src/Views/Blame.axaml @@ -9,7 +9,6 @@ x:DataType="vm:Blame" Icon="/App.ico" Title="{DynamicResource Text.Blame}" - WindowStartupLocation="CenterOwner" MinWidth="1280" MinHeight="720"> diff --git a/src/Views/Blame.axaml.cs b/src/Views/Blame.axaml.cs index a8f74b95..ba539d68 100644 --- a/src/Views/Blame.axaml.cs +++ b/src/Views/Blame.axaml.cs @@ -4,7 +4,6 @@ using System.Globalization; using Avalonia; using Avalonia.Controls; -using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Media; @@ -326,11 +325,6 @@ namespace SourceGit.Views { public Blame() { - if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) - { - Owner = desktop.MainWindow; - } - InitializeComponent(); }