import settings from '../../../client/state/settings';
import {
toggleSystemTheme, toggleMarkdown, toggleMembershipEvents, toggleNickAvatarEvents,
- toggleNotifications,
+ toggleNotifications, toggleNotificationSounds,
} from '../../../client/action/settings';
import logout from '../../../client/action/logout';
import { usePermission } from '../../hooks/usePermission';
options={renderOptions()}
content={<Text variant="b3">Show notifications when new messages arrive.</Text>}
/>
+ <SettingTile
+ title="Play notification sounds"
+ options={(
+ <Toggle
+ isActive={settings.isNotificationSounds}
+ onToggle={() => { toggleNotificationSounds(); updateState({}); }}
+ />
+ )}
+ content={<Text variant="b3">Play a sound when new messages arrive.</Text>}
+ />
</div>
);
}
<div className="set-about__branding">
<img width="60" height="60" src={CinnySVG} alt="Cinny logo" />
<div>
- <Text variant="h2" weight='medium'>
+ <Text variant="h2" weight="medium">
Cinny
<span className="text text-b3" style={{ margin: '0 var(--sp-extra-tight)' }}>{`v${cons.version}`}</span>
</Text>
{/* eslint-disable-next-line react/jsx-one-expression-per-line */ }
<Text>The <a href="https://twemoji.twitter.com" target="_blank" rel="noreferrer noopener">Twemoji</a> emoji art is © <a href="https://twemoji.twitter.com" target="_blank" rel="noreferrer noopener">Twitter, Inc and other contributors</a> used under the terms of <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noreferrer noopener">CC-BY 4.0</a>.</Text>
</li>
+ <li>
+ {/* eslint-disable-next-line react/jsx-one-expression-per-line */ }
+ <Text>The <a href="https://material.io/design/sound/sound-resources.html" target="_blank" rel="noreferrer noopener">Material sound resources</a> are © <a href="https://google.com" target="_blank" rel="noreferrer noopener">Google</a> used under the terms of <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noreferrer noopener">CC-BY 4.0</a>.</Text>
+ </li>
</ul>
</div>
</div>
type: cons.actions.settings.TOGGLE_NOTIFICATIONS,
});
}
+
+export function toggleNotificationSounds() {
+ appDispatcher.dispatch({
+ type: cons.actions.settings.TOGGLE_NOTIFICATION_SOUNDS,
+ });
+}
import navigation from './navigation';
import settings from './settings';
+import NotificationSound from '../../../public/sound/notification.ogg';
+
function isNotifEvent(mEvent) {
const eType = mEvent.getType();
if (!cons.supportEventTypes.includes(eType)) return false;
}
async _displayPopupNoti(mEvent, room) {
- if (!settings.showNotifications) return;
+ if (!settings.showNotifications && !settings.isNotificationSounds) return;
const actions = this.matrixClient.getPushActionsForEvent(mEvent);
if (!actions?.notify) return;
await mEvent.attemptDecryption(this.matrixClient.crypto);
}
- let title;
- if (!mEvent.sender || room.name === mEvent.sender.name) {
- title = room.name;
- } else if (mEvent.sender) {
- title = `${mEvent.sender.name} (${room.name})`;
- }
+ if (settings.showNotifications) {
+ let title;
+ if (!mEvent.sender || room.name === mEvent.sender.name) {
+ title = room.name;
+ } else if (mEvent.sender) {
+ title = `${mEvent.sender.name} (${room.name})`;
+ }
- const iconSize = 36;
- const icon = await renderAvatar({
- text: mEvent.sender.name,
- bgColor: cssColorMXID(mEvent.getSender()),
- imageSrc: mEvent.sender?.getAvatarUrl(this.matrixClient.baseUrl, iconSize, iconSize, 'crop'),
- size: iconSize,
- borderRadius: 8,
- scale: 8,
- });
+ const iconSize = 36;
+ const icon = await renderAvatar({
+ text: mEvent.sender.name,
+ bgColor: cssColorMXID(mEvent.getSender()),
+ imageSrc: mEvent.sender?.getAvatarUrl(this.matrixClient.baseUrl, iconSize, iconSize, 'crop'),
+ size: iconSize,
+ borderRadius: 8,
+ scale: 8,
+ });
+
+ const noti = new window.Notification(title, {
+ body: mEvent.getContent().body,
+ icon,
+ silent: settings.isNotificationSounds,
+ });
+ if (settings.isNotificationSounds) {
+ noti.onshow = () => this._playNotiSounds();
+ }
+ noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
+ } else {
+ this._playNotiSounds();
+ }
+ }
- const noti = new window.Notification(title, {
- body: mEvent.getContent().body,
- icon,
- });
- noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
+ _playNotiSounds() {
+ if (!this._notiAudio) {
+ this._notiAudio = new Audio(NotificationSound);
+ }
+ this._notiAudio.play();
}
_listenEvents() {
TOGGLE_MEMBERSHIP_EVENT: 'TOGGLE_MEMBERSHIP_EVENT',
TOGGLE_NICKAVATAR_EVENT: 'TOGGLE_NICKAVATAR_EVENT',
TOGGLE_NOTIFICATIONS: 'TOGGLE_NOTIFICATIONS',
+ TOGGLE_NOTIFICATION_SOUNDS: 'TOGGLE_NOTIFICATION_SOUNDS',
},
},
events: {
MEMBERSHIP_EVENTS_TOGGLED: 'MEMBERSHIP_EVENTS_TOGGLED',
NICKAVATAR_EVENTS_TOGGLED: 'NICKAVATAR_EVENTS_TOGGLED',
NOTIFICATIONS_TOGGLED: 'NOTIFICATIONS_TOGGLED',
+ NOTIFICATION_SOUNDS_TOGGLED: 'NOTIFICATION_SOUNDS_TOGGLED',
},
},
};
this.hideMembershipEvents = this.getHideMembershipEvents();
this.hideNickAvatarEvents = this.getHideNickAvatarEvents();
this._showNotifications = this.getShowNotifications();
+ this.isNotificationSounds = this.getIsNotificationSounds();
this.isTouchScreenDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0);
}
return settings.showNotifications;
}
+ getIsNotificationSounds() {
+ if (typeof this.isNotificationSounds === 'boolean') return this.isNotificationSounds;
+
+ const settings = getSettings();
+ if (settings === null) return true;
+ if (typeof settings.isNotificationSounds === 'undefined') return true;
+ return settings.isNotificationSounds;
+ }
+
setter(action) {
const actions = {
[cons.actions.settings.TOGGLE_SYSTEM_THEME]: () => {
setSettings('showNotifications', this._showNotifications);
this.emit(cons.events.settings.NOTIFICATIONS_TOGGLED, this._showNotifications);
},
+ [cons.actions.settings.TOGGLE_NOTIFICATION_SOUNDS]: () => {
+ this.isNotificationSounds = !this.isNotificationSounds;
+ setSettings('isNotificationSounds', this.isNotificationSounds);
+ this.emit(cons.events.settings.NOTIFICATION_SOUNDS_TOGGLED, this.isNotificationSounds);
+ },
};
actions[action.type]?.();
use: ['html-loader'],
},
{
- test: /\.(png|jpe?g|gif|otf|ttf|woff|woff2)$/,
+ test: /\.(png|jpe?g|gif|otf|ttf|woff|woff2|ogg)$/,
type: 'asset/resource',
},
{