2022-01-22 03:01:40 +00:00
|
|
|
/* global api */
|
2021-12-01 10:54:41 +00:00
|
|
|
|
2022-01-22 03:01:40 +00:00
|
|
|
async function addCredentials(connectionManager, login, password) {
|
2021-12-01 10:54:41 +00:00
|
|
|
const xmppService = login.split('@').pop()
|
2022-01-22 03:01:40 +00:00
|
|
|
await api.settings.set('connectionManager', connectionManager)
|
|
|
|
await api.settings.set('login', login)
|
|
|
|
await api.keytar.setPassword(xmppService, login, password)
|
2021-12-01 10:54:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 03:01:40 +00:00
|
|
|
async function getCredentials() {
|
2021-12-01 10:54:41 +00:00
|
|
|
const credentials = {}
|
2022-01-22 03:01:40 +00:00
|
|
|
credentials.login = await api.settings.get('login')
|
|
|
|
if (credentials.login) {
|
|
|
|
credentials.connectionManager = await api.settings.get('connectionManager') || null
|
|
|
|
credentials.xmppService = credentials.login.split('@').pop()
|
|
|
|
credentials.password = await api.keytar.getPassword(credentials.xmppService, credentials.login)
|
|
|
|
}
|
|
|
|
|
|
|
|
return credentials;
|
2021-12-01 10:54:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 03:01:40 +00:00
|
|
|
async function removeCredentials(login) {
|
|
|
|
const xmppService = login.split('@').pop();
|
|
|
|
await api.keytar.deletePassword(xmppService, login);
|
|
|
|
await api.settings.unset('login');
|
|
|
|
await api.settings.unset('connectionManager');
|
2021-12-01 10:54:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 03:01:40 +00:00
|
|
|
export {
|
2021-12-01 10:54:41 +00:00
|
|
|
addCredentials,
|
|
|
|
getCredentials,
|
|
|
|
removeCredentials
|
|
|
|
}
|