electron on VS2013

Electronfirst Electron appをビルド、実行します。

  • electron-prebuilt@0.28.3
  • Visual Studio Community 2013
  • (node.js@0.12.3)

Add New Project ...

TypeScriptのNode.jsプロジェクト、「Blank Node.js Console Application」を指定します。

package.json を作成

(package.json自体はVSが生成してくれてるので、中身を書き換えます。)
(tutorialでは、main.jsですが、app.jsにしました(なっちゃいました、してしまいました)。)

{
  "name"    : "your-app",
  "version" : "0.1.0",
  "main"    : "app.js"
}

app.ts を作成

(app.ts自体はVSが生成してくれるので、中身を書き換えます。)

var app = require('app');  // Module to control application life.
var BrowserWindow = require('browser-window');  // Module to create native browser window.

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function () {
    if (process.platform != 'darwin') {
        app.quit();
    }
});

// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function () {
    // Create the browser window.
    mainWindow = new BrowserWindow({ width: 800, height: 600 });

    // and load the index.html of the app.
    mainWindow.loadUrl('file://' + __dirname + '/index.html');

    // Open the devtools.
    mainWindow.openDevTools();

    // Emitted when the window is closed.
    mainWindow.on('closed', function () {
        // Dereference the window object, usually you would store windows
        // in an array if your app supports multi windows, this is the time
        // when you should delete the corresponding element.
        mainWindow = null;
    });
});

index.html

(新規に作成保存しました。)

<!DOCTYPE html>
<html>
<head>
    <title>Hello World!</title>
</head>
<body>
    <h1>Hello World!</h1>
    We are using io.js
    <script>document.write(process.version)</script>
    and Electron
    <script>document.write(process.versions['electron'])</script>.
</body>
</html>

フォルダ内のファイル一覧

ビルド

プロジェクトのプロパティで「Node.exe path」にelectron.exeのパスを設定します。

実行結果


補足

iojs.exe が動いている?node.jsと同梱されてるのとは版が違うし...electron-prebuiltは、でかいです。npmでインストールしたらダウンロードで10分程度掛かる大きさです。このサイズなら何が入っててもおかしくない。io.js/node.jsの相違が現れるまで追求しません。