2017-05-06 84 views
0

Javascript:Javascript - Windows Store - 强制更新

我希望我的Windows应用商店应用程序检查更新,尤其是强制更新,然后提示用户更新。

我已经发现这涉及到Windows.Services.Store,但我找不到任何这样做的JavaScript例子,只有通常的c#/ vb的。

有谁知道代码模板?

回答

1

我已经发现这涉及到Windows.Services.Store,但我找不到这样做的任何JavaScript示例,只有通常的c#/ vb的。

我想你找到的例子是Code examplesDownload and install package updates for your app。尽管这些示例是用C#编写的,但我们可以很容易地将它们转换为JavaScript,因为它们大多数都是Windows运行时API。

使用下载并安装例如所有软件包更新,JavaScript版本需要以下:C#和JavaScript版本之间

var context = Windows.Services.Store.StoreContext.getDefault(); 

context.getAppAndOptionalStorePackageUpdatesAsync().then(function (updates) { 
    if (updates.size > 0) { 
     var dialog = new Windows.UI.Popups.MessageDialog("Download and install updates now? This may cause the application to exit.", "Download and Install?"); 
     dialog.commands.append(new Windows.UI.Popups.UICommand("Yes")); 
     dialog.commands.append(new Windows.UI.Popups.UICommand("No")); 
     dialog.showAsync().then(function (command) { 
      if (command.label === "Yes") { 
       context.requestDownloadAndInstallStorePackageUpdatesAsync(updates).then(function (result) { 
        // TODO 
       }, function (error) { 
        //TODO 
       }, function (progress) { 
        var downloadProgressBar = document.getElementById("downloadProgressBar"); 
        downloadProgressBar.value = progress.packageDownloadProgress; 
       }); 
      } 
     }); 
    } 
}); 

两项重大区别这里有casing conventionsasynchronous methods。欲了解更多信息,请参阅Using the Windows Runtime in JavaScript