Skip to content

Commit

Permalink
🐛 Kreedzt - fixed build version set proxy error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreedzt committed May 18, 2020
1 parent 150310c commit 39ac8e0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 34 deletions.
38 changes: 32 additions & 6 deletions src/proxyConfig.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const {
app,
protocol,
BrowserWindow,
Menu,
MenuItem,
dialog,
shell,
clipboard
ipcMain
} = require('electron');
const log = require('electron-log');
const { getCorrectPath } = require('./utils/env');
const { getProxy, setProxy } = require('./utils/proxy');

const logger = log.scope('proxyConfig.js');

let proxyWindow = null;

Expand Down Expand Up @@ -37,6 +36,33 @@ const initializeWindow = () => {
}
}

ipcMain.on('getProxy', async (event, callback) => {
logger.info('ipcMain getProxy listener', event, callback);

try {
const proxy = await getProxy();
logger.info('ipcMain getProxy res', proxy);

event.reply('getProxy-success', proxy);
} catch(e) {
logger.error('ipcMain getProxy error', e);
event.reply('getProxy-error', e);
}
});

ipcMain.on('setProxy', async (event, url) => {
logger.info('ipcMain setProxy listener', event, url);

try {
await setProxy(url);
logger.info('ipcMain setProxy success', url);
event.reply('setProxy-success');
} catch(e) {
logger.error('ipcMain setProxy error', e);
event.reply('setProxy-error', e);
}
})

module.exports = {
initializeWindow
};
55 changes: 30 additions & 25 deletions src/proxyWebConfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,36 @@
Save
</button>
<script>
const log = require('electron-log');
const { getProxy, setProxy } = require('./utils/proxy');

const logger = log.scope('proxyWebConfig.html');
window.onload = () => {
const inputEl = document.getElementById('proxy_input');
const buttonEl = document.getElementById('save_btn');

getProxy().then(res => {
logger.info('getProxy res', res);
inputEl.value = res;
})

buttonEl.addEventListener('click', () => {
console.log('inputEl val', inputEl.value);
logger.info('inputEl val', inputEl.value);

setProxy(inputEl.value).then(() => {
window.alert('Save proxy success');
}).catch(e => {
logger.error(e);
console.error(e);
})
});
};
const { ipcRenderer } = require('electron');

window.onload = () => {
const inputEl = document.getElementById('proxy_input');
const buttonEl = document.getElementById('save_btn');

ipcRenderer.send('getProxy');

ipcRenderer.on('getProxy-success', (ev, url) => {
inputEl.value = url;
});

ipcRenderer.on('getProxy-error', (ev, err) => {
window.alert('getProxy error', err);
});

buttonEl.addEventListener('click', () => {
console.log('inputEl val', inputEl.value);

ipcRenderer.send('setProxy', inputEl.value);
});

ipcRenderer.on('setProxy-success', () => {
window.alert('Save proxy success');
});

ipcRenderer.on('setProxy-error', (ev, e) => {
window.alert('Save proxy error', e);
});
};
</script>
</body>
</html>
20 changes: 17 additions & 3 deletions src/utils/proxy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
const log = require('electron-log');
const { promisedReadFile, promisedWriteFile } = require('./promisedFs');
const { getCorrectPath } = require('./env');

const logger = log.scope('proxy.js');

const proxyFilePath = getCorrectPath('config/proxy');

const setProxy = async proxyUrl => promisedWriteFile(proxyFilePath, proxyUrl);
const setProxy = async proxyUrl => {
logger.info('setProxy fn');
logger.info('proxyFilePath', proxyFilePath);
logger.info('proxyUrl', proxyUrl);

return promisedWriteFile(proxyFilePath, proxyUrl);
};

const getProxy = async () => promisedReadFile(proxyFilePath);
const getProxy = async () => {
logger.info('getProxy fn');
logger.info('proxyFilePath', proxyFilePath);

return promisedReadFile(proxyFilePath);
};

module.exports = {
setProxy,
getProxy
getProxy,
};

0 comments on commit 39ac8e0

Please sign in to comment.