Skip to content

Commit

Permalink
flush the cache on changes of enableColors
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschz committed Oct 28, 2023
1 parent cc72a16 commit 7658166
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"message": "Force use of plain text in event descriptions"
},
"settings.enableColors": {
"message": "Enable support for event colors (experimental; calendars must be unsubscribed, Thunderbird restarted (?), and the calendars resubscribed)"
"message": "Enable support for event colors (experimental; enabling/disabling reloads all calendars)"
},

"eventdialog.conferenceLabel": {
Expand Down
12 changes: 9 additions & 3 deletions src/legacy/modules/gdataUI.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,26 @@ function register() {
},
});

let { doEnableColors, doDisableColors, getMessenger } = ChromeUtils.import(
let { doEnableColors, doDisableColors, flushCache, getMessenger } = ChromeUtils.import(
"resource://gdata-provider/legacy/modules/gdataUtils.jsm"
);

let messenger = getMessenger();
messenger.storage.onChanged.addListener((settings, _target) => {
if ("settings.enableColors" in settings) {
if (settings["settings.enableColors"].newValue) {
// check for true and false explicitly, since `undefined` can also happen
if (settings["settings.enableColors"].newValue === true) {
doEnableColors();
} else {
} else if (settings["settings.enableColors"].newValue === false) {
doDisableColors();
}
// We must delete the cache and reload all calendars from the source in order
// to add/remove the color categories. Restarting Thunderbird is insufficient
// because the locally cached calendar entries lack the color information.
flushCache();
}
});

let enableColors = messenger.gdataSyncPrefs.get("settings.enableColors", false);
if (enableColors) {
doEnableColors();
Expand Down
13 changes: 13 additions & 0 deletions src/legacy/modules/gdataUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var EXPORTED_SYMBOLS = [
"spinEventLoop",
"doEnableColors",
"doDisableColors",
"flushCache",
"getMessenger",
];

Expand Down Expand Up @@ -1525,6 +1526,18 @@ function doDisableColors() {
Services.prefs.setStringPref("calendar.categories.names", calendarCategories);
}

/**
* Deletes the local Google calendar cache and reloads all Google calendars from the source.
*/
function flushCache() {
let cals = cal.manager.wrappedJSObject.getCalendars();
for (let calendar of cals) {
if (calendar.type == "gdata") {
calendar.mUncachedCalendar.resetLog();
}
}
}

class SyncPrefs {
prefs = {};

Expand Down

0 comments on commit 7658166

Please sign in to comment.