mkiol / GNotifier

Thunderbird add-on that replaces built-in notifications with the OS native notifications
https://addons.mozilla.org/thunderbird/addon/gnotifier/
GNU General Public License v3.0
164 stars 25 forks source link

Attempt at getting notifications for some folders. #127

Closed pd5rm closed 8 years ago

pd5rm commented 8 years ago

THIS CODE IS BROKEN.

It seems to crash when I package it into an XPI, and try to load the preferences screen.

Note: this is my first attempt at XPIs, Thunderbird API, and JS. ;-)

mkiol commented 8 years ago

Very nice! It works for me. I tested it on my Linux machine and had no problems.

One remark. If foldersIncluded is empty, each notification is blocked. IMHO, empty foldersIncluded should indicate that filtering is disabled, so no notification should be blocked.

pd5rm commented 8 years ago

Really, that's great! Can you tell me how to package a xpi? I was copy/pasting the js file over an unzipped xpi.

Yeah, I agree. If foldersIncluded is empty, then all notifications should pass through.

mkiol commented 8 years ago

Can you tell me how to package a xpi?

There is jpm tool. To create xpi package, run under the source directory the jpm xpi command.

pd5rm commented 8 years ago

Thanks, I used the jpm tool to build and install.

I made the empty setting change you requested.

I'm still not able to get it working right. If I specify "inbox", and send mail to myself I don't see it notify. If I remove the inbox item from the list, it sends the notification.

I figured it was name of the folder not matching, but I couldn't get the console.log to print stuff out in the Thunderbird error console.

mkiol commented 8 years ago

The issue was in for-in loop. It behaves in javascript slightly different from what you might expect. Here is my version of isFolderAllowed:

function isFolderAllowed(folder) {
  var sps = require("sdk/simple-prefs").prefs;
  var foldersAllowed = sps['foldersAllowedList'];
  if (foldersAllowed !== "") {
    var foldersAllowedList = foldersAllowed.split(",");
    for (var i = 0; i < foldersAllowedList.length; i++) {
      if (folder.prettiestName == foldersAllowedList[i].trim())
        return true;
     }
  }
  else {
     return true;
  }
  return false;
}

To enable console.log, follow this instruction.

Looking forward for your next update :-)

pd5rm commented 8 years ago

Thanks for your help in debugging. I've added some of your style suggestions.

This code seems to work for me. I'll test on my setup for a couple days.

pd5rm commented 8 years ago

Note. I had to enable the 'app' object at top-level to get logging working. I couldn't find loglevel in TB config to make it output all log level for console.

mkiol commented 8 years ago

Cool. Thanks for your contribution :-)

mkiol commented 8 years ago

I couldn't find loglevel in TB config to make it output all log level for console.

To make it work without 'app', you have to create in about:config new entry extensions.sdk.console.logLevel with value all. In general, using this 'app' interface is not super great idea because it is not supported in Firefox - it only works in TB.

mkiol commented 7 years ago

FYI In 601bbd2 commit, I extended filtering functionality. So now, optionally, you can define also name of the account. Example: "My email|Inbox, My folder" will only allow notifications from "Inbox" folder under "My email" account and from any folder with name "My folder".