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 AUTOPLAY = 'autoplay';
export const RESULT_COUNT = 'resultCount';
export const DESKTOP_NOTIFICATIONS_ENABLED = 'desktopNotificationsEnabled';

View file

@ -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 => ({

View file

@ -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<Props, State> {
(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<Props, State> {
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<Props, State> {
automaticDarkModeEnabled,
autoplay,
walletEncrypted,
desktopNotificationsEnabled,
} = this.props;
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
@ -171,6 +178,17 @@ class SettingsPage extends React.PureComponent<Props, State> {
currentPath={daemonSettings.download_directory}
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 className="card card--section">
<div className="card__title">{__('Max Purchase Price')}</div>

View file

@ -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,

View file

@ -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: {},

View file

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