From 0cd492662c87677ac7133953d3c1b6662cbda018 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Wed, 6 Sep 2023 22:04:41 +0200 Subject: [PATCH 1/2] Update minimal TB to 91 --- app/SysTray-X/SysTray-X-app/preferences.cpp | 5 - app/SysTray-X/SysTray-X-app/preferences.h | 5 - .../SysTray-X-app/preferencesdialog.cpp | 17 - .../SysTray-X-app/preferencesdialog.h | 5 - app/SysTray-X/SysTray-X-app/systrayx.cpp | 1 - dist/arch/gnome/PKGBUILD | 4 +- dist/arch/kde/PKGBUILD | 4 +- dist/arch/minimal/PKGBUILD | 4 +- dist/deb/gnome/debian.control | 8 +- dist/deb/kde/debian.control | 8 +- dist/deb/minimal/debian.control | 8 +- dist/rpm/gnome/systray-x-gnome.spec | 12 +- dist/rpm/kde/systray-x.spec | 13 +- dist/rpm/minimal/systray-x-minimal.spec | 12 +- webext/background.js | 114 ++--- webext/js/defaults.js | 35 +- webext/js/folderChange.js | 457 ------------------ webext/js/options_accounts.js | 49 +- webext/manifest.json | 10 +- webext/modules/folderChange.jsm | 6 - webext/options.js | 158 ++---- webext/schema_folderchange.json | 114 ----- 22 files changed, 137 insertions(+), 912 deletions(-) delete mode 100644 webext/js/folderChange.js delete mode 100644 webext/modules/folderChange.jsm delete mode 100644 webext/schema_folderchange.json diff --git a/app/SysTray-X/SysTray-X-app/preferences.cpp b/app/SysTray-X/SysTray-X-app/preferences.cpp index 971889f..a237ac9 100644 --- a/app/SysTray-X/SysTray-X-app/preferences.cpp +++ b/app/SysTray-X/SysTray-X-app/preferences.cpp @@ -173,11 +173,6 @@ const QString& Preferences::getBrowserVersion() const void Preferences::setBrowserVersion( const QString version ) { m_browser_version = version; - - /* - * Tell the world the new preference - */ - emit signalBrowserVersion(); } diff --git a/app/SysTray-X/SysTray-X-app/preferences.h b/app/SysTray-X/SysTray-X-app/preferences.h index ca09123..260f9c9 100644 --- a/app/SysTray-X/SysTray-X-app/preferences.h +++ b/app/SysTray-X/SysTray-X-app/preferences.h @@ -620,11 +620,6 @@ class Preferences : public QObject */ void signalConsole( QString message ); - /** - * @brief signalBrowserVersion. Signal the browser version. - */ - void signalBrowserVersion(); - /** * @brief signalMinimizeTypeChange. Signal a minimize type change. */ diff --git a/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp b/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp index 029fbdf..3969c29 100644 --- a/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp +++ b/app/SysTray-X/SysTray-X-app/preferencesdialog.cpp @@ -779,23 +779,6 @@ void PreferencesDialog::slotDebugChange() } -/* - * Handle the browser version signal - */ -void PreferencesDialog::slotBrowserVersion() -{ - QString version = m_pref->getBrowserVersion(); - - if( version.section( '.', 0, 0 ).toInt() > 89 && version.section( '.', 0, 0 ).toInt() < 91) - { - /* - * Hide the count type for TB90 and up, not supported - */ - m_ui->countTypeGroupBox->setVisible( false ); - } -} - - /* * Handle the start minimized change signal */ diff --git a/app/SysTray-X/SysTray-X-app/preferencesdialog.h b/app/SysTray-X/SysTray-X-app/preferencesdialog.h index 03ebe41..f527c11 100644 --- a/app/SysTray-X/SysTray-X-app/preferencesdialog.h +++ b/app/SysTray-X/SysTray-X-app/preferencesdialog.h @@ -285,11 +285,6 @@ class PreferencesDialog : public QDialog */ void slotDebugChange(); - /** - * @brief slotBrowserVersion. Slot for handling the browser version signals. - */ - void slotBrowserVersion(); - /** * @brief slotMinimizeTypeChange. Slot for handling minimize type change signals. */ diff --git a/app/SysTray-X/SysTray-X-app/systrayx.cpp b/app/SysTray-X/SysTray-X-app/systrayx.cpp index 3d3eb73..2407f2a 100644 --- a/app/SysTray-X/SysTray-X-app/systrayx.cpp +++ b/app/SysTray-X/SysTray-X-app/systrayx.cpp @@ -115,7 +115,6 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) connect( m_preferences, &Preferences::signalCloseTypeChange, m_win_ctrl, &WindowCtrl::slotCloseTypeChange ); connect( m_preferences, &Preferences::signalStartMinimizedChange, m_win_ctrl, &WindowCtrl::slotStartMinimizedChange ); - connect( m_preferences, &Preferences::signalBrowserVersion, m_pref_dialog, &PreferencesDialog::slotBrowserVersion ); connect( m_preferences, &Preferences::signalDefaultIconTypeChange, m_pref_dialog, &PreferencesDialog::slotDefaultIconTypeChange ); connect( m_preferences, &Preferences::signalDefaultIconDataChange, m_pref_dialog, &PreferencesDialog::slotDefaultIconDataChange ); connect( m_preferences, &Preferences::signalHideDefaultIconChange, m_pref_dialog, &PreferencesDialog::slotHideDefaultIconChange ); diff --git a/dist/arch/gnome/PKGBUILD b/dist/arch/gnome/PKGBUILD index 2788453..cc8fb21 100644 --- a/dist/arch/gnome/PKGBUILD +++ b/dist/arch/gnome/PKGBUILD @@ -4,14 +4,14 @@ pkgname=systray-x-gnome pkgver=0 pkgrel=0 epoch=1 -pkgdesc='A system tray extension for Thunderbird 68+ (GNOME)' +pkgdesc='A system tray extension for Thunderbird (GNOME)' arch=(x86_64) url=https://github.com/Ximi1970/systray-x license=(MPL-2.0) depends=( 'qt5-base' 'gnome-shell-extension-appindicator' - 'thunderbird>=68' + 'thunderbird>=91' 'thunderbird<118' ) makedepends=( diff --git a/dist/arch/kde/PKGBUILD b/dist/arch/kde/PKGBUILD index 40a6970..0d0ff48 100644 --- a/dist/arch/kde/PKGBUILD +++ b/dist/arch/kde/PKGBUILD @@ -4,14 +4,14 @@ pkgname=systray-x pkgver=0 pkgrel=0 epoch=1 -pkgdesc='A system tray extension for Thunderbird 68+ (KDE)' +pkgdesc='A system tray extension for Thunderbird (KDE)' arch=(x86_64) url=https://github.com/Ximi1970/systray-x license=(MPL-2.0) depends=( 'qt5-base' 'knotifications' - 'thunderbird>=68' + 'thunderbird>=91' 'thunderbird<118' ) makedepends=( diff --git a/dist/arch/minimal/PKGBUILD b/dist/arch/minimal/PKGBUILD index 8874b4c..a90657c 100644 --- a/dist/arch/minimal/PKGBUILD +++ b/dist/arch/minimal/PKGBUILD @@ -4,13 +4,13 @@ pkgname=systray-x-minimal pkgver=0 pkgrel=0 epoch=1 -pkgdesc='A system tray extension for Thunderbird 68+ (Unity/XFCE/other)' +pkgdesc='A system tray extension for Thunderbird (Unity/XFCE/other)' arch=(x86_64) url=https://github.com/Ximi1970/systray-x license=(MPL-2.0) depends=( 'qt5-base' - 'thunderbird>=68' + 'thunderbird>=91' 'thunderbird<118' ) makedepends=( diff --git a/dist/deb/gnome/debian.control b/dist/deb/gnome/debian.control index e285f70..0102f88 100644 --- a/dist/deb/gnome/debian.control +++ b/dist/deb/gnome/debian.control @@ -6,14 +6,16 @@ Build-Depends: debhelper (>= 4.1.16), zip, g++, libx11-dev, qt5-qmake, qtbase5-d Package: systray-x-gnome Architecture: any -Depends: ${shlibs:Depends}, gnome-shell-extension-appindicator, thunderbird (>= 1:68), thunderbird (< 1:118) -Description: SysTray-X is a system tray extension for Thunderbird 68+ (GNOME). +Depends: ${shlibs:Depends}, gnome-shell-extension-appindicator, thunderbird (>= 1:91), thunderbird (< 1:118) +Description: SysTray-X is a system tray extension for Thunderbird (GNOME). This version is optimized for the GNOME desktop. The add-on uses the WebExtension API's to control an external system dependent system tray application. The add-on and system tray application can do: * custom new mail icon - * display number of unread mails + * display number of unread /new mails + * optional new mail indicator (icon or shading) + * run app on start or close * show / hide Thunderbird (minimize) * minimizing hides to tray * minimize on startup diff --git a/dist/deb/kde/debian.control b/dist/deb/kde/debian.control index 35fb600..56b044b 100644 --- a/dist/deb/kde/debian.control +++ b/dist/deb/kde/debian.control @@ -6,14 +6,16 @@ Build-Depends: debhelper (>= 4.1.16), zip, g++, libx11-dev, qt5-qmake, qtbase5-d Package: systray-x Architecture: any -Depends: ${shlibs:Depends}, thunderbird (>= 1:68), thunderbird (< 1:118) -Description: SysTray-X is a system tray extension for Thunderbird 68+ (KDE). +Depends: ${shlibs:Depends}, thunderbird (>= 1:91), thunderbird (< 1:118) +Description: SysTray-X is a system tray extension for Thunderbird (KDE). This version is optimized for the KDE desktop. The add-on uses the WebExtension API's to control an external system dependent system tray application. The add-on and system tray application can do: * custom new mail icon - * display number of unread mails + * display number of unread /new mails + * optional new mail indicator (icon or shading) + * run app on start or close * show / hide Thunderbird (minimize) * minimizing hides to tray * minimize on startup diff --git a/dist/deb/minimal/debian.control b/dist/deb/minimal/debian.control index 4846836..89af9b0 100644 --- a/dist/deb/minimal/debian.control +++ b/dist/deb/minimal/debian.control @@ -6,14 +6,16 @@ Build-Depends: debhelper (>= 4.1.16), zip, g++, libx11-dev, qt5-qmake, qtbase5-d Package: systray-x-minimal Architecture: any -Depends: ${shlibs:Depends}, thunderbird (>= 1:68), thunderbird (< 1:118) -Description: SysTray-X is a system tray extension for Thunderbird 68+ (non-GNOME,non-KDE). +Depends: ${shlibs:Depends}, thunderbird (>= 1:91), thunderbird (< 1:118) +Description: SysTray-X is a system tray extension for Thunderbird (non-GNOME,non-KDE). This version is for non-KDE and non-GNOME desktops. The add-on uses the WebExtension API's to control an external system dependent system tray application. The add-on and system tray application can do: * custom new mail icon - * display number of unread mails + * display number of unread /new mails + * optional new mail indicator (icon or shading) + * run app on start or close * show / hide Thunderbird (minimize) * minimizing hides to tray * minimize on startup diff --git a/dist/rpm/gnome/systray-x-gnome.spec b/dist/rpm/gnome/systray-x-gnome.spec index 9ab4d3e..8a25afb 100644 --- a/dist/rpm/gnome/systray-x-gnome.spec +++ b/dist/rpm/gnome/systray-x-gnome.spec @@ -18,7 +18,7 @@ Name: systray-x-gnome Version: 0 Release: 0 -Summary: A system tray extension for Thunderbird 68+ (GNOME) +Summary: A system tray extension for Thunderbird (GNOME) License: MPL-2.0 Group: Productivity/Networking/Email/Clients URL: https://github.com/Ximi1970/systray-x @@ -32,15 +32,15 @@ BuildRequires: pkgconfig(Qt5DBus) BuildRequires: pkgconfig(x11) Requires: gnome-shell-extension-appindicator %if 0%{?fedora_version} || 0%{?centos_version} -Requires: thunderbird >= 68 +Requires: thunderbird >= 91 Requires: thunderbird < 118 %else -Requires: MozillaThunderbird >= 68 +Requires: MozillaThunderbird >= 91 Requires: MozillaThunderbird < 118 %endif %description -SysTray-X is a system tray extension for Thunderbird 68+. +SysTray-X is a system tray extension for Thunderbird. This version is optimized for the GNOME desktop. The add-on uses the WebExtension API's to control an external system dependent system tray application. @@ -48,7 +48,9 @@ dependent system tray application. The add-on and system tray application can do: * custom new mail icon - * display number of unread mails + * display number of unread /new mails + * optional new mail indicator (icon or shading) + * run app on start or close * show / hide Thunderbird (minimize) * minimizing hides to tray * minimize on startup diff --git a/dist/rpm/kde/systray-x.spec b/dist/rpm/kde/systray-x.spec index fe29c30..b39b603 100644 --- a/dist/rpm/kde/systray-x.spec +++ b/dist/rpm/kde/systray-x.spec @@ -18,7 +18,7 @@ Name: systray-x Version: 0 Release: 0 -Summary: A system tray extension for Thunderbird 68+ (KDE) +Summary: A system tray extension for Thunderbird (KDE) License: MPL-2.0 Group: Productivity/Networking/Email/Clients URL: https://github.com/Ximi1970/systray-x @@ -33,17 +33,17 @@ BuildRequires: pkgconfig(x11) %if 0%{?fedora_version} || 0%{?centos_version} BuildRequires: kf5-knotifications-devel Requires: kf5-knotifications -Requires: thunderbird >= 68 +Requires: thunderbird >= 91 Requires: thunderbird < 118 %else BuildRequires: knotifications-devel Requires: libKF5Notifications5 -Requires: MozillaThunderbird >= 68 +Requires: MozillaThunderbird >= 91 Requires: MozillaThunderbird < 118 %endif %description -SysTray-X is a system tray extension for Thunderbird 68+. +SysTray-X is a system tray extension for Thunderbird. This version is optimized for the KDE desktop. The add-on uses the WebExtension API's to control an external system dependent system tray application. @@ -51,8 +51,9 @@ dependent system tray application. The add-on and system tray application can do: * custom new mail icon - * display number of unread mails - * show / hide Thunderbird (minimize) + * display number of unread /new mails + * optional new mail indicator (icon or shading) + * run app on start or close * minimizing hides to tray * minimize on startup * minimize on close diff --git a/dist/rpm/minimal/systray-x-minimal.spec b/dist/rpm/minimal/systray-x-minimal.spec index 6236c19..67b5bb7 100644 --- a/dist/rpm/minimal/systray-x-minimal.spec +++ b/dist/rpm/minimal/systray-x-minimal.spec @@ -18,7 +18,7 @@ Name: systray-x-minimal Version: 0 Release: 0 -Summary: A system tray extension for Thunderbird 68+ (Unity/XFCE/other) +Summary: A system tray extension for Thunderbird (Unity/XFCE/other) License: MPL-2.0 Group: Productivity/Networking/Email/Clients URL: https://github.com/Ximi1970/systray-x @@ -31,15 +31,15 @@ BuildRequires: pkgconfig(Qt5Widgets) BuildRequires: pkgconfig(Qt5DBus) BuildRequires: pkgconfig(x11) %if 0%{?fedora_version} || 0%{?centos_version} -Requires: thunderbird >= 68 +Requires: thunderbird >= 91 Requires: thunderbird < 118 %else -Requires: MozillaThunderbird >= 68 +Requires: MozillaThunderbird >= 91 Requires: MozillaThunderbird < 118 %endif %description -SysTray-X is a system tray extension for Thunderbird 68+. +SysTray-X is a system tray extension for Thunderbird. This version is for non-KDE and non-GNOME desktops. The add-on uses the WebExtension API's to control an external system dependent system tray application. @@ -47,7 +47,9 @@ dependent system tray application. The add-on and system tray application can do: * custom new mail icon - * display number of unread mails + * display number of unread /new mails + * optional new mail indicator (icon or shading) + * run app on start or close * show / hide Thunderbird (minimize) * minimizing hides to tray * minimize on startup diff --git a/webext/background.js b/webext/background.js index a457b41..bc2249c 100644 --- a/webext/background.js +++ b/webext/background.js @@ -77,29 +77,19 @@ SysTrayX.Messaging = { await delay(startupDelay * 1000); // Get all accounts - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - SysTrayX.Messaging.accounts = await browser.accounts.list(); + SysTrayX.Messaging.accounts = await browser.accounts.list(false); - // Get folder tree - SysTrayX.Messaging.folderTree = getFolderTree( - SysTrayX.Messaging.accounts, - SysTrayX.Info.browserInfo + // Fill the sub folders using the folders API, they are not same... + for (let i = 0; i < SysTrayX.Messaging.accounts.length; ++i) { + const subFolders = await browser.folders.getSubFolders( + SysTrayX.Messaging.accounts[i], + true ); - } else { - SysTrayX.Messaging.accounts = await browser.accounts.list(false); - - // Fill the sub folders using the folders API, they are not same... - for (let i = 0; i < SysTrayX.Messaging.accounts.length; ++i) { - const subFolders = await browser.folders.getSubFolders( - SysTrayX.Messaging.accounts[i], - true - ); - SysTrayX.Messaging.accounts[i].folders = subFolders; - } - - console.debug("Accounts: " + JSON.stringify(SysTrayX.Messaging.accounts)); + SysTrayX.Messaging.accounts[i].folders = subFolders; } + console.debug("Accounts: " + JSON.stringify(SysTrayX.Messaging.accounts)); + // Get the filters (needs the accounts) const getFiltersPromise = () => new Promise((res) => res(getFilters())); SysTrayX.Messaging.filters = await getFiltersPromise(); @@ -108,61 +98,29 @@ SysTrayX.Messaging = { const getCountTypePromise = () => new Promise((res) => res(getCountType())); SysTrayX.Messaging.countType = await getCountTypePromise(); - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - // Set TB versionn - browser.folderChange.setVersion( - Number(SysTrayX.Info.browserInfo.majorVersion) - ); + browser.messages.onNewMailReceived.addListener( + SysTrayX.Messaging.listenerNewMail + ); - // Catch the unread / new mails - browser.folderChange.onUnreadMailChange.addListener(function (unread) { - SysTrayX.Messaging.unreadCb(unread); - }); + browser.folders.onCreated.addListener( + SysTrayX.Messaging.listenerFolderCreated + ); + browser.folders.onRenamed.addListener( + SysTrayX.Messaging.listenerFolderRenamed + ); + browser.folders.onDeleted.addListener( + SysTrayX.Messaging.listenerFolderDeleted + ); - browser.folderChange.onFolderChange.addListener(function ( - rootFolder, - parentFolder, - folder, - added - ) { - SysTrayX.Messaging.updateFilters( - rootFolder, - parentFolder, - folder, - added - ); - }); + // Get the mail count + const getCountPromise = () => + new Promise((res) => res(SysTrayX.Messaging.countMail())); + await getCountPromise(); - // Set the count type in the folderChange listener - browser.folderChange.setCountType(Number(SysTrayX.Messaging.countType)); - - // Set the filters in the folderChange listener - browser.folderChange.setFilters(SysTrayX.Messaging.filters); - } else { - browser.messages.onNewMailReceived.addListener( - SysTrayX.Messaging.listenerNewMail - ); - - browser.folders.onCreated.addListener( - SysTrayX.Messaging.listenerFolderCreated - ); - browser.folders.onRenamed.addListener( - SysTrayX.Messaging.listenerFolderRenamed - ); - browser.folders.onDeleted.addListener( - SysTrayX.Messaging.listenerFolderDeleted - ); - - // Get the mail count - const getCountPromise = () => - new Promise((res) => res(SysTrayX.Messaging.countMail())); - await getCountPromise(); - - // Set count listener - browser.folders.onFolderInfoChanged.addListener( - SysTrayX.Messaging.listenerFolderInfoChanged - ); - } + // Set count listener + browser.folders.onFolderInfoChanged.addListener( + SysTrayX.Messaging.listenerFolderInfoChanged + ); // Catch a folder change to reset the new counter browser.mailTabs.onDisplayedFolderChanged.addListener( @@ -344,12 +302,8 @@ SysTrayX.Messaging = { if ("filters" in changes && changes["filters"].newValue) { SysTrayX.Messaging.filters = changes["filters"].newValue; - - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - browser.folderChange.setFilters(SysTrayX.Messaging.filters); - } else { - getMailCount(); - } + + getMailCount(); } if ("closeType" in changes && changes["closeType"].newValue) { @@ -371,11 +325,7 @@ SysTrayX.Messaging = { if ("countType" in changes && changes["countType"].newValue) { SysTrayX.Messaging.countType = changes["countType"].newValue; - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - browser.folderChange.setCountType(Number(SysTrayX.Messaging.countType)); - } else { - getMailCount(); - } + getMailCount(); } if ("addonprefchanged" in changes && changes["addonprefchanged"].newValue) { diff --git a/webext/js/defaults.js b/webext/js/defaults.js index 63e4a72..fff7672 100644 --- a/webext/js/defaults.js +++ b/webext/js/defaults.js @@ -1,14 +1,9 @@ // // Get the prefered storage // -function storage(store) { - if (SysTrayX.Info.browserInfo.majorVersion < 91 || store === "sync") { - console.log("Using sync storage"); - return browser.storage.sync; - } else { +function storage() { console.log("Using local storage"); return browser.storage.local; - } } // @@ -229,30 +224,14 @@ async function getFilters() { if (inbox.length > 0) { let folder = {}; - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - // console.debug("Folder pre 91: " + JSON.stringify(inbox[0])); - folder = { - ...inbox[0], - accountName: account.name, - path: "/" + inbox[0].name, - version: SysTrayX.Info.version, - }; - delete folder.subFolders; + // console.debug("Folder 91+: " + JSON.stringify(inbox[0])); - filters.push({ - unread: true, - folder: folder, - }); - } else { - // console.debug("Folder 91+: " + JSON.stringify(inbox[0])); - - filters.push({ - accountId: inbox[0].accountId, - version: SysTrayX.Info.version, - folders: [inbox[0].path], - }); - } + filters.push({ + accountId: inbox[0].accountId, + version: SysTrayX.Info.version, + folders: [inbox[0].path], + }); } } diff --git a/webext/js/folderChange.js b/webext/js/folderChange.js deleted file mode 100644 index 370163a..0000000 --- a/webext/js/folderChange.js +++ /dev/null @@ -1,457 +0,0 @@ -/* eslint-disable object-shorthand */ - -const Ci = Components.interfaces; - -// Get various parts of the WebExtension framework that we need. -var { ExtensionCommon } = ChromeUtils.import( - "resource://gre/modules/ExtensionCommon.jsm" -); - -// You probably already know what this does. -var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); -var { MailServices } = ChromeUtils.import( - "resource:///modules/MailServices.jsm" -); -var { fixIterator } = ChromeUtils.import( - "resource:///modules/iteratorUtils.jsm" -); - -// ChromeUtils.import() works in experiments for core resource urls as it did -// in legacy add-ons. However, chrome:// urls that point to add-on resources no -// longer work, as the "chrome.manifest" file is no longer supported, which -// defined the root path for each add-on. Instead, ChromeUtils.import() needs -// a url generated by -// -// let url = context.extension.rootURI.resolve("path/to/file.jsm") -// -// Instead of taking the extension object from the context, you may generate -// the extension object from a given add-on ID as shown in the example below. -// This allows to import a JSM without context, for example inside another JSM. -// -var { ExtensionParent } = ChromeUtils.import( - "resource://gre/modules/ExtensionParent.jsm" -); -var extension = ExtensionParent.GlobalManager.getExtension( - "systray-x@Ximi1970" -); -var { folderChange } = ChromeUtils.import( - extension.rootURI.resolve("modules/folderChange.jsm") -); - -// This is the important part. It implements the functions and events defined in schema.json. -// The variable must have the same name you've been using so far, "myapi" in this case. -var folderChange = class extends ExtensionCommon.ExtensionAPI { - getAPI(context) { - console.log("folderChange API started"); - - // To be notified of the extension going away, call callOnClose with any object that has a - // close function, such as this one. - context.callOnClose(this); - - // - // Setup folder listener - // - SysTrayX.init(); - - return { - // Again, this key must have the same name. - folderChange: { - setVersion: async function (version) { - SysTrayX.setVersion(version); - }, - - setCountType: async function (type) { - SysTrayX.setCountType(type); - }, - - setFilters: async function (filters) { - SysTrayX.setFilters(filters); - }, - - onUnreadMailChange: new ExtensionCommon.EventManager({ - context, - name: "folderChange.onUnreadMailChange", - // In this function we add listeners for any events we want to listen to, and return a - // function that removes those listeners. To have the event fire in your extension, - // call fire.async. - register(fire) { - function callback(event, unread) { - return fire.async(unread); - } - - SysTrayX.add(callback); - return function () { - SysTrayX.remove(callback); - }; - }, - }).api(), - - onFolderChange: new ExtensionCommon.EventManager({ - context, - name: "folderChange.onFolderChange", - // In this function we add listeners for any events we want to listen to, and return a - // function that removes those listeners. To have the event fire in your extension, - // call fire.async. - register(fire) { - function callback(event, rootFolder, parentFolder, folder, added) { - return fire.async(rootFolder, parentFolder, folder, added); - } - - SysTrayX.addOnFolderChange(callback); - return function () { - SysTrayX.removeOnFolderChange(callback); - }; - }, - }).api(), - }, - }; - } - - close() { - /* - * Remove the folder listener - */ - SysTrayX.shutdown(); - - // This function is called if the extension is disabled or removed, or Thunderbird closes. - // We registered it with callOnClose, above. - console.log("folderChange API closed"); - - // Unload the JSM we imported above. This will cause Thunderbird to forget about the JSM, and - // load it afresh next time `import` is called. (If you don't call `unload`, Thunderbird will - // remember this version of the module and continue to use it, even if your extension receives - // an update.) You should *always* unload JSMs provided by your extension. - Cu.unload(extension.getURL("modules/folderChange.jsm")); - } -}; - -// A helpful class for listening to windows opening and closing. -// (This file had a lowercase E in Thunderbird 65 and earlier.) -var { ExtensionSupport } = ChromeUtils.import( - "resource:///modules/ExtensionSupport.jsm" -); - -var SysTrayX = { - MESSAGE_COUNT_TYPE_UNREAD: 0, - MESSAGE_COUNT_TYPE_NEW: 1, - - version: 0, - - countType: this.MESSAGE_COUNT_TYPE_UNREAD, - - initialized: false, - - accounts: undefined, - filters: undefined, - - currentMsgCount: null, - newMsgCount: null, - - callbackOnUnreadMailChange: undefined, - callbackOnFolderChange: undefined, - - init: function () { - if (this.initialized) { - console.warn("Folder listener already initialized"); - return; - } - - // Get the mail accounts using MailServices - this.getAccounts(); - - // Start listener - MailServices.mailSession.AddFolderListener( - this.mailSessionListener, - this.mailSessionListener.notificationFlags - ); - - this.initialized = true; - }, - - shutdown: function () { - if (!this.initialized) { - return; - } - - // Stop listener - MailServices.mailSession.RemoveFolderListener(this.mailSessionListener); - - this.initialized = false; - }, - - setVersion: function (version) { - this.version = version; - }, - - setCountType: function (type) { - if (type === 0) { - this.countType = this.MESSAGE_COUNT_TYPE_UNREAD; - } else if (type === 1) { - this.countType = this.MESSAGE_COUNT_TYPE_NEW; - } else console.log("Unknown count type: " + type); - - // Update count - this.updateMsgCountWithCb(); - }, - - setFilters: function (filters) { - this.filters = filters; - - // Update count - this.updateMsgCountWithCb(); - }, - - mailSessionListener: { - notificationFlags: - Ci.nsIFolderListener.added | - Ci.nsIFolderListener.removed | - Ci.nsIFolderListener.propertyFlagChanged | - Ci.nsIFolderListener.boolPropertyChanged | - Ci.nsIFolderListener.intPropertyChanged, - - OnItemAdded(parentItem, item) { - if (SysTrayX.callbackOnFolderChange) { - SysTrayX.callbackOnFolderChange( - "folder-changed", - parentItem.rootFolder.prettyName, - parentItem.prettyName, - item.prettyName, - true - ); - } - }, - - OnItemRemoved(parentItem, item) { - if (SysTrayX.callbackOnFolderChange) { - SysTrayX.callbackOnFolderChange( - "folder-changed", - parentItem.rootFolder.prettyName, - parentItem.prettyName, - item.prettyName, - false - ); - } - }, - - OnItemIntPropertyChanged(item, property, oldValue, newValue) { - // TotalUnreadMessages, BiffState (per server) - this.onMsgCountChange(item, property, oldValue, newValue); - }, - - OnItemBoolPropertyChanged: function (item, property, oldValue, newValue) { - // NewMessages (per folder) - this.onMsgCountChange(item, property, oldValue, newValue); - }, - - OnItemPropertyFlagChanged: function (item, property, oldFlag, newFlag) { - this.onMsgCountChange(item, property, oldFlag, newFlag); - }, - - onMsgCountChange: function (item, property, oldValue, newValue) { - let msgCountType = SysTrayX.countType; - - let prop = property.toString(); - if ( - prop === "TotalUnreadMessages" && - msgCountType === SysTrayX.MESSAGE_COUNT_TYPE_UNREAD - ) { - SysTrayX.updateMsgCountWithCb(); - } else { - if ( - prop === "NewMessages" && - msgCountType === SysTrayX.MESSAGE_COUNT_TYPE_NEW - ) { - if (oldValue === true && newValue === false) { - // https://bugzilla.mozilla.org/show_bug.cgi?id=727460 - item.setNumNewMessages(0); - } - SysTrayX.updateMsgCountWithCb(); - } - } - }, - }, - - updateMsgCountWithCb(callback) { - if (callback === undefined || !callback) { - callback = function (currentMsgCount, newMsgCount) { - if (SysTrayX.callbackOnUnreadMailChange) { - SysTrayX.callbackOnUnreadMailChange("unread-changed", newMsgCount); - } - }; - } - - let msgCountType = SysTrayX.countType; - if (msgCountType === SysTrayX.MESSAGE_COUNT_TYPE_UNREAD) { - this.countMessages("UnreadMessages"); - } else if (msgCountType === SysTrayX.MESSAGE_COUNT_TYPE_NEW) { - this.countMessages("HasNewMessages"); - } else console.error("Unknown message count type: " + msgCountType); - - // currentMsgCount and newMsgCount may be integers or bool, which do - // also support comparison operations - callback.call(this, this.currentMsgCount, this.newMsgCount); - this.currentMsgCount = this.newMsgCount; - }, - - countMessages(countType) { - this.newMsgCount = 0; - for (let accountServer of this.accounts) { - // if (accountServer.type === ACCOUNT_SERVER_TYPE_IM) { - // continue; - // } - - // if (excludedAccounts.indexOf(accountServer.key) >= 0) - // { - // continue; - // } - - this.applyToSubfolders( - accountServer.prettyName, - "", - accountServer.rootFolder, - true, - function (path, folder) { - this.msgCountIterate( - countType, - accountServer.prettyName, - path, - folder - ); - } - ); - } - }, - - applyToSubfolders(account, path, folder, recursive, fun) { - if (folder.hasSubFolders) { - let subFolders = folder.subFolders; - if (this.version < 87) { - while (subFolders.hasMoreElements()) { - let subFolder = subFolders.getNext().QueryInterface(Ci.nsIMsgFolder); - if (recursive && subFolder.hasSubFolders) - this.applyToSubfoldersRecursive( - account, - path, - subFolder, - recursive, - fun - ); - else fun.call(this, path, subFolder); - } - } else { - for (let i = 0; i < subFolders.length; ++i) { - let subFolder = subFolders[i].QueryInterface(Ci.nsIMsgFolder); - if (recursive && subFolder.hasSubFolders) - this.applyToSubfoldersRecursive( - account, - path, - subFolder, - recursive, - fun - ); - else fun.call(this, path, subFolder); - } - } - } - }, - - applyToSubfoldersRecursive(account, path, folder, recursive, fun) { - fun.call(this, path, folder); - this.applyToSubfolders( - account, - path + "/" + folder.prettyName, - folder, - recursive, - fun - ); - }, - - msgCountIterate(type, account, path, folder) { - let count = false; - - const folderPath = path + "/" + folder.prettyName; - - if (SysTrayX.filters) { - const match = SysTrayX.filters.filter((filter) => { - function ciEquals(a, b) { - return typeof a === "string" && typeof b === "string" - ? a.localeCompare(b, undefined, { sensitivity: "accent" }) === 0 - : a === b; - } - return ( - filter.folder.accountName === account && - ciEquals(filter.folder.path, folderPath) - ); - }); - - count = match.length > 0; - } else { - count = folder.getFlag(Ci.nsMsgFolderFlags.Inbox); - } - - if (count) { - SysTrayX["add" + type](folder); - } - }, - - addUnreadMessages(folder) { - let folderUnreadMsgCount = folder["getNumUnread"](false); - - /* nsMsgDBFolder::GetNumUnread basically returns mNumUnreadMessages + - mNumPendingUnreadMessages, while mNumPendingUnreadMessages may get -1 - when updated from the cache. Which means getNumUnread might return -1. */ - if (folderUnreadMsgCount > 0) { - this.newMsgCount += folderUnreadMsgCount; - } - }, - - addHasNewMessages(folder) { - let folderNewMsgCount = folder.hasNewMessages; - - if (folderNewMsgCount > 0) { - this.newMsgCount += folderNewMsgCount; - } - }, - - getAccounts() { - let accountServers = []; - for (let accountServer of fixIterator( - MailServices.accounts.accounts, - Ci.nsIMsgAccount - )) { - accountServers.push(accountServer.incomingServer); - } - - /* - for (let i = 0, len = accountServers.length; i < len; ++i) { - console.debug( - "ACCOUNT: " + - accountServers[i].prettyName + - " type: " + - accountServers[i].type + - " key: " + - accountServers[i].key.toString() - ); - } - */ - - // Store the accounts - this.accounts = accountServers; - }, - - add(callback) { - this.callbackOnUnreadMailChange = callback; - }, - - remove(callback) { - this.callbackOnUnreadMailChange = undefined; - }, - - addOnFolderChange(callback) { - this.callbackOnFolderChange = callback; - }, - - removeOnFolderChange(callback) { - this.callbackOnFolderChange = undefined; - }, -}; diff --git a/webext/js/options_accounts.js b/webext/js/options_accounts.js index ebfc121..f278029 100644 --- a/webext/js/options_accounts.js +++ b/webext/js/options_accounts.js @@ -10,19 +10,15 @@ SysTrayX.Accounts = { getAccounts: async function () { let accounts; - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - accounts = await browser.accounts.list(); - } else { - accounts = await browser.accounts.list(false); + accounts = await browser.accounts.list(false); - // Fill the sub folders using the folders API, they are not same... - for (let i = 0; i < accounts.length; ++i) { - const subFolders = await browser.folders.getSubFolders( - accounts[i], - true - ); - accounts[i].folders = subFolders; - } + // Fill the sub folders using the folders API, they are not same... + for (let i = 0; i < accounts.length; ++i) { + const subFolders = await browser.folders.getSubFolders( + accounts[i], + true + ); + accounts[i].folders = subFolders; } return accounts; @@ -173,25 +169,11 @@ SysTrayX.Accounts = { // Create a usable folder tree let folders = []; - if (SysTrayX.Info.browserInfo.majorVersion < 74) { - // Pre TB74 accounts API - folders = createFolderTreePre74( - accounts[prop][i].name, - accounts[prop][i].folders - ); - } else if (SysTrayX.Info.browserInfo.majorVersion < 91) { - // TB74 - TB90? accounts API, (this shit never ends...) - folders = createFolderTreePre91( - accounts[prop][i].name, - accounts[prop][i].folders - ); - } else { - // TB91+ accounts API, (this shit never ends...) - folders = createFolderTree( - accounts[prop][i].name, - accounts[prop][i].folders - ); - } + + folders = createFolderTree( + accounts[prop][i].name, + accounts[prop][i].folders + ); // Recursive list creator function createListLevel(level, parent) { @@ -226,10 +208,7 @@ SysTrayX.Accounts = { accountId: element.accountId, type: element.type != undefined ? element.type : "", path: element.path, - name: - SysTrayX.Info.browserInfo.majorVersion < 91 - ? element.path.split("/").pop() - : element.originalName + name: element.originalName ? element.originalName : element.name, version: SysTrayX.Info.version, diff --git a/webext/manifest.json b/webext/manifest.json index 0640ded..afed590 100644 --- a/webext/manifest.json +++ b/webext/manifest.json @@ -9,7 +9,7 @@ "applications": { "gecko": { "id": "systray-x@Ximi1970", - "strict_min_version": "68.0", + "strict_min_version": "91.0", "strict_max_version": "117.*" } }, @@ -32,14 +32,6 @@ }, "experiment_apis": { - "folderChange": { - "schema": "schema_folderchange.json", - "parent": { - "scopes": ["addon_parent"], - "paths": [["folderChange"]], - "script": "js/folderChange.js" - } - }, "windowEvent": { "schema": "schema_windowEvent.json", "parent": { diff --git a/webext/modules/folderChange.jsm b/webext/modules/folderChange.jsm deleted file mode 100644 index 47a73d5..0000000 --- a/webext/modules/folderChange.jsm +++ /dev/null @@ -1,6 +0,0 @@ -var EXPORTED_SYMBOLS = ["folderChange"]; - -var folderChange = { -}; - -console.log("Loading folderChange.jsm"); diff --git a/webext/options.js b/webext/options.js index 63f3a9e..4663205 100644 --- a/webext/options.js +++ b/webext/options.js @@ -1,14 +1,9 @@ // // Get the prefered storage // -function storage(store) { - if (SysTrayX.Info.browserInfo.majorVersion < 91 || store === "sync") { - console.log("Using sync storage"); - return browser.storage.sync; - } else { - console.log("Using local storage"); - return browser.storage.local; - } +function storage() { + console.log("Using local storage"); + return browser.storage.local; } SysTrayX.SaveOptions = { @@ -24,55 +19,30 @@ SysTrayX.SaveOptions = { ); let filters = []; - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - let checkedFolders = []; - accounts.forEach((account) => { - if (account.checked || account.indeterminate) { - // Find all selected folders - const folders = Array.from( - account.parentNode.querySelectorAll( - 'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' - ) - ).filter((folder) => folder.checked); + accounts.forEach((account) => { + if (account.checked || account.indeterminate) { + // Find all selected folders + const folders = Array.from( + account.parentNode.querySelectorAll( + 'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' + ) + ).filter((folder) => folder.checked); - checkedFolders = checkedFolders.concat(folders); + if (folders.length > 0) { + const mailFolderExt = JSON.parse(folders[0].value); + filters.push({ + accountId: mailFolderExt.accountId, + version: mailFolderExt.version, + folders: [], + }); + + folders.forEach((folder) => { + const mailFolderExt = JSON.parse(folder.value); + filters[filters.length - 1].folders.push(mailFolderExt.path); + }); } - }); - - checkedFolders.forEach((folder) => { - const mailFolderExt = JSON.parse(folder.value); - - filters.push({ - unread: true, - folder: mailFolderExt, - }); - }); - } else { - accounts.forEach((account) => { - if (account.checked || account.indeterminate) { - // Find all selected folders - const folders = Array.from( - account.parentNode.querySelectorAll( - 'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' - ) - ).filter((folder) => folder.checked); - - if (folders.length > 0) { - const mailFolderExt = JSON.parse(folders[0].value); - filters.push({ - accountId: mailFolderExt.accountId, - version: mailFolderExt.version, - folders: [], - }); - - folders.forEach((folder) => { - const mailFolderExt = JSON.parse(folder.value); - filters[filters.length - 1].folders.push(mailFolderExt.path); - }); - } - } - }); - } + } + }); // Store extended query filters @@ -1157,25 +1127,10 @@ SysTrayX.RestoreOptions = { if (inbox.length > 0) { let folder = {}; - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - folder = { - ...inbox[0], - accountName: account.name, - path: "/" + inbox[0].name, - }; - delete folder.type; - delete folder.subFolders; - - filters.push({ - unread: true, - folder: folder, - }); - } else { - filters.push({ - accountId: inbox[0].accountId, - folders: [inbox[0].path], - }); - } + filters.push({ + accountId: inbox[0].accountId, + folders: [inbox[0].path], + }); } }); } @@ -1183,22 +1138,20 @@ SysTrayX.RestoreOptions = { if (filters) { const treeBase = document.getElementById("accountsTree"); - if (SysTrayX.Info.browserInfo.majorVersion < 91) { - filters.forEach((filter) => { - const folder = filter.folder; - - const account = treeBase.querySelector( - `input[name=${folder.accountId}]` - ); - const checkboxes = Array.from( - account.parentNode.querySelectorAll( - 'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' - ) - ); + filters.forEach((filter) => { + const account = treeBase.querySelector( + `input[name=${filter.accountId}]` + ); + const checkboxes = Array.from( + account.parentNode.querySelectorAll( + 'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' + ) + ); + filter.folders.forEach((path) => { checkboxes.forEach((checkbox) => { const value = JSON.parse(checkbox.value); - if (value.path === folder.path) { + if (value.path === path) { checkbox.checked = true; const event = document.createEvent("HTMLEvents"); @@ -1207,31 +1160,7 @@ SysTrayX.RestoreOptions = { } }); }); - } else { - filters.forEach((filter) => { - const account = treeBase.querySelector( - `input[name=${filter.accountId}]` - ); - const checkboxes = Array.from( - account.parentNode.querySelectorAll( - 'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' - ) - ); - - filter.folders.forEach((path) => { - checkboxes.forEach((checkbox) => { - const value = JSON.parse(checkbox.value); - if (value.path === path) { - checkbox.checked = true; - - const event = document.createEvent("HTMLEvents"); - event.initEvent("change", false, true); - checkbox.dispatchEvent(event); - } - }); - }); - }); - } + }); } }, @@ -1472,11 +1401,6 @@ async function start() { "https://github.com/Ximi1970/systray-x/releases/tag/" + SysTrayX.Info.version; - // Disable incompatible items - if (SysTrayX.Info.browserInfo.majorVersion > 89 && SysTrayX.Info.browserInfo.majorVersion < 91) { - document.getElementById("counttype").style.display = "none"; - } - // Set the right default icon if (SysTrayX.Info.browserInfo.majorVersion < 115) { document.getElementById("defaultCustomIconImage").setAttribute("src","icons/Thunderbird.png"); diff --git a/webext/schema_folderchange.json b/webext/schema_folderchange.json deleted file mode 100644 index 046041c..0000000 --- a/webext/schema_folderchange.json +++ /dev/null @@ -1,114 +0,0 @@ -[ - { - "namespace": "folderChange", - "functions": [ - { - "name": "setVersion", - "type": "function", - "description": "Set the TB version.", - "async": true, - "parameters": [ - { - "type": "integer", - "name": "version", - "minimum": 0, - "maximum": 999 - } - ] - }, - { - "name": "setCountType", - "type": "function", - "description": "Set the count type.", - "async": true, - "parameters": [ - { - "type": "integer", - "name": "type", - "minimum": 0, - "maximum": 1 - } - ] - }, - { - "name": "setFilters", - "type": "function", - "description": "Set the account filters.", - "async": true, - "parameters": [ - { - "name": "filters", - "type": "array", - "items": { - "type": "object", - "properties": { - "unread": { - "type": "boolean" - }, - "folder": { - "type": "object", - "properties": { - "accountName": { - "type": "string" - }, - "accountId": { - "type": "string" - }, - "name": { - "type": "string" - }, - "type": { - "type": "string" - }, - "path": { - "type": "string" - }, - "version": { - "type": "string" - } - } - } - } - } - } - ] - } - ], - "events": [ - { - "name": "onUnreadMailChange", - "type": "function", - "description": "Fires when there is a change in the number of unread mails.", - "parameters": [ - { - "name": "unread", - "type": "integer" - } - ] - }, - { - "name": "onFolderChange", - "type": "function", - "description": "Fires when there is a folder added or removed.", - "parameters": [ - { - "name": "rootFolder", - "type": "string" - }, - { - "name": "parentFolder", - "type": "string" - }, - { - "name": "folder", - "type": "string" - }, - { - "name": "added", - "type": "boolean" - } - ] - } - ] - } -] From e101b5db2ce2bff4ed5148c765148e55cdc2391b Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Wed, 6 Sep 2023 22:07:28 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 330fc47..31168b9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SysTray-X -SysTray-X is a system tray extension for Thunderbird 68+. The addon uses the WebExtension API's to control an external system dependent system tray application. +SysTray-X is a system tray extension for Thunderbird. The addon uses the WebExtension API's to control an external system dependent system tray application. The addon and system tray application can do: