Fix: Adds favicon badge for notification alert. (#2079)
* Adds favicon badge for notification alert.
This commit is contained in:
@@ -21,6 +21,7 @@ import i18n from '../dashboard/i18n';
|
|||||||
import createAxios from '../dashboard/helper/APIHelper';
|
import createAxios from '../dashboard/helper/APIHelper';
|
||||||
import commonHelpers from '../dashboard/helper/commons';
|
import commonHelpers from '../dashboard/helper/commons';
|
||||||
import { getAlertAudio } from '../shared/helpers/AudioNotificationHelper';
|
import { getAlertAudio } from '../shared/helpers/AudioNotificationHelper';
|
||||||
|
import { initFaviconSwitcher } from '../shared/helpers/faviconHelper';
|
||||||
import router from '../dashboard/routes';
|
import router from '../dashboard/routes';
|
||||||
import store from '../dashboard/store';
|
import store from '../dashboard/store';
|
||||||
import vueActionCable from '../dashboard/helper/actionCable';
|
import vueActionCable from '../dashboard/helper/actionCable';
|
||||||
@@ -80,4 +81,5 @@ window.addEventListener('load', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
getAlertAudio();
|
getAlertAudio();
|
||||||
|
initFaviconSwitcher();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { MESSAGE_TYPE } from 'shared/constants/messages';
|
import { MESSAGE_TYPE } from 'shared/constants/messages';
|
||||||
const notificationAudio = require('shared/assets/audio/ding.mp3');
|
const notificationAudio = require('shared/assets/audio/ding.mp3');
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { showBadgeOnFavicon } from './faviconHelper';
|
||||||
|
|
||||||
export const playNotificationAudio = () => {
|
export const playNotificationAudio = () => {
|
||||||
try {
|
try {
|
||||||
@@ -74,5 +75,6 @@ export const newMessageNotification = data => {
|
|||||||
|
|
||||||
if (enableAudioAlerts && playAudio) {
|
if (enableAudioAlerts && playAudio) {
|
||||||
window.playAudioAlert();
|
window.playAudioAlert();
|
||||||
|
showBadgeOnFavicon();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
21
app/javascript/shared/helpers/faviconHelper.js
Normal file
21
app/javascript/shared/helpers/faviconHelper.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export const showBadgeOnFavicon = () => {
|
||||||
|
const favicons = document.querySelectorAll('.favicon');
|
||||||
|
|
||||||
|
favicons.forEach(favicon => {
|
||||||
|
const newFileName = `/favicon-badge-${favicon.sizes[[0]]}.png`;
|
||||||
|
favicon.href = newFileName;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const initFaviconSwitcher = () => {
|
||||||
|
const favicons = document.querySelectorAll('.favicon');
|
||||||
|
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (document.visibilityState === 'visible') {
|
||||||
|
favicons.forEach(favicon => {
|
||||||
|
const oldFileName = `/favicon-${favicon.sizes[[0]]}.png`;
|
||||||
|
favicon.href = oldFileName;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -23,9 +23,9 @@
|
|||||||
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
|
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
|
||||||
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
|
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
<link class="favicon" rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||||
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
|
<link class="favicon" rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
|
||||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
<link class="favicon" rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||||
<link rel="manifest" href="/manifest.json">
|
<link rel="manifest" href="/manifest.json">
|
||||||
<% end %>
|
<% end %>
|
||||||
<link rel="icon" type="image/png" sizes="512x512" href="<%= @global_config['LOGO_THUMBNAIL'] %>">
|
<link rel="icon" type="image/png" sizes="512x512" href="<%= @global_config['LOGO_THUMBNAIL'] %>">
|
||||||
|
|||||||
BIN
public/favicon-badge-16x16.png
Normal file
BIN
public/favicon-badge-16x16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 900 B |
BIN
public/favicon-badge-32x32.png
Normal file
BIN
public/favicon-badge-32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
public/favicon-badge-96x96.png
Normal file
BIN
public/favicon-badge-96x96.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
Reference in New Issue
Block a user