Skip to content

Commit

Permalink
Refactor and simplify login error events
Browse files Browse the repository at this point in the history
* Add event listener for DC_EVENT_CONFIGURE_PROGRESS instead of checking for 2041 magic number
* emit 'DC_EVENT_LOGIN_FAILED' so ipc can attach event listener to this instead of checking magic number 0
  • Loading branch information
Lars-Magnus Skog committed Jan 15, 2019
1 parent 2ba1a33 commit 97639e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
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
19 changes: 5 additions & 14 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ function init (cwd, state) {
main.send('DC_EVENT_IMEX_PROGRESS', progress)
})

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

dc.on('DC_EVENT_CONFIGURE_PROGRESS', data1 => {
if (Number(data1) === 0) {
main.send('error', 'Login failed!')
}
})
dc.on('DC_EVENT_LOGIN_FAILED', () => main.send('error', 'Login failed!'))

ipcMain.once('ipcReady', e => {
app.ipcReady = true
Expand Down Expand Up @@ -119,16 +115,11 @@ function init (cwd, state) {
})

ipcMain.on('updateCredentials', (e, credentials) => {
var dir = path.join(os.tmpdir(), Date.now().toString())
const dir = path.join(os.tmpdir(), Date.now().toString())
if (!credentials.mailPw) credentials.mailPw = dc.getConfig('mail_pw')
var tmp = new DeltaChat(dir, state.saved)
const tmp = new DeltaChat(dir, state.saved)

tmp.on('DC_EVENT_CONFIGURE_PROGRESS', data1 => {
if (Number(data1) === 0) {
main.send('error', 'Login failed')
tmp.close()
}
})
tmp.on('DC_EVENT_LOGIN_FAILED', () => main.send('error', 'Login failed!'))

function fakeRender () {
const deltachat = dc.render()
Expand Down

0 comments on commit 97639e7

Please sign in to comment.