-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Feature: Added an out-of-proc WinRT server for long-running background tasks #14335
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
36c6aaa
Upgrade to .NET 8
hez2010 e29c50f
Add an out-of-proc WinRT server
hez2010 2b37c05
Enable R2R and trimming for server
hez2010 3d10801
Referenced assembiles fixes
hez2010 65e9db4
Remove _AppxWinmdFilesToHarvest
hez2010 82e2c86
Process Files.App.Server only in RemoveOutOfProcWinMD
hez2010 fdd35fa
Use new sdk in CI
hez2010 a4bafd1
Hide winmd from UI
hez2010 58aa1b7
Microsoft.UI.Content.Private -> Microsoft.UI.Content
hez2010 69a9a1e
Exit the server automatically if no instance exists, replace the samp…
hez2010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Files.App.Server; | ||
|
||
public sealed class AppInstanceMonitor | ||
{ | ||
private static int processCount = 0; | ||
|
||
public static void StartMonitor(int processId) | ||
{ | ||
var process = Process.GetProcessById(processId); | ||
Interlocked.Increment(ref processCount); | ||
process.EnableRaisingEvents = true; | ||
process.Exited += Process_Exited; | ||
} | ||
|
||
private static void Process_Exited(object? sender, EventArgs e) | ||
{ | ||
if (sender is Process process) | ||
{ | ||
process.Dispose(); | ||
|
||
if (Interlocked.Decrement(ref processCount) == 0) | ||
{ | ||
Program.ExitSignalEvent.Set(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<DefaultLanguage>en-US</DefaultLanguage> | ||
<AppxBundleAutoResourcePackageQualifiers>Scale|DXFeatureLevel</AppxBundleAutoResourcePackageQualifiers> | ||
<AppxDefaultResourceQualifiers>Language=en-US;af;ar;bg;ca;cs-CZ;da;da-DK;de-DE;el;en-GB;es-ES;es-419;fa-IR;fi-FI;fil-PH;fr-FR;he-IL;hi-IN;hu-HU;id-ID;it-IT;ja-JP;ka;ko-KR;lt;lv-LV;nb-NO;nl-NL;or-IN;pl-PL;pt-BR;pt-PT;ro-RO;ru-RU;sk-SK;sv-SE;ta;th-TH;tr-TR;uk-UA;vi;zh-Hans;zh-Hant</AppxDefaultResourceQualifiers> | ||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework> | ||
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Configurations>Debug;Release;Stable;Preview;Store</Configurations> | ||
<Platforms>x86;x64;arm64</Platforms> | ||
<SelfContained>true</SelfContained> | ||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers> | ||
<RuntimeIdentifier Condition="'$(Platform)' == 'x86'">win-x86</RuntimeIdentifier> | ||
<RuntimeIdentifier Condition="'$(Platform)' == 'x64'">win-x64</RuntimeIdentifier> | ||
<RuntimeIdentifier Condition="'$(Platform)' == 'arm64'">win-arm64</RuntimeIdentifier> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<CsWinRTComponent>true</CsWinRTComponent> | ||
<CsWinRTWindowsMetadata>10.0.22621.0</CsWinRTWindowsMetadata> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun> | ||
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun> | ||
<PublishReadyToRunComposite Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRunComposite> | ||
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed> | ||
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<DefineConstants>TRACE;DEBUG;NETFX_CORE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)' != 'Debug'"> | ||
<DefineConstants>TRACE;RELEASE;NETFX_CORE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Manifest Include="app.manifest" /> | ||
<TrimmerRootAssembly Include="Files.App.Server" /> | ||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" /> | ||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.647-beta" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\Files.App.Server\bin\$(Platform)\$(Configuration)\$(TargetFramework)\win-$(Platform)\Files.App.Server.winmd"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<Link>Files.App.Server.winmd</Link> | ||
<Visible>false</Visible> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Files.Shared\Files.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using WinRT; | ||
|
||
namespace Files.App.Server; | ||
|
||
unsafe partial class Helpers | ||
{ | ||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])] | ||
public static int GetActivationFactory(void* activatableClassId, void** factory) | ||
{ | ||
const int E_INVALIDARG = unchecked((int)0x80070057); | ||
const int CLASS_E_CLASSNOTAVAILABLE = unchecked((int)0x80040111); | ||
const int S_OK = 0; | ||
|
||
if (activatableClassId is null || factory is null) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
try | ||
{ | ||
IntPtr obj = Module.GetActivationFactory(MarshalString.FromAbi((IntPtr)activatableClassId)); | ||
|
||
if ((void*)obj is null) | ||
{ | ||
return CLASS_E_CLASSNOTAVAILABLE; | ||
} | ||
|
||
*factory = (void*)obj; | ||
return S_OK; | ||
} | ||
catch (Exception e) | ||
{ | ||
ExceptionHelpers.SetErrorInfo(e); | ||
return ExceptionHelpers.GetHRForException(e); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
{ | ||
"$schema": "https://aka.ms/CsWin32.schema.json", | ||
|
||
// Emit COM interfaces instead of structs, and allow generation of non-blittable structs for the sake of an easier to use API. | ||
"allowMarshaling": true, | ||
|
||
// A value indicating whether to generate APIs judged to be unnecessary or redundant given the target framework. | ||
// This is useful for multi-targeting projects that need a consistent set of APIs across target frameworks | ||
// to avoid too many conditional compilation regions. | ||
"multiTargetingFriendlyAPIs": false, | ||
|
||
// A value indicating whether friendly overloads should use safe handles. | ||
"useSafeHandles": true, | ||
|
||
// Omit ANSI functions and remove `W` suffix from UTF-16 functions. | ||
"wideCharOnly": true, | ||
|
||
// A value indicating whether to emit a single source file as opposed to types spread across many files. | ||
"emitSingleFile": false, | ||
|
||
// The name of a single class under which all p/invoke methods and constants are generated, regardless of imported module. | ||
"className": "PInvoke", | ||
|
||
// A value indicating whether to expose the generated APIs publicly (as opposed to internally). | ||
"public": true | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.