应用安装程序文件 API 问题App Installer file API issues

应用安装程序文件 Api 的 JavaScript 支持JavaScript support for App Installer file APIs

Windows SDK 中的 PackageManager 类提供了可用于通过应用安装程序文件添加或修改包的方法,或用于检索应用程序安装程序关联的应用程序的相关信息。The PackageManager and Package classes in the Windows SDK provide methods you can use to add or modify packages via App Installer files or to retrieve information about apps with an App Installer association. 有关详细信息,请参阅相关文档For more information, see Related documentation.

在这些方法中,JavaScript 中不支持 PackageManager、AddPackageByAppInstallerFileAsyncPackageManagerCheckUpdateAvailabilityAsyncOf these methods, PackageManager.AddPackageByAppInstallerFileAsync, PackageManager.RequestAddPackageByAppInstallerFileAsync, and Package.CheckUpdateAvailabilityAsync are not supported in JavaScript. 不过,你可以创建一个 Windows 运行时组件 ,该组件调用这些方法,然后从 JavaScript UWP 应用调用此组件。However, you can create a Windows Runtime component that calls these methods and then call this component from a JavaScript UWP app.

以下是一个示例。Here is an example.

namespace CSRuntimeComponent
{
    public sealed class UpdateAvailabilityChecker
    {
        public static IAsyncOperation<PackageUpdateAvailability> CheckForUpdatesAsync()
        {
            return AsyncInfo.Run<PackageUpdateAvailability>((result) => Task.Run<PackageUpdateAvailability>(async () =>
            {
                PackageManager pm = new PackageManager();
                Package currentPackage = pm.FindPackageForUser(string.Empty, Package.Current.Id.FullName);
                PackageUpdateAvailabilityResult apiResult = await currentPackage.CheckUpdateAvailabilityAsync();

                if (apiResult.Availability == PackageUpdateAvailability.Error)
                {
                    Logger.Error($"Error occurred, extended code: {apiResult.ExtendedError}");
                }

                return apiResult.Availability;
            }));
        }
    }
}
window.onload = function () {
    document.getElementById('mainButton').onclick = function (evt) {
        CSRuntimeComponent.UpdateAvailabilityChecker.checkForUpdatesAsync().done(function (result) {
            document.getElementById("resultLabel").innerHTML = "Update availability result:" + result;
        });
    }
}