* [content-tracing](api/content-tracing.md)
* [dialog](api/dialog.md)
* [global-shortcut](api/global-shortcut.md)
-* [ipc (main process)](api/ipc-main-process.md)
+* [ipc-main](api/ipc-main.md)
* [menu](api/menu.md)
* [menu-item](api/menu-item.md)
* [power-monitor](api/power-monitor.md)
### 랜더러 프로세스에서 사용할 수 있는 모듈 (웹 페이지):
-* [ipc (renderer)](api/ipc-renderer.md)
+* [ipc-renderer](api/ipc-renderer.md)
* [remote](api/remote.md)
* [web-frame](api/web-frame.md)
+++ /dev/null
-# ipc (main process)
-
-`ipc` (main process) 모듈은 메인 프로세스에서 사용할 때 랜더러 프로세스(웹 페이지)에서 전달된 동기 또는 비동기 메시지를 보내고 받는 방법을 제공합니다.
-랜더러 프로세스에서 메시지를 전달하면 이 모듈을 통해 메시지를 받을 수 있습니다.
-
-## 메시지 전송
-
-물론 메인 프로세스에서 랜더러 프로세스로 메시지를 보내는 것도 가능합니다.
-자세한 내용은 [WebContents.send](web-contents.md#webcontentssendchannel-args)를 참고하세요.
-
-- 메시지를 전송할 때 이벤트 이름은 `channel`이 됩니다.
-- 메시지에 동기로 응답할 땐 반드시 `event.returnValue`를 설정해야 합니다.
-- 메시지를 비동기로 응답할 땐 `event.sender.send(...)` 메서드를 사용할 수 있습니다.
-
-랜더러 프로세스와 메인 프로세스간에 메시지를 전달하고 받는 예제입니다:
-
-```javascript
-// 메인 프로세스
-var ipc = require('ipc');
-ipc.on('asynchronous-message', function(event, arg) {
- console.log(arg); // prints "ping"
- event.sender.send('asynchronous-reply', 'pong');
-});
-
-ipc.on('synchronous-message', function(event, arg) {
- console.log(arg); // prints "ping"
- event.returnValue = 'pong';
-});
-```
-
-```javascript
-// 랜더러 프로세스 (web page)
-var ipc = require('ipc');
-console.log(ipc.sendSync('synchronous-message', 'ping')); // prints "pong"
-
-ipc.on('asynchronous-reply', function(arg) {
- console.log(arg); // prints "pong"
-});
-ipc.send('asynchronous-message', 'ping');
-```
-
-## 메시지 리스닝
-
-`ipc` 모듈은 다음과 같은 이벤트 메서드를 가지고 있습니다:
-
-### `ipc.on(channel, callback)`
-
-* `channel` String - 이벤트 이름
-* `callback` Function
-
-이벤트가 발생하면 `callback`에 `event` 객체와 `arg` 메시지가 포함되어 호출됩니다.
-
-## IPC Events
-
-`callback`에서 전달된 `event` 객체는 다음과 같은 메서드와 속성을 가지고 있습니다:
-
-### `Event.returnValue`
-
-이 메시지를 지정하면 동기 메시지를 전달합니다.
-
-### `Event.sender`
-
-메시지를 보낸 `WebContents` 객체를 반환합니다.
-
-### `Event.sender.send(channel[, arg1][, arg2][, ...])`
-
-* `channel` String - The event name.
-* `arg` (optional)
-
-랜더러 프로세스로 비동기 메시지를 전달합니다.
-옵션으로 `arg`에 한 개 또는 여러 개의 메시지를 포함할 수 있습니다. 모든 타입을 사용할 수 있습니다.
--- /dev/null
+# ipcMain
+
+`ipcMain` 모듈은 메인 프로세스에서 사용할 때 랜더러 프로세스(웹 페이지)에서 전달된 동기/비동기 메시지를 주고 받는 방법을 제공합니다.
+랜더러 프로세스에서 메시지를 전달하면 이 모듈을 통해 메시지를 받을 수 있습니다.
+
+## 메시지 전송
+
+물론 메시지를 받는 것 말고도 메인 프로세스에서 랜더러 프로세스로 보내는 것도 가능합니다.
+자세한 내용은 [webContents.send](web-contents.md#webcontentssendchannel-args)를 참고하세요.
+
+* 메시지를 전송할 때 이벤트 이름은 `channel`이 됩니다.
+* 메시지에 동기로 응답할 땐 반드시 `event.returnValue`를 설정해야 합니다.
+* 메시지를 비동기로 응답할 땐 `event.sender.send(...)` 메서드를 사용할 수 있습니다.
+
+다음 예제는 랜더러 프로세스와 메인 프로세스간에 메시지를 전달하고 받는 예제입니다:
+
+```javascript
+// 메인 프로세스
+var ipc = require('ipc');
+ipc.on('asynchronous-message', function(event, arg) {
+ console.log(arg); // prints "ping"
+ event.sender.send('asynchronous-reply', 'pong');
+});
+
+ipc.on('synchronous-message', function(event, arg) {
+ console.log(arg); // prints "ping"
+ event.returnValue = 'pong';
+});
+```
+
+```javascript
+// 랜더러 프로세스 (웹 페이지)
+var ipc = require('ipc');
+console.log(ipc.sendSync('synchronous-message', 'ping')); // prints "pong"
+
+ipc.on('asynchronous-reply', function(arg) {
+ console.log(arg); // prints "pong"
+});
+ipc.send('asynchronous-message', 'ping');
+```
+
+## 메시지 리스닝
+
+`ipcMain`은 다음과 같은 이벤트 리스닝 메서드를 가지고 있습니다:
+
+### `ipc.on(channel, callback)`
+
+* `channel` String - 이벤트 이름
+* `callback` Function
+
+이벤트가 발생하면 `event` 객체와 `arg` 메시지와 함께 `callback`이 호출됩니다.
+
+## IPC 이벤트
+
+`callback`에서 전달된 `event` 객체는 다음과 같은 메서드와 속성을 가지고 있습니다:
+
+### `Event.returnValue`
+
+이 메시지를 지정하면 동기 메시지를 전달합니다.
+
+### `Event.sender`
+
+메시지를 보낸 `webContents` 객체를 반환합니다. `event.sender.send` 메서드를 통해 비동기로 메시지를 전달할 수 있습니다.
+자세한 내용은 [webContents.send][webcontents-send]를 참고하세요.
+
+[webcontents-send]: web-contents.md#webcontentssendchannel-args
-# ipc (renderer)
+# ipcRenderer
-`ipc` (renderer) 모듈은 메인 프로세스로 동기 또는 비동기 메시지를 보내고 받는 방법을 제공합니다.
-ë¬¼ë¡ 메인 프로세스로부터 받은 메시지에 응답할 수도 있습니다.
+`ipcRenderer` 모듈은 랜더러 프로세스에서 메인 프로세스로 동기/비동기 메시지를 주고 받는 방법을 제공합니다.
+ë\98\90í\95\9c 메인 프로세스로부터 받은 메시지에 응답할 수도 있습니다.
-**참고:** 만약 랜더러 프로세스에서 메인 프로세스의 모듈을 직접적 사용하고 싶다면 [remote](remote.md) 모듈을 사용하는 것을 고려해보는 것이 좋습니다.
+[ipcMain](ipc-main.md)에서 코드 예제를 확인할 수 있습니다.
-[ipc (main process)](ipc-main-process.md)에서 예제를 확인 할 수 있습니다.
+## 메시지 리스닝
-## Methods
+`ipcRenderer`는 다음과 같은 이벤트 리스닝 메서드를 가지고 있습니다:
-`ipc` 모듈은 다음과 같은 메서드를 가지고 있습니다:
+### `ipcRenderer.on(channel, callback)`
-**참고:** 이 메소드들을 사용하여 `message`를 보낼 땐 반드시 메인 프로세스의
-[`ipc (main process)`](ipc-main-process.md) 모듈에서도 이벤트 리스너를 등록해 두어야 합니다.
+* `channel` String - 이벤트 이름
+* `callback` Function
+
+이벤트가 일어나면 `event` 객체와 임의의 인자와 함께 `callback` 함수가 호출됩니다.
+
+## 메시지 보내기
-### `ipc.send(channel[, arg1][, arg2][, ...])`
+`ipcRenderer`는 다음과 같은 메시지 전송 메서드를 가지고 있습니다:
+
+### `ipcRenderer.send(channel[, arg1][, arg2][, ...])`
* `channel` String - 이벤트 이름
* `arg` (optional)
-`channel`을 통해 메인 프로세스에 비동기 메시지를 보냅니다.
-옵션으로 `arg`에 한 개 또는 여러 개의 메시지를 포함할 수 있습니다. 모든 타입을 사용할 수 있습니다.
-메인 프로세스는 `ipc`를 통해 `channel` 이벤트를 리스닝 할 수 있습니다.
+`channel`을 통해 메인 프로세스에 비동기 메시지를 보냅니다. 그리고 필요에 따라 임의의 인자를 사용할 수도 있습니다.
+메인 프로세스는 `ipcMain` 모듈의 `channel` 이벤트를 통해 이벤트를 리스닝 할 수 있습니다.
-### `ipc.sendSync(channel[, arg1][, arg2][, ...])`
+### `ipcRenderer.sendSync(channel[, arg1][, arg2][, ...])`
* `channel` String - 이벤트 이름
* `arg` (optional)
-`channel`을 통해 메인 프로세스에 동기 메시지를 보냅니다.
-옵션으로 `arg`에 한 개 또는 여러 개의 메시지를 포함할 수 있습니다. 모든 타입을 사용할 수 있습니다.
+`channel`을 통해 메인 프로세스에 동기 메시지를 보냅니다. 그리고 필요에 따라 임의의 인자를 사용할 수도 있습니다.
메인 프로세스는 `ipc`를 통해 `channel` 이벤트를 리스닝 할 수 있습니다.
메인 프로세스에선 `ipc` 모듈의 `channel` 이벤트를 통해 받은 `event.returnValue`로 회신 할 수 있습니다.
-**참고:** 동기 메시징은 모든 랜더러 프로세스의 작업을 일시 중단시킵니다. 이 메서드를 사용하는 것을 권장하지 않습니다.
+__참고:__ 동기 메서드는 모든 랜더러 프로세스의 작업을 일시 중단시킵니다. 사용 목적이 확실하지 않다면 사용하지 않는 것이 좋습니다.
-### `ipc.sendToHost(channel[, arg1][, arg2][, ...])`
+### `ipcRenderer.sendToHost(channel[, arg1][, arg2][, ...])`
* `channel` String - 이벤트 이름
* `arg` (optional)
-`ipc.send`와 비슷하지만 이벤트를 메인 프로세스 대신 호스트 페이지내의 `<webview>`로 보냅니다.
-옵션으로 `arg`에 한 개 또는 여러 개의 메시지를 포함할 수 있습니다. 모든 타입을 사용할 수 있습니다.
+`ipcRenderer.send`와 비슷하지만 이벤트를 메인 프로세스 대신 호스트 페이지내의 `<webview>` 요소로 보냅니다.
Webview 페이지를 PDF 형식으로 인쇄합니다. `webContents.printToPDF(options, callback)` 메서드와 같습니다.
-### `<webview>.send(channel[, args...])`
+### `<webview>.send(channel[, arg1][, arg2][, ...])`
* `channel` String
* `args` (optional)
-`channel`을 통해 페이지에 `args` 비동기 메시지를 보냅니다.
-페이지에선 `ipc` 모듈의 `channel` 이벤트를 사용하면 이 메시지를 받을 수 있습니다.
+`channel`을 통해 랜더러 프로세스로 비동기 메시지를 보냅니다. 또한 `args`를 지정하여 임의의 인자를 보낼 수도 있습니다.
+랜더러 프로세스는 `ipcRenderer` 모듈의 `channel` 이벤트로 이 메시지를 받아 처리할 수 있습니다.
-예제는 [WebContents.send](web-contents.md#webcontentssendchannel-args)를 참고하세요.
+예제는 [webContents.send](web-contents.md#webcontentssendchannel-args)를 참고하세요.
### `<webview>.sendInputEvent(event)`
페이지에 input `event`를 보냅니다.
-`event` ê°\9dì²´ì\97\90 ë\8c\80í\95´ ì\9e\90ì\84¸í\95\9c ë\82´ì\9a©ì\9d\84 ì\95\8cì\95\84ë³´ë ¤ë©´ [WebContents.sendInputEvent](web-contents.md##webcontentssendinputeventevent)를 참고하세요.
+`event` ê°\9dì²´ì\97\90 ë\8c\80í\95´ ì\9e\90ì\84¸í\9e\88 ì\95\8cì\95\84ë³´ë ¤ë©´ [webContents.sendInputEvent](web-contents.md##webcontentssendinputeventevent)를 참고하세요.
## DOM 이벤트
어플리케이션 배포의 대상이 되는 서로 다른 운영체제 시스템의 환경에 맞춰 어플리케이션의 기능을 통합할 수 있습니다.
예를 들어 Windows에선 태스크바의 JumpList에 바로가기를 추가할 수 있고 Mac(OS X)에선 dock 메뉴에 커스텀 메뉴를 추가할 수 있습니다.
-이 가이드는 Electron API를 이용하여 각 운영체제 시스템의 기능을 활용하는 방법을 설명합니다.
+이 문서는 Electron API를 이용하여 각 운영체제 시스템의 기능을 활용하는 방법을 설명합니다.
+
+## 데스크톱 알림 (Windows, Linux, OS X)
+
+Windows, Linux, OS X 운영체제 모두 기본적으로 어플리케이션에서 유저에게 알림 보낼 수 있는 방법을 제공합니다.
+Electron은 HTML5 Notification API](https://notifications.spec.whatwg.org/)를 통해 개발자가
+편리하게 데스크톱 알림을 사용할 수 있는 기능을 제공합니다. 데스크톱 알림은 운영체제의 네이티브 알림 API를 사용하여 표시합니다.
+
+```javascript
+var myNotificiation = new Notification('Title', {
+ body: 'Lorem Ipsum Dolor Sit Amet'
+});
+
+myNotification.onclick = function () {
+ console.log('Notification clicked')
+}
+```
+
+위 코드를 통해 생성한 데스크톱 알림은 각 운영체제 모두 비슷한 사용자 경험을 제공합니다. 하지만 몇 가지 다른 점들이 있습니다.
+
+### Windows
+
+* Windows 10에선 "아무 문제 없이 잘" 작동합니다.
+* Windows 8.1과 8에선 [Application User Model ID][app-user-model-id]로 바로가기를 만들어 놔야 합니다.
+이 바로가기는 반드시 시작 화면에 설치되어 있어야 합니다. 참고로 반드시 시작 화면에 고정 할 필요는 없습니다.
+* Windows 7과 그 이하 버전은 데스크톱 알림을 지원하지 않습니다. 혹시 "풍선 알림" 기능을 찾는다면 [Tray API](tray-balloon)를 사용하세요.
+
+이미지를 데스크톱 알림에 사용하려면 알림 옵션의 `icon` 속성에 로컬 이미지 파일(`png` 권장)을 지정하면 됩니다.
+데스크톱 알림은 잘못된 경로를 지정하거나 `http/https` 기반의 URL을 지정해도 이미지가 보이지 않을 뿐 정상 작동합니다.
+
+```javascript
+new Notification('Title', {
+ body: 'Notification with icon',
+ icon: 'file:///C:/Users/feriese/Desktop/icon.png'
+});
+```
+
+또한 `body`의 최대 길이는 250자 입니다. Windows 개발팀에선 알림 문자열을 200자 이하로 유지하는 것을 권장합니다.
+
+### Linux
+
+데스크톱 알림의 구현으로 `libnotify`를 사용합니다. 따라서 [Desktop Notifications Specification][notification-spec]을
+따르는 모든 데스크탑 환경에서 데스크톱 알림 기능을 사용할 수 있습니다. Cinnamon, Enlightenment, Unity, GNOME, KDE등을 지원합니다.
+
+### OS X
+
+OS X에서의 데스크톱 알림은 아주 직관적입니다. 하지만 데스크톱 알림을 사용할 땐
+[Apple's Human Interface guidelines regarding notifications](https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/OSXHIGuidelines/NotificationCenter.html)
+가이드를 고려해야 합니다.
+
+참고로 데스크롭 알림의 최대 길이는 256 바이트 입니다. 길이가 초과할 경우 초과한 글자가 잘립니다.
## 최근 사용한 문서 (Windows & OS X)
[app-registration]: http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121(v=vs.85).aspx
[unity-launcher]: https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles#Adding_shortcuts_to_a_launcher
[setthumbarbuttons]: ../api/browser-window.md#browserwindowsetthumbarbuttonsbuttons
+[trayballoon]: ../api/tray.md#traydisplayballoonoptions-windows
```html
<!DOCTYPE html>
<html>
- <body>
- <script>
- var alertOnlineStatus = function() {
- window.alert(navigator.onLine ? 'online' : 'offline');
- };
-
- window.addEventListener('online', alertOnlineStatus);
- window.addEventListener('offline', alertOnlineStatus);
-
- alertOnlineStatus();
- </script>
- </body>
+<body>
+<script>
+ var alertOnlineStatus = function() {
+ window.alert(navigator.onLine ? 'online' : 'offline');
+ };
+
+ window.addEventListener('online', alertOnlineStatus);
+ window.addEventListener('offline', alertOnlineStatus);
+
+ alertOnlineStatus();
+</script>
+</body>
</html>
```
```javascript
var app = require('app');
-var ipc = require('ipc');
+var ipcMain = require('ipc-main');
var BrowserWindow = require('browser-window');
var onlineStatusWindow;
onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html');
});
-ipc.on('online-status-changed', function(event, status) {
+ipcMain.on('online-status-changed', function(event, status) {
console.log(status);
});
```
```html
<!DOCTYPE html>
<html>
- <body>
- <script>
- var ipc = require('ipc');
- var updateOnlineStatus = function() {
- ipc.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
- };
-
- window.addEventListener('online', updateOnlineStatus);
- window.addEventListener('offline', updateOnlineStatus);
-
- updateOnlineStatus();
- </script>
- </body>
+<body>
+<script>
+ var ipcRenderer = require('ipc-renderer');
+ var updateOnlineStatus = function() {
+ ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
+ };
+
+ window.addEventListener('online', updateOnlineStatus);
+ window.addEventListener('offline', updateOnlineStatus);
+
+ updateOnlineStatus();
+</script>
+</body>
</html>
```