Browse Source

Notifications and Dont Disturb

Improve disabling Notifications using Electron methods.
Persistent Dont Disturb.

Fixes #178
Fixes #249
pull/291/merge
Ramiro Saenz 9 years ago
parent
commit
65a3df3e08
  1. 3
      app/Application.js
  2. 21
      app/ux/WebView.js
  3. 3
      app/view/main/Main.js
  4. 8
      app/view/main/MainController.js
  5. 10
      electron/main.js

3
app/Application.js

@ -148,6 +148,9 @@ Ext.define('Rambox.Application', {
this.checkUpdate(true);
}
// Define default value
if ( localStorage.getItem('dontDisturb') === null ) localStorage.setItem('dontDisturb', false);
if ( localStorage.getItem('locked') ) {
console.info('Lock Rambox:', 'Enabled');
Ext.cq1('app-main').getController().showLockWindow();

21
app/ux/WebView.js

@ -153,6 +153,9 @@ Ext.define('Rambox.ux.WebView',{
// Google Analytics Event
ga_storage._trackEvent('Services', 'load', me.type, 1, true);
// Notifications in Webview
me.setNotifications(localStorage.getItem('locked') || JSON.parse(localStorage.getItem('dontDisturb')) ? false : me.record.get('notifications'));
// Show and hide spinner when is loading
webview.addEventListener("did-start-loading", function() {
console.info('Start loading...', me.src);
@ -192,15 +195,7 @@ Ext.define('Rambox.ux.WebView',{
webview.addEventListener("dom-ready", function(e) {
// Mute Webview
if ( me.muted || localStorage.getItem('locked') ) me.setAudioMuted(true);
// Notifications in Webview
webview.executeJavaScript('var originalNotification = Notification;');
if ( me.notifications ) {
me.setNotifications(me.notifications);
} else if ( localStorage.getItem('locked') ) {
me.setNotifications(false);
}
if ( me.record.get('muted') || localStorage.getItem('locked') || JSON.parse(localStorage.getItem('dontDisturb')) ) me.setAudioMuted(true);
// Injected code to detect new messages
if ( me.record ) {
@ -290,19 +285,13 @@ Ext.define('Rambox.ux.WebView',{
var me = this;
var webview = me.down('component').el.dom;
if ( !notification ) {
webview.executeJavaScript('(function() { Notification = function() { } })();');
} else {
webview.executeJavaScript('(function() { Notification = originalNotification })();');
}
ipc.send('setServiceNotifications', webview.partition, notification);
}
,setOffline: function(btn, e) {
var me = this;
var webview = me.down('component').el.dom;
console.log(btn, e);
console.info(me.type, 'Going '+ (!btn.offline ? 'offline' : 'online') + '...');
webview.getWebContents().session.setProxy({ proxyRules: !btn.offline ? 'offline' : '' }, Ext.emptyFn);

3
app/view/main/Main.js

@ -214,12 +214,13 @@ Ext.define('Rambox.view.main.Main', {
,items: [
{
glyph: 'xf1f7@FontAwesome'
,text: 'Don\'t Disturb: OFF'
,text: 'Don\'t Disturb: '+(JSON.parse(localStorage.getItem('dontDisturb')) ? 'ON' : 'OFF')
,tooltip: 'Disable notifications and sounds in all services. Perfect to be concentrated and focused.<br/><b>Shortcut key: F1</b>'
,enableToggle: true
,handler: 'dontDisturb'
,reference: 'disturbBtn'
,id: 'disturbBtn'
,pressed: JSON.parse(localStorage.getItem('dontDisturb'))
}
,{
glyph: 'xf023@FontAwesome'

8
app/view/main/MainController.js

@ -797,13 +797,11 @@ Ext.define('Rambox.view.main.MainController', {
tab.setAudioMuted(btn.pressed);
// Prevent Notifications
if ( btn.pressed ) {
tab.down('component').el.dom.getWebContents().executeJavaScript('var originalNotification = Notification; (function() { Notification = function() { } })();');
} else {
tab.down('component').el.dom.getWebContents().executeJavaScript('(function() { Notification = originalNotification })();');
}
tab.setNotifications(!btn.pressed);
});
localStorage.setItem('dontDisturb', btn.pressed);
btn.setText('Don\'t Disturb: ' + ( btn.pressed ? 'ON' : 'OFF' ));
// If this method is called from Lock method, prevent showing toast

10
electron/main.js

@ -1,6 +1,6 @@
'use strict';
const {app, protocol, BrowserWindow, dialog, shell, Menu, ipcMain, nativeImage} = require('electron');
const {app, protocol, BrowserWindow, dialog, shell, Menu, ipcMain, nativeImage, session} = require('electron');
// Menu
const appMenu = require('./menu');
// Tray
@ -237,6 +237,14 @@ ipcMain.on('setConfig', function(event, values) {
values.auto_launch ? appLauncher.enable() : appLauncher.disable();
});
// Handle Service Notifications
ipcMain.on('setServiceNotifications', function(event, partition, op) {
session.fromPartition(partition).setPermissionRequestHandler(function(webContents, permission, callback) {
if (permission === 'notifications') return callback(op);
callback(true)
});
});
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {

Loading…
Cancel
Save