aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r--src/stores/ServicesStore.js55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 1c800df59..3847536ca 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -19,7 +19,8 @@ import { DEFAULT_SERVICE_SETTINGS, KEEP_WS_LOADED_USID } from '../config';
19import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 19import { SPELLCHECKER_LOCALES } from '../i18n/languages';
20import { ferdiumVersion } from '../environment-remote'; 20import { ferdiumVersion } from '../environment-remote';
21 21
22const debug = require('debug')('Ferdium:ServiceStore'); 22// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed
23// const debug = require('debug')('Ferdium:ServiceStore');
23 24
24export default class ServicesStore extends Store { 25export default class ServicesStore extends Store {
25 @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); 26 @observable allServicesRequest = new CachedRequest(this.api.services, 'all');
@@ -212,7 +213,7 @@ export default class ServicesStore extends Store {
212 serviceMaintenanceTick = debounce(() => { 213 serviceMaintenanceTick = debounce(() => {
213 this._serviceMaintenance(); 214 this._serviceMaintenance();
214 this.serviceMaintenanceTick(); 215 this.serviceMaintenanceTick();
215 debug('Service maintenance tick'); 216 console.log('Service maintenance tick');
216 }, ms('10s')); 217 }, ms('10s'));
217 218
218 /** 219 /**
@@ -250,7 +251,7 @@ export default class ServicesStore extends Store {
250 // If service did not reply for more than 1m try to reload. 251 // If service did not reply for more than 1m try to reload.
251 if (!service.isActive) { 252 if (!service.isActive) {
252 if (this.stores.app.isOnline && service.lostRecipeReloadAttempt < 3) { 253 if (this.stores.app.isOnline && service.lostRecipeReloadAttempt < 3) {
253 debug( 254 console.log(
254 `Reloading service: ${service.name} (${service.id}). Attempt: ${service.lostRecipeReloadAttempt}`, 255 `Reloading service: ${service.name} (${service.id}). Attempt: ${service.lostRecipeReloadAttempt}`,
255 ); 256 );
256 // service.webview.reload(); 257 // service.webview.reload();
@@ -259,7 +260,7 @@ export default class ServicesStore extends Store {
259 service.lostRecipeConnection = false; 260 service.lostRecipeConnection = false;
260 } 261 }
261 } else { 262 } else {
262 debug(`Service lost connection: ${service.name} (${service.id}).`); 263 console.log(`Service lost connection: ${service.name} (${service.id}).`);
263 service.lostRecipeConnection = true; 264 service.lostRecipeConnection = true;
264 } 265 }
265 } else { 266 } else {
@@ -363,7 +364,7 @@ export default class ServicesStore extends Store {
363 return activeService; 364 return activeService;
364 } 365 }
365 366
366 debug('Service not available'); 367 console.log('Service not available');
367 } 368 }
368 369
369 return null; 370 return null;
@@ -397,9 +398,9 @@ export default class ServicesStore extends Store {
397 skipCleanup = false, 398 skipCleanup = false,
398 }) { 399 }) {
399 if (!this.stores.recipes.isInstalled(recipeId)) { 400 if (!this.stores.recipes.isInstalled(recipeId)) {
400 debug(`Recipe "${recipeId}" is not installed, installing recipe`); 401 console.log(`Recipe "${recipeId}" is not installed, installing recipe`);
401 await this.stores.recipes._install({ recipeId }); 402 await this.stores.recipes._install({ recipeId });
402 debug(`Recipe "${recipeId}" installed`); 403 console.log(`Recipe "${recipeId}" installed`);
403 } 404 }
404 405
405 // set default values for serviceData 406 // set default values for serviceData
@@ -616,7 +617,7 @@ export default class ServicesStore extends Store {
616 if (service) { 617 if (service) {
617 service.isActive = false; 618 service.isActive = false;
618 } else { 619 } else {
619 debug('No service is active'); 620 console.log('No service is active');
620 } 621 }
621 } 622 }
622 623
@@ -659,7 +660,7 @@ export default class ServicesStore extends Store {
659 service.webview = webview; 660 service.webview = webview;
660 661
661 if (!service.isAttached) { 662 if (!service.isAttached) {
662 debug('Webview is not attached, initializing'); 663 console.log('Webview is not attached, initializing');
663 service.initializeWebViewEvents({ 664 service.initializeWebViewEvents({
664 handleIPCMessage: this.actions.service.handleIPCMessage, 665 handleIPCMessage: this.actions.service.handleIPCMessage,
665 openWindow: this.actions.service.openWindow, 666 openWindow: this.actions.service.openWindow,
@@ -708,7 +709,7 @@ export default class ServicesStore extends Store {
708 } 709 }
709 } 710 }
710 } else { 711 } else {
711 debug('No service is active'); 712 console.log('No service is active');
712 } 713 }
713 } else { 714 } else {
714 this.allServicesRequest.invalidate(); 715 this.allServicesRequest.invalidate();
@@ -727,7 +728,7 @@ export default class ServicesStore extends Store {
727 // eslint-disable-next-line default-case 728 // eslint-disable-next-line default-case
728 switch (channel) { 729 switch (channel) {
729 case 'hello': { 730 case 'hello': {
730 debug('Received hello event from', serviceId); 731 console.log('Received hello event from', serviceId);
731 732
732 this._initRecipePolling(service.id); 733 this._initRecipePolling(service.id);
733 this._initializeServiceRecipeInWebview(serviceId); 734 this._initializeServiceRecipeInWebview(serviceId);
@@ -741,7 +742,7 @@ export default class ServicesStore extends Store {
741 break; 742 break;
742 } 743 }
743 case 'message-counts': { 744 case 'message-counts': {
744 debug(`Received unread message info from '${serviceId}'`, args[0]); 745 console.log(`Received unread message info from '${serviceId}'`, args[0]);
745 746
746 this.actions.service.setUnreadMessageCount({ 747 this.actions.service.setUnreadMessageCount({
747 serviceId, 748 serviceId,
@@ -754,7 +755,7 @@ export default class ServicesStore extends Store {
754 break; 755 break;
755 } 756 }
756 case 'active-dialog-title': { 757 case 'active-dialog-title': {
757 debug(`Received active dialog title from '${serviceId}'`, args[0]); 758 console.log(`Received active dialog title from '${serviceId}'`, args[0]);
758 759
759 this.actions.service.setDialogTitle({ 760 this.actions.service.setDialogTitle({
760 serviceId, 761 serviceId,
@@ -919,7 +920,7 @@ export default class ServicesStore extends Store {
919 serviceId: service.id, 920 serviceId: service.id,
920 }); 921 });
921 } else { 922 } else {
922 debug('No service is active'); 923 console.log('No service is active');
923 } 924 }
924 } 925 }
925 926
@@ -1027,7 +1028,7 @@ export default class ServicesStore extends Store {
1027 if (service) { 1028 if (service) {
1028 this._openDevTools({ serviceId: service.id }); 1029 this._openDevTools({ serviceId: service.id });
1029 } else { 1030 } else {
1030 debug('No service is active'); 1031 console.log('No service is active');
1031 } 1032 }
1032 } 1033 }
1033 1034
@@ -1037,7 +1038,7 @@ export default class ServicesStore extends Store {
1037 return; 1038 return;
1038 } 1039 }
1039 1040
1040 debug(`Hibernate ${service.name}`); 1041 console.log(`Hibernate ${service.name}`);
1041 1042
1042 service.isHibernationRequested = true; 1043 service.isHibernationRequested = true;
1043 service.lastHibernated = Date.now(); 1044 service.lastHibernated = Date.now();
@@ -1047,7 +1048,7 @@ export default class ServicesStore extends Store {
1047 const now = Date.now(); 1048 const now = Date.now();
1048 const service = this.one(serviceId); 1049 const service = this.one(serviceId);
1049 const automaticTag = automatic ? ' automatically ' : ' '; 1050 const automaticTag = automatic ? ' automatically ' : ' ';
1050 debug( 1051 console.log(
1051 `Waking up${automaticTag}from service hibernation for ${service.name}`, 1052 `Waking up${automaticTag}from service hibernation for ${service.name}`,
1052 ); 1053 );
1053 1054
@@ -1068,8 +1069,8 @@ export default class ServicesStore extends Store {
1068 // 1069 //
1069 const mainStrategy = this.stores.settings.all.app.hibernationStrategy; 1070 const mainStrategy = this.stores.settings.all.app.hibernationStrategy;
1070 let strategy = this.stores.settings.all.app.wakeUpHibernationStrategy; 1071 let strategy = this.stores.settings.all.app.wakeUpHibernationStrategy;
1071 debug(`wakeUpHibernationStrategy = ${strategy}`); 1072 console.log(`wakeUpHibernationStrategy = ${strategy}`);
1072 debug(`hibernationStrategy = ${mainStrategy}`); 1073 console.log(`hibernationStrategy = ${mainStrategy}`);
1073 if (!strategy || strategy < 1) { 1074 if (!strategy || strategy < 1) {
1074 strategy = this.stores.settings.all.app.hibernationStrategy; 1075 strategy = this.stores.settings.all.app.hibernationStrategy;
1075 } 1076 }
@@ -1081,16 +1082,16 @@ export default class ServicesStore extends Store {
1081 ) { 1082 ) {
1082 // Add 10 additional seconds 50% of the time. 1083 // Add 10 additional seconds 50% of the time.
1083 splay = 10; 1084 splay = 10;
1084 debug('Added splay'); 1085 console.log('Added splay');
1085 } else { 1086 } else {
1086 debug('skipping splay'); 1087 console.log('skipping splay');
1087 } 1088 }
1088 // wake up again in strategy + splay seconds instead of mainStrategy seconds. 1089 // wake up again in strategy + splay seconds instead of mainStrategy seconds.
1089 service.lastUsed = now - ms(`${mainStrategy - (strategy + splay)}s`); 1090 service.lastUsed = now - ms(`${mainStrategy - (strategy + splay)}s`);
1090 } else { 1091 } else {
1091 service.lastUsed = now; 1092 service.lastUsed = now;
1092 } 1093 }
1093 debug( 1094 console.log(
1094 `Setting service.lastUsed to ${service.lastUsed} (${ 1095 `Setting service.lastUsed to ${service.lastUsed} (${
1095 (now - service.lastUsed) / 1000 1096 (now - service.lastUsed) / 1000
1096 }s ago)`, 1097 }s ago)`,
@@ -1100,7 +1101,7 @@ export default class ServicesStore extends Store {
1100 } 1101 }
1101 1102
1102 @action _resetLastPollTimer({ serviceId = null }) { 1103 @action _resetLastPollTimer({ serviceId = null }) {
1103 debug( 1104 console.log(
1104 `Reset last poll timer for ${ 1105 `Reset last poll timer for ${
1105 serviceId ? `service: "${serviceId}"` : 'all services' 1106 serviceId ? `service: "${serviceId}"` : 'all services'
1106 }`, 1107 }`,
@@ -1131,7 +1132,7 @@ export default class ServicesStore extends Store {
1131 service.dialogTitle ? ` - ${service.dialogTitle}` : '' 1132 service.dialogTitle ? ` - ${service.dialogTitle}` : ''
1132 } ${service._webview ? `- ${service._webview.getTitle()}` : ''}`; 1133 } ${service._webview ? `- ${service._webview.getTitle()}` : ''}`;
1133 } else { 1134 } else {
1134 debug('No service is active'); 1135 console.log('No service is active');
1135 } 1136 }
1136 } 1137 }
1137 1138
@@ -1145,7 +1146,7 @@ export default class ServicesStore extends Store {
1145 }, 1146 },
1146 }); 1147 });
1147 } else { 1148 } else {
1148 debug('No service is active'); 1149 console.log('No service is active');
1149 } 1150 }
1150 } 1151 }
1151 1152
@@ -1261,7 +1262,7 @@ export default class ServicesStore extends Store {
1261 this.allDisplayed.findIndex(service => service.isActive) === -1 && 1262 this.allDisplayed.findIndex(service => service.isActive) === -1 &&
1262 this.allDisplayed.length > 0 1263 this.allDisplayed.length > 0
1263 ) { 1264 ) {
1264 debug('No active service found, setting active service to index 0'); 1265 console.log('No active service found, setting active service to index 0');
1265 1266
1266 this._setActive({ serviceId: this.allDisplayed[0].id }); 1267 this._setActive({ serviceId: this.allDisplayed[0].id });
1267 } 1268 }
@@ -1277,7 +1278,7 @@ export default class ServicesStore extends Store {
1277 JSON.stringify(service.shareWithWebview), 1278 JSON.stringify(service.shareWithWebview),
1278 ); 1279 );
1279 1280
1280 debug('Initialize recipe', service.recipe.id, service.name); 1281 console.log('Initialize recipe', service.recipe.id, service.name);
1281 service.webview.send( 1282 service.webview.send(
1282 'initialize-recipe', 1283 'initialize-recipe',
1283 { 1284 {