Browse Source

add ability to change notificaiton sound, add laser sound

main
Lerk 1 month ago
parent
commit
56cf435118
  1. 1
      README.md
  2. 1
      app/controllers/settings/preferences_controller.rb
  3. 4
      app/javascript/mastodon/actions/notifications.js
  4. 1
      app/javascript/mastodon/initial_state.js
  5. 13
      app/javascript/mastodon/middleware/sounds.js
  6. 20
      app/lib/notification_sounds.rb
  7. 5
      app/lib/user_settings_decorator.rb
  8. 2
      app/models/user.rb
  9. 1
      app/serializers/initial_state_serializer.rb
  10. 3
      app/views/settings/preferences/tweaks/show.html.haml
  11. 3
      config/locales/de.yml
  12. 3
      config/locales/en.yml
  13. 1
      config/locales/simple_form.de.yml
  14. 1
      config/locales/simple_form.en.yml
  15. 10
      config/sounds.yml
  16. BIN
      public/sounds/laser.mp3
  17. BIN
      public/sounds/laser.ogg

1
README.md

@ -23,5 +23,6 @@ Here's a list of nice stuff in this version:
- Only works on your public profile and status pages
- Overrides the default instance theme with the one you use
- Lower notification sound volume
- Change notification sound
- About page patched out
- /about/more is still accessible

1
app/controllers/settings/preferences_controller.rb

@ -46,6 +46,7 @@ class Settings::PreferencesController < Settings::BaseController
:setting_show_preferred_theme,
:setting_lower_notifications_volume,
:setting_enable_misclick_protection,
:setting_notification_sound,
:setting_disable_swiping,
:setting_system_font_ui,
:setting_noindex,

4
app/javascript/mastodon/actions/notifications.js

@ -95,14 +95,14 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
type: NOTIFICATIONS_UPDATE,
notification,
usePendingItems: preferPendingItems,
meta: (playSound && !filtered) ? { sound: 'boop' } : undefined,
meta: (playSound && !filtered) ? { sound: 'notificationSound' } : undefined,
});
fetchRelatedRelationships(dispatch, [notification]);
} else if (playSound && !filtered) {
dispatch({
type: NOTIFICATIONS_UPDATE_NOOP,
meta: { sound: 'boop' },
meta: { sound: 'notificationSound' },
});
}

1
app/javascript/mastodon/initial_state.js

@ -30,5 +30,6 @@ export const cropImages = getMeta('crop_images');
export const disableSwiping = getMeta('disable_swiping');
export const defaultContentType = getMeta('default_content_type');
export const lowerNotificationsVolume = getMeta('lower_notifications_volume');
export const notificationSound = getMeta('notification_sound');
export default initialState;

13
app/javascript/mastodon/middleware/sounds.js

