Tim*_*m K 7 macos node.js node-webkit
我已经为我的node-webkit应用程序创建了一个函数来触发OS X通知.它工作得很好但我想知道我是否可以设置系统或自定义声音而不是经典的iPhone boing声音?
我查看了Mozzila的官方通知API文档(https://developer.mozilla.org/en-US/docs/Web/API/notification)并且没有声音选项,但是可能有node-webkit植入该功能(无法想象他们没有),但如果他们这样做,我似乎无法找到任何关于它的文件.
所以我的问题是,node-webkit中是否有通知的声音选项?
function notif(title ,tekst, url){
var notice = new Notification(title, {
body: tekst
});
notice.onshow = function(evt) {
setTimeout(function(){notice.close()}, 5000);
}
notice.onclick = function(evt) {
gui.Shell.openExternal(url);
setTimeout(function(){notice.close()}, 1000);
};
}
Run Code Online (Sandbox Code Playgroud)
在最近的node-webkit pull请求中修复/删除了不需要的iPhone声音并将其释放.
至于生成我自己的声音,我使用原始通知对象周围的包装器,这样每当我调用notification show命令时,我也会播放声音,视情况而定.
/**
* Use composition to expand capabilities of Notifications feature.
*/
function NotificationWrapper(appIcon, title, description, soundFile) {
/**
* A path to a sound file, like /sounds/notification.wav
*/
function playSound(soundFile) {
if(soundFile === undefined) return;
var audio = document.createElement('audio');
audio.src = soundFile;
audio.play();
audio = undefined;
}
/**
* Show the notification here.
*/
var notification = new window.Notification(title, {
body: description,
icon: appIcon
});
/**
* Play the sound.
*/
playSound(soundFile);
/**
* Return notification object to controller so we can bind click events.
*/
return notification;
}
Run Code Online (Sandbox Code Playgroud)
要使用它,我们只需使用new关键字调用它:
var myNotification = new NotificationWrapper(
'#', // image icon path goes here
'node-webkit is awesome',
'Especially now that I can use my own sounds',
'/sounds/notification.wav'
);
myNotification.addEventListener('click', function() {
console.log('You clicked the notification.');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2199 次 |
| 最近记录: |