thunderbird / webext-experiments

WebExtension Experiments for Thunderbird
29 stars 14 forks source link

Calendar Settings API for categories #42

Open opto opened 2 months ago

opto commented 2 months ago

We can get the categories attached to items. It would be good to get a list of possible categories, colors etc, to set new ones and have the corresponding events.

Thanks Klaus/opto

kewisch commented 2 months ago

Proposal as follows. I wanted to model this after the BrowserSettings API, but it isn't versatile enough for multi-entry settings like this. We can still put it in a settings namespace where we can later add other BrowserSettings type settings. I'm not sure we should key it on the name of the category, but it seems most logical given this is the unique key in the app and it doesn't make sense to have two categories with the same name.

@jobisoft what do you think?

let categories = await messenger.calendar.settings.categories.getAll();
/*
  [{
    name: "Meeting",
    color: "#FFFF66"
  }, {
    ...
  }]
*/

let mtg = await messenger.calendar.settings.categories.get("Meeting");
/*
  {
    name: "Meeting",
    color: "#FFFF66"
  }
*/

await messenger.calendar.settings.categories.create({
  name: "Meeting 2",
  color: "#FF0000"
});

// Update to turn off the "use color" option
await messenger.calendar.settings.categories.update("Meeting 2", {
  color: null
});

await messenger.calendar.settings.categories.remove("Meeting");

messenger.calendar.settings.categories.onCreated.addListener((category) => {
  console.log(`Category ${category.name} created with color ${category.color}`);
});

messenger.calendar.settings.categories.onUpdated.addListener((category) => {
  console.log(`Category ${category.name} updated with color ${category.color}`);
});

messenger.calendar.settings.categories.onRemoved.addListener((name) => {
  // We could pass the category verbatim here as well.
  console.log(`Category ${name} removed`);
});
opto commented 2 months ago

fine, thanks. And please add events on create, update, etc., so that they can be propagated elsewhere. (That is missing on the tags, for example, I can propagate new tags only when they are applied to a message, but on webext I cannot discover when tags are added, updated, removed etc.)

kewisch commented 2 months ago

Good point, added those to my last comment.