Rich通知状态不会上移

Rich通知状态不会上移

本文介绍了Chrome Progress Rich通知状态不会上移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试制作Chrome浏览器进度Rich Notification,但状态栏不会移动.

I tried making a Chrome progress Rich Notification but the status bar won't move.

我认为这段代码会起作用.状态栏每40毫秒上升1%.通知会在4秒钟后消失(也可能是100%).我认为我的 setInterval

I would think this code would work. The status bar will go up by 1% every 40ms. The notification disappears after 4 seconds (happens to be 100% too). I think there is something wrong with my setInterval

var notifyStatus = function(title, message) {
  var k = 0;
  chrome.notifications.create('', {
    'type':    'progress',
    'iconUrl': 'images/icon128.png',
    'title':   title,
    'message': message || '',
    'progress': setInterval(function() {
        if (k>100) {k;}
        else {k++;}
    },40)
  }, function(nid) {
    // Automatically close the notification in 4 seconds.
    window.setTimeout(function() {
      chrome.notifications.clear(nid);
    }, 4000);
  });
};

推荐答案

当前,您正在将 progress 分配给setInterval仅返回一次 的任何值.

Currently you're assigning progress to whatever value setInterval returns just once.

您需要使用 chrome.notifications每40毫秒用新的进度值更新通知..update :

var notifyStatus = function(title, message, timeout) {
  chrome.notifications.create({
    type: 'progress',
    iconUrl: 'images/icon128.png',
    title: title,
    message: message || '',
    progress: 0
  }, function(id) {
    // Automatically close the notification in 4 seconds by default
    var progress = 0;
    var interval = setInterval(function() {
      if (++progress <= 100) {
        chrome.notifications.update(id, {progress: progress}, function(updated) {
          if (!updated) {
            // the notification was closed
            clearInterval(interval);
          }
        });
      } else {
        chrome.notifications.clear(id);
        clearInterval(interval);
      }
    }, (timeout || 4000) / 100);
  });
};

这篇关于Chrome Progress Rich通知状态不会上移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:15