代码之家  ›  专栏  ›  技术社区  ›  johnmayer

Chrome Progress Rich通知状态不会提升

  •  0
  • johnmayer  · 技术社区  · 7 年前

    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);
      });
    };  
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   woxxom    7 年前

    当前您正在分配 progress 到setInterval返回的任何值 .

    chrome.notifications.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);
      });
    };
    
    推荐文章