Skip to content

Instantly share code, notes, and snippets.

@verytired
Last active September 1, 2015 04:30
Show Gist options
  • Save verytired/18c290e1618937464d44 to your computer and use it in GitHub Desktop.
Save verytired/18c290e1618937464d44 to your computer and use it in GitHub Desktop.
electronメモ

electron開発メモ

開発開始

プロジェクト作成

npm init -y  

pakcage.jsonのmainで指定しているファイルが実行開始ファイルとなる(defaultはindex.js)

実行

(electron-prebuildインストール済みの状態で)

electron (実行ファイル格納path)

で実行

パッケージ化

electron packagerを使う

electron-packager . your-app --platform=darwin --arch=x64 --version=0.30.0 --overwrite

起動部分の実装について

1.package.jsonの記述

package.jsonにエントリポイントを記述する

{
  ...
  "main": "main.js",
  ...
}

2.main.jsの実装

brawserWindowを使ってwindowを作り、htmlをそこに読み込ませる

'use strict';

var app = require('app');
var BrowserWindow = require('browser-window');

require('crash-reporter').start();

var mainWindow = null;

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

app.on('ready', function() {

  // ブラウザ(Chromium)の起動, 初期画面のロード
  mainWindow = new BrowserWindow({width: 800, height: 600});
  mainWindow.loadUrl('file://' + __dirname + '/index.html');

  mainWindow.on('closed', function() {
    mainWindow = null;
  });
});

3.ファイルの設置

任意のフォルダにリソースを設置する。 上のサンプルコード内では実行元のindex.jsと同一フォルダにあるindex.htmlを読み込んでいる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment