aboutsummaryrefslogtreecommitdiffstats
path: root/src/models/Service.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/models/Service.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/models/Service.js')
-rw-r--r--src/models/Service.js54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/models/Service.js b/src/models/Service.js
index f073ac9fc..dc8febe0b 100644
--- a/src/models/Service.js
+++ b/src/models/Service.js
@@ -2,6 +2,8 @@ import { autorun, computed, observable } from 'mobx';
2import normalizeUrl from 'normalize-url'; 2import normalizeUrl from 'normalize-url';
3import path from 'path'; 3import path from 'path';
4 4
5import userAgent from '../helpers/userAgent-helpers';
6
5const debug = require('debug')('Ferdi:Service'); 7const debug = require('debug')('Ferdi:Service');
6 8
7export const RESTRICTION_TYPES = { 9export const RESTRICTION_TYPES = {
@@ -74,6 +76,20 @@ export default class Service {
74 76
75 @observable restrictionType = null; 77 @observable restrictionType = null;
76 78
79 @observable isHibernationEnabled = false;
80
81 @observable lastUsed = Date.now(); // timestamp
82
83 @observable lastPoll = null;
84
85 @observable lastPollAnswer = null;
86
87 @observable lostRecipeConnection = false;
88
89 @observable lostRecipeReloadAttempt = 0;
90
91 @observable chromelessUserAgent = false;
92
77 constructor(data, recipe) { 93 constructor(data, recipe) {
78 if (!data) { 94 if (!data) {
79 console.error('Service config not valid'); 95 console.error('Service config not valid');
@@ -119,6 +135,8 @@ export default class Service {
119 135
120 this.spellcheckerLanguage = data.spellcheckerLanguage !== undefined ? data.spellcheckerLanguage : this.spellcheckerLanguage; 136 this.spellcheckerLanguage = data.spellcheckerLanguage !== undefined ? data.spellcheckerLanguage : this.spellcheckerLanguage;
121 137
138 this.isHibernationEnabled = data.isHibernationEnabled !== undefined ? data.isHibernationEnabled : this.isHibernationEnabled;
139
122 this.recipe = recipe; 140 this.recipe = recipe;
123 141
124 autorun(() => { 142 autorun(() => {
@@ -187,21 +205,34 @@ export default class Service {
187 } 205 }
188 206
189 @computed get userAgent() { 207 @computed get userAgent() {
190 let { userAgent } = window.navigator; 208 let ua = userAgent(this.chromelessUserAgent);
191 if (typeof this.recipe.overrideUserAgent === 'function') { 209 if (typeof this.recipe.overrideUserAgent === 'function') {
192 userAgent = this.recipe.overrideUserAgent(); 210 ua = this.recipe.overrideUserAgent();
193 } 211 }
194 212
195 // Remove Ferdi as it can cause incompatabilities with services. 213 return ua;
196 // This way, Ferdi will look like a normal Chrome instance
197 userAgent = userAgent.replace(/(Ferdi|Electron)([^\s]+\s)/g, '');
198
199 return userAgent;
200 } 214 }
201 215
202 initializeWebViewEvents({ handleIPCMessage, openWindow, stores }) { 216 initializeWebViewEvents({ handleIPCMessage, openWindow, stores }) {
203 const webContents = this.webview.getWebContents(); 217 const webContents = this.webview.getWebContents();
204 218
219 const handleUserAgent = (url, forwardingHack = false) => {
220 if (url.startsWith('https://accounts.google.com')) {
221 if (!this.chromelessUserAgent) {
222 debug('Setting user agent to chromeless for url', url);
223 this.webview.setUserAgent(userAgent(true));
224 if (forwardingHack) {
225 this.webview.loadURL(url);
226 }
227 this.chromelessUserAgent = true;
228 }
229 } else if (this.chromelessUserAgent) {
230 debug('Setting user agent to contain chrome');
231 this.webview.setUserAgent(this.userAgent);
232 this.chromelessUserAgent = false;
233 }
234 };
235
205 this.webview.addEventListener('ipc-message', e => handleIPCMessage({ 236 this.webview.addEventListener('ipc-message', e => handleIPCMessage({
206 serviceId: this.id, 237 serviceId: this.id,
207 channel: e.channel, 238 channel: e.channel,
@@ -209,7 +240,6 @@ export default class Service {
209 })); 240 }));
210 241
211 this.webview.addEventListener('new-window', (event, url, frameName, options) => { 242 this.webview.addEventListener('new-window', (event, url, frameName, options) => {
212 console.log('open window', event, url, frameName, options);
213 openWindow({ 243 openWindow({
214 event, 244 event,
215 url, 245 url,
@@ -218,6 +248,9 @@ export default class Service {
218 }); 248 });
219 }); 249 });
220 250
251
252 this.webview.addEventListener('will-navigate', event => handleUserAgent(event.url, true));
253
221 this.webview.addEventListener('did-start-loading', (event) => { 254 this.webview.addEventListener('did-start-loading', (event) => {
222 debug('Did start load', this.name, event); 255 debug('Did start load', this.name, event);
223 256
@@ -235,7 +268,10 @@ export default class Service {
235 }; 268 };
236 269
237 this.webview.addEventListener('did-frame-finish-load', didLoad.bind(this)); 270 this.webview.addEventListener('did-frame-finish-load', didLoad.bind(this));
238 this.webview.addEventListener('did-navigate', didLoad.bind(this)); 271 this.webview.addEventListener('did-navigate', (event) => {
272 handleUserAgent(event.url);
273 didLoad();
274 });
239 275
240 this.webview.addEventListener('did-fail-load', (event) => { 276 this.webview.addEventListener('did-fail-load', (event) => {
241 debug('Service failed to load', this.name, event); 277 debug('Service failed to load', this.name, event);