「Electron」の版間の差分
ナビゲーションに移動
検索に移動
| 54行目: | 54行目: | ||
}) | }) | ||
</pre> | </pre> | ||
| − | ==== | + | ====Webページ(index.html)の作成==== |
---- | ---- | ||
*index.html | *index.html | ||
| + | *アプリケーション初期化時に一度だけ表示されるページ | ||
| + | *このページがレンダープロセスを表現する | ||
<pre> | <pre> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
| 66行目: | 68行目: | ||
</head> | </head> | ||
<body style="background: white;"> | <body style="background: white;"> | ||
| − | <h1>Hello</h1> | + | <h1>Hello World!</h1> |
| + | <p> | ||
| + | We are using Node.js <span id="node-version"></span>, | ||
| + | Chromium <span id="chrome-version"></span>, | ||
| + | and Electron <span id="electron-version"></span>. | ||
| + | </p> | ||
</body> | </body> | ||
</html> | </html> | ||
</pre> | </pre> | ||
| + | ====プレロードスクリプト(preload.js)==== | ||
| + | ---- | ||
| + | *Node.jsとWebページのブリッジ | ||
| + | * | ||
2021年5月4日 (火) 03:34時点における版
| Node.js | JavaScript | TypeScript | npm |
目次
Electron
Fiddle
Required
- Node.jsのインストール
基本的なアプリの作成
- Electronアプリケーションは本質的にNode.jsアプリケーション
- Electronアプリケーションは、package.json から開始される
プロジェクトの作成とElectronのインストール
mkdir my-electron-app && cd my-electron-app npm init -y npm i --save-dev electron
mainスクリプトファイルの作成
- mainスクリプトは、Electronアプリケーションのエントリーポイント(例えば,main。js)
- Mainプロセスを開始し、Mainプロセスはアプリケーションのライフサイクルをコントロールする
const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow() {
const win = new BrowserWindow({
width:800,
height:600,
webPreferences:{
preload: path.join(__dirname, 'preload.js')
}
})
win.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () =>{
if (BrowserWindow.getAllWindows().length == 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
Webページ(index.html)の作成
- index.html
- アプリケーション初期化時に一度だけ表示されるページ
- このページがレンダープロセスを表現する
<!DOCTYPE html>
<html>
<head>
<meta carhset="UTF-8">
<title>Sample</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body style="background: white;">
<h1>Hello World!</h1>
<p>
We are using Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
and Electron <span id="electron-version"></span>.
</p>
</body>
</html>
プレロードスクリプト(preload.js)
- Node.jsとWebページのブリッジ
© 2006 矢木浩人