diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-14 19:58:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 19:58:52 +0200 |
commit | 95df3522a15631abc51a4295cae0ea401a8d4e1e (patch) | |
tree | e5eb0f368c947683f01458e912f21756fb0d99cb /src/stores/RecipesStore.js | |
parent | docs: add sad270 as a contributor for bug, userTesting [skip ci] (#1941) (diff) | |
download | ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.gz ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.zst ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.zip |
feat: add eslint-plugin-unicorn (#1936)
Diffstat (limited to 'src/stores/RecipesStore.js')
-rw-r--r-- | src/stores/RecipesStore.js | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index d2acebb75..bfbdc57a8 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js | |||
@@ -25,9 +25,7 @@ export default class RecipesStore extends Store { | |||
25 | this.actions.recipe.update.listen(this._update.bind(this)); | 25 | this.actions.recipe.update.listen(this._update.bind(this)); |
26 | 26 | ||
27 | // Reactions | 27 | // Reactions |
28 | this.registerReactions([ | 28 | this.registerReactions([this._checkIfRecipeIsInstalled.bind(this)]); |
29 | this._checkIfRecipeIsInstalled.bind(this), | ||
30 | ]); | ||
31 | } | 29 | } |
32 | 30 | ||
33 | setup() { | 31 | setup() { |
@@ -39,7 +37,10 @@ export default class RecipesStore extends Store { | |||
39 | } | 37 | } |
40 | 38 | ||
41 | @computed get active() { | 39 | @computed get active() { |
42 | const match = matchRoute('/settings/services/add/:id', this.stores.router.location.pathname); | 40 | const match = matchRoute( |
41 | '/settings/services/add/:id', | ||
42 | this.stores.router.location.pathname, | ||
43 | ); | ||
43 | if (match) { | 44 | if (match) { |
44 | const activeRecipe = this.one(match.id); | 45 | const activeRecipe = this.one(match.id); |
45 | if (activeRecipe) { | 46 | if (activeRecipe) { |
@@ -53,11 +54,11 @@ export default class RecipesStore extends Store { | |||
53 | } | 54 | } |
54 | 55 | ||
55 | @computed get recipeIdForServices() { | 56 | @computed get recipeIdForServices() { |
56 | return this.stores.services.all.map((s) => s.recipe.id); | 57 | return this.stores.services.all.map(s => s.recipe.id); |
57 | } | 58 | } |
58 | 59 | ||
59 | one(id) { | 60 | one(id) { |
60 | return this.all.find((recipe) => recipe.id === id); | 61 | return this.all.find(recipe => recipe.id === id); |
61 | } | 62 | } |
62 | 63 | ||
63 | isInstalled(id) { | 64 | isInstalled(id) { |
@@ -77,41 +78,43 @@ export default class RecipesStore extends Store { | |||
77 | const recipes = {}; | 78 | const recipes = {}; |
78 | 79 | ||
79 | // Hackfix, reference this.all to fetch services | 80 | // Hackfix, reference this.all to fetch services |
80 | debug(`Check Recipe updates for ${this.all.map((recipe) => recipe.id)}`); | 81 | debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); |
81 | 82 | ||
82 | recipeIds.forEach((r) => { | 83 | for (const r of recipeIds) { |
83 | const recipe = this.one(r); | 84 | const recipe = this.one(r); |
84 | recipes[r] = recipe.version; | 85 | recipes[r] = recipe.version; |
85 | }); | 86 | } |
86 | 87 | ||
87 | if (Object.keys(recipes).length === 0) return; | 88 | if (Object.keys(recipes).length === 0) return; |
88 | 89 | ||
89 | const remoteUpdates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; | 90 | const remoteUpdates = await this.getRecipeUpdatesRequest.execute(recipes) |
91 | ._promise; | ||
90 | 92 | ||
91 | // Check for local updates | 93 | // Check for local updates |
92 | const allJsonFile = asarRecipesPath('all.json'); | 94 | const allJsonFile = asarRecipesPath('all.json'); |
93 | const allJson = readJSONSync(allJsonFile); | 95 | const allJson = readJSONSync(allJsonFile); |
94 | const localUpdates = []; | 96 | const localUpdates = []; |
95 | 97 | ||
96 | Object.keys(recipes).forEach((recipe) => { | 98 | for (const recipe of Object.keys(recipes)) { |
97 | const version = recipes[recipe]; | 99 | const version = recipes[recipe]; |
98 | 100 | ||
99 | // Find recipe in local recipe repository | 101 | // Find recipe in local recipe repository |
100 | const localRecipe = allJson.find((r) => r.id === recipe); | 102 | const localRecipe = allJson.find(r => r.id === recipe); |
101 | 103 | ||
102 | if (localRecipe && semver.lt(version, localRecipe.version)) { | 104 | if (localRecipe && semver.lt(version, localRecipe.version)) { |
103 | localUpdates.push(recipe); | 105 | localUpdates.push(recipe); |
104 | } | 106 | } |
105 | }); | 107 | } |
106 | 108 | ||
107 | const updates = [ | 109 | const updates = [...remoteUpdates, ...localUpdates]; |
108 | ...remoteUpdates, | 110 | debug( |
109 | ...localUpdates, | 111 | 'Got update information (local, remote):', |
110 | ]; | 112 | localUpdates, |
111 | debug('Got update information (local, remote):', localUpdates, remoteUpdates); | 113 | remoteUpdates, |
114 | ); | ||
112 | 115 | ||
113 | const length = updates.length - 1; | 116 | const length = updates.length - 1; |
114 | const syncUpdate = async (i) => { | 117 | const syncUpdate = async i => { |
115 | const update = updates[i]; | 118 | const update = updates[i]; |
116 | 119 | ||
117 | this.actions.recipe.install({ recipeId: update }); | 120 | this.actions.recipe.install({ recipeId: update }); |
@@ -134,7 +137,9 @@ export default class RecipesStore extends Store { | |||
134 | async _checkIfRecipeIsInstalled() { | 137 | async _checkIfRecipeIsInstalled() { |
135 | const { router } = this.stores; | 138 | const { router } = this.stores; |
136 | 139 | ||
137 | const match = router.location && matchRoute('/settings/services/add/:id', router.location.pathname); | 140 | const match = |
141 | router.location && | ||
142 | matchRoute('/settings/services/add/:id', router.location.pathname); | ||
138 | if (match) { | 143 | if (match) { |
139 | const recipeId = match.id; | 144 | const recipeId = match.id; |
140 | 145 | ||
@@ -142,9 +147,11 @@ export default class RecipesStore extends Store { | |||
142 | router.push('/settings/recipes'); | 147 | router.push('/settings/recipes'); |
143 | debug(`Recipe ${recipeId} is not installed, trying to install it`); | 148 | debug(`Recipe ${recipeId} is not installed, trying to install it`); |
144 | 149 | ||
145 | const recipe = await this.installRecipeRequest.execute(recipeId)._promise; | 150 | const recipe = await this.installRecipeRequest.execute(recipeId) |
151 | ._promise; | ||
146 | if (recipe) { | 152 | if (recipe) { |
147 | await this.allRecipesRequest.invalidate({ immediately: true })._promise; | 153 | await this.allRecipesRequest.invalidate({ immediately: true }) |
154 | ._promise; | ||
148 | router.push(`/settings/services/add/${recipeId}`); | 155 | router.push(`/settings/services/add/${recipeId}`); |
149 | } else { | 156 | } else { |
150 | router.push('/settings/recipes'); | 157 | router.push('/settings/recipes'); |