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