From b31781f6ef9b2ec1de59ba429bc0d4c7d80dee0e Mon Sep 17 00:00:00 2001 From: Daniel Dominguez Date: Mon, 30 Jul 2018 21:13:57 -0300 Subject: [PATCH] Add setting to skip desktop nofifications, persist the setting on localstorage, defaults to true(notifications enabled). --- src/renderer/constants/settings.js | 1 + src/renderer/page/settings/index.js | 2 ++ src/renderer/page/settings/view.jsx | 18 ++++++++++++ src/renderer/redux/actions/content.js | 35 ++++++++++++++---------- src/renderer/redux/reducers/settings.js | 3 ++ src/renderer/redux/selectors/settings.js | 4 +++ 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/renderer/constants/settings.js b/src/renderer/constants/settings.js index d27c888de..aa4ba12d2 100644 --- a/src/renderer/constants/settings.js +++ b/src/renderer/constants/settings.js @@ -14,3 +14,4 @@ export const THEMES = 'themes'; export const AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled'; export const AUTOPLAY = 'autoplay'; export const RESULT_COUNT = 'resultCount'; +export const DESKTOP_NOTIFICATIONS_ENABLED = 'desktopNotificationsEnabled'; diff --git a/src/renderer/page/settings/index.js b/src/renderer/page/settings/index.js index d0c090d06..81ef953d4 100644 --- a/src/renderer/page/settings/index.js +++ b/src/renderer/page/settings/index.js @@ -11,6 +11,7 @@ import { makeSelectClientSetting, selectDaemonSettings, selectLanguages, + selectDesktopNotificationsEnabled, } from 'redux/selectors/settings'; import { selectCurrentLanguage } from 'redux/selectors/app'; import { doWalletStatus, selectWalletIsEncrypted } from 'lbry-redux'; @@ -28,6 +29,7 @@ const select = state => ({ automaticDarkModeEnabled: makeSelectClientSetting(settings.AUTOMATIC_DARK_MODE_ENABLED)(state), autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), walletEncrypted: selectWalletIsEncrypted(state), + desktopNotificationsEnabled: selectDesktopNotificationsEnabled(state), }); const perform = dispatch => ({ diff --git a/src/renderer/page/settings/view.jsx b/src/renderer/page/settings/view.jsx index 64104c4b3..fd8788caf 100644 --- a/src/renderer/page/settings/view.jsx +++ b/src/renderer/page/settings/view.jsx @@ -34,6 +34,7 @@ type Props = { encryptWallet: () => void, decryptWallet: () => void, walletEncrypted: boolean, + desktopNotificationsEnabled: boolean, }; type State = { @@ -57,6 +58,7 @@ class SettingsPage extends React.PureComponent { (this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this); (this: any).onAutoplayChange = this.onAutoplayChange.bind(this); (this: any).clearCache = this.clearCache.bind(this); + (this: any).onDesktopNotificationsChange = this.onDesktopNotificationsChange.bind(this); // (this: any).onLanguageChange = this.onLanguageChange.bind(this) } @@ -126,6 +128,10 @@ class SettingsPage extends React.PureComponent { this.props.setDaemonSetting(name, value); } + onDesktopNotificationsChange(event: SyntheticInputEvent<*>) { + this.props.setClientSetting(settings.DESKTOP_NOTIFICATIONS_ENABLED, event.target.checked); + } + clearCache() { this.setState({ clearingCache: true, @@ -150,6 +156,7 @@ class SettingsPage extends React.PureComponent { automaticDarkModeEnabled, autoplay, walletEncrypted, + desktopNotificationsEnabled, } = this.props; const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0; @@ -171,6 +178,17 @@ class SettingsPage extends React.PureComponent { currentPath={daemonSettings.download_directory} onFileChosen={this.onDownloadDirChange} /> + +
+ {__('App Notifications.')} + +
{__('Max Purchase Price')}
diff --git a/src/renderer/redux/actions/content.js b/src/renderer/redux/actions/content.js index 04808b6e1..8a2be0fe6 100644 --- a/src/renderer/redux/actions/content.js +++ b/src/renderer/redux/actions/content.js @@ -28,7 +28,10 @@ import { MODALS, doNotify, } from 'lbry-redux'; -import { makeSelectClientSetting } from 'redux/selectors/settings'; +import { + makeSelectClientSetting, + selectDesktopNotificationsEnabled, +} from 'redux/selectors/settings'; import setBadge from 'util/setBadge'; import setProgressBar from 'util/setProgressBar'; import analytics from 'analytics'; @@ -139,19 +142,21 @@ export function doUpdateLoadStatus(uri, outpoint) { 0 ); - const notif = new window.Notification(notifications[uri].subscription.channelName, { - body: `Posted ${fileInfo.metadata.title}${ - count > 1 && count < 10 ? ` and ${count - 1} other new items` : '' - }${count > 9 ? ' and 9+ other new items' : ''}`, - silent: false, - }); - notif.onclick = () => { - dispatch( - doNavigate('/show', { - uri, - }) - ); - }; + if (selectDesktopNotificationsEnabled(getState())) { + const notif = new window.Notification(notifications[uri].subscription.channelName, { + body: `Posted ${fileInfo.metadata.title}${ + count > 1 && count < 10 ? ` and ${count - 1} other new items` : '' + }${count > 9 ? ' and 9+ other new items' : ''}`, + silent: false, + }); + notif.onclick = () => { + dispatch( + doNavigate('/show', { + uri, + }) + ); + }; + } dispatch( setSubscriptionNotification( notifications[uri].subscription, @@ -160,6 +165,8 @@ export function doUpdateLoadStatus(uri, outpoint) { ) ); } else { + // If notifications are disabled(false) just return + if (!selectDesktopNotificationsEnabled(getState())) return; const notif = new window.Notification('LBRY Download Complete', { body: fileInfo.metadata.title, silent: false, diff --git a/src/renderer/redux/reducers/settings.js b/src/renderer/redux/reducers/settings.js index 383b76161..af2ce6cef 100644 --- a/src/renderer/redux/reducers/settings.js +++ b/src/renderer/redux/reducers/settings.js @@ -26,6 +26,9 @@ const defaultState = { automaticDarkModeEnabled: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false), autoplay: getLocalStorageSetting(SETTINGS.AUTOPLAY, false), resultCount: Number(getLocalStorageSetting(SETTINGS.RESULT_COUNT, 50)), + desktopNotificationsEnabled: Boolean( + getLocalStorageSetting(SETTINGS.DESKTOP_NOTIFICATIONS_ENABLED, true) + ), }, isNight: false, languages: {}, diff --git a/src/renderer/redux/selectors/settings.js b/src/renderer/redux/selectors/settings.js index 9c90cfac2..6cd7d374a 100644 --- a/src/renderer/redux/selectors/settings.js +++ b/src/renderer/redux/selectors/settings.js @@ -33,3 +33,7 @@ export const selectThemePath = createSelector( return `${staticResourcesPath}/themes/${dynamicTheme || 'light'}.css`; } ); + +export const selectDesktopNotificationsEnabled = makeSelectClientSetting( + SETTINGS.DESKTOP_NOTIFICATIONS_ENABLED +);