Skip to content

Commit

Permalink
Rewritten settings saving. Now saves on 'close' window event.
Browse files Browse the repository at this point in the history
  • Loading branch information
assnctr committed Jan 18, 2019
1 parent ef4f623 commit be336fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/actions/ResultActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getFilteredProxies } from '../store/selectors/getFilteredProxies';
import { writeFile } from 'fs';
import { sort } from 'js-flock';
import { remote } from 'electron';
import { saveSettings } from '../core/settings';
import {
SHOW_RESULT,
TOGGLE_ANON,
Expand Down Expand Up @@ -61,9 +60,8 @@ export const getResultsInProtocolIpPort = items => {
};

export const save = () => (dispatch, getState) => {
const { core, judges, blacklist, ip, result } = getState();
const saveType = result.exporting.type == 1 ? getResultsInIpPort : getResultsInProtocolIpPort;

const saveType = getState().exporting.type == 1 ? getResultsInIpPort : getResultsInProtocolIpPort;

let savePath = dialog.showSaveDialog({
filters: [
{
Expand All @@ -76,17 +74,6 @@ export const save = () => (dispatch, getState) => {
if (savePath) {
writeFile(savePath, saveType(getFilteredProxies(getState())), () => {
dispatch(toggleExport());
saveSettings({
core,
judges,
ip: {
lookupUrl: ip.lookupUrl
},
blacklist,
exporting: {
type: result.exporting.type
}
});
});
}
};
Expand Down
18 changes: 18 additions & 0 deletions src/core/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import store from '../store';
import { remote } from 'electron';
import { writeFile, readFileSync, existsSync } from 'fs';
import { SETTINGS_FILE_PATH, MERGED_DEFAULT_SETTINGS } from '../constants/SettingsConstants';

Expand All @@ -21,3 +23,19 @@ const getSettings = () => {
};

export const initial = getSettings();

remote.getCurrentWindow().on('close', () => {
const { core, judges, ip, blacklist, result } = store.getState();

saveSettings({
core,
judges,
ip: {
lookupUrl: ip.lookupUrl
},
blacklist,
exporting: {
type: result.exporting.type
}
});
});

0 comments on commit be336fd

Please sign in to comment.