Browse Source

Merge pull request #1160 from maxetime/service-icon-loading

Service icon loading
pull/1193/head
Ramiro Saenz 8 years ago committed by GitHub
parent
commit
f056a0e475
  1. 32
      app/util/IconLoader.js
  2. 5
      app/ux/WebView.js

32
app/util/IconLoader.js

@ -0,0 +1,32 @@
/**
* Singleton class to handle the global unread counter.
*/
Ext.define('Rambox.util.IconLoader', {
singleton: true,
constructor: function(config) {
config = config || {};
/**
* Sets the icon for a specific service.
*
* @param {*} id Id of the service
*/
this.loadServiceIconUrl = function (service, webview) {
switch (service.type) {
case 'slack':
webview.executeJavaScript("(()=>{let a=document.querySelector('.team_icon');if(!a){const d=document.querySelector('#team_menu');d&&(d.click(),a=document.querySelector('.team_icon'))}if(!a)return!1;const{style:{backgroundImage:b}}=a,c=document.createEvent('MouseEvents');return c.initEvent('mousedown',!0,!0),document.querySelector('.client_channels_list_container').dispatchEvent(c),b.slice(5,-2)})();",
false,
function (backgroundImage) {
if (backgroundImage) {
service.fireEvent('iconchange', service, backgroundImage, service.icon);
}
}
);
break;
}
};
}
});

5
app/ux/WebView.js

@ -9,6 +9,7 @@ Ext.define('Rambox.ux.WebView',{
'Rambox.util.Format'
,'Rambox.util.Notifier'
,'Rambox.util.UnreadCounter'
,'Rambox.util.IconLoader'
]
// private
@ -251,6 +252,8 @@ Ext.define('Rambox.ux.WebView',{
// Apply saved zoom level
webview.setZoomLevel(me.record.get('zoomLevel'));
Rambox.util.IconLoader.loadServiceIconUrl(me, webview);
});
// Open links in default browser
@ -338,7 +341,7 @@ Ext.define('Rambox.ux.WebView',{
require('electron').shell.openExternal(e.url);
}
});
webview.addEventListener('will-navigate', function(e, url) {
e.preventDefault();
});

Loading…
Cancel
Save