From 64296b645d257cfadce4c2d7a622fde93a6c91a1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 30 Mar 2016 16:06:16 +0200 Subject: [PATCH] Added electron support as external page. --- .../app/controllers/widget/electron_events.coffee | 10 ++++++++++ .../app/controllers/widget/online_notification.coffee | 2 ++ .../app/lib/app_post/interface_handle.coffee | 4 +++- app/assets/javascripts/app/lib/base/email-addresses.js | 4 +++- app/assets/javascripts/app/lib/core/jquery-2.2.1.js | 4 +++- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/widget/electron_events.coffee diff --git a/app/assets/javascripts/app/controllers/widget/electron_events.coffee b/app/assets/javascripts/app/controllers/widget/electron_events.coffee new file mode 100644 index 000000000..81ad4d641 --- /dev/null +++ b/app/assets/javascripts/app/controllers/widget/electron_events.coffee @@ -0,0 +1,10 @@ +class Widget + constructor: -> + return if !window.require + ipcRenderer = window.require('electron').ipcRenderer + return if !ipcRenderer + App.Event.bind('online_notification_counter', (e) -> + ipcRenderer.send('set-badge', e) + ) + +App.Config.set('aaa_electron_events', Widget, 'Navigations') diff --git a/app/assets/javascripts/app/controllers/widget/online_notification.coffee b/app/assets/javascripts/app/controllers/widget/online_notification.coffee index 391ce2a16..71642dffc 100644 --- a/app/assets/javascripts/app/controllers/widget/online_notification.coffee +++ b/app/assets/javascripts/app/controllers/widget/online_notification.coffee @@ -114,6 +114,8 @@ class App.OnlineNotificationWidget extends App.Controller count = '' if count is 0 $('.js-notificationsCounter').text(count) + App.Event.trigger('online_notification_counter', count.toString()) + @count = count # show mark all as read if needed diff --git a/app/assets/javascripts/app/lib/app_post/interface_handle.coffee b/app/assets/javascripts/app/lib/app_post/interface_handle.coffee index 1836d605f..aa6583818 100644 --- a/app/assets/javascripts/app/lib/app_post/interface_handle.coffee +++ b/app/assets/javascripts/app/lib/app_post/interface_handle.coffee @@ -43,7 +43,9 @@ class App.Run extends App.Controller App.Event.trigger(event + ':init') widgets = App.Config.get(config) if widgets - for key, widget of widgets + sortedKeys = Object.keys(widgets).sort() + for key in sortedKeys + widget = widgets[key] new widget( el: el key: key diff --git a/app/assets/javascripts/app/lib/base/email-addresses.js b/app/assets/javascripts/app/lib/base/email-addresses.js index 2c3bad078..912c6c5d5 100644 --- a/app/assets/javascripts/app/lib/base/email-addresses.js +++ b/app/assets/javascripts/app/lib/base/email-addresses.js @@ -945,7 +945,9 @@ function handleOpts(opts, defs) { parse5322.parseOneAddress = parseOneAddressSimple; parse5322.parseAddressList = parseAddressListSimple; -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { +// if electron is used, go back to non CommonJS +//if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { +if (typeof module !== 'undefined' && typeof module.exports !== 'undefined' && !(process && process.version && process.versions.electron)) { module.exports = parse5322; } else { global.emailAddresses = parse5322; diff --git a/app/assets/javascripts/app/lib/core/jquery-2.2.1.js b/app/assets/javascripts/app/lib/core/jquery-2.2.1.js index b7c491f4c..7820de241 100644 --- a/app/assets/javascripts/app/lib/core/jquery-2.2.1.js +++ b/app/assets/javascripts/app/lib/core/jquery-2.2.1.js @@ -14,7 +14,9 @@ (function( global, factory ) { - if ( typeof module === "object" && typeof module.exports === "object" ) { + // if electron is used, go back to non CommonJS + //if ( typeof module === "object" && typeof module.exports === "object" ) { + if ( typeof module === "object" && typeof module.exports === "object" && !(process && process.version && process.versions.electron)) { // For CommonJS and CommonJS-like environments where a proper `window` // is present, execute the factory and get jQuery. // For environments that do not have a `window` with a `document`