Skip to content

Commit

Permalink
Merge pull request graasp#178 from fboechats/refactor/set_language
Browse files Browse the repository at this point in the history
refactor: factor out setLanguage listener
  • Loading branch information
juancarlosfarah authored Aug 27, 2019
2 parents ac4e65a + cc98626 commit 14e2222
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions public/app/listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const showLoadSpacePrompt = require('./showLoadSpacePrompt');
const showExportSpacePrompt = require('./showExportSpacePrompt');
const showDeleteSpacePrompt = require('./showDeleteSpacePrompt');
const getUserFolder = require('./getUserFolder');
const setLanguage = require('./setLanguage');
const getLanguage = require('./getLanguage');

module.exports = {
Expand All @@ -29,5 +30,6 @@ module.exports = {
showExportSpacePrompt,
showDeleteSpacePrompt,
getUserFolder,
setLanguage,
getLanguage,
};
15 changes: 15 additions & 0 deletions public/app/listeners/setLanguage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { SET_LANGUAGE_CHANNEL } = require('../config/channels');
const logger = require('../logger');
const { ERROR_GENERAL } = require('../config/errors');

const setLanguage = (mainWindow, db) => async (event, lang) => {
try {
db.set('user.lang', lang).write();
mainWindow.webContents.send(SET_LANGUAGE_CHANNEL, lang);
} catch (e) {
logger.error(e);
mainWindow.webContents.send(SET_LANGUAGE_CHANNEL, ERROR_GENERAL);
}
};

module.exports = setLanguage;
11 changes: 2 additions & 9 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const {
getGeolocationEnabled,
setGeolocationEnabled,
getUserFolder,
setLanguage,
getLanguage,
} = require('./app/listeners');
const isMac = require('./app/utils/isMac');
Expand Down Expand Up @@ -328,15 +329,7 @@ app.on('ready', async () => {
ipcMain.on(GET_LANGUAGE_CHANNEL, getLanguage(mainWindow, db));

// called when setting language
ipcMain.on(SET_LANGUAGE_CHANNEL, (event, lang) => {
try {
db.set('user.lang', lang).write();
mainWindow.webContents.send(SET_LANGUAGE_CHANNEL, lang);
} catch (e) {
logger.error(e);
mainWindow.webContents.send(SET_LANGUAGE_CHANNEL, ERROR_GENERAL);
}
});
ipcMain.on(SET_LANGUAGE_CHANNEL, setLanguage(mainWindow));

// called when getting developer mode
ipcMain.on(GET_DEVELOPER_MODE_CHANNEL, () => {
Expand Down

0 comments on commit 14e2222

Please sign in to comment.