diff options
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/Plan.js | 17 | ||||
-rw-r--r-- | src/models/Recipe.js | 21 | ||||
-rw-r--r-- | src/models/RecipePreview.js | 3 | ||||
-rw-r--r-- | src/models/Service.js | 53 | ||||
-rw-r--r-- | src/models/User.js | 3 | ||||
-rw-r--r-- | src/models/UserAgent.js | 4 |
6 files changed, 44 insertions, 57 deletions
diff --git a/src/models/Plan.js b/src/models/Plan.js deleted file mode 100644 index 3dedf0d5e..000000000 --- a/src/models/Plan.js +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | // @flow | ||
2 | |||
3 | export default class Plan { | ||
4 | month = { | ||
5 | id: '', | ||
6 | price: 0, | ||
7 | } | ||
8 | |||
9 | year = { | ||
10 | id: '', | ||
11 | price: 0, | ||
12 | } | ||
13 | |||
14 | constructor(data) { | ||
15 | Object.assign(this, data); | ||
16 | } | ||
17 | } | ||
diff --git a/src/models/Recipe.js b/src/models/Recipe.js index 4db056f26..0d97d4472 100644 --- a/src/models/Recipe.js +++ b/src/models/Recipe.js | |||
@@ -1,9 +1,9 @@ | |||
1 | import emailParser from 'address-rfc2822'; | ||
2 | import semver from 'semver'; | 1 | import semver from 'semver'; |
3 | import fs from 'fs-extra'; | 2 | import { pathExistsSync } from 'fs-extra'; |
4 | import path from 'path'; | 3 | import { join } from 'path'; |
5 | 4 | ||
6 | export default class Recipe { | 5 | export default class Recipe { |
6 | // Note: Do NOT change these default values. If they change, then the corresponding changes in the recipes needs to be done | ||
7 | id = ''; | 7 | id = ''; |
8 | 8 | ||
9 | name = ''; | 9 | name = ''; |
@@ -12,6 +12,8 @@ export default class Recipe { | |||
12 | 12 | ||
13 | version = ''; | 13 | version = ''; |
14 | 14 | ||
15 | aliases = []; | ||
16 | |||
15 | path = ''; | 17 | path = ''; |
16 | 18 | ||
17 | serviceURL = ''; | 19 | serviceURL = ''; |
@@ -60,9 +62,8 @@ export default class Recipe { | |||
60 | 62 | ||
61 | this.id = data.id || this.id; | 63 | this.id = data.id || this.id; |
62 | this.name = data.name || this.name; | 64 | this.name = data.name || this.name; |
63 | this.rawAuthor = data.author || this.author; | ||
64 | this.description = data.description || this.description; | ||
65 | this.version = data.version || this.version; | 65 | this.version = data.version || this.version; |
66 | this.aliases = data.aliases || this.aliases; | ||
66 | this.path = data.path; | 67 | this.path = data.path; |
67 | 68 | ||
68 | this.serviceURL = data.config.serviceURL || this.serviceURL; | 69 | this.serviceURL = data.config.serviceURL || this.serviceURL; |
@@ -86,18 +87,12 @@ export default class Recipe { | |||
86 | this.message = data.config.message || this.message; | 87 | this.message = data.config.message || this.message; |
87 | } | 88 | } |
88 | 89 | ||
90 | // TODO: Need to remove this if its not used anywhere | ||
89 | get author() { | 91 | get author() { |
90 | try { | ||
91 | const addresses = emailParser.parse(this.rawAuthor); | ||
92 | return addresses.map(a => ({ email: a.address, name: a.phrase })); | ||
93 | } catch (err) { | ||
94 | console.warn(`Not a valid author for ${this.name}`); | ||
95 | } | ||
96 | |||
97 | return []; | 92 | return []; |
98 | } | 93 | } |
99 | 94 | ||
100 | get hasDarkMode() { | 95 | get hasDarkMode() { |
101 | return fs.pathExistsSync(path.join(this.path, 'darkmode.css')); | 96 | return pathExistsSync(join(this.path, 'darkmode.css')); |
102 | } | 97 | } |
103 | } | 98 | } |
diff --git a/src/models/RecipePreview.js b/src/models/RecipePreview.js index cfb22f860..6a9ce3080 100644 --- a/src/models/RecipePreview.js +++ b/src/models/RecipePreview.js | |||
@@ -7,9 +7,10 @@ export default class RecipePreview { | |||
7 | 7 | ||
8 | icon = ''; | 8 | icon = ''; |
9 | 9 | ||
10 | // TODO: check if this isn't replaced by `icons` | ||
11 | featured = false; | 10 | featured = false; |
12 | 11 | ||
12 | aliases = []; | ||
13 | |||
13 | constructor(data) { | 14 | constructor(data) { |
14 | if (!data.id) { | 15 | if (!data.id) { |
15 | throw Error('RecipePreview requires Id'); | 16 | throw Error('RecipePreview requires Id'); |
diff --git a/src/models/Service.js b/src/models/Service.js index 5656295da..fe56e5a76 100644 --- a/src/models/Service.js +++ b/src/models/Service.js | |||
@@ -2,7 +2,7 @@ import { autorun, computed, observable } from 'mobx'; | |||
2 | import { ipcRenderer } from 'electron'; | 2 | import { ipcRenderer } from 'electron'; |
3 | import { webContents } from '@electron/remote'; | 3 | import { webContents } from '@electron/remote'; |
4 | import normalizeUrl from 'normalize-url'; | 4 | import normalizeUrl from 'normalize-url'; |
5 | import path from 'path'; | 5 | import { join } from 'path'; |
6 | 6 | ||
7 | import { todosStore } from '../features/todos'; | 7 | import { todosStore } from '../features/todos'; |
8 | import { isValidExternalURL } from '../helpers/url-helpers'; | 8 | import { isValidExternalURL } from '../helpers/url-helpers'; |
@@ -10,11 +10,6 @@ import UserAgent from './UserAgent'; | |||
10 | 10 | ||
11 | const debug = require('debug')('Ferdi:Service'); | 11 | const debug = require('debug')('Ferdi:Service'); |
12 | 12 | ||
13 | export const RESTRICTION_TYPES = { | ||
14 | SERVICE_LIMIT: 0, | ||
15 | CUSTOM_URL: 1, | ||
16 | }; | ||
17 | |||
18 | export default class Service { | 13 | export default class Service { |
19 | id = ''; | 14 | id = ''; |
20 | 15 | ||
@@ -42,8 +37,6 @@ export default class Service { | |||
42 | 37 | ||
43 | @observable isMuted = false; | 38 | @observable isMuted = false; |
44 | 39 | ||
45 | @observable isHibernating = false; | ||
46 | |||
47 | @observable team = ''; | 40 | @observable team = ''; |
48 | 41 | ||
49 | @observable customUrl = ''; | 42 | @observable customUrl = ''; |
@@ -82,10 +75,12 @@ export default class Service { | |||
82 | 75 | ||
83 | @observable isHibernationEnabled = false; | 76 | @observable isHibernationEnabled = false; |
84 | 77 | ||
85 | @observable isHibernating = false; | 78 | @observable isHibernationRequested = false; |
86 | 79 | ||
87 | @observable lastUsed = Date.now(); // timestamp | 80 | @observable lastUsed = Date.now(); // timestamp |
88 | 81 | ||
82 | @observable lastHibernated = null; // timestamp | ||
83 | |||
89 | @observable lastPoll = Date.now(); | 84 | @observable lastPoll = Date.now(); |
90 | 85 | ||
91 | @observable lastPollAnswer = Date.now(); | 86 | @observable lastPollAnswer = Date.now(); |
@@ -150,14 +145,11 @@ export default class Service { | |||
150 | this.recipe = recipe; | 145 | this.recipe = recipe; |
151 | 146 | ||
152 | // Check if "Hibernate on Startup" is enabled and hibernate all services except active one | 147 | // Check if "Hibernate on Startup" is enabled and hibernate all services except active one |
153 | const { | 148 | const { hibernateOnStartup } = window.ferdi.stores.settings.app; |
154 | hibernate, | ||
155 | hibernateOnStartup, | ||
156 | } = window.ferdi.stores.settings.app; | ||
157 | // The service store is probably not loaded yet so we need to use localStorage data to get active service | 149 | // The service store is probably not loaded yet so we need to use localStorage data to get active service |
158 | const isActive = window.localStorage.service && JSON.parse(window.localStorage.service).activeService === this.id; | 150 | const isActive = window.localStorage.service && JSON.parse(window.localStorage.service).activeService === this.id; |
159 | if (hibernate && hibernateOnStartup && !isActive) { | 151 | if (hibernateOnStartup && !isActive) { |
160 | this.isHibernating = true; | 152 | this.isHibernationRequested = true; |
161 | } | 153 | } |
162 | 154 | ||
163 | autorun(() => { | 155 | autorun(() => { |
@@ -190,6 +182,14 @@ export default class Service { | |||
190 | return this.recipe.id === todosStore.todoRecipeId; | 182 | return this.recipe.id === todosStore.todoRecipeId; |
191 | } | 183 | } |
192 | 184 | ||
185 | @computed get canHibernate() { | ||
186 | return this.isHibernationEnabled; | ||
187 | } | ||
188 | |||
189 | @computed get isHibernating() { | ||
190 | return this.canHibernate && this.isHibernationRequested; | ||
191 | } | ||
192 | |||
193 | get webview() { | 193 | get webview() { |
194 | if (this.isTodosService) { | 194 | if (this.isTodosService) { |
195 | return todosStore.webview; | 195 | return todosStore.webview; |
@@ -230,7 +230,7 @@ export default class Service { | |||
230 | return this.iconUrl; | 230 | return this.iconUrl; |
231 | } | 231 | } |
232 | 232 | ||
233 | return path.join(this.recipe.path, 'icon.svg'); | 233 | return join(this.recipe.path, 'icon.svg'); |
234 | } | 234 | } |
235 | 235 | ||
236 | @computed get hasCustomIcon() { | 236 | @computed get hasCustomIcon() { |
@@ -275,11 +275,17 @@ export default class Service { | |||
275 | debug(this.name, 'modifyRequestHeaders is not defined in the recipe'); | 275 | debug(this.name, 'modifyRequestHeaders is not defined in the recipe'); |
276 | } | 276 | } |
277 | 277 | ||
278 | this.webview.addEventListener('ipc-message', e => handleIPCMessage({ | 278 | this.webview.addEventListener('ipc-message', async (e) => { |
279 | serviceId: this.id, | 279 | if (e.channel === 'inject-js-unsafe') { |
280 | channel: e.channel, | 280 | await Promise.all(e.args.map((script) => this.webview.executeJavaScript(`"use strict"; (() => { ${script} })();`))); |
281 | args: e.args, | 281 | } else { |
282 | })); | 282 | handleIPCMessage({ |
283 | serviceId: this.id, | ||
284 | channel: e.channel, | ||
285 | args: e.args, | ||
286 | }); | ||
287 | } | ||
288 | }); | ||
283 | 289 | ||
284 | this.webview.addEventListener('new-window', (event, url, frameName, options) => { | 290 | this.webview.addEventListener('new-window', (event, url, frameName, options) => { |
285 | debug('new-window', event, url, frameName, options); | 291 | debug('new-window', event, url, frameName, options); |
@@ -334,6 +340,11 @@ export default class Service { | |||
334 | this.hasCrashed = true; | 340 | this.hasCrashed = true; |
335 | }); | 341 | }); |
336 | 342 | ||
343 | this.webview.addEventListener('found-in-page', ({ result }) => { | ||
344 | debug('Found in page', result); | ||
345 | this.webview.send('found-in-page', result); | ||
346 | }); | ||
347 | |||
337 | webviewWebContents.on('login', (event, request, authInfo, callback) => { | 348 | webviewWebContents.on('login', (event, request, authInfo, callback) => { |
338 | // const authCallback = callback; | 349 | // const authCallback = callback; |
339 | debug('browser login event', authInfo); | 350 | debug('browser login event', authInfo); |
diff --git a/src/models/User.js b/src/models/User.js index 74a39926b..d864dde0c 100644 --- a/src/models/User.js +++ b/src/models/User.js | |||
@@ -24,8 +24,6 @@ export default class User { | |||
24 | 24 | ||
25 | @observable hadSubscription = false; | 25 | @observable hadSubscription = false; |
26 | 26 | ||
27 | @observable isPremium = true; | ||
28 | |||
29 | @observable beta = false; | 27 | @observable beta = false; |
30 | 28 | ||
31 | @observable donor = {}; | 29 | @observable donor = {}; |
@@ -49,7 +47,6 @@ export default class User { | |||
49 | this.lastname = data.lastname || this.lastname; | 47 | this.lastname = data.lastname || this.lastname; |
50 | this.organization = data.organization || this.organization; | 48 | this.organization = data.organization || this.organization; |
51 | this.accountType = data.accountType || this.accountType; | 49 | this.accountType = data.accountType || this.accountType; |
52 | this.isPremium = true; | ||
53 | this.beta = data.beta || this.beta; | 50 | this.beta = data.beta || this.beta; |
54 | this.donor = data.donor || this.donor; | 51 | this.donor = data.donor || this.donor; |
55 | this.isDonor = data.isDonor || this.isDonor; | 52 | this.isDonor = data.isDonor || this.isDonor; |
diff --git a/src/models/UserAgent.js b/src/models/UserAgent.js index 6f91d4ed0..930ae19ef 100644 --- a/src/models/UserAgent.js +++ b/src/models/UserAgent.js | |||
@@ -95,10 +95,10 @@ export default class UserAgent { | |||
95 | _addWebviewEvents(webview) { | 95 | _addWebviewEvents(webview) { |
96 | debug('Adding event handlers'); | 96 | debug('Adding event handlers'); |
97 | 97 | ||
98 | this._willNavigateListener = event => this._handleNavigate(event.url, true); | 98 | this._willNavigateListener = (event) => this._handleNavigate(event.url, true); |
99 | webview.addEventListener('will-navigate', this._willNavigateListener); | 99 | webview.addEventListener('will-navigate', this._willNavigateListener); |
100 | 100 | ||
101 | this._didNavigateListener = event => this._handleNavigate(event.url); | 101 | this._didNavigateListener = (event) => this._handleNavigate(event.url); |
102 | webview.addEventListener('did-navigate', this._didNavigateListener); | 102 | webview.addEventListener('did-navigate', this._didNavigateListener); |
103 | } | 103 | } |
104 | 104 | ||