From 4ba676f1940fd82ad5f09c21011748d759941abb Mon Sep 17 00:00:00 2001 From: patryk-sierzega <126664583+patryk-sierzega@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:41:00 +0200 Subject: [PATCH 1/8] [CP-2159] [Contacts] Secondary phone number stays visible after removing it (#1431) --- .../components/contact-details/contact-details.component.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app/src/contacts/components/contact-details/contact-details.component.tsx b/packages/app/src/contacts/components/contact-details/contact-details.component.tsx index f63b00a252..47246df5ec 100644 --- a/packages/app/src/contacts/components/contact-details/contact-details.component.tsx +++ b/packages/app/src/contacts/components/contact-details/contact-details.component.tsx @@ -210,7 +210,7 @@ const ContactDetails: FunctionComponent = ({ = ({ Date: Tue, 17 Oct 2023 08:44:43 +0200 Subject: [PATCH 2/8] [CP-101] Windows titles updated - TEST (#1465) --- packages/app/src/__deprecated__/main/main.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/app/src/__deprecated__/main/main.ts b/packages/app/src/__deprecated__/main/main.ts index 4968cfbfd6..ba46b426a3 100644 --- a/packages/app/src/__deprecated__/main/main.ts +++ b/packages/app/src/__deprecated__/main/main.ts @@ -268,7 +268,7 @@ if (!gotTheLock) { } ipcMain.answerRenderer(HelpActions.OpenWindow, () => { - const title = "Mudita Center - Help" + const title = "CP-101-test - Help" if (helpWindow === null) { helpWindow = new BrowserWindow( getWindowOptions({ @@ -373,7 +373,7 @@ createOpenWindowListener( AboutActions.LicenseOpenWindow, Mode.License, URL_MAIN.license, - "Mudita Center - License", + "CP-101-test - License", licenseWindow ) @@ -381,7 +381,7 @@ createOpenWindowListener( AboutActions.TermsOpenWindow, Mode.TermsOfService, URL_MAIN.termsOfService, - "Mudita Center - Terms of service", + "CP-101-test - Terms of service", termsWindow ) @@ -389,7 +389,7 @@ createOpenWindowListener( AboutActions.PolicyOpenWindow, Mode.PrivacyPolicy, URL_MAIN.privacyPolicy, - "Mudita Center - Privacy policy", + "CP-101-test - Privacy policy", policyWindow ) @@ -397,7 +397,7 @@ createOpenWindowListener( PureSystemActions.SarOpenWindow, Mode.Sar, URL_OVERVIEW.sar, - "Mudita Center - SAR information", + "CP-101-test - SAR information", policyWindow ) @@ -416,7 +416,7 @@ const createErrorWindow = async (googleAuthWindow: BrowserWindow) => { } ipcMain.answerRenderer(GoogleAuthActions.OpenWindow, async (scope: Scope) => { - const title = "Mudita Center - Google Auth" + const title = "CP-101-test - Google Auth" if (process.env.MUDITA_CENTER_SERVER_URL) { const cb = (data: string) => { // AUTO DISABLED - fix me if you like :) @@ -488,7 +488,7 @@ ipcMain.answerRenderer( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/require-await async (data: { authorizationUrl: string; scope: string }) => { - const title = "Mudita Center - Outlook Auth" + const title = "CP-101-test - Outlook Auth" const { authorizationUrl, scope } = data if (clientId) { if (outlookAuthWindow === null) { From 0b6bfc705e23c645aad58c1b3f23f7eae6991243 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 17 Oct 2023 08:46:15 +0200 Subject: [PATCH 3/8] Revert "[CP-101] Windows titles updated - TEST (#1465)" (#1466) --- packages/app/src/__deprecated__/main/main.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/app/src/__deprecated__/main/main.ts b/packages/app/src/__deprecated__/main/main.ts index ba46b426a3..4968cfbfd6 100644 --- a/packages/app/src/__deprecated__/main/main.ts +++ b/packages/app/src/__deprecated__/main/main.ts @@ -268,7 +268,7 @@ if (!gotTheLock) { } ipcMain.answerRenderer(HelpActions.OpenWindow, () => { - const title = "CP-101-test - Help" + const title = "Mudita Center - Help" if (helpWindow === null) { helpWindow = new BrowserWindow( getWindowOptions({ @@ -373,7 +373,7 @@ createOpenWindowListener( AboutActions.LicenseOpenWindow, Mode.License, URL_MAIN.license, - "CP-101-test - License", + "Mudita Center - License", licenseWindow ) @@ -381,7 +381,7 @@ createOpenWindowListener( AboutActions.TermsOpenWindow, Mode.TermsOfService, URL_MAIN.termsOfService, - "CP-101-test - Terms of service", + "Mudita Center - Terms of service", termsWindow ) @@ -389,7 +389,7 @@ createOpenWindowListener( AboutActions.PolicyOpenWindow, Mode.PrivacyPolicy, URL_MAIN.privacyPolicy, - "CP-101-test - Privacy policy", + "Mudita Center - Privacy policy", policyWindow ) @@ -397,7 +397,7 @@ createOpenWindowListener( PureSystemActions.SarOpenWindow, Mode.Sar, URL_OVERVIEW.sar, - "CP-101-test - SAR information", + "Mudita Center - SAR information", policyWindow ) @@ -416,7 +416,7 @@ const createErrorWindow = async (googleAuthWindow: BrowserWindow) => { } ipcMain.answerRenderer(GoogleAuthActions.OpenWindow, async (scope: Scope) => { - const title = "CP-101-test - Google Auth" + const title = "Mudita Center - Google Auth" if (process.env.MUDITA_CENTER_SERVER_URL) { const cb = (data: string) => { // AUTO DISABLED - fix me if you like :) @@ -488,7 +488,7 @@ ipcMain.answerRenderer( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/require-await async (data: { authorizationUrl: string; scope: string }) => { - const title = "CP-101-test - Outlook Auth" + const title = "Mudita Center - Outlook Auth" const { authorizationUrl, scope } = data if (clientId) { if (outlookAuthWindow === null) { From 9774cfb9a65fb9b70d169f108683b38fca00b9ed Mon Sep 17 00:00:00 2001 From: Oskar Michalkiewicz <32848134+OskarMichalkiewicz@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:12:07 +0000 Subject: [PATCH 4/8] [CP-2203] OS update badge status enhancements (#1442) Co-authored-by: patryk-sierzega <126664583+patryk-sierzega@users.noreply.github.com> --- .github/pull_request_template.md | 2 +- .../renderer/locales/default/en-US.json | 6 +- .../constants/overview.enum.ts | 4 +- .../harmony-overview.component.tsx | 24 - .../overview-content.component.tsx | 25 +- .../helpers/use-update-flow-state.hook.tsx | 130 +++-- .../helpers/use-update-flow-state.test.tsx | 543 ++++++++++++++---- .../overview-content.component.tsx | 48 +- .../pure-overview/pure-overview.component.tsx | 22 - .../system-update-text.component.tsx | 53 +- .../system-update-text.interface.ts | 2 - .../system-update-text.test.tsx | 67 ++- .../components/system/system.component.tsx | 51 +- .../components/system/system.stories.tsx | 31 +- .../components/system/system.test.tsx | 174 ++++-- 15 files changed, 787 insertions(+), 395 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 77ed363e36..898850dcc6 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,7 +2,7 @@ JIRA Reference: [CP-XXX] ### :memo: Description ️ -- +- ### :muscle: Checklist before requesting a review - nice to have diff --git a/packages/app/src/__deprecated__/renderer/locales/default/en-US.json b/packages/app/src/__deprecated__/renderer/locales/default/en-US.json index 3abb8f6dbc..a7942cfdab 100644 --- a/packages/app/src/__deprecated__/renderer/locales/default/en-US.json +++ b/packages/app/src/__deprecated__/renderer/locales/default/en-US.json @@ -714,9 +714,9 @@ "module.overview.systemDownloadAction": "Download now", "module.overview.systemLastUpdate": "Updated: {date}", "module.overview.systemUpdateAction": "Update now", - "module.overview.systemUpdateAvailable": "Update is available", - "module.overview.systemUpdateCheckFailed": "Checking for update failed", - "module.overview.systemUpdateDownloaded": "Update is available", + "module.overview.systemUpdateAvailable": "Version {version} is available", + "module.overview.systemUpdateCheckFailed": "Checking for updates failed", + "module.overview.systemUpdateDownloaded": "Install now", "module.overview.systemUpdateUpToDate": "You’re up to date.", "module.overview.systemVersion": "MuditaOS version", "module.overview.systemVersionTitle": "Current version:", diff --git a/packages/app/src/overview/components/overview-screens/constants/overview.enum.ts b/packages/app/src/overview/components/overview-screens/constants/overview.enum.ts index 2dadf757c0..35e4072fec 100644 --- a/packages/app/src/overview/components/overview-screens/constants/overview.enum.ts +++ b/packages/app/src/overview/components/overview-screens/constants/overview.enum.ts @@ -4,8 +4,10 @@ */ export enum CheckForUpdateLocalState { + Initial = "initial", Loading = "loading", - SilentCheckLoading = "silent-check-loading", Failed = "failed", Loaded = "loaded", + Download = "downloaded", + Install = "install", } diff --git a/packages/app/src/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx b/packages/app/src/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx index 4a36000f51..4f9181bd3a 100644 --- a/packages/app/src/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx +++ b/packages/app/src/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx @@ -5,10 +5,8 @@ import { DeviceType } from "App/device/constants" import { Feature, flags } from "App/feature-flags" -import { CheckForUpdateLocalState } from "App/overview/components/overview-screens/constants/overview.enum" import { HarmonyOverviewProps } from "App/overview/components/overview-screens/harmony-overview/harmony-overview.component.interface" import OverviewContent from "App/overview/components/overview-screens/harmony-overview/overview-content.component" -import { useUpdateFlowState } from "App/overview/components/overview-screens/helpers/use-update-flow-state.hook" import { UpdateOsFlow } from "App/overview/components/update-os-flow" import UpdatingForceModalFlow from "App/overview/components/updating-force-modal-flow/updating-force-modal-flow.component" import { CheckForUpdateMode } from "App/update/constants" @@ -47,15 +45,6 @@ export const HarmonyOverview: FunctionComponent = ({ forceUpdateState, closeForceUpdateFlow, }) => { - const { checkForUpdateLocalState } = useUpdateFlowState({ - checkingForUpdateState, - silentCheckForUpdateState, - checkForUpdate: () => - checkForUpdate(DeviceType.MuditaHarmony, CheckForUpdateMode.SilentCheck), - forceUpdateNeeded, - osVersion, - }) - const goToHelp = (): void => { void ipcRenderer.callMain(HelpActions.OpenWindow) } @@ -138,22 +127,9 @@ export const HarmonyOverview: FunctionComponent = ({ )} 0} - checkForUpdateFailed={ - checkForUpdateLocalState === CheckForUpdateLocalState.Failed - } - checkForUpdateInProgress={ - checkForUpdateLocalState === - CheckForUpdateLocalState.SilentCheckLoading - } - checkForUpdatePerformed={ - checkForUpdateLocalState === CheckForUpdateLocalState.Loaded - } - pureOsDownloaded={areAllReleasesDownloaded} onUpdateCheck={checkForHarmonyUpdate} onUpdateInstall={() => updateReleases()} onUpdateDownload={openCheckForUpdateModal} diff --git a/packages/app/src/overview/components/overview-screens/harmony-overview/overview-content.component.tsx b/packages/app/src/overview/components/overview-screens/harmony-overview/overview-content.component.tsx index 2d6b5f1e88..9d85bc2cc9 100644 --- a/packages/app/src/overview/components/overview-screens/harmony-overview/overview-content.component.tsx +++ b/packages/app/src/overview/components/overview-screens/harmony-overview/overview-content.component.tsx @@ -19,14 +19,8 @@ interface OverviewProps { readonly onUpdateInstall: () => void readonly toggleDevMode?: () => void readonly disconnectDevice: () => void - readonly checkForUpdateInProgress: boolean readonly osVersion: string readonly batteryLevel: number - readonly pureOsAvailable: boolean - readonly pureOsDownloaded: boolean - readonly checkForUpdatePerformed: boolean - readonly checkForUpdateFailed: boolean - readonly deviceType: DeviceType readonly serialNumber: string | undefined } @@ -36,35 +30,28 @@ const OverviewContent: FunctionComponent = ({ onUpdateCheck, onUpdateDownload, onUpdateInstall, - pureOsAvailable, - pureOsDownloaded, toggleDevMode, osVersion, - deviceType, serialNumber, - checkForUpdateInProgress, - checkForUpdatePerformed, - checkForUpdateFailed, }) => { return ( - + ) diff --git a/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx b/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx index c77076086d..5976f8fdf7 100644 --- a/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx +++ b/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx @@ -3,85 +3,139 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +// AUTO DISABLED - fix me if you like :) +/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-assignment */ import { CheckForUpdateLocalState } from "App/overview/components/overview-screens/constants/overview.enum" -import { SilentCheckForUpdateState } from "App/update/constants" -import { RejectableThunk } from "App/__deprecated__/renderer/store" +import { + CheckForUpdateMode, + SilentCheckForUpdateState, +} from "App/update/constants" +import { + ReduxRootState, + RejectableThunk, + TmpDispatch, +} from "App/__deprecated__/renderer/store" import { useEffect, useState } from "react" import { CheckForUpdateState } from "App/update/constants/check-for-update-state.constant" +import { useDispatch, useSelector } from "react-redux" +import { checkForUpdate } from "App/update/actions" +import { DeviceType } from "App/device" +import { areAllReleasesDownloaded } from "App/update/selectors" -interface Params { - silentCheckForUpdateState: SilentCheckForUpdateState - checkingForUpdateState: CheckForUpdateState - checkForUpdate: () => RejectableThunk - forceUpdateNeeded: boolean - osVersion: string | undefined +interface Props { + deviceType: DeviceType } interface Result { - checkForUpdateLocalState: CheckForUpdateLocalState | undefined + checkForUpdateInProgress: boolean + checkForUpdatePerformed: boolean + checkForUpdateFailed: boolean + updateAvailable: boolean + updateDownloaded: boolean } -export const useUpdateFlowState = ({ - checkingForUpdateState, - silentCheckForUpdateState, - forceUpdateNeeded, - checkForUpdate, - osVersion, -}: Params): Result => { +export const useUpdateFlowState = ({ deviceType }: Props): Result => { + // AUTO DISABLED - fix me if you like :) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const dispatch = useDispatch() const [checkForUpdateLocalState, setCheckForUpdateLocalState] = - useState() + useState(CheckForUpdateLocalState.Initial) const [silentCheckForUpdatePromise, setSilentCheckForUpdatePromise] = useState() + const { + data, + checkForUpdateState, + error, + silentCheckForUpdate, + needsForceUpdate, + } = useSelector((state: ReduxRootState) => state.update) + const osVersion = useSelector( + (state: ReduxRootState) => state.device.data?.osVersion || "" + ) + const allDownloaded = useSelector(areAllReleasesDownloaded) + + const { availableReleasesForUpdate } = data + const silentCheck = () => + dispatch( + checkForUpdate({ deviceType, mode: CheckForUpdateMode.SilentCheck }) + ) useEffect(() => { if ( - silentCheckForUpdateState === SilentCheckForUpdateState.Initial && - !forceUpdateNeeded && + silentCheckForUpdate === SilentCheckForUpdateState.Initial && + !needsForceUpdate && osVersion ) { - const actionResult = checkForUpdate() + const actionResult = silentCheck() setSilentCheckForUpdatePromise(actionResult) } return () => { if ( silentCheckForUpdatePromise && - silentCheckForUpdateState === SilentCheckForUpdateState.Loading + silentCheckForUpdate === SilentCheckForUpdateState.Loading ) { silentCheckForUpdatePromise.abort() setSilentCheckForUpdatePromise(undefined) } } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [silentCheckForUpdateState, forceUpdateNeeded, osVersion]) + }, [silentCheckForUpdate, needsForceUpdate, osVersion]) useEffect(() => { - if (forceUpdateNeeded) { + if (needsForceUpdate) { return } if ( - (silentCheckForUpdateState === SilentCheckForUpdateState.Skipped && - checkingForUpdateState === CheckForUpdateState.Initial) || - silentCheckForUpdateState === SilentCheckForUpdateState.Failed || - checkingForUpdateState === CheckForUpdateState.Failed || - checkingForUpdateState === CheckForUpdateState.PerformedWithFailure + silentCheckForUpdate === SilentCheckForUpdateState.Loading || + checkForUpdateState === CheckForUpdateState.Loading || + (checkForUpdateState === CheckForUpdateState.Initial && + silentCheckForUpdate === SilentCheckForUpdateState.Initial) ) { - setCheckForUpdateLocalState(CheckForUpdateLocalState.Failed) + setCheckForUpdateLocalState(CheckForUpdateLocalState.Loading) + } else if (allDownloaded) { + setCheckForUpdateLocalState(CheckForUpdateLocalState.Install) + } else if ((availableReleasesForUpdate || []).length > 0) { + setCheckForUpdateLocalState(CheckForUpdateLocalState.Download) } else if ( - silentCheckForUpdateState === SilentCheckForUpdateState.Loading + error || + [ + CheckForUpdateState.PerformedWithFailure, + CheckForUpdateState.Failed, + ].includes(checkForUpdateState) || + (checkForUpdateState === CheckForUpdateState.Initial && + [ + SilentCheckForUpdateState.Skipped, + SilentCheckForUpdateState.Failed, + ].includes(silentCheckForUpdate)) ) { - setCheckForUpdateLocalState(CheckForUpdateLocalState.SilentCheckLoading) - } else if (checkingForUpdateState === CheckForUpdateState.Loading) { - setCheckForUpdateLocalState(CheckForUpdateLocalState.Loading) + setCheckForUpdateLocalState(CheckForUpdateLocalState.Failed) } else if ( - silentCheckForUpdateState === SilentCheckForUpdateState.Loaded || - checkingForUpdateState === CheckForUpdateState.Loaded || - checkingForUpdateState === CheckForUpdateState.Performed + [CheckForUpdateState.Loaded, CheckForUpdateState.Performed].includes( + checkForUpdateState + ) || + SilentCheckForUpdateState.Loaded === silentCheckForUpdate ) { setCheckForUpdateLocalState(CheckForUpdateLocalState.Loaded) } - }, [silentCheckForUpdateState, checkingForUpdateState, forceUpdateNeeded]) + }, [ + silentCheckForUpdate, + checkForUpdateState, + needsForceUpdate, + allDownloaded, + availableReleasesForUpdate, + error, + ]) return { - checkForUpdateLocalState, + checkForUpdateInProgress: + checkForUpdateLocalState === CheckForUpdateLocalState.Loading, + checkForUpdatePerformed: + checkForUpdateLocalState === CheckForUpdateLocalState.Loaded, + checkForUpdateFailed: + checkForUpdateLocalState === CheckForUpdateLocalState.Failed, + updateAvailable: + checkForUpdateLocalState === CheckForUpdateLocalState.Download, + updateDownloaded: + checkForUpdateLocalState === CheckForUpdateLocalState.Install, } } diff --git a/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx b/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx index 0bc57a6df9..85d65016d7 100644 --- a/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx +++ b/packages/app/src/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx @@ -3,206 +3,507 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { renderHook } from "@testing-library/react-hooks" +import { + RenderHookResult, + WrapperComponent, + renderHook, +} from "@testing-library/react-hooks" +import { CaseColor, DeviceType, PureDeviceData } from "App/device" import { CheckForUpdateLocalState } from "App/overview/components/overview-screens/constants/overview.enum" import { useUpdateFlowState } from "App/overview/components/overview-screens/helpers/use-update-flow-state.hook" -import { SilentCheckForUpdateState } from "App/update/constants" +import { + OsReleaseType, + Product, + ReleaseProcessState, + SilentCheckForUpdateState, +} from "App/update/constants" import { CheckForUpdateState } from "App/update/constants/check-for-update-state.constant" +import React from "react" +import { Provider } from "react-redux" +import createMockStore, { MockStore } from "redux-mock-store" +import thunk from "redux-thunk" +import { waitFor, type RenderOptions } from "@testing-library/react" +import type { PreloadedState } from "@reduxjs/toolkit" +import { ReduxRootState } from "App/__deprecated__/renderer/store" +import { initialState as update } from "App/update/reducers" +import { initialState as device } from "App/device/reducers/device.reducer" +import { OsRelease } from "App/update/dto" -type TestCase = [ - testedState: SilentCheckForUpdateState | CheckForUpdateState, - expectedState: CheckForUpdateLocalState +const mockedRelease: OsRelease = { + date: "2021-02-02", + file: { + name: "test file", + size: 123, + url: "some-url", + }, + product: Product.PurePhone, + type: OsReleaseType.Daily, + version: "1.1.0", + mandatoryVersions: [], +} + +const pureDeviceMock: PureDeviceData = { + networkName: "Network", + networkLevel: "5", + osVersion: "0.75.1", + batteryLevel: 0.99, + simCards: [ + { + slot: 1, + active: true, + number: 12345678, + network: "", + networkLevel: 0.75, + }, + ], + serialNumber: "303", + phoneLockTime: 1630703219, + memorySpace: { + reservedSpace: 124, + usedUserSpace: 1021, + total: 16000000000, + }, + caseColour: CaseColor.Gray, + backupFilePath: "path/to/directory/fileBase.tar", +} + +const defaultState = { + update, + device: { + ...device, + data: pureDeviceMock, + }, +} as ReduxRootState + +interface ExtendedRenderOptions extends Omit { + preloadedState?: PreloadedState + store?: MockStore +} + +export function renderHookWithProviders( + render: (initialProps: Props) => Result, + { + preloadedState = {}, + store = createMockStore([thunk])({ ...defaultState, ...preloadedState }), + ...renderOptions + }: ExtendedRenderOptions = {} +): { store: MockStore } & RenderHookResult { + const wrapper: WrapperComponent | undefined = ({ children }) => { + return {children} + } + + return { + store, + ...renderHook(render, { ...renderOptions, wrapper }), + } +} +type TestCaseSilent = [ + testedState: SilentCheckForUpdateState, + expectedState: ReturnType, + stateEnum: CheckForUpdateLocalState +] +type TestCaseNormal = [ + testedState: CheckForUpdateState, + expectedState: ReturnType, + stateEnum: CheckForUpdateLocalState +] +type TestCaseBoth = [ + firstTestedState: CheckForUpdateState, + secondTestedState: SilentCheckForUpdateState, + expectedState: ReturnType, + stateEnum: CheckForUpdateLocalState ] -const defaultParams = { - checkForUpdate: jest.fn(), - checkingForUpdateState: CheckForUpdateState.Initial, - silentCheckForUpdateState: SilentCheckForUpdateState.Initial, - forceUpdateNeeded: false, - osVersion: "1.2.0", +const defaultParams = { deviceType: DeviceType.MuditaPure } +const defaultResult = { + checkForUpdateInProgress: false, + checkForUpdatePerformed: false, + checkForUpdateFailed: false, + updateAvailable: false, + updateDownloaded: false, } -const silentCheckTestCases: TestCase[] = [ - [SilentCheckForUpdateState.Failed, CheckForUpdateLocalState.Failed], +const silentCheckTestCases: TestCaseSilent[] = [ + [ + SilentCheckForUpdateState.Failed, + { ...defaultResult, checkForUpdateFailed: true }, + CheckForUpdateLocalState.Failed, + ], [ SilentCheckForUpdateState.Loading, - CheckForUpdateLocalState.SilentCheckLoading, + { ...defaultResult, checkForUpdateInProgress: true }, + CheckForUpdateLocalState.Loading, + ], + [ + SilentCheckForUpdateState.Loaded, + { ...defaultResult, checkForUpdatePerformed: true }, + CheckForUpdateLocalState.Loaded, ], - [SilentCheckForUpdateState.Loaded, CheckForUpdateLocalState.Loaded], ] -const checkForUpdateTestCases: TestCase[] = [ - [CheckForUpdateState.Failed, CheckForUpdateLocalState.Failed], - [CheckForUpdateState.Loading, CheckForUpdateLocalState.Loading], - [CheckForUpdateState.Loaded, CheckForUpdateLocalState.Loaded], - [CheckForUpdateState.PerformedWithFailure, CheckForUpdateLocalState.Failed], - [CheckForUpdateState.Performed, CheckForUpdateLocalState.Loaded], +const checkForUpdateTestCases: TestCaseNormal[] = [ + [ + CheckForUpdateState.Failed, + { ...defaultResult, checkForUpdateFailed: true }, + CheckForUpdateLocalState.Failed, + ], + [ + CheckForUpdateState.Loading, + { ...defaultResult, checkForUpdateInProgress: true }, + CheckForUpdateLocalState.Loading, + ], + [ + CheckForUpdateState.Loaded, + { ...defaultResult, checkForUpdatePerformed: true }, + CheckForUpdateLocalState.Loaded, + ], + [ + CheckForUpdateState.PerformedWithFailure, + { ...defaultResult, checkForUpdateFailed: true }, + CheckForUpdateLocalState.Failed, + ], + [ + CheckForUpdateState.Performed, + { ...defaultResult, checkForUpdatePerformed: true }, + CheckForUpdateLocalState.Loaded, + ], ] +const bothStatusesTestCases: TestCaseBoth[] = [ + [ + CheckForUpdateState.Initial, + SilentCheckForUpdateState.Initial, + { ...defaultResult, checkForUpdateInProgress: true }, + CheckForUpdateLocalState.Loading, + ], + [ + CheckForUpdateState.Initial, + SilentCheckForUpdateState.Skipped, + { ...defaultResult, checkForUpdateFailed: true }, + CheckForUpdateLocalState.Failed, + ], + [ + CheckForUpdateState.Initial, + SilentCheckForUpdateState.Failed, + { ...defaultResult, checkForUpdateFailed: true }, + CheckForUpdateLocalState.Failed, + ], +] describe.each(silentCheckTestCases)( "when value for silentCheckForUpdateState equals to %p", - (param, expectedResult) => { - test(`checkForUpdateLocalState should equal to ${expectedResult}`, () => { - const { result } = renderHook(() => - useUpdateFlowState({ - ...defaultParams, - silentCheckForUpdateState: param as SilentCheckForUpdateState, - }) + (param, expectedResult, stateEnum) => { + test(`checkForUpdateLocalState should equal to ${stateEnum}`, () => { + const { result } = renderHookWithProviders( + () => + useUpdateFlowState({ + ...defaultParams, + }), + { + preloadedState: { + update: { + ...update, + silentCheckForUpdate: param, + }, + }, + } ) - expect(result.current.checkForUpdateLocalState).toEqual(expectedResult) + expect(result.current).toEqual(expectedResult) }) } ) describe.each(checkForUpdateTestCases)( "when value for checkingForUpdateState equals to %p", - (b, c) => { - test(`checkForUpdateLocalState should equal to ${c}`, () => { - const { result } = renderHook(() => - useUpdateFlowState({ - ...defaultParams, - checkingForUpdateState: b as CheckForUpdateState, - }) + (param, expectedResult, stateEnum) => { + test(`checkForUpdateLocalState should equal to ${stateEnum}`, () => { + const { result } = renderHookWithProviders( + () => + useUpdateFlowState({ + ...defaultParams, + }), + { + preloadedState: { + update: { + ...update, + checkForUpdateState: param, + }, + }, + } + ) + + expect(result.current).toEqual(expectedResult) + }) + } +) + +describe.each(bothStatusesTestCases)( + "when value for silentCheckForUpdateState equals to %p", + (firstParam, secondParam, expectedResult, stateEnum) => { + test(`checkForUpdateLocalState should equal to ${stateEnum}`, () => { + const { result } = renderHookWithProviders( + () => + useUpdateFlowState({ + ...defaultParams, + }), + { + preloadedState: { + update: { + ...update, + checkForUpdateState: firstParam, + silentCheckForUpdate: secondParam, + }, + }, + } ) - expect(result.current.checkForUpdateLocalState).toEqual(c) + expect(result.current).toEqual(expectedResult) }) } ) -describe("when value for silentCheckForUpdateState equals to Skipped and value for checkingForUpdateState equals to Initial", () => { - test("checkForUpdateLocalState should equal to Failed", () => { - const { result } = renderHook(() => - useUpdateFlowState({ - ...defaultParams, - checkingForUpdateState: CheckForUpdateState.Initial, - silentCheckForUpdateState: SilentCheckForUpdateState.Skipped, - }) +describe("when all releases were downloaded", () => { + test("checkForUpdateLocalState should equal to Install", () => { + const { result } = renderHookWithProviders( + () => + useUpdateFlowState({ + ...defaultParams, + }), + { + preloadedState: { + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + data: { + ...update.data, + downloadedProcessedReleases: [ + { release: mockedRelease, state: ReleaseProcessState.Done }, + ], + }, + }, + }, + } ) - expect(result.current.checkForUpdateLocalState).toEqual( - CheckForUpdateLocalState.Failed + expect(result.current).toEqual({ ...defaultResult, updateDownloaded: true }) + }) +}) + +describe("when there are new releases to download", () => { + test("checkForUpdateLocalState should equal to Download", () => { + const { result } = renderHookWithProviders( + () => + useUpdateFlowState({ + ...defaultParams, + }), + { + preloadedState: { + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + data: { + ...update.data, + availableReleasesForUpdate: [mockedRelease], + }, + }, + }, + } ) + + expect(result.current).toEqual({ ...defaultResult, updateAvailable: true }) }) }) describe("when silentCheckForUpdateState is set as initial", () => { test("check for update should be called", () => { - const spy = jest.fn() - renderHook(() => - useUpdateFlowState({ - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Initial, - checkForUpdate: spy, - }) + const mockStore = createMockStore([thunk])(defaultState) + + const { result } = renderHookWithProviders( + () => useUpdateFlowState(defaultParams), + { store: mockStore } + ) + + expect(result.current).toEqual({ + ...defaultResult, + checkForUpdateInProgress: true, + }) + expect(mockStore.getActions()).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "CHECK_FOR_UPDATE/pending", + }), + ]) ) - expect(spy).toHaveBeenCalledTimes(1) }) }) describe("when silentCheckForUpdateState is not set as initial", () => { test("check for update should not be called", () => { - const spy = jest.fn() - renderHook(() => - useUpdateFlowState({ - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Loaded, - checkForUpdate: spy, - }) + const mockStore = createMockStore([thunk])({ + ...defaultState, + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loading, + }, + }) + + const { result } = renderHookWithProviders( + () => useUpdateFlowState(defaultParams), + { store: mockStore } + ) + + expect(result.current).toEqual({ + ...defaultResult, + checkForUpdateInProgress: true, + }) + expect(mockStore.getActions()).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "CHECK_FOR_UPDATE/pending", + }), + ]) ) - expect(spy).toHaveBeenCalledTimes(0) }) }) describe("when os version is not specified", () => { test("check for update should not be called", () => { - const spy = jest.fn() - renderHook(() => - useUpdateFlowState({ - ...defaultParams, - checkForUpdate: spy, - osVersion: undefined, - }) + const mockStore = createMockStore([thunk])({ + ...defaultState, + device: { + ...defaultState.device, + data: { + ...pureDeviceMock, + osVersion: undefined, + }, + }, + }) + + const { result } = renderHookWithProviders( + () => useUpdateFlowState(defaultParams), + { store: mockStore } + ) + + expect(result.current).toEqual({ + ...defaultResult, + checkForUpdateInProgress: true, + }) + expect(mockStore.getActions()).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "CHECK_FOR_UPDATE/pending", + }), + ]) ) - expect(spy).toHaveBeenCalledTimes(0) }) }) describe("when hook is going to be destroyed", () => { - test("should abort pending check for update action", () => { - const abortSpy = jest.fn() - const mockedCheckForUpdate = jest.fn().mockReturnValue({ - abort: abortSpy, - }) - let params = { - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Initial, - checkForUpdate: mockedCheckForUpdate, - } - - const { rerender, unmount } = renderHook(() => useUpdateFlowState(params)) + test("should abort pending check for update action", async () => { + let state = defaultState + const mockStore = createMockStore([thunk]) + const store = mockStore(() => state) - params = { - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Loading, - checkForUpdate: mockedCheckForUpdate, + const { rerender, unmount } = renderHookWithProviders( + () => useUpdateFlowState(defaultParams), + { store } + ) + state = { + ...defaultState, + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loading, + }, } rerender() unmount() - expect(abortSpy).toHaveBeenCalledTimes(1) - }) - test("should not abort check for update action that is not pending", () => { - const abortSpy = jest.fn() - const mockedCheckForUpdate = jest.fn().mockReturnValue({ - abort: abortSpy, + await waitFor(() => { + expect(store.getActions()).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "CHECK_FOR_UPDATE/rejected", + error: { name: "AbortError", message: "Aborted" }, + }), + ]) + ) }) - let params = { - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Initial, - checkForUpdate: mockedCheckForUpdate, - } - - const { rerender, unmount } = renderHook(() => useUpdateFlowState(params)) + }) + test("should not abort check for update action that is not pending", async () => { + let state = defaultState + const mockStore = createMockStore([thunk]) + const store = mockStore(() => state) - params = { - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Loaded, - checkForUpdate: mockedCheckForUpdate, + const { rerender, unmount } = renderHookWithProviders( + () => useUpdateFlowState(defaultParams), + { store } + ) + state = { + ...defaultState, + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + }, } rerender() unmount() - expect(abortSpy).toHaveBeenCalledTimes(0) + await waitFor(() => { + expect(store.getActions()).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "CHECK_FOR_UPDATE/rejected", + error: { name: "AbortError", message: "Aborted" }, + }), + ]) + ) + }) }) }) describe("when force update is needed", () => { test("checkForUpdate should not be called", () => { - const spy = jest.fn() - renderHook(() => - useUpdateFlowState({ - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Initial, - checkForUpdate: spy, - forceUpdateNeeded: true, - }) + const mockStore = createMockStore([thunk])({ + ...defaultState, + update: { + ...update, + needsForceUpdate: true, + }, + }) + + const { result } = renderHookWithProviders( + () => useUpdateFlowState(defaultParams), + { store: mockStore } + ) + + expect(result.current).toEqual(defaultResult) + expect(mockStore.getActions()).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "CHECK_FOR_UPDATE/pending", + }), + ]) ) - expect(spy).toHaveBeenCalledTimes(0) }) test("checkForUpdateLocalState should not be changed", () => { - const { result } = renderHook(() => - useUpdateFlowState({ - ...defaultParams, - silentCheckForUpdateState: SilentCheckForUpdateState.Failed, - forceUpdateNeeded: true, - }) + const { result } = renderHookWithProviders( + () => + useUpdateFlowState({ + ...defaultParams, + }), + { + preloadedState: { + update: { + ...update, + needsForceUpdate: true, + }, + }, + } ) - expect(result.current.checkForUpdateLocalState).toEqual(undefined) + expect(result.current).toEqual(defaultResult) }) }) diff --git a/packages/app/src/overview/components/overview-screens/pure-overview/overview-content.component.tsx b/packages/app/src/overview/components/overview-screens/pure-overview/overview-content.component.tsx index a0a1e25dfa..0fb159b025 100644 --- a/packages/app/src/overview/components/overview-screens/pure-overview/overview-content.component.tsx +++ b/packages/app/src/overview/components/overview-screens/pure-overview/overview-content.component.tsx @@ -18,27 +18,22 @@ import { noop } from "App/__deprecated__/renderer/utils/noop" import { MemorySpace } from "App/files-manager/components/files-manager/files-manager.interface" interface OverviewContentProps { - readonly batteryLevel: number - readonly memorySpace: MemorySpace - readonly networkName: string - readonly networkLevel: number | undefined - readonly pureOsAvailable: boolean - readonly pureOsDownloaded: boolean - readonly checkForUpdatePerformed: boolean - readonly checkForUpdateInProgress: boolean - readonly checkForUpdateFailed: boolean - readonly osVersion: string - readonly caseColour: CaseColor | undefined - readonly lastBackupDate: Date | undefined - readonly serialNumber: string | undefined - readonly disconnectDevice: () => void - readonly onBackupCreate: () => void - readonly onBackupRestore: () => void - readonly onUpdateCheck: () => void - readonly onUpdateDownload: () => void - readonly onUpdateInstall: () => void - readonly toggleDevMode?: () => void - readonly backupActionDisabled: boolean + batteryLevel: number + memorySpace: MemorySpace + networkName: string + networkLevel: number | undefined + osVersion: string + caseColour: CaseColor | undefined + lastBackupDate: Date | undefined + serialNumber: string | undefined + disconnectDevice: () => void + onBackupCreate: () => void + onBackupRestore: () => void + onUpdateCheck: () => void + onUpdateDownload: () => void + onUpdateInstall: () => void + toggleDevMode?: () => void + backupActionDisabled: boolean } const OverviewContent: FunctionComponent = ({ @@ -50,11 +45,6 @@ const OverviewContent: FunctionComponent = ({ onUpdateCheck, onUpdateDownload, onUpdateInstall, - pureOsAvailable, - pureOsDownloaded, - checkForUpdatePerformed, - checkForUpdateInProgress, - checkForUpdateFailed, toggleDevMode, osVersion, caseColour, @@ -79,11 +69,7 @@ const OverviewContent: FunctionComponent = ({ networkLevel={networkLevel} /> = ({ failedModal: false, }) const [progress, setProgress] = useState(0) - const { checkForUpdateLocalState } = useUpdateFlowState({ - checkingForUpdateState, - silentCheckForUpdateState, - checkForUpdate: () => - checkForUpdate(DeviceType.MuditaPure, CheckForUpdateMode.SilentCheck), - forceUpdateNeeded, - osVersion, - }) useEffect(() => { let progressSimulator: NodeJS.Timeout @@ -292,18 +282,6 @@ export const PureOverview: FunctionComponent = ({ memorySpace={memorySpace} networkName={networkName} networkLevel={networkLevel} - pureOsAvailable={(availableReleasesForUpdate ?? []).length > 0} - pureOsDownloaded={areAllReleasesDownloaded} - checkForUpdateFailed={ - checkForUpdateLocalState === CheckForUpdateLocalState.Failed - } - checkForUpdateInProgress={ - checkForUpdateLocalState === - CheckForUpdateLocalState.SilentCheckLoading - } - checkForUpdatePerformed={ - checkForUpdateLocalState === CheckForUpdateLocalState.Loaded - } onUpdateCheck={checkForPureUpdate} onUpdateInstall={() => updateReleases()} onUpdateDownload={openCheckForUpdateModal} diff --git a/packages/app/src/overview/components/system-update-text/system-update-text.component.tsx b/packages/app/src/overview/components/system-update-text/system-update-text.component.tsx index e01c5db0a8..d24b5b38da 100644 --- a/packages/app/src/overview/components/system-update-text/system-update-text.component.tsx +++ b/packages/app/src/overview/components/system-update-text/system-update-text.component.tsx @@ -8,6 +8,10 @@ import { AvailableUpdateText } from "App/overview/components/system-update-text/ import { FunctionComponent } from "App/__deprecated__/renderer/types/function-component.interface" import React from "react" import { defineMessages, FormattedMessage } from "react-intl" +import { useSelector } from "react-redux" +import { ReduxRootState } from "App/__deprecated__/renderer/store" +import { DownloadState } from "App/update/constants" +import { State } from "App/core/constants" const messages = defineMessages({ systemUpdateDownloaded: { @@ -25,47 +29,46 @@ const messages = defineMessages({ }) export const SystemUpdateText: FunctionComponent = ({ - updateAvailable, - updateDownloaded, + checkForUpdateFailed, checkForUpdateInProgress, checkForUpdatePerformed, - checkForUpdateFailed, }) => { + const { data, updateOsState, downloadState } = useSelector( + (state: ReduxRootState) => state.update + ) + const { availableReleasesForUpdate } = data + if ( + checkForUpdateInProgress || + updateOsState === State.Loading || + downloadState === DownloadState.Loading + ) { + return null + } if (checkForUpdateFailed) { return ( ) - } - - if (checkForUpdateInProgress) { - return null - } - - if (!checkForUpdatePerformed) { - return null - } - - if (updateAvailable && updateDownloaded) { + } else if (availableReleasesForUpdate?.length) { return ( - + ) - } - - if (updateAvailable && !updateDownloaded) { + } else if (checkForUpdatePerformed) { return ( - + ) } - - return ( - - - - ) + return null } diff --git a/packages/app/src/overview/components/system-update-text/system-update-text.interface.ts b/packages/app/src/overview/components/system-update-text/system-update-text.interface.ts index 08bc43cdad..828073a020 100644 --- a/packages/app/src/overview/components/system-update-text/system-update-text.interface.ts +++ b/packages/app/src/overview/components/system-update-text/system-update-text.interface.ts @@ -4,8 +4,6 @@ */ export interface SystemUpdateTextProps { - updateAvailable: boolean - updateDownloaded: boolean checkForUpdateInProgress: boolean checkForUpdatePerformed: boolean checkForUpdateFailed: boolean diff --git a/packages/app/src/overview/components/system-update-text/system-update-text.test.tsx b/packages/app/src/overview/components/system-update-text/system-update-text.test.tsx index d70aaa165b..9dcb059376 100644 --- a/packages/app/src/overview/components/system-update-text/system-update-text.test.tsx +++ b/packages/app/src/overview/components/system-update-text/system-update-text.test.tsx @@ -7,21 +7,47 @@ import { SystemUpdateText } from "App/overview/components/system-update-text/sys import { SystemUpdateTextProps } from "App/overview/components/system-update-text/system-update-text.interface" import { renderWithThemeAndIntl } from "App/__deprecated__/renderer/utils/render-with-theme-and-intl" import React from "react" +import { Provider } from "react-redux" +import store, { ReduxRootState } from "App/__deprecated__/renderer/store" +import createMockStore from "redux-mock-store" +import thunk from "redux-thunk" +import { initialState as update } from "App/update/reducers" +import { OsRelease } from "App/update/dto" +import { OsReleaseType, Product } from "App/update/constants" const defaultProps: SystemUpdateTextProps = { checkForUpdateFailed: false, checkForUpdateInProgress: false, checkForUpdatePerformed: false, - updateAvailable: false, - updateDownloaded: false, } -const render = (extraProps?: Partial) => { +const mockedRelease: OsRelease = { + date: "2021-02-02", + file: { + name: "test file", + size: 123, + url: "some-url", + }, + product: Product.PurePhone, + type: OsReleaseType.Daily, + version: "1.1.0", + mandatoryVersions: [], +} + +const render = ( + extraProps?: Partial, + state?: Partial +) => { const props = { ...defaultProps, ...extraProps, } - return renderWithThemeAndIntl() + + return renderWithThemeAndIntl( + + + + ) } test("renders nothing for update in progress state", () => { @@ -42,24 +68,21 @@ test("renders update check failed", () => { ).toBeInTheDocument() }) -test("renders update downloaded info", () => { - const { queryByText } = render({ - checkForUpdatePerformed: true, - updateAvailable: true, - updateDownloaded: true, - }) - - expect( - queryByText("[value] module.overview.systemUpdateDownloaded") - ).toBeInTheDocument() -}) - test("renders update available info", () => { - const { queryByText } = render({ - checkForUpdatePerformed: true, - updateAvailable: true, - updateDownloaded: false, - }) + const { queryByText } = render( + { + checkForUpdatePerformed: true, + }, + { + update: { + ...update, + data: { + ...update.data, + availableReleasesForUpdate: [mockedRelease], + }, + }, + } + ) expect( queryByText("[value] module.overview.systemUpdateAvailable") @@ -69,8 +92,6 @@ test("renders update available info", () => { test("renders system up to date info", () => { const { queryByText } = render({ checkForUpdatePerformed: true, - updateAvailable: false, - updateDownloaded: false, checkForUpdateFailed: false, checkForUpdateInProgress: false, }) diff --git a/packages/app/src/overview/components/system/system.component.tsx b/packages/app/src/overview/components/system/system.component.tsx index 0af429f5d2..64e3bc2dd8 100644 --- a/packages/app/src/overview/components/system/system.component.tsx +++ b/packages/app/src/overview/components/system/system.component.tsx @@ -20,6 +20,8 @@ import { FunctionComponent } from "App/__deprecated__/renderer/types/function-co import { noop } from "App/__deprecated__/renderer/utils/noop" import React from "react" import { defineMessages, FormattedMessage } from "react-intl" +import { DeviceType } from "App/device" +import { useUpdateFlowState } from "../overview-screens/helpers/use-update-flow-state.hook" const messages = defineMessages({ muditaOsUpdateTitle: { @@ -43,29 +45,30 @@ const messages = defineMessages({ }) interface Props { + deviceType: DeviceType osVersion?: string onUpdateCheck?: () => void onUpdate?: () => void onDownload?: () => void - updateAvailable: boolean - updateDownloaded: boolean - checkForUpdateInProgress: boolean - checkForUpdatePerformed: boolean - checkForUpdateFailed: boolean } const System: FunctionComponent = ({ + deviceType, osVersion = "", - updateAvailable, - updateDownloaded, - checkForUpdateInProgress, - checkForUpdatePerformed, - checkForUpdateFailed, onUpdateCheck = noop, onUpdate = noop, onDownload = noop, ...props }) => { + const { + checkForUpdateInProgress, + checkForUpdatePerformed, + checkForUpdateFailed, + updateAvailable, + updateDownloaded, + } = useUpdateFlowState({ + deviceType: deviceType, + }) return ( @@ -89,26 +92,22 @@ const System: FunctionComponent = ({ checkForUpdateFailed={checkForUpdateFailed} checkForUpdateInProgress={checkForUpdateInProgress} checkForUpdatePerformed={checkForUpdatePerformed} - updateAvailable={updateAvailable} - updateDownloaded={updateDownloaded} /> {updateAvailable ? ( - updateDownloaded ? ( - - ) : ( - - ) + + ) : updateDownloaded ? ( + ) : ( * { @@ -23,57 +24,37 @@ storiesOf("Views|Overview/System", module).add("System", () => { diff --git a/packages/app/src/overview/components/system/system.test.tsx b/packages/app/src/overview/components/system/system.test.tsx index e9b92b2093..4b48090295 100644 --- a/packages/app/src/overview/components/system/system.test.tsx +++ b/packages/app/src/overview/components/system/system.test.tsx @@ -4,30 +4,99 @@ */ import "@testing-library/jest-dom/extend-expect" +import thunk from "redux-thunk" import React, { ComponentProps } from "react" import { fireEvent } from "@testing-library/dom" import { renderWithThemeAndIntl } from "App/__deprecated__/renderer/utils/render-with-theme-and-intl" import { intl } from "App/__deprecated__/renderer/utils/intl" import System from "App/overview/components/system/system.component" import { SystemTestIds } from "App/overview/components/system/system-test-ids.enum" +import { CaseColor, DeviceType, PureDeviceData } from "App/device" +import { Provider } from "react-redux" +import { ReduxRootState } from "App/__deprecated__/renderer/store" +import createMockStore from "redux-mock-store" +import { OsRelease } from "App/update/dto" +import { initialState as update } from "App/update/reducers" +import { initialState as device } from "App/device/reducers/device.reducer" +import { + OsReleaseType, + Product, + ReleaseProcessState, + SilentCheckForUpdateState, +} from "App/update/constants" type Props = ComponentProps const defaultProps: Props = { + deviceType: DeviceType.MuditaPure, osVersion: "1.0.0", - checkForUpdateInProgress: false, - checkForUpdatePerformed: true, - checkForUpdateFailed: false, - updateAvailable: false, - updateDownloaded: false, } -const render = (extraProps?: Partial) => { +const pureDeviceMock: PureDeviceData = { + networkName: "Network", + networkLevel: "5", + osVersion: "0.75.1", + batteryLevel: 0.99, + simCards: [ + { + slot: 1, + active: true, + number: 12345678, + network: "", + networkLevel: 0.75, + }, + ], + serialNumber: "303", + phoneLockTime: 1630703219, + memorySpace: { + reservedSpace: 124, + usedUserSpace: 1021, + total: 16000000000, + }, + caseColour: CaseColor.Gray, + backupFilePath: "path/to/directory/fileBase.tar", +} + +const mockedRelease: OsRelease = { + date: "2021-02-02", + file: { + name: "test file", + size: 123, + url: "some-url", + }, + product: Product.PurePhone, + type: OsReleaseType.Daily, + version: "1.1.0", + mandatoryVersions: [], +} + +const defaultState = { + update, + device: { + ...device, + data: pureDeviceMock, + }, +} as ReduxRootState + +const render = ( + extraState?: Partial, + extraProps?: Partial +) => { + const storeMock = createMockStore([thunk])({ + ...defaultState, + ...extraState, + }) + const props = { ...defaultProps, ...extraProps, } - return renderWithThemeAndIntl() + + return renderWithThemeAndIntl( + + + + ) } test("renders os version properly", () => { @@ -39,8 +108,14 @@ test("renders os version properly", () => { test("renders available update info properly", () => { const { getByText } = render({ - updateAvailable: true, - checkForUpdatePerformed: true, + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + data: { + ...update.data, + availableReleasesForUpdate: [mockedRelease], + }, + }, }) expect( getByText( @@ -51,8 +126,10 @@ test("renders available update info properly", () => { test("renders You're up to date info properly", () => { const { getByText } = render({ - updateAvailable: false, - checkForUpdatePerformed: true, + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + }, }) expect( getByText( @@ -69,17 +146,23 @@ test("renders 'check for updates' button properly", () => { }) test("renders 'update now' button properly", () => { - const { queryByRole } = render({ updateAvailable: true }) + const { queryByRole } = render({ + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + data: { + ...update.data, + availableReleasesForUpdate: [mockedRelease], + }, + }, + }) expect(queryByRole("button")).toHaveTextContent( intl.formatMessage({ id: "module.overview.systemDownloadAction" }) ) }) test("does not render any label when check for update was not performed", () => { - const { queryByText } = render({ - updateAvailable: true, - checkForUpdatePerformed: false, - }) + const { queryByText } = render({}) expect( queryByText( intl.formatMessage({ id: "module.overview.systemUpdateAvailable" }) @@ -97,11 +180,7 @@ test("does not render any label when check for update was not performed", () => ).not.toBeInTheDocument() }) test("does not render any label when check for update is in progress", () => { - const { queryByText } = render({ - updateAvailable: true, - checkForUpdatePerformed: true, - checkForUpdateInProgress: true, - }) + const { queryByText } = render({}) expect( queryByText( intl.formatMessage({ id: "module.overview.systemUpdateAvailable" }) @@ -121,10 +200,17 @@ test("does not render any label when check for update is in progress", () => { test("checks for update after button click", () => { const onUpdateCheck = jest.fn() + const props = { onUpdateCheck } - const { getByRole } = render({ - onUpdateCheck, - }) + const { getByRole } = render( + { + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + }, + }, + props + ) fireEvent.click(getByRole("button")) @@ -133,11 +219,20 @@ test("checks for update after button click", () => { test("triggers download after button click", () => { const onDownload = jest.fn() - - const { getByRole } = render({ - updateAvailable: true, - onDownload, - }) + const props = { onDownload } + const { getByRole } = render( + { + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + data: { + ...update.data, + availableReleasesForUpdate: [mockedRelease], + }, + }, + }, + props + ) fireEvent.click(getByRole("button")) @@ -146,12 +241,23 @@ test("triggers download after button click", () => { test("triggers update after button click", () => { const onUpdate = jest.fn() + const props = { onUpdate } - const { getByRole } = render({ - updateAvailable: true, - updateDownloaded: true, - onUpdate, - }) + const { getByRole } = render( + { + update: { + ...update, + silentCheckForUpdate: SilentCheckForUpdateState.Loaded, + data: { + ...update.data, + downloadedProcessedReleases: [ + { release: mockedRelease, state: ReleaseProcessState.Done }, + ], + }, + }, + }, + props + ) fireEvent.click(getByRole("button")) From 5bda7d35e9caa6bc02de8fa74247fd32be80b37f Mon Sep 17 00:00:00 2001 From: patryk-sierzega <126664583+patryk-sierzega@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:12:34 +0200 Subject: [PATCH 5/8] [CP-2079] Merge enums used in invoking methods between main and renderer (#1492) --- packages/app/src/__deprecated__/main/main.ts | 8 ---- .../constants/controller.constant.ts | 26 +++-------- .../analytic-data-tracker.controller.ts | 8 +--- .../set-external-usage-device.request.ts | 4 +- .../requests/set-visitor-metadata.request.ts | 4 +- .../requests/toggle-tracking.request.ts | 4 +- ...ack-unique-without-device-check.request.ts | 4 +- .../requests/track-unique.request.ts | 4 +- .../track-without-device-check.request.ts | 4 +- .../requests/track.request.ts | 4 +- .../backup/constants/controller.constant.ts | 12 ++--- .../backup/controllers/backup.controller.ts | 9 +--- .../backup/requests/create-backup.request.ts | 4 +- .../backup/requests/load-backups.request.ts | 4 +- .../backup/requests/restore-backup.request.ts | 4 +- .../contacts/constants/controller.constant.ts | 14 ++---- .../controllers/contact.controller.ts | 5 +-- .../requests/create-contact.request.ts | 4 +- .../requests/delete-contacts.request.ts | 7 +-- .../contacts/requests/edit-contact.request.ts | 8 ++-- packages/app/src/core/application.module.ts | 2 - .../initializers/controller.initializer.ts | 8 +--- .../constants/controller.constant.ts | 14 ++---- .../controllers/crash-dump.controller.ts | 7 ++- .../requests/download-crash-dump.request.ts | 4 +- .../requests/get-crash-dumps.request.ts | 4 +- .../requests/ignore-crash-dump.request.ts | 4 +- .../constants/controller.constant.ts | 14 ++---- .../controllers/data-sync.controller.ts | 9 +--- .../requests/get-index.request.test.ts | 4 +- .../data-sync/requests/get-index.request.ts | 4 +- .../requests/index-all.request.test.ts | 4 +- .../data-sync/requests/index-all.request.ts | 4 +- .../requests/initialize-data-sync.request.ts | 4 +- .../constants/controller.constant.ts | 17 ++----- .../device-file-system.controller.ts | 8 +--- .../requests/download-device-file.request.ts | 4 +- .../requests/remove-file.request.ts | 4 +- .../upload-device-file-locally.request.ts | 4 +- .../requests/upload-device-file.request.ts | 4 +- .../constants/controller.constant.ts | 8 +--- .../controllers/device-info.controller.ts | 5 +-- .../requests/get-device-info.request.ts | 4 +- .../constants/controller.constant.ts | 8 +--- .../controllers/device-log.controller.ts | 5 +-- .../requests/get-device-log-files.request.ts | 4 +- .../constants/controller.constant.ts | 10 +---- .../controllers/device-manager.controller.ts | 18 +------- .../requests/get-current-device.request.ts | 4 +- .../device/constants/controller.constant.ts | 20 +++------ .../device/controllers/device.controller.ts | 5 +-- .../device/requests/connect-device.request.ts | 4 +- .../requests/device-lock-time.request.ts | 4 +- .../device/requests/set-updating.request.ts | 4 +- .../requests/unlock-device-status.request.ts | 7 +-- .../device/requests/unlock-device.request.ts | 4 +- .../constants/controller.constant.ts | 14 ------ .../file-system/constants/error.constant.ts | 8 ---- .../app/src/file-system/constants/index.ts | 8 ---- .../constants/ipc-file-system.enum.ts | 11 ----- .../dialog-file-system.controller.ts | 26 ----------- .../app/src/file-system/controllers/index.ts | 6 --- .../file-system/dto/get-paths-input.object.ts | 11 ----- packages/app/src/file-system/dto/index.ts | 6 --- .../app/src/file-system/file-system.module.ts | 44 ------------------- .../helpers/array-buffer-to-buffer.test.ts | 22 ---------- .../helpers/array-buffer-to-buffer.ts | 18 -------- packages/app/src/file-system/helpers/index.ts | 6 --- .../listeners/decrypt-file.listener.ts | 21 --------- .../listeners/encrypt-file.listener.ts | 21 --------- .../app/src/file-system/listeners/index.ts | 9 ---- .../listeners/read-file.listener.ts | 19 -------- .../listeners/unlink-file.listener.ts | 21 --------- .../requests/decrypt-file.request.ts | 16 ------- .../requests/encrypt-file.request.ts | 16 ------- .../file-system/requests/get-paths.request.ts | 15 ------- .../app/src/file-system/requests/index.ts | 6 --- .../file-system/requests/read-file.request.ts | 16 ------- .../requests/unlink-file.request.ts | 16 ------- .../file-system-dialog.service.test.ts | 42 ------------------ .../services/file-system-dialog.service.ts | 28 ------------ .../app/src/file-system/services/index.ts | 6 --- .../actions/upload-file.action.test.ts | 1 - .../constants/controller.constant.ts | 14 ++---- .../controllers/files-manager.controller.ts | 8 +--- .../requests/delete-files.request.ts | 4 +- .../requests/get-files.request.ts | 4 +- .../requests/upload-files.request.ts | 4 +- .../messages/constants/controller.constant.ts | 28 +++--------- .../controllers/message.controller.ts | 8 +--- .../messages/controllers/thread.controller.ts | 8 +--- .../requests/create-message.request.ts | 4 +- .../requests/delete-message.request.ts | 4 +- .../requests/delete-threads.request.ts | 4 +- .../requests/resend-message.request.ts | 4 +- .../toggle-threads-read-status.request.ts | 4 +- .../requests/update-message.request.ts | 4 +- .../search/constants/controller.constant.ts | 8 +--- .../search/controllers/search.controller.ts | 5 +-- .../app/src/search/requests/search.request.ts | 4 +- .../settings/constants/controller.constant.ts | 21 ++------- .../controllers/configuration.controller.ts | 8 +--- .../controllers/settings.controller.ts | 8 +--- .../requests/get-configuration.request.ts | 4 +- .../settings/requests/get-settings.request.ts | 4 +- .../requests/reset-settings.request.ts | 4 +- .../requests/update-settings.request.ts | 4 +- .../constants/controller.constant.ts | 17 ++----- .../controllers/template.controller.ts | 5 +-- .../requests/create-template.request.ts | 4 +- .../requests/delete-templates.request.ts | 4 +- .../requests/update-template-order.request.ts | 4 +- .../requests/update-template.request.ts | 4 +- .../update/constants/controller.constant.ts | 27 +++--------- .../controllers/device-update.controller.ts | 8 +--- .../update/controllers/releases.controller.ts | 9 +--- .../update/requests/checkUpdate.request.ts | 4 +- .../requests/get-all-releases.request.ts | 4 +- .../requests/get-latest-release.request.ts | 4 +- .../get-releases-by-versions.request.ts | 4 +- .../remove-downloaded-os-updates.request.ts | 4 +- .../requests/start-os-update.request.ts | 4 +- 122 files changed, 212 insertions(+), 881 deletions(-) delete mode 100644 packages/app/src/file-system/constants/controller.constant.ts delete mode 100644 packages/app/src/file-system/constants/error.constant.ts delete mode 100644 packages/app/src/file-system/constants/index.ts delete mode 100644 packages/app/src/file-system/constants/ipc-file-system.enum.ts delete mode 100644 packages/app/src/file-system/controllers/dialog-file-system.controller.ts delete mode 100644 packages/app/src/file-system/controllers/index.ts delete mode 100644 packages/app/src/file-system/dto/get-paths-input.object.ts delete mode 100644 packages/app/src/file-system/dto/index.ts delete mode 100644 packages/app/src/file-system/file-system.module.ts delete mode 100644 packages/app/src/file-system/helpers/array-buffer-to-buffer.test.ts delete mode 100644 packages/app/src/file-system/helpers/array-buffer-to-buffer.ts delete mode 100644 packages/app/src/file-system/helpers/index.ts delete mode 100644 packages/app/src/file-system/listeners/decrypt-file.listener.ts delete mode 100644 packages/app/src/file-system/listeners/encrypt-file.listener.ts delete mode 100644 packages/app/src/file-system/listeners/index.ts delete mode 100644 packages/app/src/file-system/listeners/read-file.listener.ts delete mode 100644 packages/app/src/file-system/listeners/unlink-file.listener.ts delete mode 100644 packages/app/src/file-system/requests/decrypt-file.request.ts delete mode 100644 packages/app/src/file-system/requests/encrypt-file.request.ts delete mode 100644 packages/app/src/file-system/requests/get-paths.request.ts delete mode 100644 packages/app/src/file-system/requests/index.ts delete mode 100644 packages/app/src/file-system/requests/read-file.request.ts delete mode 100644 packages/app/src/file-system/requests/unlink-file.request.ts delete mode 100644 packages/app/src/file-system/services/file-system-dialog.service.test.ts delete mode 100644 packages/app/src/file-system/services/file-system-dialog.service.ts delete mode 100644 packages/app/src/file-system/services/index.ts diff --git a/packages/app/src/__deprecated__/main/main.ts b/packages/app/src/__deprecated__/main/main.ts index 4968cfbfd6..034910d35c 100644 --- a/packages/app/src/__deprecated__/main/main.ts +++ b/packages/app/src/__deprecated__/main/main.ts @@ -24,11 +24,7 @@ import registerCopyFileListener from "App/__deprecated__/main/functions/register import registerWriteGzipListener from "App/__deprecated__/main/functions/register-write-gzip-listener" import registerRmdirListener from "App/__deprecated__/main/functions/register-rmdir-listener" import registerArchiveFilesListener from "App/__deprecated__/main/functions/register-archive-files-listener" -import registerReadFileListener from "App/file-system/listeners/read-file.listener" import createDownloadListenerRegistrar from "App/__deprecated__/main/functions/create-download-listener-registrar" -import registerEncryptFileListener from "App/file-system/listeners/encrypt-file.listener" -import registerDecryptFileListener from "App/file-system/listeners/decrypt-file.listener" -import registerUnlinkFileListener from "App/file-system/listeners/unlink-file.listener" import { registerDownloadHelpHandler, removeDownloadHelpHandler, @@ -196,10 +192,6 @@ const createWindow = async () => { registerRmdirListener() registerWriteGzipListener() registerArchiveFilesListener() - registerEncryptFileListener() - registerReadFileListener() - registerUnlinkFileListener() - registerDecryptFileListener() registerMetadataAllGetValueListener() registerMetadataGetValueListener() registerMetadataSetValueListener() diff --git a/packages/app/src/analytic-data-tracker/constants/controller.constant.ts b/packages/app/src/analytic-data-tracker/constants/controller.constant.ts index 1efb0ea5f4..c1205a8d77 100644 --- a/packages/app/src/analytic-data-tracker/constants/controller.constant.ts +++ b/packages/app/src/analytic-data-tracker/constants/controller.constant.ts @@ -3,24 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "analytic-data-tracker" - export enum IpcAnalyticDataTrackerEvent { - Track = "track", - TrackUnique = "track-unique", - TrackWithoutDeviceCheck = "track-without-device-check", - TrackUniqueWithoutDeviceCheck = "track-unique-without-device-check", - ToggleTracking = "toggle-tracking", - SetExternalUsageDevice = "set-external-usage-device", - SetVisitorMetadata = "set-visitor-metadata", -} - -export enum IpcAnalyticDataTrackerRequest { - Track = "analytic-data-tracker-track", - TrackUnique = "analytic-data-tracker-track-unique", - TrackWithoutDeviceCheck = "analytic-data-tracker-track-without-device-check", - TrackUniqueWithoutDeviceCheck = "analytic-data-tracker-track-unique-without-device-check", - ToggleTracking = "analytic-data-tracker-toggle-tracking", - SetExternalUsageDevice = "analytic-data-tracker-set-external-usage-device", - SetVisitorMetadata = "analytic-data-tracker-set-visitor-metadata", + Track = "analytic_track", + TrackUnique = "analytic_track-unique", + TrackWithoutDeviceCheck = "analytic_track-without-device-check", + TrackUniqueWithoutDeviceCheck = "analytic_track-unique-without-device-check", + ToggleTracking = "analytic_toggle-tracking", + SetExternalUsageDevice = "analytic_set-external-usage-device", + SetVisitorMetadata = "analytic_set-visitor-metadata", } diff --git a/packages/app/src/analytic-data-tracker/controllers/analytic-data-tracker.controller.ts b/packages/app/src/analytic-data-tracker/controllers/analytic-data-tracker.controller.ts index 20ad83e23c..bbe0538b89 100644 --- a/packages/app/src/analytic-data-tracker/controllers/analytic-data-tracker.controller.ts +++ b/packages/app/src/analytic-data-tracker/controllers/analytic-data-tracker.controller.ts @@ -3,18 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" -import { - ControllerPrefix, - IpcAnalyticDataTrackerEvent, -} from "App/analytic-data-tracker/constants" +import { IpcEvent } from "App/core/decorators" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" import { AnalyticDataTrackerClass, VisitorMetadata, } from "App/analytic-data-tracker/services" import { TrackEvent } from "App/analytic-data-tracker/types" -@Controller(ControllerPrefix) export class AnalyticDataTrackerController { constructor(private tracker: AnalyticDataTrackerClass) {} diff --git a/packages/app/src/analytic-data-tracker/requests/set-external-usage-device.request.ts b/packages/app/src/analytic-data-tracker/requests/set-external-usage-device.request.ts index 03bcd5717c..0859c8394e 100644 --- a/packages/app/src/analytic-data-tracker/requests/set-external-usage-device.request.ts +++ b/packages/app/src/analytic-data-tracker/requests/set-external-usage-device.request.ts @@ -4,13 +4,13 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" export const setExternalUsageDeviceRequest = async ( flag: boolean ): Promise => { return ipcRenderer.callMain( - IpcAnalyticDataTrackerRequest.SetExternalUsageDevice, + IpcAnalyticDataTrackerEvent.SetExternalUsageDevice, flag ) } diff --git a/packages/app/src/analytic-data-tracker/requests/set-visitor-metadata.request.ts b/packages/app/src/analytic-data-tracker/requests/set-visitor-metadata.request.ts index 30f4f3145c..1dfe99e739 100644 --- a/packages/app/src/analytic-data-tracker/requests/set-visitor-metadata.request.ts +++ b/packages/app/src/analytic-data-tracker/requests/set-visitor-metadata.request.ts @@ -4,14 +4,14 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" import { VisitorMetadata } from "App/analytic-data-tracker/services" export const setVisitorMetadataRequest = async ( visitorMetadata: VisitorMetadata ): Promise => { return ipcRenderer.callMain( - IpcAnalyticDataTrackerRequest.SetVisitorMetadata, + IpcAnalyticDataTrackerEvent.SetVisitorMetadata, visitorMetadata ) } diff --git a/packages/app/src/analytic-data-tracker/requests/toggle-tracking.request.ts b/packages/app/src/analytic-data-tracker/requests/toggle-tracking.request.ts index b91fe7f5f7..8248fc9535 100644 --- a/packages/app/src/analytic-data-tracker/requests/toggle-tracking.request.ts +++ b/packages/app/src/analytic-data-tracker/requests/toggle-tracking.request.ts @@ -4,8 +4,8 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" export const toggleTrackingRequest = async (flag: boolean): Promise => { - return ipcRenderer.callMain(IpcAnalyticDataTrackerRequest.ToggleTracking, flag) + return ipcRenderer.callMain(IpcAnalyticDataTrackerEvent.ToggleTracking, flag) } diff --git a/packages/app/src/analytic-data-tracker/requests/track-unique-without-device-check.request.ts b/packages/app/src/analytic-data-tracker/requests/track-unique-without-device-check.request.ts index 92cfe70d6c..273e3fd32a 100644 --- a/packages/app/src/analytic-data-tracker/requests/track-unique-without-device-check.request.ts +++ b/packages/app/src/analytic-data-tracker/requests/track-unique-without-device-check.request.ts @@ -4,14 +4,14 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" import { TrackEvent } from "App/analytic-data-tracker/types" export const trackUniqueWithoutDeviceCheckRequest = async ( event: TrackEvent ): Promise => { return ipcRenderer.callMain( - IpcAnalyticDataTrackerRequest.TrackUniqueWithoutDeviceCheck, + IpcAnalyticDataTrackerEvent.TrackUniqueWithoutDeviceCheck, event ) } diff --git a/packages/app/src/analytic-data-tracker/requests/track-unique.request.ts b/packages/app/src/analytic-data-tracker/requests/track-unique.request.ts index d426233c93..b883df4458 100644 --- a/packages/app/src/analytic-data-tracker/requests/track-unique.request.ts +++ b/packages/app/src/analytic-data-tracker/requests/track-unique.request.ts @@ -4,9 +4,9 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" import { TrackEvent } from "App/analytic-data-tracker/types" export const trackUniqueRequest = async (event: TrackEvent): Promise => { - return ipcRenderer.callMain(IpcAnalyticDataTrackerRequest.TrackUnique, event) + return ipcRenderer.callMain(IpcAnalyticDataTrackerEvent.TrackUnique, event) } diff --git a/packages/app/src/analytic-data-tracker/requests/track-without-device-check.request.ts b/packages/app/src/analytic-data-tracker/requests/track-without-device-check.request.ts index bdab76cbb5..531819eab4 100644 --- a/packages/app/src/analytic-data-tracker/requests/track-without-device-check.request.ts +++ b/packages/app/src/analytic-data-tracker/requests/track-without-device-check.request.ts @@ -4,14 +4,14 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" import { TrackEvent } from "App/analytic-data-tracker/types" export const trackWithoutDeviceCheckRequest = async ( event: TrackEvent ): Promise => { return ipcRenderer.callMain( - IpcAnalyticDataTrackerRequest.TrackWithoutDeviceCheck, + IpcAnalyticDataTrackerEvent.TrackWithoutDeviceCheck, event ) } diff --git a/packages/app/src/analytic-data-tracker/requests/track.request.ts b/packages/app/src/analytic-data-tracker/requests/track.request.ts index ee069af304..e58853c209 100644 --- a/packages/app/src/analytic-data-tracker/requests/track.request.ts +++ b/packages/app/src/analytic-data-tracker/requests/track.request.ts @@ -4,9 +4,9 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants" +import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants" import { TrackEvent } from "App/analytic-data-tracker/types" export const trackRequest = async (event: TrackEvent): Promise => { - return ipcRenderer.callMain(IpcAnalyticDataTrackerRequest.Track, event) + return ipcRenderer.callMain(IpcAnalyticDataTrackerEvent.Track, event) } diff --git a/packages/app/src/backup/constants/controller.constant.ts b/packages/app/src/backup/constants/controller.constant.ts index 847278ffa4..3feb5126d7 100644 --- a/packages/app/src/backup/constants/controller.constant.ts +++ b/packages/app/src/backup/constants/controller.constant.ts @@ -6,13 +6,7 @@ export const ControllerPrefix = "backup" export enum IpcBackupEvent { - LoadBackups = "load-backups", - CreateBackup = "create-backup", - RestoreBackup = "restore-backup", -} - -export enum IpcBackupRequest { - LoadBackups = "backup-load-backups", - CreateBackup = "backup-create-backup", - RestoreBackup = "backup-restore-backup", + LoadBackups = "backup_load-backups", + CreateBackup = "backup_create-backup", + RestoreBackup = "backup_restore-backup", } diff --git a/packages/app/src/backup/controllers/backup.controller.ts b/packages/app/src/backup/controllers/backup.controller.ts index 49cc25adc0..6e87d983c0 100644 --- a/packages/app/src/backup/controllers/backup.controller.ts +++ b/packages/app/src/backup/controllers/backup.controller.ts @@ -3,14 +3,10 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject } from "App/core/builder" import { Backup } from "App/backup/dto" -import { - BackupError, - ControllerPrefix, - IpcBackupEvent, -} from "App/backup/constants" +import { BackupError, IpcBackupEvent } from "App/backup/constants" import { BackupCreateService, BackupRestoreService, @@ -18,7 +14,6 @@ import { } from "App/backup/services" import { CreateDeviceBackup, RestoreDeviceBackup } from "App/backup/types" -@Controller(ControllerPrefix) export class BackupController { constructor( private backupCreateService: BackupCreateService, diff --git a/packages/app/src/backup/requests/create-backup.request.ts b/packages/app/src/backup/requests/create-backup.request.ts index 2e10092a4c..4e09e89ad5 100644 --- a/packages/app/src/backup/requests/create-backup.request.ts +++ b/packages/app/src/backup/requests/create-backup.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcBackupRequest } from "App/backup/constants" +import { IpcBackupEvent } from "App/backup/constants" import { CreateDeviceBackup } from "App/backup/types" export const createBackupRequest = async ( options: CreateDeviceBackup ): Promise> => { - return ipcRenderer.callMain(IpcBackupRequest.CreateBackup, options) + return ipcRenderer.callMain(IpcBackupEvent.CreateBackup, options) } diff --git a/packages/app/src/backup/requests/load-backups.request.ts b/packages/app/src/backup/requests/load-backups.request.ts index 06e27830ba..8994c82efd 100644 --- a/packages/app/src/backup/requests/load-backups.request.ts +++ b/packages/app/src/backup/requests/load-backups.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcBackupRequest } from "App/backup/constants" +import { IpcBackupEvent } from "App/backup/constants" import { Backup } from "App/backup/dto" export const loadBackupsRequest = async ( options: string ): Promise> => { - return ipcRenderer.callMain(IpcBackupRequest.LoadBackups, options) + return ipcRenderer.callMain(IpcBackupEvent.LoadBackups, options) } diff --git a/packages/app/src/backup/requests/restore-backup.request.ts b/packages/app/src/backup/requests/restore-backup.request.ts index 52507d91b9..6d37ef66cb 100644 --- a/packages/app/src/backup/requests/restore-backup.request.ts +++ b/packages/app/src/backup/requests/restore-backup.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { BackupError, IpcBackupRequest } from "App/backup/constants" +import { BackupError, IpcBackupEvent } from "App/backup/constants" import { RestoreDeviceBackup } from "App/backup/types" export const restoreBackupRequest = async ( options: RestoreDeviceBackup ): Promise> => { - return ipcRenderer.callMain(IpcBackupRequest.RestoreBackup, options) + return ipcRenderer.callMain(IpcBackupEvent.RestoreBackup, options) } diff --git a/packages/app/src/contacts/constants/controller.constant.ts b/packages/app/src/contacts/constants/controller.constant.ts index e260d139a9..e52d07deb8 100644 --- a/packages/app/src/contacts/constants/controller.constant.ts +++ b/packages/app/src/contacts/constants/controller.constant.ts @@ -3,16 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "contact" - export enum IpcContactEvent { - CreateContact = "create-contact", - EditContact = "edit-contact", - DeleteContacts = "delete-contacts", -} - -export enum IpcContactRequest { - CreateContact = "contact-create-contact", - EditContact = "contact-edit-contact", - DeleteContacts = "contact-delete-contacts", + CreateContact = "contact_create-contact", + EditContact = "contact_edit-contact", + DeleteContacts = "contact_delete-contacts", } diff --git a/packages/app/src/contacts/controllers/contact.controller.ts b/packages/app/src/contacts/controllers/contact.controller.ts index bab91fb2d0..08bef10542 100644 --- a/packages/app/src/contacts/controllers/contact.controller.ts +++ b/packages/app/src/contacts/controllers/contact.controller.ts @@ -3,13 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ContactService } from "App/contacts/services" import { RequestResponse } from "App/core/types/request-response.interface" -import { ControllerPrefix, IpcContactEvent } from "App/contacts/constants" +import { IpcContactEvent } from "App/contacts/constants" import { Contact, ContactID } from "App/contacts/reducers" -@Controller(ControllerPrefix) export class ContactController { constructor(private contactService: ContactService) {} diff --git a/packages/app/src/contacts/requests/create-contact.request.ts b/packages/app/src/contacts/requests/create-contact.request.ts index 748851ac5f..c7e045177e 100644 --- a/packages/app/src/contacts/requests/create-contact.request.ts +++ b/packages/app/src/contacts/requests/create-contact.request.ts @@ -4,12 +4,12 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcContactRequest } from "App/contacts/constants" +import { IpcContactEvent } from "App/contacts/constants" import { Contact, NewContact } from "App/contacts/reducers/contacts.interface" import { RequestResponse } from "App/core/types/request-response.interface" export const createContactRequest = async ( newContact: NewContact ): Promise> => { - return ipcRenderer.callMain(IpcContactRequest.CreateContact, newContact) + return ipcRenderer.callMain(IpcContactEvent.CreateContact, newContact) } diff --git a/packages/app/src/contacts/requests/delete-contacts.request.ts b/packages/app/src/contacts/requests/delete-contacts.request.ts index 88b43907b1..78dedb4732 100644 --- a/packages/app/src/contacts/requests/delete-contacts.request.ts +++ b/packages/app/src/contacts/requests/delete-contacts.request.ts @@ -4,15 +4,12 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcContactRequest } from "App/contacts/constants" +import { IpcContactEvent } from "App/contacts/constants" import { ContactID } from "App/contacts/reducers/contacts.interface" import { RequestResponse } from "App/core/types/request-response.interface" export const deleteContactsRequest = async ( contactIds: ContactID[] ): Promise> => { - return await ipcRenderer.callMain( - IpcContactRequest.DeleteContacts, - contactIds - ) + return await ipcRenderer.callMain(IpcContactEvent.DeleteContacts, contactIds) } diff --git a/packages/app/src/contacts/requests/edit-contact.request.ts b/packages/app/src/contacts/requests/edit-contact.request.ts index 1f03d18202..c4066f034f 100644 --- a/packages/app/src/contacts/requests/edit-contact.request.ts +++ b/packages/app/src/contacts/requests/edit-contact.request.ts @@ -4,10 +4,12 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcContactRequest } from "App/contacts/constants" +import { IpcContactEvent } from "App/contacts/constants" import { Contact } from "App/contacts/reducers/contacts.interface" import { RequestResponse } from "App/core/types/request-response.interface" -export const editContactRequest = (contact: Contact): Promise> => { - return ipcRenderer.callMain(IpcContactRequest.EditContact, contact) +export const editContactRequest = ( + contact: Contact +): Promise> => { + return ipcRenderer.callMain(IpcContactEvent.EditContact, contact) } diff --git a/packages/app/src/core/application.module.ts b/packages/app/src/core/application.module.ts index 5398d90fd9..701595122f 100644 --- a/packages/app/src/core/application.module.ts +++ b/packages/app/src/core/application.module.ts @@ -21,7 +21,6 @@ import { } from "App/core/initializers" import { Module } from "App/core/types" import { FileSystemService } from "App/file-system/services/file-system.service.refactored" -import { FileSystemModule } from "App/file-system/file-system.module" import { IndexStorageModule } from "App/index-storage/index-storage.module" import { DataSyncModule } from "App/data-sync/data-sync.module" import { ContactModule } from "App/contacts/contact.module" @@ -48,7 +47,6 @@ import { export class ApplicationModule { public modules: Module[] = [ DeviceInfoModule, - FileSystemModule, IndexStorageModule, OutboxModule, AnalyticDataTrackerModule, diff --git a/packages/app/src/core/initializers/controller.initializer.ts b/packages/app/src/core/initializers/controller.initializer.ts index 4df8bda649..970c80dbfd 100644 --- a/packages/app/src/core/initializers/controller.initializer.ts +++ b/packages/app/src/core/initializers/controller.initializer.ts @@ -10,12 +10,6 @@ import { EventDefinition, Controller } from "App/core/types" export class ControllerInitializer { public initialize(controllers: Controller[]): void { controllers.forEach((controller) => { - // AUTO DISABLED - fix me if you like :) - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const prefix = Reflect.getMetadata( - ReflectKey.Prefix, - controller.constructor - ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const events: EventDefinition[] = Reflect.getMetadata( @@ -26,7 +20,7 @@ export class ControllerInitializer { events.forEach((event) => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/require-await - ipcMain.answerRenderer(`${prefix}-${event.name}`, async (data) => { + ipcMain.answerRenderer(event.name, (data) => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any return (controller as Record)[event.methodName](data) diff --git a/packages/app/src/crash-dump/constants/controller.constant.ts b/packages/app/src/crash-dump/constants/controller.constant.ts index 392c7c355e..c01b2b9a25 100644 --- a/packages/app/src/crash-dump/constants/controller.constant.ts +++ b/packages/app/src/crash-dump/constants/controller.constant.ts @@ -3,16 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "crash-dump" - export enum IpcCrashDumpEvent { - Ignore = "ignore-file", - GetFiles = "get-files", - DownloadFiles = "download-files", -} - -export enum IpcCrashDumpRequest { - Ignore = "crash-dump-ignore-file", - GetFiles = "crash-dump-get-files", - DownloadCrashDump = "crash-dump-download-files", + Ignore = "crash-dump_ignore-file", + GetFiles = "crash-dump_get-files", + DownloadCrashDump = "crash-dump_download-files", } diff --git a/packages/app/src/crash-dump/controllers/crash-dump.controller.ts b/packages/app/src/crash-dump/controllers/crash-dump.controller.ts index 01f8900cfe..7642a94e77 100644 --- a/packages/app/src/crash-dump/controllers/crash-dump.controller.ts +++ b/packages/app/src/crash-dump/controllers/crash-dump.controller.ts @@ -3,20 +3,19 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { RequestResponse } from "App/core/types" import { SettingsService } from "App/settings/services" -import { ControllerPrefix, IpcCrashDumpEvent } from "App/crash-dump/constants" +import { IpcCrashDumpEvent } from "App/crash-dump/constants" import { CrashDumpService } from "App/crash-dump/services" -@Controller(ControllerPrefix) export class CrashDumpController { constructor( private crashDumpService: CrashDumpService, private settingsService: SettingsService ) {} - @IpcEvent(IpcCrashDumpEvent.DownloadFiles) + @IpcEvent(IpcCrashDumpEvent.DownloadCrashDump) public async downloadFile(): Promise> { const result = await this.crashDumpService.downloadDeviceCrashDumpFiles() this.settingsService.updateSettings({ diff --git a/packages/app/src/crash-dump/requests/download-crash-dump.request.ts b/packages/app/src/crash-dump/requests/download-crash-dump.request.ts index 8149db2139..b689a63f1d 100644 --- a/packages/app/src/crash-dump/requests/download-crash-dump.request.ts +++ b/packages/app/src/crash-dump/requests/download-crash-dump.request.ts @@ -5,10 +5,10 @@ import { ipcRenderer } from "electron-better-ipc" import { RequestResponse } from "App/core/types/request-response.interface" -import { IpcCrashDumpRequest } from "App/crash-dump/constants" +import { IpcCrashDumpEvent } from "App/crash-dump/constants" export const downloadCrashDumpRequest = async (): Promise< RequestResponse > => { - return ipcRenderer.callMain(IpcCrashDumpRequest.DownloadCrashDump) + return ipcRenderer.callMain(IpcCrashDumpEvent.DownloadCrashDump) } diff --git a/packages/app/src/crash-dump/requests/get-crash-dumps.request.ts b/packages/app/src/crash-dump/requests/get-crash-dumps.request.ts index c67cb95391..e1876ba507 100644 --- a/packages/app/src/crash-dump/requests/get-crash-dumps.request.ts +++ b/packages/app/src/crash-dump/requests/get-crash-dumps.request.ts @@ -5,10 +5,10 @@ import { ipcRenderer } from "electron-better-ipc" import { RequestResponse } from "App/core/types/request-response.interface" -import { IpcCrashDumpRequest } from "App/crash-dump/constants" +import { IpcCrashDumpEvent } from "App/crash-dump/constants" export const getCrashDumpsRequest = async (): Promise< RequestResponse > => { - return ipcRenderer.callMain(IpcCrashDumpRequest.GetFiles) + return ipcRenderer.callMain(IpcCrashDumpEvent.GetFiles) } diff --git a/packages/app/src/crash-dump/requests/ignore-crash-dump.request.ts b/packages/app/src/crash-dump/requests/ignore-crash-dump.request.ts index bde6a1c546..88694db34c 100644 --- a/packages/app/src/crash-dump/requests/ignore-crash-dump.request.ts +++ b/packages/app/src/crash-dump/requests/ignore-crash-dump.request.ts @@ -5,10 +5,10 @@ import { ipcRenderer } from "electron-better-ipc" import { RequestResponse } from "App/core/types/request-response.interface" -import { IpcCrashDumpRequest } from "App/crash-dump/constants" +import { IpcCrashDumpEvent } from "App/crash-dump/constants" export const ignoreCrashDumpRequest = async ( url: string ): Promise> => { - return ipcRenderer.callMain(IpcCrashDumpRequest.Ignore, url) + return ipcRenderer.callMain(IpcCrashDumpEvent.Ignore, url) } diff --git a/packages/app/src/data-sync/constants/controller.constant.ts b/packages/app/src/data-sync/constants/controller.constant.ts index 3a053876e6..b7afedea93 100644 --- a/packages/app/src/data-sync/constants/controller.constant.ts +++ b/packages/app/src/data-sync/constants/controller.constant.ts @@ -3,16 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "data-sync" - export enum IpcDataSyncEvent { - GetIndex = "get-index", - IndexAll = "index-all", - InitializeDataSync = "initialize", -} - -export enum IpcDataSyncRequest { - GetIndex = "data-sync-get-index", - IndexAll = "data-sync-index-all", - InitializeDataSync = "data-sync-initialize", + GetIndex = "data-sync_get-index", + IndexAll = "data-sync_index-all", + InitializeDataSync = "data-sync_initialize", } diff --git a/packages/app/src/data-sync/controllers/data-sync.controller.ts b/packages/app/src/data-sync/controllers/data-sync.controller.ts index 785fa1b235..0bae874975 100644 --- a/packages/app/src/data-sync/controllers/data-sync.controller.ts +++ b/packages/app/src/data-sync/controllers/data-sync.controller.ts @@ -3,17 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { IndexStorage } from "App/index-storage/types" import { DataSyncService } from "App/data-sync/services/data-sync.service" -import { - ControllerPrefix, - IpcDataSyncEvent, - DataIndex, -} from "App/data-sync/constants" +import { IpcDataSyncEvent, DataIndex } from "App/data-sync/constants" import { SerialisedIndexData } from "elasticlunr" -@Controller(ControllerPrefix) export class DataSyncController { constructor( private index: IndexStorage, diff --git a/packages/app/src/data-sync/requests/get-index.request.test.ts b/packages/app/src/data-sync/requests/get-index.request.test.ts index ab1a449cce..5449758589 100644 --- a/packages/app/src/data-sync/requests/get-index.request.test.ts +++ b/packages/app/src/data-sync/requests/get-index.request.test.ts @@ -4,7 +4,7 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcDataSyncRequest, DataIndex } from "App/data-sync/constants" +import { IpcDataSyncEvent, DataIndex } from "App/data-sync/constants" import { getIndexRequest } from "App/data-sync/requests" import { SerialisedIndexData } from "elasticlunr" @@ -24,7 +24,7 @@ describe("`getIndexRequest`", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any ;(ipcRenderer as any).__rendererCalls = { - [IpcDataSyncRequest.GetIndex]: getIndexResponse, + [IpcDataSyncEvent.GetIndex]: getIndexResponse, } const response = await getIndexRequest(DataIndex.Contact) expect(response).toEqual(getIndexResponse) diff --git a/packages/app/src/data-sync/requests/get-index.request.ts b/packages/app/src/data-sync/requests/get-index.request.ts index 9b3bc2b77c..2e10206d8a 100644 --- a/packages/app/src/data-sync/requests/get-index.request.ts +++ b/packages/app/src/data-sync/requests/get-index.request.ts @@ -5,12 +5,12 @@ import { ipcRenderer } from "electron-better-ipc" import { SerialisedIndexData } from "elasticlunr" -import { IpcDataSyncRequest, DataIndex } from "App/data-sync/constants" +import { IpcDataSyncEvent, DataIndex } from "App/data-sync/constants" // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/ban-types export const getIndexRequest = async ( indexName: DataIndex ): Promise | undefined> => { - return ipcRenderer.callMain(IpcDataSyncRequest.GetIndex, indexName) + return ipcRenderer.callMain(IpcDataSyncEvent.GetIndex, indexName) } diff --git a/packages/app/src/data-sync/requests/index-all.request.test.ts b/packages/app/src/data-sync/requests/index-all.request.test.ts index 58ddccc961..30495142b6 100644 --- a/packages/app/src/data-sync/requests/index-all.request.test.ts +++ b/packages/app/src/data-sync/requests/index-all.request.test.ts @@ -4,7 +4,7 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcDataSyncRequest } from "App/data-sync/constants" +import { IpcDataSyncEvent } from "App/data-sync/constants" import { indexAllRequest } from "App/data-sync/requests/index-all.request" describe("`indexAllRequest`", () => { @@ -12,7 +12,7 @@ describe("`indexAllRequest`", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any ;(ipcRenderer as any).__rendererCalls = { - [IpcDataSyncRequest.IndexAll]: undefined, + [IpcDataSyncEvent.IndexAll]: undefined, } const response = await indexAllRequest() expect(response).toBeUndefined() diff --git a/packages/app/src/data-sync/requests/index-all.request.ts b/packages/app/src/data-sync/requests/index-all.request.ts index 578baa3e55..e9dac7d0da 100644 --- a/packages/app/src/data-sync/requests/index-all.request.ts +++ b/packages/app/src/data-sync/requests/index-all.request.ts @@ -4,8 +4,8 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcDataSyncRequest } from "App/data-sync/constants" +import { IpcDataSyncEvent } from "App/data-sync/constants" export const indexAllRequest = async (): Promise => { - return ipcRenderer.callMain(IpcDataSyncRequest.IndexAll) + return ipcRenderer.callMain(IpcDataSyncEvent.IndexAll) } diff --git a/packages/app/src/data-sync/requests/initialize-data-sync.request.ts b/packages/app/src/data-sync/requests/initialize-data-sync.request.ts index 47e35d2f3d..516c4167c5 100644 --- a/packages/app/src/data-sync/requests/initialize-data-sync.request.ts +++ b/packages/app/src/data-sync/requests/initialize-data-sync.request.ts @@ -4,11 +4,11 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcDataSyncRequest } from "App/data-sync/constants" +import { IpcDataSyncEvent } from "App/data-sync/constants" import { InitializeOptions } from "App/data-sync/types" export const initializeDataSyncRequest = async ( options: InitializeOptions ): Promise => { - return ipcRenderer.callMain(IpcDataSyncRequest.InitializeDataSync, options) + return ipcRenderer.callMain(IpcDataSyncEvent.InitializeDataSync, options) } diff --git a/packages/app/src/device-file-system/constants/controller.constant.ts b/packages/app/src/device-file-system/constants/controller.constant.ts index 4746ccefb6..28e2c5743b 100644 --- a/packages/app/src/device-file-system/constants/controller.constant.ts +++ b/packages/app/src/device-file-system/constants/controller.constant.ts @@ -3,18 +3,9 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "device-file-system" - export enum IpcDeviceFileSystemEvent { - DownloadDeviceFiles = "download-device-files", - RemoveDeviceFile = "remove-device-file", - UploadFileLocally = "upload-file-locally", - UploadFileToDevice = "upload-file-to-device", -} - -export enum IpcDeviceFileSystemRequest { - DownloadDeviceFiles = "device-file-system-download-device-files", - RemoveDeviceFile = "device-file-system-remove-device-file", - UploadFileLocally = "device-file-system-upload-file-locally", - UploadFileToDevice = "device-file-system-upload-file-to-device", + DownloadDeviceFiles = "device-file-system_download-device-files", + RemoveDeviceFile = "device-file-system_remove-device-file", + UploadFileLocally = "device-file-system_upload-file-locally", + UploadFileToDevice = "device-file-system_upload-file-to-device", } diff --git a/packages/app/src/device-file-system/controllers/device-file-system.controller.ts b/packages/app/src/device-file-system/controllers/device-file-system.controller.ts index 080542e8b3..d14f4b5b3b 100644 --- a/packages/app/src/device-file-system/controllers/device-file-system.controller.ts +++ b/packages/app/src/device-file-system/controllers/device-file-system.controller.ts @@ -4,11 +4,8 @@ */ import { ResultObject } from "App/core/builder" -import { Controller, IpcEvent } from "App/core/decorators" -import { - ControllerPrefix, - IpcDeviceFileSystemEvent, -} from "App/device-file-system/constants" +import { IpcEvent } from "App/core/decorators" +import { IpcDeviceFileSystemEvent } from "App/device-file-system/constants" import { DeviceFileSystemService } from "App/device-file-system/services" import { UploadFile, @@ -16,7 +13,6 @@ import { DeviceFile, } from "App/device-file-system/dto" -@Controller(ControllerPrefix) export class DeviceFileSystemController { constructor(private deviceFileSystemService: DeviceFileSystemService) {} diff --git a/packages/app/src/device-file-system/requests/download-device-file.request.ts b/packages/app/src/device-file-system/requests/download-device-file.request.ts index 40f621819f..44c6430c8c 100644 --- a/packages/app/src/device-file-system/requests/download-device-file.request.ts +++ b/packages/app/src/device-file-system/requests/download-device-file.request.ts @@ -5,14 +5,14 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceFileSystemRequest } from "App/device-file-system/constants" +import { IpcDeviceFileSystemEvent } from "App/device-file-system/constants" import { DeviceFile } from "App/device-file-system/dto" export const downloadDeviceFiles = async ( filePaths: string[] ): Promise> => { return ipcRenderer.callMain( - IpcDeviceFileSystemRequest.DownloadDeviceFiles, + IpcDeviceFileSystemEvent.DownloadDeviceFiles, filePaths ) } diff --git a/packages/app/src/device-file-system/requests/remove-file.request.ts b/packages/app/src/device-file-system/requests/remove-file.request.ts index 27f6306d18..9b9b1e652d 100644 --- a/packages/app/src/device-file-system/requests/remove-file.request.ts +++ b/packages/app/src/device-file-system/requests/remove-file.request.ts @@ -5,9 +5,9 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceFileSystemRequest } from "App/device-file-system/constants" +import { IpcDeviceFileSystemEvent } from "App/device-file-system/constants" export const removeFileRequest = ( filePath: string ): Promise> => - ipcRenderer.callMain(IpcDeviceFileSystemRequest.RemoveDeviceFile, filePath) + ipcRenderer.callMain(IpcDeviceFileSystemEvent.RemoveDeviceFile, filePath) diff --git a/packages/app/src/device-file-system/requests/upload-device-file-locally.request.ts b/packages/app/src/device-file-system/requests/upload-device-file-locally.request.ts index 37d7b69a7a..dee38639d5 100644 --- a/packages/app/src/device-file-system/requests/upload-device-file-locally.request.ts +++ b/packages/app/src/device-file-system/requests/upload-device-file-locally.request.ts @@ -5,14 +5,14 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceFileSystemRequest } from "App/device-file-system/constants" +import { IpcDeviceFileSystemEvent } from "App/device-file-system/constants" import { UploadFileLocally, DeviceFile } from "App/device-file-system/dto" export const uploadDeviceFileLocally = async ( payload: UploadFileLocally ): Promise> => { return ipcRenderer.callMain( - IpcDeviceFileSystemRequest.UploadFileLocally, + IpcDeviceFileSystemEvent.UploadFileLocally, payload ) } diff --git a/packages/app/src/device-file-system/requests/upload-device-file.request.ts b/packages/app/src/device-file-system/requests/upload-device-file.request.ts index 64f3740560..507ac9bb02 100644 --- a/packages/app/src/device-file-system/requests/upload-device-file.request.ts +++ b/packages/app/src/device-file-system/requests/upload-device-file.request.ts @@ -5,14 +5,14 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceFileSystemRequest } from "App/device-file-system/constants" +import { IpcDeviceFileSystemEvent } from "App/device-file-system/constants" import { UploadFile } from "App/device-file-system/dto" export const uploadDeviceFile = async ( payload: UploadFile ): Promise> => { return ipcRenderer.callMain( - IpcDeviceFileSystemRequest.UploadFileToDevice, + IpcDeviceFileSystemEvent.UploadFileToDevice, payload ) } diff --git a/packages/app/src/device-info/constants/controller.constant.ts b/packages/app/src/device-info/constants/controller.constant.ts index 2ed4b44e33..6987affae8 100644 --- a/packages/app/src/device-info/constants/controller.constant.ts +++ b/packages/app/src/device-info/constants/controller.constant.ts @@ -3,12 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "device-info" - export enum IpcDeviceInfoEvent { - GetDeviceInfo = "get-device-info", -} - -export enum IpcDeviceInfoRequest { - GetDeviceInfo = "device-info-get-device-info", + GetDeviceInfo = "device-info_get-device-info", } diff --git a/packages/app/src/device-info/controllers/device-info.controller.ts b/packages/app/src/device-info/controllers/device-info.controller.ts index b9a040d6bb..bf397714b5 100644 --- a/packages/app/src/device-info/controllers/device-info.controller.ts +++ b/packages/app/src/device-info/controllers/device-info.controller.ts @@ -3,13 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject } from "App/core/builder" import { DeviceInfo } from "App/device-info/dto" import { DeviceInfoService } from "App/device-info/services" -import { ControllerPrefix, IpcDeviceInfoEvent } from "App/device-info/constants" +import { IpcDeviceInfoEvent } from "App/device-info/constants" -@Controller(ControllerPrefix) export class DeviceInfoController { constructor(private deviceInfoService: DeviceInfoService) {} diff --git a/packages/app/src/device-info/requests/get-device-info.request.ts b/packages/app/src/device-info/requests/get-device-info.request.ts index ab94bad348..078c5b87cf 100644 --- a/packages/app/src/device-info/requests/get-device-info.request.ts +++ b/packages/app/src/device-info/requests/get-device-info.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceInfoRequest } from "App/device-info/constants" +import { IpcDeviceInfoEvent } from "App/device-info/constants" import { DeviceInfo } from "App/device-info/dto" export const getDeviceInfoRequest = async (): Promise< ResultObject > => { - return ipcRenderer.callMain(IpcDeviceInfoRequest.GetDeviceInfo) + return ipcRenderer.callMain(IpcDeviceInfoEvent.GetDeviceInfo) } diff --git a/packages/app/src/device-log/constants/controller.constant.ts b/packages/app/src/device-log/constants/controller.constant.ts index f3e9e9e13d..d1fa3d94be 100644 --- a/packages/app/src/device-log/constants/controller.constant.ts +++ b/packages/app/src/device-log/constants/controller.constant.ts @@ -3,12 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "device-log" - export enum IpcDeviceLogEvent { - GetLog = "get-log", -} - -export enum IpcDeviceLogRequest { - GetLog = "device-log-get-log", + GetLog = "device-log_get-log", } diff --git a/packages/app/src/device-log/controllers/device-log.controller.ts b/packages/app/src/device-log/controllers/device-log.controller.ts index ca56cf8a7d..29918386f3 100644 --- a/packages/app/src/device-log/controllers/device-log.controller.ts +++ b/packages/app/src/device-log/controllers/device-log.controller.ts @@ -3,14 +3,13 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject } from "App/core/builder" import { DeviceLogService } from "App/device-log/services" -import { ControllerPrefix, IpcDeviceLogEvent } from "App/device-log/constants" +import { IpcDeviceLogEvent } from "App/device-log/constants" import { DeviceFile } from "App/device-file-system/dto" import { DeviceFilesOption } from "App/device-file-system/types" -@Controller(ControllerPrefix) export class DeviceLogController { constructor(private deviceInfoService: DeviceLogService) {} diff --git a/packages/app/src/device-log/requests/get-device-log-files.request.ts b/packages/app/src/device-log/requests/get-device-log-files.request.ts index 6881c7562c..276722a856 100644 --- a/packages/app/src/device-log/requests/get-device-log-files.request.ts +++ b/packages/app/src/device-log/requests/get-device-log-files.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceLogRequest } from "App/device-log/constants" +import { IpcDeviceLogEvent } from "App/device-log/constants" import { DeviceFilesOption } from "App/device-file-system/types" import { DeviceFile } from "App/device-file-system/dto" export const getDeviceLogFiles = async ( options?: DeviceFilesOption ): Promise> => - ipcRenderer.callMain(IpcDeviceLogRequest.GetLog, options) + ipcRenderer.callMain(IpcDeviceLogEvent.GetLog, options) diff --git a/packages/app/src/device-manager/constants/controller.constant.ts b/packages/app/src/device-manager/constants/controller.constant.ts index 557bce39c9..e67f926bcc 100644 --- a/packages/app/src/device-manager/constants/controller.constant.ts +++ b/packages/app/src/device-manager/constants/controller.constant.ts @@ -6,13 +6,5 @@ export const ControllerPrefix = "device-manager" export enum IpcDeviceManagerEvent { - GetDevices = "get-devices", - GetCurrentDevice = "get-current-device", - SetCurrentDevice = "set-current-device", -} - -export enum IpcDeviceManagerRequest { - GetDevices = "device-manager-get-devices", - GetCurrentDevice = "device-manager-get-current-device", - SetCurrentDevice = "device-manager-set-current-device", + GetCurrentDevice = "device-manager_get-current-device", } diff --git a/packages/app/src/device-manager/controllers/device-manager.controller.ts b/packages/app/src/device-manager/controllers/device-manager.controller.ts index aa6d8dd9ff..bffd0387dd 100644 --- a/packages/app/src/device-manager/controllers/device-manager.controller.ts +++ b/packages/app/src/device-manager/controllers/device-manager.controller.ts @@ -3,17 +3,13 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject, Result } from "App/core/builder" import { AppError } from "App/core/errors" import { DeviceManager } from "App/device-manager/services" -import { - ControllerPrefix, - IpcDeviceManagerEvent, -} from "App/device-manager/constants" +import { IpcDeviceManagerEvent } from "App/device-manager/constants" import { Device } from "App/device/modules/device" -@Controller(ControllerPrefix) export class DeviceManagerController { constructor(private deviceManager: DeviceManager) {} @@ -25,14 +21,4 @@ export class DeviceManagerController { return Result.failed(error as AppError) } } - - @IpcEvent(IpcDeviceManagerEvent.GetDevices) - public getDevices(): ResultObject { - return Result.success(this.deviceManager.devices) - } - - @IpcEvent(IpcDeviceManagerEvent.SetCurrentDevice) - public setCurrentDevice(path: string): ResultObject { - return this.deviceManager.setCurrentDevice(path) - } } diff --git a/packages/app/src/device-manager/requests/get-current-device.request.ts b/packages/app/src/device-manager/requests/get-current-device.request.ts index ab257a6842..93c74bb729 100644 --- a/packages/app/src/device-manager/requests/get-current-device.request.ts +++ b/packages/app/src/device-manager/requests/get-current-device.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceManagerRequest } from "App/device-manager/constants" +import { IpcDeviceManagerEvent } from "App/device-manager/constants" import { Device } from "App/device/modules/device" export const getCurrentDeviceRequest = async (): Promise< ResultObject > => { - return ipcRenderer.callMain(IpcDeviceManagerRequest.GetCurrentDevice) + return ipcRenderer.callMain(IpcDeviceManagerEvent.GetCurrentDevice) } diff --git a/packages/app/src/device/constants/controller.constant.ts b/packages/app/src/device/constants/controller.constant.ts index b2bed9f3fe..180c638680 100644 --- a/packages/app/src/device/constants/controller.constant.ts +++ b/packages/app/src/device/constants/controller.constant.ts @@ -3,20 +3,10 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "device" - export enum IpcDeviceEvent { - Connect = "connect", - Unlock = "unlock", - UnlockStatus = "unlock-status", - LockTime = "lock-time", - SetUpdating = "set-updating", -} - -export enum IpcDeviceRequest { - Connect = "device-connect", - Unlock = "device-unlock", - UnlockStatus = "device-unlock-status", - LockTime = "device-lock-time", - SetUpdating = "device-set-updating", + Connect = "device_connect", + Unlock = "device_unlock", + UnlockStatus = "device_unlock-status", + LockTime = "device_lock-time", + SetUpdating = "device_set-updating", } diff --git a/packages/app/src/device/controllers/device.controller.ts b/packages/app/src/device/controllers/device.controller.ts index 84ac41d1fb..6468b916fa 100644 --- a/packages/app/src/device/controllers/device.controller.ts +++ b/packages/app/src/device/controllers/device.controller.ts @@ -3,14 +3,13 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject } from "App/core/builder" import { DeviceService } from "App/device/services" import { PhoneLockTime } from "App/device/dto" -import { ControllerPrefix, IpcDeviceEvent } from "App/device/constants" +import { IpcDeviceEvent } from "App/device/constants" import { DeviceInfo } from "App/device/types/mudita-os" -@Controller(ControllerPrefix) export class DeviceController { constructor(private deviceService: DeviceService) {} diff --git a/packages/app/src/device/requests/connect-device.request.ts b/packages/app/src/device/requests/connect-device.request.ts index 98c8565246..b0409cb6e2 100644 --- a/packages/app/src/device/requests/connect-device.request.ts +++ b/packages/app/src/device/requests/connect-device.request.ts @@ -5,9 +5,9 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceRequest } from "App/device/constants" +import { IpcDeviceEvent } from "App/device/constants" import { Device } from "App/device/modules/device" export const connectDeviceRequest = async (): Promise> => { - return ipcRenderer.callMain(IpcDeviceRequest.Connect) + return ipcRenderer.callMain(IpcDeviceEvent.Connect) } diff --git a/packages/app/src/device/requests/device-lock-time.request.ts b/packages/app/src/device/requests/device-lock-time.request.ts index ba384a8db3..fc8a33bdca 100644 --- a/packages/app/src/device/requests/device-lock-time.request.ts +++ b/packages/app/src/device/requests/device-lock-time.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceRequest } from "App/device/constants" +import { IpcDeviceEvent } from "App/device/constants" import { PhoneLockTime } from "App/device/dto" export const deviceLockTimeRequest = async (): Promise< ResultObject > => { - return ipcRenderer.callMain(IpcDeviceRequest.LockTime) + return ipcRenderer.callMain(IpcDeviceEvent.LockTime) } diff --git a/packages/app/src/device/requests/set-updating.request.ts b/packages/app/src/device/requests/set-updating.request.ts index 84fe235278..d8850a5122 100644 --- a/packages/app/src/device/requests/set-updating.request.ts +++ b/packages/app/src/device/requests/set-updating.request.ts @@ -4,11 +4,11 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcDeviceRequest } from "App/device/constants" +import { IpcDeviceEvent } from "App/device/constants" // This request is a tmp solution to manage `updating` state in `deviceManager` class // The tech debt will be fixed as part ot tech task // https://appnroll.atlassian.net/browse/CP-1765 export const setUpdatingRequest = async (updating: boolean): Promise => { - return ipcRenderer.callMain(IpcDeviceRequest.SetUpdating, updating) + return ipcRenderer.callMain(IpcDeviceEvent.SetUpdating, updating) } diff --git a/packages/app/src/device/requests/unlock-device-status.request.ts b/packages/app/src/device/requests/unlock-device-status.request.ts index 94b5de0952..5d883d3588 100644 --- a/packages/app/src/device/requests/unlock-device-status.request.ts +++ b/packages/app/src/device/requests/unlock-device-status.request.ts @@ -5,13 +5,10 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { - DeviceCommunicationError, - IpcDeviceRequest, -} from "App/device/constants" +import { DeviceCommunicationError, IpcDeviceEvent } from "App/device/constants" export const unlockDeviceStatusRequest = async (): Promise< ResultObject > => { - return ipcRenderer.callMain(IpcDeviceRequest.UnlockStatus) + return ipcRenderer.callMain(IpcDeviceEvent.UnlockStatus) } diff --git a/packages/app/src/device/requests/unlock-device.request.ts b/packages/app/src/device/requests/unlock-device.request.ts index ffeadd9238..e3109f017a 100644 --- a/packages/app/src/device/requests/unlock-device.request.ts +++ b/packages/app/src/device/requests/unlock-device.request.ts @@ -5,10 +5,10 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcDeviceRequest } from "App/device/constants" +import { IpcDeviceEvent } from "App/device/constants" export const unlockDeviceRequest = async ( code: number[] ): Promise> => { - return ipcRenderer.callMain(IpcDeviceRequest.Unlock, code) + return ipcRenderer.callMain(IpcDeviceEvent.Unlock, code) } diff --git a/packages/app/src/file-system/constants/controller.constant.ts b/packages/app/src/file-system/constants/controller.constant.ts deleted file mode 100644 index d65f9ad300..0000000000 --- a/packages/app/src/file-system/constants/controller.constant.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export const DialogControllerPrefix = "dialog-file-system" - -export enum IpcDialogFileSystemEvent { - GetPaths = "get-paths", -} - -export enum IpcDialogFileSystemRequest { - GetPaths = "dialog-file-system-get-paths", -} diff --git a/packages/app/src/file-system/constants/error.constant.ts b/packages/app/src/file-system/constants/error.constant.ts deleted file mode 100644 index 084bf0c6cb..0000000000 --- a/packages/app/src/file-system/constants/error.constant.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export enum DialogFileSystemError { - GetPath = "CANT_GET_SELECTED_FILES_PATH_ERROR", -} diff --git a/packages/app/src/file-system/constants/index.ts b/packages/app/src/file-system/constants/index.ts deleted file mode 100644 index dd30a7d30a..0000000000 --- a/packages/app/src/file-system/constants/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export * from "./controller.constant" -export * from "./error.constant" -export * from "./ipc-file-system.enum" diff --git a/packages/app/src/file-system/constants/ipc-file-system.enum.ts b/packages/app/src/file-system/constants/ipc-file-system.enum.ts deleted file mode 100644 index 753d4f3efd..0000000000 --- a/packages/app/src/file-system/constants/ipc-file-system.enum.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export enum IpcFileSystem { - EncryptFile = "file-system-encrypt-file", - DecryptFile = "file-system-decrypt-file", - ReadFile = "file-system-read-file", - UnlinkFile = "file-system-unlink-file", -} diff --git a/packages/app/src/file-system/controllers/dialog-file-system.controller.ts b/packages/app/src/file-system/controllers/dialog-file-system.controller.ts deleted file mode 100644 index ca274c0d94..0000000000 --- a/packages/app/src/file-system/controllers/dialog-file-system.controller.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { Controller, IpcEvent } from "App/core/decorators" -import { ResultObject } from "App/core/builder" -import { - DialogControllerPrefix, - IpcDialogFileSystemEvent, -} from "App/file-system/constants" -import { GetPathsInput } from "App/file-system/dto" -import { FilesSystemDialogService } from "App/file-system/services/file-system-dialog.service" - -@Controller(DialogControllerPrefix) -export class DialogFileSystemController { - constructor(private filesSystemDialogService: FilesSystemDialogService) {} - - @IpcEvent(IpcDialogFileSystemEvent.GetPaths) - public async getPaths({ - filters = [], - properties, - }: GetPathsInput): Promise> { - return this.filesSystemDialogService.getPaths(filters, properties) - } -} diff --git a/packages/app/src/file-system/controllers/index.ts b/packages/app/src/file-system/controllers/index.ts deleted file mode 100644 index cff9f81cc0..0000000000 --- a/packages/app/src/file-system/controllers/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export * from "./dialog-file-system.controller" diff --git a/packages/app/src/file-system/dto/get-paths-input.object.ts b/packages/app/src/file-system/dto/get-paths-input.object.ts deleted file mode 100644 index f0dc7b3f18..0000000000 --- a/packages/app/src/file-system/dto/get-paths-input.object.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { FileFilter, OpenDialogOptions } from "electron" - -export interface GetPathsInput { - filters: FileFilter[] - properties: OpenDialogOptions["properties"] -} diff --git a/packages/app/src/file-system/dto/index.ts b/packages/app/src/file-system/dto/index.ts deleted file mode 100644 index 22669858f8..0000000000 --- a/packages/app/src/file-system/dto/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export * from "./get-paths-input.object" diff --git a/packages/app/src/file-system/file-system.module.ts b/packages/app/src/file-system/file-system.module.ts deleted file mode 100644 index 4ffb0fc895..0000000000 --- a/packages/app/src/file-system/file-system.module.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { MainProcessIpc } from "electron-better-ipc" -import { EventEmitter } from "events" -import { MetadataStore } from "App/metadata/services" -import { FileSystemService } from "App/file-system/services/file-system.service.refactored" -import { AppLogger } from "App/__deprecated__/main/utils/logger" -import { IndexStorage } from "App/index-storage/types" -import { BaseModule } from "App/core/module" -import { FilesSystemDialogService } from "App/file-system/services" -import { DialogFileSystemController } from "App/file-system/controllers" -import { DeviceManager } from "App/device-manager/services" - -export class FileSystemModule extends BaseModule { - constructor( - public index: IndexStorage, - public deviceManager: DeviceManager, - public keyStorage: MetadataStore, - public logger: AppLogger, - public ipc: MainProcessIpc, - public eventEmitter: EventEmitter, - public fileSystem: FileSystemService - ) { - super( - index, - deviceManager, - keyStorage, - logger, - ipc, - eventEmitter, - fileSystem - ) - - const filesSystemDialogService = new FilesSystemDialogService() - const dialogFileSystemController = new DialogFileSystemController( - filesSystemDialogService - ) - - this.controllers = [dialogFileSystemController] - } -} diff --git a/packages/app/src/file-system/helpers/array-buffer-to-buffer.test.ts b/packages/app/src/file-system/helpers/array-buffer-to-buffer.test.ts deleted file mode 100644 index 9cb69e5180..0000000000 --- a/packages/app/src/file-system/helpers/array-buffer-to-buffer.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { arrayBufferToBuffer } from "App/file-system/helpers/array-buffer-to-buffer" - -describe("`arrayBufferToBuffer` function", () => { - const data = [1, 2, 3, 4, 5] - - test("Uint8Array constructor isn't equal to buffer", () => { - const bufferView = new Uint8Array(data) - expect(bufferView.constructor).not.toBe(Buffer) - expect(bufferView.constructor).toBe(Uint8Array) - }) - - test("mapped buffer return buffer as constructor", () => { - const buffer = arrayBufferToBuffer(new Uint8Array(data)) - expect(buffer.constructor).not.toBe(Uint8Array) - expect(buffer.constructor).toBe(Buffer) - }) -}) diff --git a/packages/app/src/file-system/helpers/array-buffer-to-buffer.ts b/packages/app/src/file-system/helpers/array-buffer-to-buffer.ts deleted file mode 100644 index c4e08b260f..0000000000 --- a/packages/app/src/file-system/helpers/array-buffer-to-buffer.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -/** - * Uint8Array is a general-purpose byte-array that’s available in both nodejs and browsers. - * Buffer is a subclass of Uint8Array that’s only available in nodejs - */ - -export const arrayBufferToBuffer = (ab: Uint8Array): Buffer => { - const buffer = Buffer.alloc(ab.byteLength) - const view = new Uint8Array(ab) - for (let i = 0; i < buffer.length; ++i) { - buffer[i] = view[i] - } - return buffer -} diff --git a/packages/app/src/file-system/helpers/index.ts b/packages/app/src/file-system/helpers/index.ts deleted file mode 100644 index 0d2e34f3d9..0000000000 --- a/packages/app/src/file-system/helpers/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export * from "./array-buffer-to-buffer" diff --git a/packages/app/src/file-system/listeners/decrypt-file.listener.ts b/packages/app/src/file-system/listeners/decrypt-file.listener.ts deleted file mode 100644 index b366cf7edb..0000000000 --- a/packages/app/src/file-system/listeners/decrypt-file.listener.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { ipcMain } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants/ipc-file-system.enum" -import CryptoFileService, { - CryptoFileOptions, -} from "App/file-system/services/crypto-file-service/crypto-file-service" - -const registerDecryptFileListener = (): void => { - ipcMain.answerRenderer( - IpcFileSystem.DecryptFile, - // AUTO DISABLED - fix me if you like :) - // eslint-disable-next-line @typescript-eslint/unbound-method - CryptoFileService.decrypt - ) -} - -export default registerDecryptFileListener diff --git a/packages/app/src/file-system/listeners/encrypt-file.listener.ts b/packages/app/src/file-system/listeners/encrypt-file.listener.ts deleted file mode 100644 index 57f3214b81..0000000000 --- a/packages/app/src/file-system/listeners/encrypt-file.listener.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { ipcMain } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants/ipc-file-system.enum" -import CryptoFileService, { - CryptoFileOptions, -} from "App/file-system/services/crypto-file-service/crypto-file-service" - -const registerEncryptFileListener = (): void => { - ipcMain.answerRenderer( - IpcFileSystem.EncryptFile, - // AUTO DISABLED - fix me if you like :) - // eslint-disable-next-line @typescript-eslint/unbound-method - CryptoFileService.encrypt - ) -} - -export default registerEncryptFileListener diff --git a/packages/app/src/file-system/listeners/index.ts b/packages/app/src/file-system/listeners/index.ts deleted file mode 100644 index 2eed4e6c1b..0000000000 --- a/packages/app/src/file-system/listeners/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export * from "./decrypt-file.listener" -export * from "./encrypt-file.listener" -export * from "./read-file.listener" -export * from "./unlink-file.listener" diff --git a/packages/app/src/file-system/listeners/read-file.listener.ts b/packages/app/src/file-system/listeners/read-file.listener.ts deleted file mode 100644 index e09dc0f83c..0000000000 --- a/packages/app/src/file-system/listeners/read-file.listener.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import fs, { PathOrFileDescriptor } from "fs" -import { ipcMain } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants/ipc-file-system.enum" - -const registerReadFileListener = (): void => { - ipcMain.answerRenderer( - IpcFileSystem.ReadFile, - (path) => { - return fs.readFileSync(path) - } - ) -} - -export default registerReadFileListener diff --git a/packages/app/src/file-system/listeners/unlink-file.listener.ts b/packages/app/src/file-system/listeners/unlink-file.listener.ts deleted file mode 100644 index fbff2d3598..0000000000 --- a/packages/app/src/file-system/listeners/unlink-file.listener.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { ipcMain } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants/ipc-file-system.enum" -import fs, { PathLike } from "fs" - -export const unlinkSync = (path: PathLike): void => { - return fs.unlinkSync(path) -} - -const registerUnlinkFileListener = (): void => { - ipcMain.answerRenderer( - IpcFileSystem.UnlinkFile, - unlinkSync - ) -} - -export default registerUnlinkFileListener diff --git a/packages/app/src/file-system/requests/decrypt-file.request.ts b/packages/app/src/file-system/requests/decrypt-file.request.ts deleted file mode 100644 index d47097ee45..0000000000 --- a/packages/app/src/file-system/requests/decrypt-file.request.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { ipcRenderer } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants" -import { CryptoFileOptions } from "App/file-system/services/crypto-file-service/crypto-file-service" - -const decryptFile = async ( - options: CryptoFileOptions -): Promise => { - return await ipcRenderer.callMain(IpcFileSystem.DecryptFile, options) -} - -export default decryptFile diff --git a/packages/app/src/file-system/requests/encrypt-file.request.ts b/packages/app/src/file-system/requests/encrypt-file.request.ts deleted file mode 100644 index 75313e249c..0000000000 --- a/packages/app/src/file-system/requests/encrypt-file.request.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { ipcRenderer } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants" -import { CryptoFileOptions } from "App/file-system/services/crypto-file-service/crypto-file-service" - -const encryptFile = async ( - options: CryptoFileOptions -): Promise => { - return await ipcRenderer.callMain(IpcFileSystem.EncryptFile, options) -} - -export default encryptFile diff --git a/packages/app/src/file-system/requests/get-paths.request.ts b/packages/app/src/file-system/requests/get-paths.request.ts deleted file mode 100644 index 87af4faeaf..0000000000 --- a/packages/app/src/file-system/requests/get-paths.request.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { ipcRenderer } from "electron-better-ipc" -import { ResultObject } from "App/core/builder" -import { IpcDialogFileSystemRequest } from "App/file-system/constants" -import { GetPathsInput } from "App/file-system/dto" - -export const getPathsRequest = async ( - props: GetPathsInput -): Promise> => { - return ipcRenderer.callMain(IpcDialogFileSystemRequest.GetPaths, props) -} diff --git a/packages/app/src/file-system/requests/index.ts b/packages/app/src/file-system/requests/index.ts deleted file mode 100644 index c05e9141cc..0000000000 --- a/packages/app/src/file-system/requests/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export * from "./get-paths.request" diff --git a/packages/app/src/file-system/requests/read-file.request.ts b/packages/app/src/file-system/requests/read-file.request.ts deleted file mode 100644 index 2a0d150348..0000000000 --- a/packages/app/src/file-system/requests/read-file.request.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { PathOrFileDescriptor } from "fs" -import { ipcRenderer } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants" - -const readFile = async ( - path: PathOrFileDescriptor -): Promise => { - return await ipcRenderer.callMain(IpcFileSystem.ReadFile, path) -} - -export default readFile diff --git a/packages/app/src/file-system/requests/unlink-file.request.ts b/packages/app/src/file-system/requests/unlink-file.request.ts deleted file mode 100644 index 92d695a13e..0000000000 --- a/packages/app/src/file-system/requests/unlink-file.request.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { ipcRenderer } from "electron-better-ipc" -import { IpcFileSystem } from "App/file-system/constants" -import { PathLike } from "fs" - -const unlinkFile = async ( - path: PathLike -): Promise => { - return await ipcRenderer.callMain(IpcFileSystem.UnlinkFile, path) -} - -export default unlinkFile diff --git a/packages/app/src/file-system/services/file-system-dialog.service.test.ts b/packages/app/src/file-system/services/file-system-dialog.service.test.ts deleted file mode 100644 index c82f4757d3..0000000000 --- a/packages/app/src/file-system/services/file-system-dialog.service.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { dialog } from "electron" -import { Result } from "App/core/builder" -import { AppError } from "App/core/errors" -import { FilesSystemDialogService } from "App/file-system/services/file-system-dialog.service" -import { DialogFileSystemError } from "App/file-system/constants" - -jest.mock("electron", () => ({ - dialog: { - showOpenDialog: jest.fn(), - }, -})) - -const subject = new FilesSystemDialogService() - -beforeEach(() => [jest.resetAllMocks()]) - -test("returns `Result.success` with selected files list", async () => { - ;(dialog.showOpenDialog as jest.Mock).mockResolvedValueOnce({ - filePaths: ["/test/file-1.txt"], - }) - - const result = await subject.getPaths() - expect(result).toEqual(Result.success(["/test/file-1.txt"])) -}) - -test("returns `Result.failed` if `showOpenDialog` throw an error", async () => { - ;(dialog.showOpenDialog as jest.Mock).mockRejectedValueOnce( - new Error("Luke, I'm your error") - ) - - const result = await subject.getPaths() - expect(result).toEqual( - Result.failed( - new AppError(DialogFileSystemError.GetPath, "Luke, I'm your error") - ) - ) -}) diff --git a/packages/app/src/file-system/services/file-system-dialog.service.ts b/packages/app/src/file-system/services/file-system-dialog.service.ts deleted file mode 100644 index 4fe565e6ef..0000000000 --- a/packages/app/src/file-system/services/file-system-dialog.service.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -import { dialog, FileFilter, OpenDialogOptions } from "electron" -import { AppError } from "App/core/errors" -import { Result, ResultObject } from "App/core/builder" -import { DialogFileSystemError } from "App/file-system/constants" - -export class FilesSystemDialogService { - public async getPaths( - filters?: FileFilter[], - properties?: OpenDialogOptions["properties"] - ): Promise> { - try { - const result = await dialog.showOpenDialog({ filters, properties }) - return Result.success(result.filePaths) - } catch (error) { - return Result.failed( - new AppError( - DialogFileSystemError.GetPath, - error ? (error as Error).message : "Something went wrong" - ) - ) - } - } -} diff --git a/packages/app/src/file-system/services/index.ts b/packages/app/src/file-system/services/index.ts deleted file mode 100644 index 5ccdd60437..0000000000 --- a/packages/app/src/file-system/services/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copyright (c) Mudita sp. z o.o. All rights reserved. - * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md - */ - -export * from "./file-system-dialog.service" diff --git a/packages/app/src/files-manager/actions/upload-file.action.test.ts b/packages/app/src/files-manager/actions/upload-file.action.test.ts index 2b923b6213..7383f8f849 100644 --- a/packages/app/src/files-manager/actions/upload-file.action.test.ts +++ b/packages/app/src/files-manager/actions/upload-file.action.test.ts @@ -22,7 +22,6 @@ import { } from "App/files-manager/actions/base.action" import { getFiles } from "App/files-manager/actions/get-files.action" -jest.mock("App/file-system/requests") jest.mock("App/files-manager/requests") const GET_FILES_MOCK_RESULT = { diff --git a/packages/app/src/files-manager/constants/controller.constant.ts b/packages/app/src/files-manager/constants/controller.constant.ts index 6b458b647b..cebf1315df 100644 --- a/packages/app/src/files-manager/constants/controller.constant.ts +++ b/packages/app/src/files-manager/constants/controller.constant.ts @@ -3,16 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "files-manager" - export enum IpcFilesManagerEvent { - GetFiles = "get-files", - UploadFiles = "upload-files", - DeleteFiles = "delete-files", -} - -export enum IpcFilesManagerRequest { - GetFiles = "files-manager-get-files", - UploadFiles = "files-manager-upload-files", - DeleteFiles = "files-manager-delete-files", + GetFiles = "files-manager_get-files", + UploadFiles = "files-manager_upload-files", + DeleteFiles = "files-manager_delete-files", } diff --git a/packages/app/src/files-manager/controllers/files-manager.controller.ts b/packages/app/src/files-manager/controllers/files-manager.controller.ts index 9781a9a36c..c60613cafd 100644 --- a/packages/app/src/files-manager/controllers/files-manager.controller.ts +++ b/packages/app/src/files-manager/controllers/files-manager.controller.ts @@ -3,16 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject } from "App/core/builder" -import { - ControllerPrefix, - IpcFilesManagerEvent, -} from "App/files-manager/constants" +import { IpcFilesManagerEvent } from "App/files-manager/constants" import { File, UploadFilesInput, GetFilesInput } from "App/files-manager/dto" import { FileManagerService } from "App/files-manager/services" -@Controller(ControllerPrefix) export class FilesManagerController { constructor(private fileManagerService: FileManagerService) {} diff --git a/packages/app/src/files-manager/requests/delete-files.request.ts b/packages/app/src/files-manager/requests/delete-files.request.ts index d1c7f5bb9d..1dec12960a 100644 --- a/packages/app/src/files-manager/requests/delete-files.request.ts +++ b/packages/app/src/files-manager/requests/delete-files.request.ts @@ -5,10 +5,10 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcFilesManagerRequest } from "App/files-manager/constants" +import { IpcFilesManagerEvent } from "App/files-manager/constants" export const deleteFilesRequest = async ( paths: string[] ): Promise> => { - return ipcRenderer.callMain(IpcFilesManagerRequest.DeleteFiles, paths) + return ipcRenderer.callMain(IpcFilesManagerEvent.DeleteFiles, paths) } diff --git a/packages/app/src/files-manager/requests/get-files.request.ts b/packages/app/src/files-manager/requests/get-files.request.ts index 5420ff92aa..bb01db47b5 100644 --- a/packages/app/src/files-manager/requests/get-files.request.ts +++ b/packages/app/src/files-manager/requests/get-files.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcFilesManagerRequest } from "App/files-manager/constants" +import { IpcFilesManagerEvent } from "App/files-manager/constants" import { File, GetFilesInput } from "App/files-manager/dto" export const getFilesRequest = async ( input: GetFilesInput ): Promise> => { - return ipcRenderer.callMain(IpcFilesManagerRequest.GetFiles, input) + return ipcRenderer.callMain(IpcFilesManagerEvent.GetFiles, input) } diff --git a/packages/app/src/files-manager/requests/upload-files.request.ts b/packages/app/src/files-manager/requests/upload-files.request.ts index ad8c53993f..4d691df3be 100644 --- a/packages/app/src/files-manager/requests/upload-files.request.ts +++ b/packages/app/src/files-manager/requests/upload-files.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcFilesManagerRequest } from "App/files-manager/constants" +import { IpcFilesManagerEvent } from "App/files-manager/constants" import { UploadFilesInput } from "App/files-manager/dto" export const uploadFilesRequest = async ( input: UploadFilesInput ): Promise> => { - return ipcRenderer.callMain(IpcFilesManagerRequest.UploadFiles, input) + return ipcRenderer.callMain(IpcFilesManagerEvent.UploadFiles, input) } diff --git a/packages/app/src/messages/constants/controller.constant.ts b/packages/app/src/messages/constants/controller.constant.ts index a070943f1a..a2950e5cac 100644 --- a/packages/app/src/messages/constants/controller.constant.ts +++ b/packages/app/src/messages/constants/controller.constant.ts @@ -3,30 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const MessageControllerPrefix = "message" - export enum IpcMessageEvent { - CreateMessage = "create-message", - DeleteMessage = "delete-message", - ResendMessage = "resend-message", - UpdateMessage = "update-message", -} - -export enum IpcMessageRequest { - CreateMessage = "message-create-message", - DeleteMessage = "message-delete-message", - ResendMessage = "message-resend-message", - UpdateMessage = "message-update-message", + CreateMessage = "message_create-message", + DeleteMessage = "message_delete-message", + ResendMessage = "message_resend-message", + UpdateMessage = "message_update-message", } -export const ThreadControllerPrefix = "thread" - export enum IpcThreadEvent { - DeleteThreads = "delete-threads", - ToggleThreadsReadStatus = "toggle-threads-read-status", -} - -export enum IpcThreadRequest { - DeleteThreads = "thread-delete-threads", - ToggleThreadsReadStatus = "thread-toggle-threads-read-status", + DeleteThreads = "thread_delete-threads", + ToggleThreadsReadStatus = "thread_toggle-threads-read-status", } diff --git a/packages/app/src/messages/controllers/message.controller.ts b/packages/app/src/messages/controllers/message.controller.ts index fc344c2aeb..8fca00efe3 100644 --- a/packages/app/src/messages/controllers/message.controller.ts +++ b/packages/app/src/messages/controllers/message.controller.ts @@ -4,19 +4,15 @@ */ import { ResultObject } from "App/core/builder" -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { RequestResponse } from "App/core/types/request-response.interface" import { CreateMessageDataResponse, MessageService, } from "App/messages/services" -import { - IpcMessageEvent, - MessageControllerPrefix, -} from "App/messages/constants/controller.constant" +import { IpcMessageEvent } from "App/messages/constants/controller.constant" import { NewMessage, Message } from "App/messages/dto" -@Controller(MessageControllerPrefix) export class MessageController { constructor(private messageService: MessageService) {} diff --git a/packages/app/src/messages/controllers/thread.controller.ts b/packages/app/src/messages/controllers/thread.controller.ts index a6ca197585..72ae7dd549 100644 --- a/packages/app/src/messages/controllers/thread.controller.ts +++ b/packages/app/src/messages/controllers/thread.controller.ts @@ -3,16 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { RequestResponse } from "App/core/types/request-response.interface" import { ThreadService } from "App/messages/services" -import { - IpcThreadEvent, - ThreadControllerPrefix, -} from "App/messages/constants/controller.constant" +import { IpcThreadEvent } from "App/messages/constants/controller.constant" import { Thread } from "App/messages/dto" -@Controller(ThreadControllerPrefix) export class ThreadController { constructor(private threadService: ThreadService) {} diff --git a/packages/app/src/messages/requests/create-message.request.ts b/packages/app/src/messages/requests/create-message.request.ts index e68db357a9..31f4ec4ad1 100644 --- a/packages/app/src/messages/requests/create-message.request.ts +++ b/packages/app/src/messages/requests/create-message.request.ts @@ -4,7 +4,7 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcMessageRequest } from "App/messages/constants/controller.constant" +import { IpcMessageEvent } from "App/messages/constants/controller.constant" import { NewMessage } from "App/messages/dto" import { RequestResponse } from "App/core/types/request-response.interface" import { CreateMessageDataResponse } from "App/messages/services" @@ -12,5 +12,5 @@ import { CreateMessageDataResponse } from "App/messages/services" export const createMessageRequest = ( newMessage: NewMessage ): Promise> => { - return ipcRenderer.callMain(IpcMessageRequest.CreateMessage, newMessage) + return ipcRenderer.callMain(IpcMessageEvent.CreateMessage, newMessage) } diff --git a/packages/app/src/messages/requests/delete-message.request.ts b/packages/app/src/messages/requests/delete-message.request.ts index adc0a2e370..0aa87d8e49 100644 --- a/packages/app/src/messages/requests/delete-message.request.ts +++ b/packages/app/src/messages/requests/delete-message.request.ts @@ -4,11 +4,11 @@ */ import { RequestResponse } from "App/core/types/request-response.interface" -import { IpcMessageRequest } from "App/messages/constants/controller.constant" +import { IpcMessageEvent } from "App/messages/constants/controller.constant" import { ipcRenderer } from "electron-better-ipc" export const deleteMessageRequest = ( messageId: string ): Promise> => { - return ipcRenderer.callMain(IpcMessageRequest.DeleteMessage, messageId) + return ipcRenderer.callMain(IpcMessageEvent.DeleteMessage, messageId) } diff --git a/packages/app/src/messages/requests/delete-threads.request.ts b/packages/app/src/messages/requests/delete-threads.request.ts index 0d3acfe56f..ca14e771b5 100644 --- a/packages/app/src/messages/requests/delete-threads.request.ts +++ b/packages/app/src/messages/requests/delete-threads.request.ts @@ -4,11 +4,11 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcThreadRequest } from "App/messages/constants/controller.constant" +import { IpcThreadEvent } from "App/messages/constants/controller.constant" import { RequestResponse } from "App/core/types/request-response.interface" export const deleteThreadsRequest = async ( threadIds: string[] ): Promise> => { - return await ipcRenderer.callMain(IpcThreadRequest.DeleteThreads, threadIds) + return await ipcRenderer.callMain(IpcThreadEvent.DeleteThreads, threadIds) } diff --git a/packages/app/src/messages/requests/resend-message.request.ts b/packages/app/src/messages/requests/resend-message.request.ts index 38abf20a2f..fedfcf650d 100644 --- a/packages/app/src/messages/requests/resend-message.request.ts +++ b/packages/app/src/messages/requests/resend-message.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { RequestResponse } from "App/core/types/request-response.interface" -import { IpcMessageRequest } from "App/messages/constants/controller.constant" +import { IpcMessageEvent } from "App/messages/constants/controller.constant" import { CreateMessageDataResponse } from "App/messages/services" export const resendMessageRequest = ( messageId: string ): Promise> => { - return ipcRenderer.callMain(IpcMessageRequest.ResendMessage, messageId) + return ipcRenderer.callMain(IpcMessageEvent.ResendMessage, messageId) } diff --git a/packages/app/src/messages/requests/toggle-threads-read-status.request.ts b/packages/app/src/messages/requests/toggle-threads-read-status.request.ts index 3681c9e2db..b13633ae83 100644 --- a/packages/app/src/messages/requests/toggle-threads-read-status.request.ts +++ b/packages/app/src/messages/requests/toggle-threads-read-status.request.ts @@ -4,7 +4,7 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcThreadRequest } from "App/messages/constants/controller.constant" +import { IpcThreadEvent } from "App/messages/constants/controller.constant" import { RequestResponse } from "App/core/types/request-response.interface" import { Thread } from "App/messages/dto" @@ -12,7 +12,7 @@ export const toggleThreadsReadStatusRequest = async ( threads: Thread[] ): Promise> => { return await ipcRenderer.callMain( - IpcThreadRequest.ToggleThreadsReadStatus, + IpcThreadEvent.ToggleThreadsReadStatus, threads ) } diff --git a/packages/app/src/messages/requests/update-message.request.ts b/packages/app/src/messages/requests/update-message.request.ts index 97942b9f08..98a9a33ec7 100644 --- a/packages/app/src/messages/requests/update-message.request.ts +++ b/packages/app/src/messages/requests/update-message.request.ts @@ -5,11 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcMessageRequest } from "App/messages/constants/controller.constant" +import { IpcMessageEvent } from "App/messages/constants/controller.constant" import { Message } from "App/messages/dto" export const updateMessageRequest = ( message: Message ): Promise> => { - return ipcRenderer.callMain(IpcMessageRequest.UpdateMessage, message) + return ipcRenderer.callMain(IpcMessageEvent.UpdateMessage, message) } diff --git a/packages/app/src/search/constants/controller.constant.ts b/packages/app/src/search/constants/controller.constant.ts index 9d7541d840..c748490139 100644 --- a/packages/app/src/search/constants/controller.constant.ts +++ b/packages/app/src/search/constants/controller.constant.ts @@ -3,12 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const SearchControllerPrefix = "search" - export enum IpcSearchEvent { - SearchData = "search-data", -} - -export enum IpcSearchRequest { - SearchData = "search-search-data", + SearchData = "search_search-data", } diff --git a/packages/app/src/search/controllers/search.controller.ts b/packages/app/src/search/controllers/search.controller.ts index 20828afdaf..a58e4832ee 100644 --- a/packages/app/src/search/controllers/search.controller.ts +++ b/packages/app/src/search/controllers/search.controller.ts @@ -3,13 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject } from "App/core/builder" -import { SearchControllerPrefix, IpcSearchEvent } from "App/search/constants" +import { IpcSearchEvent } from "App/search/constants" import { SearchParams, SearchResult } from "App/search/dto" import { SearchService } from "App/search/services" -@Controller(SearchControllerPrefix) export class SearchController { constructor(private searchService: SearchService) {} diff --git a/packages/app/src/search/requests/search.request.ts b/packages/app/src/search/requests/search.request.ts index 6063cd5f52..790f30f2e5 100644 --- a/packages/app/src/search/requests/search.request.ts +++ b/packages/app/src/search/requests/search.request.ts @@ -6,10 +6,10 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" import { SearchParams, SearchResult } from "App/search/dto" -import { IpcSearchRequest } from "App/search/constants" +import { IpcSearchEvent } from "App/search/constants" export const searchRequest = async ( data: SearchParams ): Promise> => { - return ipcRenderer.callMain(IpcSearchRequest.SearchData, data) + return ipcRenderer.callMain(IpcSearchEvent.SearchData, data) } diff --git a/packages/app/src/settings/constants/controller.constant.ts b/packages/app/src/settings/constants/controller.constant.ts index 458a0662f1..a0d12006fc 100644 --- a/packages/app/src/settings/constants/controller.constant.ts +++ b/packages/app/src/settings/constants/controller.constant.ts @@ -3,25 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const SettingsControllerPrefix = "settings" -export const ConfigurationsControllerPrefix = "configurations" - export enum IpcSettingsEvent { - Get = "get", - Reset = "reset", - Update = "update", + Get = "settings_get", + Reset = "settings_reset", + Update = "settings_update", } export enum IpcConfigurationsEvent { - Get = "get", -} - -export enum IpcSettingsRequest { - Get = "settings-get", - Reset = "settings-reset", - Update = "settings-update", -} - -export enum IpcConfigurationsRequest { - Get = "configurations-get", + Get = "configurations_get", } diff --git a/packages/app/src/settings/controllers/configuration.controller.ts b/packages/app/src/settings/controllers/configuration.controller.ts index 26aafe8e7e..0fb09c6977 100644 --- a/packages/app/src/settings/controllers/configuration.controller.ts +++ b/packages/app/src/settings/controllers/configuration.controller.ts @@ -3,15 +3,11 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" -import { - ConfigurationsControllerPrefix, - IpcConfigurationsEvent, -} from "App/settings/constants" +import { IpcEvent } from "App/core/decorators" +import { IpcConfigurationsEvent } from "App/settings/constants" import { Configuration } from "App/settings/dto" import { ConfigurationService } from "App/settings/services" -@Controller(ConfigurationsControllerPrefix) export class ConfigurationController { constructor(private configurationService: ConfigurationService) {} diff --git a/packages/app/src/settings/controllers/settings.controller.ts b/packages/app/src/settings/controllers/settings.controller.ts index 4ff18eb5b3..0c7595dfc1 100644 --- a/packages/app/src/settings/controllers/settings.controller.ts +++ b/packages/app/src/settings/controllers/settings.controller.ts @@ -3,16 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" -import { - SettingsControllerPrefix, - IpcSettingsEvent, -} from "App/settings/constants" +import { IpcEvent } from "App/core/decorators" +import { IpcSettingsEvent } from "App/settings/constants" import { Settings, SettingsUpdateOption } from "App/settings/dto" import { SettingsService } from "App/settings/services" import { SettingsValue } from "App/settings/types" -@Controller(SettingsControllerPrefix) export class SettingsController { constructor(private settingsService: SettingsService) {} diff --git a/packages/app/src/settings/requests/get-configuration.request.ts b/packages/app/src/settings/requests/get-configuration.request.ts index 68e39d44c2..83c9bea06d 100644 --- a/packages/app/src/settings/requests/get-configuration.request.ts +++ b/packages/app/src/settings/requests/get-configuration.request.ts @@ -5,7 +5,7 @@ import { ipcRenderer } from "electron-better-ipc" import { Configuration } from "App/settings/dto" -import { IpcConfigurationsRequest } from "App/settings/constants" +import { IpcConfigurationsEvent } from "App/settings/constants" export const getConfiguration = (): Promise => - ipcRenderer.callMain(IpcConfigurationsRequest.Get) + ipcRenderer.callMain(IpcConfigurationsEvent.Get) diff --git a/packages/app/src/settings/requests/get-settings.request.ts b/packages/app/src/settings/requests/get-settings.request.ts index c739a9dc45..cd239e3f34 100644 --- a/packages/app/src/settings/requests/get-settings.request.ts +++ b/packages/app/src/settings/requests/get-settings.request.ts @@ -5,7 +5,7 @@ import { ipcRenderer } from "electron-better-ipc" import { Settings } from "App/settings/dto" -import { IpcSettingsRequest } from "App/settings/constants" +import { IpcSettingsEvent } from "App/settings/constants" export const getSettings = (): Promise => - ipcRenderer.callMain(IpcSettingsRequest.Get) + ipcRenderer.callMain(IpcSettingsEvent.Get) diff --git a/packages/app/src/settings/requests/reset-settings.request.ts b/packages/app/src/settings/requests/reset-settings.request.ts index 6b67b35fbd..6ac9823a9d 100644 --- a/packages/app/src/settings/requests/reset-settings.request.ts +++ b/packages/app/src/settings/requests/reset-settings.request.ts @@ -5,7 +5,7 @@ import { ipcRenderer } from "electron-better-ipc" import { Settings } from "App/settings/dto" -import { IpcSettingsRequest } from "App/settings/constants" +import { IpcSettingsEvent } from "App/settings/constants" export const resetSettings = (): Promise => - ipcRenderer.callMain(IpcSettingsRequest.Reset) + ipcRenderer.callMain(IpcSettingsEvent.Reset) diff --git a/packages/app/src/settings/requests/update-settings.request.ts b/packages/app/src/settings/requests/update-settings.request.ts index 93a9763353..f317f66fa4 100644 --- a/packages/app/src/settings/requests/update-settings.request.ts +++ b/packages/app/src/settings/requests/update-settings.request.ts @@ -5,9 +5,9 @@ import { ipcRenderer } from "electron-better-ipc" import { Settings, SettingsUpdateOption } from "App/settings/dto" -import { IpcSettingsRequest } from "App/settings/constants" +import { IpcSettingsEvent } from "App/settings/constants" export const updateSettings = ( option: SettingsUpdateOption ): Promise> => - ipcRenderer.callMain(IpcSettingsRequest.Update, option) + ipcRenderer.callMain(IpcSettingsEvent.Update, option) diff --git a/packages/app/src/templates/constants/controller.constant.ts b/packages/app/src/templates/constants/controller.constant.ts index 8db7182127..1c6f43184e 100644 --- a/packages/app/src/templates/constants/controller.constant.ts +++ b/packages/app/src/templates/constants/controller.constant.ts @@ -3,18 +3,9 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "template" - export enum IpcTemplateEvent { - CreateTemplate = "create-template", - DeleteTemplates = "delete-templates", - UpdateTemplate = "update-template", - UpdateTemplateOrder = "update-template-order", -} - -export enum IpcTemplateRequest { - CreateTemplate = "template-create-template", - DeleteTemplates = "template-delete-templates", - UpdateTemplate = "template-update-template", - UpdateTemplateOrder = "template-update-template-order", + CreateTemplate = "template_create-template", + DeleteTemplates = "template_delete-templates", + UpdateTemplate = "template_update-template", + UpdateTemplateOrder = "template_update-template-order", } diff --git a/packages/app/src/templates/controllers/template.controller.ts b/packages/app/src/templates/controllers/template.controller.ts index 487573c60b..29c4ed91e5 100644 --- a/packages/app/src/templates/controllers/template.controller.ts +++ b/packages/app/src/templates/controllers/template.controller.ts @@ -3,13 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { TemplateService } from "App/templates/services" import { RequestResponse } from "App/core/types/request-response.interface" -import { ControllerPrefix, IpcTemplateEvent } from "App/templates/constants" +import { IpcTemplateEvent } from "App/templates/constants" import { NewTemplate, Template } from "App/templates/dto" -@Controller(ControllerPrefix) export class TemplateController { constructor(private templateService: TemplateService) {} diff --git a/packages/app/src/templates/requests/create-template.request.ts b/packages/app/src/templates/requests/create-template.request.ts index 507b9ea864..19c5566894 100644 --- a/packages/app/src/templates/requests/create-template.request.ts +++ b/packages/app/src/templates/requests/create-template.request.ts @@ -4,12 +4,12 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcTemplateRequest } from "App/templates/constants" +import { IpcTemplateEvent } from "App/templates/constants" import { Template, NewTemplate } from "App/templates/dto" import { RequestResponse } from "App/core/types/request-response.interface" export const createTemplateRequest = async ( template: NewTemplate ): Promise> => { - return ipcRenderer.callMain(IpcTemplateRequest.CreateTemplate, template) + return ipcRenderer.callMain(IpcTemplateEvent.CreateTemplate, template) } diff --git a/packages/app/src/templates/requests/delete-templates.request.ts b/packages/app/src/templates/requests/delete-templates.request.ts index 140d6c5777..a5bb49bb03 100644 --- a/packages/app/src/templates/requests/delete-templates.request.ts +++ b/packages/app/src/templates/requests/delete-templates.request.ts @@ -4,14 +4,14 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcTemplateRequest } from "App/templates/constants" +import { IpcTemplateEvent } from "App/templates/constants" import { DeleteTemplateRequestResponse } from "App/templates/reducers" export const deleteTemplatesRequest = async ( templateIds: string[] ): Promise => { return await ipcRenderer.callMain( - IpcTemplateRequest.DeleteTemplates, + IpcTemplateEvent.DeleteTemplates, templateIds ) } diff --git a/packages/app/src/templates/requests/update-template-order.request.ts b/packages/app/src/templates/requests/update-template-order.request.ts index 3e8a9d323d..0e8d048ca3 100644 --- a/packages/app/src/templates/requests/update-template-order.request.ts +++ b/packages/app/src/templates/requests/update-template-order.request.ts @@ -4,7 +4,7 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcTemplateRequest } from "App/templates/constants" +import { IpcTemplateEvent } from "App/templates/constants" import { Template } from "App/templates/dto" import { UpdateTemplateOrderRequestResponse } from "App/templates/reducers" @@ -12,7 +12,7 @@ export const updateTemplateOrderRequest = async ( templates: Template[] ): Promise => { return await ipcRenderer.callMain( - IpcTemplateRequest.UpdateTemplateOrder, + IpcTemplateEvent.UpdateTemplateOrder, templates ) } diff --git a/packages/app/src/templates/requests/update-template.request.ts b/packages/app/src/templates/requests/update-template.request.ts index 2b877d3922..070924a56b 100644 --- a/packages/app/src/templates/requests/update-template.request.ts +++ b/packages/app/src/templates/requests/update-template.request.ts @@ -4,12 +4,12 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcTemplateRequest } from "App/templates/constants" +import { IpcTemplateEvent } from "App/templates/constants" import { Template } from "App/templates/dto" import { RequestResponse } from "App/core/types/request-response.interface" export const updateTemplateRequest = async ( template: Template ): Promise> => { - return ipcRenderer.callMain(IpcTemplateRequest.UpdateTemplate, template) + return ipcRenderer.callMain(IpcTemplateEvent.UpdateTemplate, template) } diff --git a/packages/app/src/update/constants/controller.constant.ts b/packages/app/src/update/constants/controller.constant.ts index 6dde15df48..7714a8a820 100644 --- a/packages/app/src/update/constants/controller.constant.ts +++ b/packages/app/src/update/constants/controller.constant.ts @@ -3,29 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const DeviceUpdateControllerPrefix = "device-update" -export const ReleaseControllerPrefix = "release" - export enum IpcReleaseEvent { - GetAllReleases = "get-all-releases", - GetLatestRelease = "get-latest-release", - GetReleasesByVersions = "get-releases-by-versions", -} - -export enum IpcReleaseRequest { - GetAllReleases = "release-get-all-releases", - GetLatestRelease = "release-get-latest-release", - GetReleasesByVersions = "release-get-releases-by-versions", + GetAllReleases = "os-release_get-all-releases", + GetLatestRelease = "os-release_get-latest-release", + GetReleasesByVersions = "os-release_get-releases-by-versions", } export enum IpcDeviceUpdateEvent { - UpdateOS = "update-os", - CheckUpdate = "check-update", - RemoveDownloadedOsUpdates = "remove-downloaded-os-updates", -} - -export enum IpcDeviceUpdateRequest { - UpdateOS = "device-update-update-os", - CheckUpdate = "device-update-check-update", - RemoveDownloadedOsUpdates = "device-update-remove-downloaded-os-updates", + UpdateOS = "device-update_update-os", + CheckUpdate = "device-update_check-update", + RemoveDownloadedOsUpdates = "device-update_remove-downloaded-os-updates", } diff --git a/packages/app/src/update/controllers/device-update.controller.ts b/packages/app/src/update/controllers/device-update.controller.ts index 6490ee3c91..cce367f2fd 100644 --- a/packages/app/src/update/controllers/device-update.controller.ts +++ b/packages/app/src/update/controllers/device-update.controller.ts @@ -3,19 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { ResultObject } from "App/core/builder" import { UpdateOS } from "App/update/dto" import { DeviceUpdateFilesService, DeviceUpdateService, } from "App/update/services" -import { - DeviceUpdateControllerPrefix, - IpcDeviceUpdateEvent, -} from "App/update/constants" +import { IpcDeviceUpdateEvent } from "App/update/constants" -@Controller(DeviceUpdateControllerPrefix) export class DeviceUpdateController { constructor( private deviceUpdateService: DeviceUpdateService, diff --git a/packages/app/src/update/controllers/releases.controller.ts b/packages/app/src/update/controllers/releases.controller.ts index 83015f2575..b5b395f3db 100644 --- a/packages/app/src/update/controllers/releases.controller.ts +++ b/packages/app/src/update/controllers/releases.controller.ts @@ -3,18 +3,13 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Controller, IpcEvent } from "App/core/decorators" +import { IpcEvent } from "App/core/decorators" import { Feature, flags } from "App/feature-flags" import { ResultObject, Result } from "App/core/builder" -import { - ReleaseControllerPrefix, - IpcReleaseEvent, - Product, -} from "App/update/constants" +import { IpcReleaseEvent, Product } from "App/update/constants" import { GetReleasesByVersionsInput, OsRelease } from "App/update/dto" import { ReleaseService } from "App/update/services" -@Controller(ReleaseControllerPrefix) export class ReleasesController { constructor(private releaseService: ReleaseService) {} diff --git a/packages/app/src/update/requests/checkUpdate.request.ts b/packages/app/src/update/requests/checkUpdate.request.ts index 9547b38b4a..0f3d62dbb6 100644 --- a/packages/app/src/update/requests/checkUpdate.request.ts +++ b/packages/app/src/update/requests/checkUpdate.request.ts @@ -6,12 +6,12 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" import { - IpcDeviceUpdateRequest, UpdateErrorServiceErrors, + IpcDeviceUpdateEvent, } from "App/update/constants" export const checkUpdate = async (): Promise< ResultObject > => { - return ipcRenderer.callMain(IpcDeviceUpdateRequest.CheckUpdate) + return ipcRenderer.callMain(IpcDeviceUpdateEvent.CheckUpdate) } diff --git a/packages/app/src/update/requests/get-all-releases.request.ts b/packages/app/src/update/requests/get-all-releases.request.ts index 4811021dc0..f3df6c18a0 100644 --- a/packages/app/src/update/requests/get-all-releases.request.ts +++ b/packages/app/src/update/requests/get-all-releases.request.ts @@ -5,14 +5,14 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcReleaseRequest, Product } from "App/update/constants" +import { IpcReleaseEvent, Product } from "App/update/constants" import { OsRelease } from "App/update/dto" export const getAllReleasesRequest = async ( product: Product, deviceSerialNumber?: string ): Promise> => { - return ipcRenderer.callMain(IpcReleaseRequest.GetAllReleases, { + return ipcRenderer.callMain(IpcReleaseEvent.GetAllReleases, { product, deviceSerialNumber, }) diff --git a/packages/app/src/update/requests/get-latest-release.request.ts b/packages/app/src/update/requests/get-latest-release.request.ts index 3101ccb11f..2dff2e0d9d 100644 --- a/packages/app/src/update/requests/get-latest-release.request.ts +++ b/packages/app/src/update/requests/get-latest-release.request.ts @@ -5,14 +5,14 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" -import { IpcReleaseRequest, Product } from "App/update/constants" +import { IpcReleaseEvent, Product } from "App/update/constants" import { OsRelease } from "App/update/dto" export const getLatestReleaseRequest = async ( product: Product, deviceSerialNumber?: string ): Promise> => { - return ipcRenderer.callMain(IpcReleaseRequest.GetLatestRelease, { + return ipcRenderer.callMain(IpcReleaseEvent.GetLatestRelease, { product, deviceSerialNumber, }) diff --git a/packages/app/src/update/requests/get-releases-by-versions.request.ts b/packages/app/src/update/requests/get-releases-by-versions.request.ts index 5e5bad8160..fec99efb86 100644 --- a/packages/app/src/update/requests/get-releases-by-versions.request.ts +++ b/packages/app/src/update/requests/get-releases-by-versions.request.ts @@ -4,12 +4,12 @@ */ import { ResultObject } from "App/core/builder" -import { IpcReleaseRequest } from "App/update/constants" +import { IpcReleaseEvent } from "App/update/constants" import { GetReleasesByVersionsInput, OsRelease } from "App/update/dto" import { ipcRenderer } from "electron-better-ipc" export const getReleasesByVersions = async ( params: GetReleasesByVersionsInput ): Promise> => { - return ipcRenderer.callMain(IpcReleaseRequest.GetReleasesByVersions, params) + return ipcRenderer.callMain(IpcReleaseEvent.GetReleasesByVersions, params) } diff --git a/packages/app/src/update/requests/remove-downloaded-os-updates.request.ts b/packages/app/src/update/requests/remove-downloaded-os-updates.request.ts index 975853dd4b..5780d02c5a 100644 --- a/packages/app/src/update/requests/remove-downloaded-os-updates.request.ts +++ b/packages/app/src/update/requests/remove-downloaded-os-updates.request.ts @@ -4,8 +4,8 @@ */ import { ipcRenderer } from "electron-better-ipc" -import { IpcDeviceUpdateRequest } from "App/update/constants" +import { IpcDeviceUpdateEvent } from "App/update/constants" export const removeDownloadedOsUpdates = (): Promise => { - return ipcRenderer.callMain(IpcDeviceUpdateRequest.RemoveDownloadedOsUpdates) + return ipcRenderer.callMain(IpcDeviceUpdateEvent.RemoveDownloadedOsUpdates) } diff --git a/packages/app/src/update/requests/start-os-update.request.ts b/packages/app/src/update/requests/start-os-update.request.ts index 69a2edf07e..1b3ae4a996 100644 --- a/packages/app/src/update/requests/start-os-update.request.ts +++ b/packages/app/src/update/requests/start-os-update.request.ts @@ -6,7 +6,7 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "App/core/builder" import { - IpcDeviceUpdateRequest, + IpcDeviceUpdateEvent, UpdateErrorServiceErrors, } from "App/update/constants" import { UpdateOS } from "App/update/dto" @@ -14,5 +14,5 @@ import { UpdateOS } from "App/update/dto" export const startOsUpdate = async ( payload: UpdateOS ): Promise> => { - return ipcRenderer.callMain(IpcDeviceUpdateRequest.UpdateOS, payload) + return ipcRenderer.callMain(IpcDeviceUpdateEvent.UpdateOS, payload) } From 01365046a174bfc0cc94a89f074e1bcd566bdd53 Mon Sep 17 00:00:00 2001 From: Oskar Michalkiewicz <32848134+OskarMichalkiewicz@users.noreply.github.com> Date: Wed, 25 Oct 2023 08:01:10 +0000 Subject: [PATCH 6/8] [CP-2202] Add a dedicated version of Mudita Center for mass updates (#1494) Co-authored-by: patryk-sierzega <126664583+patryk-sierzega@users.noreply.github.com> Co-authored-by: Daniel Karski --- .env.example | 1 + .github/workflows/nexus-development.yml | 1 + .github/workflows/nexus-pre-production.yml | 1 + .github/workflows/nexus-production.yml | 1 + .../services/analytic-data-tracker.factory.ts | 3 ++- 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 0fde896bb5..55a5c880f2 100644 --- a/.env.example +++ b/.env.example @@ -30,6 +30,7 @@ FRESHDESK_API_URL= FRESHDESK_API_TOKEN= # [Optional] analytics.mudita.com +ANALYTICS_ENABLED= ANALYTICS_API_URL= ANALYTICS_API_SITE_ID= diff --git a/.github/workflows/nexus-development.yml b/.github/workflows/nexus-development.yml index 21fedf5589..5e48e734e2 100644 --- a/.github/workflows/nexus-development.yml +++ b/.github/workflows/nexus-development.yml @@ -32,6 +32,7 @@ jobs: FONTS_DIRECTORY_URL: ${{ secrets.FONTS_DIRECTORY_URL }} FRESHDESK_API_URL: ${{ secrets.FRESHDESK_API_URL }} FRESHDESK_API_TOKEN: ${{ secrets.FRESHDESK_API_TOKEN }} + ANALYTICS_ENABLED: ${{ secrets.ANALYTICS_ENABLED }} ANALYTICS_API_URL: ${{ secrets.ANALYTICS_API_URL }} ANALYTICS_API_SITE_ID: ${{ secrets.ANALYTICS_API_SITE_ID }} FEATURE_TOGGLE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_ENVIRONMENT }} diff --git a/.github/workflows/nexus-pre-production.yml b/.github/workflows/nexus-pre-production.yml index 34f27a833c..94553fec59 100644 --- a/.github/workflows/nexus-pre-production.yml +++ b/.github/workflows/nexus-pre-production.yml @@ -33,6 +33,7 @@ jobs: FONTS_DIRECTORY_URL: ${{ secrets.FONTS_DIRECTORY_URL }} FRESHDESK_API_URL: ${{ secrets.FRESHDESK_API_URL }} FRESHDESK_API_TOKEN: ${{ secrets.FRESHDESK_API_TOKEN }} + ANALYTICS_ENABLED: ${{ secrets.ANALYTICS_ENABLED }} ANALYTICS_API_URL: ${{ secrets.ANALYTICS_API_URL }} ANALYTICS_API_SITE_ID: ${{ secrets.ANALYTICS_API_SITE_ID }} FEATURE_TOGGLE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_ENVIRONMENT }} diff --git a/.github/workflows/nexus-production.yml b/.github/workflows/nexus-production.yml index efd6f2f994..0b740cafc7 100644 --- a/.github/workflows/nexus-production.yml +++ b/.github/workflows/nexus-production.yml @@ -33,6 +33,7 @@ jobs: FONTS_DIRECTORY_URL: ${{ secrets.FONTS_DIRECTORY_URL }} FRESHDESK_API_URL: ${{ secrets.FRESHDESK_API_URL }} FRESHDESK_API_TOKEN: ${{ secrets.FRESHDESK_API_TOKEN }} + ANALYTICS_ENABLED: ${{ secrets.ANALYTICS_ENABLED }} ANALYTICS_API_URL: ${{ secrets.ANALYTICS_API_URL }} ANALYTICS_API_SITE_ID: ${{ secrets.ANALYTICS_API_SITE_ID }} FEATURE_TOGGLE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_ENVIRONMENT }} diff --git a/packages/app/src/analytic-data-tracker/services/analytic-data-tracker.factory.ts b/packages/app/src/analytic-data-tracker/services/analytic-data-tracker.factory.ts index 713851cb8f..c9390bf77a 100644 --- a/packages/app/src/analytic-data-tracker/services/analytic-data-tracker.factory.ts +++ b/packages/app/src/analytic-data-tracker/services/analytic-data-tracker.factory.ts @@ -64,7 +64,8 @@ export class AnalyticDataTrackerFactory { const appSettings = settingsService.getSettings() const _id = appSettings.applicationId - const trackingEnabled = appSettings.privacyPolicyAccepted + const trackingEnabled = + appSettings.privacyPolicyAccepted && process.env.ANALYTICS_ENABLED === "1" const axiosInstance: AxiosInstance = axios.create({ httpsAgent: new https.Agent({ From f6946e19b1ac0f5d30dd120c101baab7eba0c9c5 Mon Sep 17 00:00:00 2001 From: Oskar Michalkiewicz <32848134+OskarMichalkiewicz@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:11:59 +0000 Subject: [PATCH 7/8] [CP-2151] MC update badge status enhancements (#1497) Co-authored-by: patryk-sierzega <126664583+patryk-sierzega@users.noreply.github.com> Co-authored-by: Daniel Karski --- .../app/src/__deprecated__/main/autoupdate.ts | 1 - .../update-button/update-button.component.tsx | 2 +- .../renderer/locales/default/en-US.json | 2 +- .../renderer/wrappers/root-wrapper.test.tsx | 156 ------------------ .../renderer/wrappers/root-wrapper.tsx | 21 ++- .../actions/load-settings.action.test.ts | 1 + .../settings/actions/load-settings.action.ts | 1 + .../set-checking-for-update-failed.action.ts | 11 ++ .../actions/set-settings.action.test.ts | 1 + .../components/about/about-ui.component.tsx | 144 ++++++++-------- .../components/about/about.component.tsx | 13 +- .../components/about/about.stories.tsx | 2 - .../settings/components/about/about.test.tsx | 46 ++++-- .../src/settings/constants/event.constant.ts | 1 + .../settings/reducers/settings.interface.ts | 1 + .../reducers/settings.reducer.test.ts | 1 + .../src/settings/reducers/settings.reducer.ts | 5 + 17 files changed, 143 insertions(+), 266 deletions(-) delete mode 100644 packages/app/src/__deprecated__/renderer/wrappers/root-wrapper.test.tsx create mode 100644 packages/app/src/settings/actions/set-checking-for-update-failed.action.ts diff --git a/packages/app/src/__deprecated__/main/autoupdate.ts b/packages/app/src/__deprecated__/main/autoupdate.ts index 2bc920f09f..8f7cdcc07b 100644 --- a/packages/app/src/__deprecated__/main/autoupdate.ts +++ b/packages/app/src/__deprecated__/main/autoupdate.ts @@ -53,7 +53,6 @@ export default (win: BrowserWindow): void => { }) autoUpdater.on("error", (error) => { void ipcMain.callRenderer(win, AppUpdateEvent.Error, error) - void ipcMain.callRenderer(win, AppUpdateEvent.NotAvailable) win.setProgressBar(-1) }) autoUpdater.on("download-progress", ({ percent }) => { diff --git a/packages/app/src/__deprecated__/renderer/components/rest/news/update-button/update-button.component.tsx b/packages/app/src/__deprecated__/renderer/components/rest/news/update-button/update-button.component.tsx index 9cedc782ee..f8b2451394 100644 --- a/packages/app/src/__deprecated__/renderer/components/rest/news/update-button/update-button.component.tsx +++ b/packages/app/src/__deprecated__/renderer/components/rest/news/update-button/update-button.component.tsx @@ -57,7 +57,7 @@ const UpdateButtonComponent: FunctionComponent< ({ - remote: { - Menu: () => ({ - popup: jest.fn, - append: jest.fn, - }), - MenuItem: () => jest.fn(), - getCurrentWindow: jest.fn(), - app: { - getPath: () => "", - }, - }, - app: { - getPath: () => "", - }, -})) - -jest.mock( - "electron-better-ipc", - () => { - const mockIpcRenderer = { - callMain: jest.fn(), - answerMain: () => jest.fn(), - on: jest.fn(), - removeListener: jest.fn(), - } - return { ipcRenderer: mockIpcRenderer } - }, - { virtual: true } -) - -jest.mock("App/__deprecated__/renderer/requests/connect-device.request", () => - jest.fn().mockReturnValue({ - status: "ok", - }) -) - -jest.mock("App/settings/requests", () => ({ - getConfiguration: jest.fn().mockReturnValue({ - centerVersion: "1.0.0", - productVersions: { - MuditaHarmony: "1.0.0", - MuditaPure: "1.0.0", - }, - }), -})) - -jest.mock("App/settings/requests/get-settings.request.ts", () => ({ - getAppSettings: jest.fn().mockReturnValue({ - autostart: false, - tethering: false, - incomingCalls: false, - incomingMessages: false, - lowBattery: false, - osUpdates: false, - nonStandardAudioFilesConversion: false, - convert: "Convert automatically", - conversionFormat: "WAV", - tray: true, - osBackupLocation: `fake/path/pure/phone/backups/`, - osDownloadLocation: `fake/path/pure/os/downloads/`, - language: "en-US", - neverConnected: true, - collectingData: undefined, - diagnosticSentTimestamp: 0, - }), -})) - -jest.mock("App/__deprecated__/renderer/requests/check-app-update.request") - -type Props = ComponentProps - -const defaultProps: Props = { - history, -} - -const store = init({ - models: { networkStatus }, - redux: { - middlewares: [thunk], - reducers: { - device: deviceReducer, - backup: backupReducer, - crashDump: crashDumpReducer, - modalsManager: modalsManagerReducer, - settings: settingsReducer, - update: updateOsReducer, - dataSync: dataSyncReducer, - }, - }, -}) as Store - -const render = (extraProps?: Partial) => { - const props = { - ...defaultProps, - ...extraProps, - } - - return { - ...testingLibraryRender( - - - - ), - store, - } -} - -test("checkAppUpdateRequest isn't call when online is set to false ", async () => { - const online = jest.spyOn(window.navigator, "onLine", "get") - online.mockReturnValue(false) - - render() - - await waitFor(() => { - expect(checkUpdateAvailable).not.toHaveBeenCalled() - }) -}) - -test("appUpdateAvailable is to false when online is set to false", async () => { - const online = jest.spyOn(window.navigator, "onLine", "get") - online.mockReturnValue(false) - - const { store } = render() - - await waitFor(() => { - expect( - (store.getState() as unknown as ReduxRootState).settings.updateAvailable - ).toBeFalsy() - }) -}) diff --git a/packages/app/src/__deprecated__/renderer/wrappers/root-wrapper.tsx b/packages/app/src/__deprecated__/renderer/wrappers/root-wrapper.tsx index 257b7e4f5f..b3b1b9cee6 100644 --- a/packages/app/src/__deprecated__/renderer/wrappers/root-wrapper.tsx +++ b/packages/app/src/__deprecated__/renderer/wrappers/root-wrapper.tsx @@ -69,6 +69,8 @@ import { import { setConnectionStatus } from "App/device/actions" import { resetUploadingState } from "App/files-manager/actions" import { setInitializationFailed } from "App/data-sync/actions" +import registerErrorAppUpdateListener from "App/__deprecated__/main/functions/register-error-app-update-listener" +import { setCheckingForUpdateFailed } from "App/settings/actions/set-checking-for-update-failed.action" interface Props { history: History @@ -144,14 +146,6 @@ const RootWrapper: FunctionComponent = ({ [mode, history] ) - const handleAppUpdateAvailableCheck = (): void => { - if (!window.navigator.onLine) { - toggleApplicationUpdateAvailable(false) - } else { - checkUpdateAvailable() - } - } - const onDeviceDetachHandler = () => { void resetUploadingState() void setConnectionStatus(false) @@ -220,8 +214,17 @@ const RootWrapper: FunctionComponent = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [connectedAndUnlocked]) + useEffect(() => { + const unregister = registerErrorAppUpdateListener(() => { + dispatch(setCheckingForUpdateFailed(true)) + setCheckingForUpdate(false) + }) + return () => unregister() + }) + useEffect(() => { const unregister = registerAvailableAppUpdateListener((version) => { + dispatch(setCheckingForUpdateFailed(false)) setCheckingForUpdate(false) toggleApplicationUpdateAvailable(true) setLatestVersion(version as string) @@ -242,7 +245,7 @@ const RootWrapper: FunctionComponent = ({ useEffect(() => { loadSettings() if (!mode) { - handleAppUpdateAvailableCheck() + checkUpdateAvailable() } const devModeEnabled = flags.get(Feature.DeveloperModeEnabled) diff --git a/packages/app/src/settings/actions/load-settings.action.test.ts b/packages/app/src/settings/actions/load-settings.action.test.ts index 6a9c0db841..2a69344788 100644 --- a/packages/app/src/settings/actions/load-settings.action.test.ts +++ b/packages/app/src/settings/actions/load-settings.action.test.ts @@ -63,6 +63,7 @@ test("`loadSettings` action dispatch SettingsEvent.LoadSettings event and calls type: SettingsEvent.SetSettings, payload: { checkingForUpdate: false, + checkingForUpdateFailed: false, collectingData: false, currentVersion: `${packageInfo.version}`, lowestSupportedVersions: { diff --git a/packages/app/src/settings/actions/load-settings.action.ts b/packages/app/src/settings/actions/load-settings.action.ts index 59501b2d6a..4cff4adc55 100644 --- a/packages/app/src/settings/actions/load-settings.action.ts +++ b/packages/app/src/settings/actions/load-settings.action.ts @@ -47,6 +47,7 @@ export const loadSettings = createAsyncThunk( updateRequired, currentVersion: packageInfo.version, checkingForUpdate: false, + checkingForUpdateFailed: false, lowestSupportedVersions: { lowestSupportedCenterVersion: configuration.centerVersion, lowestSupportedProductVersion: configuration.productVersions, diff --git a/packages/app/src/settings/actions/set-checking-for-update-failed.action.ts b/packages/app/src/settings/actions/set-checking-for-update-failed.action.ts new file mode 100644 index 0000000000..106d3ee259 --- /dev/null +++ b/packages/app/src/settings/actions/set-checking-for-update-failed.action.ts @@ -0,0 +1,11 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createAction } from "@reduxjs/toolkit" +import { SettingsEvent } from "App/settings/constants" + +export const setCheckingForUpdateFailed = createAction( + SettingsEvent.SetCheckingForUpdateFailed +) diff --git a/packages/app/src/settings/actions/set-settings.action.test.ts b/packages/app/src/settings/actions/set-settings.action.test.ts index 3df94d8d87..4c4bdac1d5 100644 --- a/packages/app/src/settings/actions/set-settings.action.test.ts +++ b/packages/app/src/settings/actions/set-settings.action.test.ts @@ -44,6 +44,7 @@ const settings: Omit< }, }, checkingForUpdate: false, + checkingForUpdateFailed: false, } const mockStore = createMockStore([thunk])() diff --git a/packages/app/src/settings/components/about/about-ui.component.tsx b/packages/app/src/settings/components/about/about-ui.component.tsx index 0b018fab2d..9d532924f9 100644 --- a/packages/app/src/settings/components/about/about-ui.component.tsx +++ b/packages/app/src/settings/components/about/about-ui.component.tsx @@ -3,11 +3,10 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import React, { useState, useEffect } from "react" +import React, { useState } from "react" import { FunctionComponent } from "App/__deprecated__/renderer/types/function-component.interface" import { ActionsWrapper } from "App/__deprecated__/renderer/components/rest/messages/threads-table.component" import { TextDisplayStyle } from "App/__deprecated__/renderer/components/core/text/text.component" -import { FormattedMessage } from "react-intl" import ButtonComponent from "App/__deprecated__/renderer/components/core/button/button.component" import { DisplayStyle } from "App/__deprecated__/renderer/components/core/button/button.config" import { @@ -28,8 +27,13 @@ import { AppUpdateNotAvailable } from "App/__deprecated__/renderer/wrappers/app- import { UpdateFailedModal } from "App/settings/components/about/update-failed-modal.component" import { AboutLoaderModal } from "App/settings/components/about/about-loader.component" import { ModalLayers } from "App/modals-manager/constants/modal-layers.enum" -import { useOnlineChecker } from "App/settings/hooks/use-online-checker" -import registerErrorAppUpdateListener from "App/__deprecated__/main/functions/register-error-app-update-listener" +import { defineMessages, FormattedMessage } from "react-intl" +import UpdateButtonComponent from "App/__deprecated__/renderer/components/rest/news/update-button/update-button.component" +import { intl } from "App/__deprecated__/renderer/utils/intl" +import { useDispatch, useSelector } from "react-redux" +import { ModalStateKey, showModal } from "App/modals-manager" +import { ReduxRootState } from "App/__deprecated__/renderer/store" +import { setCheckingForUpdateFailed } from "App/settings/actions/set-checking-for-update-failed.action" const AvailableUpdate = styled(Text)` margin-top: 0.8rem; @@ -57,6 +61,27 @@ const ActionContainer = styled.div` align-items: center; margin-right: 3rem; ` +const StyledUpdateButton = styled(UpdateButtonComponent)` + min-width: 17.6rem; +` + +const messages = defineMessages({ + updateCheckButton: { + id: "module.overview.systemCheckForUpdates", + }, + updateAvailableButton: { + id: "module.settings.aboutAppUpdateAction", + }, + updateAvailableBadge: { + id: "module.settings.aboutAvailableVersion", + }, + updateFailedBadge: { + id: "module.overview.systemUpdateCheckFailed", + }, + upToDateBadge: { + id: "module.overview.systemUpdateUpToDate", + }, +}) interface Props { openLicense: () => void @@ -69,8 +94,6 @@ interface Props { onAppUpdateAvailableCheck: () => void hideAppUpdateNotAvailable: () => void checkingForUpdate: boolean - appUpdateFailedShow: boolean - hideAppUpdateFailed: () => void } const AboutUI: FunctionComponent = ({ @@ -84,13 +107,17 @@ const AboutUI: FunctionComponent = ({ onAppUpdateAvailableCheck, hideAppUpdateNotAvailable, checkingForUpdate, - appUpdateFailedShow, - hideAppUpdateFailed, }) => { + const dispatch = useDispatch() const [updateCheck, setUpdateCheck] = useState(false) - const online = useOnlineChecker() - + const { checkingForUpdateFailed } = useSelector( + (state: ReduxRootState) => state.settings + ) + const { appUpdateFlowShow } = useSelector( + (state: ReduxRootState) => state.modalsManager + ) const appUpdateAvailableCheckHandler = () => { + dispatch(setCheckingForUpdateFailed(false)) setUpdateCheck(true) onAppUpdateAvailableCheck() } @@ -101,23 +128,24 @@ const AboutUI: FunctionComponent = ({ const hideAppUpdateFailedHandler = () => { setUpdateCheck(false) hideAppUpdateNotAvailable() - hideAppUpdateFailed() } const showUpToDateModal = - updateCheck && !appUpdateFailedShow && !checkingForUpdate + !checkingForUpdateFailed && !checkingForUpdate && updateCheck - useEffect(() => { - const unregister = registerErrorAppUpdateListener(() => { - setUpdateCheck(false) - }) - return () => unregister() - }, []) + const handleProcessDownload = () => { + void dispatch(showModal(ModalStateKey.AppUpdateFlow)) + } + const badgeText = appUpdateAvailable + ? messages.updateAvailableBadge + : checkingForUpdateFailed + ? messages.updateFailedBadge + : messages.upToDateBadge return ( <> @@ -128,7 +156,7 @@ const AboutUI: FunctionComponent = ({ {showUpToDateModal && ( @@ -143,60 +171,34 @@ const AboutUI: FunctionComponent = ({ /> - {!online && ( - - - - - - - )} - {appUpdateAvailable && online && ( - - + + + {!checkingForUpdate && !appUpdateFlowShow && ( - - - - )} - {!appUpdateAvailable && online && ( - - - - - - - )} + )} + + + diff --git a/packages/app/src/settings/components/about/about.component.tsx b/packages/app/src/settings/components/about/about.component.tsx index f1189b3a5e..ae0f7c67f1 100644 --- a/packages/app/src/settings/components/about/about.component.tsx +++ b/packages/app/src/settings/components/about/about.component.tsx @@ -26,7 +26,6 @@ export const About: FunctionComponent = ({ }) => { const [appUpdateNotAvailableShow, setAppUpdateNotAvailableShow] = useState(false) - const [appUpdateFailedShow, setAppUpdateFailedShow] = useState(false) const openLicenseWindow = () => ipcRenderer.callMain(AboutActions.LicenseOpenWindow) @@ -39,20 +38,12 @@ export const About: FunctionComponent = ({ setAppUpdateNotAvailableShow(false) } - const hideAppUpdateFailed = () => { - setAppUpdateFailedShow(false) - } - useEffect(() => { setAppUpdateNotAvailableShow(updateAvailable === false) }, [updateAvailable, checkingForUpdate]) const handleAppUpdateAvailableCheck = (): void => { - if (!window.navigator.onLine) { - setAppUpdateFailedShow(true) - } else { - checkUpdateAvailable() - } + checkUpdateAvailable() } return ( @@ -67,8 +58,6 @@ export const About: FunctionComponent = ({ appUpdateNotAvailableShow={appUpdateNotAvailableShow} hideAppUpdateNotAvailable={hideAppUpdateNotAvailable} checkingForUpdate={checkingForUpdate} - appUpdateFailedShow={appUpdateFailedShow} - hideAppUpdateFailed={hideAppUpdateFailed} /> ) } diff --git a/packages/app/src/settings/components/about/about.stories.tsx b/packages/app/src/settings/components/about/about.stories.tsx index 62e8410e9d..f95d21afd9 100644 --- a/packages/app/src/settings/components/about/about.stories.tsx +++ b/packages/app/src/settings/components/about/about.stories.tsx @@ -17,8 +17,6 @@ storiesOf("Settings/About", module).add("About", () => ( hideAppUpdateNotAvailable={noop} onAppUpdateAvailableCheck={noop} checkingForUpdate={false} - appUpdateFailedShow={false} - hideAppUpdateFailed={noop} /> )) diff --git a/packages/app/src/settings/components/about/about.test.tsx b/packages/app/src/settings/components/about/about.test.tsx index 4f8a5fd06c..b2a46c5381 100644 --- a/packages/app/src/settings/components/about/about.test.tsx +++ b/packages/app/src/settings/components/about/about.test.tsx @@ -9,9 +9,11 @@ import React, { ComponentProps } from "react" import AboutUI from "./about-ui.component" import { noop } from "App/__deprecated__/renderer/utils/noop" import { AboutTestIds } from "App/settings/components/about/about.enum" -import { fireEvent, screen } from "@testing-library/dom" +import { screen, waitFor } from "@testing-library/dom" import { AppUpdateStepModalTestIds } from "App/__deprecated__/renderer/wrappers/app-update-step-modal/app-update-step-modal-test-ids.enum" import { flags } from "App/feature-flags" +import store from "App/__deprecated__/renderer/store" +import { Provider } from "react-redux" jest.mock("App/feature-flags") jest.mock( @@ -30,8 +32,6 @@ const defaultProps: Props = { appUpdateAvailable: true, appUpdateNotAvailableShow: false, checkingForUpdate: false, - appUpdateFailedShow: false, - hideAppUpdateFailed: noop, } const renderer = (extraProps?: Partial) => { @@ -39,7 +39,11 @@ const renderer = (extraProps?: Partial) => { ...defaultProps, ...extraProps, } - const outcome = renderWithThemeAndIntl() + const outcome = renderWithThemeAndIntl( + + + + ) return { ...outcome, } @@ -57,24 +61,40 @@ test("renders at least one table row", () => { ) }) -test("Opens update modal properly when app update is not available", () => { +test("Opens update modal properly when app update is not available", async () => { const { getByTestId } = renderer({ appLatestVersion: "0.20.2", appCurrentVersion: "0.20.2", appUpdateNotAvailableShow: true, + appUpdateAvailable: false, }) - getByTestId(AboutTestIds.UpdateButton).click() + const button = getByTestId(AboutTestIds.UpdateButton) + await waitFor(() => { + expect(button).toBeEnabled() + }) + button.click() - expect( - screen.getByTestId(AppUpdateStepModalTestIds.AppUpdateNotAvailableModal) - ).toBeInTheDocument() + await waitFor(() => { + expect( + screen.getByTestId(AppUpdateStepModalTestIds.AppUpdateNotAvailableModal) + ).toBeInTheDocument() + }) }) -test("Calls AppUpdateAvailableCheck when clicked", () => { +test("Calls AppUpdateAvailableCheck when clicked", async () => { jest.spyOn(flags, "get").mockReturnValueOnce(true) const onAppUpdateAvailableCheck = jest.fn() - const { queryByTestId } = renderer({ onAppUpdateAvailableCheck }) - fireEvent.click(queryByTestId(AboutTestIds.UpdateButton) as HTMLElement) - expect(onAppUpdateAvailableCheck).toHaveBeenCalledTimes(1) + const { getByTestId } = renderer({ + onAppUpdateAvailableCheck, + appUpdateAvailable: false, + }) + const button = getByTestId(AboutTestIds.UpdateButton) + await waitFor(() => { + expect(button).toBeEnabled() + }) + button.click() + await waitFor(() => { + expect(onAppUpdateAvailableCheck).toHaveBeenCalledTimes(1) + }) }) diff --git a/packages/app/src/settings/constants/event.constant.ts b/packages/app/src/settings/constants/event.constant.ts index f3ce2dab41..9ee0444cb8 100644 --- a/packages/app/src/settings/constants/event.constant.ts +++ b/packages/app/src/settings/constants/event.constant.ts @@ -24,4 +24,5 @@ export enum SettingsEvent { SendDiagnosticData = "SEND_DIAGNOSTIC_DATA", DeleteCollectingData = "DELETE_COLLECTING_DATA", SetCheckingForUpdate = "SET_CHECKING_FOR_UPDATE", + SetCheckingForUpdateFailed = "SET_CHECKING_FOR_UPDATE_FAILED", } diff --git a/packages/app/src/settings/reducers/settings.interface.ts b/packages/app/src/settings/reducers/settings.interface.ts index 9087af1260..c000c76a3e 100644 --- a/packages/app/src/settings/reducers/settings.interface.ts +++ b/packages/app/src/settings/reducers/settings.interface.ts @@ -20,4 +20,5 @@ export interface SettingsState extends Settings { updateRequired: boolean updateAvailable: boolean | undefined checkingForUpdate: boolean + checkingForUpdateFailed: boolean } diff --git a/packages/app/src/settings/reducers/settings.reducer.test.ts b/packages/app/src/settings/reducers/settings.reducer.test.ts index 763e40fbf6..d264501e23 100644 --- a/packages/app/src/settings/reducers/settings.reducer.test.ts +++ b/packages/app/src/settings/reducers/settings.reducer.test.ts @@ -49,6 +49,7 @@ const settings: Omit< }, }, checkingForUpdate: false, + checkingForUpdateFailed: false, } test("empty event returns initial state", () => { diff --git a/packages/app/src/settings/reducers/settings.reducer.ts b/packages/app/src/settings/reducers/settings.reducer.ts index c6ae5a17c6..784ae2d540 100644 --- a/packages/app/src/settings/reducers/settings.reducer.ts +++ b/packages/app/src/settings/reducers/settings.reducer.ts @@ -26,6 +26,7 @@ import { setCheckingForUpdate, } from "App/settings/actions" import { deleteCollectingData } from "App/settings/actions/delete-collecting-data.action" +import { setCheckingForUpdateFailed } from "../actions/set-checking-for-update-failed.action" export const initialState: SettingsState = { applicationId: "", @@ -55,6 +56,7 @@ export const initialState: SettingsState = { loaded: false, loading: false, checkingForUpdate: false, + checkingForUpdateFailed: false, } export const settingsReducer = createReducer( @@ -159,5 +161,8 @@ export const settingsReducer = createReducer( .addCase(setCheckingForUpdate, (state, action) => { state.checkingForUpdate = action.payload }) + .addCase(setCheckingForUpdateFailed, (state, action) => { + state.checkingForUpdateFailed = action.payload + }) } ) From 2625afbc0bfa3f6d1d3c435eeea5876479edad4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kowalczyk?= <37898730+lkowalczyk87@users.noreply.github.com> Date: Wed, 25 Oct 2023 12:32:28 +0200 Subject: [PATCH 8/8] update changelog for 2.2.4 (#1519) --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 553fc8c422..1ea9229b4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Here we write upgrading notes for brands. It's a team effort to make them as straightforward as possible. +## [2.2.4] - 2023-10-26 + +Here we write upgrading notes for brands. It's a team effort to make them as +straightforward as possible. + +### Fixed + +- Secondary phone number disappears after deleting it + +### Changed + +- Enhance of update badge status for Mudita Center +- Enhance of update badge status for OS + ## [2.2.3] - 2023-05-10 ### Fixed