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

Please add support pin to taskbar for desktop apps #8819

Closed
Gaoyifei1011 opened this issue Sep 3, 2023 · 1 comment
Closed

Please add support pin to taskbar for desktop apps #8819

Gaoyifei1011 opened this issue Sep 3, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Gaoyifei1011
Copy link

Gaoyifei1011 commented Sep 3, 2023

Describe the bug

In the WinRT API WIndows.UI.Shell namespace, the inside of the TaskbarManager class can provide some fixed method applied to the task bar. With the new fixed taskbar notification update in Windows 11 22621 beta, we found that notification transitioned from CoreWindow to ToastNotificaton. In further exploration, we found that for desktop applications, the function of the new Toast notification fixed to the taskbar has been locked for desktop applications, and the corresponding function needs to be unlocked in order to use it. We hope that the future version can unlock this function for desktop applications, and provide a corresponding method to detect whether this function is available.

Steps to reproduce the bug

See describe bug description

Expected behavior

Please unlock the pin to taskbar for deskop features

Screenshots

An exception message when unlocked
image

引发的异常:“System.UnauthorizedAccessException”(位于 System.Private.CoreLib.dll 中)
WinRT 信息: Feature com.microsoft.windows.taskbar.pin is not available.
“System.UnauthorizedAccessException”类型的异常在 System.Private.CoreLib.dll 中发生,但未在用户代码中进行处理
WinRT 信息: Feature com.microsoft.windows.taskbar.pin is not available.
拒绝访问。

Content prompted after unlocking (desktop app)
image

Corresponding code

        Task.Run(async () =>
        {
            bool IsPinnedSuccessfully = false;

            try
            {
                string featureId = "com.microsoft.windows.taskbar.pin";
                string token = FeatureAccessHelper.GenerateTokenFromFeatureId(featureId);
                string attestation = FeatureAccessHelper.GenerateAttestation(featureId);
                LimitedAccessFeatureRequestResult accessResult = LimitedAccessFeatures.TryUnlockFeature(featureId, token, attestation);

                if (accessResult.Status is LimitedAccessFeatureStatus.Available)
                {
                    IsPinnedSuccessfully = await TaskbarManager.GetDefault().RequestPinCurrentAppAsync();
                }
            }
            catch (Exception e)
            {
                // None
            }
            finally
            {
               // None
            }
        });

public static class FeatureAccessHelper
{
    private static string packageFamilyName = Package.Current.Id.FamilyName;

    // Windows 11 22621 受限的 API 和对应的访问密钥
    private static readonly Dictionary<string, string> LimitedAccessFeaturesDict = new Dictionary<string, string>()
    {
        { "com.microsoft.services.cortana.cortanaactionableinsights_v1", "nEVyyzytE6ankNk1CIAu6sZsh8vKLw3Q7glTOHB11po=" },
        { "com.microsoft.windows.applicationmodel.conversationalagent_v1", "hhrovbOc/z8TgeoWheL4RF5vLLJrKNAQpdyvhlTee6I" },
        { "com.microsoft.windows.applicationmodel.phonelinetransportdevice_v1", "cb9WIvVfhp+8lFhaSrB6V6zUBGqctteKi/f/9AIeoZ4" },
        { "com.microsoft.windows.applicationwindow", "e5a85131-319b-4a56-9577-1c1d9c781218" },
        { "com.microsoft.windows.callcontrolpublicapi_v1", "6e7e52aa-cddb-4e57-9f1c-7dd511ad7d01" },
        { "com.microsoft.windows.focussessionmanager.1", "ba3faac1-0878-4bb9-9b35-2224aa0ee7cf" },
        { "com.microsoft.windows.geolocationprovider", "6D1544E3-55CB-40D2-A022-31F24E139708" },
        { "com.microsoft.windows.holographic.keyboardcursor_v1", "FE676B8B-E396-4A80-9573-B67542840E5C" },
        { "com.microsoft.windows.holographic.shell", "527f4968-f193-419a-b91f-46b9106e1129" },
        { "com.microsoft.windows.holographic.xrruntime.1", "036EFF74-8BF2-4249-82AF-92235C6E1A10" },
        { "com.microsoft.windows.holographic.xrruntime.2", "58AA36EF-7C1A-4A56-9308-FC882F56465A" },
        { "com.microsoft.windows.richeditmath", "RDZCQjY2M0YtQkFDMi00NkIwLUI3NzEtODg4NjMxMEVENkFF" },
        { "com.microsoft.windows.shell.sharewindowcommandsource_v1", "yDvrila5HS/y8SctohQM3WJZOby8NbSoL2hEPTyIRco=" },
        { "com.microsoft.windows.system.remotedesktop.provider_v1", "2F712169EF57A9FB0D590593743819F5F47E2DD13E4D9A5458DDA77608CC5E10" },
        { "com.microsoft.windows.taskbar.pin", "4096B239A7295B635C090E647E867B5707DA6AB6CB78340B01FE4E0C8F4953D4" },
        { "com.microsoft.windows.taskbar.requestPinSecondaryTile", "04c19204-10d9-450a-95c4-2910c8f72be3" },
        { "com.microsoft.windows.ui.notifications.preview.toastOcclusionManagerPreview", "738a6acf-45c1-44ed-85a4-5eb11dc2d084" },
        { "com.microsoft.windows.updateorchestrator.1", "20C662033A4007A55375BF00D986C280B41A418F" },
        { "com.microsoft.windows.windowdecorations", "425261a8-7f73-4319-8a53-fc13f87e1717" },
    };

    public static string GenerateTokenFromFeatureId(string featureId)
    {
        string generatedContent = string.Format("{0}!{1}!{2}", featureId, LimitedAccessFeaturesDict[featureId], packageFamilyName);
        byte[] computedHash = HashAlgorithmHelper.ComputeSHA256Hash(generatedContent);
        byte[] tokenBytes = new byte[16];
        Array.Copy(computedHash, tokenBytes, tokenBytes.Length);
        return Convert.ToBase64String(tokenBytes);
    }

    public static string GenerateAttestation(string featureId)
    {
        return string.Format("{0} has registered their use of {1} with Microsoft and agrees to the terms of use.", packageFamilyName.Split('_').Last(), featureId);
    }
}

NuGet package version

WinUI 3 - Windows App SDK 1.4.0: 1.4.230822000

Windows version

Windows 11 (22H2): Build 22621

Additional context

Reference Links

Pin your app to the taskbar
https://learn.microsoft.com/zh-cn/windows/apps/design/shell/pin-to-taskbar

A principled approach to app pinning and app defaults in Windows
https://blogs.windows.com/windowsexperience/2023/03/17/a-principled-approach-to-app-pinning-and-app-defaults-in-windows/

@Gaoyifei1011 Gaoyifei1011 added the bug Something isn't working label Sep 3, 2023
@bpulliam
Copy link
Contributor

bpulliam commented Sep 7, 2023

Duplicate of microsoft/WindowsAppSDK#3917

@bpulliam bpulliam closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants