Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复:窗口隐藏启动时会闪一下的问题 #6190

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v2rayN/ServiceLib/Enums/EViewAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum EViewAction
ShareSub,
ShareServer,
ShowHideWindow,
ShowInTaskbar,
ScanScreenTask,
ScanImageTask,
Shutdown,
Expand Down
10 changes: 1 addition & 9 deletions v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ private async Task Init()
}

await Reload();
await AutoHideStartup();
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
}

Expand Down Expand Up @@ -333,6 +332,7 @@ public async Task UpgradeApp(string arg)
public void ShowHideWindow(bool? blShow)
{
_updateView?.Invoke(EViewAction.ShowHideWindow, blShow);
_updateView?.Invoke(EViewAction.ShowInTaskbar, blShow);
}

#endregion Actions
Expand Down Expand Up @@ -588,14 +588,6 @@ public async Task CloseCore()
await CoreHandler.Instance.CoreStop();
}

private async Task AutoHideStartup()
{
if (_config.UiItem.AutoHideStartup)
{
ShowHideWindow(false);
}
}

#endregion core job

#region Presets
Expand Down
15 changes: 13 additions & 2 deletions v2rayN/v2rayN.Desktop/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Splat;
Expand Down Expand Up @@ -30,10 +31,20 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.Exit += OnExit;

// 先完成组件初始化
AppHandler.Instance.InitComponents();
var mainWindow = new MainWindow();
if (AppHandler.Instance.Config.UiItem.AutoHideStartup)
{
// 创建主窗口实例但暂不显示
mainWindow.ShowInTaskbar = false;
mainWindow.WindowState = WindowState.Minimized;
mainWindow.IsVisible = false;

desktop.Exit += OnExit;
desktop.MainWindow = new MainWindow();
}
desktop.MainWindow = mainWindow;
}

base.OnFrameworkInitializationCompleted();
Expand Down
11 changes: 11 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
DispatcherPriority.Default);
break;

case EViewAction.ShowInTaskbar:
Dispatcher.UIThread.Post(() =>
showInTaskbar((bool?)obj),
DispatcherPriority.Default);
break;
case EViewAction.DispatcherStatistics:
if (obj is null) return false;
Dispatcher.UIThread.Post(() =>
Expand Down Expand Up @@ -391,6 +396,12 @@ private async void MenuClose_Click(object? sender, RoutedEventArgs e)

#region UI

private void showInTaskbar(bool? blShow)
{
var bl = blShow ?? this.WindowState == WindowState.Normal;
this.ShowInTaskbar = bl;
}

public void ShowHideWindow(bool? blShow)
{
var bl = blShow ?? !_config.UiItem.ShowInTaskbar;
Expand Down