diff options
author | Ricardo Cino <ricardo@cino.io> | 2022-06-26 14:24:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-26 14:24:06 +0200 |
commit | 070a441fafc173dc286a884739da536903452736 (patch) | |
tree | 5c4aec94cfd36c01f57746bf48f7593be45bdef1 /src | |
parent | 6.0.0-nightly.78 [skip ci] (diff) | |
download | ferdium-app-070a441fafc173dc286a884739da536903452736.tar.gz ferdium-app-070a441fafc173dc286a884739da536903452736.tar.zst ferdium-app-070a441fafc173dc286a884739da536903452736.zip |
fix: solve recipe function calls that were broken cause of js=>ts con… (#369)
* fix: solve recipe function calls that were broken cause of js=>ts conversion
* fix: use an interface instead to keep type-safety
* fix: remove faulty test
Diffstat (limited to 'src')
-rw-r--r-- | src/models/Recipe.ts | 93 | ||||
-rw-r--r-- | src/models/Service.ts | 11 |
2 files changed, 62 insertions, 42 deletions
diff --git a/src/models/Recipe.ts b/src/models/Recipe.ts index eb8b0b1ff..a171a288a 100644 --- a/src/models/Recipe.ts +++ b/src/models/Recipe.ts | |||
@@ -4,7 +4,7 @@ import { join } from 'path'; | |||
4 | import { DEFAULT_SERVICE_SETTINGS } from '../config'; | 4 | import { DEFAULT_SERVICE_SETTINGS } from '../config'; |
5 | import { ifUndefined } from '../jsUtils'; | 5 | import { ifUndefined } from '../jsUtils'; |
6 | 6 | ||
7 | interface IRecipe { | 7 | interface RecipeData { |
8 | id: string; | 8 | id: string; |
9 | name: string; | 9 | name: string; |
10 | version: string; | 10 | version: string; |
@@ -29,67 +29,86 @@ interface IRecipe { | |||
29 | }; | 29 | }; |
30 | } | 30 | } |
31 | 31 | ||
32 | export default class Recipe { | 32 | export interface IRecipe { |
33 | id: string = ''; | 33 | id: string; |
34 | name: string; | ||
35 | description: string; | ||
36 | version: string; | ||
37 | aliases: string[]; | ||
38 | serviceURL: string; | ||
39 | hasDirectMessages: boolean; | ||
40 | hasIndirectMessages: boolean; | ||
41 | hasNotificationSound: boolean; | ||
42 | hasTeamId: boolean; | ||
43 | hasCustomUrl: boolean; | ||
44 | hasHostedOption: boolean; | ||
45 | urlInputPrefix: string; | ||
46 | urlInputSuffix: string; | ||
47 | message: string; | ||
48 | allowFavoritesDelineationInUnreadCount: boolean; | ||
49 | disablewebsecurity: boolean; | ||
50 | autoHibernate: boolean; | ||
51 | path: string; | ||
52 | partition: string; | ||
53 | local: boolean; | ||
54 | |||
55 | readonly overrideUserAgent?: null | Function; | ||
56 | readonly buildUrl?: null | Function; | ||
57 | readonly modifyRequestHeaders?: null | Function; | ||
58 | readonly knownCertificateHosts?: null | Function; | ||
59 | readonly events?: null | { (key: string): string }; | ||
60 | } | ||
61 | |||
62 | export default class Recipe implements IRecipe { | ||
63 | id = ''; | ||
34 | 64 | ||
35 | name: string = ''; | 65 | name = ''; |
36 | 66 | ||
37 | description: string = ''; | 67 | description = ''; |
38 | 68 | ||
39 | version: string = ''; | 69 | version = ''; |
40 | 70 | ||
71 | // Removing this specific type will cause a typescript error | ||
72 | // even while it's the exact same as the interface | ||
41 | aliases: string[] = []; | 73 | aliases: string[] = []; |
42 | 74 | ||
43 | serviceURL: string = ''; | 75 | serviceURL = ''; |
44 | 76 | ||
45 | hasDirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasDirectMessages; | 77 | hasDirectMessages = DEFAULT_SERVICE_SETTINGS.hasDirectMessages; |
46 | 78 | ||
47 | hasIndirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasIndirectMessages; | 79 | hasIndirectMessages = DEFAULT_SERVICE_SETTINGS.hasIndirectMessages; |
48 | 80 | ||
49 | hasNotificationSound: boolean = DEFAULT_SERVICE_SETTINGS.hasNotificationSound; | 81 | hasNotificationSound = DEFAULT_SERVICE_SETTINGS.hasNotificationSound; |
50 | 82 | ||
51 | hasTeamId: boolean = DEFAULT_SERVICE_SETTINGS.hasTeamId; | 83 | hasTeamId = DEFAULT_SERVICE_SETTINGS.hasTeamId; |
52 | 84 | ||
53 | hasCustomUrl: boolean = DEFAULT_SERVICE_SETTINGS.hasCustomUrl; | 85 | hasCustomUrl = DEFAULT_SERVICE_SETTINGS.hasCustomUrl; |
54 | 86 | ||
55 | hasHostedOption: boolean = DEFAULT_SERVICE_SETTINGS.hasHostedOption; | 87 | hasHostedOption = DEFAULT_SERVICE_SETTINGS.hasHostedOption; |
56 | 88 | ||
57 | urlInputPrefix: string = ''; | 89 | urlInputPrefix = ''; |
58 | 90 | ||
59 | urlInputSuffix: string = ''; | 91 | urlInputSuffix = ''; |
60 | 92 | ||
61 | message: string = ''; | 93 | message = ''; |
62 | 94 | ||
63 | allowFavoritesDelineationInUnreadCount: boolean = | 95 | allowFavoritesDelineationInUnreadCount = |
64 | DEFAULT_SERVICE_SETTINGS.allowFavoritesDelineationInUnreadCount; | 96 | DEFAULT_SERVICE_SETTINGS.allowFavoritesDelineationInUnreadCount; |
65 | 97 | ||
66 | disablewebsecurity: boolean = DEFAULT_SERVICE_SETTINGS.disablewebsecurity; | 98 | disablewebsecurity = DEFAULT_SERVICE_SETTINGS.disablewebsecurity; |
67 | 99 | ||
68 | // TODO: Is this even used? | 100 | // TODO: Is this even used? |
69 | autoHibernate: boolean = DEFAULT_SERVICE_SETTINGS.autoHibernate; | 101 | autoHibernate = DEFAULT_SERVICE_SETTINGS.autoHibernate; |
70 | 102 | ||
71 | path: string = ''; | 103 | path = ''; |
72 | 104 | ||
73 | partition: string = ''; | 105 | partition = ''; |
74 | 106 | ||
75 | // TODO: Is this being used? | 107 | // TODO: Is this being used? |
76 | local: boolean = false; | 108 | local = false; |
77 | |||
78 | // TODO Add types for this once we know if they are neccesary to pass | ||
79 | // on to the initialize-recipe ipc event. | ||
80 | overrideUserAgent: any; | ||
81 | |||
82 | buildUrl: any; | ||
83 | |||
84 | modifyRequestHeaders: any; | ||
85 | |||
86 | knownCertificateHosts: any; | ||
87 | |||
88 | events: any; | ||
89 | // End todo. | ||
90 | 109 | ||
91 | // TODO: Need to reconcile which of these are optional/mandatory | 110 | // TODO: Need to reconcile which of these are optional/mandatory |
92 | constructor(data: IRecipe) { | 111 | constructor(data: RecipeData) { |
93 | if (!data) { | 112 | if (!data) { |
94 | throw new Error('Recipe config not valid'); | 113 | throw new Error('Recipe config not valid'); |
95 | } | 114 | } |
@@ -109,7 +128,7 @@ export default class Recipe { | |||
109 | this.id = ifUndefined<string>(data.id, this.id); | 128 | this.id = ifUndefined<string>(data.id, this.id); |
110 | this.name = ifUndefined<string>(data.name, this.name); | 129 | this.name = ifUndefined<string>(data.name, this.name); |
111 | this.version = ifUndefined<string>(data.version, this.version); | 130 | this.version = ifUndefined<string>(data.version, this.version); |
112 | this.aliases = data.aliases || this.aliases; | 131 | this.aliases = ifUndefined<Array<string>>(data.aliases, this.aliases); |
113 | this.serviceURL = ifUndefined<string>( | 132 | this.serviceURL = ifUndefined<string>( |
114 | data.config.serviceURL, | 133 | data.config.serviceURL, |
115 | this.serviceURL, | 134 | this.serviceURL, |
diff --git a/src/models/Service.ts b/src/models/Service.ts index c4165e59a..dfc074204 100644 --- a/src/models/Service.ts +++ b/src/models/Service.ts | |||
@@ -10,7 +10,7 @@ import { isValidExternalURL } from '../helpers/url-helpers'; | |||
10 | import UserAgent from './UserAgent'; | 10 | import UserAgent from './UserAgent'; |
11 | import { DEFAULT_SERVICE_ORDER } from '../config'; | 11 | import { DEFAULT_SERVICE_ORDER } from '../config'; |
12 | import { ifUndefined } from '../jsUtils'; | 12 | import { ifUndefined } from '../jsUtils'; |
13 | import Recipe from './Recipe'; | 13 | import { IRecipe } from './Recipe'; |
14 | 14 | ||
15 | const debug = require('../preload-safe-debug')('Ferdium:Service'); | 15 | const debug = require('../preload-safe-debug')('Ferdium:Service'); |
16 | 16 | ||
@@ -18,7 +18,7 @@ const debug = require('../preload-safe-debug')('Ferdium:Service'); | |||
18 | export default class Service { | 18 | export default class Service { |
19 | id: string = ''; | 19 | id: string = ''; |
20 | 20 | ||
21 | recipe: Recipe; | 21 | recipe: IRecipe; |
22 | 22 | ||
23 | _webview: ElectronWebView | null = null; | 23 | _webview: ElectronWebView | null = null; |
24 | 24 | ||
@@ -117,7 +117,7 @@ export default class Service { | |||
117 | 117 | ||
118 | @observable proxy: string | null = null; | 118 | @observable proxy: string | null = null; |
119 | 119 | ||
120 | constructor(data, recipe: Recipe) { | 120 | constructor(data, recipe: IRecipe) { |
121 | if (!data) { | 121 | if (!data) { |
122 | throw new Error('Service config not valid'); | 122 | throw new Error('Service config not valid'); |
123 | } | 123 | } |
@@ -270,8 +270,9 @@ export default class Service { | |||
270 | ); | 270 | ); |
271 | } | 271 | } |
272 | 272 | ||
273 | if (typeof this.recipe.buildUrl === 'function') { | 273 | const { buildUrl } = this.recipe; |
274 | url = this.recipe.buildUrl(url); | 274 | if (typeof buildUrl === 'function') { |
275 | url = buildUrl(url); | ||
275 | } | 276 | } |
276 | 277 | ||
277 | return url; | 278 | return url; |