Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1475 from imolorhe/add-proxy-settings
Added new settings for proxy configuration.
- Loading branch information
Showing
22 changed files
with
2,990 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const settingsStoreFileName = 'desktop_settings'; | ||
|
||
const SETTINGS_STORE_EVENTS = { | ||
GET_SETTINGS_DATA: 'GET_SETTINGS_DATA', | ||
UPDATE_SETTINGS_DATA: 'UPDATE_SETTINGS_DATA', | ||
}; | ||
|
||
module.exports = { | ||
settingsStoreFileName, | ||
SETTINGS_STORE_EVENTS, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { ipcMain } = require('electron'); | ||
const settingsStore = require('./store'); | ||
const { SETTINGS_STORE_EVENTS } = require('../constants'); | ||
const initSettingsStoreEvents = () => { | ||
|
||
ipcMain.on(SETTINGS_STORE_EVENTS.GET_SETTINGS_DATA, (e) => { | ||
e.returnValue = settingsStore.get('settings'); | ||
}); | ||
|
||
ipcMain.on(SETTINGS_STORE_EVENTS.UPDATE_SETTINGS_DATA, (e, value) => { | ||
e.returnValue = settingsStore.set('settings', value); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
initSettingsStoreEvents, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const ElectronStore = require('electron-store'); | ||
const { settingsStoreFileName } = require('../constants'); | ||
|
||
const store = new ElectronStore({ | ||
name: settingsStoreFileName, | ||
}); | ||
|
||
module.exports = store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const ipc = require('electron').ipcRenderer; | ||
const { SETTINGS_STORE_EVENTS } = require('../constants'); | ||
|
||
/** | ||
* event delegation | ||
* @param {string} selector | ||
* @param {string} eventName | ||
* @param {(e: Event) => void} handler | ||
*/ | ||
const on = (selector, eventName, handler) => { | ||
document.addEventListener(eventName, function(e) { | ||
// loop parent nodes from the target to the delegation node | ||
for (let target = e.target; target && target !== this; target = target.parentNode) { | ||
if (target.matches(selector)) { | ||
Reflect.apply(handler, target, [ e ]); | ||
break; | ||
} | ||
} | ||
}, false); | ||
}; | ||
|
||
const serializeForm = (form) => { | ||
let obj = {}; | ||
const data = new FormData(form); | ||
for (let [key, value] of data) { | ||
if (typeof obj[key] === 'undefined') { | ||
obj[key] = value; | ||
} else { | ||
if (!Array.isArray(obj[key])) { | ||
obj[key] = [obj[key]]; | ||
} | ||
obj[key].push(value); | ||
} | ||
} | ||
return obj; | ||
}; | ||
|
||
const hideAllNested = () => { | ||
document.querySelectorAll('.nested').forEach(el => { | ||
el.classList.add('hidden'); | ||
}); | ||
document.querySelectorAll('input.js-input[type="radio"]:checked').forEach((radioEl) => { | ||
const radioContainer = radioEl.closest('.radio'); | ||
const nested = radioContainer.querySelector('.nested'); | ||
if (nested) { | ||
nested.classList.remove('hidden'); | ||
} | ||
}); | ||
}; | ||
|
||
// Initialize when loaded | ||
document.addEventListener('DOMContentLoaded', function () { | ||
// load settings | ||
const initialData = ipc.sendSync(SETTINGS_STORE_EVENTS.GET_SETTINGS_DATA); | ||
// set selected settings | ||
const networkForm = document.querySelector('.js-network-form'); | ||
Object.keys(initialData).forEach((key) => { | ||
networkForm[key].value = initialData[key]; | ||
}); | ||
// hide nested | ||
hideAllNested(); | ||
|
||
on('input.js-input[type="radio"]', 'click', () => { | ||
hideAllNested(); | ||
}); | ||
|
||
on('.js-network-form', 'submit', (e) => { | ||
e.preventDefault(); | ||
const formData = serializeForm(e.target); | ||
|
||
console.log('submitted.', formData); | ||
ipc.sendSync(SETTINGS_STORE_EVENTS.UPDATE_SETTINGS_DATA, formData); | ||
ipc.sendSync('restart-app'); | ||
}); | ||
}); | ||
|
Oops, something went wrong.