From e4fc275fcbc2d2bf4a19bb16ec5617b0c340b7d0 Mon Sep 17 00:00:00 2001 From: Thomas Beverley Date: Thu, 14 Jan 2016 22:52:23 +0000 Subject: [PATCH] Removed electron-rpc and stuck with the default ipc to resolve memory leaks and issue #2 --- package.json | 3 +- package.sh | 2 +- .../{GoogleAuthServer.js => googleAuth.js} | 30 +++++++++---------- src/mailbox/js/actions/mailbox.js | 8 ++--- .../js/auth/googleAuth.js} | 21 ++++++------- src/mailbox/js/index.js | 15 +++++----- src/main.js | 14 ++++----- 7 files changed, 44 insertions(+), 49 deletions(-) rename src/auth/{GoogleAuthServer.js => googleAuth.js} (68%) rename src/{auth/GoogleAuthClient.js => mailbox/js/auth/googleAuth.js} (62%) diff --git a/package.json b/package.json index 7fd57362..ad405664 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wmail", - "version": "1.1.1", + "version": "1.1.2", "description": "OSX app wrapper for Google Inbox and Google Mail", "main": "src/main.js", "scripts": { @@ -19,7 +19,6 @@ "compare-version": "^0.1.2", "electron-google-oauth": "^1.1.4", "electron-localshortcut": "^0.6.0", - "electron-rpc": "^1.0.3", "googleapis": "^2.1.7", "node-fetch": "^1.3.3", "node-localstorage": "^1.1.2", diff --git a/package.sh b/package.sh index 94585adf..61d0d55f 100644 --- a/package.sh +++ b/package.sh @@ -1,6 +1,6 @@ #!/bin/bash -electron-packager . "WMail" --platform=darwin --arch=all --version=0.36.2 --app-bundle-id="tombeverley.wmail" --app-version="1.1.1" --icon="icons/app.icns" --overwrite --ignore="/release/|/icons/|package.sh|screenshot.png|README.md"; +electron-packager . "WMail" --platform=darwin --arch=all --version=0.36.2 --app-bundle-id="tombeverley.wmail" --app-version="1.1.2" --icon="icons/app.icns" --overwrite --ignore="/release/|/icons/|package.sh|screenshot.png|README.md"; mkdir ./WMail-darwin-x64/vendor-licenses; mv ./WMail-darwin-x64/LICENSES.chromium.html ./WMail-darwin-x64/vendor-licenses/LICENSES.chromium.html; mv ./WMail-darwin-x64/LICENSE ./WMail-darwin-x64/vendor-licenses/LICENSE.electron; diff --git a/src/auth/GoogleAuthServer.js b/src/auth/googleAuth.js similarity index 68% rename from src/auth/GoogleAuthServer.js rename to src/auth/googleAuth.js index 786eee43..09040290 100644 --- a/src/auth/GoogleAuthServer.js +++ b/src/auth/googleAuth.js @@ -1,21 +1,18 @@ "use strict" -const Server = require('electron-rpc/server') +const ipcMain = require('electron').ipcMain; const electronGoogleOauth = require('electron-google-oauth') const credentials = require('../credentials') -class GoogleAuthServer { +class GoogleAuth { /*****************************************************************************/ // Lifecycle /*****************************************************************************/ - /** - * @param webContent: the webcontent to listen on - */ - constructor(webContent) { - this.app = new Server() - this.app.configure(webContent) - this.app.on('authgoogle', (req, done) => this.handleAuthGoogle(req, done)) + constructor() { + ipcMain.on('auth-google', (evt, body) => { + this.handleAuthGoogle(evt, body) + }) } /*****************************************************************************/ @@ -24,10 +21,10 @@ class GoogleAuthServer { /** * Handles the oauth request - * @param req: the incoming request - * @param done: the function to call on completion + * @param evt: the incoming event + * @param body: the body sent to us */ - handleAuthGoogle(req, done) { + handleAuthGoogle(evt, body) { electronGoogleOauth(undefined, { useContentSize : true, center : true, @@ -38,7 +35,7 @@ class GoogleAuthServer { autoHideMenuBar : true, webPreferences : { nodeIntegration : false, - partition : "persist:" + req.body.id + partition : "persist:" + body.id } }).getAccessToken( [ @@ -50,9 +47,12 @@ class GoogleAuthServer { credentials.GOOGLE_CLIENT_ID, credentials.GOOGLE_CLIENT_SECRET ).then(auth => { - done(null, auth) + evt.sender.send('auth-google-complete', { + id : body.id, + auth : auth + }) }) } } -module.exports = GoogleAuthServer \ No newline at end of file +module.exports = new GoogleAuth() \ No newline at end of file diff --git a/src/mailbox/js/actions/mailbox.js b/src/mailbox/js/actions/mailbox.js index 34979983..c8c058dd 100644 --- a/src/mailbox/js/actions/mailbox.js +++ b/src/mailbox/js/actions/mailbox.js @@ -1,7 +1,7 @@ "use strict" const MMailbox = require('../models/MMailbox') -const GoogleAuthClient = require('../../../auth/GoogleAuthClient') +const googleAuth = require('../auth/googleAuth') module.exports = { /** @@ -9,9 +9,8 @@ module.exports = { * @param app: the app reference that can process callbacks */ addGmailMailbox : function(app) { - let client = new GoogleAuthClient() let id = MMailbox.provisionId() - client.auth(id).then(auth => { + googleAuth.auth(id).then(auth => { let mailbox = MMailbox.create(id) mailbox.type = 'gmail' mailbox.googleAuth = auth @@ -26,9 +25,8 @@ module.exports = { * @param app: the app reference that can process callbacks */ addInboxMailbox : function(app) { - let client = new GoogleAuthClient() let id = MMailbox.provisionId() - client.auth(id).then(auth => { + googleAuth.auth(id).then(auth => { let mailbox = MMailbox.create(id) mailbox.type = 'ginbox' mailbox.googleAuth = auth diff --git a/src/auth/GoogleAuthClient.js b/src/mailbox/js/auth/googleAuth.js similarity index 62% rename from src/auth/GoogleAuthClient.js rename to src/mailbox/js/auth/googleAuth.js index d3e538bd..90c0eb34 100644 --- a/src/auth/GoogleAuthClient.js +++ b/src/mailbox/js/auth/googleAuth.js @@ -1,6 +1,6 @@ "use strict" -const Client = require('electron-rpc/client') +const ipcRenderer = require('electron').ipcRenderer; class GoogleAuthClient { /*****************************************************************************/ @@ -8,7 +8,11 @@ class GoogleAuthClient { /*****************************************************************************/ constructor() { - this.client = new Client() + this.requests = {} + ipcRenderer.on('auth-google-complete', (evt, body) => { + this.requests[body.id](evt, body) + delete this.requests[body.id] + }) } /*****************************************************************************/ @@ -22,15 +26,12 @@ class GoogleAuthClient { */ auth(id) { return new Promise((resolve, reject) => { - this.client.request('authgoogle', { id:id }, (err, body) => { - if (err) { - reject(err) - } else { - resolve(body) - } - }) + this.requests[id] = (evt, body) => { + resolve(body.auth) + } + ipcRenderer.send('auth-google', { id:id }) }) } } -module.exports = GoogleAuthClient \ No newline at end of file +module.exports = new GoogleAuthClient() \ No newline at end of file diff --git a/src/mailbox/js/index.js b/src/mailbox/js/index.js index ea87c35f..454954dc 100644 --- a/src/mailbox/js/index.js +++ b/src/mailbox/js/index.js @@ -5,7 +5,8 @@ const Mailboxes = require('./js/Mailboxes') const MMailbox = require('./js/models/MMailbox') const GoogleMailboxSyncManger = require('./js/sync/GoogleMailboxSyncManager') const credentials = require('../credentials') -const RPCClient = require('electron-rpc/client') +const ipcRenderer = require('electron').ipcRenderer; + const remote = require('remote'); const app = remote.require('app'); @@ -19,7 +20,6 @@ class App { this.mailboxes = new Mailboxes(this) this.googleMailbox = new GoogleMailboxSyncManger(this) - this.rpcClient = new RPCClient() } load() { @@ -27,8 +27,8 @@ class App { document.addEventListener('drop', evt => { evt.preventDefault() }, false) document.addEventListener('dragover', evt => { evt.preventDefault() }, false) document.addEventListener('dragover', evt => { evt.preventDefault() }, false) - this.rpcClient.on('switch-mailbox', (err, res) => { - this.procChangeActive(res.mailboxId) + ipcRenderer.on('switch-mailbox', (evt, body) => { + this.procChangeActive(body.mailboxId) }) // Render our first run @@ -92,10 +92,11 @@ class App { app.dock.setBadge('') } - const mailboxSummaries = MMailbox.all().map(mailbox => { - return { id:mailbox.id, name:mailbox.name, email:mailbox.email } + ipcRenderer.send('mailboxes-changed', { + mailboxes : MMailbox.all().map(mailbox => { + return { id:mailbox.id, name:mailbox.name, email:mailbox.email } + }) }) - this.rpcClient.request('mailboxes-changed', { mailboxes:mailboxSummaries }) } /** diff --git a/src/main.js b/src/main.js index c476f9e8..dde8e9d0 100644 --- a/src/main.js +++ b/src/main.js @@ -4,17 +4,15 @@ const app = require('app') const BrowserWindow = require('browser-window') const Menu = require('menu') const shell = require('shell') -const GoogleAuthServer = require('./auth/GoogleAuthServer') +const googleAuth = require('./auth/googleAuth') const CONSTANTS = require('./constants') const update = require('./update') const analytics = require('./analytics') const appMenu = require('./appMenu') -const RPCServer = require('electron-rpc/server') +const ipcMain = require('electron').ipcMain let mailboxWindow -let googleAuth let fullQuit = false -let rpcServer = new RPCServer() /*****************************************************************************/ // App Lifecycle @@ -45,7 +43,6 @@ app.on('ready', function() { } }) mailboxWindow.loadURL('file://' + __dirname + '/mailbox/index.html') - googleAuth = new GoogleAuthServer(mailboxWindow.webContents) // Setup the menu & Shortcuts const appMenuSelectors = { @@ -56,7 +53,7 @@ app.on('ready', function() { learnMore : () => { shell.openExternal(CONSTANTS.GITHUB_URL) }, bugReport : () => { shell.openExternal(CONSTANTS.GITHUB_ISSUE_URL) }, mailbox : (mailboxId) => { - rpcServer.send('switch-mailbox', { mailboxId:mailboxId }) + mailboxWindow.webContents.send('switch-mailbox', {mailboxId:mailboxId }) } } Menu.setApplicationMenu(appMenu.build(appMenuSelectors, [])) @@ -77,9 +74,8 @@ app.on('ready', function() { }) // Bind to page events - rpcServer.configure(mailboxWindow.webContents) - rpcServer.on('mailboxes-changed', (req) => { - Menu.setApplicationMenu(appMenu.build(appMenuSelectors, req.body.mailboxes)) + ipcMain.on('mailboxes-changed', (evt, body) => { + Menu.setApplicationMenu(appMenu.build(appMenuSelectors, body.mailboxes)) })