From 12dd32c168015d26bdf1060784a7e2f693213a3a Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 21:08:45 +0800 Subject: [PATCH 1/6] Test fix dependency injection installer issue --- Flow.Launcher/App.xaml.cs | 59 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 952ca70c458..5b139ba6916 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -30,37 +30,7 @@ public partial class App : IDisposable, ISingleInstanceApp public static IPublicAPI API { get; private set; } private const string Unique = "Flow.Launcher_Unique_Application_Mutex"; private static bool _disposed; - private readonly Settings _settings; - - public App() - { - // Initialize settings - var storage = new FlowLauncherJsonStorage(); - _settings = storage.Load(); - _settings.SetStorage(storage); - _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); - - // Configure the dependency injection container - var host = Host.CreateDefaultBuilder() - .UseContentRoot(AppContext.BaseDirectory) - .ConfigureServices(services => services - .AddSingleton(_ => _settings) - .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - ).Build(); - Ioc.Default.ConfigureServices(host.Services); - - // Initialize the public API and Settings first - API = Ioc.Default.GetRequiredService(); - _settings.Initialize(); - } + private Settings _settings; [STAThread] public static void Main() @@ -79,6 +49,33 @@ private async void OnStartupAsync(object sender, StartupEventArgs e) { await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => { + // Initialize settings + var storage = new FlowLauncherJsonStorage(); + _settings = storage.Load(); + _settings.SetStorage(storage); + _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); + + // Configure the dependency injection container + var host = Host.CreateDefaultBuilder() + .UseContentRoot(AppContext.BaseDirectory) + .ConfigureServices(services => services + .AddSingleton(_ => _settings) + .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + ).Build(); + Ioc.Default.ConfigureServices(host.Services); + + // Initialize the public API and Settings first + API = Ioc.Default.GetRequiredService(); + _settings.Initialize(); + Ioc.Default.GetRequiredService().PreStartCleanUpAfterPortabilityUpdate(); Log.Info("|App.OnStartup|Begin Flow Launcher startup ----------------------------------------------------"); From 0391e7e665b7375ecc7ccc30d930e1f919c11fe3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 21:20:47 +0800 Subject: [PATCH 2/6] Revert "Test fix dependency injection installer issue" This reverts commit 12dd32c168015d26bdf1060784a7e2f693213a3a. --- Flow.Launcher/App.xaml.cs | 59 ++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 5b139ba6916..952ca70c458 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -30,7 +30,37 @@ public partial class App : IDisposable, ISingleInstanceApp public static IPublicAPI API { get; private set; } private const string Unique = "Flow.Launcher_Unique_Application_Mutex"; private static bool _disposed; - private Settings _settings; + private readonly Settings _settings; + + public App() + { + // Initialize settings + var storage = new FlowLauncherJsonStorage(); + _settings = storage.Load(); + _settings.SetStorage(storage); + _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); + + // Configure the dependency injection container + var host = Host.CreateDefaultBuilder() + .UseContentRoot(AppContext.BaseDirectory) + .ConfigureServices(services => services + .AddSingleton(_ => _settings) + .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + ).Build(); + Ioc.Default.ConfigureServices(host.Services); + + // Initialize the public API and Settings first + API = Ioc.Default.GetRequiredService(); + _settings.Initialize(); + } [STAThread] public static void Main() @@ -49,33 +79,6 @@ private async void OnStartupAsync(object sender, StartupEventArgs e) { await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => { - // Initialize settings - var storage = new FlowLauncherJsonStorage(); - _settings = storage.Load(); - _settings.SetStorage(storage); - _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); - - // Configure the dependency injection container - var host = Host.CreateDefaultBuilder() - .UseContentRoot(AppContext.BaseDirectory) - .ConfigureServices(services => services - .AddSingleton(_ => _settings) - .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - ).Build(); - Ioc.Default.ConfigureServices(host.Services); - - // Initialize the public API and Settings first - API = Ioc.Default.GetRequiredService(); - _settings.Initialize(); - Ioc.Default.GetRequiredService().PreStartCleanUpAfterPortabilityUpdate(); Log.Info("|App.OnStartup|Begin Flow Launcher startup ----------------------------------------------------"); From 487ae56cf20561513efa4760494b2418e94f8c25 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 21:26:20 +0800 Subject: [PATCH 3/6] Test fix dependency injection installer issue 1 --- Flow.Launcher/App.xaml.cs | 58 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 952ca70c458..18cbfea0bc3 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -35,10 +36,36 @@ public partial class App : IDisposable, ISingleInstanceApp public App() { // Initialize settings + WriteToLogFile(1); var storage = new FlowLauncherJsonStorage(); - _settings = storage.Load(); - _settings.SetStorage(storage); - _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); + WriteToLogFile(2); + try + { + _settings = storage.Load(); + } + catch (Exception ex) + { + WriteToLogFile(ex.Message); + } + WriteToLogFile(3); + try + { + _settings.SetStorage(storage); + } + catch (Exception ex) + { + WriteToLogFile(ex.Message); + } + WriteToLogFile(4); + try + { + _settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); + } + catch (Exception ex) + { + WriteToLogFile(ex.Message); + } + WriteToLogFile(5); // Configure the dependency injection container var host = Host.CreateDefaultBuilder() @@ -55,30 +82,55 @@ public App() .AddSingleton() .AddSingleton() ).Build(); + WriteToLogFile(6); Ioc.Default.ConfigureServices(host.Services); + WriteToLogFile(7); // Initialize the public API and Settings first API = Ioc.Default.GetRequiredService(); + WriteToLogFile(8); _settings.Initialize(); + WriteToLogFile(9); + } + + private static void WriteToLogFile(string message) + { + // d:\LOG.TXT + using var sw = new StreamWriter("d:\\LOG.TXT", true); + sw.WriteLine($" {message} "); + } + + private static void WriteToLogFile(int message) + { + // d:\LOG.TXT + using var sw = new StreamWriter("d:\\LOG.TXT", true); + sw.WriteLine($" {message} "); } [STAThread] public static void Main() { + WriteToLogFile("A"); if (SingleInstance.InitializeAsFirstInstance(Unique)) { + WriteToLogFile("B"); using (var application = new App()) { + WriteToLogFile("C"); application.InitializeComponent(); + WriteToLogFile("D"); application.Run(); + WriteToLogFile("E"); } } } private async void OnStartupAsync(object sender, StartupEventArgs e) { + WriteToLogFile(10); await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => { + WriteToLogFile(11); Ioc.Default.GetRequiredService().PreStartCleanUpAfterPortabilityUpdate(); Log.Info("|App.OnStartup|Begin Flow Launcher startup ----------------------------------------------------"); From 3ad62abbc5617c6ab08a3dee332e80bb92c33743 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 21:45:55 +0800 Subject: [PATCH 4/6] Test fix dependency injection installer issue 2 --- Flow.Launcher/App.xaml.cs | 46 ++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 18cbfea0bc3..b6c937a2a90 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -32,6 +32,7 @@ public partial class App : IDisposable, ISingleInstanceApp private const string Unique = "Flow.Launcher_Unique_Application_Mutex"; private static bool _disposed; private readonly Settings _settings; + private readonly IHost _host; public App() { @@ -68,22 +69,37 @@ public App() WriteToLogFile(5); // Configure the dependency injection container - var host = Host.CreateDefaultBuilder() - .UseContentRoot(AppContext.BaseDirectory) - .ConfigureServices(services => services - .AddSingleton(_ => _settings) - .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - ).Build(); + try + { + WriteToLogFile($"AppContext.BaseDirectory: {AppContext.BaseDirectory}"); + _host = Host.CreateDefaultBuilder() + .UseContentRoot(AppContext.BaseDirectory) + .ConfigureServices(services => services + .AddSingleton(_ => _settings) + .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + ).Build(); + } + catch (Exception ex) + { + WriteToLogFile(ex.Message); + } WriteToLogFile(6); - Ioc.Default.ConfigureServices(host.Services); + try + { + Ioc.Default.ConfigureServices(_host.Services); + } + catch (Exception ex) + { + WriteToLogFile(ex.Message); + } WriteToLogFile(7); // Initialize the public API and Settings first From babfe5cb794ab0a81be4c6c425877596ce12009c Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 22:04:58 +0800 Subject: [PATCH 5/6] Test fix dependency injection installer issue 3 --- Flow.Launcher/App.xaml.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index b6c937a2a90..5f6018e7186 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -22,6 +22,7 @@ using Flow.Launcher.ViewModel; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch; namespace Flow.Launcher @@ -74,6 +75,12 @@ public App() WriteToLogFile($"AppContext.BaseDirectory: {AppContext.BaseDirectory}"); _host = Host.CreateDefaultBuilder() .UseContentRoot(AppContext.BaseDirectory) + .ConfigureLogging(logging => + { + // Clear default logging providers + // Fix issue EventLog access is not supported on this platform. + logging.ClearProviders(); + }) .ConfigureServices(services => services .AddSingleton(_ => _settings) .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) From e7e13a0691c597c8fd5d214e6b6f48685ed5237e Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 24 Feb 2025 22:07:26 +0800 Subject: [PATCH 6/6] Test fix dependency injection installer issue 4 --- Flow.Launcher/App.xaml.cs | 6 ------ Flow.Launcher/Flow.Launcher.csproj | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 5f6018e7186..b64c24784d0 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -75,12 +75,6 @@ public App() WriteToLogFile($"AppContext.BaseDirectory: {AppContext.BaseDirectory}"); _host = Host.CreateDefaultBuilder() .UseContentRoot(AppContext.BaseDirectory) - .ConfigureLogging(logging => - { - // Clear default logging providers - // Fix issue EventLog access is not supported on this platform. - logging.ClearProviders(); - }) .ConfigureServices(services => services .AddSingleton(_ => _settings) .AddSingleton(sp => new Updater(sp.GetRequiredService(), Launcher.Properties.Settings.Default.GithubRepo)) diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj index 43c1dfd9007..d760787bcf2 100644 --- a/Flow.Launcher/Flow.Launcher.csproj +++ b/Flow.Launcher/Flow.Launcher.csproj @@ -90,8 +90,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all