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

Feature: Added an out-of-proc WinRT server for long-running background tasks #14335

Merged
merged 10 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ jobs:
- name: Setup NuGet
uses: NuGet/[email protected]

- name: Setup .NET 7
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

- name: Restore NuGet
shell: pwsh
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
- name: Setup NuGet
uses: NuGet/[email protected]

- name: Setup .NET 7
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

# TODO: Move the command to PowerShell script instead
- name: Update Package.appxmanifest
Expand Down
78 changes: 60 additions & 18 deletions Files.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Files.App.Launcher", "src\Files.App.Launcher\Files.App.Launcher.vcxproj", "{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App", "src\Files.App\Files.App.csproj", "{6F431D82-A5FF-4833-B5E4-702E1E523126}"
ProjectSection(ProjectDependencies) = postProject
{1EE996D6-885E-4403-A461-26C7A4E14D26} = {1EE996D6-885E-4403-A461-26C7A4E14D26}
EndProjectSection
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Files.Package", "src\Files.App (Package)\Files.Package.wapproj", "{8F60FD8E-1921-47D6-97B0-D26D7B3A4999}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.Core.SourceGenerator", "src\Files.Core.SourceGenerator\Files.Core.SourceGenerator.csproj", "{6FA07816-DE0A-4D49-84E8-38E953A33C87}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App.Server", "src\Files.App.Server\Files.App.Server.csproj", "{1EE996D6-885E-4403-A461-26C7A4E14D26}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Expand Down Expand Up @@ -378,30 +383,66 @@ Global
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x86.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x86.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|arm64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|arm64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x86.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x86.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.Build.0 = Release|Any CPU
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.ActiveCfg = Debug|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.Build.0 = Debug|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.Deploy.0 = Debug|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x64.ActiveCfg = Debug|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x64.Build.0 = Debug|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x64.Deploy.0 = Debug|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x86.ActiveCfg = Debug|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x86.Build.0 = Debug|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|x86.Deploy.0 = Debug|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|arm64.ActiveCfg = Preview|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|arm64.Build.0 = Preview|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x64.ActiveCfg = Preview|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x64.Build.0 = Preview|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x86.ActiveCfg = Preview|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Preview|x86.Build.0 = Preview|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|arm64.ActiveCfg = Release|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|arm64.Build.0 = Release|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|arm64.Deploy.0 = Release|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x64.ActiveCfg = Release|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x64.Build.0 = Release|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x64.Deploy.0 = Release|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x86.ActiveCfg = Release|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x86.Build.0 = Release|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Release|x86.Deploy.0 = Release|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|arm64.ActiveCfg = Stable|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|arm64.Build.0 = Stable|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x64.ActiveCfg = Stable|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x64.Build.0 = Stable|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x86.ActiveCfg = Stable|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Stable|x86.Build.0 = Stable|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|arm64.ActiveCfg = Store|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|arm64.Build.0 = Store|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x64.ActiveCfg = Store|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x64.Build.0 = Store|x64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x86.ActiveCfg = Store|x86
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Store|x86.Build.0 = Store|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -420,6 +461,7 @@ Global
{6F431D82-A5FF-4833-B5E4-702E1E523126} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{8F60FD8E-1921-47D6-97B0-D26D7B3A4999} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{6FA07816-DE0A-4D49-84E8-38E953A33C87} = {9F36C2AD-005D-4EA5-A1F1-6BC42773FC85}
{1EE996D6-885E-4403-A461-26C7A4E14D26} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0E62043C-A7A1-4982-9EC9-4CDB2939B776}
Expand Down
8 changes: 4 additions & 4 deletions builds/azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ jobs:
- task: UseDotNet@2
inputs:
packageType: sdk
version: 7.0.x
includePreviewVersions: true
version: 8.0.x
includePreviewVersions: false

- task: CmdLine@2
inputs:
Expand Down Expand Up @@ -240,8 +240,8 @@ jobs:
- task: UseDotNet@2
inputs:
packageType: sdk
version: 7.0.x
includePreviewVersions: true
version: 8.0.x
includePreviewVersions: false

