aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2020-01-31 13:40:00 +0100
committerLibravatar vantezzen <hello@vantezzen.io>2020-01-31 13:40:00 +0100
commit0a89e919b3caf4d4935d135d687ad5b31bdc4441 (patch)
treeaed2ede067e7294c7e945f334d5d4e8e77907b03 /src
parent#285 Fix DarkReader for FastMail (diff)
downloadferdium-app-0a89e919b3caf4d4935d135d687ad5b31bdc4441.tar.gz
ferdium-app-0a89e919b3caf4d4935d135d687ad5b31bdc4441.tar.zst
ferdium-app-0a89e919b3caf4d4935d135d687ad5b31bdc4441.zip
#328 Implement local updates
Diffstat (limited to 'src')
-rw-r--r--src/stores/RecipesStore.js29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js
index 8b2bde5df..fc7a07dd8 100644
--- a/src/stores/RecipesStore.js
+++ b/src/stores/RecipesStore.js
@@ -1,9 +1,13 @@
1import { action, computed, observable } from 'mobx'; 1import { action, computed, observable } from 'mobx';
2import fs from 'fs-extra';
3import path from 'path';
4import semver from 'semver';
2 5
3import Store from './lib/Store'; 6import Store from './lib/Store';
4import CachedRequest from './lib/CachedRequest'; 7import CachedRequest from './lib/CachedRequest';
5import Request from './lib/Request'; 8import Request from './lib/Request';
6import { matchRoute } from '../helpers/routing-helpers'; 9import { matchRoute } from '../helpers/routing-helpers';
10import { RECIPES_PATH } from '../config';
7 11
8const debug = require('debug')('Ferdi:RecipeStore'); 12const debug = require('debug')('Ferdi:RecipeStore');
9 13
@@ -83,7 +87,30 @@ export default class RecipesStore extends Store {
83 87
84 if (Object.keys(recipes).length === 0) return; 88 if (Object.keys(recipes).length === 0) return;
85 89
86 const updates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; 90 const remoteUpdates = await this.getRecipeUpdatesRequest.execute(recipes)._promise;
91
92 // Check for local updates
93 const allJsonFile = path.join(RECIPES_PATH, 'all.json');
94 const allJson = await fs.readJSON(allJsonFile);
95 const localUpdates = [];
96
97 Object.keys(recipes).forEach((recipe) => {
98 const version = recipes[recipe];
99
100 // Find recipe in local recipe repository
101 const localRecipe = allJson.find((r) => r.id === recipe);
102
103 if (localRecipe && semver.lt(version, localRecipe.version)) {
104 localUpdates.push(recipe);
105 }
106 });
107
108 const updates = [
109 ...remoteUpdates,
110 ...localUpdates,
111 ];
112 debug('Got update information (local, remote):', localUpdates, remoteUpdates);
113
87 const length = updates.length - 1; 114 const length = updates.length - 1;
88 const syncUpdate = async (i) => { 115 const syncUpdate = async (i) => {
89 const update = updates[i]; 116 const update = updates[i];