App Installer file API issues

JavaScript support for App Installer file APIs

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.

Of these methods, PackageManager.AddPackageByAppInstallerFileAsync, PackageManager.RequestAddPackageByAppInstallerFileAsync, and Package.CheckUpdateAvailabilityAsync are not supported in JavaScript. 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;
        });
    }
}