Kev*_*ang 2 javascript google-chrome-extension
我希望我的chrome扩展程序可以使用notification.id,并且:
clear()然后调用create()是不理想的,因为动画在视觉上对于两者remove()和create()方法都是不和谐的,我想在没有动画的情况下进行更新.此外,显然,呼叫update()消失的通知不会做任何事情.
有没有简单的方法来实现这个?
编辑:由于删除了Chrome的通知中心,此方法不再适用于ChromeOS以外的任何平台.
解决它的可能想法包括requireInteraction: true在通知上使用标志来完全控制通知生命周期.
重新显示通知有一个肮脏的技巧.如果将通知的优先级更改为更高的值,则会重新显示该通知的优先级(如果存在).
function createOrUpdate(id, options, callback) {
// Try to lower priority to minimal "shown" priority
chrome.notifications.update(id, {priority: 0}, function(existed) {
if(existed) {
var targetPriority = options.priority || 0;
options.priority = 1;
// Update with higher priority
chrome.notifications.update(id, options, function() {
chrome.notifications.update(id, {priority: targetPriority}, function() {
callback(true); // Updated
});
});
} else {
chrome.notifications.create(id, options, function() {
callback(false); // Created
});
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1297 次 |
| 最近记录: |