aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/server/ServerApi.js56
-rw-r--r--src/stores/AppStore.js2
-rw-r--r--src/stores/RecipesStore.js4
3 files changed, 46 insertions, 16 deletions
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js
index 86f4c99e7..8b0b7563c 100644
--- a/src/api/server/ServerApi.js
+++ b/src/api/server/ServerApi.js
@@ -1,6 +1,6 @@
1import os from 'os'; 1import os from 'os';
2import path from 'path'; 2import path from 'path';
3import targz from 'tar.gz'; 3import tar from 'tar';
4import fs from 'fs-extra'; 4import fs from 'fs-extra';
5import { remote } from 'electron'; 5import { remote } from 'electron';
6 6
@@ -293,7 +293,11 @@ export default class ServerApi {
293 const buffer = await res.buffer(); 293 const buffer = await res.buffer();
294 fs.writeFileSync(archivePath, buffer); 294 fs.writeFileSync(archivePath, buffer);
295 295
296 await targz().extract(archivePath, recipeTempDirectory); 296 tar.x({
297 file: archivePath,
298 cwd: recipeTempDirectory,
299 sync: true,
300 });
297 301
298 const { id } = fs.readJsonSync(path.join(recipeTempDirectory, 'package.json')); 302 const { id } = fs.readJsonSync(path.join(recipeTempDirectory, 'package.json'));
299 const recipeDirectory = path.join(recipesDirectory, id); 303 const recipeDirectory = path.join(recipesDirectory, id);
@@ -443,6 +447,10 @@ export default class ServerApi {
443 447
444 // Helper 448 // Helper
445 async _mapServiceModels(services) { 449 async _mapServiceModels(services) {
450 const recipes = services.map(s => s.recipeId);
451
452 await this._bulkRecipeCheck(recipes);
453
446 return Promise.all(services 454 return Promise.all(services
447 .map(async service => await this._prepareServiceModel(service)) // eslint-disable-line 455 .map(async service => await this._prepareServiceModel(service)) // eslint-disable-line
448 ); 456 );
@@ -454,19 +462,8 @@ export default class ServerApi {
454 recipe = this.recipes.find(r => r.id === service.recipeId); 462 recipe = this.recipes.find(r => r.id === service.recipeId);
455 463
456 if (!recipe) { 464 if (!recipe) {
457 console.warn(`Recipe '${service.recipeId}' not installed, trying to fetch from server`); 465 console.warn(`Recipe ${service.recipeId} not loaded`);
458 466 return null;
459 await this.getRecipePackage(service.recipeId);
460
461 console.debug('Rerun ServerAPI::getInstalledRecipes');
462 await this.getInstalledRecipes();
463
464 recipe = this.recipes.find(r => r.id === service.recipeId);
465
466 if (!recipe) {
467 console.warn(`Could not load recipe ${service.recipeId}`);
468 return null;
469 }
470 } 467 }
471 468
472 return new ServiceModel(service, recipe); 469 return new ServiceModel(service, recipe);
@@ -476,6 +473,35 @@ export default class ServerApi {
476 } 473 }
477 } 474 }
478 475
476 async _bulkRecipeCheck(unfilteredRecipes) {
477 // Filter recipe duplicates as we don't need to download 3 Slack recipes
478 const recipes = unfilteredRecipes.filter((elem, pos, arr) => arr.indexOf(elem) === pos);
479
480 return Promise.all(recipes
481 .map(async (recipeId) => {
482 let recipe = this.recipes.find(r => r.id === recipeId);
483
484 if (!recipe) {
485 console.warn(`Recipe '${recipeId}' not installed, trying to fetch from server`);
486
487 await this.getRecipePackage(recipeId);
488
489 console.debug('Rerun ServerAPI::getInstalledRecipes');
490 await this.getInstalledRecipes();
491
492 recipe = this.recipes.find(r => r.id === recipeId);
493
494 if (!recipe) {
495 console.warn(`Could not load recipe ${recipeId}`);
496 return null;
497 }
498 }
499
500 return recipe;
501 }),
502 ).catch(err => console.error(err));
503 }
504
479 _mapRecipePreviewModel(recipes) { 505 _mapRecipePreviewModel(recipes) {
480 return recipes.map((recipe) => { 506 return recipes.map((recipe) => {
481 try { 507 try {
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 8435c9ab8..7dbef985d 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -80,7 +80,7 @@ export default class AppStore extends Store {
80 // Check for updates once every 4 hours 80 // Check for updates once every 4 hours
81 setInterval(() => this._checkForUpdates(), CHECK_INTERVAL); 81 setInterval(() => this._checkForUpdates(), CHECK_INTERVAL);
82 // Check for an update in 30s (need a delay to prevent Squirrel Installer lock file issues) 82 // Check for an update in 30s (need a delay to prevent Squirrel Installer lock file issues)
83 setTimeout(() => this._checkForUpdates(), 3000); 83 setTimeout(() => this._checkForUpdates(), 30000);
84 ipcRenderer.on('autoUpdate', (event, data) => { 84 ipcRenderer.on('autoUpdate', (event, data) => {
85 if (data.available) { 85 if (data.available) {
86 this.updateStatus = this.updateStatusTypes.AVAILABLE; 86 this.updateStatus = this.updateStatusTypes.AVAILABLE;
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js
index cdc274685..67fee1d50 100644
--- a/src/stores/RecipesStore.js
+++ b/src/stores/RecipesStore.js
@@ -65,6 +65,10 @@ export default class RecipesStore extends Store {
65 @action async _update() { 65 @action async _update() {
66 const recipeIds = this.recipeIdForServices; 66 const recipeIds = this.recipeIdForServices;
67 const recipes = {}; 67 const recipes = {};
68
69 // Hackfix, reference this.all to fetch services
70 console.debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`);
71
68 recipeIds.forEach((r) => { 72 recipeIds.forEach((r) => {
69 const recipe = this.one(r); 73 const recipe = this.one(r);
70 recipes[r] = recipe.version; 74 recipes[r] = recipe.version;