Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc cleanup #588

Merged
merged 4 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/main/deltachat.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ class DeltaChatController extends events.EventEmitter {

dc.on('ALL', (event, data1, data2) => {
log.debug('ALL event', { event, data1, data2 }, event)
if (event === 2041) {
this.logCoreEvent('DC_EVENT_CONFIGURE_PROGRESS', data1)
this.emit('DC_EVENT_CONFIGURE_PROGRESS', data1, data2)
if (Number(data1) === 0) { // login failed
this.logout()
}
})

dc.on('DC_EVENT_CONFIGURE_PROGRESS', progress => {
this.logCoreEvent('DC_EVENT_CONFIGURE_PROGRESS', progress)
if (Number(progress) === 0) { // login failed
this.emit('DC_EVENT_LOGIN_FAILED')
this.logout()
}
})

Expand Down
100 changes: 44 additions & 56 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,122 +16,110 @@ const setupNotifications = require('./notifications')
const logHandler = require('./developerTools/logHandler')

function init (cwd, state) {
const ipc = ipcMain
const main = windows.main
const dc = new DeltaChat(cwd, state.saved)

dc.on('ready', function () {
dc.on('ready', () => {
if (!state.logins.includes(dc.credentials.addr)) {
state.logins.push(dc.credentials.addr)
}
})

ipc.once('ipcReady', function (e) {
dc.on('DC_EVENT_IMEX_FILE_WRITTEN', filename => {
main.send('DC_EVENT_IMEX_FILE_WRITTEN', filename)
})

dc.on('DC_EVENT_IMEX_PROGRESS', progress => {
main.send('DC_EVENT_IMEX_PROGRESS', progress)
})

dc.on('error', error => main.send('error', error))

dc.on('DC_EVENT_LOGIN_FAILED', () => main.send('error', 'Login failed!'))

ipcMain.once('ipcReady', e => {
app.ipcReady = true
app.emit('ipcReady')
})

ipc.on('setAspectRatio', (e, ...args) => main.setAspectRatio(...args))
ipc.on('setBounds', (e, ...args) => main.setBounds(...args))
ipc.on('setProgress', (e, ...args) => main.setProgress(...args))
ipc.on('show', () => main.show())
ipc.on('setAllowNav', (e, ...args) => menu.setAllowNav(...args))
ipc.on('chooseLanguage', (e, locale) => {
ipcMain.on('setAspectRatio', (e, ...args) => main.setAspectRatio(...args))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to grep for ipcMain to see which ipc event listeners we have in the main process

ipcMain.on('setBounds', (e, ...args) => main.setBounds(...args))
ipcMain.on('setProgress', (e, ...args) => main.setProgress(...args))
ipcMain.on('show', () => main.show())
ipcMain.on('setAllowNav', (e, ...args) => menu.setAllowNav(...args))
ipcMain.on('chooseLanguage', (e, locale) => {
localize.setup(app, locale)
dc.setCoreStrings(txCoreStrings())
menu.init()
})

ipc.on('handleLogMessage', (e, ...args) => logHandler.log(...args))
ipcMain.on('handleLogMessage', (e, ...args) => logHandler.log(...args))

setupNotifications(dc, state.saved)

// Create a new instance
ipc.on('login', (e, ...args) => {
ipcMain.on('login', (e, ...args) => {
dc.login(...args, render, txCoreStrings())
})

ipc.on('forgetLogin', (e, addr) => {
ipcMain.on('forgetLogin', (e, addr) => {
var targetDir = dc.getPath(addr)
rimraf.sync(targetDir)
state.logins.splice(state.logins.indexOf(addr), 1)
render()
})

dc.on('DC_EVENT_IMEX_FILE_WRITTEN', (filename) => {
windows.main.send('DC_EVENT_IMEX_FILE_WRITTEN', filename)
})

dc.on('DC_EVENT_IMEX_PROGRESS', (progress) => {
windows.main.send('DC_EVENT_IMEX_PROGRESS', progress)
})

dc.on('error', (error) => {
windows.main.send('error', error)
})

dc.on('DC_EVENT_CONFIGURE_PROGRESS', function (data1) {
if (Number(data1) === 0) { // login failed
windows.main.send('error', 'Login failed!')
}
})

// Calls a function directly in the deltachat-node instance and returns the
// value (sync)
ipc.on('dispatchSync', (e, ...args) => {
ipcMain.on('dispatchSync', (e, ...args) => {
e.returnValue = dispatch(...args)
})

// Calls the function without returning the value (async)
ipc.on('dispatch', (e, ...args) => {
ipcMain.on('dispatch', (e, ...args) => {
dispatch(...args)
})

ipc.on('initiateKeyTransfer', (e, ...args) => {
ipcMain.on('initiateKeyTransfer', (e, ...args) => {
dc.initiateKeyTransfer((err, resp) => {
windows.main.send('initiateKeyTransferResp', err, resp)
main.send('initiateKeyTransferResp', err, resp)
})
})

ipc.on('continueKeyTransfer', (e, messageId, setupCode) => {
dc.continueKeyTransfer(messageId, setupCode, function (err) {
windows.main.send('continueKeyTransferResp', err)
ipcMain.on('continueKeyTransfer', (e, messageId, setupCode) => {
dc.continueKeyTransfer(messageId, setupCode, err => {
main.send('continueKeyTransferResp', err)
})
})

ipc.on('saveFile', (e, source, target) => {
fs.copyFile(source, target, function (err) {
if (err) windows.main.send('error', err.message)
ipcMain.on('saveFile', (e, source, target) => {
fs.copyFile(source, target, err => {
if (err) main.send('error', err.message)
})
})