Skip to content

Commit

Permalink
Add notification enabled check to main
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Nov 28, 2024
1 parent 80a6a5e commit 24535cf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions backend/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ const publicMethods = {
for (const client of to || server.clients) {
const msg = typeof message === 'string' ? message : JSON.stringify(message)
if (client.endpoint) {
if (msg.length > 1) {
console.error('@@XXX1 posting', typeof message, message)
}
postEvent(client, msg).catch(e => {
console.error(e, 'Error posting push notification')
})
Expand Down
3 changes: 3 additions & 0 deletions frontend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ async function startApp () {
window.location.reload() // try again, sometimes it fixes it
throw e
})
if (typeof Notification === 'function') {
sbp('state/vuex/commit', 'setNotificationEnabled', Notification.permission === 'granted')
}

/* TODO: MOVE TO ANOTHER FILE */
sbp('okTurtles.data/set', 'API_URL', self.location.origin)
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/settings/vuexModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const defaultSettings = {
: ['error', 'warn', 'info']): string[]),
fontSize: 16,
increasedContrast: false,
notificationEnabled: true,
notificationEnabled: false,
reducedMotion: false,
theme: defaultTheme,
themeColor: defaultColor
Expand Down
2 changes: 2 additions & 0 deletions shared/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export type UnsubMessage = {
// ====== Enums ====== //

export const NOTIFICATION_TYPE = Object.freeze({
// used for push notifications in excess of 4 KiB
ABBREVIATED_ENTRY: 'abbreviated_entry',
ENTRY: 'entry',
KV: 'kv',
PING: 'ping',
Expand Down

0 comments on commit 24535cf

Please sign in to comment.