「Electron」の版間の差分
ナビゲーションに移動
検索に移動
| 19行目: | 19行目: | ||
npm i --save-dev electron | npm i --save-dev electron | ||
</pre> | </pre> | ||
| − | + | ====mainスクリプトファイルの作成==== | |
| + | ---- | ||
*mainスクリプトは、Electronアプリケーションのエントリーポイント(例えば,main。js) | *mainスクリプトは、Electronアプリケーションのエントリーポイント(例えば,main。js) | ||
*Mainプロセスを開始し、Mainプロセスはアプリケーションのライフサイクルをコントロールする | *Mainプロセスを開始し、Mainプロセスはアプリケーションのライフサイクルをコントロールする | ||
| + | <pre> | ||
| + | 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() | ||
| + | } | ||
| + | }) | ||
| + | </pre> | ||
| + | ====Webページの作成==== | ||
| + | ---- | ||
| + | *index.html | ||
| + | <pre> | ||
| + | <!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</h1> | ||
| + | </body> | ||
| + | </html> | ||
| + | </pre> | ||
2021年5月4日 (火) 03:28時点における版
| 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
<!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</h1>
</body>
</html>
© 2006 矢木浩人