Cut over the window to Explorer.Host.exe so only the host writes the index.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Explorer.Hosting;
|
||||
using Explorer.Hosting.Ipc;
|
||||
using Explorer.Presentation.ViewModels;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -10,6 +12,7 @@ namespace Explorer.App;
|
||||
public partial class App : System.Windows.Application
|
||||
{
|
||||
private IHost? _host;
|
||||
private WorkbenchPipeClient? _workbenchClient;
|
||||
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
@@ -29,9 +32,35 @@ public partial class App : System.Windows.Application
|
||||
retainedFileCountLimit: 14)
|
||||
.CreateLogger();
|
||||
|
||||
_workbenchClient = await WorkbenchHostConnector.ConnectOrStartAsync(
|
||||
TimeSpan.FromSeconds(12),
|
||||
logger: null).ConfigureAwait(true);
|
||||
var hostExe = HostLogonAutostart.FindHostExecutable();
|
||||
if (_workbenchClient is null && hostExe is not null)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Explorer.Host.exe is present but the window could not connect to it. See logs.",
|
||||
"Explorer Workbench",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
Shutdown(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
_host = Host.CreateDefaultBuilder()
|
||||
.UseSerilog()
|
||||
.ConfigureServices((_, services) => services.AddExplorer())
|
||||
.ConfigureServices((_, services) =>
|
||||
{
|
||||
if (_workbenchClient is not null)
|
||||
{
|
||||
services.AddExplorerClient(_workbenchClient);
|
||||
services.AddExplorerUi();
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddExplorer();
|
||||
}
|
||||
})
|
||||
.Build();
|
||||
|
||||
var vm = _host.Services.GetRequiredService<MainViewModel>();
|
||||
@@ -60,6 +89,11 @@ public partial class App : System.Windows.Application
|
||||
_host.Dispose();
|
||||
}
|
||||
|
||||
if (_workbenchClient is not null)
|
||||
{
|
||||
await _workbenchClient.DisposeAsync().ConfigureAwait(true);
|
||||
}
|
||||
|
||||
Log.CloseAndFlush();
|
||||
base.OnExit(e);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
<CheckBox x:Name="BackgroundHostAtLogon" Margin="0,0,0,6"
|
||||
Content="Start Explorer.Host.exe at Windows sign-in"/>
|
||||
<TextBlock TextWrapping="Wrap" Foreground="{DynamicResource FgMuted}" Margin="24,0,0,18" FontSize="12"
|
||||
Text="Registers a per-user logon task. The window still owns indexing in this version. If the host starts while this window is open, it exits because the index is already in use."/>
|
||||
Text="Registers a per-user logon task. The window connects to Explorer.Host.exe for indexing and the queue. If the host is not running, the window starts it. Only the host opens the index for write."/>
|
||||
|
||||
<TextBlock Text="7-Zip" FontSize="16" FontWeight="SemiBold" Margin="0,8,0,10"/>
|
||||
<TextBlock TextWrapping="Wrap" Foreground="{DynamicResource FgMuted}" Margin="0,0,0,8" FontSize="12"
|
||||
|
||||
Reference in New Issue
Block a user