예제 개요
이 섹션에서는 여러분이 Electron 애플리케이션에서 구현하고 싶을 만한 일반적인 기능에 대한 가이드 모음을 준비했다. 각 가이드는 최소한의 독립 실행형 예제 앱을 통해 실질적인 예제를 제공한다. 이 예제를 실행하는 가장 쉬운 방법은 Electron Fiddle을 다운로드하는 것이다.
Fiddle을 설치한 후에는 아래와 같은 코드 샘플 아래에 있는 "Open in Fiddle" 버튼을 눌러 실행할 수 있다:
- main.js
- preload.js
- index.html
const { app, BrowserWindow } = require('electron/main')
const path = require('node: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()
}
})
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body>
<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>
어떻게 하나요?
"어떻게 하나요?"에 대한 전체 목록은 사이드바에서 확인할 수 있다. 만약 문서화되지 않은 작업을 수행하고 싶다면, Discord 서버에 참여하여 알려주기 바란다!