[beast: 54/70] EBEAST: move application logic into app.js
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 54/70] EBEAST: move application logic into app.js
- Date: Tue, 28 Mar 2017 23:26:15 +0000 (UTC)
commit 921bb066f42244d130ec217109ba44981c6f3228
Author: Tim Janik <timj gnu org>
Date: Tue Mar 7 17:44:58 2017 +0100
EBEAST: move application logic into app.js
Signed-off-by: Tim Janik <timj gnu org>
ebeast/app.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
ebeast/index.html | 49 +++++--------------------------------------------
ebeast/main.js | 11 +++++++----
ebeast/menus.js | 4 +++-
4 files changed, 66 insertions(+), 49 deletions(-)
---
diff --git a/ebeast/app.js b/ebeast/app.js
new file mode 100644
index 0000000..b9a94fe
--- /dev/null
+++ b/ebeast/app.js
@@ -0,0 +1,51 @@
+'use strict';
+
+// load external libraries
+window.Electron = require ('electron').remote;
+window.Bse = require ('./v8bse/v8bse.node');
+// window.$ = preloaded jQuery
+window.Mithril = require ('mithril');
+
+// Assign global App object with defaults
+window.App = {
+ show_about: false,
+ __proto__ : Electron.app
+};
+Object.preventExtensions (App);
+
+// load application parts that depend on App
+const Widgets = require ('./assets/widgets.js');
+const Dialogs = require ('./assets/dialogs.js');
+const Menus = require ('./menus.js');
+const m = Mithril;
+
+// assign BrowserWindow's menubar
+Electron.Menu.setApplicationMenu (Menus.build_menubar());
+
+// Application start onready
+module.exports.start_app = function () {
+ Dialogs.toggle_about = function() {
+ const m = Mithril;
+ return (
+ m ('button',
+ { onclick: function () { App.show_about = !App.show_about; } },
+ 'Toggle About')
+ );
+ };
+
+ const MithrilApp = {
+ view: function () {
+ const m = Mithril;
+ const app_body = [
+ Dialogs.toggle_about(),
+ Dialogs.about_dialog(),
+ ];
+ return (
+ m ('div#mithril.Mithril', {
+ style: 'position: absolute; top: 0; left: 0; right: 0; bottom: 0;',
+ }, app_body)
+ );
+ }
+ };
+ m.mount (document.body, MithrilApp);
+};
diff --git a/ebeast/index.html b/ebeast/index.html
index dca68d9..ad9678d 100644
--- a/ebeast/index.html
+++ b/ebeast/index.html
@@ -7,50 +7,11 @@
<script>
'use strict';
- const Electron = require ('electron').remote;
- const Bse = require ('./v8bse/v8bse.node');
- 0 + Bse; // FIXME 'unused' warnings
- const Mithril = require ('mithril');
+ /* Load application code right away, start application once DOM is ready */
window.$ = window.jQuery = require ('jquery');
- const Dialogs = require ('./assets/dialogs.js');
- const Menus = require ('./menus.js');
- 0 + Menus; // FIXME 'unused' warnings
- const App = {
- show_about: false,
- __proto__ : Electron.app
- };
- Object.preventExtensions (App);
+ $(require ('./app.js').start_app);
</script>
-</head><body>
-
- <script>
- Dialogs.toggle_about = function() {
- const m = Mithril;
- return (
- m ('button',
- { onclick: function () { App.show_about = !App.show_about; } },
- 'Toggle About')
- );
- };
- </script>
-
- <script>
- const MithrilApp = {
- view: function () {
- const m = Mithril;
- const app_body = [
- Dialogs.toggle_about(),
- Dialogs.about_dialog(),
- ];
- return (
- m ('div#mithril.Mithril', {
- style: 'position: absolute; top: 0; left: 0; right: 0; bottom: 0;',
- }, app_body)
- );
- }
- };
- Mithril.mount (document.body, MithrilApp);
- </script>
-
-</body></html>
+</head>
+<body></body>
+</html>
diff --git a/ebeast/main.js b/ebeast/main.js
index 77639f5..83a064a 100644
--- a/ebeast/main.js
+++ b/ebeast/main.js
@@ -1,10 +1,13 @@
// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
-const {app, BrowserWindow} = require ('electron');
+const Electron = require ('electron');
// create the main ebeast window
var win;
function create_window ()
{
+ // avoid menu flicker, leave menu construction to the window
+ Electron.Menu.setApplicationMenu (null);
+ // window configuraiton
const options = {
width: 1820, height: 1024, // calling win.maximize() flickers, using a big size not
webPreferences: {
@@ -24,13 +27,13 @@ function create_window ()
darkTheme: true,
backgroundColor: '#333333',
};
- win = new BrowserWindow (options);
+ win = new Electron.BrowserWindow (options);
win.once ('ready-to-show', () => { win.show(); });
win.loadURL ('file:///' + __dirname + '/index.html');
// win.webContents.openDevTools();
win.on ('closed', () => { win = null; });
}
-app.on ('ready', create_window); // create window once everything is loaded
+Electron.app.on ('ready', create_window); // create window once everything is loaded
// quit when all windows are closed.
-app.on ('window-all-closed', app.quit);
+Electron.app.on ('window-all-closed', Electron.app.quit);
diff --git a/ebeast/menus.js b/ebeast/menus.js
index 4099be3..5145f08 100644
--- a/ebeast/menus.js
+++ b/ebeast/menus.js
@@ -33,7 +33,9 @@ function assign_click (item, func) {
assign_click (menubar_menus, (menuitem, _focusedBrowserWindow, _event) => {
app_command (menuitem.role, menuitem.data);
});
-Electron.Menu.setApplicationMenu (Electron.Menu.buildFromTemplate (menubar_menus));
+module.exports.build_menubar = function () {
+ return Electron.Menu.buildFromTemplate (menubar_menus);
+};
// handle menu activations
function app_command (role, _data) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]