diff --git a/.gitignore b/.gitignore index c346b13..a2291bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ bower_components/ node_modules/ + +# Electron stuff +fonts/ +Glowing\ Bear-*/ diff --git a/README.md b/README.md index 61cff33..bf3aaba 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,15 @@ Now point your browser to the [Glowing Bear](http://www.glowing-bear.org)! If yo Please note that the above instructions set up an *unencrypted* relay, and all your data will be transmitted in clear. Therefore, we strongly recommend that you set up encryption if you want to keep using Glowing Bear. We've written [a detailed guide on how to set up a trusted secure relay](https://4z2.de/2014/07/06/weechat-trusted-relay) for you. -You can run Glowing Bear in many ways: use it like any other webpage, as an app in Firefox (choose "Install app" on the landing page) or Chrome ("Tools", then "Create application shortcuts"), or a full-screen Chrome app on Android ("Add to homescreen"). We also provide an [Android app](https://play.google.com/store/apps/details?id=com.glowing_bear) that you can install from the Google Play Store, and a [Firefox OS app](https://marketplace.firefox.com/app/glowing-bear/) in the Firefox Marketplace. +You can run Glowing Bear in many ways: + + * like any other webpage + * as an app in Firefox (choose "Install app" on the landing page) + * Chrome app ("Tools", then "Create application shortcuts") + * Android Chrome app a full-screen experience ("Add to homescreen"). + * [Android app](https://play.google.com/store/apps/details?id=com.glowing_bear) that you can install from the Google Play Store + * [Firefox OS app](https://marketplace.firefox.com/app/glowing-bear/) in the Firefox Marketplace. + * Electron app, for Windows, Linux and MacOSX. ```npm install; npm install electron-packager; npm run build-electron-{windows, darwin, linux}``` diff --git a/assets/img/glowing-bear.icns b/assets/img/glowing-bear.icns new file mode 100644 index 0000000..968d9f3 Binary files /dev/null and b/assets/img/glowing-bear.icns differ diff --git a/bower.json b/bower.json index 72a4e1c..be44d88 100644 --- a/bower.json +++ b/bower.json @@ -12,6 +12,9 @@ "angular-touch": "1.4.x", "angular-loader": "1.4.x", "angular-mocks": "1.4.x", - "html5-boilerplate": "~4.3.0" + "html5-boilerplate": "~4.3.0", + "underscore": "~1.7", + "bootstrap": "~3.1", + "emojione": "~2.1" } } diff --git a/electron-globals.js b/electron-globals.js new file mode 100644 index 0000000..1459c70 --- /dev/null +++ b/electron-globals.js @@ -0,0 +1,19 @@ +/** + * Global functions for electron app + */ +var ipc = require('electron').ipcRenderer; + +// Set app bagde +var setElectronBadge = function(value) { + // Check ipc + if (ipc && typeof ipc.send === 'function') { + // Send new badge value + ipc.send('badge', value); + } +}; + +// Export global variables and functions +global.setElectronBadge = setElectronBadge; + +// Let Glowing Bear know it's running as an electron app +window.is_electron = 1; diff --git a/electron-main.js b/electron-main.js new file mode 100644 index 0000000..729323e --- /dev/null +++ b/electron-main.js @@ -0,0 +1,219 @@ +(function() { + 'use strict'; + const electron = require('electron'); + const app = electron.app; // Module to control application life. + const BrowserWindow = electron.BrowserWindow; // Module to create native browser window. + + const ipcMain = require('electron').ipcMain; + const nativeImage = require('electron').nativeImage; + const Menu = require('electron').Menu; + + var template; + + template = [ + { + label: 'Edit', + submenu: [ + { + label: 'Undo', + accelerator: 'CmdOrCtrl+Z', + role: 'undo' + }, + { + label: 'Redo', + accelerator: 'Shift+CmdOrCtrl+Z', + role: 'redo' + }, + { + type: 'separator' + }, + { + label: 'Cut', + accelerator: 'CmdOrCtrl+X', + role: 'cut' + }, + { + label: 'Copy', + accelerator: 'CmdOrCtrl+C', + role: 'copy' + }, + { + label: 'Paste', + accelerator: 'CmdOrCtrl+V', + role: 'paste' + }, + { + label: 'Select All', + accelerator: 'CmdOrCtrl+A', + role: 'selectall' + }, + ] + }, + { + label: 'View', + submenu: [ + { + label: 'Reload', + accelerator: 'CmdOrCtrl+R', + click: function(item, focusedWindow) { + if (focusedWindow) + focusedWindow.reload(); + } + }, + { + label: 'Toggle Full Screen', + accelerator: (function() { + if (process.platform == 'darwin') + return 'Ctrl+Command+F'; + else + return 'F11'; + })(), + click: function(item, focusedWindow) { + if (focusedWindow) + focusedWindow.setFullScreen(!focusedWindow.isFullScreen()); + } + }, + { + label: 'Toggle Developer Tools', + accelerator: (function() { + if (process.platform == 'darwin') + return 'Alt+Command+I'; + else + return 'Ctrl+Shift+I'; + })(), + click: function(item, focusedWindow) { + if (focusedWindow) + focusedWindow.toggleDevTools(); + } + }, + ] + }, + { + label: 'Window', + role: 'window', + submenu: [ + { + label: 'Minimize', + accelerator: 'CmdOrCtrl+M', + role: 'minimize' + }, + { + label: 'Close', + accelerator: 'CmdOrCtrl+W', + role: 'close' + }, + ] + }, + { + label: 'Help', + role: 'help', + submenu: [ + { + label: 'Learn More', + click: function() { require('electron').shell.openExternal('https://github.com/glowing-bear/glowing-bear'); } + }, + ] + }, + ]; + + if (process.platform == 'darwin') { + var name = app.getName(); + template.unshift({ + label: name, + submenu: [ + { + label: 'About ' + name, + role: 'about' + }, + { + type: 'separator' + }, + { + label: 'Services', + role: 'services', + submenu: [] + }, + { + type: 'separator' + }, + { + label: 'Hide ' + name, + accelerator: 'Command+H', + role: 'hide' + }, + { + label: 'Hide Others', + accelerator: 'Command+Alt+H', + role: 'hideothers' + }, + { + label: 'Show All', + role: 'unhide' + }, + { + type: 'separator' + }, + { + label: 'Quit', + accelerator: 'Command+Q', + click: function() { app.quit(); } + }, + ] + }); + // Window menu. + template[3].submenu.push( + { + type: 'separator' + }, + { + label: 'Bring All to Front', + role: 'front' + } + ); + } + + // Keep a global reference of the window object, if you don't, the window will + // be closed automatically when the JavaScript object is garbage collected. + var mainWindow = null; + + app.on('browser-window-focus', function(e, w) { + w.webContents.send('browser-window-focus'); + }); + + app.on('ready', function() { + + var menu = Menu.buildFromTemplate(template); + Menu.setApplicationMenu(menu); + + mainWindow = new BrowserWindow({width: 1280, height: 800, 'min-width': 1024, 'min-height': 600, 'autoHideMenuBar': true, 'web-security': true, 'java': false, 'accept-first-mouse': true, defaultEncoding: 'UTF-8', 'icon':'file://'+__dirname + '/assets/img/favicon.png'}); + mainWindow.loadURL('file://' + __dirname + '/electron-start.html'); + mainWindow.focus(); + + // Listen for badge changes + ipcMain.on('badge', function(event, arg) { + if (process.platform === "darwin") { + app.dock.setBadge(String(arg)); + } + else if (process.platform === "win32") { + let n = parseInt(arg, 10); + // Only show notifications with number + if (isNaN(n)) { + return; + } + if (n > 0) { + mainWindow.setOverlayIcon(__dirname + '/assets/img/favicon.ico', String(arg)); + } else { + mainWindow.setOverlayIcon(null, ''); + } + } + }); + + mainWindow.on('devtools-opened', function() { + mainWindow.webContents.executeJavaScript("document.getElementById('glowingbear').openDevTools();"); + }); + + mainWindow.on('closed', function() { + app.quit(); + }); + }); +})(); diff --git a/electron-start.html b/electron-start.html new file mode 100644 index 0000000..028a7a9 --- /dev/null +++ b/electron-start.html @@ -0,0 +1,37 @@ + + +
+ + + + +