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

Add changes #299

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "pch.h"
#include "CountingWidgetImpl.h"
#include <iostream>

CountingWidget::CountingWidget(winrt::hstring const& id, winrt::hstring const& state) : WidgetImplBase(id, state)
{
Expand Down Expand Up @@ -77,6 +78,11 @@ void CountingWidget::Deactivate()
m_isActivated = false;
}

void CountingWidget::OnCustomizationRequested(winrt::WidgetCustomizationRequestedArgs args)
{
std::wcout << args.CustomState().c_str() << std::endl;
}

winrt::hstring CountingWidget::GetDefaultTemplate()
{
auto uri = winrt::Uri(L"ms-appx:///Templates/CountingWidgetTemplate.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CountingWidget : public WidgetImplBase
void OnWidgetContextChanged(winrt::WidgetContextChangedArgs contextChangedArgs);
void Activate();
void Deactivate();
void OnCustomizationRequested(winrt::WidgetCustomizationRequestedArgs args);
winrt::hstring GetTemplateForWidget();
winrt::hstring GetDataForWidget();
private:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.props" Condition="Exists('..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.props')" />
<PropertyGroup>
<!-- When building centrally, this will define a single nuget package location for all samples -->
<NugetPackageDirectory Condition="'$(NugetPackageDirectory)'==''">..\packages</NugetPackageDirectory>
Expand Down Expand Up @@ -141,7 +142,7 @@
<Import Project="$(NugetPackageDirectory)\Microsoft.Windows.CppWinRT.2.0.221104.6\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(NugetPackageDirectory)\Microsoft.Windows.CppWinRT.2.0.221104.6\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="$(NugetPackageDirectory)\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(NugetPackageDirectory)\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="$(NugetPackageDirectory)\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('$(NugetPackageDirectory)\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets')" />
<Import Project="$(NugetPackageDirectory)\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('$(NugetPackageDirectory)\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets')" />
<Import Project="..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand All @@ -152,7 +153,7 @@
<Error Condition="!Exists('$(NugetPackageDirectory)\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NugetPackageDirectory)\Microsoft.Windows.ImplementationLibrary.1.0.220914.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('$(NugetPackageDirectory)\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '$(NugetPackageDirectory)\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.props'))" />
<Error Condition="!Exists('$(NugetPackageDirectory)\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NugetPackageDirectory)\Microsoft.Windows.SDK.BuildTools.10.0.22621.755\build\Microsoft.Windows.SDK.BuildTools.targets'))" />
<Error Condition="!Exists('$(NugetPackageDirectory)\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '$(NugetPackageDirectory)\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.props'))" />
<Error Condition="!Exists('$(NugetPackageDirectory)\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NugetPackageDirectory)\Microsoft.WindowsAppSDK.1.3.230331000\build\native\Microsoft.WindowsAppSDK.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.WindowsAppSDK.1.4.20230612-1948-Dev\build\native\Microsoft.WindowsAppSDK.targets'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
<UniqueIdentifier>{6631e18a-745d-4d25-bfb5-a8c377b47a07}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natvis" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ void WeatherWidget::Deactivate()
m_isActivated = false;
}

void WeatherWidget::OnCustomizationRequested(winrt::WidgetCustomizationRequestedArgs args)
{
}

winrt::hstring WeatherWidget::GetDefaultTemplate()
{
auto uri = winrt::Uri(L"ms-appx:///Templates/WeatherWidgetTemplate.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class WeatherWidget : public WidgetImplBase
void OnWidgetContextChanged(winrt::WidgetContextChangedArgs contextChangedArgs);
void Activate();
void Deactivate();
void OnCustomizationRequested(winrt::WidgetCustomizationRequestedArgs args);
winrt::hstring GetTemplateForWidget();
winrt::hstring GetDataForWidget();
private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class WidgetImplBase
virtual void Deactivate(winrt::hstring) {};
virtual void OnActionInvoked(winrt::WidgetActionInvokedArgs actionInvokedArgs) {};
virtual void OnWidgetContextChanged(winrt::WidgetContextChangedArgs contextChangedArgs) {};

virtual void OnCustomizationRequested(winrt::WidgetCustomizationRequestedArgs args) {};

virtual winrt::hstring GetTemplateForWidget() = 0;
virtual winrt::hstring GetDataForWidget() = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "pch.h"
#include "WidgetProvider.h"
#include <iostream>

using CreateWidgetImplFn = std::function<std::shared_ptr<WidgetImplBase>(winrt::WidgetContext, winrt::hstring)>;

Expand Down Expand Up @@ -142,6 +143,36 @@ void WidgetProvider::Deactivate(winrt::hstring widgetId)
}
}

// Handle the OnCustomizationRequested call. This function is called when widgets host stops listening
// to the widget updates. It generally happens when the widget is not visible to the user
// anymore and any further updates won't be displayed until the widget is visible again.
// It's recommended to stop sending updates until Activate function was called.
void WidgetProvider::OnCustomizationRequested(winrt::WidgetCustomizationRequestedArgs const& args)
{
if (const auto& runningWidget = FindRunningWidget(args.WidgetContext().Id()))
{
runningWidget->OnCustomizationRequested(args);
}
}

// Handle the OnCustomizationRequested call. This function is called when widgets host stops listening
// to the widget updates. It generally happens when the widget is not visible to the user
// anymore and any further updates won't be displayed until the widget is visible again.
// It's recommended to stop sending updates until Activate function was called.
void WidgetProvider::OnAnalyticsInfoReported(winrt::WidgetAnalyticsInfoReportedArgs const& args)
{
std::wcout << args.AnalyticsJson().c_str() << std::endl;
}

// Handle the OnCustomizationRequested call. This function is called when widgets host stops listening
// to the widget updates. It generally happens when the widget is not visible to the user
// anymore and any further updates won't be displayed until the widget is visible again.
// It's recommended to stop sending updates until Activate function was called.
void WidgetProvider::OnErrorInfoReported(winrt::WidgetErrorInfoReportedArgs const& args)
{
std::wcout << args.ErrorJson().c_str() << std::endl;
}

// This function will be called in WidgetProvider Constructor
// to get information about all the widgets that this provider
// is currently providing. It's helpful in case of the Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#pragma once
#include "WidgetImplBase.h"

struct WidgetProvider : winrt::implements<WidgetProvider, winrt::Microsoft::Windows::Widgets::Providers::IWidgetProvider>
struct WidgetProvider : winrt::implements<WidgetProvider, winrt::Microsoft::Windows::Widgets::Providers::IWidgetProvider,
winrt::Microsoft::Windows::Widgets::Providers::IWidgetProvider2,
winrt::Microsoft::Windows::Widgets::Providers::IWidgetProviderAnalytics,
winrt::Microsoft::Windows::Widgets::Providers::IWidgetProviderErrors>
{
WidgetProvider();

Expand All @@ -17,6 +20,18 @@ struct WidgetProvider : winrt::implements<WidgetProvider, winrt::Microsoft::Wind
void Deactivate(winrt::hstring widgetId);
/* IWidgetProvider required functions that need to be implemented */

/* IWidgetProvider2 required functions that need to be implemented */
void OnCustomizationRequested(winrt::WidgetCustomizationRequestedArgs const& args);
/* IWidgetProvider2 required functions that need to be implemented */

/* IWidgetProviderAnalytics required functions that need to be implemented */
void OnAnalyticsInfoReported(winrt::WidgetAnalyticsInfoReportedArgs const& eventNotifiedArgs);
/* IWidgetProviderAnalytics required functions that need to be implemented */

/* IWidgetProviderErrors required functions that need to be implemented */
void OnErrorInfoReported(winrt::WidgetErrorInfoReportedArgs const& eventNotifiedArgs);
/* IWidgetProviderErrors required functions that need to be implemented */

private:
void RecoverRunningWidgets();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<package id="Microsoft.Windows.CppWinRT" version="2.0.221104.6" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220914.1" targetFramework="native" />
<package id="Microsoft.Windows.SDK.BuildTools" version="10.0.22621.755" targetFramework="native" />
<package id="Microsoft.WindowsAppSDK" version="1.3.230331000" targetFramework="native" />
<package id="Microsoft.WindowsAppSDK" version="1.4.20230612-1948-Dev" targetFramework="native" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap uap3 rescap">

<Extensions>
<Extension Category="windows.activatableClass.proxyStub">
<ProxyStub ClassId="00000355-0000-0000-C000-000000000046">
<Path>Microsoft.Windows.Widgets.winmd</Path>
<Interface Name="Microsoft.Windows.Widgets.Providers.IWidgetProvider" InterfaceId="5C5774CC-72A0-452D-B9ED-075C0DD25EED" />
<Interface Name="Microsoft.Windows.Widgets.Providers.IWidgetProvider2" InterfaceId="38C3A963-DD93-479D-9276-04BF84EE1816" />
<Interface Name="Microsoft.Windows.Widgets.Providers.IWidgetProviderErrors" InterfaceId="90C1B5F0-0D3A-4AC6-ABB7-C97B367B8FCC" />
<Interface Name="Microsoft.Windows.Widgets.Providers.IWidgetProviderAnalytics" InterfaceId="661985A5-D187-482D-9EEF-6FDA05D21845" />
</ProxyStub>
</Extension>
</Extensions>

<Identity
Name="SampleWidgetProviderAppPackage"
Publisher="CN=Microsoft Corporation"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
</PropertyGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>7C9DBD64-9DC7-4706-8FDA-8Df2A43184FE</ProjectGuid>
<TargetPlatformVersion>10.0.22000.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<AssetTargetFallback>net6.0-windows$(TargetPlatformVersion);$(AssetTargetFallback)</AssetTargetFallback>
<DefaultLanguage>en-US</DefaultLanguage>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<EntryPointProjectUniqueName>..\SampleWidgetProviderApp\SampleWidgetProviderApp.vcxproj</EntryPointProjectUniqueName>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Templates\WeatherWidgetTemplate.json" />
<Content Include="Templates\CountingWidgetTemplate.json" />
<Content Include="Images\SplashScreen.scale-200.png" />
<Content Include="Images\LockScreenLogo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
<Content Include="ProviderAssets\Counting_Icon.png" />
<Content Include="ProviderAssets\Counting_Screenshot.png" />
<Content Include="ProviderAssets\Weather_Icon.png" />
<Content Include="ProviderAssets\Weather_Screenshot.png" />
</ItemGroup>
<!--
<ItemGroup>
<AppxSystemBinary Include="Microsoft.Windows.Widgets.winmd" />
</ItemGroup>
-->
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" PrivateAssets="all" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.20230612-1948-Dev">
<IncludeAssets>build</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SampleWidgetProviderApp\SampleWidgetProviderApp.vcxproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<DefaultLanguage>en-US</DefaultLanguage>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
<EntryPointProjectUniqueName>..\SampleWidgetProviderApp\SampleWidgetProviderApp.vcxproj</EntryPointProjectUniqueName>
<UserSecretsId>46dcaee8-712c-4246-88c2-4e8e9d01d721</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
Expand All @@ -70,12 +71,15 @@
<Content Include="ProviderAssets\Weather_Icon.png" />
<Content Include="ProviderAssets\Weather_Screenshot.png" />
</ItemGroup>
<ItemGroup>
<AppxSystemBinary Include="Microsoft.Windows.Widgets.winmd" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230331000">
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" PrivateAssets="all" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.20230612-1948-Dev">
<IncludeAssets>build</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SampleWidgetProviderApp\SampleWidgetProviderApp.vcxproj" />
Expand Down