1
0
mirror of https://github.com/hyperspacedev/hyperspace synced 2025-02-07 04:43:20 +01:00

Disable notification switch when user denies permissions

This commit is contained in:
Marquis Kurt 2019-04-19 14:43:06 -04:00
parent 7671524475
commit 58826fc14b
2 changed files with 9 additions and 5 deletions

View File

@ -214,16 +214,18 @@ class SettingsPage extends Component<any, ISettingsState> {
<ListItemText
primary="Enable push notifications"
secondary={
browserSupportsNotificationRequests()?
"":
"Notifications aren't supported in this browser."
getUserDefaultBool('userDeniedNotification')?
"Check your browser's notification permissions.":
browserSupportsNotificationRequests()?
"":
"Your browser doesn't support notifications."
}
/>
<ListItemSecondaryAction>
<Switch
checked={this.state.pushNotificationsEnabled}
onChange={this.togglePushNotifications}
disabled={!browserSupportsNotificationRequests()}
disabled={!browserSupportsNotificationRequests() || getUserDefaultBool('userDeniedNotification')}
/>
</ListItemSecondaryAction>
</ListItem>
@ -234,7 +236,7 @@ class SettingsPage extends Component<any, ISettingsState> {
<Paper className={classes.pageListConstraints}>
<List>
<ListItem>
<ListItemText primary="Configure on Mastodon" secondary="Configure your account settings on Mastodon"/>
<ListItemText primary="Configure on Mastodon"/>
<ListItemSecondaryAction>
<IconButton href={(localStorage.getItem("baseurl") as string) + "/settings/preferences"} target="_blank" rel="noreferrer">
<OpenInNewIcon/>

View File

@ -9,8 +9,10 @@ export function getNotificationRequestPermission() {
let request = Notification.permission;
if (request === "granted") {
setUserDefaultBool('enablePushNotifications', true);
setUserDefaultBool('userDeniedNotification', false);
} else {
setUserDefaultBool('enablePushNotifications', false);
setUserDefaultBool('userDeniedNotification', true);
}
} else {
console.warn("Notifications aren't supported in this browser. The setting will be disabled.");