node.js를 사용하여 크로스 플랫폼 기본 알림을 보냅니다. MACOS 용 알림 센터, Linux 용 notify-osd / libnotify-bin , Windows 8/10 용 토스터 또는 이전 Windows 버전 용 작업 표시 줄 풍선. 이러한 요구 사항 중 어느 것도 충족되지 않으면 으르렁 거리는 growl이 사용됩니다. 전자와 잘 어울립니다.
MacOS, Windows, Linux에 기본 알림 표시 :
const notifier = require ( 'node-notifier' ) ;
// String
notifier . notify ( 'Message' ) ;
// Object
notifier . notify ( {
title : 'My notification' ,
message : 'Hello, there!'
} ) ; notify-osd 또는 libnotify-bin 설치 (Ubuntu는 기본적으로이를 가져야합니다)리포터 선택은 문서 및 흐름도를 참조하십시오.
npm install --save node-notifierCLI는 https://github.com/mikaelbr/node-notifier-cli를 별도의 프로젝트로 옮겼습니다
리포터 흐름도에 정의 된 크로스 플랫폼 폴백이있는 표준 사용량. 아래의 모든 옵션은 대부분의 플랫폼에서 어떤 식 으로든 작동합니다.
const notifier = require ( 'node-notifier' ) ;
const path = require ( 'path' ) ;
notifier . notify (
{
title : 'My awesome title' ,
message : 'Hello from node, Mr. User!' ,
icon : path . join ( __dirname , 'coulson.jpg' ) , // Absolute path (doesn't work on balloons)
sound : true , // Only Notification Center or Windows Toasters
wait : true // Wait with callback, until user action is taken against notification, does not apply to Windows Toasters as they always wait or notify-send as it does not support the wait option
} ,
function ( err , response , metadata ) {
// Response is response from notification
// Metadata contains activationType, activationAt, deliveredAt
}
) ;
notifier . on ( 'click' , function ( notifierObject , options , event ) {
// Triggers if `wait: true` and user clicks notification
} ) ;
notifier . on ( 'timeout' , function ( notifierObject , options ) {
// Triggers if `wait: true` and notification closes
} ) ;매우 세밀한 제어를 원한다면 각 리포터를 개별적으로 사용자 정의하여 다른 시스템에 대한 특정 옵션을 조정할 수 있습니다.
각 기자에 대한 문서는 아래를 참조하십시오.
예:
const NotificationCenter = require ( 'node-notifier/notifiers/notificationcenter' ) ;
new NotificationCenter ( options ) . notify ( ) ;
const NotifySend = require ( 'node-notifier/notifiers/notifysend' ) ;
new NotifySend ( options ) . notify ( ) ;
const WindowsToaster = require ( 'node-notifier/notifiers/toaster' ) ;
new WindowsToaster ( options ) . notify ( ) ;
const Growl = require ( 'node-notifier/notifiers/growl' ) ;
new Growl ( options ) . notify ( ) ;
const WindowsBalloon = require ( 'node-notifier/notifiers/balloon' ) ;
new WindowsBalloon ( options ) . notify ( ) ;또는 여러 기자를 사용하는 경우 (또는 게으른 경우) :
// NOTE: Technically, this takes longer to require
const nn = require ( 'node-notifier' ) ;
new nn . NotificationCenter ( options ) . notify ( ) ;
new nn . NotifySend ( options ) . notify ( ) ;
new nn . WindowsToaster ( options ) . notify ( options ) ;
new nn . WindowsBalloon ( options ) . notify ( options ) ;
new nn . Growl ( options ) . notify ( options ) ; NotificationCenter terminal-notifier 와 동일한 사용 및 매개 변수 설정.
기본 알림 센터에는 MACOS 버전 10.8 이상이 필요합니다. 이전 버전이 있으면 Growl이 폴백이됩니다. Growl이 설치되지 않으면 콜백에서 오류가 반환됩니다.
node-notifier terminal-notifier 주위를 감싸기 때문에 속성을 notify 메소드에 전달하여 terminal-notifier 할 수있는 모든 것을 수행 할 수 있습니다.
예를 들어:
terminal-notifier -message 라고 말하면 {message: 'Foo'} 수행 할 수 있습니다.terminal-notifier -list ALL 라고 말하면 {list: 'ALL'} 수행 할 수 있습니다.알림은이 모듈의 주요 초점이므로 목록 및 활성화는 작동하지만 문서화되지는 않습니다.
const NotificationCenter = require ( 'node-notifier' ) . NotificationCenter ;
var notifier = new NotificationCenter ( {
withFallback : false , // Use Growl Fallback if <= 10.8
customPath : undefined // Relative/Absolute path to binary if you want to use your own fork of terminal-notifier
} ) ;
notifier . notify (
{
title : undefined ,
subtitle : undefined ,
message : undefined ,
sound : false , // Case Sensitive string for location of sound file, or use one of macOS' native sounds (see below)
icon : 'Terminal Icon' , // Absolute Path to Triggering Icon
contentImage : undefined , // Absolute Path to Attached Image (Content Image)
open : undefined , // URL to open on Click
wait : false , // Wait for User Action against Notification or times out. Same as timeout = 5 seconds
// New in latest version. See `example/macInput.js` for usage
timeout : 5 , // Takes precedence over wait if both are defined.
closeLabel : undefined , // String. Label for cancel button
actions : undefined , // String | Array<String>. Action label or list of labels in case of dropdown
dropdownLabel : undefined , // String. Label to be used if multiple actions
reply : false // Boolean. If notification should take input. Value passed as third argument in callback and event emitter.
} ,
function ( error , response , metadata ) {
console . log ( response , metadata ) ;
}
) ; 참고 : wait 옵션은 timeout: 5 . 이것은 단지 5 초 동안 타임 아웃을 설정합니다. 그것은 알림을 끈적하게 만들지 않습니다 !
버전 6.0 기준으로 애플리케이션이 올바르게 닫히도록 기본 timeout 10 가 있습니다. timeout 제거하고 즉시 종료 된 알림 (작업을 지원하지 않음)을 사용하려면 timeout false 로 설정하십시오. action 사용하는 경우 사용자가 응답 할 시간이되도록 timeout 높은 값으로 설정하는 것이 좋습니다.
예외 : reply 정의되면 timeout 높은 값으로 설정하거나 전혀 아무것도하지 않는 것이 좋습니다.
MACOS 알림 : icon , contentImage 및 모든 형태의 reply / actions 에는 MACOS 10.9가 필요합니다.
사운드는 Basso , Blow , Bottle , Frog , Funk , Glass , Hero , Morse , Ping , Pop , Purr , Sosumi , Submarine , Tink 중 하나 일 수 있습니다.
sound 단순히 true 이라면 Bottle 사용됩니다.
또한 참조 :
사용자 정의 경로 설명
customPath terminal-notifier 의 포크/커스텀 버전의 이진에 대한 상대적 또는 절대 경로의 값을 취합니다.
예 : ./vendor/mac.noindex/terminal-notifier.app/Contents/MacOS/terminal-notifier
스포트라이트 설명
terminal-notifier.app mac.noindex 폴더에 있습니다.
WindowsToaster참고 : 기본 Windows 8 알림의 이미지에는 몇 가지 제한 사항이 있습니다.
이러한 제한은 토스트 알림 시스템 때문입니다. 좋은 팁은 path.join 또는 path.delimiter 와 같은 것을 사용하여 PATH를 교차 플랫폼으로 유지하는 것입니다.
Mikaelbr/Gulp-Notify#90 (댓글)에서
시스템> 알림 및 작업으로 이동하여 작동하게 할 수 있습니다. '토스트'앱에는 배너가 활성화되어 있어야합니다. ( '토스트'앱을 클릭하고 '표시 알림 배너'를 켜짐으로써 배너를 활성화 할 수 있습니다)
Windows 10 가을 제작자 업데이트 (버전 1709) 참고 :
Snoretoast는 기본 창 토스트를 얻는 데 사용됩니다!
기본 동작은 기본 토스터 응용 프로그램을 appID 로 갖는 것입니다. 이것은 예상대로 작동하지만 알림의 텍스트로 SnoreToast 보여줍니다.
가을 제작자 업데이트를 사용하면 Windows 10에 대한 알림은 유효한 appID 지정된 경우에만 예상대로 작동합니다. appID 는 앱을 설치하는 동안 등록 된 것과 정확히 동일한 값이어야합니다.
앱을 설치할 때 지정된 appID 의 레지스트리를 검색하여 앱의 ID를 찾을 수 있습니다. 예를 들어, 다람쥐 프레임 워크를 사용하는 경우 appID com.squirrel.your.app 와 같은 것입니다.
const WindowsToaster = require ( 'node-notifier' ) . WindowsToaster ;
var notifier = new WindowsToaster ( {
withFallback : false , // Fallback to Growl or Balloons?
customPath : undefined // Relative/Absolute path if you want to use your fork of SnoreToast.exe
} ) ;
notifier . notify (
{
title : undefined , // String. Required
message : undefined , // String. Required if remove is not defined
icon : undefined , // String. Absolute path to Icon
sound : false , // Bool | String (as defined by http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx)
id : undefined , // Number. ID to use for closing notification.
appID : undefined , // String. App.ID and app Name. Defaults to no value, causing SnoreToast text to be visible.
remove : undefined , // Number. Refer to previously created notification to close.
install : undefined // String (path, application, app id). Creates a shortcut <path> in the start menu which point to the executable <application>, appID used for the notifications.
} ,
function ( error , response ) {
console . log ( response ) ;
}
) ;Growl const Growl = require ( 'node-notifier' ) . Growl ;
var notifier = new Growl ( {
name : 'Growl Name Used' , // Defaults as 'Node'
host : 'localhost' ,
port : 23053
} ) ;
notifier . notify ( {
title : 'Foo' ,
message : 'Hello World' ,
icon : fs . readFileSync ( __dirname + '/coulson.jpg' ) ,
wait : false , // Wait for User Action against Notification
// and other growl options like sticky etc.
sticky : false ,
label : undefined ,
priority : undefined
} ) ;Growly 사용에 대한 자세한 정보를 참조하십시오.
WindowsBalloon 이전 버전의 Windows의 경우 작업 표시 줄 풍선이 사용됩니다 (폴백이 활성화되고 Growl이 실행되지 않는 한). Balloons Notifier는 notifu 라는 훌륭한 프로젝트를 사용합니다.
const WindowsBalloon = require ( 'node-notifier' ) . WindowsBalloon ;
var notifier = new WindowsBalloon ( {
withFallback : false , // Try Windows Toast and Growl first?
customPath : undefined // Relative/Absolute path if you want to use your fork of notifu
} ) ;
notifier . notify (
{
title : undefined ,
message : undefined ,
sound : false , // true | false.
time : 5000 , // How long to show balloon in ms
wait : false , // Wait for User Action against Notification
type : 'info' // The notification type : info | warn | error
} ,
function ( error , response ) {
console . log ( response ) ;
}
) ; Project HomePage : notifu 에서 전체 사용량을 참조하십시오.
NotifySend 참고 : notify-send wait 플래그를 지원하지 않습니다.
const NotifySend = require ( 'node-notifier' ) . NotifySend ;
var notifier = new NotifySend ( ) ;
notifier . notify ( {
title : 'Foo' ,
message : 'Hello World' ,
icon : __dirname + '/coulson.jpg' ,
wait : false , // Defaults no expire time set. If true expire time of 5 seconds is used
timeout : 10 , // Alias for expire-time, time etc. Time before notify-send expires. Defaults to 10 seconds.
// .. and other notify-send flags:
'app-name' : 'node-notifier' ,
urgency : undefined ,
category : undefined ,
hint : undefined
} ) ; Man Page notify-send(1) 의 플래그 및 옵션을 참조하십시오.
node-notifier 오픈 소스 소프트웨어를 통해 가능합니다. 모든 모듈 node-notifier 사용하는 데 매우 특별한 감사를드립니다.
terminal-notifierSnoretoastnotifugrowlyAraxeus 의이 문제를 참조하십시오.
SnoreToast 텍스트 Windows 섹션의 "Windows 10 Fall Creators Update"에 대한 참고 사항을 참조하십시오. 짧은 답변 : appID 업데이트하십시오.
WSL2 내에 알림이 표시되지 않으면 EXE 공급 업체 파일 (SnoreToast)의 권한을 변경해야 할 수도 있습니다. 자세한 내용은 문제를 참조하십시오
TMUX 세션 내에서 node-notifier 사용하면 시스템에 매달릴 수 있습니다. 이것은이 의견에 설명 된 단계를 따르면 해결할 수 있습니다.
여기에 더 많은 정보가 있습니다 #61 (댓글).
node-notifier 의 구성 객체에서 아이콘을 정의하더라도 알림에 작은 터미널 아이콘이 표시됩니다 (이 문서 상단의 예 참조).
이것이 MACOS에 대한 알림이 작동하는 방식입니다. 그들은 항상 알림을 시작하는 부모 응용 프로그램의 아이콘을 보여줍니다. node-notifier 의 경우 terminal-notifier 개시제이며 터미널 아이콘이 아이콘으로 정의되어 있습니다.
사용자 정의 아이콘을 정의하려면 terminal-notifier 포크하고 아이콘으로 사용자 정의 버전을 작성해야합니다.
자세한 정보 #71은 문제 #71을 참조하십시오.
전자 앱을 asar 로 포장하는 경우 node-notifier 로드되지 않습니다.
ASAR의 작동 방식으로 인해 asar 내에서 이진을 실행할 수 없습니다. 간단한 솔루션으로 앱을 ASAR에 포장 할 때는 node-notifier 의 vendor/ 폴더 --unpack 모듈이 여전히 알림 바이너리에 액세스 할 수 있는지 확인하십시오.
다음 명령으로 그렇게 할 수 있습니다.
asar pack . app.asar --unpack " ./node_modules/node-notifier/vendor/** " 또는 ASAR을 직접 사용하지 않고 electron-builder 사용하는 경우 다음과 같이 package.json 에 build 객체를 추가하십시오.
...
build: {
asarUnpack: [
' ./node_modules/node-notifier/**/* ' ,
]
},
...PKG 모듈을 사용하는 문제의 경우. 이 문제를 확인하십시오 : #220 (댓글)
webpack 내부에서 node-notifier 사용하는 경우 아래 스 니펫을 webpack.config.js 에 추가해야합니다.
node-notifier 바이너리에서 알림을로드하므로 상대 파일 경로가 필요하기 때문에 필요합니다. Webpack이 모듈을 컴파일하면 파일 디렉토리를 억제하여 특정 플랫폼에서 node-notifier 오류가 발생합니다.
이 문제를 해결하려면 웹 팩을 구성하여 상대 파일 디렉토리를 유지할 수 있습니다. 다음 코드를 webpack.config.js 에 추가하십시오.
node: {
__filename : true ,
__dirname : true
} 이 패키지는 MIT 라이센스를 사용하여 라이센스가 부여됩니다.
Snoretoast와 Notifu는 MIT 라이센스, LGPL-3 및 BSD 3-Clause와 구체적으로 일치하지 않는 공급 버전의 라이센스를 보유하고 있습니다. 우리는 변호사가 아니지만 우리가 선택한 라이센스를 사용 하여이 패키지를 공개하면서 해당 라이센스의 약관을 준수하기 위해 최선을 다했습니다.