Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Commit

Permalink
Removed electron-rpc and stuck with the default ipc to resolve memory…
Browse files Browse the repository at this point in the history
… leaks and issue #2
  • Loading branch information
Thomas101 committed Jan 14, 2016
1 parent 0e8f62a commit e4fc275
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 49 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.sh
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
30 changes: 15 additions & 15 deletions src/auth/GoogleAuthServer.js → src/auth/googleAuth.js
Original file line number Diff line number Diff line change
@@ -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)
})
}

/*****************************************************************************/
Expand All @@ -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,
Expand All @@ -38,7 +35,7 @@ class GoogleAuthServer {
autoHideMenuBar : true,
webPreferences : {
nodeIntegration : false,
partition : "persist:" + req.body.id
partition : "persist:" + body.id
}
}).getAccessToken(
[
Expand All @@ -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
module.exports = new GoogleAuth()
8 changes: 3 additions & 5 deletions src/mailbox/js/actions/mailbox.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"use strict"

const MMailbox = require('../models/MMailbox')
const GoogleAuthClient = require('../../../auth/GoogleAuthClient')
const googleAuth = require('../auth/googleAuth')

module.exports = {
/**
* Adds a gmail mailbox
* @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
Expand All @@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/auth/GoogleAuthClient.js → src/mailbox/js/auth/googleAuth.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"use strict"

const Client = require('electron-rpc/client')
const ipcRenderer = require('electron').ipcRenderer;

class GoogleAuthClient {
/*****************************************************************************/
// Lifecycle
/*****************************************************************************/

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]
})
}

/*****************************************************************************/
Expand All @@ -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
module.exports = new GoogleAuthClient()
15 changes: 8 additions & 7 deletions src/mailbox/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -19,16 +20,15 @@ class App {
this.mailboxes = new Mailboxes(this)

this.googleMailbox = new GoogleMailboxSyncManger(this)
this.rpcClient = new RPCClient()
}

load() {
// Bind event listeners
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
Expand Down Expand Up @@ -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 })
}

/**
Expand Down
14 changes: 5 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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, []))
Expand All @@ -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))
})


Expand Down

0 comments on commit e4fc275

Please sign in to comment.