diff --git a/src/components/ElectronJS/FrameButtons.vue b/src/components/ElectronJS/FrameButtons.vue index 9013e31..4eda991 100644 --- a/src/components/ElectronJS/FrameButtons.vue +++ b/src/components/ElectronJS/FrameButtons.vue @@ -22,7 +22,7 @@ + diff --git a/src/store/modules/settingsModule.js b/src/store/modules/settingsModule.js index 9c20858..7ca104e 100644 --- a/src/store/modules/settingsModule.js +++ b/src/store/modules/settingsModule.js @@ -9,6 +9,7 @@ const state = { GDriveLinked: false, customEmojis: [], recentEmojis: JSON.parse(localStorage.getItem('recentEmojis')) || [], + notification: JSON.parse(localStorage.getItem('notificationSettings')) || {}, apperance: {} } @@ -28,6 +29,12 @@ const actions = { setGDriveLinked(context, status) { context.commit('GoogleDriveLinked', status) }, + updateNotification(context, data) { + let notificationSettings = JSON.parse(localStorage.getItem('notificationSettings')) || {}; + Object.assign(notificationSettings, data); + localStorage.setItem("notificationSettings", JSON.stringify(notificationSettings)); + context.commit('updateNotification', notificationSettings) + }, addRecentEmoji(context, shortcode) { const recentEmojis = JSON.parse(localStorage.getItem('recentEmojis')) || []; let filter = recentEmojis.filter(function (item) { @@ -85,6 +92,9 @@ const actions = { } const mutations = { + updateNotification(state, data) { + Vue.set(state, 'notification', data) + }, setApperance(state, data) { Vue.set(state.apperance, Object.keys(data)[0], data[Object.keys(data)[0]]) }, diff --git a/src/store/modules/socketIOModule.js b/src/store/modules/socketIOModule.js index d009fb8..fb53c11 100644 --- a/src/store/modules/socketIOModule.js +++ b/src/store/modules/socketIOModule.js @@ -1,7 +1,8 @@ +import config from '@/config'; import {bus} from '../../main' import {router} from './../../router' import Vue from 'vue'; - +import DesktopNotification from '@/utils/ElectronJS/DesktopNotification' const state = { @@ -151,6 +152,8 @@ const actions = { } if (context.rootState.channelModule.selectedChannelID == data.message.channelID && document.hasFocus()) { this._vm.$socket.emit('notification:dismiss', {channelID: data.message.channelID}); + } else { + desktopNotification(); } // send notification if other users message the recipient if (data.message.creator.uniqueID === context.getters.user.uniqueID) return; @@ -160,6 +163,28 @@ const actions = { sender: data.message.creator } context.dispatch('messageCreatedNotification', notification); + function desktopNotification() { + // send desktop notification + const disableDesktopNotification = context.rootGetters['settingsModule/settings'].notification.disableDesktopNotification; + if (disableDesktopNotification === true) return + const channel = context.getters.channels[data.message.channelID]; + if (channel.server_id) { + const server = context.getters['servers/servers'][channel.server_id] + DesktopNotification.serverMessage({ + serverName: server.name, + channelName: channel.name, + username: data.message.creator.username, + avatarURL: config.domain + '/avatars/' + server.avatar, + message: data.message.message + }) + } else { + DesktopNotification.directMessage({ + username: data.message.creator.username, + avatarURL: config.domain + '/avatars/' + data.message.creator.avatar, + message: data.message.message + }) + } + } }, socket_userStatusChange(context, data) { if (context.rootState.user.user.uniqueID === data.uniqueID) return; diff --git a/src/utils/ElectronJS/DesktopNotification.js b/src/utils/ElectronJS/DesktopNotification.js new file mode 100644 index 0000000..e86b5d9 --- /dev/null +++ b/src/utils/ElectronJS/DesktopNotification.js @@ -0,0 +1,30 @@ +module.exports = { + directMessage({username, avatarURL, message}) { + let myNotification = new Notification(`${username}`, { + body: message, + icon: avatarURL, + silent: true + }) + myNotification.onclick = () => { + console.log("CLICK") + } + myNotification.onclose = () => { + myNotification = null; + } + }, + serverMessage({serverName, channelName, username, avatarURL, message}) { + let myNotification = new Notification(`${username} in ${serverName}#${channelName}`, { + body: message, + icon: avatarURL, + silent: true + }) + myNotification.onclick = () => { + console.log("CLICK") + } + myNotification.onclose = () => { + myNotification = null; + } + } +} + + diff --git a/src/views/App.vue b/src/views/App.vue index 9ce9886..0390359 100644 --- a/src/views/App.vue +++ b/src/views/App.vue @@ -256,7 +256,7 @@ export default { display: flex; overflow-y: hidden; overflow-x: auto; - max-width: 495px; + max-width: 560px; flex-basis: auto; /* default value */ flex-grow: 1; -webkit-app-region: no-drag;