Merge pull request #1834 from dan1d/issue-1788

Add setting to skip desktop nofifications
This commit is contained in:
Sean Yesmunt 2018-08-05 21:59:41 -04:00 committed by GitHub
commit 3b390ffc67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 51 additions and 17 deletions

View file

@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
* Abandoned claim transactions now show in wallet history ([#1769](https://github.com/lbryio/lbry-desktop/pull/1769))
* Emoji support in the claim description ([#1800](https://github.com/lbryio/lbry-desktop/pull/1800))
* PDF preview ([#1576](https://github.com/lbryio/lbry-desktop/pull/1576))
* Add Desktop notification settings to be enabled/disabled ([#1834](https://github.com/lbryio/lbry-desktop/pull/1834))
### Changed
* Upgraded LBRY Protocol to [version 0.20.4](https://github.com/lbryio/lbry/releases/tag/v0.20.4) to assist with download availability and lower CPU usage on idle.
@ -41,6 +42,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
* Hide the "Community top bids" section if user chooses to hide NSFW content ([#1760](https://github.com/lbryio/lbry-desktop/pull/1760))
* More descriptive error message when Shapeshift is unavailable ([#1771](https://github.com/lbryio/lbry-desktop/pull/1771))
* Rename the Github repo to lbry-desktop ([#1765](https://github.com/lbryio/lbry-desktop/pull/1765))
* Changed default browser checkbox to use toggle on all checkbox inputs ([#1834](https://github.com/lbryio/lbry-desktop/pull/1834))
### Fixed
* Edit option missing from certain published claims ([#1756](https://github.com/lbryio/lbry-desktop/issues/1756))

View file

@ -23,7 +23,6 @@ type Props = {
children?: React.Node,
stretch?: boolean,
affixClass?: string, // class applied to prefix/postfix label
useToggle?: boolean,
firstInList?: boolean, // at the top of a list, no padding top
};
@ -41,7 +40,6 @@ export class FormField extends React.PureComponent<Props> {
children,
stretch,
affixClass,
useToggle,
firstInList,
...inputProps
} = this.props;
@ -79,7 +77,7 @@ export class FormField extends React.PureComponent<Props> {
);
} else if (type === 'textarea') {
input = <textarea type={type} id={name} {...inputProps} />;
} else if (type === 'checkbox' && useToggle) {
} else if (type === 'checkbox') {
input = <Toggle id={name} {...inputProps} />;
} else {
input = <input type={type} id={name} {...inputProps} />;

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 OS_NOTIFICATIONS_ENABLED = 'osNotificationsEnabled';

View file

@ -11,6 +11,7 @@ import {
makeSelectClientSetting,
selectDaemonSettings,
selectLanguages,
selectosNotificationsEnabled,
} 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),
osNotificationsEnabled: selectosNotificationsEnabled(state),
});
const perform = dispatch => ({

View file

@ -34,6 +34,7 @@ type Props = {
encryptWallet: () => void,
decryptWallet: () => void,
walletEncrypted: boolean,
osNotificationsEnabled: 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.OS_NOTIFICATIONS_ENABLED, event.target.checked);
}
clearCache() {
this.setState({
clearingCache: true,
@ -150,6 +156,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
automaticDarkModeEnabled,
autoplay,
walletEncrypted,
osNotificationsEnabled,
} = this.props;
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
@ -269,6 +276,18 @@ class SettingsPage extends React.PureComponent<Props, State> {
)}
/>
</section>
<section className="card card--section">
<div className="card__title">{__('Notifications')}</div>
<FormField
type="checkbox"
name="desktopNotification"
onChange={this.onDesktopNotificationsChange}
checked={osNotificationsEnabled}
postfix={__('Show Desktop Notifications')}
/>
</section>
<section className="card card--section">
<div className="card__title">{__('Share Diagnostic Data')}</div>
<FormField

View file

@ -28,7 +28,7 @@ import {
MODALS,
doNotify,
} from 'lbry-redux';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { makeSelectClientSetting, selectosNotificationsEnabled } from 'redux/selectors/settings';
import setBadge from 'util/setBadge';
import setProgressBar from 'util/setProgressBar';
import analytics from 'analytics';
@ -139,19 +139,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 (selectosNotificationsEnabled(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 +162,8 @@ export function doUpdateLoadStatus(uri, outpoint) {
)
);
} else {
// If notifications are disabled(false) just return
if (!selectosNotificationsEnabled(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)),
osNotificationsEnabled: Boolean(
getLocalStorageSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED, true)
),
},
isNight: false,
languages: {},

View file

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

View file

@ -8,6 +8,7 @@
border: 0;
padding: 0;
user-select: none;
margin-bottom: auto;
}
.react-toggle-screenreader-only {