This removes all AngularJS code Angular version 1 is unmaintained and largely obsolete since years. Additionally, I'd rather re-use the conventions and libraries from Converse instead of having different ones in converse-desktop. This means we're losing some functionality, such as the app settings and the about modal. This is unfortunate, but ideally (non-Electron) app settings should be implemented in Converse itself and not in this repo.
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
/* global require, module */
|
|
|
|
const settings = require('electron-settings');
|
|
const keytar = require('keytar')
|
|
|
|
function addCredentials (connectionManager, login, password) {
|
|
const xmppService = login.split('@').pop()
|
|
settings.setSync('connectionManager', connectionManager)
|
|
settings.setSync('login', login)
|
|
keytar.setPassword(xmppService, login, password)
|
|
}
|
|
|
|
function getCredentials () {
|
|
const credentials = {}
|
|
credentials.login = settings.getSync('login')
|
|
return new Promise((resolve) => {
|
|
if (credentials.login) {
|
|
credentials.connectionManager = settings.getSync('connectionManager')
|
|
credentials.xmppService = credentials.login.split('@').pop()
|
|
let password = keytar.getPassword(credentials.xmppService, credentials.login)
|
|
password.then((result) => {
|
|
credentials.password = result
|
|
resolve(credentials)
|
|
})
|
|
} else {
|
|
resolve({});
|
|
}
|
|
});
|
|
}
|
|
|
|
function removeCredentials (login) {
|
|
const xmppService = login.split('@').pop()
|
|
const passwordDelete = keytar.deletePassword(xmppService, login)
|
|
return new Promise((resolve, reject) => {
|
|
passwordDelete.then(() => {
|
|
settings.unsetSync('login')
|
|
settings.unsetSync('connectionManager')
|
|
resolve()
|
|
}, (error) => {
|
|
reject(error)
|
|
})
|
|
})
|
|
}
|
|
|
|
module.exports = {
|
|
addCredentials,
|
|
getCredentials,
|
|
removeCredentials
|
|
}
|