From 070a441fafc173dc286a884739da536903452736 Mon Sep 17 00:00:00 2001 From: Ricardo Cino Date: Sun, 26 Jun 2022 14:24:06 +0200 Subject: fix: solve recipe function calls that were broken cause of js=>ts con… (#369) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- src/models/Recipe.ts | 93 +++++++++++++++++++++++++++++++-------------------- src/models/Service.ts | 11 +++--- 2 files changed, 62 insertions(+), 42 deletions(-) (limited to 'src') 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'; import { DEFAULT_SERVICE_SETTINGS } from '../config'; import { ifUndefined } from '../jsUtils'; -interface IRecipe { +interface RecipeData { id: string; name: string; version: string; @@ -29,67 +29,86 @@ interface IRecipe { }; } -export default class Recipe { - id: string = ''; +export interface IRecipe { + id: string; + name: string; + description: string; + version: string; + aliases: string[]; + serviceURL: string; + hasDirectMessages: boolean; + hasIndirectMessages: boolean; + hasNotificationSound: boolean; + hasTeamId: boolean; + hasCustomUrl: boolean; + hasHostedOption: boolean; + urlInputPrefix: string; + urlInputSuffix: string; + message: string; + allowFavoritesDelineationInUnreadCount: boolean; + disablewebsecurity: boolean; + autoHibernate: boolean; + path: string; + partition: string; + local: boolean; + + readonly overrideUserAgent?: null | Function; + readonly buildUrl?: null | Function; + readonly modifyRequestHeaders?: null | Function; + readonly knownCertificateHosts?: null | Function; + readonly events?: null | { (key: string): string }; +} + +export default class Recipe implements IRecipe { + id = ''; - name: string = ''; + name = ''; - description: string = ''; + description = ''; - version: string = ''; + version = ''; + // Removing this specific type will cause a typescript error + // even while it's the exact same as the interface aliases: string[] = []; - serviceURL: string = ''; + serviceURL = ''; - hasDirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasDirectMessages; + hasDirectMessages = DEFAULT_SERVICE_SETTINGS.hasDirectMessages; - hasIndirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasIndirectMessages; + hasIndirectMessages = DEFAULT_SERVICE_SETTINGS.hasIndirectMessages; - hasNotificationSound: boolean = DEFAULT_SERVICE_SETTINGS.hasNotificationSound; + hasNotificationSound = DEFAULT_SERVICE_SETTINGS.hasNotificationSound; - hasTeamId: boolean = DEFAULT_SERVICE_SETTINGS.hasTeamId; + hasTeamId = DEFAULT_SERVICE_SETTINGS.hasTeamId; - hasCustomUrl: boolean = DEFAULT_SERVICE_SETTINGS.hasCustomUrl; + hasCustomUrl = DEFAULT_SERVICE_SETTINGS.hasCustomUrl; - hasHostedOption: boolean = DEFAULT_SERVICE_SETTINGS.hasHostedOption; + hasHostedOption = DEFAULT_SERVICE_SETTINGS.hasHostedOption; - urlInputPrefix: string = ''; + urlInputPrefix = ''; - urlInputSuffix: string = ''; + urlInputSuffix = ''; - message: string = ''; + message = ''; - allowFavoritesDelineationInUnreadCount: boolean = + allowFavoritesDelineationInUnreadCount = DEFAULT_SERVICE_SETTINGS.allowFavoritesDelineationInUnreadCount; - disablewebsecurity: boolean = DEFAULT_SERVICE_SETTINGS.disablewebsecurity; + disablewebsecurity = DEFAULT_SERVICE_SETTINGS.disablewebsecurity; // TODO: Is this even used? - autoHibernate: boolean = DEFAULT_SERVICE_SETTINGS.autoHibernate; + autoHibernate = DEFAULT_SERVICE_SETTINGS.autoHibernate; - path: string = ''; + path = ''; - partition: string = ''; + partition = ''; // TODO: Is this being used? - local: boolean = false; - - // TODO Add types for this once we know if they are neccesary to pass - // on to the initialize-recipe ipc event. - overrideUserAgent: any; - - buildUrl: any; - - modifyRequestHeaders: any; - - knownCertificateHosts: any; - - events: any; - // End todo. + local = false; // TODO: Need to reconcile which of these are optional/mandatory - constructor(data: IRecipe) { + constructor(data: RecipeData) { if (!data) { throw new Error('Recipe config not valid'); } @@ -109,7 +128,7 @@ export default class Recipe { this.id = ifUndefined(data.id, this.id); this.name = ifUndefined(data.name, this.name); this.version = ifUndefined(data.version, this.version); - this.aliases = data.aliases || this.aliases; + this.aliases = ifUndefined>(data.aliases, this.aliases); this.serviceURL = ifUndefined( data.config.serviceURL, 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'; import UserAgent from './UserAgent'; import { DEFAULT_SERVICE_ORDER } from '../config'; import { ifUndefined } from '../jsUtils'; -import Recipe from './Recipe'; +import { IRecipe } from './Recipe'; const debug = require('../preload-safe-debug')('Ferdium:Service'); @@ -18,7 +18,7 @@ const debug = require('../preload-safe-debug')('Ferdium:Service'); export default class Service { id: string = ''; - recipe: Recipe; + recipe: IRecipe; _webview: ElectronWebView | null = null; @@ -117,7 +117,7 @@ export default class Service { @observable proxy: string | null = null; - constructor(data, recipe: Recipe) { + constructor(data, recipe: IRecipe) { if (!data) { throw new Error('Service config not valid'); } @@ -270,8 +270,9 @@ export default class Service { ); } - if (typeof this.recipe.buildUrl === 'function') { - url = this.recipe.buildUrl(url); + const { buildUrl } = this.recipe; + if (typeof buildUrl === 'function') { + url = buildUrl(url); } return url; -- cgit v1.2.3-54-g00ecf