diff --git a/app/util/IconLoader.js b/app/util/IconLoader.js new file mode 100644 index 00000000..b4f0349b --- /dev/null +++ b/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; + } + }; + } +}); diff --git a/app/ux/WebView.js b/app/ux/WebView.js index aa58c4e9..a512695c 100644 --- a/app/ux/WebView.js +++ b/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(); });