diff --git a/src/ST.Client.Desktop.Linux/ServiceCollectionExtensions.cs b/src/ST.Client.Desktop.Linux/ServiceCollectionExtensions.cs index ce4f262dc..a3104d97d 100644 --- a/src/ST.Client.Desktop.Linux/ServiceCollectionExtensions.cs +++ b/src/ST.Client.Desktop.Linux/ServiceCollectionExtensions.cs @@ -9,7 +9,7 @@ namespace Microsoft.Extensions.DependencyInjection { public static partial class ServiceCollectionExtensions { - public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services, bool hasSteam, bool hasGUI) + public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services, bool hasSteam, bool hasGUI, bool hasNotifyIcon) { if (OperatingSystem2.IsLinux) { @@ -17,7 +17,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddSingleton(); services.AddSingleton(s => s.GetRequiredService()); services.AddSingleton(s => s.GetRequiredService()); - services.AddNotifyIcon(); + if (hasNotifyIcon) services.AddNotifyIcon(); } else { diff --git a/src/ST.Client.Desktop.Mac/ServiceCollectionExtensions.cs b/src/ST.Client.Desktop.Mac/ServiceCollectionExtensions.cs index 17d1b6774..0c5c78da5 100644 --- a/src/ST.Client.Desktop.Mac/ServiceCollectionExtensions.cs +++ b/src/ST.Client.Desktop.Mac/ServiceCollectionExtensions.cs @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.DependencyInjection { public static partial class ServiceCollectionExtensions { - public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services, bool hasSteam, bool hasGUI) + public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services, bool hasSteam, bool hasGUI, bool hasNotifyIcon) { if (OperatingSystem2.IsMacOS) { @@ -21,7 +21,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddSingleton(s => s.GetRequiredService()); services.AddSingleton(s => s.GetRequiredService()); services.AddSingleton(); - services.AddNotifyIcon(); + if (hasNotifyIcon) services.AddNotifyIcon(); } else { diff --git a/src/ST.Client.Desktop.Windows/ServiceCollectionExtensions.cs b/src/ST.Client.Desktop.Windows/ServiceCollectionExtensions.cs index aba1a14ab..2e1dea85e 100644 --- a/src/ST.Client.Desktop.Windows/ServiceCollectionExtensions.cs +++ b/src/ST.Client.Desktop.Windows/ServiceCollectionExtensions.cs @@ -10,14 +10,7 @@ namespace Microsoft.Extensions.DependencyInjection { public static partial class ServiceCollectionExtensions { - /// - /// 添加桌面平台服务 - /// - /// - /// - /// - /// - public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services, bool hasSteam, bool hasGUI) + public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services, bool hasSteam, bool hasGUI, bool hasNotifyIcon) { if (OperatingSystem2.IsWindows) { @@ -43,7 +36,7 @@ namespace Microsoft.Extensions.DependencyInjection } services.AddSingleton(); services.AddSingleton(); - services.AddNotifyIcon(); + if (hasNotifyIcon) services.AddNotifyIcon(); } else { diff --git a/src/ST.Client.Desktop/UI/Views/INotifyIconWindow.cs b/src/ST.Client.Desktop/UI/Views/INotifyIconWindow.cs deleted file mode 100644 index 78f1d73a4..000000000 --- a/src/ST.Client.Desktop/UI/Views/INotifyIconWindow.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace System.Application.UI.Views -{ - public interface INotifyIconWindow - { - IntPtr Handle { get; } - } - - public interface INotifyIconWindow : INotifyIconWindow - { - void Initialize(INotifyIcon notifyIcon); - } -} \ No newline at end of file diff --git a/src/Startup2.cs b/src/Startup2.cs index a8b8f654c..aaf07e1a6 100644 --- a/src/Startup2.cs +++ b/src/Startup2.cs @@ -140,7 +140,7 @@ namespace System.Application var hasSteam = level.HasFlag(DILevel.Steam); #if !UI_DEMO && !__MOBILE__ // 桌面平台服务 此项放在其他通用业务实现服务之前 - services.AddDesktopPlatformService(hasSteam, hasGUI); + services.AddDesktopPlatformService(hasSteam, hasGUI, HasNotifyIcon); #endif #if __MOBILE__ services.AddMobilePlatformService(hasGUI); @@ -353,21 +353,6 @@ namespace System.Application StartupTrace.Restart("DI.ConfigureDemandServices.Steam"); #endif } -#if !CONSOLEAPP - if (HasNotifyIcon) - { - // 托盘图标 -#if WINDOWS - //services.AddTransient, Win32NotifyIconWindow>(); -#endif -#if !UI_DEMO - services.AddNotifyIcon(); -#endif -#if StartupTrace - StartupTrace.Restart("DI.ConfigureDemandServices.NotifyIcon"); -#endif - } -#endif #endif #if !CONSOLEAPP if (hasMainProcessRequired) @@ -426,24 +411,24 @@ namespace System.Application } static void SetApiBaseUrl(AppSettings s) { -//#if DEBUG -// if (BuildConfig.IsAigioPC && Program.IsMainProcess) -// { -// try -// { -// var url = CSConst.Prefix_HTTPS + "localhost:5001"; -// var request = WebRequest.CreateHttp(url); -// request.Timeout = 1888; -// request.GetResponse(); -// s.ApiBaseUrl = url; -// return; -// } -// catch (Exception e) -// { -// Debug.WriteLine(e.ToString()); -// } -// } -//#endif + //#if DEBUG + // if (BuildConfig.IsAigioPC && Program.IsMainProcess) + // { + // try + // { + // var url = CSConst.Prefix_HTTPS + "localhost:5001"; + // var request = WebRequest.CreateHttp(url); + // request.Timeout = 1888; + // request.GetResponse(); + // s.ApiBaseUrl = url; + // return; + // } + // catch (Exception e) + // { + // Debug.WriteLine(e.ToString()); + // } + // } + //#endif var value = (_ThisAssembly.Debuggable || !s.GetIsOfficialChannelPackage()) ? CSConst.Prefix_HTTPS + "pan.mossimo.net:8862" : @@ -458,111 +443,6 @@ namespace System.Application #if !__MOBILE__ && !CONSOLEAPP public static bool HasNotifyIcon { get; private set; } - -#if !UI_DEMO && !CONSOLEAPP - sealed class NotifyIconImpl : NotifyIcon, INotifyIcon { } -#endif - -#if WINDOWS && !CONSOLEAPP - //sealed class Win32NotifyIconWindow : MainWindow, INotifyIconWindow - //{ - // sealed class Win32WindowImpl : Avalonia.Win32.WindowImpl - // { - // public Win32NotifyIconWindow? Window { get; set; } - - // protected override IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) - // { - // var _notifyIcon = Window?.NotifyIcon; - // var value = _notifyIcon == null ? null : NotifyIcon.WndProc(_notifyIcon, msg, wParam, lParam); - // return value ?? base.WndProc(hWnd, msg, wParam, lParam); - // } - // } - - // public Win32NotifyIconWindow() : base(new Win32WindowImpl()) - // { - // if (PlatformImpl is Win32WindowImpl impl) - // { - // impl.Window = this; - // } - // else - // { - // throw new PlatformNotSupportedException(); - // } - // } - - // public IntPtr Handle => PlatformImpl.Handle.Handle; - - // [NotNull, DisallowNull] // C# 8 not null - // public NotifyIcon? NotifyIcon { get; private set; } - - // public void Initialize(INotifyIcon notifyIcon) - // { - // if (notifyIcon is NotifyIcon _notifyIcon) - // { - // NotifyIcon = _notifyIcon; - // } - // else - // { - // throw new PlatformNotSupportedException(); - // } - // //Content = NotifyIcon; - // } - //} - - // sealed class WPFMessageBoxCompatService : IMessageBoxCompatService - // { - // static MessageBoxButton GetButtonEnum(MessageBoxButtonCompat button) => button switch - // { - // MessageBoxButtonCompat.OK => MessageBoxButton.OK, - // MessageBoxButtonCompat.OKCancel => MessageBoxButton.OKCancel, - //#pragma warning disable CS0618 // 类型或成员已过时 - // MessageBoxButtonCompat.YesNo => MessageBoxButton.YesNo, - // MessageBoxButtonCompat.YesNoCancel => MessageBoxButton.YesNoCancel, - //#pragma warning restore CS0618 // 类型或成员已过时 - // _ => throw new ArgumentOutOfRangeException(nameof(button), $"value: {button}"), - // }; - - // static MessageBoxImage GetIcon(MessageBoxImageCompat icon) => icon switch - // { - // MessageBoxImageCompat.Asterisk => MessageBoxImage.Asterisk, - // MessageBoxImageCompat.Error => MessageBoxImage.Error, - // MessageBoxImageCompat.Exclamation => MessageBoxImage.Exclamation, - // MessageBoxImageCompat.None => MessageBoxImage.None, - //#pragma warning disable CS0618 // 类型或成员已过时 - // MessageBoxImageCompat.Question => MessageBoxImage.Question, - //#pragma warning restore CS0618 // 类型或成员已过时 - // _ => throw new ArgumentOutOfRangeException(nameof(icon), $"value: {icon}"), - // }; - - // static MessageBoxResultCompat GetResult(MessageBoxResult result) => result switch - // { - // MessageBoxResult.OK => MessageBoxResultCompat.OK, - //#pragma warning disable CS0618 // 类型或成员已过时 - // MessageBoxResult.Yes => MessageBoxResultCompat.Yes, - // MessageBoxResult.No => MessageBoxResultCompat.No, - //#pragma warning restore CS0618 // 类型或成员已过时 - // MessageBoxResult.Cancel => MessageBoxResultCompat.Cancel, - // MessageBoxResult.None => MessageBoxResultCompat.None, - // _ => throw new ArgumentOutOfRangeException(nameof(result), $"value: {result}"), - // }; - - // public Task ShowAsync(string messageBoxText, string caption, MessageBoxButtonCompat button, MessageBoxImageCompat? icon) - // { - // var button_ = GetButtonEnum(button); - // if (icon.HasValue) - // { - // var icon_ = GetIcon(icon.Value); - // var result = MessageBox.Show(messageBoxText, caption, button_, icon_); - // return Task.FromResult(GetResult(result)); - // } - // else - // { - // var result = MessageBox.Show(messageBoxText, caption, button_); - // return Task.FromResult(GetResult(result)); - // } - // } - // } -#endif #endif #if UI_DEMO