From a3b55c68876ad60284ac8642da883e85c390329d Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Wed, 1 Apr 2020 23:33:08 +0200 Subject: [PATCH 1/3] Add poll timing options in addon --- webext/js/options_mailform.js | 15 +++++++ webext/options.html | 41 +++++++++++++++++++ webext/options.js | 75 +++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 webext/js/options_mailform.js diff --git a/webext/js/options_mailform.js b/webext/js/options_mailform.js new file mode 100644 index 0000000..773cc0e --- /dev/null +++ b/webext/js/options_mailform.js @@ -0,0 +1,15 @@ +function pollStartupDelay(e) { +// console.debug("Startup: " + e.target.value); +} + +function pollInterval(e) { +// console.debug("Interval: " + e.target.value); +} + +document + .getElementById("pollStartupDelay") + .addEventListener("change", pollStartupDelay); + +document + .getElementById("pollInterval") + .addEventListener("change", pollInterval); diff --git a/webext/options.html b/webext/options.html index 5fc1277..248424a 100644 --- a/webext/options.html +++ b/webext/options.html @@ -80,7 +80,48 @@

Included accounts

+ +
+ + + + + + + + + +
+ + + +
+ + + +
+ + +
diff --git a/webext/options.js b/webext/options.js index 57e7710..0272736 100644 --- a/webext/options.js +++ b/webext/options.js @@ -38,6 +38,25 @@ SysTrayX.SaveOptions = { filters: filters }); + // + // Save poll startup delay state + // + const pollStartupDelay = document.querySelector( + 'input[name="pollStartupDelay"]' + ).value; + browser.storage.sync.set({ + pollStartupDelay: `${pollStartupDelay}` + }); + + // + // Save poll interval state + // + const pollInterval = document.querySelector('input[name="pollInterval"]') + .value; + browser.storage.sync.set({ + pollInterval: `${pollInterval}` + }); + // // Save debug state // @@ -138,6 +157,24 @@ SysTrayX.RestoreOptions = { SysTrayX.RestoreOptions.setIcon, SysTrayX.RestoreOptions.onIconError ); + + // + // Restore poll startup delay state + // + const getPollStartupDelay = browser.storage.sync.get("pollStartupDelay"); + getPollStartupDelay.then( + SysTrayX.RestoreOptions.setPollStartupDelay, + SysTrayX.RestoreOptions.onPollStartupDelayError + ); + + // + // Restore poll interval state + // + const getPollInterval = browser.storage.sync.get("pollInterval"); + getPollInterval.then( + SysTrayX.RestoreOptions.setPollInterval, + SysTrayX.RestoreOptions.onPollIntervalError + ); }, // @@ -242,6 +279,34 @@ SysTrayX.RestoreOptions = { onIconError: function(error) { console.log(`Icon Error: ${error}`); + }, + + // + // Restore poll startup delay state callbacks + // + setPollStartupDelay: function(result) { + const pollStartupDelay = result.pollStartupDelay || 5; + + const input = document.querySelector(`input[name="pollStartupDelay"]`); + input.value = pollStartupDelay; + }, + + onPollStartupDelayError: function(error) { + console.log(`Poll startup delay Error: ${error}`); + }, + + // + // Restore poll interval state callbacks + // + setPollInterval: function(result) { + const pollInterval = result.pollInterval || 5; + + const input = document.querySelector(`input[name="pollInterval"]`); + input.value = pollInterval; + }, + + onPollPollInterval: function(error) { + console.log(`Poll interval Error: ${error}`); } }; @@ -278,6 +343,16 @@ SysTrayX.StorageChanged = { startMinimized: changes[item].newValue }); } + if (item === "pollStartupDelay") { + SysTrayX.RestoreOptions.setPollStartupDelay({ + pollStartupDelay: changes[item].newValue + }); + } + if (item === "pollInterval") { + SysTrayX.RestoreOptions.setPollInterval({ + pollInterval: changes[item].newValue + }); + } if (item === "debug") { SysTrayX.RestoreOptions.setDebug({ debug: changes[item].newValue From 7d432558b4770b968bfcdaf051d06edc1313703c Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Thu, 2 Apr 2020 22:27:34 +0200 Subject: [PATCH 2/3] Add poll timing options in app, sync --- app/SysTray-X/preferences.cpp | 55 +++++ app/SysTray-X/preferences.h | 48 ++++ app/SysTray-X/preferences.ui | 350 ++++++++++++++++------------ app/SysTray-X/preferencesdialog.cpp | 39 ++++ app/SysTray-X/preferencesdialog.h | 24 ++ app/SysTray-X/systrayx.cpp | 4 + app/SysTray-X/systrayxlink.cpp | 46 ++++ app/SysTray-X/systrayxlink.h | 10 + webext/background.js | 20 ++ webext/options.js | 4 +- 10 files changed, 447 insertions(+), 153 deletions(-) diff --git a/app/SysTray-X/preferences.cpp b/app/SysTray-X/preferences.cpp index aea078a..c7f05dd 100644 --- a/app/SysTray-X/preferences.cpp +++ b/app/SysTray-X/preferences.cpp @@ -30,6 +30,9 @@ Preferences::Preferences( QObject *parent ) : QObject( parent ) m_hide_minimize = true; m_start_minimized = false; + m_poll_startup_delay = 5; + m_poll_interval = 5; + m_debug = false; } @@ -178,6 +181,58 @@ void Preferences::setStartMinimized( bool state ) } +/* + * Get the poll startup delay. + */ +int Preferences::getPollStartupDelay() const +{ + return m_poll_startup_delay; +} + + +/* + * Set the startup poll delay. + */ +void Preferences::setPollStartupDelay( int val ) +{ + if( m_poll_startup_delay != val ) + { + m_poll_startup_delay = val; + + /* + * Tell the world the new preference + */ + emit signalPollStartupDelayChange(); + } +} + + +/* + * Get the poll interval. + */ +int Preferences::getPollInterval() const +{ + return m_poll_interval; +} + + +/* + * Set the startup poll delay. + */ +void Preferences::setPollInterval( int val ) +{ + if( m_poll_interval != val ) + { + m_poll_interval = val; + + /* + * Tell the world the new preference + */ + emit signalPollIntervalChange(); + } +} + + /* * Get the debug state. */ diff --git a/app/SysTray-X/preferences.h b/app/SysTray-X/preferences.h index e089558..d0f09ea 100644 --- a/app/SysTray-X/preferences.h +++ b/app/SysTray-X/preferences.h @@ -121,6 +121,34 @@ class Preferences : public QObject */ void setStartMinimized( bool state ); + /** + * @brief getPollStartupDelay. Get the poll startup delay. + * + * @return The poll startup delay. + */ + int getPollStartupDelay() const; + + /** + * @brief setPollStartupDelay. Set the poll startup delay. + * + * @param The poll startup delay. + */ + void setPollStartupDelay( int val ); + + /** + * @brief getPollInterval. Get the poll interval. + * + * @return The poll interval. + */ + int getPollInterval() const; + + /** + * @brief setPollInterval. Set the poll interval. + * + * @param The poll interval. + */ + void setPollInterval( int val ); + /** * @brief getDebug. Get the debug windows state. * @@ -157,6 +185,16 @@ class Preferences : public QObject */ void signalStartMinimizedChange(); + /** + * @brief signalPollStartupDelayChange. Signal a poll startup delay change. + */ + void signalPollStartupDelayChange(); + + /** + * @brief signalPollIntervalChange. Signal a poll interval change. + */ + void signalPollIntervalChange(); + /** * @brief signalDebugChange. Signal a debug state change. */ @@ -194,6 +232,16 @@ class Preferences : public QObject */ bool m_start_minimized; + /** + * @brief m_poll_startup_delay. The startup poll delay. + */ + int m_poll_startup_delay; + + /** + * @brief m_poll_interval. The poll interval. + */ + int m_poll_interval; + /** * @brief m_debug. Display debug window. */ diff --git a/app/SysTray-X/preferences.ui b/app/SysTray-X/preferences.ui index 3fbaa55..4d770b7 100644 --- a/app/SysTray-X/preferences.ui +++ b/app/SysTray-X/preferences.ui @@ -7,177 +7,225 @@ 0 0 292 - 326 + 487 SysTray-X Preferences - - - QLayout::SetFixedSize - - - - - - - Windows - - + + + + + Windows + + + + + + Minimizing window hides to tray + + + true + + + + + + + Start application minimized + + + + + + + + + + Mail notification icon + + + + - - - Minimizing window hides to tray + + + QLayout::SetFixedSize - - true - - - - - - - Start application minimized - - - - - - - - - - Mail notification icon - - - - - - - QLayout::SetFixedSize + + + Blank icon - - - - Blank icon - - - true - - - iconTypeGroup - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + true + + + iconTypeGroup + + - - - QLayout::SetFixedSize + + + Qt::Horizontal - - - - New mail icon - - - iconTypeGroup - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + 40 + 20 + + + + + + + + + + QLayout::SetFixedSize + + + + + New mail icon + + + iconTypeGroup + + - - - QLayout::SetMaximumSize + + + Qt::Horizontal - - - - Custom icon - - - iconTypeGroup - - - - - - - - - - - - - - Choose - - - false - - - - + + + 40 + 20 + + + + + + + + + + QLayout::SetMaximumSize + + + + + Custom icon + + + iconTypeGroup + + + + + + + + + + + + + + Choose + + + false + + - - - - - - Display debug window - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + - + + + + Mail actions + + + + + + + + + + Poll startup delay + + + + + + + 1 + + + 5 + + + + + + + + + + + Poll interval + + + + + + + 1 + + + 5 + + + + + + + + + + + + + + Display debug window + + + + + + + Qt::Vertical + + + + 239 + 36 + + + + + Qt::Horizontal diff --git a/app/SysTray-X/preferencesdialog.cpp b/app/SysTray-X/preferencesdialog.cpp index 62ded0f..5625d47 100644 --- a/app/SysTray-X/preferencesdialog.cpp +++ b/app/SysTray-X/preferencesdialog.cpp @@ -59,6 +59,24 @@ void PreferencesDialog::setDebug( bool state ) } +/* + * Set the poll startup delay + */ +void PreferencesDialog::setPollStartupDelay( int val ) +{ + m_ui->pollStartupDelaySpinBox->setValue( val ); +} + + +/* + * Set the poll interval + */ +void PreferencesDialog::setPollInterval( int val ) +{ + m_ui->pollIntervalSpinBox->setValue( val ); +} + + /* * Set the hide on minimize state */ @@ -141,6 +159,9 @@ void PreferencesDialog::slotAccept() m_pref->setHideOnMinimize( m_ui->hideOnMinimizeCheckBox->isChecked() ); m_pref->setStartMinimized( m_ui->startMinimizedCheckBox->isChecked() ); + m_pref->setPollStartupDelay(m_ui->pollStartupDelaySpinBox->value()); + m_pref->setPollInterval(m_ui->pollIntervalSpinBox->value()); + m_pref->setDebug( m_ui->debugWindowCheckBox->isChecked() ); /* @@ -203,6 +224,24 @@ void PreferencesDialog::slotDebugChange() } +/* + * Handle the poll startup delay change signal + */ +void PreferencesDialog::slotPollStartupDelayChange() +{ + setPollStartupDelay( m_pref->getPollStartupDelay() ); +} + + +/* + * Handle the poll interval change signal + */ +void PreferencesDialog::slotPollIntervalChange() +{ + setPollInterval( m_pref->getPollInterval() ); +} + + /* * Handle the hide on minimize change signal */ diff --git a/app/SysTray-X/preferencesdialog.h b/app/SysTray-X/preferencesdialog.h index e3be69d..d1e608f 100644 --- a/app/SysTray-X/preferencesdialog.h +++ b/app/SysTray-X/preferencesdialog.h @@ -48,6 +48,20 @@ class PreferencesDialog : public QDialog */ void setDebug( bool state ); + /** + * @brief setPollStartupDelay. Set the poll startup delay. + * + * @param val The new value. + */ + void setPollStartupDelay( int val ); + + /** + * @brief setPollInterval. Set the poll interval. + * + * @param val The new value. + */ + void setPollInterval( int val ); + /** * @brief setHideOnMinimize. Set the hide on minimize state. * @@ -96,6 +110,16 @@ class PreferencesDialog : public QDialog */ void slotDebugChange(); + /** + * @brief slotPollStartupDelayChange. Slot for handling poll startup delay signals. + */ + void slotPollStartupDelayChange(); + + /** + * @brief slotPollIntervalChange. Slot for handling poll interval signals. + */ + void slotPollIntervalChange(); + /** * @brief slotHideOnMinimizeChange. Slot for handling hide on minimize change signals. */ diff --git a/app/SysTray-X/systrayx.cpp b/app/SysTray-X/systrayx.cpp index 47dc9ab..f2febf1 100644 --- a/app/SysTray-X/systrayx.cpp +++ b/app/SysTray-X/systrayx.cpp @@ -86,12 +86,16 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) connect( m_preferences, &Preferences::signalIconDataChange, m_pref_dialog, &PreferencesDialog::slotIconDataChange ); connect( m_preferences, &Preferences::signalHideOnMinimizeChange, m_pref_dialog, &PreferencesDialog::slotHideOnMinimizeChange ); connect( m_preferences, &Preferences::signalStartMinimizedChange, m_pref_dialog, &PreferencesDialog::slotStartMinimizedChange ); + connect( m_preferences, &Preferences::signalPollStartupDelayChange, m_pref_dialog, &PreferencesDialog::slotPollStartupDelayChange ); + connect( m_preferences, &Preferences::signalPollIntervalChange, m_pref_dialog, &PreferencesDialog::slotPollIntervalChange ); connect( m_preferences, &Preferences::signalDebugChange, m_pref_dialog, &PreferencesDialog::slotDebugChange ); connect( m_preferences, &Preferences::signalIconTypeChange, m_link, &SysTrayXLink::slotIconTypeChange ); connect( m_preferences, &Preferences::signalIconDataChange, m_link, &SysTrayXLink::slotIconDataChange ); connect( m_preferences, &Preferences::signalHideOnMinimizeChange, m_link, &SysTrayXLink::slotHideOnMinimizeChange ); connect( m_preferences, &Preferences::signalStartMinimizedChange, m_link, &SysTrayXLink::slotStartMinimizedChange ); + connect( m_preferences, &Preferences::signalPollStartupDelayChange, m_link, &SysTrayXLink::slotPollStartupDelayChange ); + connect( m_preferences, &Preferences::signalPollIntervalChange, m_link, &SysTrayXLink::slotPollIntervalChange ); connect( m_preferences, &Preferences::signalDebugChange, m_link, &SysTrayXLink::slotDebugChange ); connect( m_preferences, &Preferences::signalDebugChange, m_debug, &DebugWidget::slotDebugChange ); diff --git a/app/SysTray-X/systrayxlink.cpp b/app/SysTray-X/systrayxlink.cpp index 394dc27..9472521 100644 --- a/app/SysTray-X/systrayxlink.cpp +++ b/app/SysTray-X/systrayxlink.cpp @@ -377,6 +377,26 @@ void SysTrayXLink::DecodePreferences( const QJsonObject& pref ) m_pref->setStartMinimized( start_minimized ); } + if( pref.contains( "pollStartupDelay" ) && pref[ "pollStartupDelay" ].isString() ) + { + QString poll_startup_delay = pref[ "pollStartupDelay" ].toString(); + + /* + * Store the new start minimized state + */ + m_pref->setPollStartupDelay( poll_startup_delay.toInt() ); + } + + if( pref.contains( "pollInterval" ) && pref[ "pollInterval" ].isString() ) + { + QString poll_interval = pref[ "pollInterval" ].toString(); + + /* + * Store the new poll interval + */ + m_pref->setPollInterval( poll_interval.toInt() ); + } + if( pref.contains( "debug" ) && pref[ "debug" ].isString() ) { bool debug = pref[ "debug" ].toString() == "true"; @@ -399,6 +419,8 @@ void SysTrayXLink::EncodePreferences( const Preferences& pref ) */ QJsonObject prefObject; prefObject.insert("debug", QJsonValue::fromVariant( QString( pref.getDebug() ? "true" : "false" ) ) ); + prefObject.insert("pollStartupDelay", QJsonValue::fromVariant( QString::number( pref.getPollStartupDelay() ) ) ); + prefObject.insert("pollInterval", QJsonValue::fromVariant( QString::number( pref.getPollInterval() ) ) ); prefObject.insert("hideOnMinimize", QJsonValue::fromVariant( QString( pref.getHideOnMinimize() ? "true" : "false" ) ) ); prefObject.insert("startMinimized", QJsonValue::fromVariant( QString( pref.getStartMinimized() ? "true" : "false" ) ) ); prefObject.insert("iconType", QJsonValue::fromVariant( QString::number( pref.getIconType() ) ) ); @@ -448,6 +470,30 @@ void SysTrayXLink::slotDebugChange() } +/* + * Handle a poll startup delay change signal + */ +void SysTrayXLink::slotPollStartupDelayChange() +{ + if( m_pref->getAppPrefChanged() ) + { + sendPreferences(); + } +} + + +/* + * Handle a poll interval change signal + */ +void SysTrayXLink::slotPollIntervalChange() +{ + if( m_pref->getAppPrefChanged() ) + { + sendPreferences(); + } +} + + /* * Handle a hide on minimize state change signal */ diff --git a/app/SysTray-X/systrayxlink.h b/app/SysTray-X/systrayxlink.h index a8afd45..0f05a46 100644 --- a/app/SysTray-X/systrayxlink.h +++ b/app/SysTray-X/systrayxlink.h @@ -174,6 +174,16 @@ class SysTrayXLink : public QObject */ void slotDebugChange(); + /** + * @brief slotPollStartupDelayChange. Handle a change in poll startup delay. + */ + void slotPollStartupDelayChange(); + + /** + * @brief slotPollIntervalChange. Handle a change in poll interval. + */ + void slotPollIntervalChange(); + /** * @brief slotHideOnMinimizeChange. Handle a change in hide on minimize state. */ diff --git a/webext/background.js b/webext/background.js index cd2e08c..6feec47 100644 --- a/webext/background.js +++ b/webext/background.js @@ -112,6 +112,8 @@ SysTrayX.Messaging = { sendPreferences: function() { const getter = browser.storage.sync.get([ "debug", + "pollStartupDelay", + "pollInterval", "hideOnMinimize", "startMinimized", "iconType", @@ -123,6 +125,8 @@ SysTrayX.Messaging = { sendPreferencesStorage: function(result) { const debug = result.debug || "false"; + const pollStartupDelay = result.pollStartupDelay || "5"; + const pollInterval = result.pollInterval || "5"; const hideOnMinimize = result.hideOnMinimize || "true"; const startMinimized = result.startMinimized || "false"; const iconType = result.iconType || "0"; @@ -133,6 +137,8 @@ SysTrayX.Messaging = { SysTrayX.Link.postSysTrayXMessage({ preferences: { debug: debug, + pollStartupDelay: pollStartupDelay, + pollInterval: pollInterval, hideOnMinimize: hideOnMinimize, startMinimized: startMinimized, iconType: iconType, @@ -265,6 +271,20 @@ SysTrayX.Link = { }); } + const pollStartupDelay = response["preferences"].pollStartupDelay; + if (pollStartupDelay) { + browser.storage.sync.set({ + pollStartupDelay: pollStartupDelay + }); + } + + const pollInterval = response["preferences"].pollInterval; + if (pollInterval) { + browser.storage.sync.set({ + pollInterval: pollInterval + }); + } + const debug = response["preferences"].debug; if (debug) { browser.storage.sync.set({ diff --git a/webext/options.js b/webext/options.js index 0272736..52a45e3 100644 --- a/webext/options.js +++ b/webext/options.js @@ -45,7 +45,7 @@ SysTrayX.SaveOptions = { 'input[name="pollStartupDelay"]' ).value; browser.storage.sync.set({ - pollStartupDelay: `${pollStartupDelay}` + pollStartupDelay: pollStartupDelay }); // @@ -54,7 +54,7 @@ SysTrayX.SaveOptions = { const pollInterval = document.querySelector('input[name="pollInterval"]') .value; browser.storage.sync.set({ - pollInterval: `${pollInterval}` + pollInterval: pollInterval }); // From bfcd30efcf4df28fd53831fa73f907cf973e5d47 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Fri, 3 Apr 2020 17:45:20 +0200 Subject: [PATCH 3/3] use new poll timing --- webext/background.js | 36 +++++++++++++++++++++++++++++++++++- webext/js/defaults.js | 18 ++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/webext/background.js b/webext/background.js index 6feec47..adc14ad 100644 --- a/webext/background.js +++ b/webext/background.js @@ -1,6 +1,11 @@ var SysTrayX = { debugAccounts: false, + pollTiming: { + pollStartupDelay: "5", + pollInterval: "5" + }, + platformInfo: undefined }; @@ -13,6 +18,8 @@ SysTrayX.Messaging = { init: function() { // Get the accounts from the storage SysTrayX.Messaging.getAccounts(); + + // Lookout for storage changes browser.storage.onChanged.addListener(SysTrayX.Messaging.storageChanged); // Send the window title to app @@ -22,7 +29,11 @@ SysTrayX.Messaging = { SysTrayX.Messaging.sendPreferences(); // this.unReadMessages(this.unreadFiltersTest).then(this.unreadCb); - window.setInterval(SysTrayX.Messaging.pollAccounts, 1000); + // window.setInterval(SysTrayX.Messaging.pollAccounts, 1000); + window.setTimeout( + SysTrayX.Messaging.pollAccounts, + SysTrayX.pollTiming.pollStartupDelay * 1000 + ); // Try to catch the window state browser.windows.onFocusChanged.addListener(SysTrayX.Window.focusChanged); @@ -35,6 +46,20 @@ SysTrayX.Messaging = { // Get the new preferences SysTrayX.Messaging.getAccounts(); + if ("pollStartupDelay" in changes && changes["pollStartupDelay"].newValue) { + SysTrayX.pollTiming = { + ...SysTrayX.pollTiming, + pollStartupDelay: changes["pollStartupDelay"].newValue + }; + } + + if ("pollInterval" in changes && changes["pollInterval"].newValue) { + SysTrayX.pollTiming = { + ...SysTrayX.pollTiming, + pollInterval: changes["pollInterval"].newValue + }; + } + if ("addonprefchanged" in changes && changes["addonprefchanged"].newValue) { // // Send new preferences to the app @@ -73,6 +98,12 @@ SysTrayX.Messaging = { SysTrayX.Messaging.unreadCb ); } + + // Next round... + window.setTimeout( + SysTrayX.Messaging.pollAccounts, + SysTrayX.pollTiming.pollInterval * 1000 + ); }, // @@ -315,6 +346,9 @@ async function start() { }); } + // Get the poll timing + SysTrayX.pollTiming = await getPollTiming(); + // Set platform SysTrayX.platformInfo = await browser.runtime .getPlatformInfo() diff --git a/webext/js/defaults.js b/webext/js/defaults.js index 0d1313e..b79aa90 100644 --- a/webext/js/defaults.js +++ b/webext/js/defaults.js @@ -67,3 +67,21 @@ async function getStartupState() { const getState = browser.storage.sync.get("startMinimized"); return await getState.then(getStartupState, onStartupStateError); } + +// +// Get poll timing +// +async function getPollTiming() { + function getDelayAndInterval(result) { + return { pollStartupDelay: result.pollStartupDelay || "5", pollInterval: result.pollInterval || "5" }; + } + + function onDelayAndIntervalError() { + return { pollStartupDelay: "5", pollInterval: "5" }; + } + + const getTiming = browser.storage.sync.get([ + "pollStartupDelay", + "pollInterval"]); + return await getTiming.then(getDelayAndInterval, onDelayAndIntervalError); +}