diff --git a/.gitignore b/.gitignore index dd5ea8f4..e0685013 100644 --- a/.gitignore +++ b/.gitignore @@ -85,5 +85,5 @@ client_secret.json src/originalBudgetTrackingApp/mockData src/originalBudgetTrackingApp/categoryCalculationScript.js -config.json +config.encrypted googleApiToken.json diff --git a/package.json b/package.json index d44cd45f..bc57e2ee 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/originalBudgetTrackingApp/config-manager/configManager.js b/src/originalBudgetTrackingApp/config-manager/configManager.js index ee9d6a18..f32e55ef 100644 --- a/src/originalBudgetTrackingApp/config-manager/configManager.js +++ b/src/originalBudgetTrackingApp/config-manager/configManager.js @@ -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() { @@ -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); -} diff --git a/src/store/index.js b/src/store/index.js index c343c914..5df0d2a5 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -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', }); diff --git a/src/store/modules/config.js b/src/store/modules/config.js new file mode 100644 index 00000000..59c836d8 --- /dev/null +++ b/src/store/modules/config.js @@ -0,0 +1,13 @@ +const state = { + scraping: { + numDaysBack: 40, + showBrowser: false, + accountsToScrape: [] + }, + outputVendors: {}, + monitoring: {} +}; + +export default { + state +}; diff --git a/src/store/plugins/persisted-config.js b/src/store/plugins/persisted-config.js new file mode 100644 index 00000000..d54da3fc --- /dev/null +++ b/src/store/plugins/persisted-config.js @@ -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), +}); diff --git a/yarn.lock b/yarn.lock index 55216206..1806142f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"