From bfe8847d72cd0893230f2e654242658214943e61 Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Sat, 2 Oct 2021 09:24:32 +0200 Subject: chore: convert various files from JS to TS (#2010) --- src/api/AppApi.js | 9 ---- src/api/AppApi.ts | 11 ++++ src/api/FeaturesApi.js | 13 ----- src/api/FeaturesApi.ts | 15 ++++++ src/api/LocalApi.js | 22 -------- src/api/LocalApi.ts | 26 +++++++++ src/api/NewsApi.js | 14 ----- src/api/NewsApi.ts | 18 +++++++ src/api/RecipePreviewsApi.js | 17 ------ src/api/RecipePreviewsApi.ts | 19 +++++++ src/api/RecipesApi.js | 17 ------ src/api/RecipesApi.ts | 19 +++++++ src/api/ServicesApi.js | 30 ----------- src/api/ServicesApi.ts | 34 ++++++++++++ src/api/UserApi.js | 53 ------------------ src/api/UserApi.ts | 58 ++++++++++++++++++++ src/api/index.js | 19 ------- src/api/index.ts | 19 +++++++ src/api/utils/auth.js | 32 ----------- src/api/utils/auth.ts | 38 +++++++++++++ .../settings/services/EditServiceForm.js | 17 +++--- src/components/ui/Tabs/TabItem.js | 15 ------ src/components/ui/Tabs/TabItem.tsx | 3 ++ src/components/ui/Tabs/index.js | 6 --- src/features/basicAuth/Form.ts | 1 + src/features/communityRecipes/store.js | 32 ----------- src/features/communityRecipes/store.ts | 39 ++++++++++++++ src/features/nightlyBuilds/store.js | 7 --- src/features/nightlyBuilds/store.ts | 7 +++ src/features/publishDebugInfo/store.js | 7 --- src/features/publishDebugInfo/store.ts | 7 +++ src/features/quickSwitch/store.js | 7 --- src/features/quickSwitch/store.ts | 7 +++ src/features/serviceProxy/index.js | 38 ------------- src/features/serviceProxy/index.ts | 54 +++++++++++++++++++ src/features/settingsWS/actions.js | 10 ---- src/features/settingsWS/actions.ts | 10 ++++ src/features/settingsWS/index.js | 27 ---------- src/features/settingsWS/index.ts | 28 ++++++++++ src/features/settingsWS/state.js | 13 ----- src/features/settingsWS/state.ts | 13 +++++ src/features/todos/actions.js | 28 ---------- src/features/todos/actions.ts | 31 +++++++++++ src/features/todos/constants.js | 8 --- src/features/todos/constants.ts | 8 +++ src/features/todos/index.js | 28 ---------- src/features/todos/index.ts | 29 ++++++++++ src/lib/DBus.js | 45 ---------------- src/lib/DBus.ts | 55 +++++++++++++++++++ src/lib/Form.js | 32 ----------- src/lib/Form.ts | 32 +++++++++++ src/lib/TouchBar.js | 49 ----------------- src/lib/TouchBar.ts | 62 ++++++++++++++++++++++ 53 files changed, 651 insertions(+), 587 deletions(-) delete mode 100644 src/api/AppApi.js create mode 100644 src/api/AppApi.ts delete mode 100644 src/api/FeaturesApi.js create mode 100644 src/api/FeaturesApi.ts delete mode 100644 src/api/LocalApi.js create mode 100644 src/api/LocalApi.ts delete mode 100644 src/api/NewsApi.js create mode 100644 src/api/NewsApi.ts delete mode 100644 src/api/RecipePreviewsApi.js create mode 100644 src/api/RecipePreviewsApi.ts delete mode 100644 src/api/RecipesApi.js create mode 100644 src/api/RecipesApi.ts delete mode 100644 src/api/ServicesApi.js create mode 100644 src/api/ServicesApi.ts delete mode 100644 src/api/UserApi.js create mode 100644 src/api/UserApi.ts delete mode 100644 src/api/index.js create mode 100644 src/api/index.ts delete mode 100644 src/api/utils/auth.js create mode 100644 src/api/utils/auth.ts delete mode 100644 src/components/ui/Tabs/TabItem.js create mode 100644 src/components/ui/Tabs/TabItem.tsx delete mode 100644 src/components/ui/Tabs/index.js delete mode 100644 src/features/communityRecipes/store.js create mode 100644 src/features/communityRecipes/store.ts delete mode 100644 src/features/nightlyBuilds/store.js create mode 100644 src/features/nightlyBuilds/store.ts delete mode 100644 src/features/publishDebugInfo/store.js create mode 100644 src/features/publishDebugInfo/store.ts delete mode 100644 src/features/quickSwitch/store.js create mode 100644 src/features/quickSwitch/store.ts delete mode 100644 src/features/serviceProxy/index.js create mode 100644 src/features/serviceProxy/index.ts delete mode 100755 src/features/settingsWS/actions.js create mode 100755 src/features/settingsWS/actions.ts delete mode 100755 src/features/settingsWS/index.js create mode 100755 src/features/settingsWS/index.ts delete mode 100755 src/features/settingsWS/state.js create mode 100755 src/features/settingsWS/state.ts delete mode 100644 src/features/todos/actions.js create mode 100644 src/features/todos/actions.ts delete mode 100644 src/features/todos/constants.js create mode 100644 src/features/todos/constants.ts delete mode 100644 src/features/todos/index.js create mode 100644 src/features/todos/index.ts delete mode 100644 src/lib/DBus.js create mode 100644 src/lib/DBus.ts delete mode 100644 src/lib/Form.js create mode 100644 src/lib/Form.ts delete mode 100644 src/lib/TouchBar.js create mode 100644 src/lib/TouchBar.ts (limited to 'src') diff --git a/src/api/AppApi.js b/src/api/AppApi.js deleted file mode 100644 index 411c187f4..000000000 --- a/src/api/AppApi.js +++ /dev/null @@ -1,9 +0,0 @@ -export default class AppApi { - constructor(server) { - this.server = server; - } - - health() { - return this.server.healthCheck(); - } -} diff --git a/src/api/AppApi.ts b/src/api/AppApi.ts new file mode 100644 index 000000000..6e5e5c806 --- /dev/null +++ b/src/api/AppApi.ts @@ -0,0 +1,11 @@ +export default class AppApi { + server: any; + + constructor(server: any) { + this.server = server; + } + + health() { + return this.server.healthCheck(); + } +} diff --git a/src/api/FeaturesApi.js b/src/api/FeaturesApi.js deleted file mode 100644 index c66f28f5b..000000000 --- a/src/api/FeaturesApi.js +++ /dev/null @@ -1,13 +0,0 @@ -export default class FeaturesApi { - constructor(server) { - this.server = server; - } - - default() { - return this.server.getDefaultFeatures(); - } - - features() { - return this.server.getFeatures(); - } -} diff --git a/src/api/FeaturesApi.ts b/src/api/FeaturesApi.ts new file mode 100644 index 000000000..ccad4a189 --- /dev/null +++ b/src/api/FeaturesApi.ts @@ -0,0 +1,15 @@ +export default class FeaturesApi { + server: any; + + constructor(server: any) { + this.server = server; + } + + default() { + return this.server.getDefaultFeatures(); + } + + features() { + return this.server.getFeatures(); + } +} diff --git a/src/api/LocalApi.js b/src/api/LocalApi.js deleted file mode 100644 index ccdedd3f5..000000000 --- a/src/api/LocalApi.js +++ /dev/null @@ -1,22 +0,0 @@ -export default class LocalApi { - constructor(server, local) { - this.server = server; - this.local = local; - } - - getAppSettings(type) { - return this.local.getAppSettings(type); - } - - updateAppSettings(type, data) { - return this.local.updateAppSettings(type, data); - } - - getAppCacheSize() { - return this.local.getAppCacheSize(); - } - - clearCache() { - return this.local.clearCache(); - } -} diff --git a/src/api/LocalApi.ts b/src/api/LocalApi.ts new file mode 100644 index 000000000..0140a5450 --- /dev/null +++ b/src/api/LocalApi.ts @@ -0,0 +1,26 @@ +export default class LocalApi { + server: any; + + local: any; + + constructor(server: any, local: any) { + this.server = server; + this.local = local; + } + + getAppSettings(type: any) { + return this.local.getAppSettings(type); + } + + updateAppSettings(type: any, data: any) { + return this.local.updateAppSettings(type, data); + } + + getAppCacheSize() { + return this.local.getAppCacheSize(); + } + + clearCache() { + return this.local.clearCache(); + } +} diff --git a/src/api/NewsApi.js b/src/api/NewsApi.js deleted file mode 100644 index 294957511..000000000 --- a/src/api/NewsApi.js +++ /dev/null @@ -1,14 +0,0 @@ -export default class NewsApi { - constructor(server, local) { - this.server = server; - this.local = local; - } - - latest() { - return this.server.getLatestNews(); - } - - hide(id) { - return this.server.hideNews(id); - } -} diff --git a/src/api/NewsApi.ts b/src/api/NewsApi.ts new file mode 100644 index 000000000..31d3d903b --- /dev/null +++ b/src/api/NewsApi.ts @@ -0,0 +1,18 @@ +export default class NewsApi { + server: any; + + local: any; + + constructor(server: any, local: any) { + this.server = server; + this.local = local; + } + + latest() { + return this.server.getLatestNews(); + } + + hide(id: any) { + return this.server.hideNews(id); + } +} diff --git a/src/api/RecipePreviewsApi.js b/src/api/RecipePreviewsApi.js deleted file mode 100644 index a56fa587f..000000000 --- a/src/api/RecipePreviewsApi.js +++ /dev/null @@ -1,17 +0,0 @@ -export default class RecipePreviewsApi { - constructor(server) { - this.server = server; - } - - all() { - return this.server.getRecipePreviews(); - } - - featured() { - return this.server.getFeaturedRecipePreviews(); - } - - search(needle) { - return this.server.searchRecipePreviews(needle); - } -} diff --git a/src/api/RecipePreviewsApi.ts b/src/api/RecipePreviewsApi.ts new file mode 100644 index 000000000..78f2a9596 --- /dev/null +++ b/src/api/RecipePreviewsApi.ts @@ -0,0 +1,19 @@ +export default class RecipePreviewsApi { + server: any; + + constructor(server: any) { + this.server = server; + } + + all() { + return this.server.getRecipePreviews(); + } + + featured() { + return this.server.getFeaturedRecipePreviews(); + } + + search(needle: string) { + return this.server.searchRecipePreviews(needle); + } +} diff --git a/src/api/RecipesApi.js b/src/api/RecipesApi.js deleted file mode 100644 index 800888b00..000000000 --- a/src/api/RecipesApi.js +++ /dev/null @@ -1,17 +0,0 @@ -export default class RecipesApi { - constructor(server) { - this.server = server; - } - - all() { - return this.server.getInstalledRecipes(); - } - - install(recipeId) { - return this.server.getRecipePackage(recipeId); - } - - update(recipes) { - return this.server.getRecipeUpdates(recipes); - } -} diff --git a/src/api/RecipesApi.ts b/src/api/RecipesApi.ts new file mode 100644 index 000000000..11d2241b5 --- /dev/null +++ b/src/api/RecipesApi.ts @@ -0,0 +1,19 @@ +export default class RecipesApi { + server: any; + + constructor(server: any) { + this.server = server; + } + + all() { + return this.server.getInstalledRecipes(); + } + + install(recipeId: string) { + return this.server.getRecipePackage(recipeId); + } + + update(recipes: any) { + return this.server.getRecipeUpdates(recipes); + } +} diff --git a/src/api/ServicesApi.js b/src/api/ServicesApi.js deleted file mode 100644 index 85efd26a6..000000000 --- a/src/api/ServicesApi.js +++ /dev/null @@ -1,30 +0,0 @@ -export default class ServicesApi { - constructor(server, local) { - this.local = local; - this.server = server; - } - - all() { - return this.server.getServices(); - } - - create(recipeId, data) { - return this.server.createService(recipeId, data); - } - - delete(serviceId) { - return this.server.deleteService(serviceId); - } - - update(serviceId, data) { - return this.server.updateService(serviceId, data); - } - - reorder(data) { - return this.server.reorderService(data); - } - - clearCache(serviceId) { - return this.local.clearCache(serviceId); - } -} diff --git a/src/api/ServicesApi.ts b/src/api/ServicesApi.ts new file mode 100644 index 000000000..5bd8aa60e --- /dev/null +++ b/src/api/ServicesApi.ts @@ -0,0 +1,34 @@ +export default class ServicesApi { + server: any; + + local: any; + + constructor(server: any, local: any) { + this.server = server; + this.local = local; + } + + all() { + return this.server.getServices(); + } + + create(recipeId: string, data: any) { + return this.server.createService(recipeId, data); + } + + delete(serviceId: string) { + return this.server.deleteService(serviceId); + } + + update(serviceId: string, data: any) { + return this.server.updateService(serviceId, data); + } + + reorder(data: any) { + return this.server.reorderService(data); + } + + clearCache(serviceId: string) { + return this.local.clearCache(serviceId); + } +} diff --git a/src/api/UserApi.js b/src/api/UserApi.js deleted file mode 100644 index edfb88988..000000000 --- a/src/api/UserApi.js +++ /dev/null @@ -1,53 +0,0 @@ -import { hash } from '../helpers/password-helpers'; - -export default class UserApi { - constructor(server, local) { - this.server = server; - this.local = local; - } - - login(email, password) { - return this.server.login(email, hash(password)); - } - - logout() { - return this; - } - - signup(data) { - Object.assign(data, { - password: hash(data.password), - }); - return this.server.signup(data); - } - - password(email) { - return this.server.retrievePassword(email); - } - - invite(data) { - return this.server.inviteUser(data); - } - - getInfo() { - return this.server.userInfo(); - } - - updateInfo(data) { - const userData = data; - if (userData.oldPassword && userData.newPassword) { - userData.oldPassword = hash(userData.oldPassword); - userData.newPassword = hash(userData.newPassword); - } - - return this.server.updateUserInfo(userData); - } - - getLegacyServices() { - return this.server.getLegacyServices(); - } - - delete() { - return this.server.deleteAccount(); - } -} diff --git a/src/api/UserApi.ts b/src/api/UserApi.ts new file mode 100644 index 000000000..31c8acead --- /dev/null +++ b/src/api/UserApi.ts @@ -0,0 +1,58 @@ +import { BinaryLike } from 'crypto'; +import { hash } from '../helpers/password-helpers'; + +export default class UserApi { + server: any; + + local: any; + + constructor(server: any, local: any) { + this.server = server; + this.local = local; + } + + login(email: string, password: BinaryLike) { + return this.server.login(email, hash(password)); + } + + logout() { + return this; + } + + signup(data: { password: BinaryLike }) { + Object.assign(data, { + password: hash(data.password), + }); + return this.server.signup(data); + } + + password(email: string) { + return this.server.retrievePassword(email); + } + + invite(data: any) { + return this.server.inviteUser(data); + } + + getInfo() { + return this.server.userInfo(); + } + + updateInfo(data: { oldPassword: string; newPassword: string }) { + const userData = data; + if (userData.oldPassword && userData.newPassword) { + userData.oldPassword = hash(userData.oldPassword); + userData.newPassword = hash(userData.newPassword); + } + + return this.server.updateUserInfo(userData); + } + + getLegacyServices() { + return this.server.getLegacyServices(); + } + + delete() { + return this.server.deleteAccount(); + } +} diff --git a/src/api/index.js b/src/api/index.js deleted file mode 100644 index ed6c13488..000000000 --- a/src/api/index.js +++ /dev/null @@ -1,19 +0,0 @@ -import AppApi from './AppApi'; -import ServicesApi from './ServicesApi'; -import RecipePreviewsApi from './RecipePreviewsApi'; -import RecipesApi from './RecipesApi'; -import UserApi from './UserApi'; -import LocalApi from './LocalApi'; -import NewsApi from './NewsApi'; -import FeaturesApi from './FeaturesApi'; - -export default (server, local) => ({ - app: new AppApi(server, local), - services: new ServicesApi(server, local), - recipePreviews: new RecipePreviewsApi(server, local), - recipes: new RecipesApi(server, local), - features: new FeaturesApi(server, local), - user: new UserApi(server, local), - local: new LocalApi(server, local), - news: new NewsApi(server, local), -}); diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 000000000..73f613da1 --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,19 @@ +import AppApi from './AppApi'; +import ServicesApi from './ServicesApi'; +import RecipePreviewsApi from './RecipePreviewsApi'; +import RecipesApi from './RecipesApi'; +import UserApi from './UserApi'; +import LocalApi from './LocalApi'; +import NewsApi from './NewsApi'; +import FeaturesApi from './FeaturesApi'; + +export default (server: any, local: any) => ({ + app: new AppApi(server), + services: new ServicesApi(server, local), + recipePreviews: new RecipePreviewsApi(server), + recipes: new RecipesApi(server), + features: new FeaturesApi(server), + user: new UserApi(server, local), + local: new LocalApi(server, local), + news: new NewsApi(server, local), +}); diff --git a/src/api/utils/auth.js b/src/api/utils/auth.js deleted file mode 100644 index 07b0c096b..000000000 --- a/src/api/utils/auth.js +++ /dev/null @@ -1,32 +0,0 @@ -import localStorage from 'mobx-localstorage'; -import { ferdiLocale, ferdiVersion } from '../../environment-remote'; - -export const prepareAuthRequest = ( - // eslint-disable-next-line unicorn/no-object-as-default-parameter - options = { method: 'GET' }, - auth = true, -) => { - const request = Object.assign(options, { - mode: 'cors', - headers: { - 'Content-Type': 'application/json', - 'X-Franz-Source': 'desktop', - 'X-Franz-Version': ferdiVersion, - 'X-Franz-platform': process.platform, - 'X-Franz-Timezone-Offset': new Date().getTimezoneOffset(), - 'X-Franz-System-Locale': ferdiLocale, - ...options.headers, - }, - }); - - if (auth) { - request.headers.Authorization = `Bearer ${localStorage.getItem( - 'authToken', - )}`; - } - - return request; -}; - -export const sendAuthRequest = (url, options, auth) => - window.fetch(url, prepareAuthRequest(options, auth)); diff --git a/src/api/utils/auth.ts b/src/api/utils/auth.ts new file mode 100644 index 000000000..98295d1a4 --- /dev/null +++ b/src/api/utils/auth.ts @@ -0,0 +1,38 @@ +import localStorage from 'mobx-localstorage'; +import { ferdiLocale, ferdiVersion } from '../../environment-remote'; + +export const prepareAuthRequest = ( + // eslint-disable-next-line unicorn/no-object-as-default-parameter + options = { method: 'GET' }, + auth = true, +) => { + const request = Object.assign(options, { + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + 'X-Franz-Source': 'desktop', + 'X-Franz-Version': ferdiVersion, + 'X-Franz-platform': process.platform, + 'X-Franz-Timezone-Offset': new Date().getTimezoneOffset(), + 'X-Franz-System-Locale': ferdiLocale, + // @ts-expect-error Property 'headers' does not exist on type '{ method: string; }'. + ...options.headers, + }, + }); + + if (auth) { + request.headers.Authorization = `Bearer ${localStorage.getItem( + 'authToken', + )}`; + } + + return request; +}; + +export const sendAuthRequest = ( + url: RequestInfo, + options: { method: string } | undefined, + auth?: boolean, +) => + // @ts-expect-error Argument of type '{ method: string; } & { mode: string; headers: any; }' is not assignable to parameter of type 'RequestInit | undefined'. + window.fetch(url, prepareAuthRequest(options, auth)); diff --git a/src/components/settings/services/EditServiceForm.js b/src/components/settings/services/EditServiceForm.js index 179741338..22089ec45 100644 --- a/src/components/settings/services/EditServiceForm.js +++ b/src/components/settings/services/EditServiceForm.js @@ -8,7 +8,8 @@ import normalizeUrl from 'normalize-url'; import Form from '../../../lib/Form'; import Recipe from '../../../models/Recipe'; import Service from '../../../models/Service'; -import Tabs, { TabItem } from '../../ui/Tabs'; +import Tabs from '../../ui/Tabs/Tabs'; +import { TabItem } from '../../ui/Tabs/TabItem'; import Input from '../../ui/Input'; import Toggle from '../../ui/Toggle'; import Slider from '../../ui/Slider'; @@ -262,11 +263,11 @@ class EditServiceForm extends Component { {action === 'add' ? intl.formatMessage(messages.addServiceHeadline, { - name: recipe.name, - }) + name: recipe.name, + }) : intl.formatMessage(messages.editServiceHeadline, { - name: service.name !== '' ? service.name : recipe.name, - })} + name: service.name !== '' ? service.name : recipe.name, + })}
@@ -342,11 +343,9 @@ class EditServiceForm extends Component { {intl.formatMessage(messages.indirectMessageInfo)}

- )} + )} {recipe.allowFavoritesDelineationInUnreadCount && ( - + )}
diff --git a/src/components/ui/Tabs/TabItem.js b/src/components/ui/Tabs/TabItem.js deleted file mode 100644 index d0ef4e798..000000000 --- a/src/components/ui/Tabs/TabItem.js +++ /dev/null @@ -1,15 +0,0 @@ -import React, { Component } from 'react'; - -import { oneOrManyChildElements } from '../../../prop-types'; - -export default class TabItem extends Component { - static propTypes = { - children: oneOrManyChildElements.isRequired, - }; - - render() { - const { children } = this.props; - - return <>{children}; - } -} diff --git a/src/components/ui/Tabs/TabItem.tsx b/src/components/ui/Tabs/TabItem.tsx new file mode 100644 index 000000000..bd613ddc7 --- /dev/null +++ b/src/components/ui/Tabs/TabItem.tsx @@ -0,0 +1,3 @@ +import React from 'react'; + +export const TabItem = ({ children }) => <>{children}; diff --git a/src/components/ui/Tabs/index.js b/src/components/ui/Tabs/index.js deleted file mode 100644 index e4adb62c7..000000000 --- a/src/components/ui/Tabs/index.js +++ /dev/null @@ -1,6 +0,0 @@ -import Tabs from './Tabs'; -import TabItem from './TabItem'; - -export default Tabs; - -export { TabItem }; diff --git a/src/features/basicAuth/Form.ts b/src/features/basicAuth/Form.ts index 95721d0e9..e84156d96 100644 --- a/src/features/basicAuth/Form.ts +++ b/src/features/basicAuth/Form.ts @@ -1,5 +1,6 @@ import Form from '../../lib/Form'; +// @ts-expect-error Expected 0 arguments, but got 1 export default new Form({ fields: { user: { diff --git a/src/features/communityRecipes/store.js b/src/features/communityRecipes/store.js deleted file mode 100644 index 05e18e2f7..000000000 --- a/src/features/communityRecipes/store.js +++ /dev/null @@ -1,32 +0,0 @@ -import { computed } from 'mobx'; -import { FeatureStore } from '../utils/FeatureStore'; - -const debug = require('debug')('Ferdi:feature:communityRecipes:store'); - -export class CommunityRecipesStore extends FeatureStore { - start(stores, actions) { - debug('start'); - this.stores = stores; - this.actions = actions; - } - - stop() { - debug('stop'); - super.stop(); - } - - @computed get communityRecipes() { - if (!this.stores) return []; - - return this.stores.recipePreviews.dev.map(recipePreview => { - // TODO: Need to figure out if this is even necessary/used - recipePreview.isDevRecipe = !!recipePreview.author.some( - author => author.email === this.stores.user.data.email, - ); - - return recipePreview; - }); - } -} - -export default CommunityRecipesStore; diff --git a/src/features/communityRecipes/store.ts b/src/features/communityRecipes/store.ts new file mode 100644 index 000000000..a8d358ba0 --- /dev/null +++ b/src/features/communityRecipes/store.ts @@ -0,0 +1,39 @@ +import { computed } from 'mobx'; +import { FeatureStore } from '../utils/FeatureStore'; + +const debug = require('debug')('Ferdi:feature:communityRecipes:store'); + +export class CommunityRecipesStore extends FeatureStore { + stores: any; + + actions: any; + + start(stores: any, actions: any) { + debug('start'); + this.stores = stores; + this.actions = actions; + } + + stop() { + debug('stop'); + super.stop(); + } + + @computed get communityRecipes() { + if (!this.stores) return []; + + return this.stores.recipePreviews.dev.map( + (recipePreview: { isDevRecipe: boolean; author: any[] }) => { + // TODO: Need to figure out if this is even necessary/used + recipePreview.isDevRecipe = !!recipePreview.author.some( + (author: { email: any }) => + author.email === this.stores.user.data.email, + ); + + return recipePreview; + }, + ); + } +} + +export default CommunityRecipesStore; diff --git a/src/features/nightlyBuilds/store.js b/src/features/nightlyBuilds/store.js deleted file mode 100644 index ed06e5a7d..000000000 --- a/src/features/nightlyBuilds/store.js +++ /dev/null @@ -1,7 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isModalVisible: false, -}; - -export const state = observable(defaultState); diff --git a/src/features/nightlyBuilds/store.ts b/src/features/nightlyBuilds/store.ts new file mode 100644 index 000000000..ed06e5a7d --- /dev/null +++ b/src/features/nightlyBuilds/store.ts @@ -0,0 +1,7 @@ +import { observable } from 'mobx'; + +const defaultState = { + isModalVisible: false, +}; + +export const state = observable(defaultState); diff --git a/src/features/publishDebugInfo/store.js b/src/features/publishDebugInfo/store.js deleted file mode 100644 index ed06e5a7d..000000000 --- a/src/features/publishDebugInfo/store.js +++ /dev/null @@ -1,7 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isModalVisible: false, -}; - -export const state = observable(defaultState); diff --git a/src/features/publishDebugInfo/store.ts b/src/features/publishDebugInfo/store.ts new file mode 100644 index 000000000..ed06e5a7d --- /dev/null +++ b/src/features/publishDebugInfo/store.ts @@ -0,0 +1,7 @@ +import { observable } from 'mobx'; + +const defaultState = { + isModalVisible: false, +}; + +export const state = observable(defaultState); diff --git a/src/features/quickSwitch/store.js b/src/features/quickSwitch/store.js deleted file mode 100644 index ed06e5a7d..000000000 --- a/src/features/quickSwitch/store.js +++ /dev/null @@ -1,7 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isModalVisible: false, -}; - -export const state = observable(defaultState); diff --git a/src/features/quickSwitch/store.ts b/src/features/quickSwitch/store.ts new file mode 100644 index 000000000..ed06e5a7d --- /dev/null +++ b/src/features/quickSwitch/store.ts @@ -0,0 +1,7 @@ +import { observable } from 'mobx'; + +const defaultState = { + isModalVisible: false, +}; + +export const state = observable(defaultState); diff --git a/src/features/serviceProxy/index.js b/src/features/serviceProxy/index.js deleted file mode 100644 index b9320cda9..000000000 --- a/src/features/serviceProxy/index.js +++ /dev/null @@ -1,38 +0,0 @@ -import { autorun, observable } from 'mobx'; -import { session } from '@electron/remote'; - -const debug = require('debug')('Ferdi:feature:serviceProxy'); - -export const config = observable({ - isEnabled: true, -}); - -export default function init(stores) { - debug('Initializing `serviceProxy` feature'); - - autorun(() => { - config.isEnabled = true; - - const services = stores.services.enabled; - const proxySettings = stores.settings.proxy; - - debug('Service Proxy autorun'); - - for (const service of services) { - const s = session.fromPartition(`persist:service-${service.id}`); - - if (config.isEnabled) { - const serviceProxyConfig = proxySettings[service.id]; - - if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { - const proxyHost = `${serviceProxyConfig.host}${serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : ''}`; - debug(`Setting proxy config from service settings for "${service.name}" (${service.id}) to`, proxyHost); - - s.setProxy({ proxyRules: proxyHost }, () => { - debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`); - }); - } - } - } - }); -} diff --git a/src/features/serviceProxy/index.ts b/src/features/serviceProxy/index.ts new file mode 100644 index 000000000..f095b286a --- /dev/null +++ b/src/features/serviceProxy/index.ts @@ -0,0 +1,54 @@ +import { autorun, observable } from 'mobx'; +import { session } from '@electron/remote'; + +const debug = require('debug')('Ferdi:feature:serviceProxy'); + +export const config = observable({ + isEnabled: true, +}); + +export default function init(stores: { + services: { enabled: any }; + settings: { proxy: any }; +}) { + debug('Initializing `serviceProxy` feature'); + + autorun(() => { + config.isEnabled = true; + + const services = stores.services.enabled; + const proxySettings = stores.settings.proxy; + + debug('Service Proxy autorun'); + + for (const service of services) { + const s = session.fromPartition(`persist:service-${service.id}`); + + if (config.isEnabled) { + const serviceProxyConfig = proxySettings[service.id]; + + if ( + serviceProxyConfig && + serviceProxyConfig.isEnabled && + serviceProxyConfig.host + ) { + const proxyHost = `${serviceProxyConfig.host}${ + serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : '' + }`; + debug( + `Setting proxy config from service settings for "${service.name}" (${service.id}) to`, + proxyHost, + ); + + s.setProxy({ proxyRules: proxyHost }) + .then(() => { + debug( + `Using proxy "${proxyHost}" for "${service.name}" (${service.id})`, + ); + }) + .catch(error => console.error(error)); + } + } + } + }); +} diff --git a/src/features/settingsWS/actions.js b/src/features/settingsWS/actions.js deleted file mode 100755 index 631670c8a..000000000 --- a/src/features/settingsWS/actions.js +++ /dev/null @@ -1,10 +0,0 @@ -import PropTypes from 'prop-types'; -import { createActionsFromDefinitions } from '../../actions/lib/actions'; - -export const settingsWSActions = createActionsFromDefinitions({ - greet: { - name: PropTypes.string.isRequired, - }, -}, PropTypes.checkPropTypes); - -export default settingsWSActions; diff --git a/src/features/settingsWS/actions.ts b/src/features/settingsWS/actions.ts new file mode 100755 index 000000000..631670c8a --- /dev/null +++ b/src/features/settingsWS/actions.ts @@ -0,0 +1,10 @@ +import PropTypes from 'prop-types'; +import { createActionsFromDefinitions } from '../../actions/lib/actions'; + +export const settingsWSActions = createActionsFromDefinitions({ + greet: { + name: PropTypes.string.isRequired, + }, +}, PropTypes.checkPropTypes); + +export default settingsWSActions; diff --git a/src/features/settingsWS/index.js b/src/features/settingsWS/index.js deleted file mode 100755 index 7771421d6..000000000 --- a/src/features/settingsWS/index.js +++ /dev/null @@ -1,27 +0,0 @@ -import { reaction } from 'mobx'; -import { SettingsWSStore } from './store'; - -const debug = require('debug')('Ferdi:feature:settingsWS'); - -export const settingsStore = new SettingsWSStore(); - -export default function initSettingsWebSocket(stores, actions) { - const { features } = stores; - - // Toggle SettingsWebSocket feature - reaction( - () => ( - features.features.isSettingsWSEnabled - ), - (isEnabled) => { - if (isEnabled) { - debug('Initializing `settingsWS` feature'); - settingsStore.start(stores, actions); - } else if (settingsStore) { - debug('Disabling `settingsWS` feature'); - settingsStore.stop(); - } - }, - { fireImmediately: true }, - ); -} diff --git a/src/features/settingsWS/index.ts b/src/features/settingsWS/index.ts new file mode 100755 index 000000000..9bb206d82 --- /dev/null +++ b/src/features/settingsWS/index.ts @@ -0,0 +1,28 @@ +import { reaction } from 'mobx'; +import { SettingsWSStore } from './store'; + +const debug = require('debug')('Ferdi:feature:settingsWS'); + +export const settingsStore = new SettingsWSStore(); + +export default function initSettingsWebSocket( + stores: { features: any }, + actions: any, +) { + const { features } = stores; + + // Toggle SettingsWebSocket feature + reaction( + () => features.features.isSettingsWSEnabled, + isEnabled => { + if (isEnabled) { + debug('Initializing `settingsWS` feature'); + settingsStore.start(stores, actions); + } else if (settingsStore) { + debug('Disabling `settingsWS` feature'); + settingsStore.stop(); + } + }, + { fireImmediately: true }, + ); +} diff --git a/src/features/settingsWS/state.js b/src/features/settingsWS/state.js deleted file mode 100755 index 7b16b2b6e..000000000 --- a/src/features/settingsWS/state.js +++ /dev/null @@ -1,13 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isFeatureActive: false, -}; - -export const settingsWSState = observable(defaultState); - -export function resetState() { - Object.assign(settingsWSState, defaultState); -} - -export default settingsWSState; diff --git a/src/features/settingsWS/state.ts b/src/features/settingsWS/state.ts new file mode 100755 index 000000000..7b16b2b6e --- /dev/null +++ b/src/features/settingsWS/state.ts @@ -0,0 +1,13 @@ +import { observable } from 'mobx'; + +const defaultState = { + isFeatureActive: false, +}; + +export const settingsWSState = observable(defaultState); + +export function resetState() { + Object.assign(settingsWSState, defaultState); +} + +export default settingsWSState; diff --git a/src/features/todos/actions.js b/src/features/todos/actions.js deleted file mode 100644 index cc17e919b..000000000 --- a/src/features/todos/actions.js +++ /dev/null @@ -1,28 +0,0 @@ -import PropTypes from 'prop-types'; -import { createActionsFromDefinitions } from '../../actions/lib/actions'; - -export const todoActions = createActionsFromDefinitions({ - resize: { - width: PropTypes.number.isRequired, - }, - toggleTodosPanel: {}, - toggleTodosFeatureVisibility: {}, - setTodosWebview: { - webview: PropTypes.instanceOf(Element).isRequired, - }, - handleHostMessage: { - action: PropTypes.string.isRequired, - data: PropTypes.object, - }, - handleClientMessage: { - channel: PropTypes.string.isRequired, - message: PropTypes.shape({ - action: PropTypes.string.isRequired, - data: PropTypes.object, - }), - }, - openDevTools: {}, - reload: {}, -}, PropTypes.checkPropTypes); - -export default todoActions; diff --git a/src/features/todos/actions.ts b/src/features/todos/actions.ts new file mode 100644 index 000000000..04e299e71 --- /dev/null +++ b/src/features/todos/actions.ts @@ -0,0 +1,31 @@ +import PropTypes from 'prop-types'; +import { createActionsFromDefinitions } from '../../actions/lib/actions'; + +export const todoActions = createActionsFromDefinitions( + { + resize: { + width: PropTypes.number.isRequired, + }, + toggleTodosPanel: {}, + toggleTodosFeatureVisibility: {}, + setTodosWebview: { + webview: PropTypes.instanceOf(Element).isRequired, + }, + handleHostMessage: { + action: PropTypes.string.isRequired, + data: PropTypes.object, + }, + handleClientMessage: { + channel: PropTypes.string.isRequired, + message: PropTypes.shape({ + action: PropTypes.string.isRequired, + data: PropTypes.object, + }), + }, + openDevTools: {}, + reload: {}, + }, + PropTypes.checkPropTypes, +); + +export default todoActions; diff --git a/src/features/todos/constants.js b/src/features/todos/constants.js deleted file mode 100644 index 303a7a16e..000000000 --- a/src/features/todos/constants.js +++ /dev/null @@ -1,8 +0,0 @@ -export const IPC = { - TODOS_HOST_CHANNEL: 'TODOS_HOST_CHANNEL', - TODOS_CLIENT_CHANNEL: 'TODOS_CLIENT_CHANNEL', -}; - -export const TODOS_ROUTES = { - TARGET: '/todos', -}; diff --git a/src/features/todos/constants.ts b/src/features/todos/constants.ts new file mode 100644 index 000000000..303a7a16e --- /dev/null +++ b/src/features/todos/constants.ts @@ -0,0 +1,8 @@ +export const IPC = { + TODOS_HOST_CHANNEL: 'TODOS_HOST_CHANNEL', + TODOS_CLIENT_CHANNEL: 'TODOS_CLIENT_CHANNEL', +}; + +export const TODOS_ROUTES = { + TARGET: '/todos', +}; diff --git a/src/features/todos/index.js b/src/features/todos/index.js deleted file mode 100644 index 573190881..000000000 --- a/src/features/todos/index.js +++ /dev/null @@ -1,28 +0,0 @@ -import { reaction } from 'mobx'; -import TodoStore from './store'; - -const debug = require('debug')('Ferdi:feature:todos'); - -export const todosStore = new TodoStore(); - -export default function initTodos(stores, actions) { - stores.todos = todosStore; - const { features } = stores; - - // Toggle todos feature - reaction( - () => ( - features.features.isTodosEnabled - ), - (isEnabled) => { - if (isEnabled) { - debug('Initializing `todos` feature'); - todosStore.start(stores, actions); - } else if (todosStore.isFeatureActive) { - debug('Disabling `todos` feature'); - todosStore.stop(); - } - }, - { fireImmediately: true }, - ); -} diff --git a/src/features/todos/index.ts b/src/features/todos/index.ts new file mode 100644 index 000000000..3665812e6 --- /dev/null +++ b/src/features/todos/index.ts @@ -0,0 +1,29 @@ +import { reaction } from 'mobx'; +import TodoStore from './store'; + +const debug = require('debug')('Ferdi:feature:todos'); + +export const todosStore = new TodoStore(); + +export default function initTodos( + stores: { todos?: any; features?: any }, + actions: any, +) { + stores.todos = todosStore; + const { features } = stores; + + // Toggle todos feature + reaction( + () => features.features.isTodosEnabled, + isEnabled => { + if (isEnabled) { + debug('Initializing `todos` feature'); + todosStore.start(stores, actions); + } else if (todosStore.isFeatureActive) { + debug('Disabling `todos` feature'); + todosStore.stop(); + } + }, + { fireImmediately: true }, + ); +} diff --git a/src/lib/DBus.js b/src/lib/DBus.js deleted file mode 100644 index 9baaea014..000000000 --- a/src/lib/DBus.js +++ /dev/null @@ -1,45 +0,0 @@ -import { sessionBus } from 'dbus-next'; -import { isLinux } from '../environment'; - -export default class DBus { - bus = null; - - constructor(trayIcon) { - this.trayIcon = trayIcon; - } - - start() { - if (!isLinux || this.bus) return; - - try { - this.bus = sessionBus(); - } catch { - // Error connecting to the bus. - return; - } - - // HACK Hook onto the MessageBus to track StatusNotifierWatchers - this.bus._addMatch("type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',path='/org/freedesktop/DBus',member='NameOwnerChanged'"); - const mangled = JSON.stringify({ - path: '/org/freedesktop/DBus', - interface: 'org.freedesktop.DBus', - member: 'NameOwnerChanged', - }); - this.bus._signals.on(mangled, (msg) => { - const [name, oldOwner, newOwner] = msg.body; - if (name === 'org.kde.StatusNotifierWatcher' && oldOwner !== newOwner && newOwner !== '') { - // Leave ample time for the StatusNotifierWatcher to be initialized - setTimeout(() => { - this.trayIcon.recreateIfVisible(); - }, 400); - } - }); - } - - stop() { - if (!this.bus) return; - - this.bus.disconnect(); - this.bus = null; - } -} diff --git a/src/lib/DBus.ts b/src/lib/DBus.ts new file mode 100644 index 000000000..b1febc2d1 --- /dev/null +++ b/src/lib/DBus.ts @@ -0,0 +1,55 @@ +import { MessageBus, sessionBus } from 'dbus-next'; +import { isLinux } from '../environment'; + +export default class DBus { + bus: MessageBus | null = null; + + trayIcon: any; + + constructor(trayIcon: any) { + this.trayIcon = trayIcon; + } + + start() { + if (!isLinux || this.bus) return; + + try { + this.bus = sessionBus(); + } catch { + // Error connecting to the bus. + return; + } + + // HACK Hook onto the MessageBus to track StatusNotifierWatchers + // @ts-expect-error Property '_addMatch' does not exist on type 'MessageBus'. + this.bus._addMatch( + "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',path='/org/freedesktop/DBus',member='NameOwnerChanged'", + ); + const mangled = JSON.stringify({ + path: '/org/freedesktop/DBus', + interface: 'org.freedesktop.DBus', + member: 'NameOwnerChanged', + }); + // @ts-expect-error Property '_signals' does not exist on type 'MessageBus'. + this.bus._signals.on(mangled, (msg: { body: [any, any, any] }) => { + const [name, oldOwner, newOwner] = msg.body; + if ( + name === 'org.kde.StatusNotifierWatcher' && + oldOwner !== newOwner && + newOwner !== '' + ) { + // Leave ample time for the StatusNotifierWatcher to be initialized + setTimeout(() => { + this.trayIcon.recreateIfVisible(); + }, 400); + } + }); + } + + stop() { + if (!this.bus) return; + + this.bus.disconnect(); + this.bus = null; + } +} diff --git a/src/lib/Form.js b/src/lib/Form.js deleted file mode 100644 index 9b8321948..000000000 --- a/src/lib/Form.js +++ /dev/null @@ -1,32 +0,0 @@ -import Form from 'mobx-react-form'; - -export default class DefaultForm extends Form { - bindings() { - return { - default: { - id: 'id', - name: 'name', - type: 'type', - value: 'value', - label: 'label', - placeholder: 'placeholder', - disabled: 'disabled', - onChange: 'onChange', - onFocus: 'onFocus', - onBlur: 'onBlur', - error: 'error', - }, - }; - } - - options() { - return { - validateOnInit: false, // default: true - // validateOnBlur: true, // default: true - // validateOnChange: true // default: false - // // validationDebounceWait: { - // // trailing: true, - // // }, - }; - } -} diff --git a/src/lib/Form.ts b/src/lib/Form.ts new file mode 100644 index 000000000..9b8321948 --- /dev/null +++ b/src/lib/Form.ts @@ -0,0 +1,32 @@ +import Form from 'mobx-react-form'; + +export default class DefaultForm extends Form { + bindings() { + return { + default: { + id: 'id', + name: 'name', + type: 'type', + value: 'value', + label: 'label', + placeholder: 'placeholder', + disabled: 'disabled', + onChange: 'onChange', + onFocus: 'onFocus', + onBlur: 'onBlur', + error: 'error', + }, + }; + } + + options() { + return { + validateOnInit: false, // default: true + // validateOnBlur: true, // default: true + // validateOnChange: true // default: false + // // validationDebounceWait: { + // // trailing: true, + // // }, + }; + } +} diff --git a/src/lib/TouchBar.js b/src/lib/TouchBar.js deleted file mode 100644 index c80931200..000000000 --- a/src/lib/TouchBar.js +++ /dev/null @@ -1,49 +0,0 @@ -import semver from 'semver'; -import { TouchBar, getCurrentWindow } from '@electron/remote'; -import { autorun } from 'mobx'; - -import { isMac, osRelease } from '../environment'; - -export default class FranzTouchBar { - constructor(stores, actions) { - this.stores = stores; - this.actions = actions; - - // Temporary fix for https://github.com/electron/electron/issues/10442 - // TODO: remove when we upgrade to electron 1.8.2 or later - try { - if (isMac && semver.gt(osRelease, '16.6.0')) { - this.build = autorun(this._build.bind(this)); - } - } catch (error) { - console.error(error); - } - } - - _build() { - const currentWindow = getCurrentWindow(); - - if (this.stores.user.isLoggedIn) { - const { TouchBarButton, TouchBarSpacer } = TouchBar; - - const buttons = []; - for (const service of this.stores.services.allDisplayed) { - buttons.push(new TouchBarButton({ - label: `${service.name}${service.unreadDirectMessageCount > 0 - ? ' 🔴' : ''} ${service.unreadDirectMessageCount === 0 - && service.unreadIndirectMessageCount > 0 - ? ' ⚪️' : ''}`, - backgroundColor: service.isActive ? '#3498DB' : null, - click: () => { - this.actions.service.setActive({ serviceId: service.id }); - }, - }), new TouchBarSpacer({ size: 'small' })); - } - - const touchBar = new TouchBar({ items: buttons }); - currentWindow.setTouchBar(touchBar); - } else { - currentWindow.setTouchBar(null); - } - } -} diff --git a/src/lib/TouchBar.ts b/src/lib/TouchBar.ts new file mode 100644 index 000000000..417e20411 --- /dev/null +++ b/src/lib/TouchBar.ts @@ -0,0 +1,62 @@ +import semver from 'semver'; +import { TouchBar, getCurrentWindow } from '@electron/remote'; +import { autorun } from 'mobx'; + +import { isMac, osRelease } from '../environment'; + +export default class FranzTouchBar { + stores: any; + + actions: any; + + build: any; + + constructor(stores: any, actions: any) { + this.stores = stores; + this.actions = actions; + + // Temporary fix for https://github.com/electron/electron/issues/10442 + // TODO: remove when we upgrade to electron 1.8.2 or later + try { + if (isMac && semver.gt(osRelease, '16.6.0')) { + this.build = autorun(this._build.bind(this)); + } + } catch (error) { + console.error(error); + } + } + + _build() { + const currentWindow = getCurrentWindow(); + + if (this.stores.user.isLoggedIn) { + const { TouchBarButton, TouchBarSpacer } = TouchBar; + + const buttons: any[] = []; + for (const service of this.stores.services.allDisplayed) { + buttons.push( + new TouchBarButton({ + label: `${service.name}${ + service.unreadDirectMessageCount > 0 ? ' 🔴' : '' + } ${ + service.unreadDirectMessageCount === 0 && + service.unreadIndirectMessageCount > 0 + ? ' ⚪️' + : '' + }`, + backgroundColor: service.isActive && '#3498DB', + click: () => { + this.actions.service.setActive({ serviceId: service.id }); + }, + }), + new TouchBarSpacer({ size: 'small' }), + ); + } + + const touchBar = new TouchBar({ items: buttons }); + currentWindow.setTouchBar(touchBar); + } else { + currentWindow.setTouchBar(null); + } + } +} -- cgit v1.2.3-54-g00ecf