3

以下代码在调试模式 (F5) 下运行时可以完美运行。但在部署(作为应用程序磁贴)或在没有调试器 (ctl+f5) 的情况下运行时,它无法正常运行。

预期行为/工作时:单击磁贴会立即启动 Steam url 链接,而不会显式呈现 html 页面。

收到/不工作的行为:单击磁贴启动应用程序,仅呈现 html 页面,从不启动 steam url。

var mydefs = new Object();
mydefs = { url: 'steam://rungameid/200710' };

function launch(url) {
    var uri = new Windows.Foundation.Uri(url);

    Windows.System.Launcher.launchUriAsync(uri).then(
         function (success) {
             if (success) {
                 // File launched
                 window.close();
             } else {
                 // File launch failed
             }
         });
}

(function () {
    "use strict";

    WinJS.Binding.optimizeBindingReferences = true;

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            launch(mydefs.url);

            args.setPromise(WinJS.UI.processAll());
        }
    };

    app.oncheckpoint = function (args) {
        window.close();
    };

    app.start();
})();
4

1 回答 1

2

看起来是时间问题。以下对我来说是一个瓷砖

(function () {
   "use strict";
    var mydefs = new Object();
    mydefs = { url: 'steam://rungameid/200710' };

    WinJS.Namespace.define("Steam", {
      launch: function launch(url) {
        var uri = new Windows.Foundation.Uri(url);

        Windows.System.Launcher.launchUriAsync(uri).then(
             function (success) {
                 if (success) {
                     // File launched
                     window.close();
                 } else {
                     // File launch failed
                 }
             });
          }
  });


  WinJS.Binding.optimizeBindingReferences = true;

  var app = WinJS.Application;
  var activation = Windows.ApplicationModel.Activation;

  app.onactivated = function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {                 
        setTimeout('Steam.launch("steam://rungameid/200710");', 2000);
        args.setPromise(WinJS.UI.processAll());
    }
  };

  app.start();
})();
于 2012-11-10T20:00:05.717 回答