WinJS System.Launcher仅在调试模式下工作

时间:2012-11-06 03:44:37

标签: visual-studio-2012 microsoft-metro winjs

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

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

行为收到/无效:点击磁贴启动应用,只渲染html页面,永远不会启动蒸汽网址。

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();
})();

1 个答案:

答案 0 :(得分: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();
})();