Skip to content

Commit

Permalink
Use configManager as pesisted storage
Browse files Browse the repository at this point in the history
  • Loading branch information
baruchiro authored and brafdlog committed Jun 12, 2020
1 parent 0afdfe2 commit 1181e2f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ client_secret.json

src/originalBudgetTrackingApp/mockData
src/originalBudgetTrackingApp/categoryCalculationScript.js
config.json
config.encrypted
googleApiToken.json
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"vuetify": "^2.2.22",
"vuex": "^3.1.3",
"vuex-electron": "^1.0.3",
"vuex-persistedstate": "^3.0.1",
"ynab": "^1.19.0"
},
"devDependencies": {
Expand Down
9 changes: 2 additions & 7 deletions src/originalBudgetTrackingApp/config-manager/configManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import configExample from './config-example';
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);

const CONFIG_FILE_NAME = 'config.json';
const CONFIG_FILE_NAME = 'config.encrypted';
const LOCAL_CONFIG_FILE_PATH = CONFIG_FILE_NAME;

export async function getConfig() {
Expand Down Expand Up @@ -35,11 +35,6 @@ async function getConfigFromFile(configFilePath) {

export async function updateConfig(configToUpdate) {
const stringifiedConfig = JSON.stringify(configToUpdate, null, 2);
const encryptedConfigStr = encryptConfig(stringifiedConfig);
const encryptedConfigStr = await encrypt(stringifiedConfig);
await writeFile(LOCAL_CONFIG_FILE_PATH, encryptedConfigStr);
}

function encryptConfig(stringifiedConfig) {
const encryptedConfig = encrypt(stringifiedConfig);
return JSON.stringify(encryptedConfig);
}
11 changes: 2 additions & 9 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import Vue from 'vue';
import Vuex from 'vuex';

import { createPersistedState, createSharedMutations } from 'vuex-electron';
import configManagerPlugin from './plugins/persisted-config';

import modules from './modules';

import migrations from './migrations';

Vue.use(Vuex);

const store = new Vuex.Store({
modules,
plugins: [
// Win location: AppData\Roaming\Electron\vuex.json
// linux location: ~/.config/israeli-bank-scrapers-desktop/vuex.json
createPersistedState(),
createSharedMutations(),
],
plugins: [configManagerPlugin('config')],
strict: process.env.NODE_ENV !== 'production',
});

Expand Down
13 changes: 13 additions & 0 deletions src/store/modules/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const state = {
scraping: {
numDaysBack: 40,
showBrowser: false,
accountsToScrape: []
},
outputVendors: {},
monitoring: {}
};

export default {
state
};
18 changes: 18 additions & 0 deletions src/store/plugins/persisted-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import createPersistedState from 'vuex-persistedstate';
import { configManager } from '@/originalBudgetTrackingApp';

const createConfigManagerStorage = (keyName) => ({
getItem: async (key) => {
return key === keyName ? configManager.getConfig() : Promise.resolve();
},
setItem: async (key, value) => {
if (key === keyName) await configManager.updateConfig(value);
},
removeItem: (key) => console.log(key),
});

export default (keyName) => createPersistedState({
key: keyName,
paths: [keyName],
storage: createConfigManagerStorage(keyName),
});
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12261,6 +12261,11 @@ shellwords@^0.1.1:
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==

shvl@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/shvl/-/shvl-2.0.0.tgz#55fd550b6e81bf7574f2f576b8b5c1ffae74e10f"
integrity sha512-WbpzSvI5XgVGJ3A4ySGe8hBxj0JgJktfnoLhhJmvITDdK21WPVWwgG8GPlYEh4xqdti3Ff7PJ5G0QrRAjNS0Ig==

sigmund@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
Expand Down Expand Up @@ -14203,6 +14208,14 @@ vuex-electron@^1.0.3:
deepmerge "^2.1.1"
electron-store "^2.0.0"

vuex-persistedstate@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/vuex-persistedstate/-/vuex-persistedstate-3.0.1.tgz#6eacc3c416fe8cfe63c40d3ee7b8ed13aac4f04f"
integrity sha512-2dH77+fIecAXO8GeJEXiYnC++gx48PFGUayB5d7rWrN3fblRCOHQoVnmu/VV9DXbHHJcJth/0W/ofl8vw12j1A==
dependencies:
deepmerge "^4.2.2"
shvl "^2.0.0"

vuex@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.1.3.tgz#f2ad73e3fb73691698b38c93f66e58e267947180"
Expand Down

0 comments on commit 1181e2f

Please sign in to comment.