aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-03-18 21:06:30 +0100
committerLibravatar GitHub <noreply@github.com>2018-03-18 21:06:30 +0100
commitadc67db3a46b5d5de411c4b73f92464fbe64a03c (patch)
tree85e10e35f8867e3e747c92e0eddc0a75bdb94516 /src
parentMerge pull request #798 from meetfranz/fix/order-performance (diff)
parentAdd debug flags to render process (diff)
downloadferdium-app-adc67db3a46b5d5de411c4b73f92464fbe64a03c.tar.gz
ferdium-app-adc67db3a46b5d5de411c4b73f92464fbe64a03c.tar.zst
ferdium-app-adc67db3a46b5d5de411c4b73f92464fbe64a03c.zip
Merge pull request #805 from meetfranz/chore/add-debugger
Replace console logs with debugger
Diffstat (limited to 'src')
-rw-r--r--src/api/server/LocalApi.js8
-rw-r--r--src/api/server/ServerApi.js60
-rw-r--r--src/index.html11
-rw-r--r--src/lib/analytics.js6
-rw-r--r--src/stores/RecipesStore.js8
-rw-r--r--src/stores/RequestStore.js4
-rw-r--r--src/stores/ServicesStore.js10
7 files changed, 61 insertions, 46 deletions
diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js
index aa3a7d655..4d2497c61 100644
--- a/src/api/server/LocalApi.js
+++ b/src/api/server/LocalApi.js
@@ -3,6 +3,8 @@ import du from 'du';
3 3
4import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js'; 4import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js';
5 5
6const debug = require('debug')('LocalApi');
7
6const { session } = remote; 8const { session } = remote;
7 9
8export default class LocalApi { 10export default class LocalApi {
@@ -13,7 +15,7 @@ export default class LocalApi {
13 du(partitionsDir, (err, size) => { 15 du(partitionsDir, (err, size) => {
14 if (err) reject(err); 16 if (err) reject(err);
15 17
16 console.debug('LocalApi::getAppCacheSize resolves', size); 18 debug('LocalApi::getAppCacheSize resolves', size);
17 resolve(size); 19 resolve(size);
18 }); 20 });
19 }); 21 });
@@ -22,14 +24,14 @@ export default class LocalApi {
22 async clearCache(serviceId) { 24 async clearCache(serviceId) {
23 const s = session.fromPartition(`persist:service-${serviceId}`); 25 const s = session.fromPartition(`persist:service-${serviceId}`);
24 26
25 console.debug('LocalApi::clearCache resolves', serviceId); 27 debug('LocalApi::clearCache resolves', serviceId);
26 return new Promise(resolve => s.clearCache(resolve)); 28 return new Promise(resolve => s.clearCache(resolve));
27 } 29 }
28 30
29 async clearAppCache() { 31 async clearAppCache() {
30 const s = session.defaultSession; 32 const s = session.defaultSession;
31 33
32 console.debug('LocalApi::clearCache clearAppCache'); 34 debug('LocalApi::clearCache clearAppCache');
33 return new Promise(resolve => s.clearCache(resolve)); 35 return new Promise(resolve => s.clearCache(resolve));
34 } 36 }
35} 37}
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js
index 8f3297d13..353faa7f4 100644
--- a/src/api/server/ServerApi.js
+++ b/src/api/server/ServerApi.js
@@ -27,6 +27,8 @@ import {
27 removeServicePartitionDirectory, 27 removeServicePartitionDirectory,
28} from '../../helpers/service-helpers.js'; 28} from '../../helpers/service-helpers.js';
29 29
30const debug = require('debug')('ServerApi');
31
30module.paths.unshift( 32module.paths.unshift(
31 getDevRecipeDirectory(), 33 getDevRecipeDirectory(),
32 getRecipeDirectory(), 34 getRecipeDirectory(),
@@ -55,7 +57,7 @@ export default class ServerApi {
55 } 57 }
56 const u = await request.json(); 58 const u = await request.json();
57 59
58 console.debug('ServerApi::login resolves', u); 60 debug('ServerApi::login resolves', u);
59 return u.token; 61 return u.token;
60 } 62 }
61 63
@@ -69,7 +71,7 @@ export default class ServerApi {
69 } 71 }
70 const u = await request.json(); 72 const u = await request.json();
71 73
72 console.debug('ServerApi::signup resolves', u); 74 debug('ServerApi::signup resolves', u);
73 return u.token; 75 return u.token;
74 } 76 }
75 77
@@ -82,7 +84,7 @@ export default class ServerApi {
82 throw request; 84 throw request;
83 } 85 }
84 86
85 console.debug('ServerApi::inviteUser'); 87 debug('ServerApi::inviteUser');
86 return true; 88 return true;
87 } 89 }
88 90
@@ -98,7 +100,7 @@ export default class ServerApi {
98 } 100 }
99 const r = await request.json(); 101 const r = await request.json();
100 102
101 console.debug('ServerApi::retrievePassword'); 103 debug('ServerApi::retrievePassword');
102 return r; 104 return r;
103 } 105 }
104 106
@@ -112,7 +114,7 @@ export default class ServerApi {
112 const data = await request.json(); 114 const data = await request.json();
113 115
114 const user = new UserModel(data); 116 const user = new UserModel(data);
115 console.debug('ServerApi::userInfo resolves', user); 117 debug('ServerApi::userInfo resolves', user);
116 118
117 return user; 119 return user;
118 } 120 }
@@ -128,7 +130,7 @@ export default class ServerApi {
128 const updatedData = await request.json(); 130 const updatedData = await request.json();
129 131
130 const user = Object.assign(updatedData, { data: new UserModel(updatedData.data) }); 132 const user = Object.assign(updatedData, { data: new UserModel(updatedData.data) });
131 console.debug('ServerApi::updateUserInfo resolves', user); 133 debug('ServerApi::updateUserInfo resolves', user);
132 return user; 134 return user;
133 } 135 }
134 136
@@ -141,7 +143,7 @@ export default class ServerApi {
141 } 143 }
142 const data = await request.json(); 144 const data = await request.json();
143 145
144 console.debug('ServerApi::deleteAccount resolves', data); 146 debug('ServerApi::deleteAccount resolves', data);
145 return data; 147 return data;
146 } 148 }
147 149
@@ -157,7 +159,7 @@ export default class ServerApi {
157 159
158 let services = await this._mapServiceModels(data); 160 let services = await this._mapServiceModels(data);
159 services = services.filter(service => service !== null); 161 services = services.filter(service => service !== null);
160 console.debug('ServerApi::getServices resolves', services); 162 debug('ServerApi::getServices resolves', services);
161 return services; 163 return services;
162 } 164 }
163 165
@@ -181,7 +183,7 @@ export default class ServerApi {
181 183
182 const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); 184 const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) });
183 185
184 console.debug('ServerApi::createService resolves', service); 186 debug('ServerApi::createService resolves', service);
185 return service; 187 return service;
186 } 188 }
187 189
@@ -205,7 +207,7 @@ export default class ServerApi {
205 207
206 const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); 208 const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) });
207 209
208 console.debug('ServerApi::updateService resolves', service); 210 debug('ServerApi::updateService resolves', service);
209 return service; 211 return service;
210 } 212 }
211 213
@@ -240,7 +242,7 @@ export default class ServerApi {
240 throw request; 242 throw request;
241 } 243 }
242 const serviceData = await request.json(); 244 const serviceData = await request.json();
243 console.debug('ServerApi::reorderService resolves', serviceData); 245 debug('ServerApi::reorderService resolves', serviceData);
244 return serviceData; 246 return serviceData;
245 } 247 }
246 248
@@ -255,7 +257,7 @@ export default class ServerApi {
255 257
256 removeServicePartitionDirectory(id, true); 258 removeServicePartitionDirectory(id, true);
257 259
258 console.debug('ServerApi::deleteService resolves', data); 260 debug('ServerApi::deleteService resolves', data);
259 return data; 261 return data;
260 } 262 }
261 263
@@ -277,7 +279,7 @@ export default class ServerApi {
277 279
278 this.recipes = this.recipes.concat(this._getDevRecipes()); 280 this.recipes = this.recipes.concat(this._getDevRecipes());
279 281
280 console.debug('StubServerApi::getInstalledRecipes resolves', this.recipes); 282 debug('StubServerApi::getInstalledRecipes resolves', this.recipes);
281 return this.recipes; 283 return this.recipes;
282 } 284 }
283 285
@@ -290,7 +292,7 @@ export default class ServerApi {
290 throw request; 292 throw request;
291 } 293 }
292 const recipes = await request.json(); 294 const recipes = await request.json();
293 console.debug('ServerApi::getRecipeUpdates resolves', recipes); 295 debug('ServerApi::getRecipeUpdates resolves', recipes);
294 return recipes; 296 return recipes;
295 } 297 }
296 298
@@ -305,7 +307,7 @@ export default class ServerApi {
305 const data = await request.json(); 307 const data = await request.json();
306 308
307 const recipePreviews = this._mapRecipePreviewModel(data); 309 const recipePreviews = this._mapRecipePreviewModel(data);
308 console.debug('ServerApi::getRecipes resolves', recipePreviews); 310 debug('ServerApi::getRecipes resolves', recipePreviews);
309 311
310 return recipePreviews; 312 return recipePreviews;
311 } 313 }
@@ -322,7 +324,7 @@ export default class ServerApi {
322 // data = this._addLocalRecipesToPreviews(data); 324 // data = this._addLocalRecipesToPreviews(data);
323 325
324 const recipePreviews = this._mapRecipePreviewModel(data); 326 const recipePreviews = this._mapRecipePreviewModel(data);
325 console.debug('ServerApi::getFeaturedRecipes resolves', recipePreviews); 327 debug('ServerApi::getFeaturedRecipes resolves', recipePreviews);
326 return recipePreviews; 328 return recipePreviews;
327 } 329 }
328 330
@@ -336,7 +338,7 @@ export default class ServerApi {
336 const data = await request.json(); 338 const data = await request.json();
337 339
338 const recipePreviews = this._mapRecipePreviewModel(data); 340 const recipePreviews = this._mapRecipePreviewModel(data);
339 console.debug('ServerApi::searchRecipePreviews resolves', recipePreviews); 341 debug('ServerApi::searchRecipePreviews resolves', recipePreviews);
340 return recipePreviews; 342 return recipePreviews;
341 } 343 }
342 344
@@ -350,7 +352,7 @@ export default class ServerApi {
350 352
351 fs.ensureDirSync(recipeTempDirectory); 353 fs.ensureDirSync(recipeTempDirectory);
352 const res = await fetch(packageUrl); 354 const res = await fetch(packageUrl);
353 console.debug('Recipe downloaded', recipeId); 355 debug('Recipe downloaded', recipeId);
354 const buffer = await res.buffer(); 356 const buffer = await res.buffer();
355 fs.writeFileSync(archivePath, buffer); 357 fs.writeFileSync(archivePath, buffer);
356 358
@@ -392,7 +394,7 @@ export default class ServerApi {
392 const data = await request.json(); 394 const data = await request.json();
393 395
394 const plan = new PlanModel(data); 396 const plan = new PlanModel(data);
395 console.debug('ServerApi::getPlans resolves', plan); 397 debug('ServerApi::getPlans resolves', plan);
396 return plan; 398 return plan;
397 } 399 }
398 400
@@ -408,7 +410,7 @@ export default class ServerApi {
408 } 410 }
409 const data = await request.json(); 411 const data = await request.json();
410 412
411 console.debug('ServerApi::getHostedPage resolves', data); 413 debug('ServerApi::getHostedPage resolves', data);
412 return data; 414 return data;
413 } 415 }
414 416
@@ -421,7 +423,7 @@ export default class ServerApi {
421 } 423 }
422 const data = await request.json(); 424 const data = await request.json();
423 425
424 console.debug('ServerApi::getPaymentDashboardUrl resolves', data); 426 debug('ServerApi::getPaymentDashboardUrl resolves', data);
425 return data; 427 return data;
426 } 428 }
427 429
@@ -434,7 +436,7 @@ export default class ServerApi {
434 } 436 }
435 const data = await request.json(); 437 const data = await request.json();
436 const orders = this._mapOrderModels(data); 438 const orders = this._mapOrderModels(data);
437 console.debug('ServerApi::getSubscriptionOrders resolves', orders); 439 debug('ServerApi::getSubscriptionOrders resolves', orders);
438 return orders; 440 return orders;
439 } 441 }
440 442
@@ -451,7 +453,7 @@ export default class ServerApi {
451 } 453 }
452 const data = await request.json(); 454 const data = await request.json();
453 const news = this._mapNewsModels(data); 455 const news = this._mapNewsModels(data);
454 console.debug('ServerApi::getLatestNews resolves', news); 456 debug('ServerApi::getLatestNews resolves', news);
455 return news; 457 return news;
456 } 458 }
457 459
@@ -465,7 +467,7 @@ export default class ServerApi {
465 throw request; 467 throw request;
466 } 468 }
467 469
468 console.debug('ServerApi::hideNews resolves', id); 470 debug('ServerApi::hideNews resolves', id);
469 } 471 }
470 472
471 // Health Check 473 // Health Check
@@ -476,7 +478,7 @@ export default class ServerApi {
476 if (!request.ok) { 478 if (!request.ok) {
477 throw request; 479 throw request;
478 } 480 }
479 console.debug('ServerApi::healthCheck resolves'); 481 debug('ServerApi::healthCheck resolves');
480 } 482 }
481 483
482 async getLegacyServices() { 484 async getLegacyServices() {
@@ -502,7 +504,7 @@ export default class ServerApi {
502 return service; 504 return service;
503 })); 505 }));
504 506
505 console.debug('ServerApi::getLegacyServices resolves', services); 507 debug('ServerApi::getLegacyServices resolves', services);
506 return services; 508 return services;
507 } 509 }
508 } catch (err) { 510 } catch (err) {
@@ -535,7 +537,7 @@ export default class ServerApi {
535 537
536 return new ServiceModel(service, recipe); 538 return new ServiceModel(service, recipe);
537 } catch (e) { 539 } catch (e) {
538 console.debug(e); 540 debug(e);
539 return null; 541 return null;
540 } 542 }
541 } 543 }
@@ -553,7 +555,7 @@ export default class ServerApi {
553 555
554 await this.getRecipePackage(recipeId); 556 await this.getRecipePackage(recipeId);
555 557
556 console.debug('Rerun ServerAPI::getInstalledRecipes'); 558 debug('Rerun ServerAPI::getInstalledRecipes');
557 await this.getInstalledRecipes(); 559 await this.getInstalledRecipes();
558 560
559 recipe = this.recipes.find(r => r.id === recipeId); 561 recipe = this.recipes.find(r => r.id === recipeId);
@@ -653,7 +655,7 @@ export default class ServerApi {
653 655
654 return recipes; 656 return recipes;
655 } catch (err) { 657 } catch (err) {
656 console.debug('Could not load dev recipes'); 658 debug('Could not load dev recipes');
657 return false; 659 return false;
658 } 660 }
659 } 661 }
diff --git a/src/index.html b/src/index.html
index 6c259e5be..5ce7f6a96 100644
--- a/src/index.html
+++ b/src/index.html
@@ -15,6 +15,11 @@
15 15
16 const { isDevMode } = require('./environment'); 16 const { isDevMode } = require('./environment');
17 if (isDevMode) { 17 if (isDevMode) {
18 const debugging = require('debug');
19 debugging.enable(process.env.DEBUG);
20
21 const debug = debugging('Index');
22
18 document.querySelector('body').classList.add('isDevMode'); 23 document.querySelector('body').classList.add('isDevMode');
19 24
20 (function() { 25 (function() {
@@ -25,7 +30,7 @@
25 document.body.appendChild(s); 30 document.body.appendChild(s);
26 31
27 s.onload = () => { 32 s.onload = () => {
28 console.log('livereload loaded'); 33 debug('livereload loaded');
29 const originalReloadBehaviour = window._onLiveReloadFileChanged; 34 const originalReloadBehaviour = window._onLiveReloadFileChanged;
30 35
31 window._onLiveReloadFileChanged = (file) => { 36 window._onLiveReloadFileChanged = (file) => {
@@ -33,10 +38,10 @@
33 originalReloadBehaviour(file); 38 originalReloadBehaviour(file);
34 } else { 39 } else {
35 if (file.path.includes('/build/webview/')) { 40 if (file.path.includes('/build/webview/')) {
36 console.log('Livereload: Reloading all webvies'); 41 debug('Livereload: Reloading all webvies');
37 const webviews = document.querySelectorAll('webview').forEach(webview => webview.reload()); 42 const webviews = document.querySelectorAll('webview').forEach(webview => webview.reload());
38 } else { 43 } else {
39 console.log('Livereload: skip reload as only main process files have changed'); 44 debug('Livereload: skip reload as only main process files have changed');
40 } 45 }
41 } 46 }
42 } 47 }
diff --git a/src/lib/analytics.js b/src/lib/analytics.js
index b13bf8faa..585cbcdba 100644
--- a/src/lib/analytics.js
+++ b/src/lib/analytics.js
@@ -2,6 +2,8 @@ import { remote } from 'electron';
2import { GA_ID } from '../config'; 2import { GA_ID } from '../config';
3// import { isDevMode } from '../environment'; 3// import { isDevMode } from '../environment';
4 4
5const debug = require('debug')('Analytics');
6
5const { app } = remote; 7const { app } = remote;
6 8
7/* eslint-disable */ 9/* eslint-disable */
@@ -28,13 +30,13 @@ ga('send', 'App');
28export function gaPage(page) { 30export function gaPage(page) {
29 ga('send', 'pageview', page); 31 ga('send', 'pageview', page);
30 32
31 console.debug('GA track page', page); 33 debug('GA track page', page);
32} 34}
33 35
34export function gaEvent(category, action, label) { 36export function gaEvent(category, action, label) {
35 ga('send', 'event', category, action, label); 37 ga('send', 'event', category, action, label);
36 38
37 console.debug('GA track page', category, action); 39 debug('GA track page', category, action);
38} 40}
39 41
40setTimeout(() => { 42setTimeout(() => {
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js
index 67fee1d50..a24308f6a 100644
--- a/src/stores/RecipesStore.js
+++ b/src/stores/RecipesStore.js
@@ -5,6 +5,8 @@ import CachedRequest from './lib/CachedRequest';
5import Request from './lib/Request'; 5import Request from './lib/Request';
6import { matchRoute } from '../helpers/routing-helpers'; 6import { matchRoute } from '../helpers/routing-helpers';
7 7
8const debug = require('debug')('RecipeStore');
9
8export default class RecipesStore extends Store { 10export default class RecipesStore extends Store {
9 @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); 11 @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all');
10 @observable installRecipeRequest = new Request(this.api.recipes, 'install'); 12 @observable installRecipeRequest = new Request(this.api.recipes, 'install');
@@ -34,7 +36,7 @@ export default class RecipesStore extends Store {
34 return activeRecipe; 36 return activeRecipe;
35 } 37 }
36 38
37 console.warn('Recipe not installed'); 39 debug(`Recipe ${match.id} not installed`);
38 } 40 }
39 41
40 return null; 42 return null;
@@ -54,10 +56,8 @@ export default class RecipesStore extends Store {
54 56
55 // Actions 57 // Actions
56 @action async _install({ recipeId }) { 58 @action async _install({ recipeId }) {
57 // console.log(this.installRecipeRequest._promise);
58 const recipe = await this.installRecipeRequest.execute(recipeId)._promise; 59 const recipe = await this.installRecipeRequest.execute(recipeId)._promise;
59 await this.allRecipesRequest.invalidate({ immediately: true })._promise; 60 await this.allRecipesRequest.invalidate({ immediately: true })._promise;
60 // console.log(this.installRecipeRequest._promise);
61 61
62 return recipe; 62 return recipe;
63 } 63 }
@@ -67,7 +67,7 @@ export default class RecipesStore extends Store {
67 const recipes = {}; 67 const recipes = {};
68 68
69 // Hackfix, reference this.all to fetch services 69 // Hackfix, reference this.all to fetch services
70 console.debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); 70 debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`);
71 71
72 recipeIds.forEach((r) => { 72 recipeIds.forEach((r) => {
73 const recipe = this.one(r); 73 const recipe = this.one(r);
diff --git a/src/stores/RequestStore.js b/src/stores/RequestStore.js
index 4140ca362..595852583 100644
--- a/src/stores/RequestStore.js
+++ b/src/stores/RequestStore.js
@@ -2,6 +2,8 @@ import { action, computed, observable } from 'mobx';
2 2
3import Store from './lib/Store'; 3import Store from './lib/Store';
4 4
5const debug = require('debug')('RequestsStore');
6
5export default class RequestStore extends Store { 7export default class RequestStore extends Store {
6 @observable userInfoRequest; 8 @observable userInfoRequest;
7 @observable servicesRequest; 9 @observable servicesRequest;
@@ -52,7 +54,7 @@ export default class RequestStore extends Store {
52 } 54 }
53 55
54 this._autoRetry(); 56 this._autoRetry();
55 console.debug(`Retry required requests delayed in ${(delay) / 1000}s`); 57 debug(`Retry required requests delayed in ${(delay) / 1000}s`);
56 }, delay); 58 }, delay);
57 } 59 }
58 } 60 }
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index c2dbff55d..f7d92b1ff 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -10,6 +10,8 @@ import CachedRequest from './lib/CachedRequest';
10import { matchRoute } from '../helpers/routing-helpers'; 10import { matchRoute } from '../helpers/routing-helpers';
11import { gaEvent } from '../lib/analytics'; 11import { gaEvent } from '../lib/analytics';
12 12
13const debug = require('debug')('ServiceStore');
14
13export default class ServicesStore extends Store { 15export default class ServicesStore extends Store {
14 @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); 16 @observable allServicesRequest = new CachedRequest(this.api.services, 'all');
15 @observable createServiceRequest = new Request(this.api.services, 'create'); 17 @observable createServiceRequest = new Request(this.api.services, 'create');
@@ -109,7 +111,7 @@ export default class ServicesStore extends Store {
109 return activeService; 111 return activeService;
110 } 112 }
111 113
112 console.warn('Service not available'); 114 debug('Service not available');
113 } 115 }
114 116
115 return null; 117 return null;
@@ -123,10 +125,10 @@ export default class ServicesStore extends Store {
123 const recipesStore = this.stores.recipes; 125 const recipesStore = this.stores.recipes;
124 126
125 if (recipesStore.isInstalled(recipeId)) { 127 if (recipesStore.isInstalled(recipeId)) {
126 console.debug('Recipe is installed'); 128 debug(`Recipe ${recipeId} is installed`);
127 this._redirectToAddServiceRoute(recipeId); 129 this._redirectToAddServiceRoute(recipeId);
128 } else { 130 } else {
129 console.warn('Recipe is not installed'); 131 debug(`Recipe ${recipeId} is not installed`);
130 // We access the RecipeStore action directly 132 // We access the RecipeStore action directly
131 // returns Promise instead of action 133 // returns Promise instead of action
132 await this.stores.recipes._install({ recipeId }); 134 await this.stores.recipes._install({ recipeId });
@@ -493,7 +495,7 @@ export default class ServicesStore extends Store {
493 if (service) { 495 if (service) {
494 service.webview.openDevTools(); 496 service.webview.openDevTools();
495 } else { 497 } else {
496 console.warn('No service is active'); 498 debug('No service is active');
497 } 499 }
498 } 500 }
499 501