Add setting to skip desktop nofifications, persist the setting on localstorage, defaults to true(notifications enabled).

This commit is contained in:
Daniel Dominguez 2018-07-30 21:13:57 -03:00
parent 26d73c63e9
commit b31781f6ef
6 changed files with 49 additions and 14 deletions

View file

@ -14,3 +14,4 @@ export const THEMES = 'themes';
export const AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled'; export const AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled';
export const AUTOPLAY = 'autoplay'; export const AUTOPLAY = 'autoplay';
export const RESULT_COUNT = 'resultCount'; export const RESULT_COUNT = 'resultCount';
export const DESKTOP_NOTIFICATIONS_ENABLED = 'desktopNotificationsEnabled';

View file

@ -11,6 +11,7 @@ import {
makeSelectClientSetting, makeSelectClientSetting,
selectDaemonSettings, selectDaemonSettings,
selectLanguages, selectLanguages,
selectDesktopNotificationsEnabled,
} from 'redux/selectors/settings'; } from 'redux/selectors/settings';
import { selectCurrentLanguage } from 'redux/selectors/app'; import { selectCurrentLanguage } from 'redux/selectors/app';
import { doWalletStatus, selectWalletIsEncrypted } from 'lbry-redux'; import { doWalletStatus, selectWalletIsEncrypted } from 'lbry-redux';
@ -28,6 +29,7 @@ const select = state => ({
automaticDarkModeEnabled: makeSelectClientSetting(settings.AUTOMATIC_DARK_MODE_ENABLED)(state), automaticDarkModeEnabled: makeSelectClientSetting(settings.AUTOMATIC_DARK_MODE_ENABLED)(state),
autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state),
walletEncrypted: selectWalletIsEncrypted(state), walletEncrypted: selectWalletIsEncrypted(state),
desktopNotificationsEnabled: selectDesktopNotificationsEnabled(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({

View file

@ -34,6 +34,7 @@ type Props = {
encryptWallet: () => void, encryptWallet: () => void,
decryptWallet: () => void, decryptWallet: () => void,
walletEncrypted: boolean, walletEncrypted: boolean,
desktopNotificationsEnabled: boolean,
}; };
type State = { type State = {
@ -57,6 +58,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this); (this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
(this: any).onAutoplayChange = this.onAutoplayChange.bind(this); (this: any).onAutoplayChange = this.onAutoplayChange.bind(this);
(this: any).clearCache = this.clearCache.bind(this); (this: any).clearCache = this.clearCache.bind(this);
(this: any).onDesktopNotificationsChange = this.onDesktopNotificationsChange.bind(this);
// (this: any).onLanguageChange = this.onLanguageChange.bind(this) // (this: any).onLanguageChange = this.onLanguageChange.bind(this)
} }
@ -126,6 +128,10 @@ class SettingsPage extends React.PureComponent<Props, State> {
this.props.setDaemonSetting(name, value); this.props.setDaemonSetting(name, value);
} }
onDesktopNotificationsChange(event: SyntheticInputEvent<*>) {
this.props.setClientSetting(settings.DESKTOP_NOTIFICATIONS_ENABLED, event.target.checked);
}
clearCache() { clearCache() {
this.setState({ this.setState({
clearingCache: true, clearingCache: true,
@ -150,6 +156,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
automaticDarkModeEnabled, automaticDarkModeEnabled,
autoplay, autoplay,
walletEncrypted, walletEncrypted,
desktopNotificationsEnabled,
} = this.props; } = this.props;
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0; const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
@ -171,6 +178,17 @@ class SettingsPage extends React.PureComponent<Props, State> {
currentPath={daemonSettings.download_directory} currentPath={daemonSettings.download_directory}
onFileChosen={this.onDownloadDirChange} onFileChosen={this.onDownloadDirChange}
/> />
<br />
<span className="card__subtitle">{__('App Notifications.')}</span>
<FormField
type="checkbox"
name="desktopNotification"
onChange={this.onDesktopNotificationsChange}
checked={desktopNotificationsEnabled}
postfix={__('Desktop Notification')}
/>
</section> </section>
<section className="card card--section"> <section className="card card--section">
<div className="card__title">{__('Max Purchase Price')}</div> <div className="card__title">{__('Max Purchase Price')}</div>

View file

@ -28,7 +28,10 @@ import {
MODALS, MODALS,
doNotify, doNotify,
} from 'lbry-redux'; } from 'lbry-redux';
import { makeSelectClientSetting } from 'redux/selectors/settings'; import {
makeSelectClientSetting,
selectDesktopNotificationsEnabled,
} from 'redux/selectors/settings';
import setBadge from 'util/setBadge'; import setBadge from 'util/setBadge';
import setProgressBar from 'util/setProgressBar'; import setProgressBar from 'util/setProgressBar';
import analytics from 'analytics'; import analytics from 'analytics';
@ -139,19 +142,21 @@ export function doUpdateLoadStatus(uri, outpoint) {
0 0
); );
const notif = new window.Notification(notifications[uri].subscription.channelName, { if (selectDesktopNotificationsEnabled(getState())) {
body: `Posted ${fileInfo.metadata.title}${ const notif = new window.Notification(notifications[uri].subscription.channelName, {
count > 1 && count < 10 ? ` and ${count - 1} other new items` : '' body: `Posted ${fileInfo.metadata.title}${
}${count > 9 ? ' and 9+ other new items' : ''}`, count > 1 && count < 10 ? ` and ${count - 1} other new items` : ''
silent: false, }${count > 9 ? ' and 9+ other new items' : ''}`,
}); silent: false,
notif.onclick = () => { });
dispatch( notif.onclick = () => {
doNavigate('/show', { dispatch(
uri, doNavigate('/show', {
}) uri,
); })
}; );
};
}
dispatch( dispatch(
setSubscriptionNotification( setSubscriptionNotification(
notifications[uri].subscription, notifications[uri].subscription,
@ -160,6 +165,8 @@ export function doUpdateLoadStatus(uri, outpoint) {
) )
); );
} else { } else {
// If notifications are disabled(false) just return
if (!selectDesktopNotificationsEnabled(getState())) return;
const notif = new window.Notification('LBRY Download Complete', { const notif = new window.Notification('LBRY Download Complete', {
body: fileInfo.metadata.title, body: fileInfo.metadata.title,
silent: false, silent: false,

View file

@ -26,6 +26,9 @@ const defaultState = {
automaticDarkModeEnabled: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false), automaticDarkModeEnabled: getLocalStorageSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false),
autoplay: getLocalStorageSetting(SETTINGS.AUTOPLAY, false), autoplay: getLocalStorageSetting(SETTINGS.AUTOPLAY, false),
resultCount: Number(getLocalStorageSetting(SETTINGS.RESULT_COUNT, 50)), resultCount: Number(getLocalStorageSetting(SETTINGS.RESULT_COUNT, 50)),
desktopNotificationsEnabled: Boolean(
getLocalStorageSetting(SETTINGS.DESKTOP_NOTIFICATIONS_ENABLED, true)
),
}, },
isNight: false, isNight: false,
languages: {}, languages: {},

View file

@ -33,3 +33,7 @@ export const selectThemePath = createSelector(
return `${staticResourcesPath}/themes/${dynamicTheme || 'light'}.css`; return `${staticResourcesPath}/themes/${dynamicTheme || 'light'}.css`;
} }
); );
export const selectDesktopNotificationsEnabled = makeSelectClientSetting(
SETTINGS.DESKTOP_NOTIFICATIONS_ENABLED
);