aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.js
diff options
context:
space:
mode:
authorLibravatar Bennett <hello@vantezzen.io>2020-04-17 14:32:53 +0200
committerLibravatar GitHub <noreply@github.com>2020-04-17 13:32:53 +0100
commit3239172af9fb68226e1e11392b16f833b726ad72 (patch)
treefdafdea17c8873cffdec64351e532ffdb2c7d233 /src/stores/ServicesStore.js
parentNew Crowdin translations (#570) (diff)
downloadferdium-app-3239172af9fb68226e1e11392b16f833b726ad72.tar.gz
ferdium-app-3239172af9fb68226e1e11392b16f833b726ad72.tar.zst
ferdium-app-3239172af9fb68226e1e11392b16f833b726ad72.zip
Merge Franz 5.5.0 beta.1 and 2 (#549)
* Automatic i18n update (i18n.meetfranz.com) * Fix zoom not working * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Add environment variable FRANZ_APPDATA_DIR * Add environment variable for config FRANZ_APPDATA_DIR * fix stuff that shouldn't need fixing in the first place * notarize app * bump version to 5.4.1 * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * update to electron 7.1.7 * bump version to 5.5.0 * Automatic i18n update (i18n.meetfranz.com) * Bump electron to 7.1.10 * plan changes * filter plan variants * add missing string * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Replace/remove deprecated electron function calls Electron replaced several function calls with object properties. Franz still uses some of these deprecated functions, so this commit will replace these with their new property counterpart. This commit is only transferring the changes made in getferdi/ferdi#371 and getferdi/ferdi#384 into the upstream repository. * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Update to electron 8.0.1 * feat(Service): Add service hibernation to save system resources * Fix linting issues * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Bump version to electron 8.1.1 * update strings * update electron-notarize * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Automatic i18n update (i18n.meetfranz.com) * Add audio & video permission request for cataline * Automatic i18n update (i18n.meetfranz.com) * bump version to beta 1 * Automatic i18n update (i18n.meetfranz.com) * enable external links * Fix main content href * Automatic i18n update (i18n.meetfranz.com) * fix(Service): Fix issue with user agent override in service workers * Automatic i18n update (i18n.meetfranz.com) * fix macOS string replacement * Automatic i18n update (i18n.meetfranz.com) * fix(Experimental): Fix Google signin * fix(Service): Add integrity checks to prevent services recipes getting lost * Remove service reload on app-resume * update strings * bump version to beta 2 * Automatic i18n update (i18n.meetfranz.com) * bump electron-builder and electron-updater deps * test video permissions * fix `extendInfo` keys * fix typo * fix permission request * update camera/microphone entitlements * Automatic i18n update (i18n.meetfranz.com) * Test screen capture permissions * unpack `mac-screen-capture-permissions` * don't require localstorage temp key for permissions request * move macOS permission request to main process * Fix checking for permissions * fix(macOS): Ask the user to move Franz to the `/Applications` Folder * only try to recover recipe when user is online * update service request link * Update changelog * Reset `service.lostRecipeReloadAttempt` once service is alive again * Update translations * Fix crash on macOS * Fix merge errors * Fix lint * Disable ConnectionLostBanner * #551 Add information about Ferdi to the user agent * Fix requested changes * Remove tsbuildinfo files * Add .tsbuildinfo files to gitignore * Fix "Cannot destructure property 'app' of '_electron.remote' as it is undefined" Co-authored-by: FranzBot <i18n@meetfranz.com> Co-authored-by: Makazzz <makazzzpro@live.ca> Co-authored-by: Stefan Malzner <stefan@adlk.io>
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r--src/stores/ServicesStore.js67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 19e6f8299..80c7d7e81 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -5,7 +5,7 @@ import {
5 computed, 5 computed,
6 observable, 6 observable,
7} from 'mobx'; 7} from 'mobx';
8import { remove } from 'lodash'; 8import { debounce, remove } from 'lodash';
9import ms from 'ms'; 9import ms from 'ms';
10import fs from 'fs-extra'; 10import fs from 'fs-extra';
11import path from 'path'; 11import path from 'path';
@@ -127,6 +127,60 @@ export default class ServicesStore extends Store {
127 ); 127 );
128 } 128 }
129 129
130 initialize() {
131 super.initialize();
132
133 // Check services to become hibernated
134 this.serviceMaintenanceTick();
135 }
136
137 teardown() {
138 super.teardown();
139
140 // Stop checking services for hibernation
141 this.serviceMaintenanceTick.cancel();
142 }
143
144 /**
145 * Сheck for services to become hibernated.
146 */
147 serviceMaintenanceTick = debounce(() => {
148 this._serviceMaintenance();
149 this.serviceMaintenanceTick();
150 debug('Service maintenance tick');
151 }, ms('10s'));
152
153 /**
154 * Run various maintenance tasks on services
155 */
156 _serviceMaintenance() {
157 this.all.forEach((service) => {
158 // Defines which services should be hibernated.
159 if (!service.isActive && (Date.now() - service.lastUsed > ms('5m'))) {
160 // If service is stale for 5 min, hibernate it.
161 this._hibernate({ serviceId: service.id });
162 }
163
164 if (service.lastPoll && (service.lastPoll) - service.lastPollAnswer > ms('30s')) {
165 // If service did not reply for more than 30s try to reload.
166 if (!service.isActive) {
167 if (this.stores.app.isOnline && service.lostRecipeReloadAttempt < 3) {
168 service.webview.reload();
169 service.lostRecipeReloadAttempt += 1;
170
171 service.lostRecipeConnection = false;
172 }
173 } else {
174 service.lostRecipeConnection = true;
175 }
176 } else {
177 service.lostRecipeConnection = false;
178 service.lostRecipeReloadAttempt = 0;
179 }
180 });
181 }
182
183 // Computed props
130 @computed get all() { 184 @computed get all() {
131 if (this.stores.user.isLoggedIn) { 185 if (this.stores.user.isLoggedIn) {
132 const services = this.allServicesRequest.execute().result; 186 const services = this.allServicesRequest.execute().result;
@@ -379,6 +433,7 @@ export default class ServicesStore extends Store {
379 this.all[index].isActive = false; 433 this.all[index].isActive = false;
380 }); 434 });
381 service.isActive = true; 435 service.isActive = true;
436 service.lastUsed = Date.now();
382 437
383 // Update list of last used services 438 // Update list of last used services
384 this.lastUsedServices = this.lastUsedServices.filter(id => id !== serviceId); 439 this.lastUsedServices = this.lastUsedServices.filter(id => id !== serviceId);
@@ -475,10 +530,16 @@ export default class ServicesStore extends Store {
475 const service = this.one(serviceId); 530 const service = this.one(serviceId);
476 531
477 if (channel === 'hello') { 532 if (channel === 'hello') {
533 debug('Received hello event from', serviceId);
534
478 this._initRecipePolling(service.id); 535 this._initRecipePolling(service.id);
479 this._initializeServiceRecipeInWebview(serviceId); 536 this._initializeServiceRecipeInWebview(serviceId);
480 this._shareSettingsWithServiceProcess(); 537 this._shareSettingsWithServiceProcess();
538 } else if (channel === 'alive') {
539 service.lastPollAnswer = Date.now();
481 } else if (channel === 'messages') { 540 } else if (channel === 'messages') {
541 debug(`Received unread message info from '${serviceId}'`, args[0]);
542
482 this.actions.service.setUnreadMessageCount({ 543 this.actions.service.setUnreadMessageCount({
483 serviceId, 544 serviceId,
484 count: { 545 count: {
@@ -600,6 +661,7 @@ export default class ServicesStore extends Store {
600 if (!service.isEnabled) return; 661 if (!service.isEnabled) return;
601 662
602 service.resetMessageCount(); 663 service.resetMessageCount();
664 service.lostRecipeConnection = false;
603 665
604 // service.webview.loadURL(service.url); 666 // service.webview.loadURL(service.url);
605 service.webview.reload(); 667 service.webview.reload();
@@ -777,7 +839,7 @@ export default class ServicesStore extends Store {
777 const isMuted = isAppMuted || service.isMuted; 839 const isMuted = isAppMuted || service.isMuted;
778 840
779 if (isAttached) { 841 if (isAttached) {
780 service.webview.setAudioMuted(isMuted); 842 service.webview.audioMuted = isMuted;
781 } 843 }
782 }); 844 });
783 } 845 }
@@ -863,6 +925,7 @@ export default class ServicesStore extends Store {
863 service.webview.send('poll'); 925 service.webview.send('poll');
864 926
865 service.timer = setTimeout(loop, delay); 927 service.timer = setTimeout(loop, delay);
928 service.lastPoll = Date.now();
866 }; 929 };
867 930
868 loop(); 931 loop();