@ -1,4 +1,4 @@
import { lowerNotificationsVolume } from '../initial_state';
import { lowerNotificationsVolume, notificationSound } from '../initial_state';
const createAudio = sources => {
const audio = new Audio();
@ -32,16 +32,7 @@ const play = audio => {
export default function soundsMiddleware() {
const soundCache = {
boop: createAudio([
{
src: '/sounds/boop.ogg',
type: 'audio/ogg',
},
{
src: '/sounds/boop.mp3',
type: 'audio/mpeg',
},
]),
notificationSound: createAudio(notificationSound),
};
return () => next => action => {

20
app/lib/notification_sounds.rb

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'singleton'
require 'yaml'
class NotificationSounds
include Singleton
def initialize
@conf = YAML.load_file(Rails.root.join('config', 'sounds.yml'))
end
def names
@conf.keys
end
def by_name(name)
@conf[name]
end
end

5
app/lib/user_settings_decorator.rb

@ -30,6 +30,7 @@ class UserSettingsDecorator
user.settings['disable_swiping'] = disable_swiping_preference if change?('setting_disable_swiping')
user.settings['show_preferred_theme'] = show_preferred_theme_preference if change?('setting_show_preferred_theme')
user.settings['lower_notifications_volume'] = lower_notifications_volume_preference if change?('setting_lower_notifications_volume')
user.settings['notification_sound'] = notification_sound_preference if change?('setting_notification_sound')
user.settings['enable_misclick_protection'] = enable_misclick_protection_preference if change?('setting_enable_misclick_protection')
user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui')
user.settings['noindex'] = noindex_preference if change?('setting_noindex')
@ -105,6 +106,10 @@ class UserSettingsDecorator
boolean_cast_setting 'setting_enable_misclick_protection'
end
def notification_sound_preference
settings['setting_notification_sound']
end
def noindex_preference
boolean_cast_setting 'setting_noindex'
end

2
app/models/user.rb

@ -125,7 +125,7 @@ class User < ApplicationRecord
:reduce_motion, :system_font_ui, :show_preferred_theme, :noindex, :theme, :display_media, :hide_network,
:expand_spoilers, :default_language, :aggregate_reblogs, :show_application, :rounded_profile_pics,
:advanced_layout, :use_blurhash, :use_pending_items, :trends, :crop_images, :enable_misclick_protection,
:disable_swiping, :lower_notifications_volume,
:disable_swiping, :lower_notifications_volume, :notification_sound,
to: :settings, prefix: :setting, allow_nil: false
attr_reader :invite_code, :sign_in_token_attempt

1
app/serializers/initial_state_serializer.rb

@ -35,6 +35,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
store[:show_preferred_theme] = object.current_account.user.setting_show_preferred_theme
store[:lower_notifications_volume] = object.current_account.user.setting_lower_notifications_volume
store[:notification_sound] = NotificationSounds.instance.by_name(object.current_account.user.setting_notification_sound)
store[:disable_swiping] = object.current_account.user.setting_disable_swiping
store[:enable_misclick_protection] = object.current_account.user.setting_enable_misclick_protection
store[:advanced_layout] = object.current_account.user.setting_advanced_layout

3
app/views/settings/preferences/tweaks/show.html.haml

@ -18,5 +18,8 @@
%h4= t 'tweaks.notification_tweaks'
.fields-group
= f.input :setting_notification_sound, collection: NotificationSounds.instance.names, label: t('simple_form.labels.defaults.setting_notification_sound'), label_method: lambda { |sound| I18n.t("sounds.#{sound}", default: sound) }, wrapper: :with_label, include_blank: false
.fields-group
= f.input :setting_lower_notifications_volume, as: :boolean, wrapper: :with_label

3
config/locales/de.yml

@ -1417,6 +1417,9 @@ de:
contrast: Mastodon (Hoher Kontrast)
mastodon-dark: Mastodon (Dunkel)
mastodon-light: Mastodon (Hell)
sounds:
default: Boop
laser: Laser
time:
formats:
default: "%d.%m.%Y %H:%M"

3
config/locales/en.yml

@ -1460,6 +1460,9 @@ en:
mastodon-dark: Mastodon (Dark)
default: Night
mastodon-light: Mastodon (Light)
sounds:
default: Boop
laser: Laser
time:
formats:
default: "%b %d, %Y, %H:%M"

1
config/locales/simple_form.de.yml

@ -184,6 +184,7 @@ de:
username: Profilname
username_or_email: Profilname oder E-Mail
whole_word: Ganzes Wort
setting_notification_sound: Benachrichtigungston
email_domain_block:
with_dns_records: MX-Einträge und IPs der Domain einbeziehen
featured_tag:

1
config/locales/simple_form.en.yml

@ -184,6 +184,7 @@ en:
username: Username
username_or_email: Username or Email
whole_word: Whole word
setting_notification_sound: Notification Sound
email_domain_block:
with_dns_records: Include MX records and IPs of the domain
featured_tag:

10
config/sounds.yml

@ -0,0 +1,10 @@
default:
- src: '/sounds/boop.mp3'
type: 'audio/mp3'
- src: '/sounds/boop.ogg'
type: 'audio/ogg'
laser:
- src: '/sounds/laser.mp3'
type: 'audio/mp3'
- src: '/sounds/laser.ogg'
type: 'audio/ogg'

BIN
public/sounds/laser.mp3

Binary file not shown.

BIN
public/sounds/laser.ogg

Binary file not shown.
Loading…
Cancel
Save