- task: CmdLine@2
inputs:
Expand Down
13 changes: 11 additions & 2 deletions src/Files.App (Package)/Files.Package.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ProjectGuid>8f60fd8e-1921-47d6-97b0-d26d7b3a4999</ProjectGuid>
<TargetPlatformVersion>10.0.22621.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<AssetTargetFallback>net7.0-windows$(TargetPlatformVersion);$(AssetTargetFallback)</AssetTargetFallback>
<AssetTargetFallback>net8.0-windows$(TargetPlatformVersion);$(AssetTargetFallback)</AssetTargetFallback>
<DefaultLanguage>en-US</DefaultLanguage>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
Expand Down Expand Up @@ -98,14 +98,23 @@
<Content Include="Package.appinstaller" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Files.App.Server\Files.App.Server.csproj">
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
<PublishProfile>Properties\PublishProfiles\win-$(Platform).pubxml</PublishProfile>
</ProjectReference>
<ProjectReference Include="..\Files.App\Files.App.csproj">
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
<PublishProfile>Properties\PublishProfiles\win-$(Platform).pubxml</PublishProfile>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231115000" IncludeAssets="build" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" IncludeAssets="build" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
<Target Name="RemoveOutOfProcWinMD" BeforeTargets="_GenerateCurrentProjectAppxManifest">
<ItemGroup>
<_AppxWinmdFilesToHarvest Condition="'%(FileName)' == 'Files.App.Server'" Remove="@(_AppxWinmdFilesToHarvest)" />
</ItemGroup>
</Target>
</Project>
7 changes: 7 additions & 0 deletions src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@
<ActivatableClass ActivatableClassId="Files.App.BackgroundTasks.UpdateTask" ThreadingModel="both" />
</InProcessServer>
</Extension>
<Extension Category="windows.activatableClass.outOfProcessServer">
<OutOfProcessServer ServerName="Files.App.Server" uap5:IdentityType="activateAsPackage" uap5:RunFullTrust="true">
<Path>Files.App.Server\Files.App.Server.exe</Path>
<Instancing>singleInstance</Instancing>
<ActivatableClass ActivatableClassId="Files.App.Server.GreetingService" />
</OutOfProcessServer>
</Extension>
</Extensions>

<Capabilities>
Expand Down
12 changes: 10 additions & 2 deletions src/Files.App.BackgroundTasks/Files.App.BackgroundTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<IsTrimmable>true</IsTrimmable>
<Configurations>Debug;Release;Stable;Preview;Store</Configurations>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -17,6 +17,14 @@
<CsWinRTGeneratedFilesDir>$(MSBuildProjectDirectory)\bin\$(Platform)\$(Configuration)</CsWinRTGeneratedFilesDir>
</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>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" />
</ItemGroup>
Expand Down
52 changes: 52 additions & 0 deletions src/Files.App.Server/Files.App.Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<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">
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>Files.App.Server.winmd</Link>
</None>
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions src/Files.App.Server/GreetingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Windows.UI.Notifications;

namespace Files.App.Server;

public sealed class GreetingService
{
public static void ShowGreet()
{
var doc = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);
doc.SelectSingleNode("""//text[@id="1"]""").InnerText = "Welcome to Files!";
doc.SelectSingleNode("""//text[@id="2"]""").InnerText = "This is a toast notification sent from Files.App.Server";
ToastNotificationManager.CreateToastNotifier("App").Show(new ToastNotification(doc));
}
}
39 changes: 39 additions & 0 deletions src/Files.App.Server/Helpers.cs
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);
}
}
}
28 changes: 28 additions & 0 deletions src/Files.App.Server/NativeMethods.json
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
}
9 changes: 9 additions & 0 deletions src/Files.App.Server/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

RoRegisterActivationFactories
RoRevokeActivationFactories
WindowsCreateString
WindowsDeleteString
RoInitialize
RoUninitialize
Loading