From 9a268387216f54ae28a1c25e755e88c06e4358f8 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Thu, 6 Jun 2024 15:02:05 +0200 Subject: [PATCH 001/100] [CP-2898] device-manager generated --- libs/device-manager/.babelrc | 20 ++++++++++++++++++++ libs/device-manager/.eslintrc.json | 18 ++++++++++++++++++ libs/device-manager/README.md | 7 +++++++ libs/device-manager/jest.config.ts | 11 +++++++++++ libs/device-manager/project.json | 20 ++++++++++++++++++++ libs/device-manager/src/index.ts | 4 ++++ libs/device-manager/tsconfig.json | 20 ++++++++++++++++++++ libs/device-manager/tsconfig.lib.json | 24 ++++++++++++++++++++++++ libs/device-manager/tsconfig.spec.json | 20 ++++++++++++++++++++ tsconfig.base.json | 1 + 10 files changed, 145 insertions(+) create mode 100644 libs/device-manager/.babelrc create mode 100644 libs/device-manager/.eslintrc.json create mode 100644 libs/device-manager/README.md create mode 100644 libs/device-manager/jest.config.ts create mode 100644 libs/device-manager/project.json create mode 100644 libs/device-manager/src/index.ts create mode 100644 libs/device-manager/tsconfig.json create mode 100644 libs/device-manager/tsconfig.lib.json create mode 100644 libs/device-manager/tsconfig.spec.json diff --git a/libs/device-manager/.babelrc b/libs/device-manager/.babelrc new file mode 100644 index 0000000000..ef4889c1ab --- /dev/null +++ b/libs/device-manager/.babelrc @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [ + [ + "styled-components", + { + "pure": true, + "ssr": true + } + ] + ] +} diff --git a/libs/device-manager/.eslintrc.json b/libs/device-manager/.eslintrc.json new file mode 100644 index 0000000000..d3e61a2ea8 --- /dev/null +++ b/libs/device-manager/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/device-manager/README.md b/libs/device-manager/README.md new file mode 100644 index 0000000000..9e9426a85f --- /dev/null +++ b/libs/device-manager/README.md @@ -0,0 +1,7 @@ +# device-manager + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test device-manager` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-manager/jest.config.ts b/libs/device-manager/jest.config.ts new file mode 100644 index 0000000000..8f614ef088 --- /dev/null +++ b/libs/device-manager/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "device-manager", + preset: "../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../coverage/libs/device-manager", +} diff --git a/libs/device-manager/project.json b/libs/device-manager/project.json new file mode 100644 index 0000000000..80ee4f9952 --- /dev/null +++ b/libs/device-manager/project.json @@ -0,0 +1,20 @@ +{ + "name": "device-manager", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/device-manager/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/device-manager/jest.config.ts" + } + } + } +} diff --git a/libs/device-manager/src/index.ts b/libs/device-manager/src/index.ts new file mode 100644 index 0000000000..e6a6939657 --- /dev/null +++ b/libs/device-manager/src/index.ts @@ -0,0 +1,4 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ diff --git a/libs/device-manager/tsconfig.json b/libs/device-manager/tsconfig.json new file mode 100644 index 0000000000..3c41f10fb2 --- /dev/null +++ b/libs/device-manager/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../tsconfig.base.json" +} diff --git a/libs/device-manager/tsconfig.lib.json b/libs/device-manager/tsconfig.lib.json new file mode 100644 index 0000000000..cfc4843293 --- /dev/null +++ b/libs/device-manager/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/device-manager/tsconfig.spec.json b/libs/device-manager/tsconfig.spec.json new file mode 100644 index 0000000000..26ef046ac5 --- /dev/null +++ b/libs/device-manager/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 8fa587cdb0..93ff4d8f71 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -28,6 +28,7 @@ "E2E/*": ["./apps/mudita-center-e2e/src/*"], "Libs/*": ["./libs/*"], "Root/*": ["./*"], + "device-manager": ["libs/device-manager/src/index.ts"], "device/adapters": ["libs/device/adapters/src/index.ts"], "device/feature": ["libs/device/feature/src/index.ts"], "device/models": ["libs/device/models/src/index.ts"], From d4f2f5e4faf4edb011b64393ab022260d553a082 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 7 Jun 2024 10:21:34 +0200 Subject: [PATCH 002/100] [CP-2898] device-protocol generated --- libs/device-protocol/.babelrc | 12 ++++++++++++ libs/device-protocol/.eslintrc.json | 18 ++++++++++++++++++ libs/device-protocol/README.md | 7 +++++++ libs/device-protocol/jest.config.ts | 11 +++++++++++ libs/device-protocol/project.json | 20 ++++++++++++++++++++ libs/device-protocol/src/index.ts | 6 ++++++ libs/device-protocol/tsconfig.json | 20 ++++++++++++++++++++ libs/device-protocol/tsconfig.lib.json | 24 ++++++++++++++++++++++++ libs/device-protocol/tsconfig.spec.json | 20 ++++++++++++++++++++ tsconfig.base.json | 1 + 10 files changed, 139 insertions(+) create mode 100644 libs/device-protocol/.babelrc create mode 100644 libs/device-protocol/.eslintrc.json create mode 100644 libs/device-protocol/README.md create mode 100644 libs/device-protocol/jest.config.ts create mode 100644 libs/device-protocol/project.json create mode 100644 libs/device-protocol/src/index.ts create mode 100644 libs/device-protocol/tsconfig.json create mode 100644 libs/device-protocol/tsconfig.lib.json create mode 100644 libs/device-protocol/tsconfig.spec.json diff --git a/libs/device-protocol/.babelrc b/libs/device-protocol/.babelrc new file mode 100644 index 0000000000..1ea870ead4 --- /dev/null +++ b/libs/device-protocol/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/device-protocol/.eslintrc.json b/libs/device-protocol/.eslintrc.json new file mode 100644 index 0000000000..d3e61a2ea8 --- /dev/null +++ b/libs/device-protocol/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/device-protocol/README.md b/libs/device-protocol/README.md new file mode 100644 index 0000000000..05cae1f828 --- /dev/null +++ b/libs/device-protocol/README.md @@ -0,0 +1,7 @@ +# device-protocol + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test device-protocol` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-protocol/jest.config.ts b/libs/device-protocol/jest.config.ts new file mode 100644 index 0000000000..5d89c82171 --- /dev/null +++ b/libs/device-protocol/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "device-protocol", + preset: "../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../coverage/libs/device-protocol", +} diff --git a/libs/device-protocol/project.json b/libs/device-protocol/project.json new file mode 100644 index 0000000000..625383bde8 --- /dev/null +++ b/libs/device-protocol/project.json @@ -0,0 +1,20 @@ +{ + "name": "device-protocol", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/device-protocol/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/device-protocol/jest.config.ts" + } + } + } +} diff --git a/libs/device-protocol/src/index.ts b/libs/device-protocol/src/index.ts new file mode 100644 index 0000000000..a92db91ecd --- /dev/null +++ b/libs/device-protocol/src/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./lib/device-protocol" diff --git a/libs/device-protocol/tsconfig.json b/libs/device-protocol/tsconfig.json new file mode 100644 index 0000000000..3c41f10fb2 --- /dev/null +++ b/libs/device-protocol/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../tsconfig.base.json" +} diff --git a/libs/device-protocol/tsconfig.lib.json b/libs/device-protocol/tsconfig.lib.json new file mode 100644 index 0000000000..cfc4843293 --- /dev/null +++ b/libs/device-protocol/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/device-protocol/tsconfig.spec.json b/libs/device-protocol/tsconfig.spec.json new file mode 100644 index 0000000000..26ef046ac5 --- /dev/null +++ b/libs/device-protocol/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 93ff4d8f71..7d8bf51287 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -29,6 +29,7 @@ "Libs/*": ["./libs/*"], "Root/*": ["./*"], "device-manager": ["libs/device-manager/src/index.ts"], + "device-protocol": ["libs/device-protocol/src/index.ts"], "device/adapters": ["libs/device/adapters/src/index.ts"], "device/feature": ["libs/device/feature/src/index.ts"], "device/models": ["libs/device/models/src/index.ts"], From de6f1081fec9d088d04772c2166e99f64fdff466 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 7 Jun 2024 10:44:02 +0200 Subject: [PATCH 003/100] [CP-2898] core-device generated --- libs/core-device/.babelrc | 12 ++++++++++++ libs/core-device/.eslintrc.json | 18 ++++++++++++++++++ libs/core-device/README.md | 7 +++++++ libs/core-device/jest.config.ts | 11 +++++++++++ libs/core-device/project.json | 20 ++++++++++++++++++++ libs/core-device/src/index.ts | 6 ++++++ libs/core-device/tsconfig.json | 20 ++++++++++++++++++++ libs/core-device/tsconfig.lib.json | 24 ++++++++++++++++++++++++ libs/core-device/tsconfig.spec.json | 20 ++++++++++++++++++++ 9 files changed, 138 insertions(+) create mode 100644 libs/core-device/.babelrc create mode 100644 libs/core-device/.eslintrc.json create mode 100644 libs/core-device/README.md create mode 100644 libs/core-device/jest.config.ts create mode 100644 libs/core-device/project.json create mode 100644 libs/core-device/src/index.ts create mode 100644 libs/core-device/tsconfig.json create mode 100644 libs/core-device/tsconfig.lib.json create mode 100644 libs/core-device/tsconfig.spec.json diff --git a/libs/core-device/.babelrc b/libs/core-device/.babelrc new file mode 100644 index 0000000000..1ea870ead4 --- /dev/null +++ b/libs/core-device/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/core-device/.eslintrc.json b/libs/core-device/.eslintrc.json new file mode 100644 index 0000000000..d3e61a2ea8 --- /dev/null +++ b/libs/core-device/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/core-device/README.md b/libs/core-device/README.md new file mode 100644 index 0000000000..c7a124f9c2 --- /dev/null +++ b/libs/core-device/README.md @@ -0,0 +1,7 @@ +# core-device + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test core-device` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/core-device/jest.config.ts b/libs/core-device/jest.config.ts new file mode 100644 index 0000000000..a3390894a9 --- /dev/null +++ b/libs/core-device/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "core-device", + preset: "../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../coverage/libs/core-device", +} diff --git a/libs/core-device/project.json b/libs/core-device/project.json new file mode 100644 index 0000000000..062abc5cf8 --- /dev/null +++ b/libs/core-device/project.json @@ -0,0 +1,20 @@ +{ + "name": "core-device", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/core-device/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/core-device/jest.config.ts" + } + } + } +} diff --git a/libs/core-device/src/index.ts b/libs/core-device/src/index.ts new file mode 100644 index 0000000000..355c98239d --- /dev/null +++ b/libs/core-device/src/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./lib/core-device" diff --git a/libs/core-device/tsconfig.json b/libs/core-device/tsconfig.json new file mode 100644 index 0000000000..3c41f10fb2 --- /dev/null +++ b/libs/core-device/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../tsconfig.base.json" +} diff --git a/libs/core-device/tsconfig.lib.json b/libs/core-device/tsconfig.lib.json new file mode 100644 index 0000000000..cfc4843293 --- /dev/null +++ b/libs/core-device/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/core-device/tsconfig.spec.json b/libs/core-device/tsconfig.spec.json new file mode 100644 index 0000000000..26ef046ac5 --- /dev/null +++ b/libs/core-device/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} From 1afea6869c2a8817f3de22993baa0e3d9c65ef49 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Thu, 6 Jun 2024 15:08:04 +0200 Subject: [PATCH 004/100] [CP-2898] Moved DeviceManager to a separate library with modular dependencies --- libs/core-device/README.md | 7 - libs/core-device/{ => feature}/.babelrc | 0 libs/core-device/{ => feature}/.eslintrc.json | 2 +- libs/core-device/feature/README.md | 7 + libs/core-device/{ => feature}/jest.config.ts | 6 +- .../feature}/project.json | 8 +- .../feature/src/actions/base.action.ts | 21 + .../src}/actions/configure-device.action.ts | 16 +- libs/core-device/feature/src/actions/index.ts | 7 + .../src/constants/controller.constant.ts | 8 + .../feature/src/constants/event.constant.ts | 11 + .../feature/src}/constants/index.ts | 1 - .../controllers/core-device.controller.ts} | 26 +- .../feature/src/controllers}/index.ts | 2 +- .../feature/src/core-device.module.ts | 25 + libs/core-device/feature/src/index.ts | 10 + .../src/reducers/core-device.reducer.ts} | 56 +- .../{src => feature/src/reducers}/index.ts | 2 +- .../get-device-configuration.request.ts | 6 +- .../core-device/feature/src/requests/index.ts | 6 + .../selectors/core-device-state.selector.ts | 10 + .../selectors/get-core-devices.selector.ts | 15 + .../feature/src/selectors/index.ts | 7 + .../device-cache-configuration.service.ts | 2 +- .../core-device/feature/src/services/index.ts | 6 + .../feature}/tsconfig.json | 2 +- .../{ => feature}/tsconfig.lib.json | 2 +- .../feature}/tsconfig.spec.json | 2 +- .../models}/.babelrc | 0 .../models}/.eslintrc.json | 2 +- libs/core-device/models/README.md | 7 + .../models}/jest.config.ts | 6 +- .../models}/project.json | 8 +- .../models/src}/case-colour.constant.ts | 0 .../models/src/core-device.interface.ts} | 7 +- .../device-communication-error.constant.ts | 0 .../models/src}/endpoint.constant.ts | 0 libs/core-device/models/src/index.ts | 10 + .../models/src}/request-method.constant.ts | 0 libs/core-device/{ => models}/tsconfig.json | 2 +- .../models}/tsconfig.lib.json | 2 +- .../models}/tsconfig.spec.json | 2 +- .../interfaces/device-info.interface.ts | 2 +- .../core/icon/battery-icon.component.tsx | 4 +- .../core/icon/battery-icon.test.tsx | 2 +- .../components/core/icon/icon.stories.tsx | 6 +- .../rest/menu/menu-bottom.component.tsx | 14 +- .../rest/menu/menu-group.component.tsx | 2 +- .../rest/menu/menu-top.component.tsx | 2 +- .../components/rest/menu/menu.component.tsx | 6 +- .../components/rest/menu/menu.test.tsx | 17 +- .../renderer/constants/menu-elements.ts | 2 +- .../models/basic-info/basic-info.typings.ts | 3 +- .../__deprecated__/renderer/store/reducers.ts | 4 +- .../map-device-type-to-product.helper.test.ts | 2 +- .../map-device-type-to-product.helper.ts | 2 +- .../use-dynamic-progress-value.hook.test.tsx | 89 ---- .../analytic-data-tracker.module.ts | 4 +- .../helpers/track-os-update.test.ts | 2 +- .../helpers/track-os-update.ts | 2 +- .../helpers/track-os-version.test.ts | 2 +- .../helpers/track-os-version.ts | 2 +- libs/core/backup/actions/base.action.ts | 3 - libs/core/backup/backup.module.ts | 4 +- libs/core/backup/constants/event.enum.ts | 1 - libs/core/backup/reducers/backup.reducer.ts | 5 +- .../services/backup-create.service.test.ts | 12 +- .../backup/services/backup-create.service.ts | 7 +- .../services/backup-restore.service.test.ts | 7 +- .../backup/services/backup-restore.service.ts | 6 +- .../backup/services/base-backup.service.ts | 8 +- .../services/sync-backup-create.service.ts | 7 +- .../actions/send-ticket.action.test.ts | 3 +- libs/core/contacts/actions/base.action.ts | 4 - .../actions/delete-contacts.action.ts | 2 +- .../contacts/actions/import-contact.action.ts | 2 +- .../contacts/contacts.component.tsx | 2 +- libs/core/contacts/constants/event.enum.ts | 1 - libs/core/contacts/contact.module.ts | 4 +- .../contacts/reducers/contacts.reducer.ts | 5 +- .../contacts/services/contact.service.test.ts | 6 +- .../core/contacts/services/contact.service.ts | 10 +- libs/core/core/application.module.ts | 25 +- .../hooks/use-device-connect-failed-effect.ts | 14 +- .../core/hooks/use-device-connected-effect.ts | 26 +- .../core/hooks/use-device-detached-effect.ts | 21 +- .../core/hooks/use-device-locked-effect.ts | 4 +- .../hooks/use-discovery-redirect-effect.ts | 3 +- .../hooks/use-watch-outbox-entries-effect.ts | 4 +- .../hooks/use-watch-unlock-status-effect.ts | 6 +- libs/core/core/module/base.module.ts | 4 +- libs/core/core/types/module.type.ts | 4 +- .../crash-dump-modal.component.tsx | 2 +- .../crash-dump-modal.stories.tsx | 2 +- .../crash-dump-modal.test.tsx | 2 +- .../crash-dump/crash-dump.component.test.tsx | 2 +- .../crash-dump/crash-dump.interface.ts | 2 +- libs/core/crash-dump/crash-dump.module.ts | 4 +- .../services/crash-dump.service.test.ts | 12 +- .../crash-dump/services/crash-dump.service.ts | 7 +- .../data-sync/actions/base-app.action.test.ts | 27 - .../core/data-sync/actions/base-app.action.ts | 3 - libs/core/data-sync/constants/event.enum.ts | 2 - libs/core/data-sync/data-sync.module.ts | 4 +- .../data-sync/reducers/data-sync.reducer.ts | 12 +- .../data-sync/services/data-sync.service.ts | 4 +- libs/core/desktop/desktop.module.ts | 4 +- .../commands/base.command.ts | 4 +- .../commands/file-delete.command.test.ts | 10 +- .../commands/file-delete.command.ts | 2 +- .../commands/file-upload.command.test.ts | 10 +- .../commands/file-upload.command.ts | 6 +- .../commands/retrieve-files.command.test.ts | 10 +- .../commands/retrieve-files.command.ts | 2 +- .../device-file-system.module.ts | 4 +- .../device-file-system.service.test.ts | 6 +- .../services/device-file-system.service.ts | 6 +- libs/core/device-info/device-info.module.ts | 4 +- .../device-info/dto/device-info.object.ts | 2 +- .../presenters/device-info.presenter.ts | 3 +- .../services/device-info.service.ts | 10 +- .../initialize-mudita-harmony.action.ts | 5 +- .../actions/initialize-mudita-pure.action.ts | 10 +- .../devices-initialization.component.tsx | 6 +- ...s-passcode-modal-can-be-closed.selector.ts | 2 +- libs/core/device-log/device-log.module.ts | 4 +- .../services/device-log.service.test.ts | 12 +- .../device-log/services/device-log.service.ts | 7 +- .../device-manager/actions/base.action.ts | 18 - .../actions/connect-device.action.ts | 22 - .../selectors/get-device.selector.ts | 17 - .../selectors/get-devices.selector.ts | 15 - .../selectors/get-failed-devices.selector.ts | 20 - .../device-select-drawer.component.tsx | 14 +- .../components/drawer-device.component.tsx | 4 +- .../is-select-device-drawer-open.selector.ts | 2 +- libs/core/device/actions/base.action.ts | 5 +- .../actions/get-onboarding-status.action.ts | 5 +- .../actions/get-unlock-status.action.ts | 3 +- .../handle-communication-error.action.ts | 3 +- .../device/actions/load-device-data.action.ts | 2 +- .../process-device-data-on-load.action.ts | 2 +- .../device/actions/unlock-device.action.ts | 7 +- .../constants/device-base-properties.ts | 2 +- libs/core/device/constants/event.enum.ts | 2 - libs/core/device/constants/index.ts | 5 - .../device/descriptors/device-descriptor.ts | 8 +- .../descriptors/mudita-harmony.descriptor.ts | 8 +- .../descriptors/mudita-pure.descriptor.ts | 8 +- libs/core/device/device.module.ts | 4 +- libs/core/device/factories/device.factory.ts | 2 +- libs/core/device/modules/base-device.ts | 2 +- libs/core/device/modules/core-device.ts | 3 +- libs/core/device/modules/device.class.ts | 3 +- libs/core/device/modules/mock-core-device.ts | 3 +- .../adapters/serial-port-device.adapters.ts | 3 +- libs/core/device/reducers/device.interface.ts | 4 +- libs/core/device/reducers/device.reducer.ts | 5 +- .../requests/unlock-device-status.request.ts | 3 +- .../device/selectors/device-type.selector.ts | 2 +- .../is-active-device-processing.selector.ts | 2 +- libs/core/device/services/device.service.ts | 12 +- .../strategies/device-strategy.class.ts | 2 +- .../device/strategies/harmony.strategy.ts | 2 +- libs/core/device/strategies/pure.strategy.ts | 2 +- .../types/mudita-os/request-config.type.ts | 2 +- .../device/types/mudita-os/response.type.ts | 3 +- .../mudita-os/serialport-request.type.ts | 5 +- .../device/types/serial-port-device.type.ts | 2 +- .../available-device-list.component.tsx | 8 +- .../available-device-list.container.tsx | 2 +- ...configured-devices-discovery.component.tsx | 23 +- .../device-connecting.component.tsx | 5 +- .../components/device-list-item.component.tsx | 4 +- .../components/device-list.component.tsx | 13 +- .../hooks/use-no-new-devices-detected.hook.ts | 5 +- .../utils/get-device-type-name.ts | 3 +- .../core/files-manager/actions/base.action.ts | 4 - .../files-manager/actions/get-files.action.ts | 5 +- .../files-manager/constants/event.enum.ts | 1 - .../files-manager/files-manager.module.ts | 4 +- .../reducers/files-manager.reducer.ts | 5 +- ...-dettached-during-upload-error.selector.ts | 2 +- .../index-storage/index-storage.module.ts | 4 +- libs/core/messages/actions/base.action.ts | 4 - .../actions/update-message.action.test.ts | 2 +- libs/core/messages/constants/event.enum.ts | 2 - libs/core/messages/message.module.ts | 4 +- .../messages/reducers/messages.reducer.ts | 4 +- .../messages/services/message.service.test.ts | 7 +- .../core/messages/services/message.service.ts | 7 +- .../messages/services/thread.service.test.ts | 6 +- libs/core/messages/services/thread.service.ts | 11 +- .../connecting-loader-modal.component.tsx | 9 +- .../use-loader-skip-on-connect.hook.ts | 2 +- .../onboarding-troubleshooting.component.tsx | 2 +- libs/core/outbox/factories/outbox.factory.ts | 4 +- libs/core/outbox/outbox.module.ts | 4 +- .../outbox/services/outbox.service.test.ts | 12 +- libs/core/outbox/services/outbox.service.ts | 12 +- .../device-preview/device-image.component.tsx | 37 +- .../device-preview.component.tsx | 2 +- .../device-preview.interface.tsx | 3 +- .../device-preview/device-preview.stories.tsx | 2 +- .../device-preview/device-preview.test.tsx | 3 +- .../harmony-overview.component.interface.ts | 3 +- .../harmony-overview.component.test.tsx | 2 +- .../harmony-overview.component.tsx | 2 +- .../overview-content.component.tsx | 3 +- .../helpers/use-update-flow-state.hook.tsx | 2 +- .../helpers/use-update-flow-state.test.tsx | 4 +- .../helpers/use-watch-device-data-effect.ts | 2 +- .../kompakt-overview.component.interface.ts | 3 +- .../overview-content.component.tsx | 3 +- .../pure-overview.component.test.tsx | 2 +- .../pure-overview/pure-overview.component.tsx | 4 +- .../pure-overview/pure-overview.interface.ts | 3 +- ...use-deactivate-device-and-redirect.hook.ts | 5 +- .../use-handle-active-device-aborted.hook.ts | 2 +- .../overview/overview.component.tsx | 2 +- .../components/overview/overview.test.tsx | 3 +- .../components/status/status.component.tsx | 2 +- .../components/status/status.interface.tsx | 2 +- .../components/status/status.stories.tsx | 2 +- .../components/status/status.test.tsx | 2 +- .../components/system/system.component.tsx | 2 +- .../components/system/system.stories.tsx | 2 +- .../components/system/system.test.tsx | 4 +- .../update-os-flow.component.interface.ts | 2 +- .../update-os-flow.component.test.tsx | 2 +- .../too-low-battery-modal.component.tsx | 2 +- .../too-low-battery-modal.interface.ts | 2 +- .../too-low-battery-modal.stories.tsx | 2 +- ...dating-force-modal-flow.component.test.tsx | 2 +- .../updating-force-modal-flow.interface.ts | 2 +- libs/core/overview/overview.container.tsx | 5 +- libs/core/search/search.module.ts | 4 +- .../actions/load-settings.action.test.ts | 2 +- .../core/settings/dto/configuration.object.ts | 2 +- .../settings/reducers/settings.interface.ts | 2 +- ...get-device-lowest-version.selector.test.ts | 2 +- .../get-device-lowest-version.selector.ts | 2 +- .../settings/services/settings.service.ts | 3 +- libs/core/settings/settings.module.ts | 4 +- .../services/template.service.test.ts | 7 +- .../templates/services/template.service.ts | 7 +- libs/core/templates/template.module.ts | 4 +- libs/core/update/actions/base.action.ts | 5 +- ...check-for-force-update-need.action.test.ts | 2 +- .../check-for-update.action.test.ts | 2 +- .../check-for-update.action.ts | 4 +- .../download-updates.action.test.ts | 12 +- .../download-updates.action.ts | 2 +- .../start-update-os.action.test.ts | 18 +- .../start-update-os/start-update-os.action.ts | 5 +- .../update-os-interrupted-flow.container.tsx | 6 +- libs/core/update/constants/event.constant.ts | 1 - .../update/reducers/update-os.reducer.test.ts | 31 -- .../core/update/reducers/update-os.reducer.ts | 497 +++++++++--------- .../update/services/device-update.service.ts | 14 +- libs/core/update/update.module.ts | 4 +- libs/device-manager/README.md | 7 - libs/device-manager/feature/.babelrc | 20 + .../{ => feature}/.eslintrc.json | 2 +- libs/device-manager/feature/README.md | 7 + .../feature}/jest.config.ts | 6 +- libs/device-manager/feature/project.json | 20 + .../src/actions/connect-device.action.ts | 27 + .../src}/actions/deactivate-device.action.ts | 24 +- .../actions/handle-device-activated.action.ts | 6 +- .../feature/src/actions/index.ts | 10 + .../src}/actions/set-active-device.action.ts | 6 +- .../set-select-device-drawer-open.action.ts | 4 +- .../src}/constants/controller.constant.ts | 3 - .../feature/src/constants/index.ts | 6 + .../controllers/device-manager.controller.ts | 24 + .../feature/src}/controllers/index.ts | 0 .../feature/src/device-manager.module.ts | 19 + libs/device-manager/feature/src/index.ts | 9 + .../src/reducers/device-manager.reducer.ts | 42 ++ .../feature/src/reducers/index.ts | 7 + .../src}/requests/connect-device.request.ts | 6 +- .../feature/src}/requests/index.ts | 1 + .../requests/set-active-device.request.ts | 6 +- .../selectors/active-device-id.selector.ts | 2 +- .../device-manager-state.selector.ts | 2 +- .../get-active-device-base-data.selector.ts | 27 +- .../get-active-device-type.selector.ts | 4 +- .../selectors/get-active-device.selector.ts | 10 +- .../get-available-devices.selector.ts | 6 +- .../get-configured-devices.selector.ts | 15 +- .../src/selectors/get-devices.selector.ts | 16 + .../selectors/get-failed-devices.selector.ts | 15 + .../feature/src/selectors/index.ts | 18 + .../is-active-device-attached.selector.ts | 2 +- .../is-active-device-set.selector.ts | 2 +- .../is-device-list-empty.selector.ts | 8 +- .../{ => feature}/tsconfig.json | 2 +- .../feature}/tsconfig.lib.json | 2 +- .../feature}/tsconfig.spec.json | 2 +- libs/device-manager/models/.babelrc | 20 + libs/device-manager/models/.eslintrc.json | 18 + libs/device-manager/models/README.md | 7 + libs/device-manager/models/jest.config.ts | 11 + .../models}/project.json | 8 +- .../models/src/device-manager.interface.ts | 11 + .../models/src}/event.constant.ts | 8 +- libs/device-manager/models/src/index.ts | 7 + libs/device-manager/models/tsconfig.json | 20 + libs/device-manager/models/tsconfig.lib.json | 24 + libs/device-manager/models/tsconfig.spec.json | 20 + libs/device-protocol/README.md | 7 - libs/device-protocol/{ => feature}/.babelrc | 0 libs/device-protocol/feature/.eslintrc.json | 18 + libs/device-protocol/feature/README.md | 7 + libs/device-protocol/feature/jest.config.ts | 11 + libs/device-protocol/feature/project.json | 20 + .../feature/src}/constants/error.constant.ts | 2 - .../feature/src/constants}/index.ts | 2 + .../feature/src/device-protocol.module.ts} | 17 +- libs/device-protocol/feature/src/index.ts | 7 + .../feature/src}/observers/index.ts | 0 .../usb-device-detection.observer.ts | 10 +- .../feature/src}/serial-port-list.helper.ts | 0 .../src/services/device-protocol.service.ts} | 24 +- .../services/device-resolver.service.test.ts | 5 +- .../src}/services/device-resolver.service.ts | 4 +- .../feature/src}/services/index.ts | 2 +- .../feature/src}/types/index.ts | 0 .../feature/src}/types/port.type.ts | 0 .../feature/src}/validators/index.ts | 0 .../validators/port-info.validator.test.ts | 0 .../src}/validators/port-info.validator.ts | 2 +- libs/device-protocol/feature/tsconfig.json | 20 + .../device-protocol/feature/tsconfig.lib.json | 24 + .../feature/tsconfig.spec.json | 20 + libs/device-protocol/models/.babelrc | 20 + libs/device-protocol/models/.eslintrc.json | 18 + libs/device-protocol/models/README.md | 7 + libs/device-protocol/models/jest.config.ts | 11 + libs/device-protocol/models/project.json | 20 + .../models/src/device-protocol-main-event.ts | 10 + .../models/src}/device-type.constant.ts | 0 libs/device-protocol/models/src/index.ts | 7 + libs/device-protocol/models/tsconfig.json | 20 + libs/device-protocol/models/tsconfig.lib.json | 24 + .../device-protocol/models/tsconfig.spec.json | 20 + .../src/lib/api-config/api-config.service.ts | 4 +- libs/device/feature/src/lib/api-device.ts | 2 +- .../lib/api-features/api-features.service.ts | 4 +- libs/device/feature/src/lib/api-module.ts | 12 +- .../feature/src/lib/backup/backup.service.ts | 4 +- .../data-transfer/data-transfer.service.ts | 4 +- .../device-system-actions.service.ts | 4 +- .../lib/file-manager/file-manager.service.ts | 4 +- .../file-transfer/file-transfer.service.ts | 4 +- .../feature/src/lib/menu/menu.service.ts | 4 +- .../feature/src/lib/outbox/outbox.service.ts | 4 +- .../src/lib/restore/restore.service.ts | 4 +- .../src/lib/mock-data-resolver-service.ts | 4 +- .../server/src/lib/mock-device/mock-device.ts | 3 +- .../data-migration/start-data.migration.ts | 6 +- .../hooks/use-api-serial-port-listeners.ts | 12 +- .../lib/selectors/data-migration-devices.ts | 2 +- .../components/pure-passcode.tsx | 3 +- .../data-migration/data-migration.tsx | 6 +- .../lib/use-data-migration-device-selector.ts | 8 +- libs/shared/utils/src/index.ts | 1 + .../utils/src/lib/call-renderer.helper.ts | 9 +- .../utils/src/lib/main-event.constant.ts | 6 - .../src/lib/settings-service.interface.ts | 15 + tsconfig.base.json | 8 +- 372 files changed, 1838 insertions(+), 1306 deletions(-) delete mode 100644 libs/core-device/README.md rename libs/core-device/{ => feature}/.babelrc (100%) rename libs/core-device/{ => feature}/.eslintrc.json (86%) create mode 100644 libs/core-device/feature/README.md rename libs/core-device/{ => feature}/jest.config.ts (64%) rename libs/{device-protocol => core-device/feature}/project.json (59%) create mode 100644 libs/core-device/feature/src/actions/base.action.ts rename libs/{core/device-manager => core-device/feature/src}/actions/configure-device.action.ts (60%) create mode 100644 libs/core-device/feature/src/actions/index.ts create mode 100644 libs/core-device/feature/src/constants/controller.constant.ts create mode 100644 libs/core-device/feature/src/constants/event.constant.ts rename libs/{core/device-manager => core-device/feature/src}/constants/index.ts (87%) rename libs/{core/device-manager/controllers/device-manager.controller.ts => core-device/feature/src/controllers/core-device.controller.ts} (67%) rename libs/{device-protocol/src => core-device/feature/src/controllers}/index.ts (78%) create mode 100644 libs/core-device/feature/src/core-device.module.ts create mode 100644 libs/core-device/feature/src/index.ts rename libs/{core/device-manager/reducers/device-manager.reducer.ts => core-device/feature/src/reducers/core-device.reducer.ts} (53%) rename libs/core-device/{src => feature/src/reducers}/index.ts (79%) rename libs/{core/device-manager => core-device/feature/src}/requests/get-device-configuration.request.ts (66%) create mode 100644 libs/core-device/feature/src/requests/index.ts create mode 100644 libs/core-device/feature/src/selectors/core-device-state.selector.ts create mode 100644 libs/core-device/feature/src/selectors/get-core-devices.selector.ts create mode 100644 libs/core-device/feature/src/selectors/index.ts rename libs/{core/device-manager => core-device/feature/src}/services/device-cache-configuration.service.ts (95%) create mode 100644 libs/core-device/feature/src/services/index.ts rename libs/{device-protocol => core-device/feature}/tsconfig.json (88%) rename libs/core-device/{ => feature}/tsconfig.lib.json (92%) rename libs/{device-protocol => core-device/feature}/tsconfig.spec.json (90%) rename libs/{device-manager => core-device/models}/.babelrc (100%) rename libs/{device-protocol => core-device/models}/.eslintrc.json (86%) create mode 100644 libs/core-device/models/README.md rename libs/{device-manager => core-device/models}/jest.config.ts (66%) rename libs/{device-manager => core-device/models}/project.json (59%) rename libs/{core/device/constants => core-device/models/src}/case-colour.constant.ts (100%) rename libs/{core/device-manager/reducers/device-manager.interface.ts => core-device/models/src/core-device.interface.ts} (79%) rename libs/{core/device/constants => core-device/models/src}/device-communication-error.constant.ts (100%) rename libs/{core/device/constants => core-device/models/src}/endpoint.constant.ts (100%) create mode 100644 libs/core-device/models/src/index.ts rename libs/{core/device/constants => core-device/models/src}/request-method.constant.ts (100%) rename libs/core-device/{ => models}/tsconfig.json (88%) rename libs/{device-manager => core-device/models}/tsconfig.lib.json (92%) rename libs/{device-manager => core-device/models}/tsconfig.spec.json (90%) delete mode 100644 libs/core/__deprecated__/renderer/utils/hooks/use-dynamic-progress-value.hook.test.tsx delete mode 100644 libs/core/data-sync/actions/base-app.action.test.ts delete mode 100644 libs/core/device-manager/actions/base.action.ts delete mode 100644 libs/core/device-manager/actions/connect-device.action.ts delete mode 100644 libs/core/device-manager/selectors/get-device.selector.ts delete mode 100644 libs/core/device-manager/selectors/get-devices.selector.ts delete mode 100644 libs/core/device-manager/selectors/get-failed-devices.selector.ts rename libs/core/{device-manager => device}/selectors/is-active-device-processing.selector.ts (89%) delete mode 100644 libs/device-manager/README.md create mode 100644 libs/device-manager/feature/.babelrc rename libs/device-manager/{ => feature}/.eslintrc.json (86%) create mode 100644 libs/device-manager/feature/README.md rename libs/{device-protocol => device-manager/feature}/jest.config.ts (65%) create mode 100644 libs/device-manager/feature/project.json create mode 100644 libs/device-manager/feature/src/actions/connect-device.action.ts rename libs/{core/device-manager => device-manager/feature/src}/actions/deactivate-device.action.ts (53%) rename libs/{core/device-manager => device-manager/feature/src}/actions/handle-device-activated.action.ts (85%) create mode 100644 libs/device-manager/feature/src/actions/index.ts rename libs/{core/device-manager => device-manager/feature/src}/actions/set-active-device.action.ts (84%) rename libs/{core/device-select => device-manager/feature/src}/actions/set-select-device-drawer-open.action.ts (67%) rename libs/{core/device-manager => device-manager/feature/src}/constants/controller.constant.ts (71%) create mode 100644 libs/device-manager/feature/src/constants/index.ts create mode 100644 libs/device-manager/feature/src/controllers/device-manager.controller.ts rename libs/{core/device-manager => device-manager/feature/src}/controllers/index.ts (100%) create mode 100644 libs/device-manager/feature/src/device-manager.module.ts create mode 100644 libs/device-manager/feature/src/index.ts create mode 100644 libs/device-manager/feature/src/reducers/device-manager.reducer.ts create mode 100644 libs/device-manager/feature/src/reducers/index.ts rename libs/{core/device-manager => device-manager/feature/src}/requests/connect-device.request.ts (69%) rename libs/{core/device-manager => device-manager/feature/src}/requests/index.ts (82%) rename libs/{core/device-manager => device-manager/feature/src}/requests/set-active-device.request.ts (68%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/active-device-id.selector.ts (79%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/device-manager-state.selector.ts (77%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/get-active-device-base-data.selector.ts (51%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/get-active-device-type.selector.ts (72%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/get-active-device.selector.ts (53%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/get-available-devices.selector.ts (59%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/get-configured-devices.selector.ts (57%) create mode 100644 libs/device-manager/feature/src/selectors/get-devices.selector.ts create mode 100644 libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts create mode 100644 libs/device-manager/feature/src/selectors/index.ts rename libs/{core/device-manager => device-manager/feature/src}/selectors/is-active-device-attached.selector.ts (79%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/is-active-device-set.selector.ts (78%) rename libs/{core/device-manager => device-manager/feature/src}/selectors/is-device-list-empty.selector.ts (56%) rename libs/device-manager/{ => feature}/tsconfig.json (88%) rename libs/{device-protocol => device-manager/feature}/tsconfig.lib.json (92%) rename libs/{core-device => device-manager/feature}/tsconfig.spec.json (90%) create mode 100644 libs/device-manager/models/.babelrc create mode 100644 libs/device-manager/models/.eslintrc.json create mode 100644 libs/device-manager/models/README.md create mode 100644 libs/device-manager/models/jest.config.ts rename libs/{core-device => device-manager/models}/project.json (58%) create mode 100644 libs/device-manager/models/src/device-manager.interface.ts rename libs/{core/device-manager/constants => device-manager/models/src}/event.constant.ts (73%) create mode 100644 libs/device-manager/models/src/index.ts create mode 100644 libs/device-manager/models/tsconfig.json create mode 100644 libs/device-manager/models/tsconfig.lib.json create mode 100644 libs/device-manager/models/tsconfig.spec.json delete mode 100644 libs/device-protocol/README.md rename libs/device-protocol/{ => feature}/.babelrc (100%) create mode 100644 libs/device-protocol/feature/.eslintrc.json create mode 100644 libs/device-protocol/feature/README.md create mode 100644 libs/device-protocol/feature/jest.config.ts create mode 100644 libs/device-protocol/feature/project.json rename libs/{core/device-manager => device-protocol/feature/src}/constants/error.constant.ts (66%) rename libs/{device-manager/src => device-protocol/feature/src/constants}/index.ts (81%) rename libs/{core/device-manager/device-manager.module.ts => device-protocol/feature/src/device-protocol.module.ts} (63%) create mode 100644 libs/device-protocol/feature/src/index.ts rename libs/{core/device-manager => device-protocol/feature/src}/observers/index.ts (100%) rename libs/{core/device-manager => device-protocol/feature/src}/observers/usb-device-detection.observer.ts (90%) rename libs/{core/device-manager/services => device-protocol/feature/src}/serial-port-list.helper.ts (100%) rename libs/{core/device-manager/services/device-manager.service.ts => device-protocol/feature/src/services/device-protocol.service.ts} (89%) rename libs/{core/device-manager => device-protocol/feature/src}/services/device-resolver.service.test.ts (87%) rename libs/{core/device-manager => device-protocol/feature/src}/services/device-resolver.service.ts (96%) rename libs/{core/device-manager => device-protocol/feature/src}/services/index.ts (82%) rename libs/{core/device-manager => device-protocol/feature/src}/types/index.ts (100%) rename libs/{core/device-manager => device-protocol/feature/src}/types/port.type.ts (100%) rename libs/{core/device-manager => device-protocol/feature/src}/validators/index.ts (100%) rename libs/{core/device-manager => device-protocol/feature/src}/validators/port-info.validator.test.ts (100%) rename libs/{core/device-manager => device-protocol/feature/src}/validators/port-info.validator.ts (98%) create mode 100644 libs/device-protocol/feature/tsconfig.json create mode 100644 libs/device-protocol/feature/tsconfig.lib.json create mode 100644 libs/device-protocol/feature/tsconfig.spec.json create mode 100644 libs/device-protocol/models/.babelrc create mode 100644 libs/device-protocol/models/.eslintrc.json create mode 100644 libs/device-protocol/models/README.md create mode 100644 libs/device-protocol/models/jest.config.ts create mode 100644 libs/device-protocol/models/project.json create mode 100644 libs/device-protocol/models/src/device-protocol-main-event.ts rename libs/{core/device/constants => device-protocol/models/src}/device-type.constant.ts (100%) create mode 100644 libs/device-protocol/models/src/index.ts create mode 100644 libs/device-protocol/models/tsconfig.json create mode 100644 libs/device-protocol/models/tsconfig.lib.json create mode 100644 libs/device-protocol/models/tsconfig.spec.json create mode 100644 libs/shared/utils/src/lib/settings-service.interface.ts diff --git a/libs/core-device/README.md b/libs/core-device/README.md deleted file mode 100644 index c7a124f9c2..0000000000 --- a/libs/core-device/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# core-device - -This library was generated with [Nx](https://nx.dev). - -## Running unit tests - -Run `nx test core-device` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/core-device/.babelrc b/libs/core-device/feature/.babelrc similarity index 100% rename from libs/core-device/.babelrc rename to libs/core-device/feature/.babelrc diff --git a/libs/core-device/.eslintrc.json b/libs/core-device/feature/.eslintrc.json similarity index 86% rename from libs/core-device/.eslintrc.json rename to libs/core-device/feature/.eslintrc.json index d3e61a2ea8..cacbe26215 100644 --- a/libs/core-device/.eslintrc.json +++ b/libs/core-device/feature/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": ["../../.eslintrc.js"], + "extends": ["../../../.eslintrc.js"], "ignorePatterns": ["!**/*"], "overrides": [ { diff --git a/libs/core-device/feature/README.md b/libs/core-device/feature/README.md new file mode 100644 index 0000000000..f33c7eb8b8 --- /dev/null +++ b/libs/core-device/feature/README.md @@ -0,0 +1,7 @@ +# core-device-feature + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test core-device-feature` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/core-device/jest.config.ts b/libs/core-device/feature/jest.config.ts similarity index 64% rename from libs/core-device/jest.config.ts rename to libs/core-device/feature/jest.config.ts index a3390894a9..9b89b49e49 100644 --- a/libs/core-device/jest.config.ts +++ b/libs/core-device/feature/jest.config.ts @@ -1,11 +1,11 @@ /* eslint-disable */ export default { - displayName: "core-device", - preset: "../../jest.preset.js", + displayName: "core-device-feature", + preset: "../../../jest.preset.js", transform: { "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], }, moduleFileExtensions: ["ts", "tsx", "js", "jsx"], - coverageDirectory: "../../coverage/libs/core-device", + coverageDirectory: "../../../coverage/libs/core-device/feature", } diff --git a/libs/device-protocol/project.json b/libs/core-device/feature/project.json similarity index 59% rename from libs/device-protocol/project.json rename to libs/core-device/feature/project.json index 625383bde8..07471387aa 100644 --- a/libs/device-protocol/project.json +++ b/libs/core-device/feature/project.json @@ -1,7 +1,7 @@ { - "name": "device-protocol", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/device-protocol/src", + "name": "core-device-feature", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/core-device/feature/src", "projectType": "library", "tags": [], "targets": { @@ -13,7 +13,7 @@ "executor": "@nx/jest:jest", "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], "options": { - "jestConfig": "libs/device-protocol/jest.config.ts" + "jestConfig": "libs/core-device/feature/jest.config.ts" } } } diff --git a/libs/core-device/feature/src/actions/base.action.ts b/libs/core-device/feature/src/actions/base.action.ts new file mode 100644 index 0000000000..6d0b3dee60 --- /dev/null +++ b/libs/core-device/feature/src/actions/base.action.ts @@ -0,0 +1,21 @@ +/** + * 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 { DeviceBaseProperties } from "Core/device/constants/device-base-properties" +import { DeviceState, CaseColour } from "core-device/models" +import { CoreDeviceEvent } from "../constants" + +export const addDevice = createAction< + DeviceBaseProperties & Partial<{ state: DeviceState; caseColour: CaseColour }> +>(CoreDeviceEvent.AddDevice) + +export const removeDevice = createAction( + CoreDeviceEvent.RemoveDevice +) + +export const setDeviceState = createAction<{ id: string; state: DeviceState }>( + CoreDeviceEvent.SetDeviceState +) diff --git a/libs/core/device-manager/actions/configure-device.action.ts b/libs/core-device/feature/src/actions/configure-device.action.ts similarity index 60% rename from libs/core/device-manager/actions/configure-device.action.ts rename to libs/core-device/feature/src/actions/configure-device.action.ts index 48214e1c75..e786858377 100644 --- a/libs/core/device-manager/actions/configure-device.action.ts +++ b/libs/core-device/feature/src/actions/configure-device.action.ts @@ -4,12 +4,12 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { DeviceType } from "device-protocol/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceManagerEvent } from "Core/device-manager/constants" import { DeviceId } from "Core/device/constants/device-id" -import { getDeviceConfigurationRequest } from "Core/device-manager/requests/get-device-configuration.request" -import { DeviceConfiguration } from "Core/device-manager/controllers" -import { DeviceType } from "Core/device" +import { getDeviceConfigurationRequest } from "../requests" +import { DeviceConfiguration } from "../controllers" +import { CoreDeviceEvent } from "../constants" interface ConfigureDevicePayload extends Partial { id: DeviceId @@ -19,10 +19,12 @@ export const configureDevice = createAsyncThunk< ConfigureDevicePayload, DeviceId, { state: ReduxRootState } ->(DeviceManagerEvent.ConfigureDevice, async (id, {getState}) => { +>(CoreDeviceEvent.ConfigureDevice, async (id, { getState }) => { // TODO: tmp solution to handle APIDevice - const device = getState().deviceManager.devices.find((device) => device.id === id) - if(device?.deviceType === DeviceType.APIDevice){ + const device = getState().coreDevice.devices.find( + (device) => device.id === id + ) + if (device?.deviceType === DeviceType.APIDevice) { return { id } } diff --git a/libs/core-device/feature/src/actions/index.ts b/libs/core-device/feature/src/actions/index.ts new file mode 100644 index 0000000000..9c5a7b6378 --- /dev/null +++ b/libs/core-device/feature/src/actions/index.ts @@ -0,0 +1,7 @@ +/** + * 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 "./base.action" +export * from "./configure-device.action" diff --git a/libs/core-device/feature/src/constants/controller.constant.ts b/libs/core-device/feature/src/constants/controller.constant.ts new file mode 100644 index 0000000000..5b127b3fca --- /dev/null +++ b/libs/core-device/feature/src/constants/controller.constant.ts @@ -0,0 +1,8 @@ +/** + * 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 IpcCoreDeviceEvent { + GetCoreDeviceConfiguration = "core-device_get-core-device-configuration", +} diff --git a/libs/core-device/feature/src/constants/event.constant.ts b/libs/core-device/feature/src/constants/event.constant.ts new file mode 100644 index 0000000000..1a4e71fb22 --- /dev/null +++ b/libs/core-device/feature/src/constants/event.constant.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 + */ + +export enum CoreDeviceEvent { + AddDevice = "core-device_add-device", + RemoveDevice = "core-device_remove-device", + SetDeviceState = "core-device_set-device-state", + ConfigureDevice = "core-device_configure-device", +} diff --git a/libs/core/device-manager/constants/index.ts b/libs/core-device/feature/src/constants/index.ts similarity index 87% rename from libs/core/device-manager/constants/index.ts rename to libs/core-device/feature/src/constants/index.ts index 47cd8ebe91..5a48343da1 100644 --- a/libs/core/device-manager/constants/index.ts +++ b/libs/core-device/feature/src/constants/index.ts @@ -4,5 +4,4 @@ */ export * from "./controller.constant" -export * from "./error.constant" export * from "./event.constant" diff --git a/libs/core/device-manager/controllers/device-manager.controller.ts b/libs/core-device/feature/src/controllers/core-device.controller.ts similarity index 67% rename from libs/core/device-manager/controllers/device-manager.controller.ts rename to libs/core-device/feature/src/controllers/core-device.controller.ts index 494aa405a9..41879c3e47 100644 --- a/libs/core/device-manager/controllers/device-manager.controller.ts +++ b/libs/core-device/feature/src/controllers/core-device.controller.ts @@ -4,36 +4,31 @@ */ import { IpcEvent } from "Core/core/decorators" -import { DeviceManager } from "Core/device-manager/services" -import { IpcDeviceManagerEvent } from "Core/device-manager/constants" +import { DeviceProtocolService } from "device-protocol/feature" import { Result, ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" +import { DeviceInfo } from "Core/device/types/mudita-os" import { CaseColour, DeviceCommunicationError, Endpoint, Method, -} from "Core/device" -import { DeviceInfo } from "Core/device/types/mudita-os" -import { DeviceCacheConfigurationService } from "Core/device-manager/services/device-cache-configuration.service" +} from "core-device/models" +import { DeviceCacheConfigurationService } from "../services" +import { IpcCoreDeviceEvent } from "../constants" export interface DeviceConfiguration { caseColour: CaseColour | undefined serialNumber: string | undefined } -export class DeviceManagerController { +export class CoreDeviceController { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private deviceCacheConfigurationService: DeviceCacheConfigurationService ) {} - @IpcEvent(IpcDeviceManagerEvent.SetActiveDevice) - public setActiveDevice(id: DeviceId | undefined): ResultObject { - return this.deviceManager.setActiveDevice(id) - } - - @IpcEvent(IpcDeviceManagerEvent.GetDeviceConfiguration) + @IpcEvent(IpcCoreDeviceEvent.GetCoreDeviceConfiguration) public async request( id: DeviceId ): Promise> { @@ -65,9 +60,4 @@ export class DeviceManagerController { return result } } - - @IpcEvent(IpcDeviceManagerEvent.ConnectDevice) - public connectDevice(id: DeviceId): Promise> { - return this.deviceManager.connectDevice(id) - } } diff --git a/libs/device-protocol/src/index.ts b/libs/core-device/feature/src/controllers/index.ts similarity index 78% rename from libs/device-protocol/src/index.ts rename to libs/core-device/feature/src/controllers/index.ts index a92db91ecd..529b494a9b 100644 --- a/libs/device-protocol/src/index.ts +++ b/libs/core-device/feature/src/controllers/index.ts @@ -3,4 +3,4 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -// export * from "./lib/device-protocol" +export * from "./core-device.controller" diff --git a/libs/core-device/feature/src/core-device.module.ts b/libs/core-device/feature/src/core-device.module.ts new file mode 100644 index 0000000000..4b5ab12533 --- /dev/null +++ b/libs/core-device/feature/src/core-device.module.ts @@ -0,0 +1,25 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { DeviceProtocolService } from "device-protocol/feature" +import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" +import { DeviceCacheConfigurationService } from "./services" +import { CoreDeviceController } from "./controllers" + +export class CoreDeviceModule { + public controllers + + constructor( + public deviceManager: DeviceProtocolService, + public fileSystem: FileSystemService + ) { + const deviceManagerController = new CoreDeviceController( + this.deviceManager, + new DeviceCacheConfigurationService(this.fileSystem) + ) + + this.controllers = [deviceManagerController] + } +} diff --git a/libs/core-device/feature/src/index.ts b/libs/core-device/feature/src/index.ts new file mode 100644 index 0000000000..ef3ecbcae5 --- /dev/null +++ b/libs/core-device/feature/src/index.ts @@ -0,0 +1,10 @@ +/** + * 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 "./actions" +export * from "./reducers" +export * from "./requests" +export * from "./selectors" +export * from "./core-device.module" diff --git a/libs/core/device-manager/reducers/device-manager.reducer.ts b/libs/core-device/feature/src/reducers/core-device.reducer.ts similarity index 53% rename from libs/core/device-manager/reducers/device-manager.reducer.ts rename to libs/core-device/feature/src/reducers/core-device.reducer.ts index 9fa2f186ee..5cf6bcfab6 100644 --- a/libs/core/device-manager/reducers/device-manager.reducer.ts +++ b/libs/core-device/feature/src/reducers/core-device.reducer.ts @@ -4,38 +4,22 @@ */ import { createReducer } from "@reduxjs/toolkit" -import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" -import { - Device, - DeviceManagerState, - DeviceState, -} from "Core/device-manager/reducers/device-manager.interface" +import { Device, CoreDeviceState, DeviceState } from "core-device/models" import { addDevice, removeDevice, -} from "Core/device-manager/actions/base.action" -import { setActiveDevice } from "Core/device-manager/actions/set-active-device.action" -import { configureDevice } from "Core/device-manager/actions/configure-device.action" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" -import { setSelectDeviceDrawerOpen } from "Core/device-select/actions/set-select-device-drawer-open.action" -import { connectDevice } from "Core/device-manager/actions/connect-device.action" + configureDevice, + setDeviceState, +} from "../actions" -export const initialState: DeviceManagerState = { +export const initialState: CoreDeviceState = { devices: [], - activeDeviceId: undefined, - selectDeviceDrawerOpen: false, } -export const deviceManagerReducer = createReducer( +export const coreDeviceReducer = createReducer( initialState, (builder) => { builder - .addCase(setDiscoveryStatus, (state, action) => { - return { - ...state, - discoveryStatus: action.payload, - } - }) .addCase(addDevice, (state, action) => { const devices = [...state.devices] devices.push({ @@ -59,12 +43,6 @@ export const deviceManagerReducer = createReducer( devices, } }) - .addCase(setActiveDevice.fulfilled, (state, action) => { - return { - ...state, - activeDeviceId: action.payload, - } - }) .addCase(configureDevice.fulfilled, (state, action) => { const devices = state.devices.reduce((prev, device) => { const payload = action.payload @@ -88,19 +66,20 @@ export const deviceManagerReducer = createReducer( devices, } }) - .addCase(connectDevice.fulfilled, (state, action) => { - if(!action.payload){ + .addCase(setDeviceState, (state, action) => { + if (!action.payload) { return { ...state } } const devices = state.devices.reduce((prev, device) => { - const id = action.meta.arg + const id = action.payload.id + const deviceState = action.payload.state if (device.id === id) { return [ ...prev, { ...device, - state: DeviceState.Connected, + state: deviceState, }, ] } else { @@ -113,18 +92,5 @@ export const deviceManagerReducer = createReducer( devices, } }) - .addCase(deactivateDevice.fulfilled, (state) => { - - return { - ...state, - activeDeviceId: undefined, - } - }) - .addCase(setSelectDeviceDrawerOpen, (state, action) => { - return { - ...state, - selectDeviceDrawerOpen: action.payload, - } - }) } ) diff --git a/libs/core-device/src/index.ts b/libs/core-device/feature/src/reducers/index.ts similarity index 79% rename from libs/core-device/src/index.ts rename to libs/core-device/feature/src/reducers/index.ts index 355c98239d..47fd2cfa48 100644 --- a/libs/core-device/src/index.ts +++ b/libs/core-device/feature/src/reducers/index.ts @@ -3,4 +3,4 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -// export * from "./lib/core-device" +export * from "./core-device.reducer" diff --git a/libs/core/device-manager/requests/get-device-configuration.request.ts b/libs/core-device/feature/src/requests/get-device-configuration.request.ts similarity index 66% rename from libs/core/device-manager/requests/get-device-configuration.request.ts rename to libs/core-device/feature/src/requests/get-device-configuration.request.ts index 33ae4b1987..7e46733c8e 100644 --- a/libs/core/device-manager/requests/get-device-configuration.request.ts +++ b/libs/core-device/feature/src/requests/get-device-configuration.request.ts @@ -5,12 +5,12 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "Core/core/builder" -import { IpcDeviceManagerEvent } from "Core/device-manager/constants" import { DeviceId } from "Core/device/constants/device-id" -import { DeviceConfiguration } from "Core/device-manager/controllers" +import { DeviceConfiguration } from "../controllers" +import { IpcCoreDeviceEvent } from "../constants" export const getDeviceConfigurationRequest = async ( id: DeviceId ): Promise> => { - return ipcRenderer.callMain(IpcDeviceManagerEvent.GetDeviceConfiguration, id) + return ipcRenderer.callMain(IpcCoreDeviceEvent.GetCoreDeviceConfiguration, id) } diff --git a/libs/core-device/feature/src/requests/index.ts b/libs/core-device/feature/src/requests/index.ts new file mode 100644 index 0000000000..b1eb40f23f --- /dev/null +++ b/libs/core-device/feature/src/requests/index.ts @@ -0,0 +1,6 @@ +/** + * 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-device-configuration.request" diff --git a/libs/core-device/feature/src/selectors/core-device-state.selector.ts b/libs/core-device/feature/src/selectors/core-device-state.selector.ts new file mode 100644 index 0000000000..1f467f5814 --- /dev/null +++ b/libs/core-device/feature/src/selectors/core-device-state.selector.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { CoreDeviceState } from "core-device/models" + +export const coreDeviceState = (state: ReduxRootState): CoreDeviceState => + state.coreDevice diff --git a/libs/core-device/feature/src/selectors/get-core-devices.selector.ts b/libs/core-device/feature/src/selectors/get-core-devices.selector.ts new file mode 100644 index 0000000000..f71402a16b --- /dev/null +++ b/libs/core-device/feature/src/selectors/get-core-devices.selector.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { Device } from "core-device/models" +import { coreDeviceState } from "./core-device-state.selector" + +export const getCoreDevicesSelector = createSelector( + coreDeviceState, + ({ devices }): Device[] => { + return devices + } +) diff --git a/libs/core-device/feature/src/selectors/index.ts b/libs/core-device/feature/src/selectors/index.ts new file mode 100644 index 0000000000..d324907b37 --- /dev/null +++ b/libs/core-device/feature/src/selectors/index.ts @@ -0,0 +1,7 @@ +/** + * 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 "./core-device-state.selector" +export * from "./get-core-devices.selector" diff --git a/libs/core/device-manager/services/device-cache-configuration.service.ts b/libs/core-device/feature/src/services/device-cache-configuration.service.ts similarity index 95% rename from libs/core/device-manager/services/device-cache-configuration.service.ts rename to libs/core-device/feature/src/services/device-cache-configuration.service.ts index 3f874ba15c..3c826ee59d 100644 --- a/libs/core/device-manager/services/device-cache-configuration.service.ts +++ b/libs/core-device/feature/src/services/device-cache-configuration.service.ts @@ -6,8 +6,8 @@ import path from "path" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import getAppPath from "Core/__deprecated__/main/utils/get-app-path" -import { DeviceConfiguration } from "Core/device-manager/controllers" import { DeviceId } from "Core/device/constants/device-id" +import { DeviceConfiguration } from "../controllers" type CacheMap = Record diff --git a/libs/core-device/feature/src/services/index.ts b/libs/core-device/feature/src/services/index.ts new file mode 100644 index 0000000000..6d80584128 --- /dev/null +++ b/libs/core-device/feature/src/services/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./device-cache-configuration.service" diff --git a/libs/device-protocol/tsconfig.json b/libs/core-device/feature/tsconfig.json similarity index 88% rename from libs/device-protocol/tsconfig.json rename to libs/core-device/feature/tsconfig.json index 3c41f10fb2..4daaf45cd3 100644 --- a/libs/device-protocol/tsconfig.json +++ b/libs/core-device/feature/tsconfig.json @@ -16,5 +16,5 @@ "path": "./tsconfig.spec.json" } ], - "extends": "../../tsconfig.base.json" + "extends": "../../../tsconfig.base.json" } diff --git a/libs/core-device/tsconfig.lib.json b/libs/core-device/feature/tsconfig.lib.json similarity index 92% rename from libs/core-device/tsconfig.lib.json rename to libs/core-device/feature/tsconfig.lib.json index cfc4843293..21799b3e6b 100644 --- a/libs/core-device/tsconfig.lib.json +++ b/libs/core-device/feature/tsconfig.lib.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "types": [ "node", diff --git a/libs/device-protocol/tsconfig.spec.json b/libs/core-device/feature/tsconfig.spec.json similarity index 90% rename from libs/device-protocol/tsconfig.spec.json rename to libs/core-device/feature/tsconfig.spec.json index 26ef046ac5..25b7af8f6d 100644 --- a/libs/device-protocol/tsconfig.spec.json +++ b/libs/core-device/feature/tsconfig.spec.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "module": "commonjs", "types": ["jest", "node"] }, diff --git a/libs/device-manager/.babelrc b/libs/core-device/models/.babelrc similarity index 100% rename from libs/device-manager/.babelrc rename to libs/core-device/models/.babelrc diff --git a/libs/device-protocol/.eslintrc.json b/libs/core-device/models/.eslintrc.json similarity index 86% rename from libs/device-protocol/.eslintrc.json rename to libs/core-device/models/.eslintrc.json index d3e61a2ea8..cacbe26215 100644 --- a/libs/device-protocol/.eslintrc.json +++ b/libs/core-device/models/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": ["../../.eslintrc.js"], + "extends": ["../../../.eslintrc.js"], "ignorePatterns": ["!**/*"], "overrides": [ { diff --git a/libs/core-device/models/README.md b/libs/core-device/models/README.md new file mode 100644 index 0000000000..7e82719bfe --- /dev/null +++ b/libs/core-device/models/README.md @@ -0,0 +1,7 @@ +# core-device-models + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test core-device-models` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-manager/jest.config.ts b/libs/core-device/models/jest.config.ts similarity index 66% rename from libs/device-manager/jest.config.ts rename to libs/core-device/models/jest.config.ts index 8f614ef088..49b89837b3 100644 --- a/libs/device-manager/jest.config.ts +++ b/libs/core-device/models/jest.config.ts @@ -1,11 +1,11 @@ /* eslint-disable */ export default { - displayName: "device-manager", - preset: "../../jest.preset.js", + displayName: "models", + preset: "../../../jest.preset.js", transform: { "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], }, moduleFileExtensions: ["ts", "tsx", "js", "jsx"], - coverageDirectory: "../../coverage/libs/device-manager", + coverageDirectory: "../../../coverage/libs/core-device/models", } diff --git a/libs/device-manager/project.json b/libs/core-device/models/project.json similarity index 59% rename from libs/device-manager/project.json rename to libs/core-device/models/project.json index 80ee4f9952..95e0a8f8b0 100644 --- a/libs/device-manager/project.json +++ b/libs/core-device/models/project.json @@ -1,7 +1,7 @@ { - "name": "device-manager", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/device-manager/src", + "name": "core-device-models", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/core-device/models/src", "projectType": "library", "tags": [], "targets": { @@ -13,7 +13,7 @@ "executor": "@nx/jest:jest", "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], "options": { - "jestConfig": "libs/device-manager/jest.config.ts" + "jestConfig": "libs/core-device/models/jest.config.ts" } } } diff --git a/libs/core/device/constants/case-colour.constant.ts b/libs/core-device/models/src/case-colour.constant.ts similarity index 100% rename from libs/core/device/constants/case-colour.constant.ts rename to libs/core-device/models/src/case-colour.constant.ts diff --git a/libs/core/device-manager/reducers/device-manager.interface.ts b/libs/core-device/models/src/core-device.interface.ts similarity index 79% rename from libs/core/device-manager/reducers/device-manager.interface.ts rename to libs/core-device/models/src/core-device.interface.ts index 5554975d65..dafa9a928d 100644 --- a/libs/core/device-manager/reducers/device-manager.interface.ts +++ b/libs/core-device/models/src/core-device.interface.ts @@ -3,7 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { CaseColour, DeviceType } from "Core/device" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" import { DeviceId } from "Core/device/constants/device-id" @@ -22,8 +23,6 @@ export interface Device extends DeviceBaseProperties { state: DeviceState } -export interface DeviceManagerState { +export interface CoreDeviceState { devices: Device[] - activeDeviceId: DeviceId | undefined - selectDeviceDrawerOpen: boolean } diff --git a/libs/core/device/constants/device-communication-error.constant.ts b/libs/core-device/models/src/device-communication-error.constant.ts similarity index 100% rename from libs/core/device/constants/device-communication-error.constant.ts rename to libs/core-device/models/src/device-communication-error.constant.ts diff --git a/libs/core/device/constants/endpoint.constant.ts b/libs/core-device/models/src/endpoint.constant.ts similarity index 100% rename from libs/core/device/constants/endpoint.constant.ts rename to libs/core-device/models/src/endpoint.constant.ts diff --git a/libs/core-device/models/src/index.ts b/libs/core-device/models/src/index.ts new file mode 100644 index 0000000000..a2bc29af27 --- /dev/null +++ b/libs/core-device/models/src/index.ts @@ -0,0 +1,10 @@ +/** + * 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 "./case-colour.constant" +export * from "./core-device.interface" +export * from "./device-communication-error.constant" +export * from "./endpoint.constant" +export * from "./request-method.constant" diff --git a/libs/core/device/constants/request-method.constant.ts b/libs/core-device/models/src/request-method.constant.ts similarity index 100% rename from libs/core/device/constants/request-method.constant.ts rename to libs/core-device/models/src/request-method.constant.ts diff --git a/libs/core-device/tsconfig.json b/libs/core-device/models/tsconfig.json similarity index 88% rename from libs/core-device/tsconfig.json rename to libs/core-device/models/tsconfig.json index 3c41f10fb2..4daaf45cd3 100644 --- a/libs/core-device/tsconfig.json +++ b/libs/core-device/models/tsconfig.json @@ -16,5 +16,5 @@ "path": "./tsconfig.spec.json" } ], - "extends": "../../tsconfig.base.json" + "extends": "../../../tsconfig.base.json" } diff --git a/libs/device-manager/tsconfig.lib.json b/libs/core-device/models/tsconfig.lib.json similarity index 92% rename from libs/device-manager/tsconfig.lib.json rename to libs/core-device/models/tsconfig.lib.json index cfc4843293..21799b3e6b 100644 --- a/libs/device-manager/tsconfig.lib.json +++ b/libs/core-device/models/tsconfig.lib.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "types": [ "node", diff --git a/libs/device-manager/tsconfig.spec.json b/libs/core-device/models/tsconfig.spec.json similarity index 90% rename from libs/device-manager/tsconfig.spec.json rename to libs/core-device/models/tsconfig.spec.json index 26ef046ac5..25b7af8f6d 100644 --- a/libs/device-manager/tsconfig.spec.json +++ b/libs/core-device/models/tsconfig.spec.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "module": "commonjs", "types": ["jest", "node"] }, diff --git a/libs/core/__deprecated__/common/interfaces/device-info.interface.ts b/libs/core/__deprecated__/common/interfaces/device-info.interface.ts index 5c9d0a1b67..c751d83be0 100644 --- a/libs/core/__deprecated__/common/interfaces/device-info.interface.ts +++ b/libs/core/__deprecated__/common/interfaces/device-info.interface.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" export default interface DeviceInfo { readonly serialNumber: string diff --git a/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.component.tsx b/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.component.tsx index 9993c90d72..42b26931aa 100644 --- a/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.component.tsx +++ b/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.component.tsx @@ -3,13 +3,13 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { FunctionComponent } from "Core/core/types/function-component.interface" import * as React from "react" +import { DeviceType } from "device-protocol/models" +import { FunctionComponent } from "Core/core/types/function-component.interface" import Icon, { Props as IconProps, } from "Core/__deprecated__/renderer/components/core/icon/icon.component" import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon-type" -import { DeviceType } from "Core/device" export interface BatteryIconProps { level: number diff --git a/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.test.tsx b/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.test.tsx index 09a613f8fc..b5964f7cb9 100644 --- a/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.test.tsx +++ b/libs/core/__deprecated__/renderer/components/core/icon/battery-icon.test.tsx @@ -4,9 +4,9 @@ */ import React from "react" +import { DeviceType } from "device-protocol/models" import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/render-with-theme-and-intl" import BatteryIcon from "Core/__deprecated__/renderer/components/core/icon/battery-icon.component" -import { DeviceType } from "Core/device" describe("battery icon returns correct component", () => { const testScenario = [ diff --git a/libs/core/__deprecated__/renderer/components/core/icon/icon.stories.tsx b/libs/core/__deprecated__/renderer/components/core/icon/icon.stories.tsx index 7f18e6f77f..19db96195b 100644 --- a/libs/core/__deprecated__/renderer/components/core/icon/icon.stories.tsx +++ b/libs/core/__deprecated__/renderer/components/core/icon/icon.stories.tsx @@ -3,18 +3,18 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { storiesOf } from "@storybook/react" import * as React from "react" +import styled from "styled-components" +import { storiesOf } from "@storybook/react" +import { DeviceType } from "device-protocol/models" import Icon, { IconSize, } from "Core/__deprecated__/renderer/components/core/icon/icon.component" -import styled from "styled-components" import StoryContainer from "Core/__deprecated__/renderer/components/storybook/story-container.component" import Story from "Core/__deprecated__/renderer/components/storybook/story.component" import BatteryIcon from "Core/__deprecated__/renderer/components/core/icon/battery-icon.component" import RangeIcon from "Core/__deprecated__/renderer/components/core/icon/range-icon.component" import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon-type" -import { DeviceType } from "Core/device" const CustomIcon = styled(Icon)` height: 3rem; diff --git a/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx b/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx index 22b402acbc..90db5ef1db 100644 --- a/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx +++ b/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx @@ -4,6 +4,14 @@ */ import React from "react" +import { useSelector, useDispatch } from "react-redux" +import { useHistory } from "react-router-dom" +import styled from "styled-components" +import { + getDevicesSelector, + setSelectDeviceDrawerOpen, + activeDeviceIdSelector, +} from "device-manager/feature" import { FunctionComponent } from "Core/core/types/function-component.interface" import { MenuGroupTestIds } from "Core/__deprecated__/renderer/components/rest/menu/menu-group-test-ids.enum" import Loader from "Core/__deprecated__/renderer/components/core/loader/loader.component" @@ -12,19 +20,13 @@ import Text, { TextDisplayStyle, } from "Core/__deprecated__/renderer/components/core/text/text.component" import { intl } from "Core/__deprecated__/renderer/utils/intl" -import styled from "styled-components" import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon-type" import ButtonComponent from "Core/__deprecated__/renderer/components/core/button/button.component" -import { useSelector, useDispatch } from "react-redux" -import { getDevicesSelector } from "Core/device-manager/selectors/get-devices.selector" -import { useHistory } from "react-router-dom" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" import { DisplayStyle } from "Core/__deprecated__/renderer/components/core/button/button.config" import { Dispatch } from "Core/__deprecated__/renderer/store" import { getDeviceInitializationStatus } from "Core/device-initialization/selectors/get-device-initialization-status.selector" import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" -import { setSelectDeviceDrawerOpen } from "Core/device-select/actions/set-select-device-drawer-open.action" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" import { useCustomerSupportIsSending } from "Core/__deprecated__/renderer/components/rest/menu/hooks/use-customer-support-is-sending" const SyncProgressWrapper = styled.div` diff --git a/libs/core/__deprecated__/renderer/components/rest/menu/menu-group.component.tsx b/libs/core/__deprecated__/renderer/components/rest/menu/menu-group.component.tsx index af08a347b4..160a14c598 100644 --- a/libs/core/__deprecated__/renderer/components/rest/menu/menu-group.component.tsx +++ b/libs/core/__deprecated__/renderer/components/rest/menu/menu-group.component.tsx @@ -4,7 +4,7 @@ */ import * as React from "react" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import Button from "Core/__deprecated__/renderer/components/core/button/button.component" import { DisplayStyle } from "Core/__deprecated__/renderer/components/core/button/button.config" import Text, { diff --git a/libs/core/__deprecated__/renderer/components/rest/menu/menu-top.component.tsx b/libs/core/__deprecated__/renderer/components/rest/menu/menu-top.component.tsx index e0a4ad9d11..b584b5b6c0 100644 --- a/libs/core/__deprecated__/renderer/components/rest/menu/menu-top.component.tsx +++ b/libs/core/__deprecated__/renderer/components/rest/menu/menu-top.component.tsx @@ -5,6 +5,7 @@ import React from "react" import styled from "styled-components" +import { DeviceType } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon-type" import { @@ -16,7 +17,6 @@ import { import MenuGroup from "Core/__deprecated__/renderer/components/rest/menu/menu-group.component" import { backgroundColor } from "Core/core/styles/theming/theme-getters" import Icon from "Core/__deprecated__/renderer/components/core/icon/icon.component" -import { DeviceType } from "Core/device" import { View } from "Core/__deprecated__/renderer/constants/views" const LogoWrapper = styled.div` diff --git a/libs/core/__deprecated__/renderer/components/rest/menu/menu.component.tsx b/libs/core/__deprecated__/renderer/components/rest/menu/menu.component.tsx index f538cb062b..96cdb99c3a 100644 --- a/libs/core/__deprecated__/renderer/components/rest/menu/menu.component.tsx +++ b/libs/core/__deprecated__/renderer/components/rest/menu/menu.component.tsx @@ -7,7 +7,9 @@ import React from "react" import styled from "styled-components" import { connect } from "react-redux" import { createSelector } from "@reduxjs/toolkit" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" +import { getActiveDeviceTypeSelector } from "device-manager/feature" +import { selectActiveDeviceMenuElements } from "generic-view/store" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { FunctionComponent } from "Core/core/types/function-component.interface" import { View } from "Core/__deprecated__/renderer/constants/views" @@ -15,10 +17,8 @@ import { getUnreadThreads } from "Core/messages/selectors" import MenuTop from "Core/__deprecated__/renderer/components/rest/menu/menu-top.component" import MenuBottom from "Core/__deprecated__/renderer/components/rest/menu/menu-bottom.component" import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-elements" -import { getActiveDeviceTypeSelector } from "Core/device-manager/selectors/get-active-device-type.selector" import { RootModel } from "Core/__deprecated__/renderer/models/models" import { deviceStateSelector } from "Core/device/selectors" -import { selectActiveDeviceMenuElements } from "generic-view/store" const MenuContainer = styled.div` flex: 1; diff --git a/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx b/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx index fc466d370f..69d51e03ae 100644 --- a/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx +++ b/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx @@ -7,7 +7,9 @@ import createMockStore from "redux-mock-store" import thunk from "redux-thunk" import React from "react" import { Provider } from "react-redux" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" +import { CoreDeviceState } from "core-device/models" +import { DeviceManagerState } from "device-manager/models" import Menu, { MenuProps, } from "Core/__deprecated__/renderer/components/rest/menu/menu.component" @@ -24,7 +26,6 @@ import { DeviceInitializationState, DeviceInitializationStatus, } from "Core/device-initialization/reducers/device-initialization.interface" -import { DeviceManagerState } from "Core/device-manager/reducers/device-manager.interface" jest.mock("Core/settings/store/schemas/generate-application-id", () => ({ generateApplicationId: () => "123", @@ -38,9 +39,10 @@ const defaultState = { device: { deviceType: DeviceType.MuditaPure, } as unknown as DeviceState, - deviceManager: { + deviceManager: {} as unknown as DeviceManagerState, + coreDevice: { devices: [], - } as unknown as DeviceManagerState, + } as unknown as CoreDeviceState, deviceInitialization: { deviceInitializationStatus: DeviceInitializationStatus.Idle, } as unknown as DeviceInitializationState, @@ -94,7 +96,6 @@ const render = ( } describe("Device: Mudita pure", () => { - test("matches snapshot", () => { const { container } = render(defaultState) expect(container).toMatchSnapshot() @@ -128,7 +129,7 @@ describe("Device: Mudita pure", () => { }, }, } as unknown as MessagesState, - deviceManager: { + coreDevice: { devices: [ { id: "1", @@ -137,6 +138,8 @@ describe("Device: Mudita pure", () => { caseColour: undefined, }, ], + } as unknown as CoreDeviceState, + deviceManager: { activeDeviceId: "1", } as unknown as DeviceManagerState, }, @@ -151,7 +154,6 @@ describe("Device: Mudita pure", () => { }) describe("Device: Mudita harmony", () => { - test("matches snapshot", () => { const { container } = render({ ...defaultState, @@ -164,7 +166,6 @@ describe("Device: Mudita harmony", () => { }) test("Menu should have overview item", () => { - const { queryByTestId } = render({ ...defaultState, device: { diff --git a/libs/core/__deprecated__/renderer/constants/menu-elements.ts b/libs/core/__deprecated__/renderer/constants/menu-elements.ts index b6aa5ddd06..4ccd85f556 100644 --- a/libs/core/__deprecated__/renderer/constants/menu-elements.ts +++ b/libs/core/__deprecated__/renderer/constants/menu-elements.ts @@ -4,7 +4,7 @@ */ import { defineMessages } from "react-intl" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { View, views } from "Core/__deprecated__/renderer/constants/views" import { MenuGroupTestIds } from "Core/__deprecated__/renderer/components/rest/menu/menu-group-test-ids.enum" import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon-type" diff --git a/libs/core/__deprecated__/renderer/models/basic-info/basic-info.typings.ts b/libs/core/__deprecated__/renderer/models/basic-info/basic-info.typings.ts index f6a216fb3f..6fce3c03e5 100644 --- a/libs/core/__deprecated__/renderer/models/basic-info/basic-info.typings.ts +++ b/libs/core/__deprecated__/renderer/models/basic-info/basic-info.typings.ts @@ -4,7 +4,8 @@ */ import { State } from "Core/core/constants" -import { DeviceType, CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" export interface SimCard { readonly network?: string diff --git a/libs/core/__deprecated__/renderer/store/reducers.ts b/libs/core/__deprecated__/renderer/store/reducers.ts index a70ac4bd76..6c95435819 100644 --- a/libs/core/__deprecated__/renderer/store/reducers.ts +++ b/libs/core/__deprecated__/renderer/store/reducers.ts @@ -21,7 +21,8 @@ import { updateOsReducer } from "Core/update/reducers" import { discoveryDeviceReducer } from "Core/discovery-device/reducers/discovery-device.reducer" import { deviceInitializationReducer } from "Core/device-initialization/reducers/device-initialization.reducer" import { appInitializationReducer } from "Core/app-initialization/reducers/app-initialization.reducer" -import { deviceManagerReducer } from "Core/device-manager/reducers/device-manager.reducer" +import { coreDeviceReducer } from "core-device/feature" +import { deviceManagerReducer } from "device-manager/feature" import { dataMigrationReducer, genericBackupsReducer, @@ -52,6 +53,7 @@ export const reducers = { discoveryDevice: discoveryDeviceReducer, deviceInitialization: deviceInitializationReducer, appInitialization: appInitializationReducer, + coreDevice: coreDeviceReducer, deviceManager: deviceManagerReducer, genericViews: genericViewsReducer, genericModals: genericModalsReducer, diff --git a/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.test.ts b/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.test.ts index 943a22aaa5..0422c79931 100644 --- a/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.test.ts +++ b/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.test.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { FreshdeskTicketProduct } from "./create-freshdesk-ticket.types" import { mapDeviceTypeToProduct } from "./map-device-type-to-product.helper" diff --git a/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.ts b/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.ts index 738ccccbb1..342c3f4b18 100644 --- a/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.ts +++ b/libs/core/__deprecated__/renderer/utils/create-freshdesk-ticket/map-device-type-to-product.helper.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants/device-type.constant" +import { DeviceType } from "device-protocol/models" import { FreshdeskTicketProduct } from "./create-freshdesk-ticket.types" const DEVICE_TYPE_TO_PRODUCT: Record = { diff --git a/libs/core/__deprecated__/renderer/utils/hooks/use-dynamic-progress-value.hook.test.tsx b/libs/core/__deprecated__/renderer/utils/hooks/use-dynamic-progress-value.hook.test.tsx deleted file mode 100644 index fa5a26c65b..0000000000 --- a/libs/core/__deprecated__/renderer/utils/hooks/use-dynamic-progress-value.hook.test.tsx +++ /dev/null @@ -1,89 +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 { renderHook, waitFor } from "@testing-library/react" -import useDynamicProgressValue from "Core/__deprecated__/renderer/utils/hooks/use-dynamic-progress-value.hook" - -test("return the incremented progress value in the next render", async () => { - const { result } = renderHook((props = 0) => - useDynamicProgressValue(props) - ) - await waitFor(() => { - expect(result.current).toBe(1) - }) - - await waitFor(() => { - expect(result.current).toBe(2) - }) -}) - -test("new props don't have an impact on the smooth incrementing value", async () => { - const { result, rerender } = renderHook((props = 0) => - useDynamicProgressValue(props) - ) - await waitFor(() => { - expect(result.current).toBe(1) - }) - - rerender(15) - - expect(result.current).not.toBe(15) - await waitFor(() => { - expect(result.current).toBe(2) - }) -}) - -test("passing the 100 number value return immediately 100 as complete progress state", async () => { - const { result, rerender } = renderHook((props = 0) => - useDynamicProgressValue(props) - ) - await waitFor(() => { - expect(result.current).toBe(1) - }) - - rerender(100) - - await waitFor(() => { - expect(result.current).not.toBe(2) - expect(result.current).toBe(100) - }) -}) - -test("incremental progress value does not back down", async () => { - const { result, rerender } = renderHook((props = 0) => - useDynamicProgressValue(props) - ) - await waitFor(() => { - expect(result.current).toBe(1) - }) - - await waitFor(() => { - expect(result.current).toBe(2) - }) - - rerender(1) - - await waitFor(() => { - expect(result.current).toBe(3) - }) -}) - -test("incremental progress value does not increase beyond the limit", async () => { - const { result } = renderHook(() => - useDynamicProgressValue(0, { limitValue: 3 }) - ) - await waitFor(() => { - expect(result.current).toBe(1) - }) - - try { - new Error("unexpected re rendering has occurred") - } catch { - await waitFor(() => { - expect(result.current).not.toBe(4) - expect(result.current).toBe(3) - }) - } -}) diff --git a/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts b/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts index 5a5da68fa9..81dff9d47c 100644 --- a/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts +++ b/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts @@ -5,6 +5,7 @@ import { EventEmitter } from "events" import { MainProcessIpc } from "electron-better-ipc" +import { DeviceProtocolService } from "device-protocol/feature" import { BaseModule } from "Core/core/module" import { IndexStorage } from "Core/index-storage/types" import { MetadataStore } from "Core/metadata" @@ -12,7 +13,6 @@ import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { AnalyticDataTrackerController } from "Core/analytic-data-tracker/controllers" import { AnalyticDataTrackerFactory } from "Core/analytic-data-tracker/services" -import { DeviceManager } from "Core/device-manager/services" const apiUrl = String(process.env.ANALYTICS_API_URL) const siteId = Number(process.env.ANALYTICS_API_SITE_ID) @@ -20,7 +20,7 @@ const siteId = Number(process.env.ANALYTICS_API_SITE_ID) export class AnalyticDataTrackerModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/analytic-data-tracker/helpers/track-os-update.test.ts b/libs/core/analytic-data-tracker/helpers/track-os-update.test.ts index 8e58f5310d..25e54c176a 100644 --- a/libs/core/analytic-data-tracker/helpers/track-os-update.test.ts +++ b/libs/core/analytic-data-tracker/helpers/track-os-update.test.ts @@ -8,7 +8,7 @@ import { TrackOsUpdateState, TrackOsUpdateOptions, } from "Core/analytic-data-tracker/helpers/track-os-update" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { trackRequest } from "Core/analytic-data-tracker/requests" import { TrackEventCategory } from "Core/analytic-data-tracker/constants" diff --git a/libs/core/analytic-data-tracker/helpers/track-os-update.ts b/libs/core/analytic-data-tracker/helpers/track-os-update.ts index 96067802f8..01170e9101 100644 --- a/libs/core/analytic-data-tracker/helpers/track-os-update.ts +++ b/libs/core/analytic-data-tracker/helpers/track-os-update.ts @@ -8,7 +8,7 @@ import { trackWithoutDeviceCheckRequest, } from "Core/analytic-data-tracker/requests" import { HarmonyDeviceData, PureDeviceData } from "Core/device" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { TrackEvent } from "Core/analytic-data-tracker/types" import { TrackEventCategory } from "Core/analytic-data-tracker/constants" diff --git a/libs/core/analytic-data-tracker/helpers/track-os-version.test.ts b/libs/core/analytic-data-tracker/helpers/track-os-version.test.ts index 94abd50690..b04165124d 100644 --- a/libs/core/analytic-data-tracker/helpers/track-os-version.test.ts +++ b/libs/core/analytic-data-tracker/helpers/track-os-version.test.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { trackOsVersion, TrackOsVersionOptions, diff --git a/libs/core/analytic-data-tracker/helpers/track-os-version.ts b/libs/core/analytic-data-tracker/helpers/track-os-version.ts index 8e7c87c9ab..cba63b2043 100644 --- a/libs/core/analytic-data-tracker/helpers/track-os-version.ts +++ b/libs/core/analytic-data-tracker/helpers/track-os-version.ts @@ -3,9 +3,9 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { DeviceType } from "device-protocol/models" import { trackUniqueRequest } from "Core/analytic-data-tracker/requests" import { HarmonyDeviceData, PureDeviceData } from "Core/device" -import { DeviceType } from "Core/device/constants" import { TrackEvent } from "Core/analytic-data-tracker/types" import { TrackEventCategory } from "Core/analytic-data-tracker/constants" diff --git a/libs/core/backup/actions/base.action.ts b/libs/core/backup/actions/base.action.ts index 261b2467fa..12f7472c17 100644 --- a/libs/core/backup/actions/base.action.ts +++ b/libs/core/backup/actions/base.action.ts @@ -7,9 +7,6 @@ import { createAction } from "@reduxjs/toolkit" import { BackupEvent } from "Core/backup/constants" import { Backup } from "Core/backup/dto" -export const setInitialBackupState = createAction( - BackupEvent.SetInitialBackupState -) export const setBackupData = createAction(BackupEvent.SetBackupData) export const readBackupDeviceDataState = createAction( diff --git a/libs/core/backup/backup.module.ts b/libs/core/backup/backup.module.ts index 2e28acd547..0a5c8f7812 100644 --- a/libs/core/backup/backup.module.ts +++ b/libs/core/backup/backup.module.ts @@ -17,7 +17,7 @@ import { LoadBackupService, } from "Core/backup/services" import { BackupController } from "Core/backup/controllers" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { FileManagerService } from "Core/files-manager/services" import { FileDeleteCommand } from "Core/device-file-system/commands/file-delete.command" import { @@ -29,7 +29,7 @@ import { DeviceInfoService } from "Core/device-info/services" export class BackupModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/backup/constants/event.enum.ts b/libs/core/backup/constants/event.enum.ts index 5815786ece..f599f3a0ec 100644 --- a/libs/core/backup/constants/event.enum.ts +++ b/libs/core/backup/constants/event.enum.ts @@ -4,7 +4,6 @@ */ export enum BackupEvent { - SetInitialBackupState = "SET_INITIAL_BACKUP_STATE", Load = "LOAD_BACKUP_DATA", SetBackupData = "SET_BACKUP_DATA", CreateBackup = "CREATE_BACKUP", diff --git a/libs/core/backup/reducers/backup.reducer.ts b/libs/core/backup/reducers/backup.reducer.ts index c6462c559f..3b62da9289 100644 --- a/libs/core/backup/reducers/backup.reducer.ts +++ b/libs/core/backup/reducers/backup.reducer.ts @@ -4,6 +4,7 @@ */ import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" import { AppError } from "Core/core/errors" import { State } from "Core/core/constants" import { BackupState } from "Core/backup/reducers/backup.interface" @@ -14,9 +15,9 @@ import { startBackupDevice, startRestoreDevice, readRestoreDeviceDataState, - setInitialBackupState, } from "Core/backup/actions" import { BackupError } from "Core/backup/constants" +import { pendingAction } from "Core/__deprecated__/renderer/store/helpers" export const initialState: BackupState = { data: { @@ -77,7 +78,7 @@ export const backupReducer = createReducer( state.restoringState = State.Initial state.error = null }) - .addCase(setInitialBackupState, () => { + .addCase(pendingAction(DeviceManagerEvent.DeactivateDevice), () => { return { ...initialState } }) } diff --git a/libs/core/backup/services/backup-create.service.test.ts b/libs/core/backup/services/backup-create.service.test.ts index b46ae7dc01..63e3c3be9a 100644 --- a/libs/core/backup/services/backup-create.service.test.ts +++ b/libs/core/backup/services/backup-create.service.test.ts @@ -3,20 +3,16 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { DeviceProtocolService } from "device-protocol/feature" +import { Endpoint, Method } from "core-device/models" +import { BackupCategory, PhoneLockCategory } from "Core/device" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { BackupCreateService } from "Core/backup/services/backup-create.service" import { MetadataStore, MetadataKey } from "Core/metadata" import { BackupError, Operation } from "Core/backup/constants" import { UpdaterStatus } from "Core/backup/dto" -import { DeviceManager } from "Core/device-manager/services" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { - BackupCategory, - Endpoint, - Method, - PhoneLockCategory, -} from "Core/device" import { FileManagerService } from "Core/files-manager/services" import { DeviceInfoService } from "Core/device-info/services" @@ -33,7 +29,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const deviceFileSystemAdapter = { downloadDeviceFilesLocally: jest.fn(), diff --git a/libs/core/backup/services/backup-create.service.ts b/libs/core/backup/services/backup-create.service.ts index 785ed35cf0..35431ece2d 100644 --- a/libs/core/backup/services/backup-create.service.ts +++ b/libs/core/backup/services/backup-create.service.ts @@ -3,14 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Endpoint, Method, BackupCategory } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" +import { DeviceProtocolService } from "device-protocol/feature" +import { BackupCategory } from "Core/device/constants" import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import { BackupError, Operation } from "Core/backup/constants" import { MetadataStore, MetadataKey } from "Core/metadata" import { CreateDeviceBackup } from "Core/backup/types" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { DeviceManager } from "Core/device-manager/services" import { BaseBackupService } from "Core/backup/services/base-backup.service" import { FileManagerService } from "Core/files-manager/services" import { DeviceDirectory } from "Core/files-manager/constants" @@ -18,7 +19,7 @@ import { DeviceInfoService } from "Core/device-info/services" export class BackupCreateService extends BaseBackupService { constructor( - protected deviceManager: DeviceManager, + protected deviceManager: DeviceProtocolService, protected deviceFileSystem: DeviceFileSystemService, protected fileManagerService: FileManagerService, protected deviceInfoService: DeviceInfoService, diff --git a/libs/core/backup/services/backup-restore.service.test.ts b/libs/core/backup/services/backup-restore.service.test.ts index 25a8fb6bc9..091313fe8b 100644 --- a/libs/core/backup/services/backup-restore.service.test.ts +++ b/libs/core/backup/services/backup-restore.service.test.ts @@ -5,6 +5,8 @@ import fs from "fs" import path from "path" +import { Endpoint, Method } from "core-device/models" +import { DeviceProtocolService } from "device-protocol/feature" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { BackupRestoreService } from "Core/backup/services/backup-restore.service" @@ -12,9 +14,8 @@ import CryptoFileService from "Core/file-system/services/crypto-file-service/cry import { BackupError, Operation } from "Core/backup/constants" import { UpdaterStatus } from "Core/backup/dto" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" -import { DeviceManager } from "Core/device-manager/services" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { Endpoint, Method, PhoneLockCategory } from "Core/device" +import { PhoneLockCategory } from "Core/device" import { DeviceInfoService } from "Core/device-info/services" const arrayBufferToBuffer = (unitArray: Uint8Array): Buffer => { @@ -64,7 +65,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const deviceFileSystemAdapter = { uploadFile: jest.fn(), diff --git a/libs/core/backup/services/backup-restore.service.ts b/libs/core/backup/services/backup-restore.service.ts index 439b91b421..daffa5a752 100644 --- a/libs/core/backup/services/backup-restore.service.ts +++ b/libs/core/backup/services/backup-restore.service.ts @@ -3,21 +3,21 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Endpoint, Method } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import CryptoFileService from "Core/file-system/services/crypto-file-service/crypto-file-service" import { RestoreDeviceBackup } from "Core/backup/types" import { BackupError, Operation } from "Core/backup/constants" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { BaseBackupService } from "Core/backup/services/base-backup.service" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { DeviceInfoService } from "Core/device-info/services" export class BackupRestoreService extends BaseBackupService { constructor( - protected deviceManager: DeviceManager, + protected deviceManager: DeviceProtocolService, protected deviceFileSystem: DeviceFileSystemService, protected deviceInfoService: DeviceInfoService, private fileSystem: FileSystemService diff --git a/libs/core/backup/services/base-backup.service.ts b/libs/core/backup/services/base-backup.service.ts index 06793648cb..c000cd6ac0 100644 --- a/libs/core/backup/services/base-backup.service.ts +++ b/libs/core/backup/services/base-backup.service.ts @@ -3,12 +3,13 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Endpoint, Method, PhoneLockCategory } from "Core/device" +import { Endpoint, Method } from "core-device/models" +import { PhoneLockCategory } from "Core/device" import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import { Operation, BackupError } from "Core/backup/constants" import { UpdaterStatus } from "Core/backup/dto" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceFileSystemService } from "Core/device-file-system/services" import { DeviceInfoService } from "Core/device-info/services" @@ -17,7 +18,7 @@ export class BaseBackupService { private REQUEST_TIME_OUT = 5000 constructor( - protected deviceManager: DeviceManager, + protected deviceManager: DeviceProtocolService, protected deviceFileSystem: DeviceFileSystemService, protected deviceInfoService: DeviceInfoService ) {} @@ -95,7 +96,6 @@ export class BaseBackupService { } private async waitUntilDeviceResponse(index = 0): Promise { - if (index === this.MAX_WAKE_UP_RETRIES) { return false } diff --git a/libs/core/backup/services/sync-backup-create.service.ts b/libs/core/backup/services/sync-backup-create.service.ts index e89fee569d..5b87f1ebe5 100644 --- a/libs/core/backup/services/sync-backup-create.service.ts +++ b/libs/core/backup/services/sync-backup-create.service.ts @@ -8,9 +8,10 @@ import { AppError } from "Core/core/errors" import { BackupError } from "Core/backup/constants" import { MetadataStore, MetadataKey } from "Core/metadata" import { TokenOptions } from "Core/file-system/services/crypto-file-service/crypto-file-service" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { BackupCategory, BackupState, Endpoint, Method } from "Core/device" +import { Endpoint, Method } from "core-device/models" +import { BackupCategory, BackupState } from "Core/device" import { DeviceInfo, GetBackupDeviceStatusRequestConfigBody, @@ -26,7 +27,7 @@ export interface createSyncBackupOptions export class SyncBackupCreateService { constructor( - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public deviceFileSystem: DeviceFileSystemService, private keyStorage: MetadataStore ) {} diff --git a/libs/core/contact-support/actions/send-ticket.action.test.ts b/libs/core/contact-support/actions/send-ticket.action.test.ts index a6e1279957..1170bc16f6 100644 --- a/libs/core/contact-support/actions/send-ticket.action.test.ts +++ b/libs/core/contact-support/actions/send-ticket.action.test.ts @@ -14,7 +14,8 @@ import sendTicketRequest, { CreateBugTicketResponseStatus, } from "Core/contact-support/requests/send-ticket.request" import { AppError } from "Core/core/errors" -import { DeviceState, DeviceType } from "Core/device" +import { DeviceState } from "Core/device" +import { DeviceType } from "device-protocol/models" import { ReduxRootState, RootState } from "Core/__deprecated__/renderer/store" import { testError } from "Core/__deprecated__/renderer/store/constants" import { FreshdeskTicketProduct } from "Core/__deprecated__/renderer/utils/create-freshdesk-ticket/create-freshdesk-ticket.types" diff --git a/libs/core/contacts/actions/base.action.ts b/libs/core/contacts/actions/base.action.ts index 6224b7cfeb..96c3851b50 100644 --- a/libs/core/contacts/actions/base.action.ts +++ b/libs/core/contacts/actions/base.action.ts @@ -7,10 +7,6 @@ import { createAction } from "@reduxjs/toolkit" import { ContactsEvent } from "Core/contacts/constants" import { Contact, ContactID } from "Core/contacts/reducers" -export const setInitialContactsState = createAction( - ContactsEvent.SetInitialContactsState -) - export const setContacts = createAction(ContactsEvent.SetContacts) export const addNewContactsToState = createAction( diff --git a/libs/core/contacts/actions/delete-contacts.action.ts b/libs/core/contacts/actions/delete-contacts.action.ts index ef5261a54d..03ceb634b8 100644 --- a/libs/core/contacts/actions/delete-contacts.action.ts +++ b/libs/core/contacts/actions/delete-contacts.action.ts @@ -4,12 +4,12 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { isActiveDeviceSet } from "device-manager/feature" import { deleteContactsInState } from "Core/contacts/actions/base.action" import { ContactsEvent } from "Core/contacts/constants" import { ContactID } from "Core/contacts/reducers" import { deleteContactsRequest } from "Core/contacts/requests" import { AppError } from "Core/core/errors" -import { isActiveDeviceSet } from "Core/device-manager/selectors/is-active-device-set.selector" import { ReduxRootState } from "Core/__deprecated__/renderer/store" export const deleteContacts = createAsyncThunk< diff --git a/libs/core/contacts/actions/import-contact.action.ts b/libs/core/contacts/actions/import-contact.action.ts index 710a6b29d0..8e4f6eb222 100644 --- a/libs/core/contacts/actions/import-contact.action.ts +++ b/libs/core/contacts/actions/import-contact.action.ts @@ -12,7 +12,7 @@ import { } from "Core/contacts/requests" import { AppError } from "Core/core/errors" import { RequestResponseStatus } from "Core/core/types/request-response.interface" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" +import { activeDeviceIdSelector } from "device-manager/feature" import { ReduxRootState } from "Core/__deprecated__/renderer/store" export interface ImportContactArg { diff --git a/libs/core/contacts/components/contacts/contacts.component.tsx b/libs/core/contacts/components/contacts/contacts.component.tsx index d0a5e4de42..ca89335c54 100644 --- a/libs/core/contacts/components/contacts/contacts.component.tsx +++ b/libs/core/contacts/components/contacts/contacts.component.tsx @@ -57,7 +57,7 @@ import { filterContacts } from "Core/contacts/helpers/filter-contacts/filter-con import { AppError } from "Core/core/errors" import { RequestResponseStatus } from "Core/core/types" import createFile from "Core/__deprecated__/renderer/utils/create-file/create-file" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" +import { activeDeviceIdSelector } from "device-manager/feature" const allPossibleFormErrorCausedByAPI: FormError[] = [ { diff --git a/libs/core/contacts/constants/event.enum.ts b/libs/core/contacts/constants/event.enum.ts index 0271898ebf..ac31c35332 100644 --- a/libs/core/contacts/constants/event.enum.ts +++ b/libs/core/contacts/constants/event.enum.ts @@ -4,7 +4,6 @@ */ export enum ContactsEvent { - SetInitialContactsState = "SET_INITIAL_CONTACTS_STATE", DevClearAllContacts = "CONTACTS_DEV_CLEAR_ALL_CONTACTS", SetContacts = "CONTACTS_SET_CONTACTS", Authorize = "CONTACTS_AUTHORIZE", diff --git a/libs/core/contacts/contact.module.ts b/libs/core/contacts/contact.module.ts index af433b8f56..60accc3b2e 100644 --- a/libs/core/contacts/contact.module.ts +++ b/libs/core/contacts/contact.module.ts @@ -14,12 +14,12 @@ import { ContactModel } from "Core/contacts/models" import { ContactController } from "Core/contacts/controllers" import { ContactService } from "Core/contacts/services" import { ContactRepository } from "Core/contacts/repositories" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class ContactModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/contacts/reducers/contacts.reducer.ts b/libs/core/contacts/reducers/contacts.reducer.ts index 1d6789f3c8..e0c909a331 100644 --- a/libs/core/contacts/reducers/contacts.reducer.ts +++ b/libs/core/contacts/reducers/contacts.reducer.ts @@ -6,8 +6,10 @@ // TODO: CP-1494, CP-1495 import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" import { fulfilledAction, + pendingAction, rejectedAction, } from "Core/__deprecated__/renderer/store/helpers" import { @@ -35,7 +37,6 @@ import { resetAllItems, toggleItem, deleteContacts, - setInitialContactsState, } from "Core/contacts/actions" import { changeLocation } from "Core/core/actions" @@ -55,7 +56,7 @@ export const contactsReducer = createReducer( initialState, (builder) => { builder - .addCase(setInitialContactsState, (state) => { + .addCase(pendingAction(DeviceManagerEvent.DeactivateDevice), () => { return { ...initialState } }) .addCase( diff --git a/libs/core/contacts/services/contact.service.test.ts b/libs/core/contacts/services/contact.service.test.ts index d4b3c971e1..abfa7f5588 100644 --- a/libs/core/contacts/services/contact.service.test.ts +++ b/libs/core/contacts/services/contact.service.test.ts @@ -5,10 +5,10 @@ import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" -import { DeviceCommunicationError } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" import { ContactService } from "Core/contacts/services/contact.service" import { ContactRepository } from "Core/contacts/repositories" -import { DeviceManager } from "Core/device-manager/services/device-manager.service" +import { DeviceProtocolService } from "device-protocol/feature" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { Contact as PureContact } from "Core/device/types/mudita-os" import { Contact } from "Core/contacts/reducers" @@ -23,7 +23,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const subject = new ContactService(contactRepository, deviceManager) diff --git a/libs/core/contacts/services/contact.service.ts b/libs/core/contacts/services/contact.service.ts index b572bb191f..015c9a6eec 100644 --- a/libs/core/contacts/services/contact.service.ts +++ b/libs/core/contacts/services/contact.service.ts @@ -3,18 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { - DeviceCommunicationError, - Endpoint, - Method, -} from "Core/device/constants" +import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { GetContactResponseBody, GetContactsResponseBody, CreateContactResponseBody, CreateContactErrorResponseBody, } from "Core/device/types/mudita-os" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { Contact, ContactID } from "Core/contacts/reducers" import { ContactRepository } from "Core/contacts/repositories" import { ContactPresenter } from "Core/contacts/presenters" @@ -27,7 +23,7 @@ import { ResultObject } from "Core/core/builder" export class ContactService { constructor( private contactRepository: ContactRepository, - private deviceManager: DeviceManager + private deviceManager: DeviceProtocolService ) {} public async getContact(id: string): Promise> { diff --git a/libs/core/core/application.module.ts b/libs/core/core/application.module.ts index 337e674ca6..22c6e7cd98 100644 --- a/libs/core/core/application.module.ts +++ b/libs/core/core/application.module.ts @@ -39,17 +39,20 @@ import { DeviceInfoModule } from "Core/device-info/device-info.module" import { DeviceFileSystemModule } from "Core/device-file-system/device-file-system.module" import { DeviceLogModule } from "Core/device-log/device-log.module" import { DeviceModule } from "Core/device/device.module" -import { DeviceManagerModule } from "Core/device-manager/device-manager.module" import { - DeviceManager, + DeviceProtocolModule, + DeviceProtocolService, DeviceResolverService, -} from "Core/device-manager/services" +} from "device-protocol/feature" import { APIModule } from "device/feature" import { DesktopModule } from "Core/desktop/desktop.module" import { FileSystemDialogModule, OnlineStatusModule } from "shared/app-state" import { SystemUtilsModule } from "system-utils/feature" import { MockDeviceResolverService, mockServiceEnabled } from "e2e-mock-server" import { ApplicationUpdaterModule } from "electron/application-updater" +import { CoreDeviceModule } from "core-device/feature" +import { DeviceManagerModule } from "device-manager/feature" +import { createSettingsService } from "Core/settings/containers" export class ApplicationModule { public modules: Module[] = [ @@ -71,7 +74,7 @@ export class ApplicationModule { ] public lateModules: Module[] = [ - DeviceManagerModule, + DeviceProtocolModule, DataSyncModule, CrashDumpModule, DesktopModule, @@ -91,7 +94,7 @@ export class ApplicationModule { private apiModule: APIModule - private deviceManager = new DeviceManager( + private deviceManager = new DeviceProtocolService( mockServiceEnabled ? new MockDeviceResolverService() : new DeviceResolverService(), @@ -114,7 +117,11 @@ export class ApplicationModule { this.initializeInitializer = new InitializeInitializer() this.modules.forEach(this.initModule) - this.apiModule = new APIModule(this.deviceManager, this.systemUtilsModule) + this.apiModule = new APIModule( + this.deviceManager, + this.systemUtilsModule, + createSettingsService() + ) this.controllerInitializer.initialize(this.apiModule.getAPIServices()) this.controllerInitializer.initialize( FileSystemDialogModule.getControllers() @@ -124,6 +131,12 @@ export class ApplicationModule { new ApplicationUpdaterModule().controllers ) this.controllerInitializer.initialize(new OnlineStatusModule().controllers) + this.controllerInitializer.initialize( + new CoreDeviceModule(this.deviceManager, this.fileSystem).controllers + ) + this.controllerInitializer.initialize( + new DeviceManagerModule(this.deviceManager).controllers + ) } lateInitialization(): void { diff --git a/libs/core/core/hooks/use-device-connect-failed-effect.ts b/libs/core/core/hooks/use-device-connect-failed-effect.ts index 0ead8929d2..29baa53111 100644 --- a/libs/core/core/hooks/use-device-connect-failed-effect.ts +++ b/libs/core/core/hooks/use-device-connect-failed-effect.ts @@ -6,18 +6,18 @@ import { useEffect, useCallback } from "react" import { useHistory } from "react-router-dom" import { useDispatch, useSelector } from "react-redux" -import { answerMain, DeviceManagerMainEvent } from "shared/utils" +import { answerMain } from "shared/utils" +import { DeviceProtocolMainEvent } from "device-protocol/models" import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" -import { addDevice } from "Core/device-manager/actions/base.action" +import { activeDeviceIdSelector } from "device-manager/feature" +import { DeviceState } from "core-device/models" +import { addDevice, getDeviceConfigurationRequest } from "core-device/feature" import { Dispatch } from "Core/__deprecated__/renderer/store" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { isDiscoveryDeviceInProgress } from "Core/discovery-device/selectors/is-discovery-device-in-progress.selector" import { isInitializationDeviceInProgress } from "Core/device-initialization/selectors/is-initialization-device-in-progress.selector" import { isInitializationAppInProgress } from "Core/app-initialization/selectors/is-initialization-app-in-progress.selector" -import { DeviceState } from "Core/device-manager/reducers/device-manager.interface" -import { getDeviceConfigurationRequest } from "Core/device-manager/requests/get-device-configuration.request" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" export const useDeviceConnectFailedEffect = () => { const history = useHistory() @@ -68,7 +68,7 @@ export const useDeviceConnectFailedEffect = () => { useEffect(() => { return answerMain( - DeviceManagerMainEvent.DeviceConnectFailed, + DeviceProtocolMainEvent.DeviceConnectFailed, handleDeviceConnectFailed ) }, [handleDeviceConnectFailed]) diff --git a/libs/core/core/hooks/use-device-connected-effect.ts b/libs/core/core/hooks/use-device-connected-effect.ts index 72d19d4bde..c1515351d8 100644 --- a/libs/core/core/hooks/use-device-connected-effect.ts +++ b/libs/core/core/hooks/use-device-connected-effect.ts @@ -6,13 +6,22 @@ import { useCallback, useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" -import { answerMain, DeviceManagerMainEvent } from "shared/utils" +import { answerMain } from "shared/utils" +import { + activeDeviceIdSelector, + setActiveDevice, + getDevicesSelector, +} from "device-manager/feature" +import { + addDevice, + configureDevice, + getDeviceConfigurationRequest, +} from "core-device/feature" +import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" +import { selectDialogOpenState } from "shared/app-state" import { Dispatch } from "Core/__deprecated__/renderer/store" import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" -import { addDevice } from "Core/device-manager/actions/base.action" -import { setActiveDevice } from "Core/device-manager/actions/set-active-device.action" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" import { @@ -22,15 +31,10 @@ import { } from "Core/__deprecated__/renderer/constants/urls" import { isInitializationDeviceInProgress } from "Core/device-initialization/selectors/is-initialization-device-in-progress.selector" import { isInitializationAppInProgress } from "Core/app-initialization/selectors/is-initialization-app-in-progress.selector" -import { configureDevice } from "Core/device-manager/actions/configure-device.action" -import { DeviceType } from "Core/device" import { getTmpMuditaHarmonyPortInfoSelector } from "Core/update/selectors/get-tmp-mudita-harmony-port-info-selector" import { isUnknownSerialNumber } from "Core/device/constants/unknown-serial-number.constant" -import { getDeviceConfigurationRequest } from "Core/device-manager/requests/get-device-configuration.request" import { getDiscoveryStatus } from "Core/discovery-device/selectors/get-discovery-status.selector" -import { getDevicesSelector } from "Core/device-manager/selectors/get-devices.selector" import { checkIsAnyModalPresent } from "Core/utils/check-is-any-other-modal-present" -import { selectDialogOpenState } from "shared/app-state" export const useDeviceConnectedEffect = () => { const history = useHistory() @@ -57,7 +61,7 @@ export const useDeviceConnectedEffect = () => { } return answerMain( - DeviceManagerMainEvent.DeviceConnected, + DeviceProtocolMainEvent.DeviceConnected, handler ) }, [ diff --git a/libs/core/core/hooks/use-device-detached-effect.ts b/libs/core/core/hooks/use-device-detached-effect.ts index 690c4b318c..07e9d67c29 100644 --- a/libs/core/core/hooks/use-device-detached-effect.ts +++ b/libs/core/core/hooks/use-device-detached-effect.ts @@ -6,23 +6,26 @@ import { useCallback, useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" -import { answerMain, DeviceManagerMainEvent } from "shared/utils" -import { Dispatch, ReduxRootState } from "Core/__deprecated__/renderer/store" +import { answerMain } from "shared/utils" import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" +import { removeDevice } from "core-device/feature" +import { getDevicesSelector } from "device-manager/feature" +import { selectDialogOpenState } from "shared/app-state" +import { DeviceProtocolMainEvent } from "device-protocol/models" +import { Dispatch, ReduxRootState } from "Core/__deprecated__/renderer/store" +import { + activeDeviceIdSelector, + deactivateDevice, +} from "device-manager/feature" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import modalService from "Core/__deprecated__/renderer/components/core/modal/modal.service" -import { removeDevice } from "Core/device-manager/actions/base.action" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" import { cancelOsDownload } from "Core/update/requests" import { URL_DISCOVERY_DEVICE, URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" import { useDeactivateDeviceAndRedirect } from "Core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook" -import { getDevicesSelector } from "Core/device-manager/selectors/get-devices.selector" import { useDebouncedEventsHandler } from "Core/core/hooks/use-debounced-events-handler" -import { selectDialogOpenState } from "shared/app-state" import { closeContactSupportFlow } from "Core/contact-support" export const useDeviceDetachedEffect = () => { @@ -33,7 +36,7 @@ export const useDeviceDetachedEffect = () => { useEffect(() => { return answerMain( - DeviceManagerMainEvent.DeviceDetached, + DeviceProtocolMainEvent.DeviceDetached, batchDeviceDetachedEvents ) }, [batchDeviceDetachedEvents]) diff --git a/libs/core/core/hooks/use-device-locked-effect.ts b/libs/core/core/hooks/use-device-locked-effect.ts index 27032c949a..01758bc4c0 100644 --- a/libs/core/core/hooks/use-device-locked-effect.ts +++ b/libs/core/core/hooks/use-device-locked-effect.ts @@ -12,8 +12,8 @@ import { getDeviceInitializationStatus } from "Core/device-initialization/select import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" import { deviceUnlockedStatusSelector } from "Core/device/selectors/device-unlocked-status.selector" import { URL_DEVICE_INITIALIZATION } from "Core/__deprecated__/renderer/constants/urls" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { getActiveDevice } from "device-manager/feature" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { PureStrategyMainEvent } from "Core/device/strategies" export const useDeviceLockedEffect = () => { diff --git a/libs/core/core/hooks/use-discovery-redirect-effect.ts b/libs/core/core/hooks/use-discovery-redirect-effect.ts index 5710c2a401..9a91378489 100644 --- a/libs/core/core/hooks/use-discovery-redirect-effect.ts +++ b/libs/core/core/hooks/use-discovery-redirect-effect.ts @@ -6,8 +6,7 @@ import { useEffect, useRef } from "react" import { useSelector } from "react-redux" import { useHistory } from "react-router-dom" -import { isDeviceListEmpty } from "Core/device-manager/selectors/is-device-list-empty.selector" -import { isActiveDeviceSet } from "Core/device-manager/selectors/is-active-device-set.selector" +import { isDeviceListEmpty, isActiveDeviceSet } from "device-manager/feature" import { isDiscoveryDeviceInProgress } from "Core/discovery-device/selectors/is-discovery-device-in-progress.selector" import { isInitializationDeviceInProgress } from "Core/device-initialization/selectors/is-initialization-device-in-progress.selector" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" diff --git a/libs/core/core/hooks/use-watch-outbox-entries-effect.ts b/libs/core/core/hooks/use-watch-outbox-entries-effect.ts index 00ca5b10fc..05874cb895 100644 --- a/libs/core/core/hooks/use-watch-outbox-entries-effect.ts +++ b/libs/core/core/hooks/use-watch-outbox-entries-effect.ts @@ -17,8 +17,8 @@ import { NotificationMethod, NotificationType, } from "Core/notification/constants" -import { getActiveDeviceTypeSelector } from "Core/device-manager/selectors/get-active-device-type.selector" -import { DeviceType } from "Core/device" +import { getActiveDeviceTypeSelector } from "device-manager/feature" +import { DeviceType } from "device-protocol/models" const outboxIntervalTime = 10000 diff --git a/libs/core/core/hooks/use-watch-unlock-status-effect.ts b/libs/core/core/hooks/use-watch-unlock-status-effect.ts index 259cbff0fc..5e6f761400 100644 --- a/libs/core/core/hooks/use-watch-unlock-status-effect.ts +++ b/libs/core/core/hooks/use-watch-unlock-status-effect.ts @@ -8,10 +8,10 @@ import { useDispatch, useSelector } from "react-redux" import { getDeviceInitializationStatus } from "Core/device-initialization/selectors/get-device-initialization-status.selector" import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" import { Dispatch } from "Core/__deprecated__/renderer/store" -import { getActiveDeviceTypeSelector } from "Core/device-manager/selectors/get-active-device-type.selector" +import { getActiveDeviceTypeSelector } from "device-manager/feature" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { getUnlockStatus } from "Core/device/actions/get-unlock-status.action" -import { DeviceType } from "Core/device/constants" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { DeviceType } from "device-protocol/models" const unlockStatusIntervalTime = 10000 diff --git a/libs/core/core/module/base.module.ts b/libs/core/core/module/base.module.ts index 9ab416ee3f..e1bf9515fd 100644 --- a/libs/core/core/module/base.module.ts +++ b/libs/core/core/module/base.module.ts @@ -9,7 +9,7 @@ import { MetadataStore } from "Core/metadata/services" import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { IndexStorage } from "Core/index-storage/types" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { Controller, Model, @@ -27,7 +27,7 @@ export class BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/core/types/module.type.ts b/libs/core/core/types/module.type.ts index d5f77a9e4d..a6340b326d 100644 --- a/libs/core/core/types/module.type.ts +++ b/libs/core/core/types/module.type.ts @@ -15,13 +15,13 @@ import { Model } from "./model.type" import { Repository } from "./repository.type" import { Observer } from "./observer.type" import { Initializer } from "./initializer.type" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export interface Module { // eslint-disable-next-line @typescript-eslint/no-misused-new new ( index: IndexStorage, - deviceManager: DeviceManager, + deviceManager: DeviceProtocolService, keyStorage: MetadataStore, logger: AppLogger, ipc: MainProcessIpc, diff --git a/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.component.tsx b/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.component.tsx index 807b3aa06d..7efb4ae134 100644 --- a/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.component.tsx +++ b/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.component.tsx @@ -5,7 +5,7 @@ import React from "react" import { defineMessages } from "react-intl" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { intl } from "Core/__deprecated__/renderer/utils/intl" import { FunctionComponent } from "Core/core/types/function-component.interface" import { ModalDialog, ModalDialogProps } from "Core/ui/components/modal-dialog" diff --git a/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.stories.tsx b/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.stories.tsx index ef38368a02..c65f87a620 100644 --- a/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.stories.tsx +++ b/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.stories.tsx @@ -6,7 +6,7 @@ import React from "react" import { storiesOf } from "@storybook/react" import { action } from "@storybook/addon-actions" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { CrashDumpModal } from "Core/crash-dump/components/crash-dump-modal/crash-dump-modal.component" storiesOf("Crash Dump/Modals", module).add("Information", () => ( diff --git a/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.test.tsx b/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.test.tsx index 998ec8f4bb..9d72340fd4 100644 --- a/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.test.tsx +++ b/libs/core/crash-dump/components/crash-dump-modal/crash-dump-modal.test.tsx @@ -5,7 +5,7 @@ import React from "react" import { waitFor } from "@testing-library/dom" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { screen, fireEvent } from "@testing-library/dom" import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/render-with-theme-and-intl" import { diff --git a/libs/core/crash-dump/components/crash-dump/crash-dump.component.test.tsx b/libs/core/crash-dump/components/crash-dump/crash-dump.component.test.tsx index 5830bf751e..dc9bb60e79 100644 --- a/libs/core/crash-dump/components/crash-dump/crash-dump.component.test.tsx +++ b/libs/core/crash-dump/components/crash-dump/crash-dump.component.test.tsx @@ -9,7 +9,7 @@ import { Provider } from "react-redux" import createMockStore from "redux-mock-store" import thunk from "redux-thunk" import { screen, fireEvent } from "@testing-library/dom" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { State } from "Core/core/constants" import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/render-with-theme-and-intl" import { CrashDump } from "Core/crash-dump/components/crash-dump/crash-dump.component" diff --git a/libs/core/crash-dump/components/crash-dump/crash-dump.interface.ts b/libs/core/crash-dump/components/crash-dump/crash-dump.interface.ts index 68c6889f3c..c609ff43fd 100644 --- a/libs/core/crash-dump/components/crash-dump/crash-dump.interface.ts +++ b/libs/core/crash-dump/components/crash-dump/crash-dump.interface.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { CrashDump } from "Core/crash-dump/dto" import { ModalLayers } from "Core/modals-manager/constants/modal-layers.enum" diff --git a/libs/core/crash-dump/crash-dump.module.ts b/libs/core/crash-dump/crash-dump.module.ts index 315bba2c11..d2e679517c 100644 --- a/libs/core/crash-dump/crash-dump.module.ts +++ b/libs/core/crash-dump/crash-dump.module.ts @@ -14,7 +14,7 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { CrashDumpController } from "Core/crash-dump/controllers" import { CrashDumpService } from "Core/crash-dump/services" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class CrashDumpModule extends BaseModule { private crashDumpController: CrashDumpController @@ -22,7 +22,7 @@ export class CrashDumpModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/crash-dump/services/crash-dump.service.test.ts b/libs/core/crash-dump/services/crash-dump.service.test.ts index 92ae4625a7..4c8372e384 100644 --- a/libs/core/crash-dump/services/crash-dump.service.test.ts +++ b/libs/core/crash-dump/services/crash-dump.service.test.ts @@ -5,8 +5,8 @@ import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" -import { DeviceCommunicationError } from "Core/device/constants" -import { DeviceManager } from "Core/device-manager/services/device-manager.service" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceProtocolService } from "device-protocol/feature" import { CrashDumpService } from "Core/crash-dump/services/crash-dump.service" import { DeviceFileSystemService } from "Core/device-file-system/services" import { RequestResponseStatus } from "Core/core/types/request-response.interface" @@ -15,7 +15,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const deviceFileSystemMock = { downloadDeviceFilesLocally: jest.fn(), @@ -133,9 +133,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { .mockReturnValueOnce(Result.success(undefined)) ;( deviceFileSystemMock.downloadDeviceFilesLocally as jest.Mock - ).mockReturnValueOnce( - Result.success([]) - ) + ).mockReturnValueOnce(Result.success([])) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -148,7 +146,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { expect(await subject.downloadDeviceCrashDumpFiles()).toEqual({ status: RequestResponseStatus.Ok, - data: [] + data: [], }) // AUTO DISABLED - fix me if you like :) diff --git a/libs/core/crash-dump/services/crash-dump.service.ts b/libs/core/crash-dump/services/crash-dump.service.ts index 3a486e4063..e196084aef 100644 --- a/libs/core/crash-dump/services/crash-dump.service.ts +++ b/libs/core/crash-dump/services/crash-dump.service.ts @@ -3,7 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DiagnosticsFileList, Endpoint, Method } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" +import { DiagnosticsFileList } from "Core/device/constants" import { GetDeviceFilesResponseBody } from "Core/device/types/mudita-os" import path from "path" import { ResultObject } from "Core/core/builder" @@ -13,11 +14,11 @@ import { RequestResponse, RequestResponseStatus, } from "Core/core/types/request-response.interface" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class CrashDumpService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private deviceFileSystem: DeviceFileSystemService ) {} diff --git a/libs/core/data-sync/actions/base-app.action.test.ts b/libs/core/data-sync/actions/base-app.action.test.ts deleted file mode 100644 index adbc646d30..0000000000 --- a/libs/core/data-sync/actions/base-app.action.test.ts +++ /dev/null @@ -1,27 +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 createMockStore from "redux-mock-store" -import thunk from "redux-thunk" -import { DataSyncEvent } from "Core/data-sync/constants" -import { setDataSyncInitState } from "Core/data-sync/actions/base-app.action" - -const mockStore = createMockStore([thunk])() - -afterEach(() => { - mockStore.clearActions() -}) - -describe("Action: SetDataSyncInitState", () => { - test("fire action without payload and `SetDataSyncInitState` type", () => { - mockStore.dispatch(setDataSyncInitState()) - expect(mockStore.getActions()).toEqual([ - { - type: DataSyncEvent.SetDataSyncInitState, - payload: undefined, - }, - ]) - }) -}) diff --git a/libs/core/data-sync/actions/base-app.action.ts b/libs/core/data-sync/actions/base-app.action.ts index 521e684846..70f01379b7 100644 --- a/libs/core/data-sync/actions/base-app.action.ts +++ b/libs/core/data-sync/actions/base-app.action.ts @@ -7,9 +7,6 @@ import { createAction } from "@reduxjs/toolkit" import { DataSyncEvent } from "Core/data-sync/constants" import { SynchronizationStatus } from "Core/data-sync/reducers" -export const setDataSyncInitState = createAction( - DataSyncEvent.SetDataSyncInitState -) export const setDataSyncSetStatus = createAction( DataSyncEvent.SetDataSyncSetStatus ) diff --git a/libs/core/data-sync/constants/event.enum.ts b/libs/core/data-sync/constants/event.enum.ts index 240807a107..cc6ab8ac18 100644 --- a/libs/core/data-sync/constants/event.enum.ts +++ b/libs/core/data-sync/constants/event.enum.ts @@ -4,9 +4,7 @@ */ export enum DataSyncEvent { - SetDataSyncInitState = "DATA_SYNC_SET_INIT_STATE", SetDataSyncSetStatus = "DATA_SYNC_SET_STATUS", - ReadAllIndexes = "DATA_SYNC_READ_ALL_INDEXES", UpdateAllIndexes = "DATA_SYNC_UPDATE_ALL_INDEXES", } diff --git a/libs/core/data-sync/data-sync.module.ts b/libs/core/data-sync/data-sync.module.ts index 1c3062ca64..83733e038d 100644 --- a/libs/core/data-sync/data-sync.module.ts +++ b/libs/core/data-sync/data-sync.module.ts @@ -12,7 +12,7 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DataSyncService } from "Core/data-sync/services/data-sync.service" import { DataSyncController } from "Core/data-sync/controllers" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class DataSyncModule extends BaseModule { private dataSyncService: DataSyncService @@ -20,7 +20,7 @@ export class DataSyncModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/data-sync/reducers/data-sync.reducer.ts b/libs/core/data-sync/reducers/data-sync.reducer.ts index 886799ea3a..7939747cb1 100644 --- a/libs/core/data-sync/reducers/data-sync.reducer.ts +++ b/libs/core/data-sync/reducers/data-sync.reducer.ts @@ -3,17 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" import { DataSyncState, SynchronizationStatus, } from "Core/data-sync/reducers/data-sync.interface" -import { createReducer } from "@reduxjs/toolkit" -import { - setDataSyncInitState, - setDataSyncSetStatus, - updateAllIndexes, -} from "Core/data-sync/actions" +import { setDataSyncSetStatus, updateAllIndexes } from "Core/data-sync/actions" import { AppError } from "Core/core/errors" +import { pendingAction } from "Core/__deprecated__/renderer/store/helpers" export const initialState: DataSyncState = { status: SynchronizationStatus.Empty, @@ -24,7 +22,7 @@ export const dataSyncReducer = createReducer( initialState, (builder) => { builder - .addCase(setDataSyncInitState, () => { + .addCase(pendingAction(DeviceManagerEvent.DeactivateDevice), () => { return { ...initialState, } diff --git a/libs/core/data-sync/services/data-sync.service.ts b/libs/core/data-sync/services/data-sync.service.ts index 27df3cbfdf..542e8c02f1 100644 --- a/libs/core/data-sync/services/data-sync.service.ts +++ b/libs/core/data-sync/services/data-sync.service.ts @@ -8,7 +8,7 @@ import { DeviceFileSystemService } from "Core/device-file-system/services" import getAppPath from "Core/__deprecated__/main/utils/get-app-path" import { IndexStorage } from "Core/index-storage/types" import { DataIndex } from "Core/index-storage/constants" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { MetadataStore } from "Core/metadata/services" import { ContactIndexer, @@ -35,7 +35,7 @@ export class DataSyncService { constructor( private index: IndexStorage, - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private keyStorage: MetadataStore, private fileSystemStorage: FileSystemService ) { diff --git a/libs/core/desktop/desktop.module.ts b/libs/core/desktop/desktop.module.ts index 7fd5ac6d2b..8407f67343 100644 --- a/libs/core/desktop/desktop.module.ts +++ b/libs/core/desktop/desktop.module.ts @@ -10,14 +10,14 @@ import { FileSystemService } from "Core/file-system/services/file-system.service import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DesktopController } from "Core/desktop/desktop.controller" import { DesktopService } from "Core/desktop/desktop.service" export class DesktopModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/device-file-system/commands/base.command.ts b/libs/core/device-file-system/commands/base.command.ts index bb86061bf2..ad43f742bc 100644 --- a/libs/core/device-file-system/commands/base.command.ts +++ b/libs/core/device-file-system/commands/base.command.ts @@ -4,10 +4,10 @@ */ import * as CRC32 from "crc-32" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export abstract class BaseCommand { - constructor(public deviceManager: DeviceManager) {} + constructor(public deviceManager: DeviceProtocolService) {} public countCRC32(buffer: Buffer | Uint8Array): string { const crc = CRC32.buf(buffer) diff --git a/libs/core/device-file-system/commands/file-delete.command.test.ts b/libs/core/device-file-system/commands/file-delete.command.test.ts index 5af1fa58e6..133b0b9b2a 100644 --- a/libs/core/device-file-system/commands/file-delete.command.test.ts +++ b/libs/core/device-file-system/commands/file-delete.command.test.ts @@ -3,12 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { - Endpoint, - Method, - DeviceCommunicationError, -} from "Core/device/constants" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" +import { DeviceProtocolService } from "device-protocol/feature" import { AppError } from "Core/core/errors" import { Result, ResultObject, SuccessResult } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" @@ -18,7 +14,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const subject = new FileDeleteCommand(deviceManager) diff --git a/libs/core/device-file-system/commands/file-delete.command.ts b/libs/core/device-file-system/commands/file-delete.command.ts index cab6196abd..fe5af0de79 100644 --- a/libs/core/device-file-system/commands/file-delete.command.ts +++ b/libs/core/device-file-system/commands/file-delete.command.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Endpoint, Method } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" import { BaseCommand } from "Core/device-file-system/commands/base.command" diff --git a/libs/core/device-file-system/commands/file-upload.command.test.ts b/libs/core/device-file-system/commands/file-upload.command.test.ts index 061f735e1e..760c681bfe 100644 --- a/libs/core/device-file-system/commands/file-upload.command.test.ts +++ b/libs/core/device-file-system/commands/file-upload.command.test.ts @@ -6,13 +6,9 @@ import fs from "fs" import path from "path" import mock from "mock-fs" -import { - Endpoint, - Method, - DeviceCommunicationError, -} from "Core/device/constants" +import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { FileUploadCommand } from "Core/device-file-system/commands/file-upload.command" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" @@ -23,7 +19,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const fileSystemService = { readFile: jest.fn(), diff --git a/libs/core/device-file-system/commands/file-upload.command.ts b/libs/core/device-file-system/commands/file-upload.command.ts index 382442d259..4e6fd0ff50 100644 --- a/libs/core/device-file-system/commands/file-upload.command.ts +++ b/libs/core/device-file-system/commands/file-upload.command.ts @@ -4,9 +4,9 @@ */ import path from "path" -import { Endpoint, Method } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" import { PutFileSystemResponseBody } from "Core/device/types/mudita-os" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" @@ -16,7 +16,7 @@ import { DeviceFileSystemError } from "Core/device-file-system/constants" export class FileUploadCommand extends BaseCommand { constructor( - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public fileSystemService: FileSystemService ) { super(deviceManager) diff --git a/libs/core/device-file-system/commands/retrieve-files.command.test.ts b/libs/core/device-file-system/commands/retrieve-files.command.test.ts index 8f1e58413c..f80ba6b3c6 100644 --- a/libs/core/device-file-system/commands/retrieve-files.command.test.ts +++ b/libs/core/device-file-system/commands/retrieve-files.command.test.ts @@ -3,13 +3,9 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { - Endpoint, - Method, - DeviceCommunicationError, -} from "Core/device/constants" +import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { RetrieveFilesCommand } from "Core/device-file-system/commands/retrieve-files.command" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" @@ -19,7 +15,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const subject = new RetrieveFilesCommand(deviceManager) diff --git a/libs/core/device-file-system/commands/retrieve-files.command.ts b/libs/core/device-file-system/commands/retrieve-files.command.ts index 4283c3f735..21fad3c143 100644 --- a/libs/core/device-file-system/commands/retrieve-files.command.ts +++ b/libs/core/device-file-system/commands/retrieve-files.command.ts @@ -8,7 +8,7 @@ import { AppError } from "Core/core/errors" import { BaseCommand } from "Core/device-file-system/commands/base.command" import { DeviceFileSystemError } from "Core/device-file-system/constants" import { DirectoryFile } from "Core/device-file-system/types" -import { Endpoint, Method } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" import { GetFileSystemDirectoryResponseBody } from "Core/device/types/mudita-os" export class RetrieveFilesCommand extends BaseCommand { diff --git a/libs/core/device-file-system/device-file-system.module.ts b/libs/core/device-file-system/device-file-system.module.ts index 0ae2ec6abc..e6fbb240d2 100644 --- a/libs/core/device-file-system/device-file-system.module.ts +++ b/libs/core/device-file-system/device-file-system.module.ts @@ -12,12 +12,12 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DeviceFileSystemController } from "Core/device-file-system/controllers" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class DeviceFileSystemModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/device-file-system/services/device-file-system.service.test.ts b/libs/core/device-file-system/services/device-file-system.service.test.ts index 87a0cf83cf..2d2d5093f1 100644 --- a/libs/core/device-file-system/services/device-file-system.service.test.ts +++ b/libs/core/device-file-system/services/device-file-system.service.test.ts @@ -6,8 +6,8 @@ import path from "path" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" -import { DeviceCommunicationError } from "Core/device/constants" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceProtocolService } from "device-protocol/feature" import { DownloadFileSystemRequestConfig, GetFileSystemRequestConfig, @@ -27,7 +27,7 @@ const deviceManager = { device: { id: "abc123", }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const deviceFileSystem = new DeviceFileSystemService(deviceManager) diff --git a/libs/core/device-file-system/services/device-file-system.service.ts b/libs/core/device-file-system/services/device-file-system.service.ts index 8397db836b..016d18c53d 100644 --- a/libs/core/device-file-system/services/device-file-system.service.ts +++ b/libs/core/device-file-system/services/device-file-system.service.ts @@ -8,8 +8,8 @@ import stream from "stream" import path from "path" import { AppError } from "Core/core/errors" import { ResultObject, Result } from "Core/core/builder" -import { Endpoint, Method } from "Core/device/constants" -import { DeviceManager } from "Core/device-manager/services" +import { Endpoint, Method } from "core-device/models" +import { DeviceProtocolService } from "device-protocol/feature" import logger from "Core/__deprecated__/main/utils/logger" import countCRC32 from "Core/device-file-system/helpers/count-crc32" import { FileSystemService } from "Core/file-system/services/file-system.service" @@ -27,7 +27,7 @@ import { } from "Core/device-file-system/dto" export class DeviceFileSystemService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} public async downloadDeviceFilesLocally( filePaths: string[], diff --git a/libs/core/device-info/device-info.module.ts b/libs/core/device-info/device-info.module.ts index 31bc6fca26..9856af7aa1 100644 --- a/libs/core/device-info/device-info.module.ts +++ b/libs/core/device-info/device-info.module.ts @@ -12,12 +12,12 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DeviceInfoService } from "Core/device-info/services" import { DeviceInfoController } from "Core/device-info/controllers" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class DeviceInfoModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/device-info/dto/device-info.object.ts b/libs/core/device-info/dto/device-info.object.ts index 7073921f31..ce327e985a 100644 --- a/libs/core/device-info/dto/device-info.object.ts +++ b/libs/core/device-info/dto/device-info.object.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" // DEPRECATED import { SimCard } from "Core/__deprecated__/renderer/models/basic-info/basic-info.typings" diff --git a/libs/core/device-info/presenters/device-info.presenter.ts b/libs/core/device-info/presenters/device-info.presenter.ts index 1fc5abc23b..91e47a9ddc 100644 --- a/libs/core/device-info/presenters/device-info.presenter.ts +++ b/libs/core/device-info/presenters/device-info.presenter.ts @@ -4,7 +4,8 @@ */ import { DeviceInfo as DeviceInfoRaw } from "Core/device/types/mudita-os" -import { CaseColour, DeviceType } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { DeviceInfo } from "Core/device-info/dto" import { SimCardPresenter } from "Core/device-info/presenters/sim-card.presenter" import { OnboardingState } from "Core/device/constants/onboarding-state.constant" diff --git a/libs/core/device-info/services/device-info.service.ts b/libs/core/device-info/services/device-info.service.ts index 81251e3b87..24b0101a42 100644 --- a/libs/core/device-info/services/device-info.service.ts +++ b/libs/core/device-info/services/device-info.service.ts @@ -7,12 +7,8 @@ import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import { DeviceInfo } from "Core/device-info/dto" import { DeviceInfoPresenter } from "Core/device-info/presenters" -import { DeviceManager } from "Core/device-manager/services" -import { - DeviceCommunicationError, - Endpoint, - Method, -} from "Core/device/constants" +import { DeviceProtocolService } from "device-protocol/feature" +import { Endpoint, Method, DeviceCommunicationError } from "core-device/models" import { DeviceInfo as DeviceInfoRaw, NotSupportedDeviceInfo, @@ -20,7 +16,7 @@ import { import { DeviceId } from "Core/device/constants/device-id" export class DeviceInfoService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} private async getDeviceInfoRequest( deviceId: DeviceId = this.deviceManager.device.id diff --git a/libs/core/device-initialization/actions/initialize-mudita-harmony.action.ts b/libs/core/device-initialization/actions/initialize-mudita-harmony.action.ts index 3a627bf98d..bb088cd197 100644 --- a/libs/core/device-initialization/actions/initialize-mudita-harmony.action.ts +++ b/libs/core/device-initialization/actions/initialize-mudita-harmony.action.ts @@ -12,12 +12,11 @@ import { DeviceInitializationStatus } from "Core/device-initialization/reducers/ import { AppError } from "Core/core/errors" import { DeviceInitializationError } from "Core/device-initialization/constants/errors.enum" import { loadSettings } from "Core/settings/actions" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { isActiveDeviceAttachedSelector } from "device-manager/feature" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { getCrashDump } from "Core/crash-dump" import { checkForForceUpdateNeed } from "Core/update/actions" -import { isActiveDeviceAttachedSelector } from "Core/device-manager/selectors/is-active-device-attached.selector" - export const initializeMuditaHarmony = createAsyncThunk< DeviceInitializationStatus, void, diff --git a/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts b/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts index 8a4e5539b5..0ebfa98153 100644 --- a/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts +++ b/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts @@ -12,9 +12,12 @@ import { DeviceInitializationStatus } from "Core/device-initialization/reducers/ import { AppError } from "Core/core/errors" import { DeviceInitializationError } from "Core/device-initialization/constants/errors.enum" import { loadSettings } from "Core/settings/actions" -import { configureDevice } from "Core/device-manager/actions/configure-device.action" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { configureDevice } from "core-device/feature" +import { + activeDeviceIdSelector, + isActiveDeviceAttachedSelector, +} from "device-manager/feature" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { getCrashDump } from "Core/crash-dump" import { checkForForceUpdateNeed } from "Core/update/actions" import { deviceDataSelector } from "Core/device/selectors/device-data.selector" @@ -27,7 +30,6 @@ import { } from "Core/data-sync/actions" import { SynchronizationStatus } from "Core/data-sync/reducers" import { loadBackupData } from "Core/backup" -import { isActiveDeviceAttachedSelector } from "Core/device-manager/selectors/is-active-device-attached.selector" export const initializeMuditaPure = createAsyncThunk< DeviceInitializationStatus, diff --git a/libs/core/device-initialization/components/devices-initialization.component.tsx b/libs/core/device-initialization/components/devices-initialization.component.tsx index 5f4ef6420c..2a1b34cfd9 100644 --- a/libs/core/device-initialization/components/devices-initialization.component.tsx +++ b/libs/core/device-initialization/components/devices-initialization.component.tsx @@ -7,12 +7,12 @@ import React from "react" import { useSelector } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" -import { DeviceType } from "Core/device" +import { getActiveDevice } from "device-manager/feature" +import { DeviceType } from "device-protocol/models" import { MuditaPureInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow" import { MuditaHarmonyInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-harmony-initialization-modal-flow" import { APIDeviceInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow" -import { Device } from "Core/device-manager/reducers/device-manager.interface" +import { Device } from "core-device/models" const DevicesInitializationModalFlow: FunctionComponent<{ activeDevice?: Device diff --git a/libs/core/device-initialization/selectors/is-passcode-modal-can-be-closed.selector.ts b/libs/core/device-initialization/selectors/is-passcode-modal-can-be-closed.selector.ts index b425801631..eecc7ae3bb 100644 --- a/libs/core/device-initialization/selectors/is-passcode-modal-can-be-closed.selector.ts +++ b/libs/core/device-initialization/selectors/is-passcode-modal-can-be-closed.selector.ts @@ -5,7 +5,7 @@ import { createSelector } from "@reduxjs/toolkit" import { updateStateSelector } from "Core/update/selectors/update-state-selector" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" export const isPasscodeModalCanBeClosedSelector = createSelector( updateStateSelector, diff --git a/libs/core/device-log/device-log.module.ts b/libs/core/device-log/device-log.module.ts index 0ed685e287..5c79dae9b6 100644 --- a/libs/core/device-log/device-log.module.ts +++ b/libs/core/device-log/device-log.module.ts @@ -13,12 +13,12 @@ import { BaseModule } from "Core/core/module" import { DeviceFileSystemService } from "Core/device-file-system/services" import { DeviceLogService } from "Core/device-log/services" import { DeviceLogController } from "Core/device-log/controllers" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class DeviceLogModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/device-log/services/device-log.service.test.ts b/libs/core/device-log/services/device-log.service.test.ts index cd3a584cca..a5a5b6c624 100644 --- a/libs/core/device-log/services/device-log.service.test.ts +++ b/libs/core/device-log/services/device-log.service.test.ts @@ -5,16 +5,12 @@ import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" -import { - Endpoint, - Method, - DiagnosticsFileList, - DeviceCommunicationError, -} from "Core/device/constants" +import { DiagnosticsFileList } from "Core/device/constants" +import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { GetDeviceFilesResponseBody } from "Core/device/types/mudita-os" import { DeviceLogService } from "Core/device-log/services/device-log.service" import { DeviceEnumError } from "Core/device-log/constants" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceFileSystemService } from "Core/device-file-system/services" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { @@ -26,7 +22,7 @@ const deviceManagerMock = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const deviceFileSystemMock = { downloadDeviceFiles: jest.fn(), diff --git a/libs/core/device-log/services/device-log.service.ts b/libs/core/device-log/services/device-log.service.ts index 9874aab847..c16d330ab4 100644 --- a/libs/core/device-log/services/device-log.service.ts +++ b/libs/core/device-log/services/device-log.service.ts @@ -3,20 +3,21 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { Endpoint, Method } from "core-device/models" import { ResultObject, Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { Endpoint, Method, DiagnosticsFileList } from "Core/device/constants" +import { DiagnosticsFileList } from "Core/device/constants" import { GetDeviceFilesResponseBody } from "Core/device/types/mudita-os" import { transformDeviceFilesByOption } from "Core/device-log/helpers" import { DeviceFile } from "Core/device-file-system/dto" import { DeviceEnumError } from "Core/device-log/constants" import { DeviceFilesOption } from "Core/device-file-system/types" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class DeviceLogService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private deviceFileSystem: DeviceFileSystemService ) {} diff --git a/libs/core/device-manager/actions/base.action.ts b/libs/core/device-manager/actions/base.action.ts deleted file mode 100644 index efe2596a56..0000000000 --- a/libs/core/device-manager/actions/base.action.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 - */ - -import { createAction } from "@reduxjs/toolkit" -import { DeviceManagerEvent } from "Core/device-manager/constants" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" -import { DeviceState } from "Core/device-manager/reducers/device-manager.interface" -import { CaseColour } from "Core/device" - -export const addDevice = createAction>( - DeviceManagerEvent.AddDevice -) - -export const removeDevice = createAction( - DeviceManagerEvent.RemoveDevice -) diff --git a/libs/core/device-manager/actions/connect-device.action.ts b/libs/core/device-manager/actions/connect-device.action.ts deleted file mode 100644 index bbcc2b6245..0000000000 --- a/libs/core/device-manager/actions/connect-device.action.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 { createAsyncThunk } from "@reduxjs/toolkit" -import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceManagerEvent } from "Core/device-manager/constants" -import { DeviceId } from "Core/device/constants/device-id" -import { connectDeviceRequest } from "Core/device-manager/requests/connect-device.request" - -export const connectDevice = createAsyncThunk< - boolean, - DeviceId, - { state: ReduxRootState } ->( - DeviceManagerEvent.ConnectDevice, - async (id) => { - const result = await connectDeviceRequest(id) - return result.ok - } -) diff --git a/libs/core/device-manager/selectors/get-device.selector.ts b/libs/core/device-manager/selectors/get-device.selector.ts deleted file mode 100644 index 70b39b246f..0000000000 --- a/libs/core/device-manager/selectors/get-device.selector.ts +++ /dev/null @@ -1,17 +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 { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" -import { Device } from "Core/device-manager/reducers/device-manager.interface" - -export const getDeviceSelector = (id: string) => { - return createSelector( - deviceManagerState, - ({ devices }): Device | undefined => { - return devices.find((device) => device.id === id) - } - ) -} diff --git a/libs/core/device-manager/selectors/get-devices.selector.ts b/libs/core/device-manager/selectors/get-devices.selector.ts deleted file mode 100644 index 0a634f4191..0000000000 --- a/libs/core/device-manager/selectors/get-devices.selector.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 { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" -import { Device } from "Core/device-manager/reducers/device-manager.interface" - -export const getDevicesSelector = createSelector( - deviceManagerState, - (deviceManager): Device[] => { - return deviceManager.devices - } -) diff --git a/libs/core/device-manager/selectors/get-failed-devices.selector.ts b/libs/core/device-manager/selectors/get-failed-devices.selector.ts deleted file mode 100644 index 9caff9d657..0000000000 --- a/libs/core/device-manager/selectors/get-failed-devices.selector.ts +++ /dev/null @@ -1,20 +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 { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" -import { - Device, - DeviceState, -} from "Core/device-manager/reducers/device-manager.interface" - -export const getFailedDevicesSelector = createSelector( - deviceManagerState, - (deviceManager): Device[] => { - return deviceManager.devices.filter( - ({ state }) => state === DeviceState.Failed - ) - } -) diff --git a/libs/core/device-select/components/device-select-drawer.component.tsx b/libs/core/device-select/components/device-select-drawer.component.tsx index 93dc51812d..96a12c9e67 100644 --- a/libs/core/device-select/components/device-select-drawer.component.tsx +++ b/libs/core/device-select/components/device-select-drawer.component.tsx @@ -10,7 +10,7 @@ import Drawer from "react-modern-drawer" import "react-modern-drawer/dist/index.css" import { FunctionComponent } from "Core/core/types/function-component.interface" import { isSelectDeviceDrawerOpenSelector } from "Core/device-select/selectors/is-select-device-drawer-open.selector" -import { setSelectDeviceDrawerOpen } from "Core/device-select/actions/set-select-device-drawer-open.action" +import { setSelectDeviceDrawerOpen } from "device-manager/feature" import Text, { TextDisplayStyle, } from "Core/__deprecated__/renderer/components/core/text/text.component" @@ -18,12 +18,14 @@ import styled from "styled-components" import { Close } from "Core/__deprecated__/renderer/components/core/modal/modal.styled.elements" import { DisplayStyle } from "Core/__deprecated__/renderer/components/core/button/button.config" import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon-type" -import { getAvailableDevicesSelector } from "Core/device-manager/selectors/get-available-devices.selector" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" +import { + getAvailableDevicesSelector, + deactivateDevice, + activeDeviceIdSelector, + handleDeviceActivated, +} from "device-manager/feature" import { useHistory } from "react-router-dom" -import { handleDeviceActivated } from "Core/device-manager/actions/handle-device-activated.action" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" -import { DeviceState } from "Core/device-manager/reducers/device-manager.interface" +import { DeviceState } from "core-device/models" import { URL_DEVICE_INITIALIZATION, URL_ONBOARDING, diff --git a/libs/core/device-select/components/drawer-device.component.tsx b/libs/core/device-select/components/drawer-device.component.tsx index 7eff3d15e3..68b2aee190 100644 --- a/libs/core/device-select/components/drawer-device.component.tsx +++ b/libs/core/device-select/components/drawer-device.component.tsx @@ -17,8 +17,8 @@ import { transitionTime, transitionTimingFunction, } from "Core/core/styles/theming/theme-getters" -import { DeviceType } from "Core/device" -import { CaseColour } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" +import { CaseColour } from "core-device/models" import { getDeviceTypeName } from "Core/discovery-device/utils/get-device-type-name" import { intl } from "Core/__deprecated__/renderer/utils/intl" import { getSerialNumberValue } from "Core/utils/get-serial-number-value" diff --git a/libs/core/device-select/selectors/is-select-device-drawer-open.selector.ts b/libs/core/device-select/selectors/is-select-device-drawer-open.selector.ts index 03983429ca..2d39476d54 100644 --- a/libs/core/device-select/selectors/is-select-device-drawer-open.selector.ts +++ b/libs/core/device-select/selectors/is-select-device-drawer-open.selector.ts @@ -4,7 +4,7 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" +import { deviceManagerState } from "device-manager/feature" export const isSelectDeviceDrawerOpenSelector = createSelector( deviceManagerState, diff --git a/libs/core/device/actions/base.action.ts b/libs/core/device/actions/base.action.ts index 6cfd194928..e4f4f8c474 100644 --- a/libs/core/device/actions/base.action.ts +++ b/libs/core/device/actions/base.action.ts @@ -11,7 +11,6 @@ export const setLockTime = createAction< GetPhoneLockTimeResponseBody | undefined >(DeviceEvent.SetLockTime) -export const setInitState = createAction(DeviceEvent.SetInitState) export const setOnboardingStatus = createAction( DeviceEvent.SetOnboardingStatus ) @@ -27,4 +26,6 @@ export const setExternalUsageDevice = createAction( DeviceEvent.SetExternalUsageDevice ) -export const setRestartingStatus = createAction(DeviceEvent.SetRestartingStatus) +export const setRestartingStatus = createAction( + DeviceEvent.SetRestartingStatus +) diff --git a/libs/core/device/actions/get-onboarding-status.action.ts b/libs/core/device/actions/get-onboarding-status.action.ts index 62351e2d70..b16f835410 100644 --- a/libs/core/device/actions/get-onboarding-status.action.ts +++ b/libs/core/device/actions/get-onboarding-status.action.ts @@ -4,10 +4,11 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { DeviceCommunicationError, DeviceEvent } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceEvent } from "Core/device/constants" import { unlockDeviceStatusRequest } from "Core/device/requests" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" +import { getActiveDevice } from "device-manager/feature" export const getOnboardingStatus = createAsyncThunk< boolean, diff --git a/libs/core/device/actions/get-unlock-status.action.ts b/libs/core/device/actions/get-unlock-status.action.ts index 1e5d686725..d9038f8db7 100644 --- a/libs/core/device/actions/get-unlock-status.action.ts +++ b/libs/core/device/actions/get-unlock-status.action.ts @@ -4,7 +4,8 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { DeviceCommunicationError, DeviceEvent } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceEvent } from "Core/device/constants" import { unlockDeviceStatusRequest } from "Core/device/requests" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { setLockTime, setUnlockedStatus } from "Core/device/actions/base.action" diff --git a/libs/core/device/actions/handle-communication-error.action.ts b/libs/core/device/actions/handle-communication-error.action.ts index 42569134bc..4323e03b09 100644 --- a/libs/core/device/actions/handle-communication-error.action.ts +++ b/libs/core/device/actions/handle-communication-error.action.ts @@ -4,7 +4,8 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { DeviceCommunicationError, DeviceEvent } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceEvent } from "Core/device/constants" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { setCriticalBatteryLevelStatus, diff --git a/libs/core/device/actions/load-device-data.action.ts b/libs/core/device/actions/load-device-data.action.ts index 6715c14174..7a54449638 100644 --- a/libs/core/device/actions/load-device-data.action.ts +++ b/libs/core/device/actions/load-device-data.action.ts @@ -8,7 +8,7 @@ import { DeviceEvent } from "Core/device/constants" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { getDeviceInfoRequest } from "Core/device-info/requests" import { DeviceInfo } from "Core/device-info/dto" -import { getActiveDeviceTypeSelector } from "Core/device-manager/selectors/get-active-device-type.selector" +import { getActiveDeviceTypeSelector } from "device-manager/feature" import { DeviceState } from "Core/device/reducers" import { processDeviceDataOnLoad } from "Core/device/actions/process-device-data-on-load.action" import { handleCommunicationError } from "Core/device/actions/handle-communication-error.action" diff --git a/libs/core/device/actions/process-device-data-on-load.action.ts b/libs/core/device/actions/process-device-data-on-load.action.ts index 7cd5f044ca..3c91e412ff 100644 --- a/libs/core/device/actions/process-device-data-on-load.action.ts +++ b/libs/core/device/actions/process-device-data-on-load.action.ts @@ -10,7 +10,7 @@ import { setExternalUsageDevice } from "Core/device/actions/base.action" import { externalUsageDevice } from "Core/device/requests/external-usage-device.request" import { setExternalUsageDeviceRequest } from "Core/analytic-data-tracker/requests/set-external-usage-device.request" import { settingsStateSelector } from "Core/settings/selectors" -import { getActiveDeviceBaseDataSelector } from "Core/device-manager/selectors/get-active-device-base-data.selector" +import { getActiveDeviceBaseDataSelector } from "device-manager/feature" import { trackOsVersion } from "Core/analytic-data-tracker/helpers" import { MetadataKey, setValue } from "Core/metadata" diff --git a/libs/core/device/actions/unlock-device.action.ts b/libs/core/device/actions/unlock-device.action.ts index d5cae8fd7d..60ba2d40d6 100644 --- a/libs/core/device/actions/unlock-device.action.ts +++ b/libs/core/device/actions/unlock-device.action.ts @@ -5,11 +5,8 @@ import { createAsyncThunk, PayloadAction } from "@reduxjs/toolkit" import { delay } from "shared/utils" -import { - DeviceCommunicationError, - DeviceError, - DeviceEvent, -} from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceError, DeviceEvent } from "Core/device/constants" import { unlockDeviceRequest, unlockDeviceStatusRequest, diff --git a/libs/core/device/constants/device-base-properties.ts b/libs/core/device/constants/device-base-properties.ts index 351decf534..bad32da02f 100644 --- a/libs/core/device/constants/device-base-properties.ts +++ b/libs/core/device/constants/device-base-properties.ts @@ -4,7 +4,7 @@ */ import { PortInfo } from "serialport" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" export interface DeviceBaseProperties extends PortInfo { id: string diff --git a/libs/core/device/constants/event.enum.ts b/libs/core/device/constants/event.enum.ts index 5efff9a964..e22b23bfa8 100644 --- a/libs/core/device/constants/event.enum.ts +++ b/libs/core/device/constants/event.enum.ts @@ -4,8 +4,6 @@ */ export enum DeviceEvent { - SetInitState = "DEVICE_SET_INIT_STATE", - Unlock = "DEVICE_UNLOCK", UnlockById = "DEVICE_UNLOCK_BY_ID", Locked = "DEVICE_LOCKED", diff --git a/libs/core/device/constants/index.ts b/libs/core/device/constants/index.ts index 1df4ed5902..fc5d1830af 100644 --- a/libs/core/device/constants/index.ts +++ b/libs/core/device/constants/index.ts @@ -7,16 +7,12 @@ export * from "./access-technology.constant" export * from "./backup-category.constant" export * from "./backup-state.constant" export * from "./battery-state.constant" -export * from "./case-colour.constant" export * from "./connection-timeout.constant" export * from "./controller.constant" -export * from "./device-communication-error.constant" -export * from "./device-type.constant" export * from "./device-communication-event.constant" export * from "./device-update-error.constant" export * from "./diagnostic-file.constant" export * from "./diagnostics-file-path.constant" -export * from "./endpoint.constant" export * from "./errors.enum" export * from "./event.enum" export * from "./manufactures.constant" @@ -29,7 +25,6 @@ export * from "./outbox-entry-change.constant" export * from "./outbox-entry-type.constant" export * from "./phone-lock-category.type" export * from "./product-identifier.constant" -export * from "./request-method.constant" export * from "./response-status.constant" export * from "./restore-state.constant" export * from "./signal-strength.constant" diff --git a/libs/core/device/descriptors/device-descriptor.ts b/libs/core/device/descriptors/device-descriptor.ts index 60f42f5707..2b952df2ac 100644 --- a/libs/core/device/descriptors/device-descriptor.ts +++ b/libs/core/device/descriptors/device-descriptor.ts @@ -3,12 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { - Manufacture, - VendorID, - ProductID, - DeviceType, -} from "Core/device/constants" +import { DeviceType } from "device-protocol/models" +import { Manufacture, VendorID, ProductID } from "Core/device/constants" import { PureStrategy, HarmonyStrategy } from "Core/device/strategies" import { SerialPortDeviceAdapter } from "Core/device/modules/mudita-os/adapters/serial-port-device.adapters" diff --git a/libs/core/device/descriptors/mudita-harmony.descriptor.ts b/libs/core/device/descriptors/mudita-harmony.descriptor.ts index a10452a9df..54b43a1258 100644 --- a/libs/core/device/descriptors/mudita-harmony.descriptor.ts +++ b/libs/core/device/descriptors/mudita-harmony.descriptor.ts @@ -3,12 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { - Manufacture, - VendorID, - ProductID, - DeviceType, -} from "Core/device/constants" +import { DeviceType } from "device-protocol/models" +import { Manufacture, VendorID, ProductID } from "Core/device/constants" import { HarmonyStrategy } from "Core/device/strategies" import { SerialPortDeviceAdapter } from "Core/device/modules/mudita-os/adapters" diff --git a/libs/core/device/descriptors/mudita-pure.descriptor.ts b/libs/core/device/descriptors/mudita-pure.descriptor.ts index d9c44f28f8..49f23424bc 100644 --- a/libs/core/device/descriptors/mudita-pure.descriptor.ts +++ b/libs/core/device/descriptors/mudita-pure.descriptor.ts @@ -3,12 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { - Manufacture, - VendorID, - ProductID, - DeviceType, -} from "Core/device/constants" +import { DeviceType } from "device-protocol/models" +import { Manufacture, VendorID, ProductID } from "Core/device/constants" import { PureStrategy } from "Core/device/strategies" import { SerialPortDeviceAdapter } from "Core/device/modules/mudita-os/adapters" diff --git a/libs/core/device/device.module.ts b/libs/core/device/device.module.ts index 686faef37d..02b7d20f81 100644 --- a/libs/core/device/device.module.ts +++ b/libs/core/device/device.module.ts @@ -12,12 +12,12 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DeviceService } from "Core/device/services" import { DeviceController } from "Core/device/controllers" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class DeviceModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/device/factories/device.factory.ts b/libs/core/device/factories/device.factory.ts index 6e5a5bd425..905f5f8718 100644 --- a/libs/core/device/factories/device.factory.ts +++ b/libs/core/device/factories/device.factory.ts @@ -5,7 +5,7 @@ import { PortInfo } from "serialport" import { CoreDevice } from "Core/device/modules/core-device" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { DeviceDescriptor } from "Core/device/descriptors" export class DeviceFactory { diff --git a/libs/core/device/modules/base-device.ts b/libs/core/device/modules/base-device.ts index f095d15632..efcce192d0 100644 --- a/libs/core/device/modules/base-device.ts +++ b/libs/core/device/modules/base-device.ts @@ -7,7 +7,7 @@ import { PortInfo } from "serialport" import { ResultObject } from "Core/core/builder" import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" import { DeviceId } from "Core/device/constants/device-id" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { unknownSerialNumber } from "Core/device/constants/unknown-serial-number.constant" const uniqueId = (length = 16): DeviceId => { diff --git a/libs/core/device/modules/core-device.ts b/libs/core/device/modules/core-device.ts index a3838e695d..ff7c4766c3 100644 --- a/libs/core/device/modules/core-device.ts +++ b/libs/core/device/modules/core-device.ts @@ -5,7 +5,8 @@ import { PortInfo } from "serialport" import { ResultObject } from "Core/core/builder" -import { DeviceCommunicationError, DeviceType } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { RequestConfig } from "Core/device/types/mudita-os" import { DeviceStrategy } from "Core/device/strategies/device-strategy.class" import { BaseDevice } from "Core/device/modules/base-device" diff --git a/libs/core/device/modules/device.class.ts b/libs/core/device/modules/device.class.ts index 5982f9873a..242db6ff01 100644 --- a/libs/core/device/modules/device.class.ts +++ b/libs/core/device/modules/device.class.ts @@ -3,9 +3,10 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { DeviceType } from "device-protocol/models" import { ResultObject } from "Core/core/builder" import { RequestConfig, Response } from "Core/device/types/mudita-os" -import { DeviceCommunicationEvent, DeviceType } from "Core/device/constants" +import { DeviceCommunicationEvent } from "Core/device/constants" export interface DeviceFactoryClass { path: string diff --git a/libs/core/device/modules/mock-core-device.ts b/libs/core/device/modules/mock-core-device.ts index c3e9b1e8ec..a854941648 100644 --- a/libs/core/device/modules/mock-core-device.ts +++ b/libs/core/device/modules/mock-core-device.ts @@ -5,7 +5,8 @@ import { PortInfo } from "serialport" import { Result, ResultObject } from "Core/core/builder" -import { DeviceCommunicationError, DeviceType } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { RequestConfig } from "Core/device/types/mudita-os" import { BaseDevice } from "Core/device/modules/base-device" import { AppError } from "Core/core/errors" diff --git a/libs/core/device/modules/mudita-os/adapters/serial-port-device.adapters.ts b/libs/core/device/modules/mudita-os/adapters/serial-port-device.adapters.ts index 7669216775..1faaace478 100644 --- a/libs/core/device/modules/mudita-os/adapters/serial-port-device.adapters.ts +++ b/libs/core/device/modules/mudita-os/adapters/serial-port-device.adapters.ts @@ -8,7 +8,8 @@ import { ipcMain } from "electron-better-ipc" import { log, LogConfig } from "Core/core/decorators/log.decorator" import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" -import { CONNECTION_TIME_OUT_MS, Endpoint } from "Core/device/constants" +import { Endpoint } from "core-device/models" +import { CONNECTION_TIME_OUT_MS } from "Core/device/constants" import { DeviceCommunicationEvent, ResponseStatus } from "Core/device/constants" import { DeviceError } from "Core/device/modules/mudita-os/constants" import { SerialPortParser } from "Core/device/modules/mudita-os/parsers" diff --git a/libs/core/device/reducers/device.interface.ts b/libs/core/device/reducers/device.interface.ts index d6d8cb5246..d93cc9309f 100644 --- a/libs/core/device/reducers/device.interface.ts +++ b/libs/core/device/reducers/device.interface.ts @@ -3,7 +3,9 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { CaseColour, DeviceType, OnboardingState } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" +import { OnboardingState } from "Core/device/constants" import { SimCard } from "Core/__deprecated__/renderer/models/basic-info/basic-info.typings" export interface KompaktDeviceData { diff --git a/libs/core/device/reducers/device.reducer.ts b/libs/core/device/reducers/device.reducer.ts index 83bc95072a..ef8cf7297f 100644 --- a/libs/core/device/reducers/device.reducer.ts +++ b/libs/core/device/reducers/device.reducer.ts @@ -4,11 +4,11 @@ */ import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" import { loadDeviceData, loadStorageInfoAction, setCriticalBatteryLevelStatus, - setInitState, setLockTime, setOnboardingStatus, setRestartingStatus, @@ -17,6 +17,7 @@ import { import { DeviceState } from "Core/device/reducers/device.interface" import { AppError } from "Core/core/errors" import { getOnboardingStatus } from "Core/device/actions/get-onboarding-status.action" +import { pendingAction } from "Core/__deprecated__/renderer/store/helpers" export const initialState: DeviceState = { deviceType: null, @@ -36,7 +37,7 @@ export const deviceReducer = createReducer( initialState, (builder) => { builder - .addCase(setInitState, () => { + .addCase(pendingAction(DeviceManagerEvent.DeactivateDevice), () => { return { ...initialState, } diff --git a/libs/core/device/requests/unlock-device-status.request.ts b/libs/core/device/requests/unlock-device-status.request.ts index 5f9cab17e3..08ea5c7834 100644 --- a/libs/core/device/requests/unlock-device-status.request.ts +++ b/libs/core/device/requests/unlock-device-status.request.ts @@ -4,8 +4,9 @@ */ import { ipcRenderer } from "electron-better-ipc" +import { DeviceCommunicationError } from "core-device/models" import { ResultObject } from "Core/core/builder" -import { DeviceCommunicationError, IpcDeviceEvent } from "Core/device/constants" +import { IpcDeviceEvent } from "Core/device/constants" import { DeviceId } from "Core/device/constants/device-id" export const unlockDeviceStatusRequest = async ( diff --git a/libs/core/device/selectors/device-type.selector.ts b/libs/core/device/selectors/device-type.selector.ts index 6f853c6531..f2ede3ab7a 100644 --- a/libs/core/device/selectors/device-type.selector.ts +++ b/libs/core/device/selectors/device-type.selector.ts @@ -4,7 +4,7 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { deviceStateSelector } from "Core/device/selectors/device-state.selector" export const deviceTypeSelector = createSelector( diff --git a/libs/core/device-manager/selectors/is-active-device-processing.selector.ts b/libs/core/device/selectors/is-active-device-processing.selector.ts similarity index 89% rename from libs/core/device-manager/selectors/is-active-device-processing.selector.ts rename to libs/core/device/selectors/is-active-device-processing.selector.ts index 24f51c2e93..05bdf84f61 100644 --- a/libs/core/device-manager/selectors/is-active-device-processing.selector.ts +++ b/libs/core/device/selectors/is-active-device-processing.selector.ts @@ -4,8 +4,8 @@ */ import { createSelector } from "@reduxjs/toolkit" +import { isActiveDeviceSet } from "device-manager/feature" import { backupStateSelector } from "Core/backup" -import { isActiveDeviceSet } from "Core/device-manager/selectors/is-active-device-set.selector" import { updateStateSelector } from "Core/update/selectors/update-state-selector" import { State } from "Core/core/constants" diff --git a/libs/core/device/services/device.service.ts b/libs/core/device/services/device.service.ts index 30eb1bf4e4..1951b61e8c 100644 --- a/libs/core/device/services/device.service.ts +++ b/libs/core/device/services/device.service.ts @@ -4,19 +4,15 @@ */ import { Result, ResultObject } from "Core/core/builder" -import { - DeviceCommunicationError, - Endpoint, - Method, - PhoneLockCategory, -} from "Core/device/constants" +import { PhoneLockCategory } from "Core/device/constants" +import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { PhoneLockTime } from "Core/device/dto" import { GetPhoneLockTimeResponseBody } from "Core/device/types/mudita-os" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" export class DeviceService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} public async unlock( code: string, diff --git a/libs/core/device/strategies/device-strategy.class.ts b/libs/core/device/strategies/device-strategy.class.ts index 8d50e9af67..5f42edcfa2 100644 --- a/libs/core/device/strategies/device-strategy.class.ts +++ b/libs/core/device/strategies/device-strategy.class.ts @@ -5,7 +5,7 @@ import { RequestConfig } from "Core/device/types/mudita-os" import { ResultObject } from "Core/core/builder" -import { DeviceCommunicationError } from "Core/device" +import { DeviceCommunicationError } from "core-device/models" export interface DeviceStrategy { connect(): Promise> diff --git a/libs/core/device/strategies/harmony.strategy.ts b/libs/core/device/strategies/harmony.strategy.ts index 048d917586..fb32efacab 100644 --- a/libs/core/device/strategies/harmony.strategy.ts +++ b/libs/core/device/strategies/harmony.strategy.ts @@ -14,7 +14,7 @@ import { import { Result, ResultObject } from "Core/core/builder" import { BaseAdapter } from "Core/device/modules/base.adapter" import { AppError } from "Core/core/errors" -import { DeviceCommunicationError } from "Core/device" +import { DeviceCommunicationError } from "core-device/models" export class HarmonyStrategy implements DeviceStrategy { constructor(private adapter: BaseAdapter) { diff --git a/libs/core/device/strategies/pure.strategy.ts b/libs/core/device/strategies/pure.strategy.ts index 4965f7f869..4564a885af 100644 --- a/libs/core/device/strategies/pure.strategy.ts +++ b/libs/core/device/strategies/pure.strategy.ts @@ -4,7 +4,7 @@ */ import { callRenderer } from "shared/utils" -import { DeviceCommunicationError } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" import { RequestConfig } from "Core/device/types/mudita-os" import { RequestResponse, diff --git a/libs/core/device/types/mudita-os/request-config.type.ts b/libs/core/device/types/mudita-os/request-config.type.ts index 29fa4bf9b4..d13467ba08 100644 --- a/libs/core/device/types/mudita-os/request-config.type.ts +++ b/libs/core/device/types/mudita-os/request-config.type.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Endpoint, Method } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" export interface RequestConfigOptions { connectionTimeOut?: number diff --git a/libs/core/device/types/mudita-os/response.type.ts b/libs/core/device/types/mudita-os/response.type.ts index a111d596b1..a53741f744 100644 --- a/libs/core/device/types/mudita-os/response.type.ts +++ b/libs/core/device/types/mudita-os/response.type.ts @@ -3,7 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { ResponseStatus, Endpoint } from "Core/device/constants" +import { Endpoint } from "core-device/models" +import { ResponseStatus } from "Core/device/constants" import { ResponseError } from "Core/device/types/mudita-os/response-error.type" export interface Response { diff --git a/libs/core/device/types/mudita-os/serialport-request.type.ts b/libs/core/device/types/mudita-os/serialport-request.type.ts index ae406173d5..8cf57d0561 100644 --- a/libs/core/device/types/mudita-os/serialport-request.type.ts +++ b/libs/core/device/types/mudita-os/serialport-request.type.ts @@ -3,10 +3,10 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { CaseColour } from "core-device/models" +import { Endpoint, Method } from "core-device/models" import { BackupCategory, - Method, - Endpoint, BackupState, BatteryState, SIM, @@ -14,7 +14,6 @@ import { Tray, AccessTechnology, NetworkStatus, - CaseColour, DiagnosticsFileList, PhoneLockCategory, MessageType, diff --git a/libs/core/device/types/serial-port-device.type.ts b/libs/core/device/types/serial-port-device.type.ts index d907fe1662..b3472a07c9 100644 --- a/libs/core/device/types/serial-port-device.type.ts +++ b/libs/core/device/types/serial-port-device.type.ts @@ -3,8 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { DeviceType } from "device-protocol/models" import { DeviceEvent } from "Core/device/constants" -import { DeviceType } from "Core/device/constants" import { RequestConfig, Response } from "Core/device/types/mudita-os" export interface SerialPortDevice { diff --git a/libs/core/discovery-device/components/available-device-list.component.tsx b/libs/core/discovery-device/components/available-device-list.component.tsx index 7af0e3a280..8483bca7f1 100644 --- a/libs/core/discovery-device/components/available-device-list.component.tsx +++ b/libs/core/discovery-device/components/available-device-list.component.tsx @@ -9,19 +9,21 @@ import styled from "styled-components" import { useHistory } from "react-router-dom" import { useDispatch, useSelector } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" -import { DeviceState } from "Core/device-manager/reducers/device-manager.interface" +import { DeviceState } from "core-device/models" import Text, { TextDisplayStyle, } from "Core/__deprecated__/renderer/components/core/text/text.component" import { fontWeight } from "Core/core/styles/theming/theme-getters" import DeviceList from "Core/discovery-device/components/device-list.component" import { Dispatch } from "Core/__deprecated__/renderer/store" -import { getAvailableDevicesSelector } from "Core/device-manager/selectors/get-available-devices.selector" +import { + getAvailableDevicesSelector, + handleDeviceActivated, +} from "device-manager/feature" import { URL_DEVICE_INITIALIZATION, URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" -import { handleDeviceActivated } from "Core/device-manager/actions/handle-device-activated.action" const messages = defineMessages({ headerTitle: { id: "module.availableDeviceList.headerTitle" }, diff --git a/libs/core/discovery-device/components/available-device-list.container.tsx b/libs/core/discovery-device/components/available-device-list.container.tsx index dc51c25840..e3d5764622 100644 --- a/libs/core/discovery-device/components/available-device-list.container.tsx +++ b/libs/core/discovery-device/components/available-device-list.container.tsx @@ -8,7 +8,7 @@ import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" import { FunctionComponent } from "Core/core/types/function-component.interface" import AvailableDeviceList from "Core/discovery-device/components/available-device-list.component" -import { getDevicesSelector } from "Core/device-manager/selectors/get-devices.selector" +import { getDevicesSelector } from "device-manager/feature" import { Dispatch } from "Core/__deprecated__/renderer/store" import { URL_MAIN } from "Core/__deprecated__/renderer/constants/urls" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" diff --git a/libs/core/discovery-device/components/configured-devices-discovery.component.tsx b/libs/core/discovery-device/components/configured-devices-discovery.component.tsx index 028ceba43a..0830a7d35f 100644 --- a/libs/core/discovery-device/components/configured-devices-discovery.component.tsx +++ b/libs/core/discovery-device/components/configured-devices-discovery.component.tsx @@ -10,8 +10,12 @@ import { FunctionComponent } from "Core/core/types/function-component.interface" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" -import { getDevicesSelector } from "Core/device-manager/selectors/get-devices.selector" -import { handleDeviceActivated } from "Core/device-manager/actions/handle-device-activated.action" +import { + getDevicesSelector, + getAvailableDevicesSelector, + getFailedDevicesSelector, + handleDeviceActivated, +} from "device-manager/feature" import { Dispatch } from "Core/__deprecated__/renderer/store" import { URL_DEVICE_INITIALIZATION, @@ -19,8 +23,6 @@ import { URL_MAIN, URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" -import { getAvailableDevicesSelector } from "Core/device-manager/selectors/get-available-devices.selector" -import { getFailedDevicesSelector } from "Core/device-manager/selectors/get-failed-devices.selector" import { useNoNewDevicesDetectedHook } from "Core/discovery-device/hooks/use-no-new-devices-detected.hook" const ConfiguredDevicesDiscovery: FunctionComponent = () => { @@ -70,17 +72,22 @@ const ConfiguredDevicesDiscovery: FunctionComponent = () => { noNewDevicesDetectedState, ]) - const isAnyDeviceAttachedOnInitialRender = useRef(undefined) + const isAnyDeviceAttachedOnInitialRender = useRef( + undefined + ) useEffect(() => { - if(isAnyDeviceAttachedOnInitialRender.current !== undefined){ + if (isAnyDeviceAttachedOnInitialRender.current !== undefined) { return } - isAnyDeviceAttachedOnInitialRender.current = devices.length > 0; + isAnyDeviceAttachedOnInitialRender.current = devices.length > 0 }, [devices]) useEffect(() => { - if(!isAnyDeviceAttachedOnInitialRender.current && noNewDevicesDetectedState){ + if ( + !isAnyDeviceAttachedOnInitialRender.current && + noNewDevicesDetectedState + ) { history.push(URL_ONBOARDING.troubleshooting) return } diff --git a/libs/core/discovery-device/components/device-connecting.component.tsx b/libs/core/discovery-device/components/device-connecting.component.tsx index a26906ab88..093a498625 100644 --- a/libs/core/discovery-device/components/device-connecting.component.tsx +++ b/libs/core/discovery-device/components/device-connecting.component.tsx @@ -10,14 +10,13 @@ import { delay } from "shared/utils" import { FunctionComponent } from "Core/core/types/function-component.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" import { TmpDispatch } from "Core/__deprecated__/renderer/store" -import { activeDeviceIdSelector } from "Core/device-manager/selectors/active-device-id.selector" +import { activeDeviceIdSelector, connectDevice } from "device-manager/feature" import { URL_DEVICE_INITIALIZATION, URL_DISCOVERY_DEVICE, URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" -import { connectDevice } from "Core/device-manager/actions/connect-device.action" -import { configureDevice } from "Core/device-manager/actions/configure-device.action" +import { configureDevice } from "core-device/feature" const DeviceConnecting: FunctionComponent = () => { const history = useHistory() diff --git a/libs/core/discovery-device/components/device-list-item.component.tsx b/libs/core/discovery-device/components/device-list-item.component.tsx index a2fd02f890..b2a251704a 100644 --- a/libs/core/discovery-device/components/device-list-item.component.tsx +++ b/libs/core/discovery-device/components/device-list-item.component.tsx @@ -7,7 +7,7 @@ import React from "react" import { defineMessages } from "react-intl" import styled, { css } from "styled-components" import { FunctionComponent } from "Core/core/types/function-component.interface" -import { Device } from "Core/device-manager/reducers/device-manager.interface" +import { Device } from "core-device/models" import { backgroundColor, borderColor, @@ -20,7 +20,7 @@ import Text, { TextDisplayStyle, } from "Core/__deprecated__/renderer/components/core/text/text.component" import { intl } from "Core/__deprecated__/renderer/utils/intl" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { getSerialNumberValue } from "Core/utils/get-serial-number-value" import { getDeviceTypeName } from "Core/discovery-device/utils/get-device-type-name" diff --git a/libs/core/discovery-device/components/device-list.component.tsx b/libs/core/discovery-device/components/device-list.component.tsx index 9964a060ae..3c14579b2b 100644 --- a/libs/core/discovery-device/components/device-list.component.tsx +++ b/libs/core/discovery-device/components/device-list.component.tsx @@ -6,7 +6,7 @@ import React from "react" import styled from "styled-components" import { FunctionComponent } from "Core/core/types/function-component.interface" -import { Device } from "Core/device-manager/reducers/device-manager.interface" +import { Device } from "core-device/models" import DeviceListItem from "Core/discovery-device/components/device-list-item.component" interface Props { @@ -19,14 +19,15 @@ const Wrapper = styled.div` overflow: auto; ` const gridColumnsMap: Record = { - 1: 'repeat(1, minmax(0, 34rem))', - 2: 'repeat(2, minmax(0, 34rem))', - default: 'repeat(3, minmax(0, 34rem))', -}; + 1: "repeat(1, minmax(0, 34rem))", + 2: "repeat(2, minmax(0, 34rem))", + default: "repeat(3, minmax(0, 34rem))", +} const Container = styled.div<{ devicesLength: number }>` display: grid; - grid-template-columns: ${({ devicesLength }) => gridColumnsMap[devicesLength] || gridColumnsMap.default}; + grid-template-columns: ${({ devicesLength }) => + gridColumnsMap[devicesLength] || gridColumnsMap.default}; gap: 2.6rem; justify-content: center; max-width: 107.2rem; diff --git a/libs/core/discovery-device/hooks/use-no-new-devices-detected.hook.ts b/libs/core/discovery-device/hooks/use-no-new-devices-detected.hook.ts index 7840beba05..665075165d 100644 --- a/libs/core/discovery-device/hooks/use-no-new-devices-detected.hook.ts +++ b/libs/core/discovery-device/hooks/use-no-new-devices-detected.hook.ts @@ -4,7 +4,8 @@ */ import { useEffect, useState } from "react" -import { answerMain, DeviceManagerMainEvent } from "shared/utils" +import { answerMain } from "shared/utils" +import { DeviceProtocolMainEvent } from "device-protocol/models" export const useNoNewDevicesDetectedHook = () => { const [noNewDevicesDetectedState, setNoNewDevicesDetectedState] = @@ -22,7 +23,7 @@ export const useNoNewDevicesDetectedHook = () => { } handler() const unregisterDeviceConnectedListener = answerMain( - DeviceManagerMainEvent.DeviceConnected, + DeviceProtocolMainEvent.DeviceConnected, handler ) return () => { diff --git a/libs/core/discovery-device/utils/get-device-type-name.ts b/libs/core/discovery-device/utils/get-device-type-name.ts index 95286f7f14..6190f505b3 100644 --- a/libs/core/discovery-device/utils/get-device-type-name.ts +++ b/libs/core/discovery-device/utils/get-device-type-name.ts @@ -3,7 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { CaseColour, DeviceType } from "Core/device" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" export const DeviceNames = { Pure: "Pure", diff --git a/libs/core/files-manager/actions/base.action.ts b/libs/core/files-manager/actions/base.action.ts index 458fd9d0e6..d3d293494f 100644 --- a/libs/core/files-manager/actions/base.action.ts +++ b/libs/core/files-manager/actions/base.action.ts @@ -8,10 +8,6 @@ import { State } from "Core/core/constants" import { FilesManagerEvent } from "Core/files-manager/constants" import { SoundApp } from "Core/files-manager/reducers" -export const setInitialFilesManagerState = createAction( - FilesManagerEvent.SetInitialFilesManagerState -) - export const setUploadingState = createAction( FilesManagerEvent.SetUploadingState ) diff --git a/libs/core/files-manager/actions/get-files.action.ts b/libs/core/files-manager/actions/get-files.action.ts index ce66d8307c..daeb9faca6 100644 --- a/libs/core/files-manager/actions/get-files.action.ts +++ b/libs/core/files-manager/actions/get-files.action.ts @@ -12,9 +12,10 @@ import { } from "Core/files-manager/constants" import { getFilesRequest } from "Core/files-manager/requests/get-files.request" import { File } from "Core/files-manager/dto" -import { DeviceType, loadDeviceData } from "Core/device" +import { loadDeviceData } from "Core/device" +import { DeviceType } from "device-protocol/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { getActiveDeviceTypeSelector } from "Core/device-manager/selectors/get-active-device-type.selector" +import { getActiveDeviceTypeSelector } from "device-manager/feature" import { FilesManagerState, SoundApp } from "Core/files-manager/reducers" export const getFiles = createAsyncThunk< diff --git a/libs/core/files-manager/constants/event.enum.ts b/libs/core/files-manager/constants/event.enum.ts index a7eb5ffb67..a6bc314951 100644 --- a/libs/core/files-manager/constants/event.enum.ts +++ b/libs/core/files-manager/constants/event.enum.ts @@ -4,7 +4,6 @@ */ export enum FilesManagerEvent { - SetInitialFilesManagerState = "SET_INITIAL_FILES_MANAGER_STATE", GetFiles = "FILES_MANAGER_GET_FILES", SetFiles = "FILES_MANAGER_SET_FILES", SelectAllItems = "FILES_MANAGER_SELECT_ALL", diff --git a/libs/core/files-manager/files-manager.module.ts b/libs/core/files-manager/files-manager.module.ts index eb548b737d..abc48dc91b 100644 --- a/libs/core/files-manager/files-manager.module.ts +++ b/libs/core/files-manager/files-manager.module.ts @@ -17,14 +17,14 @@ import { FileUploadCommand, } from "Core/device-file-system/commands" import { FileDeleteCommand } from "Core/device-file-system/commands/file-delete.command" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class FilesManagerModule extends BaseModule { private readonly filesManagerController: FilesManagerController constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/files-manager/reducers/files-manager.reducer.ts b/libs/core/files-manager/reducers/files-manager.reducer.ts index 80dedd5697..8890d3a639 100644 --- a/libs/core/files-manager/reducers/files-manager.reducer.ts +++ b/libs/core/files-manager/reducers/files-manager.reducer.ts @@ -4,6 +4,7 @@ */ import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" import { @@ -22,12 +23,12 @@ import { resetUploadingStateAfterSuccess, resetFiles, setInvalidFiles, - setInitialFilesManagerState, setActiveSoundApp, } from "Core/files-manager/actions" import { changeLocation } from "Core/core/actions" import { FilesManagerState } from "Core/files-manager/reducers/files-manager.interface" import { deleteFiles } from "Core/files-manager/actions/delete-files.action" +import { pendingAction } from "Core/__deprecated__/renderer/store/helpers" export const initialState: FilesManagerState = { filesMap: { @@ -52,7 +53,7 @@ export const filesManagerReducer = createReducer( initialState, (builder) => { builder - .addCase(setInitialFilesManagerState, () => { + .addCase(pendingAction(DeviceManagerEvent.DeactivateDevice), () => { return { ...initialState } }) .addCase(getFiles.pending, (state) => { diff --git a/libs/core/files-manager/selectors/is-dettached-during-upload-error.selector.ts b/libs/core/files-manager/selectors/is-dettached-during-upload-error.selector.ts index 3da8b62202..69056f594c 100644 --- a/libs/core/files-manager/selectors/is-dettached-during-upload-error.selector.ts +++ b/libs/core/files-manager/selectors/is-dettached-during-upload-error.selector.ts @@ -6,7 +6,7 @@ import { createSelector } from "@reduxjs/toolkit" import { getFilesManager } from "Core/files-manager/selectors/get-files-manager.selector" import { State } from "Core/core/constants" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" +import { getActiveDevice } from "device-manager/feature" export const isDettachedDuringUploadErrorSelector = createSelector( getFilesManager, diff --git a/libs/core/index-storage/index-storage.module.ts b/libs/core/index-storage/index-storage.module.ts index 15eee2bf99..1abf93dc27 100644 --- a/libs/core/index-storage/index-storage.module.ts +++ b/libs/core/index-storage/index-storage.module.ts @@ -11,7 +11,7 @@ import { FileSystemService } from "Core/file-system/services/file-system.service import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { IndexStorageService } from "Core/index-storage/services" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { IndexStorageController } from "Core/index-storage/controllers" export class IndexStorageModule extends BaseModule { @@ -20,7 +20,7 @@ export class IndexStorageModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/messages/actions/base.action.ts b/libs/core/messages/actions/base.action.ts index af31f7f0b2..ab3316ad8d 100644 --- a/libs/core/messages/actions/base.action.ts +++ b/libs/core/messages/actions/base.action.ts @@ -7,10 +7,6 @@ import { createAction } from "@reduxjs/toolkit" import { MessagesEvent } from "Core/messages/constants" import { MessagesState } from "Core/messages/reducers" -export const setInitialMessagesState = createAction( - MessagesEvent.SetInitialMessagesState -) - export const changeVisibilityFilter = createAction< MessagesState["data"]["visibilityFilter"] >(MessagesEvent.ChangeVisibilityFilter) diff --git a/libs/core/messages/actions/update-message.action.test.ts b/libs/core/messages/actions/update-message.action.test.ts index fa7859d721..47c5cddea9 100644 --- a/libs/core/messages/actions/update-message.action.test.ts +++ b/libs/core/messages/actions/update-message.action.test.ts @@ -7,7 +7,7 @@ import createMockStore from "redux-mock-store" import thunk from "redux-thunk" import { AnyAction } from "@reduxjs/toolkit" import { Result, ResultObject } from "Core/core/builder" -import { DeviceCommunicationError } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" import { updateMessage } from "Core/messages/actions/update-message.action" import { updateMessageRequest } from "Core/messages/requests" import { testError } from "Core/__deprecated__/renderer/store/constants" diff --git a/libs/core/messages/constants/event.enum.ts b/libs/core/messages/constants/event.enum.ts index e19898ffaf..2b822c1b70 100644 --- a/libs/core/messages/constants/event.enum.ts +++ b/libs/core/messages/constants/event.enum.ts @@ -4,8 +4,6 @@ */ export enum MessagesEvent { - SetInitialMessagesState = "SET_INITIAL_MESSAGES_STATE", - ToggleThreadsReadStatus = "TOGGLE_THREADS_READ_STATUS", MarkThreadsReadStatus = "MARK_THREADS_READ_STATUS", diff --git a/libs/core/messages/message.module.ts b/libs/core/messages/message.module.ts index cba023a126..657e5ff2ed 100644 --- a/libs/core/messages/message.module.ts +++ b/libs/core/messages/message.module.ts @@ -14,12 +14,12 @@ import { MessageModel, ThreadModel } from "Core/messages/models" import { MessageService, ThreadService } from "Core/messages/services" import { MessageController, ThreadController } from "Core/messages/controllers" import { MessageRepository, ThreadRepository } from "Core/messages/repositories" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class MessageModule extends BaseModule { constructor( public index: IndexStorage, - public deviceModule: DeviceManager, + public deviceModule: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/messages/reducers/messages.reducer.ts b/libs/core/messages/reducers/messages.reducer.ts index 40c0561840..2a29a2540d 100644 --- a/libs/core/messages/reducers/messages.reducer.ts +++ b/libs/core/messages/reducers/messages.reducer.ts @@ -6,6 +6,7 @@ // TODO: CP-1494, CP-1495 import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" import { fulfilledAction, pendingAction, @@ -43,7 +44,6 @@ import assert from "assert" import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" import { search, searchPreview } from "Core/search/actions/search.action" -import { setInitialMessagesState } from "Core/messages/actions/base.action" export const initialState: MessagesState = { data: { @@ -67,7 +67,7 @@ export const messagesReducer = createReducer( initialState, (builder) => { builder - .addCase(setInitialMessagesState, (state) => { + .addCase(pendingAction(DeviceManagerEvent.DeactivateDevice), () => { return { ...initialState } }) .addCase( diff --git a/libs/core/messages/services/message.service.test.ts b/libs/core/messages/services/message.service.test.ts index 8dd00e7071..ddcd4f3e99 100644 --- a/libs/core/messages/services/message.service.test.ts +++ b/libs/core/messages/services/message.service.test.ts @@ -6,12 +6,11 @@ import { Result } from "Core/core/builder" import { Message as PureMessage } from "Core/device/types/mudita-os" import { - Endpoint, - Method, MessagesCategory as PureMessagesCategory, MessageType, MessageType as PureMessageType, } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" import { ErrorRequestResponse, RequestResponseStatus, @@ -25,7 +24,7 @@ import { import { MessageRepository } from "Core/messages/repositories" import { MessageService } from "Core/messages/services/message.service" import { ThreadService } from "Core/messages/services/thread.service" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import assert from "assert" import { MessageType as MessageTypeFromDTO } from "Core/messages/constants" @@ -33,7 +32,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const threadService = { getThreads: jest.fn(), diff --git a/libs/core/messages/services/message.service.ts b/libs/core/messages/services/message.service.ts index 127f4fdc78..a15e14dce6 100644 --- a/libs/core/messages/services/message.service.ts +++ b/libs/core/messages/services/message.service.ts @@ -5,11 +5,10 @@ import { ResultObject } from "Core/core/builder" import { - Endpoint, - Method, MessagesCategory as PureMessagesCategory, MessageType as PureMessageType, } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" import { GetMessagesRequestConfig as PureGetMessagesBody, Message as PureMessage, @@ -31,7 +30,7 @@ import { } from "Core/messages/presenters" import { MessageRepository } from "Core/messages/repositories" import { ThreadService } from "Core/messages/services/thread.service" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { mapToRawNumber, splitMessageByBytesSize } from "Core/messages/helpers" export interface GetMessagesByThreadIdResponse { @@ -50,7 +49,7 @@ export interface CreateMessageDataResponse { export class MessageService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private threadService: ThreadService, private messageRepository: MessageRepository ) {} diff --git a/libs/core/messages/services/thread.service.test.ts b/libs/core/messages/services/thread.service.test.ts index f3d61b6e98..ab067dfa8a 100644 --- a/libs/core/messages/services/thread.service.test.ts +++ b/libs/core/messages/services/thread.service.test.ts @@ -5,14 +5,14 @@ import { ResultObject, Result } from "Core/core/builder" import { AppError } from "Core/core/errors" -import { DeviceCommunicationError } from "Core/device/constants" +import { DeviceCommunicationError } from "core-device/models" import { Thread as PureThread } from "Core/device/types/mudita-os" import { RequestResponseStatus, SuccessRequestResponse, } from "Core/core/types/request-response.interface" import { ThreadService } from "Core/messages/services/thread.service" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { ThreadPresenter } from "Core/messages/presenters" import { ThreadRepository } from "Core/messages/repositories" import { Thread } from "Core/messages/dto" @@ -22,7 +22,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const threadRepository = { create: jest.fn(), diff --git a/libs/core/messages/services/thread.service.ts b/libs/core/messages/services/thread.service.ts index fa884ef108..a8abb73126 100644 --- a/libs/core/messages/services/thread.service.ts +++ b/libs/core/messages/services/thread.service.ts @@ -4,18 +4,15 @@ */ import { Thread } from "Core/messages/dto" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { GetThreadsRequestConfig, PaginationBody, GetThreadResponseBody, GetThreadsResponseBody, } from "Core/device/types/mudita-os" -import { - Endpoint, - Method, - MessagesCategory as PureMessagesCategory, -} from "Core/device/constants" +import { MessagesCategory as PureMessagesCategory } from "Core/device/constants" +import { Endpoint, Method } from "core-device/models" import { RequestResponse, RequestResponseStatus, @@ -32,7 +29,7 @@ export interface GetThreadsResponse { export class ThreadService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private threadRepository: ThreadRepository ) {} diff --git a/libs/core/modals-manager/components/connecting-loader-modal.component.tsx b/libs/core/modals-manager/components/connecting-loader-modal.component.tsx index acec89e9ab..80f0f6bb5a 100644 --- a/libs/core/modals-manager/components/connecting-loader-modal.component.tsx +++ b/libs/core/modals-manager/components/connecting-loader-modal.component.tsx @@ -7,7 +7,9 @@ import React, { useEffect, useState } from "react" import { useDispatch, useSelector } from "react-redux" import { defineMessages } from "react-intl" import { useHistory } from "react-router-dom" -import { answerMain, DeviceManagerMainEvent } from "shared/utils" +import { answerMain } from "shared/utils" +import { setSelectDeviceDrawerOpen } from "device-manager/feature" +import { DeviceProtocolMainEvent } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import { intl } from "Core/__deprecated__/renderer/utils/intl" import LoaderModal from "Core/ui/components/loader-modal/loader-modal.component" @@ -16,7 +18,6 @@ import { URL_DISCOVERY_DEVICE, URL_MAIN, } from "Core/__deprecated__/renderer/constants/urls" -import { setSelectDeviceDrawerOpen } from "Core/device-select/actions/set-select-device-drawer-open.action" import { getDiscoveryStatus } from "Core/discovery-device/selectors/get-discovery-status.selector" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" import { ModalLayers } from "Core/modals-manager/constants/modal-layers.enum" @@ -50,11 +51,11 @@ const ConnectingLoaderModal: FunctionComponent = () => { } const unregisterDeviceConnectedListener = answerMain( - DeviceManagerMainEvent.DeviceConnected, + DeviceProtocolMainEvent.DeviceConnected, handler ) const unregisterDeviceConnectFailedListener = answerMain( - DeviceManagerMainEvent.DeviceConnectFailed, + DeviceProtocolMainEvent.DeviceConnectFailed, handler ) diff --git a/libs/core/modals-manager/components/use-loader-skip-on-connect.hook.ts b/libs/core/modals-manager/components/use-loader-skip-on-connect.hook.ts index f8dd34b93a..4bf07d12ee 100644 --- a/libs/core/modals-manager/components/use-loader-skip-on-connect.hook.ts +++ b/libs/core/modals-manager/components/use-loader-skip-on-connect.hook.ts @@ -8,7 +8,7 @@ import { useSelector } from "react-redux" import { useHistory } from "react-router-dom" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" import { checkIsAnyOtherModalPresent } from "Core/utils/check-is-any-other-modal-present" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { isInitializationDeviceInProgress } from "Core/device-initialization/selectors/is-initialization-device-in-progress.selector" import { isInitializationAppInProgress } from "Core/app-initialization/selectors/is-initialization-app-in-progress.selector" import { useNoNewDevicesDetectedHook } from "Core/discovery-device/hooks/use-no-new-devices-detected.hook" diff --git a/libs/core/onboarding/components/onboarding-troubleshooting/onboarding-troubleshooting.component.tsx b/libs/core/onboarding/components/onboarding-troubleshooting/onboarding-troubleshooting.component.tsx index df9a872a94..c703e7487f 100644 --- a/libs/core/onboarding/components/onboarding-troubleshooting/onboarding-troubleshooting.component.tsx +++ b/libs/core/onboarding/components/onboarding-troubleshooting/onboarding-troubleshooting.component.tsx @@ -11,7 +11,7 @@ import OnboardingTroubleshootingUI from "Core/onboarding/components/onboarding-t import { FunctionComponent } from "Core/core/types/function-component.interface" import { TmpDispatch } from "Core/__deprecated__/renderer/store" import { ModalStateKey, showModal } from "Core/modals-manager" -import { getDevicesSelector } from "Core/device-manager/selectors/get-devices.selector" +import { getDevicesSelector } from "device-manager/feature" const OnboardingTroubleshooting: FunctionComponent = () => { const history = useHistory() diff --git a/libs/core/outbox/factories/outbox.factory.ts b/libs/core/outbox/factories/outbox.factory.ts index be868c8443..3b1edcb74f 100644 --- a/libs/core/outbox/factories/outbox.factory.ts +++ b/libs/core/outbox/factories/outbox.factory.ts @@ -5,7 +5,7 @@ import { EventEmitter } from "events" import { OutboxEntryType } from "Core/device/constants" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { IndexStorage } from "Core/index-storage/types" import { EntryHandlersMapType, @@ -25,7 +25,7 @@ export class OutboxFactory { static create( index: IndexStorage, eventEmitter: EventEmitter, - deviceManager: DeviceManager + deviceManager: DeviceProtocolService ): OutboxService { const contactModel = new ContactModel(index, eventEmitter) const contactRepository = new ContactRepository(contactModel) diff --git a/libs/core/outbox/outbox.module.ts b/libs/core/outbox/outbox.module.ts index ad1cd82e2d..08479b4381 100644 --- a/libs/core/outbox/outbox.module.ts +++ b/libs/core/outbox/outbox.module.ts @@ -11,13 +11,13 @@ import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { OutboxFactory } from "Core/outbox/factories" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { IndexStorageController } from "Core/outbox/controllers" export class OutboxModule extends BaseModule { constructor( public index: IndexStorage, - public deviceModule: DeviceManager, + public deviceModule: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/outbox/services/outbox.service.test.ts b/libs/core/outbox/services/outbox.service.test.ts index cfc0c70a70..0ee10c41d8 100644 --- a/libs/core/outbox/services/outbox.service.test.ts +++ b/libs/core/outbox/services/outbox.service.test.ts @@ -3,25 +3,21 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { Endpoint, Method } from "core-device/models" import { Result } from "Core/core/builder" import { EntryHandlersMapType, OutboxService, } from "Core/outbox/services/outbox.service" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { OutboxEntry } from "Core/device/types/mudita-os" -import { - OutboxEntryChange, - OutboxEntryType, - Endpoint, - Method, -} from "Core/device/constants" +import { OutboxEntryChange, OutboxEntryType } from "Core/device/constants" const deviceManager = { device: { request: jest.fn().mockResolvedValue(Result.success({ entries: [] })), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const entryHandlersMap = { [OutboxEntryType.Contact]: { handleEntry: jest.fn(), diff --git a/libs/core/outbox/services/outbox.service.ts b/libs/core/outbox/services/outbox.service.ts index 6b7d56f866..67cb50f1c1 100644 --- a/libs/core/outbox/services/outbox.service.ts +++ b/libs/core/outbox/services/outbox.service.ts @@ -3,19 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { Endpoint, Method } from "core-device/models" import { ResultObject } from "Core/core/builder" import { GetEntriesResponseBody, OutboxEntry, } from "Core/device/types/mudita-os" -import { - OutboxEntryType, - OutboxCategory, - Method, - Endpoint, -} from "Core/device/constants" +import { OutboxEntryType, OutboxCategory } from "Core/device/constants" import { asyncNoop } from "Core/__deprecated__/renderer/utils/noop" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { EntryHandler } from "Core/outbox/services/entry-handler.type" export type EntryHandlersMapType = Record @@ -24,7 +20,7 @@ export type EntryChangesEvent = { entry: OutboxEntry; payload: unknown } export class OutboxService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private entryHandlersMap: EntryHandlersMapType ) {} diff --git a/libs/core/overview/components/device-preview/device-image.component.tsx b/libs/core/overview/components/device-preview/device-image.component.tsx index 7a2e88486a..db1e460b7a 100644 --- a/libs/core/overview/components/device-preview/device-image.component.tsx +++ b/libs/core/overview/components/device-preview/device-image.component.tsx @@ -4,12 +4,16 @@ */ import React from "react" -import { DeviceType, CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import Image from "Core/__deprecated__/renderer/components/core/image/image.component" import { DeviceTestIds } from "Core/overview/components/device-preview/device-preview-test-ids.enum" -import PureGrayImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" -import PureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" +// TODO: fix imports +// import PureGrayImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" +// import PureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" +import PureGrayImage from "Core/__deprecated__/renderer/images/harmony-gray-render.png" +import PureBlackImage from "Core/__deprecated__/renderer/images/harmony-black-render.png" import KompaktBlackImage from "Core/__deprecated__/renderer/images/kompakt-black-render.png" import HarmonyGrayImage from "Core/__deprecated__/renderer/images/harmony-gray-render.png" import HarmonyBlackImage from "Core/__deprecated__/renderer/images/harmony-black-render.png" @@ -25,22 +29,37 @@ export const DeviceImage: FunctionComponent = ({ ...props }) => { if (deviceType === DeviceType.MuditaPure && caseColour === CaseColour.Black) { - return + return ( + + ) } if (deviceType === DeviceType.MuditaPure) { - return + return ( + + ) } - if (deviceType === DeviceType.MuditaHarmony && caseColour === CaseColour.Black) { - return + if ( + deviceType === DeviceType.MuditaHarmony && + caseColour === CaseColour.Black + ) { + return } if (deviceType === DeviceType.MuditaHarmony) { - return + return } if (deviceType === DeviceType.APIDevice) { - return + return } return <> diff --git a/libs/core/overview/components/device-preview/device-preview.component.tsx b/libs/core/overview/components/device-preview/device-preview.component.tsx index 1885201590..e94bcd8a5c 100644 --- a/libs/core/overview/components/device-preview/device-preview.component.tsx +++ b/libs/core/overview/components/device-preview/device-preview.component.tsx @@ -7,7 +7,7 @@ import React from "react" import styled from "styled-components" import { defineMessages } from "react-intl" import { useHistory } from "react-router-dom" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import { DevicePreviewProps } from "Core/overview/components/device-preview/device-preview.interface" import { intl } from "Core/__deprecated__/renderer/utils/intl" diff --git a/libs/core/overview/components/device-preview/device-preview.interface.tsx b/libs/core/overview/components/device-preview/device-preview.interface.tsx index d19ab0cac6..01e1d0b988 100644 --- a/libs/core/overview/components/device-preview/device-preview.interface.tsx +++ b/libs/core/overview/components/device-preview/device-preview.interface.tsx @@ -3,7 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType, CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" export interface DevicePreviewProps { onClick?: () => void diff --git a/libs/core/overview/components/device-preview/device-preview.stories.tsx b/libs/core/overview/components/device-preview/device-preview.stories.tsx index 029ca09b56..3d90a059eb 100644 --- a/libs/core/overview/components/device-preview/device-preview.stories.tsx +++ b/libs/core/overview/components/device-preview/device-preview.stories.tsx @@ -6,7 +6,7 @@ import React from "react" import styled from "styled-components" import { storiesOf } from "@storybook/react" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { DevicePreview } from "Core/overview/components/device-preview/device-preview.component" const Part = styled.div` diff --git a/libs/core/overview/components/device-preview/device-preview.test.tsx b/libs/core/overview/components/device-preview/device-preview.test.tsx index 7ba553ce0a..1011b330d1 100644 --- a/libs/core/overview/components/device-preview/device-preview.test.tsx +++ b/libs/core/overview/components/device-preview/device-preview.test.tsx @@ -7,7 +7,8 @@ import React, { ComponentProps } from "react" import { Provider } from "react-redux" import thunk from "redux-thunk" import createMockStore from "redux-mock-store" -import { CaseColour, DeviceType } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/render-with-theme-and-intl" import { DevicePreview } from "Core/overview/components/device-preview/device-preview.component" import { DeviceTestIds } from "Core/overview/components/device-preview/device-preview-test-ids.enum" diff --git a/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.interface.ts b/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.interface.ts index 47e60992e2..e638f67d2e 100644 --- a/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.interface.ts +++ b/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.interface.ts @@ -5,7 +5,8 @@ import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" -import { CaseColour, DeviceType } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { CheckForUpdateMode, DownloadState, diff --git a/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.test.tsx b/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.test.tsx index a89a147b69..ec2bc26ded 100644 --- a/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.test.tsx +++ b/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.test.tsx @@ -14,7 +14,7 @@ import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/rende import React, { ComponentProps } from "react" import { Provider } from "react-redux" import { CheckForUpdateState } from "Core/update/constants/check-for-update-state.constant" -import { CaseColour } from "Core/device" +import { CaseColour } from "core-device/models" jest.mock("Core/settings/store/schemas/generate-application-id", () => ({ generateApplicationId: () => "123", diff --git a/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx b/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx index dfc01fda2f..3095de6841 100644 --- a/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx +++ b/libs/core/overview/components/overview-screens/harmony-overview/harmony-overview.component.tsx @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { Feature, flags } from "Core/feature-flags" import { HarmonyOverviewProps } from "Core/overview/components/overview-screens/harmony-overview/harmony-overview.component.interface" import OverviewContent from "Core/overview/components/overview-screens/harmony-overview/overview-content.component" diff --git a/libs/core/overview/components/overview-screens/harmony-overview/overview-content.component.tsx b/libs/core/overview/components/overview-screens/harmony-overview/overview-content.component.tsx index f6e02e68fc..968d2eac3c 100644 --- a/libs/core/overview/components/overview-screens/harmony-overview/overview-content.component.tsx +++ b/libs/core/overview/components/overview-screens/harmony-overview/overview-content.component.tsx @@ -4,7 +4,8 @@ */ import React from "react" -import { CaseColour, DeviceType } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import { DeviceInfo, diff --git a/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx b/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx index 1caa02e1ae..3caa9d55a8 100644 --- a/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx +++ b/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.hook.tsx @@ -19,7 +19,7 @@ import { useEffect, useState } from "react" import { CheckForUpdateState } from "Core/update/constants/check-for-update-state.constant" import { useDispatch, useSelector } from "react-redux" import { checkForUpdate } from "Core/update/actions" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { areAllReleasesDownloaded } from "Core/update/selectors" interface Props { diff --git a/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx b/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx index db8182e970..c6b037568a 100644 --- a/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx +++ b/libs/core/overview/components/overview-screens/helpers/use-update-flow-state.test.tsx @@ -9,7 +9,9 @@ import { RenderOptions, renderHook, } from "@testing-library/react" -import { CaseColour, DeviceType, PureDeviceData } from "Core/device" +import { DeviceType } from "device-protocol/models" +import { CaseColour } from "core-device/models" +import { PureDeviceData } from "Core/device" import { CheckForUpdateLocalState } from "Core/overview/components/overview-screens/constants/overview.enum" import { useUpdateFlowState } from "Core/overview/components/overview-screens/helpers/use-update-flow-state.hook" import { diff --git a/libs/core/overview/components/overview-screens/helpers/use-watch-device-data-effect.ts b/libs/core/overview/components/overview-screens/helpers/use-watch-device-data-effect.ts index 27463f014b..d2eaa6f8e8 100644 --- a/libs/core/overview/components/overview-screens/helpers/use-watch-device-data-effect.ts +++ b/libs/core/overview/components/overview-screens/helpers/use-watch-device-data-effect.ts @@ -7,7 +7,7 @@ import { useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { Dispatch } from "Core/__deprecated__/renderer/store" import { loadDeviceData } from "Core/device/actions/load-device-data.action" -import { isActiveDeviceProcessingSelector } from "Core/device-manager/selectors/is-active-device-processing.selector" +import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" const deviceDataIntervalTime = 10000 diff --git a/libs/core/overview/components/overview-screens/kompakt-overview/kompakt-overview.component.interface.ts b/libs/core/overview/components/overview-screens/kompakt-overview/kompakt-overview.component.interface.ts index e0d4cd596a..98be94143e 100644 --- a/libs/core/overview/components/overview-screens/kompakt-overview/kompakt-overview.component.interface.ts +++ b/libs/core/overview/components/overview-screens/kompakt-overview/kompakt-overview.component.interface.ts @@ -8,7 +8,8 @@ import { Backup, RestoreBackup } from "Core/backup/dto" import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" import { SynchronizationStatus } from "Core/data-sync/reducers" -import { CaseColour, DeviceType } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { MemorySpace } from "Core/files-manager/components/files-manager-core/files-manager.interface" import { CheckForUpdateMode, diff --git a/libs/core/overview/components/overview-screens/pure-overview/overview-content.component.tsx b/libs/core/overview/components/overview-screens/pure-overview/overview-content.component.tsx index 5881360c3d..3fb991c1e4 100644 --- a/libs/core/overview/components/overview-screens/pure-overview/overview-content.component.tsx +++ b/libs/core/overview/components/overview-screens/pure-overview/overview-content.component.tsx @@ -4,7 +4,8 @@ */ import React from "react" -import { DeviceType, CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import { DeviceInfo, diff --git a/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.test.tsx b/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.test.tsx index 2b479f00ba..95073c607f 100644 --- a/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.test.tsx +++ b/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.test.tsx @@ -8,7 +8,7 @@ import { Provider } from "react-redux" import { ErrorSyncModalTestIds } from "Core/connecting/components/error-sync-modal/error-sync-modal-test-ids.enum" import { State } from "Core/core/constants" import { SynchronizationStatus } from "Core/data-sync/reducers" -import { CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" import { PureOverview } from "Core/overview/components/overview-screens/pure-overview/pure-overview.component" import { StatusTestIds } from "Core/overview/components/status/status-test-ids.enum" import { SystemTestIds } from "Core/overview/components/system/system-test-ids.enum" diff --git a/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.tsx b/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.tsx index 166dd61ac9..130275fca8 100644 --- a/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.tsx +++ b/libs/core/overview/components/overview-screens/pure-overview/pure-overview.component.tsx @@ -6,7 +6,7 @@ import ErrorSyncModal from "Core/connecting/components/error-sync-modal/error-sync-modal" import { State } from "Core/core/constants" import { SynchronizationStatus } from "Core/data-sync/reducers" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { Feature, flags } from "Core/feature-flags" import BackupDeviceFlow, { BackupDeviceFlowState, @@ -29,7 +29,7 @@ import { CheckForUpdateState } from "Core/update/constants/check-for-update-stat import { useWatchDeviceDataEffect } from "Core/overview/components/overview-screens/helpers/use-watch-device-data-effect" import { useDeactivateDeviceAndRedirect } from "Core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook" import { useSelector } from "react-redux" -import { isActiveDeviceAttachedSelector } from "Core/device-manager/selectors/is-active-device-attached.selector" +import { isActiveDeviceAttachedSelector } from "device-manager/feature" export const PureOverview: FunctionComponent = ({ batteryLevel = 0, diff --git a/libs/core/overview/components/overview-screens/pure-overview/pure-overview.interface.ts b/libs/core/overview/components/overview-screens/pure-overview/pure-overview.interface.ts index 5bad17825d..07df1d444b 100644 --- a/libs/core/overview/components/overview-screens/pure-overview/pure-overview.interface.ts +++ b/libs/core/overview/components/overview-screens/pure-overview/pure-overview.interface.ts @@ -8,7 +8,8 @@ import { Backup, RestoreBackup } from "Core/backup/dto" import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" import { SynchronizationStatus } from "Core/data-sync/reducers" -import { CaseColour, DeviceType } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { MemorySpace } from "Core/files-manager/components/files-manager-core/files-manager.interface" import { CheckForUpdateMode, diff --git a/libs/core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook.ts b/libs/core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook.ts index 8bb5e9a10d..6727292b7e 100644 --- a/libs/core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook.ts +++ b/libs/core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook.ts @@ -7,9 +7,10 @@ import { useHistory } from "react-router-dom" import { useDispatch, useSelector } from "react-redux" import { useCallback } from "react" import { TmpDispatch } from "Core/__deprecated__/renderer/store" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" +import { deactivateDevice } from "device-manager/feature" import { - URL_DISCOVERY_DEVICE, URL_ONBOARDING, + URL_DISCOVERY_DEVICE, + URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" import { selectDialogOpenState } from "shared/app-state" diff --git a/libs/core/overview/components/overview-screens/pure-overview/use-handle-active-device-aborted.hook.ts b/libs/core/overview/components/overview-screens/pure-overview/use-handle-active-device-aborted.hook.ts index 761970f48f..7e819b621f 100644 --- a/libs/core/overview/components/overview-screens/pure-overview/use-handle-active-device-aborted.hook.ts +++ b/libs/core/overview/components/overview-screens/pure-overview/use-handle-active-device-aborted.hook.ts @@ -7,7 +7,7 @@ import { useHistory } from "react-router-dom" import { useDispatch } from "react-redux" import { useCallback } from "react" import { TmpDispatch } from "Core/__deprecated__/renderer/store" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" +import { deactivateDevice } from "device-manager/feature" import { URL_DISCOVERY_DEVICE, URL_MAIN, diff --git a/libs/core/overview/components/overview/overview.component.tsx b/libs/core/overview/components/overview/overview.component.tsx index 3036f38739..5fe6b0bf0f 100644 --- a/libs/core/overview/components/overview/overview.component.tsx +++ b/libs/core/overview/components/overview/overview.component.tsx @@ -4,7 +4,7 @@ */ import React, { ComponentProps } from "react" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import { PureOverview, diff --git a/libs/core/overview/components/overview/overview.test.tsx b/libs/core/overview/components/overview/overview.test.tsx index 4462ac0d19..d4c63d8bbc 100644 --- a/libs/core/overview/components/overview/overview.test.tsx +++ b/libs/core/overview/components/overview/overview.test.tsx @@ -5,7 +5,8 @@ import React, { ComponentProps } from "react" import { Provider } from "react-redux" -import { DeviceType, CaseColour } from "Core/device/constants" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/render-with-theme-and-intl" import Overview from "Core/overview/components/overview/overview.component" import store from "Core/__deprecated__/renderer/store" diff --git a/libs/core/overview/components/status/status.component.tsx b/libs/core/overview/components/status/status.component.tsx index 1064427183..0ba911a609 100644 --- a/libs/core/overview/components/status/status.component.tsx +++ b/libs/core/overview/components/status/status.component.tsx @@ -4,7 +4,7 @@ */ import React from "react" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { defineMessages, FormattedMessage } from "react-intl" import styled from "styled-components" import { FunctionComponent } from "Core/core/types/function-component.interface" diff --git a/libs/core/overview/components/status/status.interface.tsx b/libs/core/overview/components/status/status.interface.tsx index 0676dd71e2..f9d0e57cd4 100644 --- a/libs/core/overview/components/status/status.interface.tsx +++ b/libs/core/overview/components/status/status.interface.tsx @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" export interface StatusProps { deviceType: DeviceType | null diff --git a/libs/core/overview/components/status/status.stories.tsx b/libs/core/overview/components/status/status.stories.tsx index 3e3191de70..f4f111268c 100644 --- a/libs/core/overview/components/status/status.stories.tsx +++ b/libs/core/overview/components/status/status.stories.tsx @@ -5,7 +5,7 @@ import { storiesOf } from "@storybook/react" import React from "react" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import Status from "Core/overview/components/status/status.component" import { css } from "styled-components" import StoryContainer from "Core/__deprecated__/renderer/components/storybook/story-container.component" diff --git a/libs/core/overview/components/status/status.test.tsx b/libs/core/overview/components/status/status.test.tsx index b06145a3de..f405717f2e 100644 --- a/libs/core/overview/components/status/status.test.tsx +++ b/libs/core/overview/components/status/status.test.tsx @@ -4,7 +4,7 @@ */ import React from "react" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/render-with-theme-and-intl" import { StatusProps } from "Core/overview/components/status/status.interface" import Status from "Core/overview/components/status/status.component" diff --git a/libs/core/overview/components/system/system.component.tsx b/libs/core/overview/components/system/system.component.tsx index dc140020de..52daa33307 100644 --- a/libs/core/overview/components/system/system.component.tsx +++ b/libs/core/overview/components/system/system.component.tsx @@ -20,7 +20,7 @@ import { FunctionComponent } from "Core/core/types/function-component.interface" import { noop } from "Core/__deprecated__/renderer/utils/noop" import React from "react" import { defineMessages, FormattedMessage } from "react-intl" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { useUpdateFlowState } from "../overview-screens/helpers/use-update-flow-state.hook" const messages = defineMessages({ diff --git a/libs/core/overview/components/system/system.stories.tsx b/libs/core/overview/components/system/system.stories.tsx index ccd6b1ff8d..1e600df1eb 100644 --- a/libs/core/overview/components/system/system.stories.tsx +++ b/libs/core/overview/components/system/system.stories.tsx @@ -10,7 +10,7 @@ import { action } from "@storybook/addon-actions" import { css } from "styled-components" import StoryContainer from "Core/__deprecated__/renderer/components/storybook/story-container.component" import Story from "Core/__deprecated__/renderer/components/storybook/story.component" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" const storyStyle = css` > * { diff --git a/libs/core/overview/components/system/system.test.tsx b/libs/core/overview/components/system/system.test.tsx index c7f855e0ff..528581fe23 100644 --- a/libs/core/overview/components/system/system.test.tsx +++ b/libs/core/overview/components/system/system.test.tsx @@ -10,7 +10,9 @@ import { renderWithThemeAndIntl } from "Core/__deprecated__/renderer/utils/rende import { intl } from "Core/__deprecated__/renderer/utils/intl" import System from "Core/overview/components/system/system.component" import { SystemTestIds } from "Core/overview/components/system/system-test-ids.enum" -import { CaseColour, DeviceType, PureDeviceData } from "Core/device" +import { PureDeviceData } from "Core/device" +import { CaseColour } from "core-device/models" +import { DeviceType } from "device-protocol/models" import { Provider } from "react-redux" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import createMockStore from "redux-mock-store" diff --git a/libs/core/overview/components/update-os-flow/update-os-flow.component.interface.ts b/libs/core/overview/components/update-os-flow/update-os-flow.component.interface.ts index 141833ac02..c28ad2b5a3 100644 --- a/libs/core/overview/components/update-os-flow/update-os-flow.component.interface.ts +++ b/libs/core/overview/components/update-os-flow/update-os-flow.component.interface.ts @@ -5,7 +5,7 @@ import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { ModalLayers } from "Core/modals-manager/constants/modal-layers.enum" import { DownloadState, diff --git a/libs/core/overview/components/update-os-flow/update-os-flow.component.test.tsx b/libs/core/overview/components/update-os-flow/update-os-flow.component.test.tsx index e47cb13f54..ce5c50b355 100644 --- a/libs/core/overview/components/update-os-flow/update-os-flow.component.test.tsx +++ b/libs/core/overview/components/update-os-flow/update-os-flow.component.test.tsx @@ -5,7 +5,7 @@ import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { UpdateOsFlow } from "Core/overview/components/update-os-flow" import { UpdateOsFlowTestIds } from "Core/overview/components/update-os-flow/update-os-flow-test-ids.enum" import { UpdateOsFlowProps } from "Core/overview/components/update-os-flow/update-os-flow.component.interface" diff --git a/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.component.tsx b/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.component.tsx index 7317934a36..e7072e5cbd 100644 --- a/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.component.tsx +++ b/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.component.tsx @@ -4,7 +4,7 @@ */ import { ModalText } from "Core/contacts/components/sync-contacts-modal/sync-contacts.styled" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { OSUpdateModal } from "Core/overview/components/update-os-modals/os-update-modal" import { TooLowBatteryModalProps } from "Core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.interface" import { RoundIconWrapper } from "Core/ui/components/modal-dialog" diff --git a/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.interface.ts b/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.interface.ts index 1a0187c6cf..79d8ce4f67 100644 --- a/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.interface.ts +++ b/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.interface.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { ModalDialogProps } from "Core/ui" export interface TooLowBatteryModalProps extends ModalDialogProps { diff --git a/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.stories.tsx b/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.stories.tsx index db1fc5fd4b..631bcc7f0b 100644 --- a/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.stories.tsx +++ b/libs/core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.stories.tsx @@ -8,7 +8,7 @@ import { Meta } from "@storybook/react" import Story from "Core/__deprecated__/renderer/components/storybook/story.component" import { action } from "@storybook/addon-actions" import { TooLowBatteryModal } from "Core/overview/components/update-os-modals/too-low-battery-modal/too-low-battery-modal.component" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" export const TooLowBatteryModalStory: FunctionComponent = () => { return ( diff --git a/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.component.test.tsx b/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.component.test.tsx index abd5781bcc..6dc6434028 100644 --- a/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.component.test.tsx +++ b/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.component.test.tsx @@ -5,7 +5,7 @@ import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { UpdatingForceModalFlowTestIds } from "Core/overview/components/updating-force-modal-flow/updating-force-modal-flow-test-ids.enum" import UpdatingForceModalFlow from "Core/overview/components/updating-force-modal-flow/updating-force-modal-flow.component" import { UpdatingForceModalFlowProps } from "Core/overview/components/updating-force-modal-flow/updating-force-modal-flow.interface" diff --git a/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.interface.ts b/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.interface.ts index 37306b1333..ca3c6b680d 100644 --- a/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.interface.ts +++ b/libs/core/overview/components/updating-force-modal-flow/updating-force-modal-flow.interface.ts @@ -5,7 +5,7 @@ import { State } from "Core/core/constants" import { AppError } from "Core/core/errors" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { ModalLayers } from "Core/modals-manager/constants/modal-layers.enum" import { UpdateError } from "Core/update/constants" import { OsRelease, ProcessedRelease } from "Core/update/dto" diff --git a/libs/core/overview/overview.container.tsx b/libs/core/overview/overview.container.tsx index f9d0070406..9d8eec781b 100644 --- a/libs/core/overview/overview.container.tsx +++ b/libs/core/overview/overview.container.tsx @@ -4,6 +4,7 @@ */ import { connect } from "react-redux" +import { DeviceType } from "device-protocol/models" import Overview from "Core/overview/components/overview/overview.component" import { ReduxRootState, @@ -11,7 +12,7 @@ import { TmpDispatch, } from "Core/__deprecated__/renderer/store" import { RootModel } from "Core/__deprecated__/renderer/models/models" -import { PureDeviceData, DeviceType } from "Core/device" +import { PureDeviceData } from "Core/device" import { lastBackupDateSelector } from "Core/backup/selectors" import { startBackupDevice, @@ -38,7 +39,7 @@ import { CheckForUpdateMode } from "Core/update/constants" import { forceUpdate } from "Core/update/actions/force-update/force-update.action" import { CheckForUpdateState } from "Core/update/constants/check-for-update-state.constant" import { isDataSyncInProgressSelector } from "Core/data-sync/selectors/is-data-sync-in-progress.selector" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" +import { deactivateDevice } from "device-manager/feature" const mapStateToProps = (state: RootModel & ReduxRootState) => { return { diff --git a/libs/core/search/search.module.ts b/libs/core/search/search.module.ts index 3487ffcd04..ffc05d8a8c 100644 --- a/libs/core/search/search.module.ts +++ b/libs/core/search/search.module.ts @@ -19,12 +19,12 @@ import { import { SearcherMediator } from "Core/search/mediators" import { SearchService } from "Core/search/services/search.service" import { SearchController } from "Core/search/controllers/search.controller" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class SearchModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/settings/actions/load-settings.action.test.ts b/libs/core/settings/actions/load-settings.action.test.ts index a925acb86f..e0786c6199 100644 --- a/libs/core/settings/actions/load-settings.action.test.ts +++ b/libs/core/settings/actions/load-settings.action.test.ts @@ -6,7 +6,7 @@ import { AnyAction } from "@reduxjs/toolkit" import thunk from "redux-thunk" import createMockStore from "redux-mock-store" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { getConfiguration } from "Core/settings/requests" import { getSettings } from "Core/settings/requests" import { SettingsEvent } from "Core/settings/constants" diff --git a/libs/core/settings/dto/configuration.object.ts b/libs/core/settings/dto/configuration.object.ts index 05e618fd3d..f21735889a 100644 --- a/libs/core/settings/dto/configuration.object.ts +++ b/libs/core/settings/dto/configuration.object.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" export interface Configuration { centerVersion: string diff --git a/libs/core/settings/reducers/settings.interface.ts b/libs/core/settings/reducers/settings.interface.ts index 035c2ccdfe..3062f50526 100644 --- a/libs/core/settings/reducers/settings.interface.ts +++ b/libs/core/settings/reducers/settings.interface.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { Settings } from "Core/settings/dto" export interface DeviceVersion { diff --git a/libs/core/settings/selectors/get-device-lowest-version.selector.test.ts b/libs/core/settings/selectors/get-device-lowest-version.selector.test.ts index 680c133cca..9590c8b62f 100644 --- a/libs/core/settings/selectors/get-device-lowest-version.selector.test.ts +++ b/libs/core/settings/selectors/get-device-lowest-version.selector.test.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { initialState } from "Core/settings/reducers" import { getDeviceLatestVersion } from "Core/settings/selectors/get-device-lowest-version.selector" diff --git a/libs/core/settings/selectors/get-device-lowest-version.selector.ts b/libs/core/settings/selectors/get-device-lowest-version.selector.ts index a7c9151f48..7416304315 100644 --- a/libs/core/settings/selectors/get-device-lowest-version.selector.ts +++ b/libs/core/settings/selectors/get-device-lowest-version.selector.ts @@ -5,7 +5,7 @@ import { createSelector } from "reselect" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { deviceTypeSelector } from "Core/device/selectors/device-type.selector" import { SettingsState } from "Core/settings/reducers/settings.interface" import { settingsStateSelector } from "Core/settings/selectors/get-settings-state.selector" diff --git a/libs/core/settings/services/settings.service.ts b/libs/core/settings/services/settings.service.ts index a3fb1e0cca..fbf9917ebd 100644 --- a/libs/core/settings/services/settings.service.ts +++ b/libs/core/settings/services/settings.service.ts @@ -4,13 +4,14 @@ */ import Store from "electron-store" +import { ISettingsService } from "shared/utils" import { Settings, SettingsUpdateOption } from "Core/settings/dto" import { settingsSchema } from "Core/settings/store/schemas" import { SettingsValue } from "Core/settings/types" // TODO: Les't merge this functionality with `metadata-store.service.ts` -export class SettingsService { +export class SettingsService implements ISettingsService { constructor(private readonly store: Store) {} init(): void { diff --git a/libs/core/settings/settings.module.ts b/libs/core/settings/settings.module.ts index fc52ec424a..3e761cf25b 100644 --- a/libs/core/settings/settings.module.ts +++ b/libs/core/settings/settings.module.ts @@ -16,12 +16,12 @@ import { } from "Core/settings/controllers" import { ConfigurationService } from "Core/settings/services" import { getSettingsService } from "Core/settings/containers/settings.container" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class SettingsModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/templates/services/template.service.test.ts b/libs/core/templates/services/template.service.test.ts index 93e6ff8989..d84be1d55d 100644 --- a/libs/core/templates/services/template.service.test.ts +++ b/libs/core/templates/services/template.service.test.ts @@ -3,11 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { Endpoint, Method } from "core-device/models" import { Result, ResultObject } from "Core/core/builder" -import { MessagesCategory, Method, Endpoint } from "Core/device/constants" +import { MessagesCategory } from "Core/device/constants" import { TemplateService } from "Core/templates/services/template.service" import { TemplateRepository } from "Core/templates/repositories" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { ErrorRequestResponse, RequestResponseStatus, @@ -24,7 +25,7 @@ const deviceManager = { device: { request: jest.fn(), }, -} as unknown as DeviceManager +} as unknown as DeviceProtocolService const subject = new TemplateService(deviceManager, templateRepository) diff --git a/libs/core/templates/services/template.service.ts b/libs/core/templates/services/template.service.ts index 9144ee66ae..f4bafbb273 100644 --- a/libs/core/templates/services/template.service.ts +++ b/libs/core/templates/services/template.service.ts @@ -3,9 +3,10 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { Endpoint, Method } from "core-device/models" import { NewTemplate, Template } from "Core/templates/dto" -import { DeviceManager } from "Core/device-manager/services" -import { Endpoint, Method, MessagesCategory } from "Core/device/constants" +import { DeviceProtocolService } from "device-protocol/feature" +import { MessagesCategory } from "Core/device/constants" import { CreateTemplateResponseBody, PureTemplate, @@ -23,7 +24,7 @@ import { export class TemplateService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private templateRepository: TemplateRepository ) {} diff --git a/libs/core/templates/template.module.ts b/libs/core/templates/template.module.ts index 03b7c04ac3..232c6c1c82 100644 --- a/libs/core/templates/template.module.ts +++ b/libs/core/templates/template.module.ts @@ -14,12 +14,12 @@ import { TemplateModel } from "Core/templates/models" import { TemplateRepository } from "Core/templates/repositories" import { TemplateService } from "Core/templates/services" import { TemplateController } from "Core/templates/controllers" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" export class TemplateModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/update/actions/base.action.ts b/libs/core/update/actions/base.action.ts index cda95dd7c7..2e5f918527 100644 --- a/libs/core/update/actions/base.action.ts +++ b/libs/core/update/actions/base.action.ts @@ -15,7 +15,6 @@ export const setCheckForUpdateState = createAction( UpdateOsEvent.SetCheckForUpdateState ) export const closeUpdateFlow = createAction(UpdateOsEvent.CloseUpdateFlow) -export const clearStateAndData = createAction(UpdateOsEvent.ClearStateAndData) export const cancelDownload = createAction(UpdateOsEvent.CancelDownload) export const setStateForDownloadedRelease = createAction<{ version: string @@ -25,4 +24,6 @@ export const setStateForInstalledRelease = createAction<{ version: string state: ReleaseProcessState }>(UpdateOsEvent.SetStateForInstalledRelease) -export const setTmpMuditaHarmonyPortInfo = createAction(UpdateOsEvent.SetTmpMuditaHarmonyPortInfo) +export const setTmpMuditaHarmonyPortInfo = createAction( + UpdateOsEvent.SetTmpMuditaHarmonyPortInfo +) diff --git a/libs/core/update/actions/check-for-force-update-need/check-for-force-update-need.action.test.ts b/libs/core/update/actions/check-for-force-update-need/check-for-force-update-need.action.test.ts index e64ee8d7c4..e15edda4cd 100644 --- a/libs/core/update/actions/check-for-force-update-need/check-for-force-update-need.action.test.ts +++ b/libs/core/update/actions/check-for-force-update-need/check-for-force-update-need.action.test.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { checkForForceUpdateNeed } from "Core/update/actions/check-for-force-update-need/check-for-force-update-need.action" import { CheckForUpdateMode, UpdateOsEvent } from "Core/update/constants" import { pendingAction } from "Core/__deprecated__/renderer/store/helpers" diff --git a/libs/core/update/actions/check-for-update/check-for-update.action.test.ts b/libs/core/update/actions/check-for-update/check-for-update.action.test.ts index 7929523c12..24a21c193a 100644 --- a/libs/core/update/actions/check-for-update/check-for-update.action.test.ts +++ b/libs/core/update/actions/check-for-update/check-for-update.action.test.ts @@ -6,7 +6,7 @@ import { AnyAction } from "@reduxjs/toolkit" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { checkForUpdate } from "Core/update/actions" import { Product, diff --git a/libs/core/update/actions/check-for-update/check-for-update.action.ts b/libs/core/update/actions/check-for-update/check-for-update.action.ts index 086949aab0..8b770fa7fe 100644 --- a/libs/core/update/actions/check-for-update/check-for-update.action.ts +++ b/libs/core/update/actions/check-for-update/check-for-update.action.ts @@ -5,7 +5,7 @@ import { createAsyncThunk } from "@reduxjs/toolkit" import { AppError } from "Core/core/errors" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import isVersionGreaterOrEqual from "Core/utils/is-version-greater-or-equal" import { CheckForUpdateMode, @@ -21,7 +21,7 @@ import { osUpdateAlreadyDownloadedCheck, } from "Core/update/requests" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { isActiveDeviceSet } from "Core/device-manager/selectors/is-active-device-set.selector" +import { isActiveDeviceSet } from "device-manager/feature" interface Params { deviceType: DeviceType diff --git a/libs/core/update/actions/download-updates/download-updates.action.test.ts b/libs/core/update/actions/download-updates/download-updates.action.test.ts index 911fa94da6..5ed65e3951 100644 --- a/libs/core/update/actions/download-updates/download-updates.action.test.ts +++ b/libs/core/update/actions/download-updates/download-updates.action.test.ts @@ -25,7 +25,8 @@ import * as osUpdateAlreadyDownloadedCheckModule from "Core/update/requests/os-u import createMockStore from "redux-mock-store" import thunk from "redux-thunk" import { trackOsDownload } from "Core/analytic-data-tracker/helpers/track-os-download" -import { DeviceManagerState } from "Core/device-manager/reducers/device-manager.interface" +import { CoreDeviceState } from "core-device/models" +import { DeviceManagerState } from "device-manager/models" jest.mock("Core/analytic-data-tracker/helpers/track-os-download") @@ -63,8 +64,11 @@ const mockedRelease2: OsRelease = { mandatoryVersions: [], } -const mockedDeviceManagerState = { +const mockedCoreDeviceState = { devices: [{ id: "1" }], +} as unknown as CoreDeviceState + +const mockedDeviceManagerState = { activeDeviceId: "1", } as unknown as DeviceManagerState @@ -128,6 +132,7 @@ describe("when some of the updates have been downloaded before", () => { batteryLevel: 0.55, }, }, + coreDevice: mockedCoreDeviceState, deviceManager: mockedDeviceManagerState, }) @@ -187,6 +192,7 @@ describe("when update downloads successfully", () => { batteryLevel: 0.55, }, }, + coreDevice: mockedCoreDeviceState, deviceManager: mockedDeviceManagerState, }) @@ -242,6 +248,7 @@ describe("when download is cancelled by user", () => { batteryLevel: 0.55, }, }, + coreDevice: mockedCoreDeviceState, deviceManager: mockedDeviceManagerState, }) @@ -290,6 +297,7 @@ describe("when download failed", () => { batteryLevel: 0.55, }, }, + coreDevice: mockedCoreDeviceState, deviceManager: mockedDeviceManagerState, }) diff --git a/libs/core/update/actions/download-updates/download-updates.action.ts b/libs/core/update/actions/download-updates/download-updates.action.ts index 9133afa7b0..edbce88cad 100644 --- a/libs/core/update/actions/download-updates/download-updates.action.ts +++ b/libs/core/update/actions/download-updates/download-updates.action.ts @@ -23,7 +23,7 @@ import { } from "Core/update/requests" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { RELEASE_SPACE } from "Core/update/constants/release-space.constant" -import { isActiveDeviceAttachedSelector } from "Core/device-manager/selectors/is-active-device-attached.selector" +import { isActiveDeviceAttachedSelector } from "device-manager/feature" interface Params { releases: OsRelease[] diff --git a/libs/core/update/actions/start-update-os/start-update-os.action.test.ts b/libs/core/update/actions/start-update-os/start-update-os.action.test.ts index ee3ea607e7..74c846856e 100644 --- a/libs/core/update/actions/start-update-os/start-update-os.action.test.ts +++ b/libs/core/update/actions/start-update-os/start-update-os.action.test.ts @@ -26,9 +26,11 @@ import { trackOsUpdate, TrackOsUpdateState, } from "Core/analytic-data-tracker/helpers" -import { DeviceType, setRestartingStatus } from "Core/device" -import { DeviceManagerState } from "Core/device-manager/reducers/device-manager.interface" +import { setRestartingStatus } from "Core/device" +import { DeviceType } from "device-protocol/models" +import { CoreDeviceState } from "core-device/models" import { startUpdateOs } from "Core/update/actions" +import { DeviceManagerState } from "device-manager/models" jest.mock("Core/update/requests/remove-downloaded-os-updates.request") jest.mock("Core/analytic-data-tracker/helpers/track-os-update") @@ -169,14 +171,16 @@ describe("when all updating os requests return success status", () => { osVersion: "1.0.0", }, }, - deviceManager: { + coreDevice: { devices: [ { id: "1", deviceType: DeviceType.MuditaPure, }, ], - activeDeviceId: "1" + } as unknown as CoreDeviceState, + deviceManager: { + activeDeviceId: "1", } as unknown as DeviceManagerState, }) @@ -281,14 +285,16 @@ describe("when updating os request return failure status", () => { osVersion: "1.0.0", }, }, - deviceManager: { + coreDevice: { devices: [ { id: "1", deviceType: DeviceType.MuditaPure, }, ], - activeDeviceId: "1" + } as unknown as CoreDeviceState, + deviceManager: { + activeDeviceId: "1", } as unknown as DeviceManagerState, }) diff --git a/libs/core/update/actions/start-update-os/start-update-os.action.ts b/libs/core/update/actions/start-update-os/start-update-os.action.ts index cb6a3141fc..b16cd3b3b7 100644 --- a/libs/core/update/actions/start-update-os/start-update-os.action.ts +++ b/libs/core/update/actions/start-update-os/start-update-os.action.ts @@ -6,7 +6,8 @@ import { createAsyncThunk } from "@reduxjs/toolkit" import { AppError } from "Core/core/errors" import { removeFile } from "Core/device-file-system" -import { DeviceType, DiagnosticsFilePath } from "Core/device/constants" +import { DiagnosticsFilePath } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" import { setStateForInstalledRelease, setTmpMuditaHarmonyPortInfo, @@ -28,7 +29,7 @@ import { } from "Core/analytic-data-tracker/helpers" import { checkUpdate } from "Core/update/requests/checkUpdate.request" import { setRestartingStatus } from "Core/device" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" +import { getActiveDevice } from "device-manager/feature" interface Params { releases: OsRelease[] diff --git a/libs/core/update/components/update-os-interrupted-flow/update-os-interrupted-flow.container.tsx b/libs/core/update/components/update-os-interrupted-flow/update-os-interrupted-flow.container.tsx index 63256e82aa..10bc419804 100644 --- a/libs/core/update/components/update-os-interrupted-flow/update-os-interrupted-flow.container.tsx +++ b/libs/core/update/components/update-os-interrupted-flow/update-os-interrupted-flow.container.tsx @@ -16,8 +16,10 @@ import { RootState, TmpDispatch, } from "Core/__deprecated__/renderer/store" -import { isActiveDeviceAttachedSelector } from "Core/device-manager/selectors/is-active-device-attached.selector" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" +import { + deactivateDevice, + isActiveDeviceAttachedSelector, +} from "device-manager/feature" const mapStateToProps = (state: RootState & ReduxRootState) => { return { diff --git a/libs/core/update/constants/event.constant.ts b/libs/core/update/constants/event.constant.ts index 6b16ae90b3..f696df94e5 100644 --- a/libs/core/update/constants/event.constant.ts +++ b/libs/core/update/constants/event.constant.ts @@ -10,7 +10,6 @@ export enum UpdateOsEvent { SetCheckForUpdateState = "SET_CHECK_FOR_UPDATE_STATE", CancelDownload = "CANCEL_DOWNLOAD", CloseUpdateFlow = "CLOSE_UPDATE_FLOW", - ClearStateAndData = "CLEAR_STATE_AND_DATA", SetStateForDownloadedRelease = "SET_STATE_FOR_DOWNLOADED_RELEASE", SetStateForInstalledRelease = "SET_STATE_FOR_INSTALLED_RELEASE", HandleDeviceAttached = "HANDLE_DEVICE_ATTACHED", diff --git a/libs/core/update/reducers/update-os.reducer.test.ts b/libs/core/update/reducers/update-os.reducer.test.ts index 2540e39153..a957e9eb44 100644 --- a/libs/core/update/reducers/update-os.reducer.test.ts +++ b/libs/core/update/reducers/update-os.reducer.test.ts @@ -598,37 +598,6 @@ describe("closeUpdateFlow", () => { }) }) -describe("clearStateAndData", () => { - test("clear states and data", () => { - const data = { - ...initialState.data, - downloadedProcessedReleases: [ - { release: mockedRelease, state: ReleaseProcessState.Done }, - ], - availableReleasesForUpdate: [mockedRelease], - updateProcessedReleases: [ - { release: mockedRelease, state: ReleaseProcessState.Initial }, - ], - } - - expect( - updateOsReducer( - { - ...initialState, - error: exampleError, - updateOsState: State.Failed, - data, - }, - { - type: UpdateOsEvent.ClearStateAndData, - } - ) - ).toEqual({ - ...initialState, - }) - }) -}) - describe("checkForForceUpdateNeed", () => { test("sets needsForceUpdate according to the action result and checkedForForceUpdateNeed as true", () => { expect( diff --git a/libs/core/update/reducers/update-os.reducer.ts b/libs/core/update/reducers/update-os.reducer.ts index 1d2e286a51..90c3903e89 100644 --- a/libs/core/update/reducers/update-os.reducer.ts +++ b/libs/core/update/reducers/update-os.reducer.ts @@ -4,13 +4,13 @@ */ import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" import { State } from "Core/core/constants" import { CheckForUpdateState } from "../constants/check-for-update-state.constant" import { AppError } from "Core/core/errors" import { cancelDownload, checkForUpdate, - clearStateAndData, closeUpdateFlow, downloadUpdates, setCheckForUpdateState, @@ -22,7 +22,6 @@ import { checkForForceUpdateNeed, setTmpMuditaHarmonyPortInfo, } from "Core/update/actions" - import { CheckForUpdateMode, DownloadState, @@ -31,6 +30,7 @@ import { UpdateError, } from "Core/update/constants" import { UpdateOsState } from "Core/update/reducers/update-os.interface" +import { pendingAction } from "Core/__deprecated__/renderer/store/helpers" export const initialState: UpdateOsState = { silentCheckForUpdate: SilentCheckForUpdateState.Initial, @@ -52,265 +52,266 @@ export const initialState: UpdateOsState = { export const updateOsReducer = createReducer( initialState, (builder) => { - builder.addCase(closeForceUpdateFlow, (state) => { - return { - ...state, - forceUpdateState: State.Initial, - } - }) - builder.addCase(setCheckForUpdateState, (state, action) => { - return { - ...state, - checkForUpdateState: action.payload, - } - }) - builder.addCase(closeUpdateFlow, (state) => { - const { PerformedWithFailure, Performed, Initial, Failed } = - CheckForUpdateState - let silentCheckForUpdate: SilentCheckForUpdateState = - state.silentCheckForUpdate - let checkForUpdateState: CheckForUpdateState = Initial - if (silentCheckForUpdate === SilentCheckForUpdateState.Failed) { - silentCheckForUpdate = SilentCheckForUpdateState.Skipped - } - if ( - state.checkForUpdateState !== Initial && - state.checkForUpdateState === Failed - ) { - checkForUpdateState = PerformedWithFailure - } else if (state.checkForUpdateState !== Initial) { - checkForUpdateState = Performed - } - return { - ...state, - error: null, - silentCheckForUpdate, - checkForUpdateState, - updateOsState: State.Initial, - downloadState: DownloadState.Initial, - } - }) - builder.addCase(clearStateAndData, (state) => { - return { - ...initialState, - tmpMuditaHarmonyPortInfo: state.tmpMuditaHarmonyPortInfo, - } - }) - builder.addCase(setStateForDownloadedRelease, (state, action) => { - const { state: newReleaseState, version } = action.payload - const newDownloadedProcessedReleases = ( - state.data.downloadedProcessedReleases ?? [] - ).map((item) => - item.release.version === version - ? { - ...item, - state: newReleaseState, - } - : item - ) - - return { - ...state, - data: { - ...state.data, - downloadedProcessedReleases: newDownloadedProcessedReleases, - }, - } - }) - builder.addCase(setStateForInstalledRelease, (state, action) => { - const { state: newReleaseState, version } = action.payload - const newUpdateProcessedReleases = ( - state.data.updateProcessedReleases ?? [] - ).map((item) => - item.release.version === version - ? { - ...item, - state: newReleaseState, - } - : item - ) - - const newAvailableReleasesForUpdate = ( - state.data.availableReleasesForUpdate ?? [] - ).filter( - (release) => - !( - release.version === version && - newReleaseState === ReleaseProcessState.Done - ) - ) - - return { - ...state, - data: { - ...state.data, - updateProcessedReleases: newUpdateProcessedReleases, - availableReleasesForUpdate: newAvailableReleasesForUpdate, - }, - } - }) - - builder.addCase(checkForUpdate.pending, (state, payload) => { - state.error = null - state.data = { - availableReleasesForUpdate: null, - downloadedProcessedReleases: null, - updateProcessedReleases: null, - } - - const { - meta: { - arg: { mode }, - }, - } = payload - - if (mode === CheckForUpdateMode.SilentCheck) { - state.silentCheckForUpdate = SilentCheckForUpdateState.Loading - state.checkForUpdateState = CheckForUpdateState.Initial - } else if (mode === CheckForUpdateMode.TryAgain) { - state.silentCheckForUpdate = SilentCheckForUpdateState.Skipped - state.checkForUpdateState = CheckForUpdateState.Loading - } else { - state.checkForUpdateState = CheckForUpdateState.Loading - } - }) - builder.addCase(checkForUpdate.fulfilled, (state, action) => { - state.data.availableReleasesForUpdate = - action.payload.availableReleasesForUpdate - if (action.meta.arg.mode === CheckForUpdateMode.SilentCheck) { - state.silentCheckForUpdate = SilentCheckForUpdateState.Loaded - } else { - state.checkForUpdateState = CheckForUpdateState.Loaded - } - if (action.payload.areAllReleasesAlreadyDownloaded) { - state.data.downloadedProcessedReleases = - action.payload.availableReleasesForUpdate.map((release) => ({ - release, - state: ReleaseProcessState.Done, - })) - } - }) - builder.addCase(checkForUpdate.rejected, (state, action) => { - const error = action.payload as AppError - - if (error?.type === UpdateError.NoActiveDevice) { - return { ...initialState } - } - - if ( - action.meta.aborted && - action.meta.arg.mode === CheckForUpdateMode.SilentCheck - ) { + builder + .addCase(closeForceUpdateFlow, (state) => { + return { + ...state, + forceUpdateState: State.Initial, + } + }) + .addCase(setCheckForUpdateState, (state, action) => { + return { + ...state, + checkForUpdateState: action.payload, + } + }) + .addCase(closeUpdateFlow, (state) => { + const { PerformedWithFailure, Performed, Initial, Failed } = + CheckForUpdateState + let silentCheckForUpdate: SilentCheckForUpdateState = + state.silentCheckForUpdate + let checkForUpdateState: CheckForUpdateState = Initial + if (silentCheckForUpdate === SilentCheckForUpdateState.Failed) { + silentCheckForUpdate = SilentCheckForUpdateState.Skipped + } + if ( + state.checkForUpdateState !== Initial && + state.checkForUpdateState === Failed + ) { + checkForUpdateState = PerformedWithFailure + } else if (state.checkForUpdateState !== Initial) { + checkForUpdateState = Performed + } return { ...state, error: null, - silentCheckForUpdate: SilentCheckForUpdateState.Initial, + silentCheckForUpdate, + checkForUpdateState, + updateOsState: State.Initial, + downloadState: DownloadState.Initial, + } + }) + .addCase(pendingAction(DeviceManagerEvent.DeactivateDevice), (state) => { + return { + ...initialState, + tmpMuditaHarmonyPortInfo: state.tmpMuditaHarmonyPortInfo, } - } else if (action.meta.arg.mode === CheckForUpdateMode.SilentCheck) { + }) + .addCase(setStateForDownloadedRelease, (state, action) => { + const { state: newReleaseState, version } = action.payload + const newDownloadedProcessedReleases = ( + state.data.downloadedProcessedReleases ?? [] + ).map((item) => + item.release.version === version + ? { + ...item, + state: newReleaseState, + } + : item + ) + return { ...state, - error: error ?? null, - silentCheckForUpdate: SilentCheckForUpdateState.Failed, + data: { + ...state.data, + downloadedProcessedReleases: newDownloadedProcessedReleases, + }, } - } else { + }) + .addCase(setStateForInstalledRelease, (state, action) => { + const { state: newReleaseState, version } = action.payload + const newUpdateProcessedReleases = ( + state.data.updateProcessedReleases ?? [] + ).map((item) => + item.release.version === version + ? { + ...item, + state: newReleaseState, + } + : item + ) + + const newAvailableReleasesForUpdate = ( + state.data.availableReleasesForUpdate ?? [] + ).filter( + (release) => + !( + release.version === version && + newReleaseState === ReleaseProcessState.Done + ) + ) + return { ...state, - error: error ?? null, - checkForUpdateState: CheckForUpdateState.Failed, + data: { + ...state.data, + updateProcessedReleases: newUpdateProcessedReleases, + availableReleasesForUpdate: newAvailableReleasesForUpdate, + }, + } + }) + + .addCase(checkForUpdate.pending, (state, payload) => { + state.error = null + state.data = { + availableReleasesForUpdate: null, + downloadedProcessedReleases: null, + updateProcessedReleases: null, + } + + const { + meta: { + arg: { mode }, + }, + } = payload + + if (mode === CheckForUpdateMode.SilentCheck) { + state.silentCheckForUpdate = SilentCheckForUpdateState.Loading + state.checkForUpdateState = CheckForUpdateState.Initial + } else if (mode === CheckForUpdateMode.TryAgain) { + state.silentCheckForUpdate = SilentCheckForUpdateState.Skipped + state.checkForUpdateState = CheckForUpdateState.Loading + } else { + state.checkForUpdateState = CheckForUpdateState.Loading + } + }) + .addCase(checkForUpdate.fulfilled, (state, action) => { + state.data.availableReleasesForUpdate = + action.payload.availableReleasesForUpdate + if (action.meta.arg.mode === CheckForUpdateMode.SilentCheck) { + state.silentCheckForUpdate = SilentCheckForUpdateState.Loaded + } else { + state.checkForUpdateState = CheckForUpdateState.Loaded + } + if (action.payload.areAllReleasesAlreadyDownloaded) { + state.data.downloadedProcessedReleases = + action.payload.availableReleasesForUpdate.map((release) => ({ + release, + state: ReleaseProcessState.Done, + })) + } + }) + .addCase(checkForUpdate.rejected, (state, action) => { + const error = action.payload as AppError + + if (error?.type === UpdateError.NoActiveDevice) { + return { ...initialState } } - } - }) - builder.addCase(downloadUpdates.pending, (state, action) => { - state.data.downloadedProcessedReleases = action.meta.arg.releases.map( - (release) => ({ - release, - state: ReleaseProcessState.Initial, - }) - ) - state.error = null - state.checkForUpdateState = CheckForUpdateState.Initial - state.downloadState = DownloadState.Loading - }) - builder.addCase(downloadUpdates.fulfilled, (state) => { - state.checkForUpdateState = CheckForUpdateState.Initial - state.silentCheckForUpdate = SilentCheckForUpdateState.Loaded - state.downloadState = DownloadState.Loaded - }) - builder.addCase(downloadUpdates.rejected, (state, action) => { - const error = action.payload as AppError - if (error?.type === UpdateError.DownloadCancelledByUser) { + if ( + action.meta.aborted && + action.meta.arg.mode === CheckForUpdateMode.SilentCheck + ) { + return { + ...state, + error: null, + silentCheckForUpdate: SilentCheckForUpdateState.Initial, + } + } else if (action.meta.arg.mode === CheckForUpdateMode.SilentCheck) { + return { + ...state, + error: error ?? null, + silentCheckForUpdate: SilentCheckForUpdateState.Failed, + } + } else { + return { + ...state, + error: error ?? null, + checkForUpdateState: CheckForUpdateState.Failed, + } + } + }) + + .addCase(downloadUpdates.pending, (state, action) => { + state.data.downloadedProcessedReleases = action.meta.arg.releases.map( + (release) => ({ + release, + state: ReleaseProcessState.Initial, + }) + ) + state.error = null + state.checkForUpdateState = CheckForUpdateState.Initial + state.downloadState = DownloadState.Loading + }) + .addCase(downloadUpdates.fulfilled, (state) => { + state.checkForUpdateState = CheckForUpdateState.Initial + state.silentCheckForUpdate = SilentCheckForUpdateState.Loaded + state.downloadState = DownloadState.Loaded + }) + .addCase(downloadUpdates.rejected, (state, action) => { + const error = action.payload as AppError + if (error?.type === UpdateError.DownloadCancelledByUser) { + state.downloadState = DownloadState.Cancelled + } else { + state.downloadState = DownloadState.Failed + state.error = error + } + }) + .addCase(cancelDownload, (state) => { state.downloadState = DownloadState.Cancelled - } else { - state.downloadState = DownloadState.Failed - state.error = error - } - }) - builder.addCase(cancelDownload, (state) => { - state.downloadState = DownloadState.Cancelled - }) + }) - builder.addCase(startUpdateOs.pending, (state, action) => { - state.data.updateProcessedReleases = action.meta.arg.releases.map( - (release) => ({ - release, - state: ReleaseProcessState.Initial, - }) - ) - state.error = null - state.downloadState = DownloadState.Initial - state.updateOsState = State.Loading - state.tmpMuditaHarmonyPortInfo = undefined - }) - builder.addCase(startUpdateOs.fulfilled, (state) => { - state.updateOsState = State.Loaded - state.data = { - ...state.data, - availableReleasesForUpdate: [], - downloadedProcessedReleases: [], - updateProcessedReleases: [], - } - state.error = null - state.tmpMuditaHarmonyPortInfo = undefined - }) - builder.addCase(startUpdateOs.rejected, (state, action) => { - state.updateOsState = State.Failed - state.error = action.payload as AppError - state.tmpMuditaHarmonyPortInfo = undefined - }) - builder.addCase(checkForForceUpdateNeed.fulfilled, (state, action) => { - state.needsForceUpdate = action.payload - state.checkedForForceUpdateNeed = true - }) + .addCase(startUpdateOs.pending, (state, action) => { + state.data.updateProcessedReleases = action.meta.arg.releases.map( + (release) => ({ + release, + state: ReleaseProcessState.Initial, + }) + ) + state.error = null + state.downloadState = DownloadState.Initial + state.updateOsState = State.Loading + state.tmpMuditaHarmonyPortInfo = undefined + }) + .addCase(startUpdateOs.fulfilled, (state) => { + state.updateOsState = State.Loaded + state.data = { + ...state.data, + availableReleasesForUpdate: [], + downloadedProcessedReleases: [], + updateProcessedReleases: [], + } + state.error = null + state.tmpMuditaHarmonyPortInfo = undefined + }) + .addCase(startUpdateOs.rejected, (state, action) => { + state.updateOsState = State.Failed + state.error = action.payload as AppError + state.tmpMuditaHarmonyPortInfo = undefined + }) + .addCase(checkForForceUpdateNeed.fulfilled, (state, action) => { + state.needsForceUpdate = action.payload + state.checkedForForceUpdateNeed = true + }) - builder.addCase(forceUpdate.pending, (state, action) => { - state.data.updateProcessedReleases = action.meta.arg.releases.map( - (release) => ({ - release, - state: ReleaseProcessState.Initial, - }) - ) - state.data.downloadedProcessedReleases = action.meta.arg.releases.map( - (release) => ({ - release, - state: ReleaseProcessState.Initial, - }) - ) - state.error = null - state.forceUpdateState = State.Loading - }) - builder.addCase(forceUpdate.fulfilled, (state) => { - state.forceUpdateState = State.Loaded - state.downloadState = DownloadState.Initial - state.updateOsState = State.Initial - state.needsForceUpdate = false - }) - builder.addCase(forceUpdate.rejected, (state, action) => { - state.forceUpdateState = State.Failed - state.error = action.payload as AppError - }) - builder.addCase(setTmpMuditaHarmonyPortInfo, (state, action) => { - state.tmpMuditaHarmonyPortInfo = action.payload - }) + .addCase(forceUpdate.pending, (state, action) => { + state.data.updateProcessedReleases = action.meta.arg.releases.map( + (release) => ({ + release, + state: ReleaseProcessState.Initial, + }) + ) + state.data.downloadedProcessedReleases = action.meta.arg.releases.map( + (release) => ({ + release, + state: ReleaseProcessState.Initial, + }) + ) + state.error = null + state.forceUpdateState = State.Loading + }) + .addCase(forceUpdate.fulfilled, (state) => { + state.forceUpdateState = State.Loaded + state.downloadState = DownloadState.Initial + state.updateOsState = State.Initial + state.needsForceUpdate = false + }) + .addCase(forceUpdate.rejected, (state, action) => { + state.forceUpdateState = State.Failed + state.error = action.payload as AppError + }) + .addCase(setTmpMuditaHarmonyPortInfo, (state, action) => { + state.tmpMuditaHarmonyPortInfo = action.payload + }) } ) diff --git a/libs/core/update/services/device-update.service.ts b/libs/core/update/services/device-update.service.ts index 917a748235..02f6273e5b 100644 --- a/libs/core/update/services/device-update.service.ts +++ b/libs/core/update/services/device-update.service.ts @@ -3,29 +3,25 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { DeviceType } from "device-protocol/models" +import { Endpoint, Method } from "core-device/models" import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { - DeviceType, - Endpoint, - Method, - OnboardingState, - PhoneLockCategory, -} from "Core/device/constants" +import { OnboardingState, PhoneLockCategory } from "Core/device/constants" import { SettingsService } from "Core/settings/services" import { UpdateErrorServiceErrors } from "Core/update/constants" import { UpdateOS } from "Core/update/dto" import { join } from "path" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import * as fs from "fs" import { DeviceInfoService } from "Core/device-info/services" export class DeviceUpdateService { constructor( private settingsService: SettingsService, - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private deviceFileSystem: DeviceFileSystemService, private deviceInfoService: DeviceInfoService ) {} diff --git a/libs/core/update/update.module.ts b/libs/core/update/update.module.ts index c9b9021447..0ca199accc 100644 --- a/libs/core/update/update.module.ts +++ b/libs/core/update/update.module.ts @@ -22,14 +22,14 @@ import { ReleasesController, DeviceUpdateController, } from "Core/update/controllers" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceInfoService } from "Core/device-info/services" import { RELEASE_TIMEOUT } from "Core/update/constants/get-release-timeout.constant" export class UpdateModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/device-manager/README.md b/libs/device-manager/README.md deleted file mode 100644 index 9e9426a85f..0000000000 --- a/libs/device-manager/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# device-manager - -This library was generated with [Nx](https://nx.dev). - -## Running unit tests - -Run `nx test device-manager` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-manager/feature/.babelrc b/libs/device-manager/feature/.babelrc new file mode 100644 index 0000000000..ef4889c1ab --- /dev/null +++ b/libs/device-manager/feature/.babelrc @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [ + [ + "styled-components", + { + "pure": true, + "ssr": true + } + ] + ] +} diff --git a/libs/device-manager/.eslintrc.json b/libs/device-manager/feature/.eslintrc.json similarity index 86% rename from libs/device-manager/.eslintrc.json rename to libs/device-manager/feature/.eslintrc.json index d3e61a2ea8..cacbe26215 100644 --- a/libs/device-manager/.eslintrc.json +++ b/libs/device-manager/feature/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": ["../../.eslintrc.js"], + "extends": ["../../../.eslintrc.js"], "ignorePatterns": ["!**/*"], "overrides": [ { diff --git a/libs/device-manager/feature/README.md b/libs/device-manager/feature/README.md new file mode 100644 index 0000000000..97b21345a6 --- /dev/null +++ b/libs/device-manager/feature/README.md @@ -0,0 +1,7 @@ +# device-manager-feature + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test device-manager-feature` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-protocol/jest.config.ts b/libs/device-manager/feature/jest.config.ts similarity index 65% rename from libs/device-protocol/jest.config.ts rename to libs/device-manager/feature/jest.config.ts index 5d89c82171..3c506b81fb 100644 --- a/libs/device-protocol/jest.config.ts +++ b/libs/device-manager/feature/jest.config.ts @@ -1,11 +1,11 @@ /* eslint-disable */ export default { - displayName: "device-protocol", - preset: "../../jest.preset.js", + displayName: "feature", + preset: "../../../jest.preset.js", transform: { "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], }, moduleFileExtensions: ["ts", "tsx", "js", "jsx"], - coverageDirectory: "../../coverage/libs/device-protocol", + coverageDirectory: "../../../coverage/libs/device-manager/feature", } diff --git a/libs/device-manager/feature/project.json b/libs/device-manager/feature/project.json new file mode 100644 index 0000000000..93b0f6c6fe --- /dev/null +++ b/libs/device-manager/feature/project.json @@ -0,0 +1,20 @@ +{ + "name": "device-manager-feature", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/device-manager-feature/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/device-manager/feature/jest.config.ts" + } + } + } +} diff --git a/libs/device-manager/feature/src/actions/connect-device.action.ts b/libs/device-manager/feature/src/actions/connect-device.action.ts new file mode 100644 index 0000000000..20ac9f8453 --- /dev/null +++ b/libs/device-manager/feature/src/actions/connect-device.action.ts @@ -0,0 +1,27 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createAsyncThunk } from "@reduxjs/toolkit" +import { DeviceManagerEvent } from "device-manager/models" +import { setDeviceState } from "core-device/feature" +import { DeviceState } from "core-device/models" +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { DeviceId } from "Core/device/constants/device-id" +import { connectDeviceRequest } from "../requests" + +export const connectDevice = createAsyncThunk< + boolean, + DeviceId, + { state: ReduxRootState } +>(DeviceManagerEvent.ConnectDevice, async (id, { dispatch }) => { + const result = await connectDeviceRequest(id) + if (result.ok) { + dispatch(setDeviceState({ id, state: DeviceState.Connected })) + } else { + dispatch(setDeviceState({ id, state: DeviceState.Failed })) + } + + return result.ok +}) diff --git a/libs/core/device-manager/actions/deactivate-device.action.ts b/libs/device-manager/feature/src/actions/deactivate-device.action.ts similarity index 53% rename from libs/core/device-manager/actions/deactivate-device.action.ts rename to libs/device-manager/feature/src/actions/deactivate-device.action.ts index dadcb558a9..a677671cc5 100644 --- a/libs/core/device-manager/actions/deactivate-device.action.ts +++ b/libs/device-manager/feature/src/actions/deactivate-device.action.ts @@ -4,24 +4,17 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { Device } from "core-device/models" +import { DeviceManagerEvent } from "device-manager/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceManagerEvent } from "Core/device-manager/constants" -import { setActiveDeviceRequest } from "Core/device-manager/requests" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" import { setDeviceInitializationStatus } from "Core/device-initialization/actions/base.action" import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" -import { setDataSyncInitState } from "Core/data-sync/actions" -import { setInitState } from "Core/device" -import { clearStateAndData } from "Core/update/actions" import { MetadataKey, setValue } from "Core/metadata" -import { setInitialBackupState } from "Core/backup" -import { setInitialContactsState } from "Core/contacts/actions" -import { setInitialFilesManagerState } from "Core/files-manager/actions" -import { setInitialMessagesState } from "Core/messages/actions/base.action" -import { getDevicesSelector } from "Core/device-manager/selectors/get-devices.selector" -import { Device } from "Core/device-manager/reducers/device-manager.interface" -import { setSelectDeviceDrawerOpen } from "Core/device-select/actions/set-select-device-drawer-open.action" +import { setActiveDeviceRequest } from "../requests" +import { getDevicesSelector } from "../selectors" +import { setSelectDeviceDrawerOpen } from "./set-select-device-drawer-open.action" export const deactivateDevice = createAsyncThunk< Device[], @@ -32,14 +25,7 @@ export const deactivateDevice = createAsyncThunk< dispatch(setSelectDeviceDrawerOpen(false)) dispatch(setDiscoveryStatus(DiscoveryStatus.Idle)) dispatch(setDeviceInitializationStatus(DeviceInitializationStatus.Idle)) - dispatch(setDataSyncInitState()) - dispatch(setInitialBackupState()) - dispatch(setInitialContactsState()) - dispatch(setInitialFilesManagerState()) - dispatch(setInitialMessagesState()) - dispatch(setInitState()) - dispatch(clearStateAndData()) void setValue({ key: MetadataKey.DeviceOsVersion, value: null }) void setValue({ key: MetadataKey.DeviceType, value: null }) diff --git a/libs/core/device-manager/actions/handle-device-activated.action.ts b/libs/device-manager/feature/src/actions/handle-device-activated.action.ts similarity index 85% rename from libs/core/device-manager/actions/handle-device-activated.action.ts rename to libs/device-manager/feature/src/actions/handle-device-activated.action.ts index 6695532603..9c0240fdec 100644 --- a/libs/core/device-manager/actions/handle-device-activated.action.ts +++ b/libs/device-manager/feature/src/actions/handle-device-activated.action.ts @@ -4,13 +4,13 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { activateDevice } from "generic-view/store" +import { DeviceManagerEvent } from "device-manager/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceManagerEvent } from "Core/device-manager/constants" -import { setActiveDevice } from "Core/device-manager/actions/set-active-device.action" import { DeviceId } from "Core/device/constants/device-id" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" -import { activateDevice } from "generic-view/store" +import { setActiveDevice } from "./set-active-device.action" export const handleDeviceActivated = createAsyncThunk< void, diff --git a/libs/device-manager/feature/src/actions/index.ts b/libs/device-manager/feature/src/actions/index.ts new file mode 100644 index 0000000000..3d19d717d8 --- /dev/null +++ b/libs/device-manager/feature/src/actions/index.ts @@ -0,0 +1,10 @@ +/** + * 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 "./connect-device.action" +export * from "./deactivate-device.action" +export * from "./handle-device-activated.action" +export * from "./set-active-device.action" +export * from "./set-select-device-drawer-open.action" diff --git a/libs/core/device-manager/actions/set-active-device.action.ts b/libs/device-manager/feature/src/actions/set-active-device.action.ts similarity index 84% rename from libs/core/device-manager/actions/set-active-device.action.ts rename to libs/device-manager/feature/src/actions/set-active-device.action.ts index cd79965753..7bf5c77648 100644 --- a/libs/core/device-manager/actions/set-active-device.action.ts +++ b/libs/device-manager/feature/src/actions/set-active-device.action.ts @@ -4,11 +4,11 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { cleanBackupProcess, cleanRestoreProcess } from "generic-view/store" +import { DeviceManagerEvent } from "device-manager/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceManagerEvent } from "Core/device-manager/constants" -import { setActiveDeviceRequest } from "Core/device-manager/requests" import { DeviceId } from "Core/device/constants/device-id" -import { cleanBackupProcess, cleanRestoreProcess } from "generic-view/store" +import { setActiveDeviceRequest } from "../requests" export const setActiveDevice = createAsyncThunk< DeviceId | undefined, diff --git a/libs/core/device-select/actions/set-select-device-drawer-open.action.ts b/libs/device-manager/feature/src/actions/set-select-device-drawer-open.action.ts similarity index 67% rename from libs/core/device-select/actions/set-select-device-drawer-open.action.ts rename to libs/device-manager/feature/src/actions/set-select-device-drawer-open.action.ts index e7b1ec442b..245049d7f7 100644 --- a/libs/core/device-select/actions/set-select-device-drawer-open.action.ts +++ b/libs/device-manager/feature/src/actions/set-select-device-drawer-open.action.ts @@ -4,8 +4,8 @@ */ import { createAction } from "@reduxjs/toolkit" -import { DeviceSelectEvent } from "Core/device-select/constants/event.constant" +import { DeviceManagerEvent } from "device-manager/models" export const setSelectDeviceDrawerOpen = createAction( - DeviceSelectEvent.SetSelectDeviceDrawerOpen + DeviceManagerEvent.SetSelectDeviceDrawerOpen ) diff --git a/libs/core/device-manager/constants/controller.constant.ts b/libs/device-manager/feature/src/constants/controller.constant.ts similarity index 71% rename from libs/core/device-manager/constants/controller.constant.ts rename to libs/device-manager/feature/src/constants/controller.constant.ts index 487dd36339..6f916e884c 100644 --- a/libs/core/device-manager/constants/controller.constant.ts +++ b/libs/device-manager/feature/src/constants/controller.constant.ts @@ -3,10 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export const ControllerPrefix = "device-manager" - export enum IpcDeviceManagerEvent { SetActiveDevice = "device-manager_set-active-device", - GetDeviceConfiguration = "device-manager_get-device-configuration", ConnectDevice = "device-manager_connect-device", } diff --git a/libs/device-manager/feature/src/constants/index.ts b/libs/device-manager/feature/src/constants/index.ts new file mode 100644 index 0000000000..eb01fd9553 --- /dev/null +++ b/libs/device-manager/feature/src/constants/index.ts @@ -0,0 +1,6 @@ +/** + * 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" diff --git a/libs/device-manager/feature/src/controllers/device-manager.controller.ts b/libs/device-manager/feature/src/controllers/device-manager.controller.ts new file mode 100644 index 0000000000..569136bdd6 --- /dev/null +++ b/libs/device-manager/feature/src/controllers/device-manager.controller.ts @@ -0,0 +1,24 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { IpcEvent } from "Core/core/decorators" +import { DeviceProtocolService } from "device-protocol/feature" +import { ResultObject } from "Core/core/builder" +import { DeviceId } from "Core/device/constants/device-id" +import { IpcDeviceManagerEvent } from "../constants" + +export class DeviceManagerController { + constructor(private deviceManager: DeviceProtocolService) {} + + @IpcEvent(IpcDeviceManagerEvent.SetActiveDevice) + public setActiveDevice(id: DeviceId | undefined): ResultObject { + return this.deviceManager.setActiveDevice(id) + } + + @IpcEvent(IpcDeviceManagerEvent.ConnectDevice) + public connectDevice(id: DeviceId): Promise> { + return this.deviceManager.connectDevice(id) + } +} diff --git a/libs/core/device-manager/controllers/index.ts b/libs/device-manager/feature/src/controllers/index.ts similarity index 100% rename from libs/core/device-manager/controllers/index.ts rename to libs/device-manager/feature/src/controllers/index.ts diff --git a/libs/device-manager/feature/src/device-manager.module.ts b/libs/device-manager/feature/src/device-manager.module.ts new file mode 100644 index 0000000000..ab77ee4a3d --- /dev/null +++ b/libs/device-manager/feature/src/device-manager.module.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceManagerController } from "./controllers" + +export class DeviceManagerModule { + public controllers + + constructor(public deviceManager: DeviceProtocolService) { + const deviceManagerController = new DeviceManagerController( + this.deviceManager + ) + + this.controllers = [deviceManagerController] + } +} diff --git a/libs/device-manager/feature/src/index.ts b/libs/device-manager/feature/src/index.ts new file mode 100644 index 0000000000..b6d66a48d4 --- /dev/null +++ b/libs/device-manager/feature/src/index.ts @@ -0,0 +1,9 @@ +/** + * 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 "./actions" +export * from "./selectors" +export * from "./reducers" +export * from "./device-manager.module" diff --git a/libs/device-manager/feature/src/reducers/device-manager.reducer.ts b/libs/device-manager/feature/src/reducers/device-manager.reducer.ts new file mode 100644 index 0000000000..2a037917b0 --- /dev/null +++ b/libs/device-manager/feature/src/reducers/device-manager.reducer.ts @@ -0,0 +1,42 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createReducer } from "@reduxjs/toolkit" +import { DeviceManagerState } from "device-manager/models" +import { + setActiveDevice, + deactivateDevice, + setSelectDeviceDrawerOpen, +} from "../actions" + +export const initialState: DeviceManagerState = { + activeDeviceId: undefined, + selectDeviceDrawerOpen: false, +} + +export const deviceManagerReducer = createReducer( + initialState, + (builder) => { + builder + .addCase(setActiveDevice.fulfilled, (state, action) => { + return { + ...state, + activeDeviceId: action.payload, + } + }) + .addCase(deactivateDevice.fulfilled, (state) => { + return { + ...state, + activeDeviceId: undefined, + } + }) + .addCase(setSelectDeviceDrawerOpen, (state, action) => { + return { + ...state, + selectDeviceDrawerOpen: action.payload, + } + }) + } +) diff --git a/libs/device-manager/feature/src/reducers/index.ts b/libs/device-manager/feature/src/reducers/index.ts new file mode 100644 index 0000000000..fcfa2ac8a7 --- /dev/null +++ b/libs/device-manager/feature/src/reducers/index.ts @@ -0,0 +1,7 @@ +/** + * 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 "../../../models/src/device-manager.interface" +export * from "./device-manager.reducer" diff --git a/libs/core/device-manager/requests/connect-device.request.ts b/libs/device-manager/feature/src/requests/connect-device.request.ts similarity index 69% rename from libs/core/device-manager/requests/connect-device.request.ts rename to libs/device-manager/feature/src/requests/connect-device.request.ts index 5c85920df3..8d9889b49b 100644 --- a/libs/core/device-manager/requests/connect-device.request.ts +++ b/libs/device-manager/feature/src/requests/connect-device.request.ts @@ -5,9 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "Core/core/builder" -import { IpcDeviceManagerEvent } from "Core/device-manager/constants" import { DeviceId } from "Core/device/constants/device-id" +import { IpcDeviceManagerEvent } from "../constants" -export const connectDeviceRequest = async (id: DeviceId): Promise> => { +export const connectDeviceRequest = async ( + id: DeviceId +): Promise> => { return ipcRenderer.callMain(IpcDeviceManagerEvent.ConnectDevice, id) } diff --git a/libs/core/device-manager/requests/index.ts b/libs/device-manager/feature/src/requests/index.ts similarity index 82% rename from libs/core/device-manager/requests/index.ts rename to libs/device-manager/feature/src/requests/index.ts index 7de1bf4d87..07f35b725e 100644 --- a/libs/core/device-manager/requests/index.ts +++ b/libs/device-manager/feature/src/requests/index.ts @@ -3,4 +3,5 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +export * from "./connect-device.request" export * from "./set-active-device.request" diff --git a/libs/core/device-manager/requests/set-active-device.request.ts b/libs/device-manager/feature/src/requests/set-active-device.request.ts similarity index 68% rename from libs/core/device-manager/requests/set-active-device.request.ts rename to libs/device-manager/feature/src/requests/set-active-device.request.ts index 44f3fc9173..30001e898b 100644 --- a/libs/core/device-manager/requests/set-active-device.request.ts +++ b/libs/device-manager/feature/src/requests/set-active-device.request.ts @@ -5,9 +5,11 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "Core/core/builder" -import { IpcDeviceManagerEvent } from "Core/device-manager/constants" import { DeviceId } from "Core/device/constants/device-id" +import { IpcDeviceManagerEvent } from "../constants" -export const setActiveDeviceRequest = async (id: DeviceId | undefined): Promise> => { +export const setActiveDeviceRequest = async ( + id: DeviceId | undefined +): Promise> => { return ipcRenderer.callMain(IpcDeviceManagerEvent.SetActiveDevice, id) } diff --git a/libs/core/device-manager/selectors/active-device-id.selector.ts b/libs/device-manager/feature/src/selectors/active-device-id.selector.ts similarity index 79% rename from libs/core/device-manager/selectors/active-device-id.selector.ts rename to libs/device-manager/feature/src/selectors/active-device-id.selector.ts index 1234c5a626..8fa81c1042 100644 --- a/libs/core/device-manager/selectors/active-device-id.selector.ts +++ b/libs/device-manager/feature/src/selectors/active-device-id.selector.ts @@ -4,7 +4,7 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" +import { deviceManagerState } from "./device-manager-state.selector" export const activeDeviceIdSelector = createSelector( deviceManagerState, diff --git a/libs/core/device-manager/selectors/device-manager-state.selector.ts b/libs/device-manager/feature/src/selectors/device-manager-state.selector.ts similarity index 77% rename from libs/core/device-manager/selectors/device-manager-state.selector.ts rename to libs/device-manager/feature/src/selectors/device-manager-state.selector.ts index ae53bea7ed..42e9a88af8 100644 --- a/libs/core/device-manager/selectors/device-manager-state.selector.ts +++ b/libs/device-manager/feature/src/selectors/device-manager-state.selector.ts @@ -4,7 +4,7 @@ */ import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceManagerState } from "Core/device-manager/reducers/device-manager.interface" +import { DeviceManagerState } from "../../../models/src/device-manager.interface" export const deviceManagerState = (state: ReduxRootState): DeviceManagerState => state.deviceManager diff --git a/libs/core/device-manager/selectors/get-active-device-base-data.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts similarity index 51% rename from libs/core/device-manager/selectors/get-active-device-base-data.selector.ts rename to libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts index 1c63312729..f9e08d9da5 100644 --- a/libs/core/device-manager/selectors/get-active-device-base-data.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts @@ -4,38 +4,45 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" +import { getCoreDevicesSelector } from "core-device/feature" import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" -import { DeviceState, HarmonyDeviceData, KompaktDeviceData, PureDeviceData } from "Core/device" +import { + DeviceState, + HarmonyDeviceData, + KompaktDeviceData, + PureDeviceData, +} from "Core/device" import { deviceStateSelector } from "Core/device/selectors" +import { deviceManagerState } from "./device-manager-state.selector" export interface DeviceBaseData extends DeviceBaseProperties, - Pick { + Pick { data: Partial } export const getActiveDeviceBaseDataSelector = createSelector( + getCoreDevicesSelector, deviceManagerState, deviceStateSelector, - (deviceManager, deviceState): DeviceBaseData | undefined => { - const { devices, activeDeviceId } = deviceManager - const activeDevice = devices.find(({ id }) => id === activeDeviceId) + (coreDevices, deviceManager, deviceState): DeviceBaseData | undefined => { + const { activeDeviceId } = deviceManager + const activeDevice = coreDevices.find(({ id }) => id === activeDeviceId) - if(activeDevice === undefined){ + if (activeDevice === undefined) { return } - const {data, externalUsageDevice} = deviceState + const { data, externalUsageDevice } = deviceState - if(data === null){ + if (data === null) { return } return { ...activeDevice, data, - externalUsageDevice + externalUsageDevice, } } ) diff --git a/libs/core/device-manager/selectors/get-active-device-type.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device-type.selector.ts similarity index 72% rename from libs/core/device-manager/selectors/get-active-device-type.selector.ts rename to libs/device-manager/feature/src/selectors/get-active-device-type.selector.ts index 14ae517fb0..c4453b00c4 100644 --- a/libs/core/device-manager/selectors/get-active-device-type.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device-type.selector.ts @@ -4,8 +4,8 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" -import { DeviceType } from "Core/device" +import { getActiveDevice } from "./get-active-device.selector" +import { DeviceType } from "device-protocol/models" export const getActiveDeviceTypeSelector = createSelector( getActiveDevice, diff --git a/libs/core/device-manager/selectors/get-active-device.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts similarity index 53% rename from libs/core/device-manager/selectors/get-active-device.selector.ts rename to libs/device-manager/feature/src/selectors/get-active-device.selector.ts index 3ff2257a89..07a12b4cd8 100644 --- a/libs/core/device-manager/selectors/get-active-device.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts @@ -4,13 +4,15 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" -import { Device } from "Core/device-manager/reducers/device-manager.interface" +import { deviceManagerState } from "./device-manager-state.selector" +import { Device } from "core-device/models" +import { getDevicesSelector } from "./get-devices.selector" export const getActiveDevice = createSelector( + getDevicesSelector, deviceManagerState, - (deviceManager): Device | undefined => { - const { devices, activeDeviceId } = deviceManager + (devices, deviceManager): Device | undefined => { + const { activeDeviceId } = deviceManager return devices.find(({ id }) => id === activeDeviceId) } ) diff --git a/libs/core/device-manager/selectors/get-available-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts similarity index 59% rename from libs/core/device-manager/selectors/get-available-devices.selector.ts rename to libs/device-manager/feature/src/selectors/get-available-devices.selector.ts index f23d4a674a..74179f75a0 100644 --- a/libs/core/device-manager/selectors/get-available-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts @@ -4,9 +4,9 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { Device } from "Core/device-manager/reducers/device-manager.interface" -import { getFailedDevicesSelector } from "Core/device-manager/selectors/get-failed-devices.selector" -import { getConfiguredDevicesSelector } from "Core/device-manager/selectors/get-configured-devices.selector" +import { Device } from "core-device/models" +import { getFailedDevicesSelector } from "./get-failed-devices.selector" +import { getConfiguredDevicesSelector } from "./get-configured-devices.selector" export const getAvailableDevicesSelector = createSelector( getConfiguredDevicesSelector, diff --git a/libs/core/device-manager/selectors/get-configured-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts similarity index 57% rename from libs/core/device-manager/selectors/get-configured-devices.selector.ts rename to libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts index 9985883e21..94e072556b 100644 --- a/libs/core/device-manager/selectors/get-configured-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts @@ -4,19 +4,16 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" -import { - Device, - DeviceState, -} from "Core/device-manager/reducers/device-manager.interface" +import { Device, DeviceState } from "core-device/models" import { selectConfiguredDeviceIDs } from "generic-view/store" -import { DeviceType } from "Core/device/constants" +import { DeviceType } from "device-protocol/models" +import { getDevicesSelector } from "./get-devices.selector" export const getConfiguredDevicesSelector = createSelector( - deviceManagerState, + getDevicesSelector, selectConfiguredDeviceIDs, - (deviceManager, apiIds): Device[] => { - return deviceManager.devices.filter(({ state, deviceType, id }) => { + (devices, apiIds): Device[] => { + return devices.filter(({ state, deviceType, id }) => { if (deviceType === DeviceType.APIDevice && apiIds.includes(id)) { return true } diff --git a/libs/device-manager/feature/src/selectors/get-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-devices.selector.ts new file mode 100644 index 0000000000..14b7213669 --- /dev/null +++ b/libs/device-manager/feature/src/selectors/get-devices.selector.ts @@ -0,0 +1,16 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { Device } from "core-device/models" +import { getCoreDevicesSelector } from "core-device/feature" + +export const getDevicesSelector = createSelector( + getCoreDevicesSelector, + (coreDevices): Device[] => { + // TODO: add api devices + return coreDevices + } +) diff --git a/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts new file mode 100644 index 0000000000..6f151e74ff --- /dev/null +++ b/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { getDevicesSelector } from "./get-devices.selector" +import { Device, DeviceState } from "core-device/models" + +export const getFailedDevicesSelector = createSelector( + getDevicesSelector, + (devices): Device[] => { + return devices.filter(({ state }) => state === DeviceState.Failed) + } +) diff --git a/libs/device-manager/feature/src/selectors/index.ts b/libs/device-manager/feature/src/selectors/index.ts new file mode 100644 index 0000000000..67e0379a91 --- /dev/null +++ b/libs/device-manager/feature/src/selectors/index.ts @@ -0,0 +1,18 @@ +/** + * 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 "./active-device-id.selector" +export * from "./device-manager-state.selector" +export * from "./get-active-device-type.selector" +export * from "./get-active-device.selector" +export * from "./get-active-device-base-data.selector" +export * from "./get-available-devices.selector" +export * from "./get-available-devices.selector" +export * from "./get-configured-devices.selector" +export * from "./get-devices.selector" +export * from "./get-failed-devices.selector" +export * from "./is-active-device-attached.selector" +export * from "./is-active-device-set.selector" +export * from "./is-device-list-empty.selector" diff --git a/libs/core/device-manager/selectors/is-active-device-attached.selector.ts b/libs/device-manager/feature/src/selectors/is-active-device-attached.selector.ts similarity index 79% rename from libs/core/device-manager/selectors/is-active-device-attached.selector.ts rename to libs/device-manager/feature/src/selectors/is-active-device-attached.selector.ts index 34e30af511..db593673c8 100644 --- a/libs/core/device-manager/selectors/is-active-device-attached.selector.ts +++ b/libs/device-manager/feature/src/selectors/is-active-device-attached.selector.ts @@ -4,7 +4,7 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" +import { getActiveDevice } from "./get-active-device.selector" export const isActiveDeviceAttachedSelector = createSelector( getActiveDevice, diff --git a/libs/core/device-manager/selectors/is-active-device-set.selector.ts b/libs/device-manager/feature/src/selectors/is-active-device-set.selector.ts similarity index 78% rename from libs/core/device-manager/selectors/is-active-device-set.selector.ts rename to libs/device-manager/feature/src/selectors/is-active-device-set.selector.ts index 2a4e92c5c3..65842e6fcb 100644 --- a/libs/core/device-manager/selectors/is-active-device-set.selector.ts +++ b/libs/device-manager/feature/src/selectors/is-active-device-set.selector.ts @@ -4,7 +4,7 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" +import { deviceManagerState } from "./device-manager-state.selector" export const isActiveDeviceSet = createSelector( deviceManagerState, diff --git a/libs/core/device-manager/selectors/is-device-list-empty.selector.ts b/libs/device-manager/feature/src/selectors/is-device-list-empty.selector.ts similarity index 56% rename from libs/core/device-manager/selectors/is-device-list-empty.selector.ts rename to libs/device-manager/feature/src/selectors/is-device-list-empty.selector.ts index 12f0e67830..566c1da18b 100644 --- a/libs/core/device-manager/selectors/is-device-list-empty.selector.ts +++ b/libs/device-manager/feature/src/selectors/is-device-list-empty.selector.ts @@ -4,11 +4,11 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "Core/device-manager/selectors/device-manager-state.selector" +import { getDevicesSelector } from "./get-devices.selector" export const isDeviceListEmpty = createSelector( - deviceManagerState, - (deviceManager): boolean => { - return deviceManager.devices.length === 0 + getDevicesSelector, + (devices): boolean => { + return devices.length === 0 } ) diff --git a/libs/device-manager/tsconfig.json b/libs/device-manager/feature/tsconfig.json similarity index 88% rename from libs/device-manager/tsconfig.json rename to libs/device-manager/feature/tsconfig.json index 3c41f10fb2..4daaf45cd3 100644 --- a/libs/device-manager/tsconfig.json +++ b/libs/device-manager/feature/tsconfig.json @@ -16,5 +16,5 @@ "path": "./tsconfig.spec.json" } ], - "extends": "../../tsconfig.base.json" + "extends": "../../../tsconfig.base.json" } diff --git a/libs/device-protocol/tsconfig.lib.json b/libs/device-manager/feature/tsconfig.lib.json similarity index 92% rename from libs/device-protocol/tsconfig.lib.json rename to libs/device-manager/feature/tsconfig.lib.json index cfc4843293..21799b3e6b 100644 --- a/libs/device-protocol/tsconfig.lib.json +++ b/libs/device-manager/feature/tsconfig.lib.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "types": [ "node", diff --git a/libs/core-device/tsconfig.spec.json b/libs/device-manager/feature/tsconfig.spec.json similarity index 90% rename from libs/core-device/tsconfig.spec.json rename to libs/device-manager/feature/tsconfig.spec.json index 26ef046ac5..25b7af8f6d 100644 --- a/libs/core-device/tsconfig.spec.json +++ b/libs/device-manager/feature/tsconfig.spec.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "module": "commonjs", "types": ["jest", "node"] }, diff --git a/libs/device-manager/models/.babelrc b/libs/device-manager/models/.babelrc new file mode 100644 index 0000000000..ef4889c1ab --- /dev/null +++ b/libs/device-manager/models/.babelrc @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [ + [ + "styled-components", + { + "pure": true, + "ssr": true + } + ] + ] +} diff --git a/libs/device-manager/models/.eslintrc.json b/libs/device-manager/models/.eslintrc.json new file mode 100644 index 0000000000..cacbe26215 --- /dev/null +++ b/libs/device-manager/models/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/device-manager/models/README.md b/libs/device-manager/models/README.md new file mode 100644 index 0000000000..47f1400a2b --- /dev/null +++ b/libs/device-manager/models/README.md @@ -0,0 +1,7 @@ +# device-manager-models + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test device-manager-models` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-manager/models/jest.config.ts b/libs/device-manager/models/jest.config.ts new file mode 100644 index 0000000000..3efd3505e2 --- /dev/null +++ b/libs/device-manager/models/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "device-manager-models", + preset: "../../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../coverage/libs/device-manager/models", +} diff --git a/libs/core-device/project.json b/libs/device-manager/models/project.json similarity index 58% rename from libs/core-device/project.json rename to libs/device-manager/models/project.json index 062abc5cf8..5b03e6d428 100644 --- a/libs/core-device/project.json +++ b/libs/device-manager/models/project.json @@ -1,7 +1,7 @@ { - "name": "core-device", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/core-device/src", + "name": "device-manager-models", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/device-manager/models/src", "projectType": "library", "tags": [], "targets": { @@ -13,7 +13,7 @@ "executor": "@nx/jest:jest", "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], "options": { - "jestConfig": "libs/core-device/jest.config.ts" + "jestConfig": "libs/device-manager/models/jest.config.ts" } } } diff --git a/libs/device-manager/models/src/device-manager.interface.ts b/libs/device-manager/models/src/device-manager.interface.ts new file mode 100644 index 0000000000..5c9670ed3f --- /dev/null +++ b/libs/device-manager/models/src/device-manager.interface.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 { DeviceId } from "Core/device/constants/device-id" + +export interface DeviceManagerState { + activeDeviceId: DeviceId | undefined + selectDeviceDrawerOpen: boolean +} diff --git a/libs/core/device-manager/constants/event.constant.ts b/libs/device-manager/models/src/event.constant.ts similarity index 73% rename from libs/core/device-manager/constants/event.constant.ts rename to libs/device-manager/models/src/event.constant.ts index 40a379c9ad..c86bf2abe9 100644 --- a/libs/core/device-manager/constants/event.constant.ts +++ b/libs/device-manager/models/src/event.constant.ts @@ -4,11 +4,9 @@ */ export enum DeviceManagerEvent { + ConnectDevice = "device-manager_connect-device", + DeactivateDevice = "device-manager_deactivate-device", HandleDeviceActivated = "device-manager_handle-device-activated", - AddDevice = "device-manager_add-device", - RemoveDevice = "device-manager_remove-device", SetActiveDevice = "device-manager_set-active-device", - DeactivateDevice = "device-manager_deactivate-device", - ConfigureDevice = "device-manager_configure-device", - ConnectDevice = "device-manager_connect-device", + SetSelectDeviceDrawerOpen = "device-manager_set-select-device-drawer-open", } diff --git a/libs/device-manager/models/src/index.ts b/libs/device-manager/models/src/index.ts new file mode 100644 index 0000000000..20c1458f7c --- /dev/null +++ b/libs/device-manager/models/src/index.ts @@ -0,0 +1,7 @@ +/** + * 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 "./device-manager.interface" +export * from "./event.constant" diff --git a/libs/device-manager/models/tsconfig.json b/libs/device-manager/models/tsconfig.json new file mode 100644 index 0000000000..4daaf45cd3 --- /dev/null +++ b/libs/device-manager/models/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../../tsconfig.base.json" +} diff --git a/libs/device-manager/models/tsconfig.lib.json b/libs/device-manager/models/tsconfig.lib.json new file mode 100644 index 0000000000..21799b3e6b --- /dev/null +++ b/libs/device-manager/models/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/device-manager/models/tsconfig.spec.json b/libs/device-manager/models/tsconfig.spec.json new file mode 100644 index 0000000000..25b7af8f6d --- /dev/null +++ b/libs/device-manager/models/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/libs/device-protocol/README.md b/libs/device-protocol/README.md deleted file mode 100644 index 05cae1f828..0000000000 --- a/libs/device-protocol/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# device-protocol - -This library was generated with [Nx](https://nx.dev). - -## Running unit tests - -Run `nx test device-protocol` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-protocol/.babelrc b/libs/device-protocol/feature/.babelrc similarity index 100% rename from libs/device-protocol/.babelrc rename to libs/device-protocol/feature/.babelrc diff --git a/libs/device-protocol/feature/.eslintrc.json b/libs/device-protocol/feature/.eslintrc.json new file mode 100644 index 0000000000..cacbe26215 --- /dev/null +++ b/libs/device-protocol/feature/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/device-protocol/feature/README.md b/libs/device-protocol/feature/README.md new file mode 100644 index 0000000000..cc20b42843 --- /dev/null +++ b/libs/device-protocol/feature/README.md @@ -0,0 +1,7 @@ +# device-protocol-feature + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test device-protocol-feature` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-protocol/feature/jest.config.ts b/libs/device-protocol/feature/jest.config.ts new file mode 100644 index 0000000000..432bda00ad --- /dev/null +++ b/libs/device-protocol/feature/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "device-protocol-feature", + preset: "../../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../../coverage/libs/device-protocol/feature", +} diff --git a/libs/device-protocol/feature/project.json b/libs/device-protocol/feature/project.json new file mode 100644 index 0000000000..e092a13994 --- /dev/null +++ b/libs/device-protocol/feature/project.json @@ -0,0 +1,20 @@ +{ + "name": "device-protocol-feature", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/device-protocol-feature/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/device-protocol/feature/jest.config.ts" + } + } + } +} diff --git a/libs/core/device-manager/constants/error.constant.ts b/libs/device-protocol/feature/src/constants/error.constant.ts similarity index 66% rename from libs/core/device-manager/constants/error.constant.ts rename to libs/device-protocol/feature/src/constants/error.constant.ts index d46dc2e407..36f578aafd 100644 --- a/libs/core/device-manager/constants/error.constant.ts +++ b/libs/device-protocol/feature/src/constants/error.constant.ts @@ -4,7 +4,5 @@ */ export enum DeviceManagerError { - NoActiveDevice = "NO_ACTIVE_DEVICE_ERROR", CannotFindDevice = "CANNOT_FIND_DEVICE_ERROR", - CannotInitializeDeviceObject = "CANNOT_INITIALIZE_DEVICE_OBJECT_ERROR", } diff --git a/libs/device-manager/src/index.ts b/libs/device-protocol/feature/src/constants/index.ts similarity index 81% rename from libs/device-manager/src/index.ts rename to libs/device-protocol/feature/src/constants/index.ts index e6a6939657..2a7dd1c8c8 100644 --- a/libs/device-manager/src/index.ts +++ b/libs/device-protocol/feature/src/constants/index.ts @@ -2,3 +2,5 @@ * 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 "./error.constant" diff --git a/libs/core/device-manager/device-manager.module.ts b/libs/device-protocol/feature/src/device-protocol.module.ts similarity index 63% rename from libs/core/device-manager/device-manager.module.ts rename to libs/device-protocol/feature/src/device-protocol.module.ts index d5f1001f72..d600d684e9 100644 --- a/libs/core/device-manager/device-manager.module.ts +++ b/libs/device-protocol/feature/src/device-protocol.module.ts @@ -10,15 +10,13 @@ import { FileSystemService } from "Core/file-system/services/file-system.service import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" -import { DeviceManager } from "Core/device-manager/services" -import { UsbDeviceDetectionObserver } from "Core/device-manager/observers" -import { DeviceManagerController } from "Core/device-manager/controllers" -import { DeviceCacheConfigurationService } from "Core/device-manager/services/device-cache-configuration.service" +import { DeviceProtocolService } from "./services" +import { UsbDeviceDetectionObserver } from "./observers" -export class DeviceManagerModule extends BaseModule { +export class DeviceProtocolModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceManager, + public deviceManager: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -39,13 +37,8 @@ export class DeviceManagerModule extends BaseModule { this.deviceManager ) - const deviceManagerController = new DeviceManagerController( - this.deviceManager, - new DeviceCacheConfigurationService(this.fileSystem) - ) - this.initializers = [] this.observers = [usbDeviceDetectionObserver] - this.controllers = [deviceManagerController] + this.controllers = [] } } diff --git a/libs/device-protocol/feature/src/index.ts b/libs/device-protocol/feature/src/index.ts new file mode 100644 index 0000000000..878afe26b3 --- /dev/null +++ b/libs/device-protocol/feature/src/index.ts @@ -0,0 +1,7 @@ +/** + * 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 "./device-protocol.module" +export * from "./services" diff --git a/libs/core/device-manager/observers/index.ts b/libs/device-protocol/feature/src/observers/index.ts similarity index 100% rename from libs/core/device-manager/observers/index.ts rename to libs/device-protocol/feature/src/observers/index.ts diff --git a/libs/core/device-manager/observers/usb-device-detection.observer.ts b/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts similarity index 90% rename from libs/core/device-manager/observers/usb-device-detection.observer.ts rename to libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts index 080d100d3c..f95387e965 100644 --- a/libs/core/device-manager/observers/usb-device-detection.observer.ts +++ b/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts @@ -4,16 +4,16 @@ */ import { Observer } from "Core/core/types" -import { DeviceManager } from "Core/device-manager/services" import { ipcMain } from "electron-better-ipc" import { ApiSerialPortToRendererEvents } from "device/models" import { SerialPortDeviceAdapterEvent } from "Core/device/modules/mudita-os/adapters" +import { DeviceProtocolService } from "../services" const intervalTime = 3000 export class UsbDeviceDetectionObserver implements Observer { private previousAttachedDevicePaths = new Set() - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} public observe(): void { void this.watchAttachedDevices() @@ -35,13 +35,13 @@ export class UsbDeviceDetectionObserver implements Observer { private mountListeners() { ipcMain.on(ApiSerialPortToRendererEvents.Closed, () => { void this.detectDeviceStateChange() - }); + }) ipcMain.on(SerialPortDeviceAdapterEvent.Closed, () => { void this.detectDeviceStateChange() - }); + }) } - private async detectDeviceStateChange(): Promise { + private async detectDeviceStateChange(): Promise { const attachedDevices = await this.deviceManager.getAttachedDevices() const detachedDevicePaths = Array.from( this.previousAttachedDevicePaths diff --git a/libs/core/device-manager/services/serial-port-list.helper.ts b/libs/device-protocol/feature/src/serial-port-list.helper.ts similarity index 100% rename from libs/core/device-manager/services/serial-port-list.helper.ts rename to libs/device-protocol/feature/src/serial-port-list.helper.ts diff --git a/libs/core/device-manager/services/device-manager.service.ts b/libs/device-protocol/feature/src/services/device-protocol.service.ts similarity index 89% rename from libs/core/device-manager/services/device-manager.service.ts rename to libs/device-protocol/feature/src/services/device-protocol.service.ts index bdce4009cd..bcadd13a73 100644 --- a/libs/core/device-manager/services/device-manager.service.ts +++ b/libs/device-protocol/feature/src/services/device-protocol.service.ts @@ -6,13 +6,11 @@ import { PortInfo as SerialPortInfo } from "serialport" import { Mutex } from "async-mutex" import { EventEmitter } from "events" -import { IDeviceResolverService } from "Core/device-manager/services/device-resolver.service" +import { callRenderer } from "shared/utils" +import { DeviceCommunicationError } from "core-device/models" +import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" -import { PortInfo } from "Core/device-manager/types" -import { PortInfoValidator } from "Core/device-manager/validators" -import { DeviceManagerError } from "Core/device-manager/constants" -import { DeviceManagerMainEvent } from "shared/utils" import logger from "Core/__deprecated__/main/utils/logger" import { DeviceId } from "Core/device/constants/device-id" import { log } from "Core/core/decorators/log.decorator" @@ -20,12 +18,14 @@ import { APIDevice } from "device/feature" import { BaseDevice } from "Core/device/modules/base-device" import { CoreDevice } from "Core/device/modules/core-device" import { RequestConfig } from "Core/device/types/mudita-os" -import { DeviceCommunicationError, DeviceType } from "Core/device" import { MockCoreDevice } from "Core/device/modules/mock-core-device" -import { callRenderer } from "shared/utils" -import { getSerialPortList } from "./serial-port-list.helper" +import { PortInfo } from "../types" +import { getSerialPortList } from "../serial-port-list.helper" +import { DeviceManagerError } from "../constants" +import { PortInfoValidator } from "../validators" +import { IDeviceResolverService } from "./device-resolver.service" -export class DeviceManager { +export class DeviceProtocolService { public activeDevice: BaseDevice | undefined public devicesMap = new Map() @@ -124,7 +124,7 @@ export class DeviceManager { } const data = device.toSerializableObject() - callRenderer(DeviceManagerMainEvent.DeviceDetached, data) + callRenderer(DeviceProtocolMainEvent.DeviceDetached, data) logger.info(`Detached device with path: ${path}`) } @@ -161,9 +161,9 @@ export class DeviceManager { const result = await device.connect() const data = device.toSerializableObject() if (result.ok) { - callRenderer(DeviceManagerMainEvent.DeviceConnected, data) + callRenderer(DeviceProtocolMainEvent.DeviceConnected, data) } else { - callRenderer(DeviceManagerMainEvent.DeviceConnectFailed, data) + callRenderer(DeviceProtocolMainEvent.DeviceConnectFailed, data) } } diff --git a/libs/core/device-manager/services/device-resolver.service.test.ts b/libs/device-protocol/feature/src/services/device-resolver.service.test.ts similarity index 87% rename from libs/core/device-manager/services/device-resolver.service.test.ts rename to libs/device-protocol/feature/src/services/device-resolver.service.test.ts index 3712a66436..94420a02e7 100644 --- a/libs/core/device-manager/services/device-resolver.service.test.ts +++ b/libs/device-protocol/feature/src/services/device-resolver.service.test.ts @@ -3,8 +3,9 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { ProductID, DeviceType } from "Core/device/constants" -import { DeviceResolverService } from "Core/device-manager/services/device-resolver.service" +import { DeviceType } from "device-protocol/models" +import { ProductID } from "Core/device/constants" +import { DeviceResolverService } from "../services" const subject = new DeviceResolverService() diff --git a/libs/core/device-manager/services/device-resolver.service.ts b/libs/device-protocol/feature/src/services/device-resolver.service.ts similarity index 96% rename from libs/core/device-manager/services/device-resolver.service.ts rename to libs/device-protocol/feature/src/services/device-resolver.service.ts index d74f952d54..d1febe5cdd 100644 --- a/libs/core/device-manager/services/device-resolver.service.ts +++ b/libs/device-protocol/feature/src/services/device-resolver.service.ts @@ -4,13 +4,13 @@ */ import { PortInfo } from "serialport" +import { APIDevice } from "device/feature" +import { DeviceType } from "device-protocol/models" import { MuditaPureDescriptor, MuditaHarmonyDescriptor, } from "Core/device/descriptors" import { DeviceFactory } from "Core/device/factories" -import { APIDevice } from "device/feature" -import { DeviceType } from "Core/device" import { BaseDevice } from "Core/device/modules/base-device" export interface IDeviceResolverService { diff --git a/libs/core/device-manager/services/index.ts b/libs/device-protocol/feature/src/services/index.ts similarity index 82% rename from libs/core/device-manager/services/index.ts rename to libs/device-protocol/feature/src/services/index.ts index 479f0d19e3..3154cff802 100644 --- a/libs/core/device-manager/services/index.ts +++ b/libs/device-protocol/feature/src/services/index.ts @@ -3,5 +3,5 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export * from "./device-manager.service" +export * from "./device-protocol.service" export * from "./device-resolver.service" diff --git a/libs/core/device-manager/types/index.ts b/libs/device-protocol/feature/src/types/index.ts similarity index 100% rename from libs/core/device-manager/types/index.ts rename to libs/device-protocol/feature/src/types/index.ts diff --git a/libs/core/device-manager/types/port.type.ts b/libs/device-protocol/feature/src/types/port.type.ts similarity index 100% rename from libs/core/device-manager/types/port.type.ts rename to libs/device-protocol/feature/src/types/port.type.ts diff --git a/libs/core/device-manager/validators/index.ts b/libs/device-protocol/feature/src/validators/index.ts similarity index 100% rename from libs/core/device-manager/validators/index.ts rename to libs/device-protocol/feature/src/validators/index.ts diff --git a/libs/core/device-manager/validators/port-info.validator.test.ts b/libs/device-protocol/feature/src/validators/port-info.validator.test.ts similarity index 100% rename from libs/core/device-manager/validators/port-info.validator.test.ts rename to libs/device-protocol/feature/src/validators/port-info.validator.test.ts diff --git a/libs/core/device-manager/validators/port-info.validator.ts b/libs/device-protocol/feature/src/validators/port-info.validator.ts similarity index 98% rename from libs/core/device-manager/validators/port-info.validator.ts rename to libs/device-protocol/feature/src/validators/port-info.validator.ts index b3058650a3..ea0e59fb5b 100644 --- a/libs/core/device-manager/validators/port-info.validator.ts +++ b/libs/device-protocol/feature/src/validators/port-info.validator.ts @@ -8,7 +8,7 @@ import { MuditaHarmonyDescriptor, MuditaKompaktDescriptor, MuditaPureDescriptor, -} from "../../device/descriptors" +} from "Core/device/descriptors" export class PortInfoValidator { static eligibleDevices = [ diff --git a/libs/device-protocol/feature/tsconfig.json b/libs/device-protocol/feature/tsconfig.json new file mode 100644 index 0000000000..4daaf45cd3 --- /dev/null +++ b/libs/device-protocol/feature/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../../tsconfig.base.json" +} diff --git a/libs/device-protocol/feature/tsconfig.lib.json b/libs/device-protocol/feature/tsconfig.lib.json new file mode 100644 index 0000000000..21799b3e6b --- /dev/null +++ b/libs/device-protocol/feature/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/device-protocol/feature/tsconfig.spec.json b/libs/device-protocol/feature/tsconfig.spec.json new file mode 100644 index 0000000000..25b7af8f6d --- /dev/null +++ b/libs/device-protocol/feature/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/libs/device-protocol/models/.babelrc b/libs/device-protocol/models/.babelrc new file mode 100644 index 0000000000..ef4889c1ab --- /dev/null +++ b/libs/device-protocol/models/.babelrc @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [ + [ + "styled-components", + { + "pure": true, + "ssr": true + } + ] + ] +} diff --git a/libs/device-protocol/models/.eslintrc.json b/libs/device-protocol/models/.eslintrc.json new file mode 100644 index 0000000000..cacbe26215 --- /dev/null +++ b/libs/device-protocol/models/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/device-protocol/models/README.md b/libs/device-protocol/models/README.md new file mode 100644 index 0000000000..b9142dccf6 --- /dev/null +++ b/libs/device-protocol/models/README.md @@ -0,0 +1,7 @@ +# device-protocol-models + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test device-protocol-models` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/device-protocol/models/jest.config.ts b/libs/device-protocol/models/jest.config.ts new file mode 100644 index 0000000000..9e92770f18 --- /dev/null +++ b/libs/device-protocol/models/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "device-protocol-models", + preset: "../../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../../coverage/libs/device-protocol/models", +} diff --git a/libs/device-protocol/models/project.json b/libs/device-protocol/models/project.json new file mode 100644 index 0000000000..e131348c4b --- /dev/null +++ b/libs/device-protocol/models/project.json @@ -0,0 +1,20 @@ +{ + "name": "device-protocol-models", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/device-protocol/models/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/device-protocol/models/jest.config.ts" + } + } + } +} diff --git a/libs/device-protocol/models/src/device-protocol-main-event.ts b/libs/device-protocol/models/src/device-protocol-main-event.ts new file mode 100644 index 0000000000..430e6e86fb --- /dev/null +++ b/libs/device-protocol/models/src/device-protocol-main-event.ts @@ -0,0 +1,10 @@ +/** + * 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 DeviceProtocolMainEvent { + DeviceDetached = "device-protocol/device-detached", + DeviceConnected = "device-protocol/device-connected", + DeviceConnectFailed = "device-protocol/device-connect-failed", +} diff --git a/libs/core/device/constants/device-type.constant.ts b/libs/device-protocol/models/src/device-type.constant.ts similarity index 100% rename from libs/core/device/constants/device-type.constant.ts rename to libs/device-protocol/models/src/device-type.constant.ts diff --git a/libs/device-protocol/models/src/index.ts b/libs/device-protocol/models/src/index.ts new file mode 100644 index 0000000000..f3133bbb27 --- /dev/null +++ b/libs/device-protocol/models/src/index.ts @@ -0,0 +1,7 @@ +/** + * 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 "./device-protocol-main-event" +export * from "./device-type.constant" diff --git a/libs/device-protocol/models/tsconfig.json b/libs/device-protocol/models/tsconfig.json new file mode 100644 index 0000000000..4daaf45cd3 --- /dev/null +++ b/libs/device-protocol/models/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../../tsconfig.base.json" +} diff --git a/libs/device-protocol/models/tsconfig.lib.json b/libs/device-protocol/models/tsconfig.lib.json new file mode 100644 index 0000000000..21799b3e6b --- /dev/null +++ b/libs/device-protocol/models/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/device-protocol/models/tsconfig.spec.json b/libs/device-protocol/models/tsconfig.spec.json new file mode 100644 index 0000000000..25b7af8f6d --- /dev/null +++ b/libs/device-protocol/models/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/libs/device/feature/src/lib/api-config/api-config.service.ts b/libs/device/feature/src/lib/api-config/api-config.service.ts index 7c390050fa..e3caf42058 100644 --- a/libs/device/feature/src/lib/api-config/api-config.service.ts +++ b/libs/device/feature/src/lib/api-config/api-config.service.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { @@ -17,7 +17,7 @@ import { AppError } from "Core/core/errors" import { APIConfigError } from "./api-config-error" export class APIConfigService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} @IpcEvent(APIConfigServiceEvents.APIConfig) public async getAPIConfig( diff --git a/libs/device/feature/src/lib/api-device.ts b/libs/device/feature/src/lib/api-device.ts index d98494edfe..3d95738c88 100644 --- a/libs/device/feature/src/lib/api-device.ts +++ b/libs/device/feature/src/lib/api-device.ts @@ -12,7 +12,7 @@ import { APIRequestWithPayload, } from "device/models" import { BaseDevice } from "Core/device/modules/base-device" -import { DeviceType } from "Core/device" +import { DeviceType } from "device-protocol/models" import { ResultObject } from "Core/core/builder" import logger from "Core/__deprecated__/main/utils/logger" diff --git a/libs/device/feature/src/lib/api-features/api-features.service.ts b/libs/device/feature/src/lib/api-features/api-features.service.ts index 03361856cc..a439899f58 100644 --- a/libs/device/feature/src/lib/api-features/api-features.service.ts +++ b/libs/device/feature/src/lib/api-features/api-features.service.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { @@ -21,7 +21,7 @@ import { DeviceId } from "Core/device/constants/device-id" import { View } from "generic-view/utils" export class APIFeaturesService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} @IpcEvent(APIFeaturesServiceEvents.FeatureConfiguration) public async getFeatureConfiguration({ diff --git a/libs/device/feature/src/lib/api-module.ts b/libs/device/feature/src/lib/api-module.ts index 9f24eb31ce..c2dd8b2167 100644 --- a/libs/device/feature/src/lib/api-module.ts +++ b/libs/device/feature/src/lib/api-module.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { APIConfigService } from "./api-config/api-config.service" import { APIFeaturesService } from "./api-features/api-features.service" import { APIBackupService } from "./backup" @@ -14,10 +14,10 @@ import { ServerService } from "./server/server.service" import { APIFileTransferService } from "./file-transfer" import { ServiceBridge } from "./service-bridge" import { SystemUtilsModule } from "system-utils/feature" -import { createSettingsService } from "Core/settings/containers/settings.container" import { APIRestoreService } from "./restore" import { DeviceSystemActionsService } from "./device-system-actions/device-system-actions.service" import { APIDataTransferService } from "./data-transfer" +import { ISettingsService } from "shared/utils" export class APIModule { private apiConfigService: APIConfigService @@ -34,8 +34,9 @@ export class APIModule { private apiDataTransferService: APIDataTransferService constructor( - deviceManager: DeviceManager, - systemUtilsModule: SystemUtilsModule + deviceManager: DeviceProtocolService, + systemUtilsModule: SystemUtilsModule, + settingsService: ISettingsService ) { this.serviceBridge = new ServiceBridge() this.apiConfigService = new APIConfigService(deviceManager) @@ -59,7 +60,8 @@ export class APIModule { ) this.serviceBridge.systemUtilsModule = systemUtilsModule this.serviceBridge.fileTransfer = this.fileTransferService - this.serviceBridge.settingsService = createSettingsService() + // @ts-ignore + this.serviceBridge.settingsService = settingsService this.serviceBridge.fileManager = this.fileManager this.serviceBridge.deviceSystemActions = this.deviceSystemActionsService } diff --git a/libs/device/feature/src/lib/backup/backup.service.ts b/libs/device/feature/src/lib/backup/backup.service.ts index 010190cf6f..0c426f4864 100644 --- a/libs/device/feature/src/lib/backup/backup.service.ts +++ b/libs/device/feature/src/lib/backup/backup.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiResponse } from "Core/device/types/mudita-os" import { @@ -19,7 +19,7 @@ import { import random from "lodash/random" export class APIBackupService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} @IpcEvent(APIBackupServiceEvents.StartPreBackup) public async startPreBackup({ diff --git a/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts b/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts index 91506e8bec..5f246cb28d 100644 --- a/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts +++ b/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiResponse } from "Core/device/types/mudita-os" import { @@ -22,7 +22,7 @@ import { import random from "lodash/random" export class APIDataTransferService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} @IpcEvent(APIDataTransferServiceEvents.StartPreDataTransfer) public async startPreDataTransfer({ diff --git a/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts b/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts index 34c11cc798..b04d9de18e 100644 --- a/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts +++ b/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts @@ -3,14 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { GeneralError, DeviceSystemActionsServiceEvents } from "device/models" import { IpcEvent } from "Core/core/decorators" export class DeviceSystemActionsService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} private async sendSystemRequest( action: string, diff --git a/libs/device/feature/src/lib/file-manager/file-manager.service.ts b/libs/device/feature/src/lib/file-manager/file-manager.service.ts index caf103ea23..89c690ff5d 100644 --- a/libs/device/feature/src/lib/file-manager/file-manager.service.ts +++ b/libs/device/feature/src/lib/file-manager/file-manager.service.ts @@ -8,7 +8,7 @@ import { IpcEvent } from "Core/core/decorators" import { ServiceBridge } from "../service-bridge" import { FileManagerServiceEvents, GeneralError } from "device/models" import { AppError } from "Core/core/errors" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import packageInfo from "../../../../../../apps/mudita-center/package.json" import { @@ -28,7 +28,7 @@ export class FileManager { private files: Record = {} constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private serviceBridge: ServiceBridge ) {} diff --git a/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts b/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts index 958f9ece22..132d81eb21 100644 --- a/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts +++ b/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError, AppErrorType } from "Core/core/errors" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiFileTransferError, @@ -38,7 +38,7 @@ const DEFAULT_MAX_REPEATS = 2 export class APIFileTransferService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private serviceBridge: ServiceBridge, private transfers: Record = {} ) {} diff --git a/libs/device/feature/src/lib/menu/menu.service.ts b/libs/device/feature/src/lib/menu/menu.service.ts index 5eb220c402..4b7ded54ee 100644 --- a/libs/device/feature/src/lib/menu/menu.service.ts +++ b/libs/device/feature/src/lib/menu/menu.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { APIMenuServiceEvents, GeneralError, @@ -16,7 +16,7 @@ import { import { DeviceId } from "Core/device/constants/device-id" export class APIMenuService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} @IpcEvent(APIMenuServiceEvents.GetMenuConfig) public async getMenuConfig( diff --git a/libs/device/feature/src/lib/outbox/outbox.service.ts b/libs/device/feature/src/lib/outbox/outbox.service.ts index f104fde898..9ebf6a23d5 100644 --- a/libs/device/feature/src/lib/outbox/outbox.service.ts +++ b/libs/device/feature/src/lib/outbox/outbox.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { APIOutboxServiceEvents, @@ -16,7 +16,7 @@ import { } from "device/models" export class APIOutboxService { - constructor(private deviceManager: DeviceManager) {} + constructor(private deviceManager: DeviceProtocolService) {} @IpcEvent(APIOutboxServiceEvents.GetOutboxData) public async getOutboxData( diff --git a/libs/device/feature/src/lib/restore/restore.service.ts b/libs/device/feature/src/lib/restore/restore.service.ts index f1f859efca..16a9f8fd56 100644 --- a/libs/device/feature/src/lib/restore/restore.service.ts +++ b/libs/device/feature/src/lib/restore/restore.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceManager } from "Core/device-manager/services" +import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiResponse } from "Core/device/types/mudita-os" import { @@ -24,7 +24,7 @@ import { ServiceBridge } from "../service-bridge" export class APIRestoreService { constructor( - private deviceManager: DeviceManager, + private deviceManager: DeviceProtocolService, private serviceBridge: ServiceBridge ) {} diff --git a/libs/e2e-mock/server/src/lib/mock-data-resolver-service.ts b/libs/e2e-mock/server/src/lib/mock-data-resolver-service.ts index d4aa66eeed..4f12b00c92 100644 --- a/libs/e2e-mock/server/src/lib/mock-data-resolver-service.ts +++ b/libs/e2e-mock/server/src/lib/mock-data-resolver-service.ts @@ -3,11 +3,11 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { IDeviceResolverService } from "Core/device-manager/services" +import { DeviceType } from "device-protocol/models" +import { IDeviceResolverService } from "device-protocol/feature" import { BaseDevice } from "Core/device/modules/base-device" import { PortInfo } from "serialport" import { MockDevice } from "./mock-device/mock-device" -import { DeviceType } from "Core/device" export class MockDeviceResolverService implements IDeviceResolverService { public resolve(portInfo: PortInfo): BaseDevice | undefined { diff --git a/libs/e2e-mock/server/src/lib/mock-device/mock-device.ts b/libs/e2e-mock/server/src/lib/mock-device/mock-device.ts index 29c34458aa..8af18198c9 100644 --- a/libs/e2e-mock/server/src/lib/mock-device/mock-device.ts +++ b/libs/e2e-mock/server/src/lib/mock-device/mock-device.ts @@ -4,7 +4,8 @@ */ import { Result, ResultObject } from "Core/core/builder" -import { DeviceType, ResponseStatus } from "Core/device" +import { ResponseStatus } from "Core/device" +import { DeviceType } from "device-protocol/models" import { DeviceError } from "Core/device/modules/mudita-os/constants" import { BaseDevice } from "Core/device/modules/base-device" import { ApiResponse } from "Core/device/types/mudita-os" diff --git a/libs/generic-view/store/src/lib/data-migration/start-data.migration.ts b/libs/generic-view/store/src/lib/data-migration/start-data.migration.ts index d00009d6cd..2ae8c9dd5d 100644 --- a/libs/generic-view/store/src/lib/data-migration/start-data.migration.ts +++ b/libs/generic-view/store/src/lib/data-migration/start-data.migration.ts @@ -4,14 +4,14 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { ActionName } from "../action-names" +import { DeviceCommunicationError } from "core-device/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceCommunicationError } from "Core/device" import { getDeviceInfoRequest } from "Core/device-info/requests" -import { setDataMigrationStatus } from "./actions" import { unlockDeviceStatusRequest } from "Core/device/requests" import { versionFormatter } from "Core/update/helpers" import isVersionGreaterOrEqual from "Core/utils/is-version-greater-or-equal" +import { ActionName } from "../action-names" +import { setDataMigrationStatus } from "./actions" export const startDataMigration = createAsyncThunk< void, diff --git a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts index 608de56637..6804640e0a 100644 --- a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts +++ b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts @@ -3,14 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { Device } from "Core/device-manager/reducers/device-manager.interface" import { useEffect } from "react" +import { Device } from "core-device/models" +import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" import { useDispatch, useSelector } from "react-redux" -import { answerMain, DeviceManagerMainEvent } from "shared/utils" +import { answerMain } from "shared/utils" import { detachDevice } from "../views/actions" import { getAPIConfig } from "../get-api-config" import { Dispatch } from "Core/__deprecated__/renderer/store" -import { DeviceType } from "Core/device" import { setBackupProcessStatus } from "../backup/actions" import { closeAllModals } from "../modals/actions" import { selectBackupProcessStatus } from "../selectors" @@ -22,7 +22,7 @@ export const useAPISerialPortListeners = () => { useEffect(() => { const unregisterFailListener = answerMain( - DeviceManagerMainEvent.DeviceConnectFailed, + DeviceProtocolMainEvent.DeviceConnectFailed, (properties) => { const { deviceType } = properties if (deviceType !== DeviceType.APIDevice) { @@ -33,7 +33,7 @@ export const useAPISerialPortListeners = () => { } ) const unregisterConnectListener = answerMain( - DeviceManagerMainEvent.DeviceConnected, + DeviceProtocolMainEvent.DeviceConnected, (properties) => { const { id, deviceType } = properties if (deviceType !== DeviceType.APIDevice) { @@ -43,7 +43,7 @@ export const useAPISerialPortListeners = () => { } ) const unregisterDetachedListener = answerMain( - DeviceManagerMainEvent.DeviceDetached, + DeviceProtocolMainEvent.DeviceDetached, async (properties) => { const { id, deviceType } = properties dispatch(clearDataMigrationDevice(id)) diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts index 0ef28dd4d8..b394f9eaff 100644 --- a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts +++ b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts @@ -16,7 +16,7 @@ const messages = { } export const selectDataMigrationSourceDevices = createSelector( - (state: ReduxRootState) => state.deviceManager.devices, + (state: ReduxRootState) => state.coreDevice.devices, (devices) => devices .filter(({ deviceType }) => deviceType === "MuditaPure") diff --git a/libs/generic-view/ui/src/lib/predefined/data-migration/components/pure-passcode.tsx b/libs/generic-view/ui/src/lib/predefined/data-migration/components/pure-passcode.tsx index 32ac562ea5..344e8f547d 100644 --- a/libs/generic-view/ui/src/lib/predefined/data-migration/components/pure-passcode.tsx +++ b/libs/generic-view/ui/src/lib/predefined/data-migration/components/pure-passcode.tsx @@ -10,6 +10,7 @@ import React, { useRef, useState, } from "react" +import { DeviceCommunicationError } from "core-device/models" import { ErrorMessageMap, ErrorState, @@ -22,7 +23,7 @@ import PasscodeModalUI from "Core/device-initialization/components/passcode-moda import { ipcRenderer } from "electron-better-ipc" import { HelpActions } from "Core/__deprecated__/common/enums/help-actions.enum" import { deviceLockTimeRequest } from "Core/device/requests" -import { DeviceCommunicationError, unlockDeviceById } from "Core/device" +import { unlockDeviceById } from "Core/device" import { PayloadAction } from "@reduxjs/toolkit" import { getDeviceInfoRequest } from "Core/device-info/requests" diff --git a/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx b/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx index 5369c3c834..7620d76ac3 100644 --- a/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx +++ b/libs/generic-view/ui/src/lib/predefined/data-migration/data-migration.tsx @@ -12,9 +12,11 @@ import React, { useRef, useState, } from "react" +import { defineMessages } from "react-intl" +import { useDispatch, useSelector } from "react-redux" import { APIFC } from "generic-view/utils" import { McDataMigrationConfig } from "generic-view/models" -import { useDispatch, useSelector } from "react-redux" +import { getActiveDevice } from "device-manager/feature" import { clearDataMigrationProgress, performDataMigration, @@ -38,8 +40,6 @@ import { modalTransitionDuration, } from "generic-view/theme" import { Device } from "./components/device-card" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" -import { defineMessages } from "react-intl" import { intl } from "Core/__deprecated__/renderer/utils/intl" import { Dispatch } from "Core/__deprecated__/renderer/store" import { PureErrorModal } from "./components/pure-error-modal" diff --git a/libs/shared/feature/src/lib/use-data-migration-device-selector.ts b/libs/shared/feature/src/lib/use-data-migration-device-selector.ts index 68778d5fe7..45d0635bcb 100644 --- a/libs/shared/feature/src/lib/use-data-migration-device-selector.ts +++ b/libs/shared/feature/src/lib/use-data-migration-device-selector.ts @@ -6,11 +6,13 @@ import { useCallback } from "react" import { DeviceId } from "Core/device/constants/device-id" import { setSourceDevice } from "generic-view/store" -import { deactivateDevice } from "Core/device-manager/actions/deactivate-device.action" -import { handleDeviceActivated } from "Core/device-manager/actions/handle-device-activated.action" +import { + deactivateDevice, + getActiveDevice, + handleDeviceActivated, +} from "device-manager/feature" import { URL_DEVICE_INITIALIZATION } from "Core/__deprecated__/renderer/constants/urls" import { useDispatch, useSelector } from "react-redux" -import { getActiveDevice } from "Core/device-manager/selectors/get-active-device.selector" import { Dispatch } from "Core/__deprecated__/renderer/store" import { useHistory } from "react-router-dom" diff --git a/libs/shared/utils/src/index.ts b/libs/shared/utils/src/index.ts index e1047eb3d4..9b03d09def 100644 --- a/libs/shared/utils/src/index.ts +++ b/libs/shared/utils/src/index.ts @@ -9,3 +9,4 @@ export * from "./lib/delay" export * from "./lib/get-main-app-window" export * from "./lib/routes-history.context" export * from "./lib/main-event.constant" +export * from "./lib/settings-service.interface" diff --git a/libs/shared/utils/src/lib/call-renderer.helper.ts b/libs/shared/utils/src/lib/call-renderer.helper.ts index cf7ff43c33..add028924e 100644 --- a/libs/shared/utils/src/lib/call-renderer.helper.ts +++ b/libs/shared/utils/src/lib/call-renderer.helper.ts @@ -4,18 +4,19 @@ */ import { ipcMain } from "electron-better-ipc" -import { LoggerFactory } from "Core/core/factories" import { ApiSerialPortToRendererEvents } from "device/models" +import { AppUpdateEvent } from "electron/application-updater" +import { DeviceProtocolMainEvent } from "device-protocol/models" +import { LoggerFactory } from "Core/core/factories" import { PureStrategyMainEvent } from "Core/device/strategies" import { getMainAppWindow } from "./get-main-app-window" -import { AppEvents, DeviceManagerMainEvent } from "./main-event.constant" -import { AppUpdateEvent } from "electron/application-updater" +import { AppEvents } from "./main-event.constant" const logger = LoggerFactory.getInstance() export type CallRendererEvent = | ApiSerialPortToRendererEvents - | DeviceManagerMainEvent + | DeviceProtocolMainEvent | AppEvents | PureStrategyMainEvent | AppUpdateEvent diff --git a/libs/shared/utils/src/lib/main-event.constant.ts b/libs/shared/utils/src/lib/main-event.constant.ts index 611da78c0d..2e5d8f3fb8 100644 --- a/libs/shared/utils/src/lib/main-event.constant.ts +++ b/libs/shared/utils/src/lib/main-event.constant.ts @@ -3,12 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export enum DeviceManagerMainEvent { - DeviceDetached = "device-manager-device-detached", - DeviceConnected = "device-manager-device-connected", - DeviceConnectFailed = "device-manager-device-connect-failed", -} - export enum AppEvents { WindowFocused = "app-events-window-focused", } diff --git a/libs/shared/utils/src/lib/settings-service.interface.ts b/libs/shared/utils/src/lib/settings-service.interface.ts new file mode 100644 index 0000000000..f9aecfbc8c --- /dev/null +++ b/libs/shared/utils/src/lib/settings-service.interface.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { Settings, SettingsUpdateOption } from "Core/settings/dto" +import { SettingsValue } from "Core/settings/types" + +export interface ISettingsService { + init(): void + getSettings(): Settings + resetSettings(): Settings + updateSettings(option: SettingsUpdateOption): SettingsValue + getByKey(key: keyof Settings): SettingsValue +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 7d8bf51287..958953fb0a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -28,8 +28,12 @@ "E2E/*": ["./apps/mudita-center-e2e/src/*"], "Libs/*": ["./libs/*"], "Root/*": ["./*"], - "device-manager": ["libs/device-manager/src/index.ts"], - "device-protocol": ["libs/device-protocol/src/index.ts"], + "core-device/feature": ["libs/core-device/feature/src/index.ts"], + "core-device/models": ["libs/core-device/models/src/index.ts"], + "device-manager/feature": ["libs/device-manager/feature/src/index.ts"], + "device-manager/models": ["libs/device-manager/models/src/index.ts"], + "device-protocol/feature": ["libs/device-protocol/feature/src/index.ts"], + "device-protocol/models": ["libs/device-protocol/models/src/index.ts"], "device/adapters": ["libs/device/adapters/src/index.ts"], "device/feature": ["libs/device/feature/src/index.ts"], "device/models": ["libs/device/models/src/index.ts"], From d7ccb183de3bc00a394876d85ac78dcd6c0f0ea0 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 14 Jun 2024 07:57:55 +0200 Subject: [PATCH 005/100] [CP-2898] Rename all deviceManager to deviceProtocolService --- .../src/controllers/core-device.controller.ts | 4 +- .../feature/src/core-device.module.ts | 4 +- .../analytic-data-tracker.module.ts | 4 +- libs/core/backup/backup.module.ts | 20 ++-- .../services/backup-create.service.test.ts | 18 +-- .../backup/services/backup-create.service.ts | 6 +- .../services/backup-restore.service.test.ts | 20 ++-- .../backup/services/backup-restore.service.ts | 6 +- .../backup/services/base-backup.service.ts | 4 +- .../services/sync-backup-create.service.ts | 16 +-- libs/core/contacts/contact.module.ts | 6 +- .../contacts/services/contact.service.test.ts | 54 +++++---- .../core/contacts/services/contact.service.ts | 28 ++--- libs/core/core/application.module.ts | 11 +- libs/core/core/module/base.module.ts | 2 +- libs/core/core/types/module.type.ts | 2 +- libs/core/crash-dump/crash-dump.module.ts | 8 +- .../services/crash-dump.service.test.ts | 55 ++++----- .../crash-dump/services/crash-dump.service.ts | 14 ++- libs/core/data-sync/data-sync.module.ts | 6 +- .../data-sync/services/data-sync.service.ts | 6 +- libs/core/desktop/desktop.module.ts | 4 +- .../commands/base.command.ts | 2 +- .../commands/file-delete.command.test.ts | 14 ++- .../commands/file-delete.command.ts | 16 +-- .../commands/file-upload.command.test.ts | 24 ++-- .../commands/file-upload.command.ts | 26 +++-- .../commands/retrieve-files.command.test.ts | 12 +- .../commands/retrieve-files.command.ts | 2 +- .../device-file-system.module.ts | 6 +- .../device-file-system.service.test.ts | 14 +-- .../services/device-file-system.service.ts | 62 +++++----- libs/core/device-info/device-info.module.ts | 6 +- .../services/device-info.service.ts | 10 +- libs/core/device-log/device-log.module.ts | 8 +- .../services/device-log.service.test.ts | 17 +-- .../device-log/services/device-log.service.ts | 18 +-- libs/core/device/device.module.ts | 6 +- libs/core/device/services/device.service.ts | 25 ++-- .../files-manager/files-manager.module.ts | 10 +- .../index-storage/index-storage.module.ts | 4 +- .../messages/services/message.service.test.ts | 108 ++++++++++-------- .../core/messages/services/message.service.ts | 22 ++-- .../messages/services/thread.service.test.ts | 70 +++++++----- libs/core/messages/services/thread.service.ts | 10 +- libs/core/outbox/factories/outbox.factory.ts | 16 ++- .../outbox/services/outbox.service.test.ts | 10 +- libs/core/outbox/services/outbox.service.ts | 6 +- libs/core/search/search.module.ts | 4 +- libs/core/settings/settings.module.ts | 4 +- .../services/template.service.test.ts | 56 +++++---- .../templates/services/template.service.ts | 27 ++--- libs/core/templates/template.module.ts | 6 +- .../update/services/device-update.service.ts | 12 +- libs/core/update/update.module.ts | 10 +- .../controllers/device-manager.controller.ts | 6 +- .../feature/src/device-manager.module.ts | 4 +- .../feature/src/device-protocol.module.ts | 6 +- .../usb-device-detection.observer.ts | 9 +- .../src/lib/api-config/api-config.service.ts | 8 +- .../lib/api-features/api-features.service.ts | 16 +-- libs/device/feature/src/lib/api-module.ts | 27 +++-- .../feature/src/lib/backup/backup.service.ts | 14 +-- .../data-transfer/data-transfer.service.ts | 18 +-- .../device-system-actions.service.ts | 6 +- .../lib/file-manager/file-manager.service.ts | 10 +- .../file-transfer/file-transfer.service.ts | 26 ++--- .../feature/src/lib/menu/menu.service.ts | 6 +- .../feature/src/lib/outbox/outbox.service.ts | 4 +- .../src/lib/restore/restore.service.ts | 18 +-- 70 files changed, 606 insertions(+), 513 deletions(-) diff --git a/libs/core-device/feature/src/controllers/core-device.controller.ts b/libs/core-device/feature/src/controllers/core-device.controller.ts index 41879c3e47..289f3457dc 100644 --- a/libs/core-device/feature/src/controllers/core-device.controller.ts +++ b/libs/core-device/feature/src/controllers/core-device.controller.ts @@ -24,7 +24,7 @@ export interface DeviceConfiguration { export class CoreDeviceController { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private deviceCacheConfigurationService: DeviceCacheConfigurationService ) {} @@ -38,7 +38,7 @@ export class CoreDeviceController { return Result.success(deviceConfigurationCached) } - const result = await this.deviceManager.request(id, { + const result = await this.deviceProtocolService.request(id, { endpoint: Endpoint.DeviceInfo, method: Method.Get, options: { diff --git a/libs/core-device/feature/src/core-device.module.ts b/libs/core-device/feature/src/core-device.module.ts index 4b5ab12533..19cf84d3d8 100644 --- a/libs/core-device/feature/src/core-device.module.ts +++ b/libs/core-device/feature/src/core-device.module.ts @@ -12,11 +12,11 @@ export class CoreDeviceModule { public controllers constructor( - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public fileSystem: FileSystemService ) { const deviceManagerController = new CoreDeviceController( - this.deviceManager, + this.deviceProtocolService, new DeviceCacheConfigurationService(this.fileSystem) ) diff --git a/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts b/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts index 81dff9d47c..7457c37fa5 100644 --- a/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts +++ b/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts @@ -20,7 +20,7 @@ const siteId = Number(process.env.ANALYTICS_API_SITE_ID) export class AnalyticDataTrackerModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -29,7 +29,7 @@ export class AnalyticDataTrackerModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, diff --git a/libs/core/backup/backup.module.ts b/libs/core/backup/backup.module.ts index 0a5c8f7812..aaa996fef6 100644 --- a/libs/core/backup/backup.module.ts +++ b/libs/core/backup/backup.module.ts @@ -29,7 +29,7 @@ import { DeviceInfoService } from "Core/device-info/services" export class BackupModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -38,7 +38,7 @@ export class BackupModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -46,30 +46,32 @@ export class BackupModule extends BaseModule { fileSystem ) - const deviceFileSystem = new DeviceFileSystemService(this.deviceManager) + const deviceFileSystem = new DeviceFileSystemService( + this.deviceProtocolService + ) const fileManagerService = new FileManagerService( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileDeleteCommand(this.deviceManager), + new FileDeleteCommand(this.deviceProtocolService), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new RetrieveFilesCommand(this.deviceManager), + new RetrieveFilesCommand(this.deviceProtocolService), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileUploadCommand(this.deviceManager, this.fileSystem) + new FileUploadCommand(this.deviceProtocolService, this.fileSystem) ) - const deviceInfoService = new DeviceInfoService(this.deviceManager) + const deviceInfoService = new DeviceInfoService(this.deviceProtocolService) const backupCreateService = new BackupCreateService( - this.deviceManager, + this.deviceProtocolService, deviceFileSystem, fileManagerService, deviceInfoService, this.keyStorage ) const backupRestoreService = new BackupRestoreService( - this.deviceManager, + this.deviceProtocolService, deviceFileSystem, deviceInfoService, fileSystem diff --git a/libs/core/backup/services/backup-create.service.test.ts b/libs/core/backup/services/backup-create.service.test.ts index 63e3c3be9a..4a80838277 100644 --- a/libs/core/backup/services/backup-create.service.test.ts +++ b/libs/core/backup/services/backup-create.service.test.ts @@ -25,7 +25,7 @@ const updaterStatusSuccessMock: UpdaterStatus = { successful: true, } -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, @@ -50,7 +50,7 @@ const deviceInfoService = { } as unknown as DeviceInfoService const subject = new BackupCreateService( - deviceManager, + deviceProtocolService, deviceFileSystemAdapter, fileManagerService, deviceInfoService, @@ -63,7 +63,7 @@ beforeEach(() => { describe("Backup process happy path", () => { test("Returns the `Result.success` object with backup data", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -114,14 +114,14 @@ describe("Backup process happy path", () => { expect(result).toEqual(Result.success(["/user/backup/backup.tar"])) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenNthCalledWith(1, { + expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(1, { endpoint: Endpoint.Backup, method: Method.Post, body: { category: BackupCategory.Backup }, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenNthCalledWith(2, { + expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(2, { endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -194,7 +194,7 @@ describe("Backup process failed path", () => { }) test("Returns the `Result.failed` with `BackupError.CannotReachBackupLocation` if `DeviceInfo` endpoint return error status", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValue(Result.failed(new AppError("", ""))) deviceInfoService.getDeviceInfo = jest.fn().mockResolvedValue( @@ -226,7 +226,7 @@ describe("Backup process failed path", () => { }) test("Returns the `Result.failed` with `BackupError.CannotReachBackupLocation` if `Backup` endpoint return error status", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValue(Result.failed(new AppError("", ""))) deviceInfoService.getDeviceInfo = jest.fn().mockResolvedValue( @@ -259,7 +259,7 @@ describe("Backup process failed path", () => { }) test("Returns the `Result.failed` with `BackupError.BackupProcessFailed` if `deviceFileSystem.downloadFile` returns error status", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -312,7 +312,7 @@ describe("Backup process failed path", () => { }, 10000) test("Returns the `Result.failed` with `BackupError.BackupDownloadFailed` if `deviceFileSystem.downloadDeviceFilesLocally` returns error status", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( diff --git a/libs/core/backup/services/backup-create.service.ts b/libs/core/backup/services/backup-create.service.ts index 35431ece2d..78d824a85a 100644 --- a/libs/core/backup/services/backup-create.service.ts +++ b/libs/core/backup/services/backup-create.service.ts @@ -19,13 +19,13 @@ import { DeviceInfoService } from "Core/device-info/services" export class BackupCreateService extends BaseBackupService { constructor( - protected deviceManager: DeviceProtocolService, + protected deviceProtocolService: DeviceProtocolService, protected deviceFileSystem: DeviceFileSystemService, protected fileManagerService: FileManagerService, protected deviceInfoService: DeviceInfoService, private keyStorage: MetadataStore ) { - super(deviceManager, deviceFileSystem, deviceInfoService) + super(deviceProtocolService, deviceFileSystem, deviceInfoService) } public async createBackup( @@ -109,7 +109,7 @@ export class BackupCreateService extends BaseBackupService { ) } - const backupResponse = await this.deviceManager.device.request({ + const backupResponse = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Backup, method: Method.Post, body: { diff --git a/libs/core/backup/services/backup-restore.service.test.ts b/libs/core/backup/services/backup-restore.service.test.ts index 091313fe8b..fa3f5151be 100644 --- a/libs/core/backup/services/backup-restore.service.test.ts +++ b/libs/core/backup/services/backup-restore.service.test.ts @@ -61,7 +61,7 @@ const updaterStatusSuccessForAnotherOperationMock: UpdaterStatus = { successful: true, } -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, @@ -84,7 +84,7 @@ const deviceInfoService = { } as unknown as DeviceInfoService const subject = new BackupRestoreService( - deviceManager, + deviceProtocolService, deviceFileSystemAdapter, deviceInfoService, fileSystemServiceMock @@ -111,7 +111,7 @@ describe("Restore process happy path", () => { .mockResolvedValueOnce( Result.success(JSON.stringify(updaterStatusSuccessMock)) ) - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -162,14 +162,14 @@ describe("Restore process happy path", () => { }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenNthCalledWith(1, { + expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(1, { endpoint: Endpoint.Restore, method: Method.Post, body: { restore: "fileBase.tar" }, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenNthCalledWith(2, { + expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(2, { endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -263,7 +263,7 @@ describe("Backup restoring failed path", () => { deviceFileSystemAdapter.uploadFile = jest .fn() .mockResolvedValueOnce(Result.success(true)) - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -275,7 +275,7 @@ describe("Backup restoring failed path", () => { return Result.failed(new AppError("", "")) }) - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValue(Result.failed(new AppError("", ""))) deviceInfoService.getDeviceInfo = jest.fn().mockResolvedValue( @@ -310,7 +310,7 @@ describe("Backup restoring failed path", () => { deviceFileSystemAdapter.downloadFile = jest .fn() .mockResolvedValueOnce(Result.failed(new AppError("", ""))) - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -371,7 +371,7 @@ describe("Backup restoring failed path", () => { JSON.stringify(updaterStatusSuccessForAnotherOperationMock) ) ) - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -430,7 +430,7 @@ describe("Backup restoring failed path", () => { .mockResolvedValueOnce( Result.success(JSON.stringify(updaterStatusFailedMock)) ) - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( diff --git a/libs/core/backup/services/backup-restore.service.ts b/libs/core/backup/services/backup-restore.service.ts index daffa5a752..7251e19eac 100644 --- a/libs/core/backup/services/backup-restore.service.ts +++ b/libs/core/backup/services/backup-restore.service.ts @@ -17,12 +17,12 @@ import { DeviceInfoService } from "Core/device-info/services" export class BackupRestoreService extends BaseBackupService { constructor( - protected deviceManager: DeviceProtocolService, + protected deviceProtocolService: DeviceProtocolService, protected deviceFileSystem: DeviceFileSystemService, protected deviceInfoService: DeviceInfoService, private fileSystem: FileSystemService ) { - super(deviceManager, deviceFileSystem, deviceInfoService) + super(deviceProtocolService, deviceFileSystem, deviceInfoService) } public async restoreBackup({ @@ -74,7 +74,7 @@ export class BackupRestoreService extends BaseBackupService { ) } - const restoreResult = await this.deviceManager.device.request({ + const restoreResult = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Restore, method: Method.Post, body: { diff --git a/libs/core/backup/services/base-backup.service.ts b/libs/core/backup/services/base-backup.service.ts index c000cd6ac0..2f6a62c9ee 100644 --- a/libs/core/backup/services/base-backup.service.ts +++ b/libs/core/backup/services/base-backup.service.ts @@ -18,7 +18,7 @@ export class BaseBackupService { private REQUEST_TIME_OUT = 5000 constructor( - protected deviceManager: DeviceProtocolService, + protected deviceProtocolService: DeviceProtocolService, protected deviceFileSystem: DeviceFileSystemService, protected deviceInfoService: DeviceInfoService ) {} @@ -127,7 +127,7 @@ export class BaseBackupService { return false } - const response = await this.deviceManager.device.request({ + const response = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, diff --git a/libs/core/backup/services/sync-backup-create.service.ts b/libs/core/backup/services/sync-backup-create.service.ts index 5b87f1ebe5..09eeebfd17 100644 --- a/libs/core/backup/services/sync-backup-create.service.ts +++ b/libs/core/backup/services/sync-backup-create.service.ts @@ -27,14 +27,14 @@ export interface createSyncBackupOptions export class SyncBackupCreateService { constructor( - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public deviceFileSystem: DeviceFileSystemService, private keyStorage: MetadataStore ) {} public async createSyncBackup( options: createSyncBackupOptions, - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { if (this.keyStorage.getValue(MetadataKey.BackupInProgress)) { return Result.failed( @@ -81,9 +81,9 @@ export class SyncBackupCreateService { } private async runDeviceSyncBackup( - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { - const deviceResponse = await this.deviceManager.request( + const deviceResponse = await this.deviceProtocolService.request( deviceId, { endpoint: Endpoint.DeviceInfo, @@ -101,7 +101,7 @@ export class SyncBackupCreateService { } // id field as backup response is a deprecated field after Pure_1.6.0 & Harmony_1.9.0 (UDM releases) - const backupResponse = await this.deviceManager.request<{ + const backupResponse = await this.deviceProtocolService.request<{ id?: string }>(deviceId, { endpoint: Endpoint.Backup, @@ -151,7 +151,7 @@ export class SyncBackupCreateService { private async waitUntilBackupDeviceFinished( id: string, iteration = 0, - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { try { const result = await this.getBackupDeviceStatus( @@ -181,9 +181,9 @@ export class SyncBackupCreateService { public async getBackupDeviceStatus( config: GetBackupDeviceStatusRequestConfigBody, - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { - return await this.deviceManager.request(deviceId, { + return await this.deviceProtocolService.request(deviceId, { endpoint: Endpoint.Backup, method: Method.Get, body: { diff --git a/libs/core/contacts/contact.module.ts b/libs/core/contacts/contact.module.ts index 60accc3b2e..73f5366529 100644 --- a/libs/core/contacts/contact.module.ts +++ b/libs/core/contacts/contact.module.ts @@ -19,7 +19,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class ContactModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -28,7 +28,7 @@ export class ContactModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -39,7 +39,7 @@ export class ContactModule extends BaseModule { const contactRepository = new ContactRepository(contactModel) const contactService = new ContactService( contactRepository, - this.deviceManager + this.deviceProtocolService ) const contactController = new ContactController(contactService) diff --git a/libs/core/contacts/services/contact.service.test.ts b/libs/core/contacts/services/contact.service.test.ts index abfa7f5588..0464f509aa 100644 --- a/libs/core/contacts/services/contact.service.test.ts +++ b/libs/core/contacts/services/contact.service.test.ts @@ -19,13 +19,13 @@ const contactRepository = { delete: jest.fn(), } as unknown as ContactRepository -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, } as unknown as DeviceProtocolService -const subject = new ContactService(contactRepository, deviceManager) +const subject = new ContactService(contactRepository, deviceProtocolService) const pureContact: PureContact = { id: 19, @@ -63,59 +63,63 @@ beforeEach(() => { describe("`ContactService`", () => { describe("`getContact` method", () => { test("map data and returns success when `device.request` returns success", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(pureContact)) const response = await subject.getContact("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) expect(response.data).toEqual(contact) }) test("returns error when `device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.getContact("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`getContacts` method", () => { test("map data and returns success when `device.request` returns success", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success({ entries: [pureContact] })) const response = await subject.getContacts() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) expect(response.data).toEqual([contact]) }) test("returns error when `device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.getContacts() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`createContact` method", () => { test("returns success and `repository.create` is called when `device.request` returns success", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success({ id: pureContact.id })) const response = await subject.createContact(contact) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.create).toHaveBeenCalled() @@ -124,11 +128,13 @@ describe("`ContactService`", () => { }) test("returns error when `device.request` returns error`", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.createContact(contact) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.create).not.toHaveBeenCalled() @@ -138,7 +144,7 @@ describe("`ContactService`", () => { describe("`editContact` method", () => { test("returns success and `repository.update` is called when `device.request` and `isContactValid` returns success", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(pureContact)) @@ -171,12 +177,14 @@ describe("`ContactService`", () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any .spyOn(subject as unknown as { isContactValid: any }, "isContactValid") .mockImplementation(() => successResponse) - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.editContact(contact) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.update).not.toHaveBeenCalled() @@ -186,12 +194,14 @@ describe("`ContactService`", () => { describe("`deleteContacts` method", () => { test("returns success and `repository.delete` is called when `device.request` returns success", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(successResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(successResponse) const response = await subject.deleteContacts(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.delete).toHaveBeenCalled() @@ -199,12 +209,14 @@ describe("`ContactService`", () => { }) test("returns error with ids when `device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.deleteContacts(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.delete).not.toHaveBeenCalled() diff --git a/libs/core/contacts/services/contact.service.ts b/libs/core/contacts/services/contact.service.ts index 015c9a6eec..ee438d386d 100644 --- a/libs/core/contacts/services/contact.service.ts +++ b/libs/core/contacts/services/contact.service.ts @@ -23,12 +23,12 @@ import { ResultObject } from "Core/core/builder" export class ContactService { constructor( private contactRepository: ContactRepository, - private deviceManager: DeviceProtocolService + private deviceProtocolService: DeviceProtocolService ) {} public async getContact(id: string): Promise> { const response = - await this.deviceManager.device.request({ + await this.deviceProtocolService.device.request({ endpoint: Endpoint.Contacts, method: Method.Get, body: { @@ -51,7 +51,7 @@ export class ContactService { public async getContacts(): Promise> { const response = - await this.deviceManager.device.request({ + await this.deviceProtocolService.device.request({ endpoint: Endpoint.Contacts, method: Method.Get, }) @@ -90,14 +90,16 @@ export class ContactService { //workaround const result = - await this.deviceManager.device.request({ - endpoint: Endpoint.Contacts, - method: Method.Post, - body: ContactPresenter.mapToPureContact(newContact), - options: { - connectionTimeOut: 5000, - }, - }) + await this.deviceProtocolService.device.request( + { + endpoint: Endpoint.Contacts, + method: Method.Post, + body: ContactPresenter.mapToPureContact(newContact), + options: { + connectionTimeOut: 5000, + }, + } + ) if (this.isInternalServerError(result)) { return { @@ -160,7 +162,7 @@ export class ContactService { return isContactValidResponse } - const result = await this.deviceManager.device.request({ + const result = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Contacts, method: Method.Put, body: ContactPresenter.mapToPureContact(contact), @@ -220,7 +222,7 @@ export class ContactService { const successIds = [] for (const id of contactIds) { - const result = await this.deviceManager.device.request({ + const result = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Contacts, method: Method.Delete, body: { id: Number(id) }, diff --git a/libs/core/core/application.module.ts b/libs/core/core/application.module.ts index 22c6e7cd98..7ef07c69ad 100644 --- a/libs/core/core/application.module.ts +++ b/libs/core/core/application.module.ts @@ -94,7 +94,7 @@ export class ApplicationModule { private apiModule: APIModule - private deviceManager = new DeviceProtocolService( + private deviceProtocolService = new DeviceProtocolService( mockServiceEnabled ? new MockDeviceResolverService() : new DeviceResolverService(), @@ -118,7 +118,7 @@ export class ApplicationModule { this.modules.forEach(this.initModule) this.apiModule = new APIModule( - this.deviceManager, + this.deviceProtocolService, this.systemUtilsModule, createSettingsService() ) @@ -132,10 +132,11 @@ export class ApplicationModule { ) this.controllerInitializer.initialize(new OnlineStatusModule().controllers) this.controllerInitializer.initialize( - new CoreDeviceModule(this.deviceManager, this.fileSystem).controllers + new CoreDeviceModule(this.deviceProtocolService, this.fileSystem) + .controllers ) this.controllerInitializer.initialize( - new DeviceManagerModule(this.deviceManager).controllers + new DeviceManagerModule(this.deviceProtocolService).controllers ) } @@ -146,7 +147,7 @@ export class ApplicationModule { private initModule = (module: Module): void => { const instance = new module( this.index, - this.deviceManager, + this.deviceProtocolService, this.keyStorage, this.logger, this.ipc, diff --git a/libs/core/core/module/base.module.ts b/libs/core/core/module/base.module.ts index e1bf9515fd..74bb4ec1b1 100644 --- a/libs/core/core/module/base.module.ts +++ b/libs/core/core/module/base.module.ts @@ -27,7 +27,7 @@ export class BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/core/types/module.type.ts b/libs/core/core/types/module.type.ts index a6340b326d..9b1562aee1 100644 --- a/libs/core/core/types/module.type.ts +++ b/libs/core/core/types/module.type.ts @@ -21,7 +21,7 @@ export interface Module { // eslint-disable-next-line @typescript-eslint/no-misused-new new ( index: IndexStorage, - deviceManager: DeviceProtocolService, + deviceProtocolService: DeviceProtocolService, keyStorage: MetadataStore, logger: AppLogger, ipc: MainProcessIpc, diff --git a/libs/core/crash-dump/crash-dump.module.ts b/libs/core/crash-dump/crash-dump.module.ts index d2e679517c..fcdbd7f3a9 100644 --- a/libs/core/crash-dump/crash-dump.module.ts +++ b/libs/core/crash-dump/crash-dump.module.ts @@ -22,7 +22,7 @@ export class CrashDumpModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -31,7 +31,7 @@ export class CrashDumpModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -46,8 +46,8 @@ export class CrashDumpModule extends BaseModule { } this.crashDumpService = new CrashDumpService( - this.deviceManager, - new DeviceFileSystemService(this.deviceManager) + this.deviceProtocolService, + new DeviceFileSystemService(this.deviceProtocolService) ) this.crashDumpController = new CrashDumpController( this.crashDumpService, diff --git a/libs/core/crash-dump/services/crash-dump.service.test.ts b/libs/core/crash-dump/services/crash-dump.service.test.ts index 4c8372e384..cbe33841b2 100644 --- a/libs/core/crash-dump/services/crash-dump.service.test.ts +++ b/libs/core/crash-dump/services/crash-dump.service.test.ts @@ -11,7 +11,7 @@ import { CrashDumpService } from "Core/crash-dump/services/crash-dump.service" import { DeviceFileSystemService } from "Core/device-file-system/services" import { RequestResponseStatus } from "Core/core/types/request-response.interface" -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, @@ -21,7 +21,10 @@ const deviceFileSystemMock = { downloadDeviceFilesLocally: jest.fn(), } as unknown as DeviceFileSystemService -const subject = new CrashDumpService(deviceManager, deviceFileSystemMock) +const subject = new CrashDumpService( + deviceProtocolService, + deviceFileSystemMock +) afterEach(() => { jest.resetAllMocks() @@ -29,7 +32,7 @@ afterEach(() => { describe("Method: getDeviceCrashDumpFiles", () => { test("returns list of files if `Endpoint.DeviceInfo` endpoint returns `success` and list of files", async () => { - deviceManager.device.request = jest.fn().mockReturnValueOnce( + deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -37,35 +40,35 @@ describe("Method: getDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect(await subject.getDeviceCrashDumpFiles()).toEqual({ data: ["/sys/crash_dumps/crashdump.hex"], status: RequestResponseStatus.Ok, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() }) test("returns empty list of files if if data key isn't exists", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValueOnce(Result.success(undefined)) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect(await subject.getDeviceCrashDumpFiles()).toEqual({ data: [], status: RequestResponseStatus.Ok, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() }) test("returns an `Error` status if status isn't equal to `Ok`", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValueOnce( Result.failed( @@ -78,19 +81,19 @@ describe("Method: getDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect(await subject.getDeviceCrashDumpFiles()).toEqual({ status: RequestResponseStatus.Error, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() }) }) describe("Method: downloadDeviceCrashDumpFiles", () => { test("returns local files urls if `downloadDeviceFilesLocally` returns `success` status and files list exists", async () => { - deviceManager.device.request = jest.fn().mockReturnValueOnce( + deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -103,7 +106,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -117,7 +120,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -128,7 +131,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `success` status if `getDeviceFiles` returns empty data", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValueOnce(Result.success(undefined)) ;( @@ -137,7 +140,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -151,7 +154,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -160,13 +163,13 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `Error` status if `getDeviceFiles` returns `Error` status", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValueOnce(Result.failed({} as AppError)) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -179,7 +182,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -188,7 +191,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `Error` status if `downloadDeviceFilesLocally` returns empty data", async () => { - deviceManager.device.request = jest.fn().mockReturnValueOnce( + deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -202,7 +205,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -215,7 +218,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -226,7 +229,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `Error` status if `downloadDeviceFilesLocally` returns `Error` status", async () => { - deviceManager.device.request = jest.fn().mockReturnValueOnce( + deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -239,7 +242,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -252,7 +255,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method diff --git a/libs/core/crash-dump/services/crash-dump.service.ts b/libs/core/crash-dump/services/crash-dump.service.ts index e196084aef..fe587c98c1 100644 --- a/libs/core/crash-dump/services/crash-dump.service.ts +++ b/libs/core/crash-dump/services/crash-dump.service.ts @@ -18,7 +18,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class CrashDumpService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private deviceFileSystem: DeviceFileSystemService ) {} @@ -87,10 +87,12 @@ export class CrashDumpService { public async getDiagnosticFileList( fileList: DiagnosticsFileList ): Promise> { - return this.deviceManager.device.request({ - endpoint: Endpoint.DeviceInfo, - method: Method.Get, - body: { fileList }, - }) + return this.deviceProtocolService.device.request( + { + endpoint: Endpoint.DeviceInfo, + method: Method.Get, + body: { fileList }, + } + ) } } diff --git a/libs/core/data-sync/data-sync.module.ts b/libs/core/data-sync/data-sync.module.ts index 83733e038d..173a830673 100644 --- a/libs/core/data-sync/data-sync.module.ts +++ b/libs/core/data-sync/data-sync.module.ts @@ -20,7 +20,7 @@ export class DataSyncModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -29,7 +29,7 @@ export class DataSyncModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -39,7 +39,7 @@ export class DataSyncModule extends BaseModule { this.dataSyncService = new DataSyncService( this.index, - this.deviceManager, + this.deviceProtocolService, this.keyStorage, this.fileSystem ) diff --git a/libs/core/data-sync/services/data-sync.service.ts b/libs/core/data-sync/services/data-sync.service.ts index 542e8c02f1..e3c92ec4ad 100644 --- a/libs/core/data-sync/services/data-sync.service.ts +++ b/libs/core/data-sync/services/data-sync.service.ts @@ -35,13 +35,13 @@ export class DataSyncService { constructor( private index: IndexStorage, - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private keyStorage: MetadataStore, private fileSystemStorage: FileSystemService ) { this.syncBackupCreateService = new SyncBackupCreateService( - this.deviceManager, - new DeviceFileSystemService(this.deviceManager), + this.deviceProtocolService, + new DeviceFileSystemService(this.deviceProtocolService), this.keyStorage ) diff --git a/libs/core/desktop/desktop.module.ts b/libs/core/desktop/desktop.module.ts index 8407f67343..a8e17a3f23 100644 --- a/libs/core/desktop/desktop.module.ts +++ b/libs/core/desktop/desktop.module.ts @@ -17,7 +17,7 @@ import { DesktopService } from "Core/desktop/desktop.service" export class DesktopModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DesktopModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, diff --git a/libs/core/device-file-system/commands/base.command.ts b/libs/core/device-file-system/commands/base.command.ts index ad43f742bc..310588b62b 100644 --- a/libs/core/device-file-system/commands/base.command.ts +++ b/libs/core/device-file-system/commands/base.command.ts @@ -7,7 +7,7 @@ import * as CRC32 from "crc-32" import { DeviceProtocolService } from "device-protocol/feature" export abstract class BaseCommand { - constructor(public deviceManager: DeviceProtocolService) {} + constructor(public deviceProtocolService: DeviceProtocolService) {} public countCRC32(buffer: Buffer | Uint8Array): string { const crc = CRC32.buf(buffer) diff --git a/libs/core/device-file-system/commands/file-delete.command.test.ts b/libs/core/device-file-system/commands/file-delete.command.test.ts index 133b0b9b2a..478587315a 100644 --- a/libs/core/device-file-system/commands/file-delete.command.test.ts +++ b/libs/core/device-file-system/commands/file-delete.command.test.ts @@ -10,13 +10,13 @@ import { Result, ResultObject, SuccessResult } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { FileDeleteCommand } from "Core/device-file-system/commands/file-delete.command" -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, } as unknown as DeviceProtocolService -const subject = new FileDeleteCommand(deviceManager) +const subject = new FileDeleteCommand(deviceProtocolService) const successResponse: ResultObject = Result.success(undefined) @@ -37,7 +37,7 @@ beforeEach(() => { describe("`FileDeleteCommand`", () => { describe("when `DeviceManager.device.request` returns success response", () => { beforeEach(() => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValue(successResponse) }) @@ -47,7 +47,7 @@ describe("`FileDeleteCommand`", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Delete, body: { @@ -60,7 +60,9 @@ describe("`FileDeleteCommand`", () => { describe("when `DeviceManager.device.request` returns failed response", () => { beforeEach(() => { - deviceManager.device.request = jest.fn().mockResolvedValue(failedResponse) + deviceProtocolService.device.request = jest + .fn() + .mockResolvedValue(failedResponse) }) test("returns `ResultObject.failed`", async () => { @@ -68,7 +70,7 @@ describe("`FileDeleteCommand`", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Delete, body: { diff --git a/libs/core/device-file-system/commands/file-delete.command.ts b/libs/core/device-file-system/commands/file-delete.command.ts index fe5af0de79..ec9bb58a1c 100644 --- a/libs/core/device-file-system/commands/file-delete.command.ts +++ b/libs/core/device-file-system/commands/file-delete.command.ts @@ -14,13 +14,15 @@ import { DeviceFileSystemError } from "Core/device-file-system/constants" export class FileDeleteCommand extends BaseCommand { public async exec(path: string): Promise> { const { ok, error } = - await this.deviceManager.device.request({ - endpoint: Endpoint.FileSystem, - method: Method.Delete, - body: { - removeFile: path, - }, - }) + await this.deviceProtocolService.device.request( + { + endpoint: Endpoint.FileSystem, + method: Method.Delete, + body: { + removeFile: path, + }, + } + ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access diff --git a/libs/core/device-file-system/commands/file-upload.command.test.ts b/libs/core/device-file-system/commands/file-upload.command.test.ts index 760c681bfe..12e0021f35 100644 --- a/libs/core/device-file-system/commands/file-upload.command.test.ts +++ b/libs/core/device-file-system/commands/file-upload.command.test.ts @@ -15,7 +15,7 @@ import { Result, ResultObject } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { DeviceFileSystemError } from "Core/device-file-system/constants" -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, @@ -26,7 +26,7 @@ const fileSystemService = { getFileSize: jest.fn(), } as unknown as FileSystemService -const subject = new FileUploadCommand(deviceManager, fileSystemService) +const subject = new FileUploadCommand(deviceProtocolService, fileSystemService) const successResponse: ResultObject<{ txID: string @@ -88,7 +88,7 @@ describe("When requested file is unreadable", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).not.toHaveBeenCalled() + expect(deviceProtocolService.device.request).not.toHaveBeenCalled() expect(result).toEqual( Result.failed( new AppError( @@ -130,7 +130,7 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValue(successResponse) }) @@ -143,7 +143,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -169,7 +169,9 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceManager.device.request = jest.fn().mockResolvedValue(failedResponse) + deviceProtocolService.device.request = jest + .fn() + .mockResolvedValue(failedResponse) }) test("returns `ResultObject.failed` with `DeviceFileSystemError.FileUploadRequest` type", async () => { @@ -180,7 +182,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -213,7 +215,7 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockImplementation(({ body }) => { // AUTO DISABLED - fix me if you like :) @@ -236,7 +238,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -269,7 +271,7 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValue(failedResponseWithInsufficientStorage) }) @@ -282,7 +284,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { diff --git a/libs/core/device-file-system/commands/file-upload.command.ts b/libs/core/device-file-system/commands/file-upload.command.ts index 4e6fd0ff50..0977f996fd 100644 --- a/libs/core/device-file-system/commands/file-upload.command.ts +++ b/libs/core/device-file-system/commands/file-upload.command.ts @@ -16,10 +16,10 @@ import { DeviceFileSystemError } from "Core/device-file-system/constants" export class FileUploadCommand extends BaseCommand { constructor( - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public fileSystemService: FileSystemService ) { - super(deviceManager) + super(deviceProtocolService) } public async exec( @@ -53,15 +53,17 @@ export class FileUploadCommand extends BaseCommand { const fileName = path.basename(filePath) const response = - await this.deviceManager.device.request({ - endpoint: Endpoint.FileSystem, - method: Method.Put, - body: { - fileSize, - fileCrc32, - fileName: [directory, fileName].join("/"), - }, - }) + await this.deviceProtocolService.device.request( + { + endpoint: Endpoint.FileSystem, + method: Method.Put, + body: { + fileSize, + fileCrc32, + fileName: [directory, fileName].join("/"), + }, + } + ) if (!response.ok || response.data === undefined) { if ( @@ -103,7 +105,7 @@ export class FileUploadCommand extends BaseCommand { const chunkedBufferSize = Buffer.byteLength(chunkedBuffer) const lastChunk = chunkedBufferSize < chunkSize - const response = await this.deviceManager.device.request({ + const response = await this.deviceProtocolService.device.request({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { diff --git a/libs/core/device-file-system/commands/retrieve-files.command.test.ts b/libs/core/device-file-system/commands/retrieve-files.command.test.ts index f80ba6b3c6..ca88cb5779 100644 --- a/libs/core/device-file-system/commands/retrieve-files.command.test.ts +++ b/libs/core/device-file-system/commands/retrieve-files.command.test.ts @@ -11,13 +11,13 @@ import { Result, ResultObject } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { DeviceFileSystemError } from "Core/device-file-system/constants" -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, } as unknown as DeviceProtocolService -const subject = new RetrieveFilesCommand(deviceManager) +const subject = new RetrieveFilesCommand(deviceProtocolService) const responseData: Record = { ["/test/directory"]: [ @@ -46,7 +46,7 @@ beforeEach(() => { describe("When `DeviceManager.device.request` returns success response", () => { beforeEach(() => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValueOnce(successResponse) }) @@ -56,7 +56,7 @@ describe("When `DeviceManager.device.request` returns success response", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Get, body: { @@ -69,7 +69,7 @@ describe("When `DeviceManager.device.request` returns success response", () => { describe("When `DeviceManager.device.request` returns failed response", () => { beforeEach(() => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValueOnce(failedResponse) }) @@ -79,7 +79,7 @@ describe("When `DeviceManager.device.request` returns failed response", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Get, body: { diff --git a/libs/core/device-file-system/commands/retrieve-files.command.ts b/libs/core/device-file-system/commands/retrieve-files.command.ts index 21fad3c143..fc52ec3cb9 100644 --- a/libs/core/device-file-system/commands/retrieve-files.command.ts +++ b/libs/core/device-file-system/commands/retrieve-files.command.ts @@ -16,7 +16,7 @@ export class RetrieveFilesCommand extends BaseCommand { directory: string ): Promise | undefined>> { const result = - await this.deviceManager.device.request( + await this.deviceProtocolService.device.request( { endpoint: Endpoint.FileSystem, method: Method.Get, diff --git a/libs/core/device-file-system/device-file-system.module.ts b/libs/core/device-file-system/device-file-system.module.ts index e6fbb240d2..e0a1c3ff41 100644 --- a/libs/core/device-file-system/device-file-system.module.ts +++ b/libs/core/device-file-system/device-file-system.module.ts @@ -17,7 +17,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class DeviceFileSystemModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DeviceFileSystemModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -35,7 +35,7 @@ export class DeviceFileSystemModule extends BaseModule { ) const deviceFileSystemService = new DeviceFileSystemService( - this.deviceManager + this.deviceProtocolService ) const deviceFileSystemController = new DeviceFileSystemController( deviceFileSystemService diff --git a/libs/core/device-file-system/services/device-file-system.service.test.ts b/libs/core/device-file-system/services/device-file-system.service.test.ts index 2d2d5093f1..fc4e2e49a5 100644 --- a/libs/core/device-file-system/services/device-file-system.service.test.ts +++ b/libs/core/device-file-system/services/device-file-system.service.test.ts @@ -22,21 +22,21 @@ import { } from "Root/jest/testing-support/mocks/diagnostic-data.mock" import { DeviceFileSystemService } from "Core/device-file-system/services/device-file-system.service" -const deviceManager = { +const deviceProtocolService = { request: jest.fn(), device: { id: "abc123", }, } as unknown as DeviceProtocolService -const deviceFileSystem = new DeviceFileSystemService(deviceManager) +const deviceFileSystem = new DeviceFileSystemService(deviceProtocolService) beforeEach(() => { jest.clearAllMocks() }) test("downloading file handle properly chunks data", async () => { - deviceManager.request = jest + deviceProtocolService.request = jest .fn() .mockImplementation( ( @@ -84,7 +84,7 @@ test("downloading file handle properly chunks data", async () => { }) test("downloading file handle properly chunks data if fileSize is less than chunkSize", async () => { - deviceManager.request = jest + deviceProtocolService.request = jest .fn() .mockImplementation( ( @@ -125,7 +125,7 @@ test("downloading file handle properly chunks data if fileSize is less than chun }) test("downloading file return error when part of the chunks data is broken", async () => { - deviceManager.request = jest + deviceProtocolService.request = jest .fn() .mockImplementation( ( @@ -169,7 +169,7 @@ test("downloading file return error when part of the chunks data is broken", asy }) test("downloading file returns error properly", async () => { - deviceManager.request = jest.fn().mockImplementation(() => { + deviceProtocolService.request = jest.fn().mockImplementation(() => { return Result.failed( new AppError( DeviceCommunicationError.RequestFailed, @@ -185,7 +185,7 @@ test("downloading file returns error properly", async () => { }) test("upload file file handle properly chunks data", async () => { - deviceManager.request = jest + deviceProtocolService.request = jest .fn() .mockImplementation( ( diff --git a/libs/core/device-file-system/services/device-file-system.service.ts b/libs/core/device-file-system/services/device-file-system.service.ts index 016d18c53d..b1fad9b97b 100644 --- a/libs/core/device-file-system/services/device-file-system.service.ts +++ b/libs/core/device-file-system/services/device-file-system.service.ts @@ -27,12 +27,12 @@ import { } from "Core/device-file-system/dto" export class DeviceFileSystemService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} public async downloadDeviceFilesLocally( filePaths: string[], options: DownloadDeviceFileLocallyOptions, - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { const data: string[] = [] @@ -61,7 +61,7 @@ export class DeviceFileSystemService { public async downloadDeviceFiles( filePaths: string[], - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { const data: DeviceFile[] = [] for (let i = 0; i < filePaths.length; i++) { @@ -81,11 +81,11 @@ export class DeviceFileSystemService { public async downloadFile( filePath: string, - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { try { const { ok, data } = - await this.deviceManager.request(deviceId, { + await this.deviceProtocolService.request(deviceId, { endpoint: Endpoint.FileSystem, method: Method.Get, body: { @@ -157,15 +157,17 @@ export class DeviceFileSystemService { const fileSize = Buffer.byteLength(data) const fileCrc32 = countCRC32(data) const response = - await this.deviceManager.device.request({ - endpoint: Endpoint.FileSystem, - method: Method.Put, - body: { - fileSize, - fileCrc32, - fileName: targetPath, - }, - }) + await this.deviceProtocolService.device.request( + { + endpoint: Endpoint.FileSystem, + method: Method.Put, + body: { + fileSize, + fileCrc32, + fileName: targetPath, + }, + } + ) if (!response.ok || response.data === undefined) { return Result.failed( @@ -190,15 +192,17 @@ export class DeviceFileSystemService { const fileCrc32 = countCRC32(fileBuffer) const { ok, data } = - await this.deviceManager.device.request({ - endpoint: Endpoint.FileSystem, - method: Method.Put, - body: { - fileSize, - fileCrc32, - fileName: targetPath, - }, - }) + await this.deviceProtocolService.device.request( + { + endpoint: Endpoint.FileSystem, + method: Method.Put, + body: { + fileSize, + fileCrc32, + fileName: targetPath, + }, + } + ) if (!ok || data === undefined) { return Result.failed( @@ -229,7 +233,7 @@ export class DeviceFileSystemService { return Result.failed(new AppError("", "")) } - const { ok } = await this.deviceManager.device.request({ + const { ok } = await this.deviceProtocolService.device.request({ endpoint: Endpoint.FileSystem, method: Method.Delete, body: { @@ -247,7 +251,7 @@ export class DeviceFileSystemService { private async downloadDeviceFileLocally( filePath: string, options: DownloadDeviceFileLocallyOptions, - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { const { data: result, ok } = await this.downloadFile(filePath, deviceId) @@ -317,7 +321,7 @@ export class DeviceFileSystemService { const chunkedBufferSize = Buffer.byteLength(chunkedBuffer) const lastChunk = chunkedBufferSize < chunkSize - const response = await this.deviceManager.device.request({ + const response = await this.deviceProtocolService.device.request({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -368,7 +372,7 @@ export class DeviceFileSystemService { const lastChunk = nread < chunkSize const dataBuffer = lastChunk ? buffer.slice(0, nread) : buffer - const response = await this.deviceManager.device.request({ + const response = await this.deviceProtocolService.device.request({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -404,10 +408,10 @@ export class DeviceFileSystemService { chunkLength: number, chunkNo = 1, chunkedString = "", - deviceId = this.deviceManager.device.id + deviceId = this.deviceProtocolService.device.id ): Promise> { const { ok, data } = - await this.deviceManager.request( + await this.deviceProtocolService.request( deviceId, { endpoint: Endpoint.FileSystem, diff --git a/libs/core/device-info/device-info.module.ts b/libs/core/device-info/device-info.module.ts index 9856af7aa1..76718a1905 100644 --- a/libs/core/device-info/device-info.module.ts +++ b/libs/core/device-info/device-info.module.ts @@ -17,7 +17,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class DeviceInfoModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DeviceInfoModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -34,7 +34,7 @@ export class DeviceInfoModule extends BaseModule { fileSystem ) - const deviceInfoService = new DeviceInfoService(this.deviceManager) + const deviceInfoService = new DeviceInfoService(this.deviceProtocolService) const deviceInfoController = new DeviceInfoController(deviceInfoService) this.controllers = [deviceInfoController] diff --git a/libs/core/device-info/services/device-info.service.ts b/libs/core/device-info/services/device-info.service.ts index 24b0101a42..990a430f67 100644 --- a/libs/core/device-info/services/device-info.service.ts +++ b/libs/core/device-info/services/device-info.service.ts @@ -16,12 +16,12 @@ import { import { DeviceId } from "Core/device/constants/device-id" export class DeviceInfoService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} private async getDeviceInfoRequest( - deviceId: DeviceId = this.deviceManager.device.id + deviceId: DeviceId = this.deviceProtocolService.device.id ): Promise> { - return this.deviceManager.request(deviceId, { + return this.deviceProtocolService.request(deviceId, { endpoint: Endpoint.DeviceInfo, method: Method.Get, }) @@ -37,8 +37,8 @@ export class DeviceInfoService { return response } const device = deviceId - ? this.deviceManager.getCoreDeviceById(deviceId) - : this.deviceManager.device + ? this.deviceProtocolService.getCoreDeviceById(deviceId) + : this.deviceProtocolService.device if (!device) { return Result.failed(new AppError("", "")) diff --git a/libs/core/device-log/device-log.module.ts b/libs/core/device-log/device-log.module.ts index 5c79dae9b6..1f8132c41f 100644 --- a/libs/core/device-log/device-log.module.ts +++ b/libs/core/device-log/device-log.module.ts @@ -18,7 +18,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class DeviceLogModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -27,7 +27,7 @@ export class DeviceLogModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -36,8 +36,8 @@ export class DeviceLogModule extends BaseModule { ) const deviceLogService = new DeviceLogService( - this.deviceManager, - new DeviceFileSystemService(this.deviceManager) + this.deviceProtocolService, + new DeviceFileSystemService(this.deviceProtocolService) ) const deviceLogController = new DeviceLogController(deviceLogService) diff --git a/libs/core/device-log/services/device-log.service.test.ts b/libs/core/device-log/services/device-log.service.test.ts index a5a5b6c624..3eaa202d94 100644 --- a/libs/core/device-log/services/device-log.service.test.ts +++ b/libs/core/device-log/services/device-log.service.test.ts @@ -18,7 +18,7 @@ import { secondsPartDecodeLog, } from "Root/jest/testing-support/mocks/diagnostic-data.mock" -const deviceManagerMock = { +const deviceProtocolService = { device: { request: jest.fn(), }, @@ -28,7 +28,10 @@ const deviceFileSystemMock = { downloadDeviceFiles: jest.fn(), } as unknown as DeviceFileSystemService -const subject = new DeviceLogService(deviceManagerMock, deviceFileSystemMock) +const subject = new DeviceLogService( + deviceProtocolService, + deviceFileSystemMock +) const deviceInfoErrorResponse: ResultObject = Result.failed( new AppError(DeviceCommunicationError.RequestFailed, "Something went wrong", { @@ -41,7 +44,7 @@ const deviceInfoSuccessResponse: ResultObject = describe("Method: `downloadDeviceLogs`", () => { test("returns Result.failed if DeviceInfo endpoint response with error", async () => { - deviceManagerMock.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValueOnce(deviceInfoErrorResponse) @@ -57,7 +60,7 @@ describe("Method: `downloadDeviceLogs`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManagerMock.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.DeviceInfo, method: Method.Get, body: { @@ -70,7 +73,7 @@ describe("Method: `downloadDeviceLogs`", () => { }) test("returns Result.failed if `downloadDeviceFiles` returns empty data", async () => { - deviceManagerMock.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValueOnce(deviceInfoSuccessResponse) deviceFileSystemMock.downloadDeviceFiles = jest @@ -89,7 +92,7 @@ describe("Method: `downloadDeviceLogs`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManagerMock.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.DeviceInfo, method: Method.Get, body: { @@ -104,7 +107,7 @@ describe("Method: `downloadDeviceLogs`", () => { }) test("returns Result.success if `downloadDeviceFiles` returns file data", async () => { - deviceManagerMock.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValueOnce(deviceInfoSuccessResponse) deviceFileSystemMock.downloadDeviceFiles = jest.fn().mockResolvedValueOnce( diff --git a/libs/core/device-log/services/device-log.service.ts b/libs/core/device-log/services/device-log.service.ts index c16d330ab4..e1e4354683 100644 --- a/libs/core/device-log/services/device-log.service.ts +++ b/libs/core/device-log/services/device-log.service.ts @@ -17,7 +17,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class DeviceLogService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private deviceFileSystem: DeviceFileSystemService ) {} @@ -26,13 +26,15 @@ export class DeviceLogService { ): Promise> { try { const files = - await this.deviceManager.device.request({ - endpoint: Endpoint.DeviceInfo, - method: Method.Get, - body: { - fileList: DiagnosticsFileList.LOGS, - }, - }) + await this.deviceProtocolService.device.request( + { + endpoint: Endpoint.DeviceInfo, + method: Method.Get, + body: { + fileList: DiagnosticsFileList.LOGS, + }, + } + ) if (!files.data || !files.ok) { return Result.failed( diff --git a/libs/core/device/device.module.ts b/libs/core/device/device.module.ts index 02b7d20f81..ea817af725 100644 --- a/libs/core/device/device.module.ts +++ b/libs/core/device/device.module.ts @@ -17,7 +17,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class DeviceModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DeviceModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -34,7 +34,7 @@ export class DeviceModule extends BaseModule { fileSystem ) - const deviceService = new DeviceService(this.deviceManager) + const deviceService = new DeviceService(this.deviceProtocolService) const deviceController = new DeviceController(deviceService) this.controllers = [deviceController] diff --git a/libs/core/device/services/device.service.ts b/libs/core/device/services/device.service.ts index 1951b61e8c..dccbab1f8e 100644 --- a/libs/core/device/services/device.service.ts +++ b/libs/core/device/services/device.service.ts @@ -12,13 +12,13 @@ import { DeviceProtocolService } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" export class DeviceService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} public async unlock( code: string, - deviceId: DeviceId = this.deviceManager.device.id + deviceId: DeviceId = this.deviceProtocolService.device.id ): Promise> { - const response = await this.deviceManager.request(deviceId, { + const response = await this.deviceProtocolService.request(deviceId, { endpoint: Endpoint.Security, method: Method.Put, body: { @@ -30,9 +30,9 @@ export class DeviceService { } public async unlockStatus( - deviceId: DeviceId = this.deviceManager.device.id + deviceId: DeviceId = this.deviceProtocolService.device.id ): Promise> { - return this.deviceManager.request(deviceId, { + return this.deviceProtocolService.request(deviceId, { endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -40,12 +40,15 @@ export class DeviceService { } public async unlockTime( - deviceId: DeviceId = this.deviceManager.device.id + deviceId: DeviceId = this.deviceProtocolService.device.id ): Promise> { - return this.deviceManager.request(deviceId, { - endpoint: Endpoint.Security, - method: Method.Get, - body: { category: PhoneLockCategory.Time }, - }) + return this.deviceProtocolService.request( + deviceId, + { + endpoint: Endpoint.Security, + method: Method.Get, + body: { category: PhoneLockCategory.Time }, + } + ) } } diff --git a/libs/core/files-manager/files-manager.module.ts b/libs/core/files-manager/files-manager.module.ts index abc48dc91b..b850c0b5f9 100644 --- a/libs/core/files-manager/files-manager.module.ts +++ b/libs/core/files-manager/files-manager.module.ts @@ -24,7 +24,7 @@ export class FilesManagerModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -33,7 +33,7 @@ export class FilesManagerModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -44,13 +44,13 @@ export class FilesManagerModule extends BaseModule { const fileManagerService = new FileManagerService( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileDeleteCommand(this.deviceManager), + new FileDeleteCommand(this.deviceProtocolService), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new RetrieveFilesCommand(this.deviceManager), + new RetrieveFilesCommand(this.deviceProtocolService), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileUploadCommand(this.deviceManager, this.fileSystem) + new FileUploadCommand(this.deviceProtocolService, this.fileSystem) ) this.filesManagerController = new FilesManagerController(fileManagerService) diff --git a/libs/core/index-storage/index-storage.module.ts b/libs/core/index-storage/index-storage.module.ts index 1abf93dc27..5a0fca6dce 100644 --- a/libs/core/index-storage/index-storage.module.ts +++ b/libs/core/index-storage/index-storage.module.ts @@ -20,7 +20,7 @@ export class IndexStorageModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -29,7 +29,7 @@ export class IndexStorageModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, diff --git a/libs/core/messages/services/message.service.test.ts b/libs/core/messages/services/message.service.test.ts index ddcd4f3e99..7182fc6363 100644 --- a/libs/core/messages/services/message.service.test.ts +++ b/libs/core/messages/services/message.service.test.ts @@ -28,7 +28,7 @@ import { DeviceProtocolService } from "device-protocol/feature" import assert from "assert" import { MessageType as MessageTypeFromDTO } from "Core/messages/constants" -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, @@ -45,7 +45,7 @@ const messageRepository = { } as unknown as MessageRepository const subject = new MessageService( - deviceManager, + deviceProtocolService, threadService, messageRepository ) @@ -117,66 +117,70 @@ beforeEach(() => { describe("`MessageService`", () => { describe("`getMessage` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const response = await subject.getMessage("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.getMessage("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`getMessages` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success({ entries: [pureMessage] })) const response = await subject.getMessages({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.getMessages({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`createMessage` method", () => { describe("when message is lower than 469 bytes", () => { - test("the `deviceManager.device.request` is called once", async () => { - deviceManager.device.request = jest + test("the `deviceProtocolService.device.request` is called once", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const response = await subject.createMessage(newMessageWithThreadId) expect(response.status).toEqual(RequestResponseStatus.Ok) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledTimes(1) + expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(1) }) }) describe("when message is bigger than 469 bytes", () => { - test("the `deviceManager.device.request` is called more than once", async () => { - deviceManager.device.request = jest + test("the `deviceProtocolService.device.request` is called more than once", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const newLongMessageWithThreadId: NewMessage = { @@ -187,14 +191,14 @@ describe("`MessageService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledTimes(2) + expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(2) }) }) describe("when every part of the message is sent successfully", () => { - describe("when `deviceManager.device.request` returns success with acceptable pure message type", () => { + describe("when `deviceProtocolService.device.request` returns success with acceptable pure message type", () => { test("return in response just message when threadId is known", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const response = await subject.createMessage( @@ -202,7 +206,7 @@ describe("`MessageService`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) assert(response.data?.messageParts) @@ -213,7 +217,7 @@ describe("`MessageService`", () => { }) test("return in response message and thread when threadId isn't known", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) threadService.getThreads = jest.fn().mockReturnValue({ @@ -225,7 +229,7 @@ describe("`MessageService`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) assert(response.data?.messageParts) @@ -237,9 +241,9 @@ describe("`MessageService`", () => { }) }) - describe("when `deviceManager.device.request` returns success with no acceptable pure message type", () => { + describe("when `deviceProtocolService.device.request` returns success with no acceptable pure message type", () => { test("method returns error", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue( Result.success({ ...pureMessage, messageType: MessageType.UNKNOWN }) @@ -247,25 +251,27 @@ describe("`MessageService`", () => { const response = await subject.createMessage(newMessageWithThreadId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) - describe("when `deviceManager.device.request` returns error", () => { + describe("when `deviceProtocolService.device.request` returns error", () => { test("method returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.createMessage(newMessageWithThreadId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) - describe("when `deviceManager.device.request` returns error for the second message", () => { + describe("when `deviceProtocolService.device.request` returns error for the second message", () => { test("method returns error", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValueOnce({ ...successResponse, @@ -275,7 +281,7 @@ describe("`MessageService`", () => { const response = await subject.createMessage(newLongMessageWithThreadId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) @@ -288,7 +294,7 @@ describe("`MessageService`", () => { describe("when everything is fine", () => { let result: unknown beforeEach(async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success(undefined)) messageRepository.findById = jest.fn().mockReturnValue(message) @@ -304,10 +310,10 @@ describe("`MessageService`", () => { test("construct proper delete request to device service and calls proper repository method", async () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledTimes(1) + expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(1) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ body: { category: PureMessagesCategory.message, messageID: 123, @@ -345,7 +351,7 @@ describe("`MessageService`", () => { describe("when an error appears", () => { test("returns error when message was not found in the repository", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(successResponse) messageRepository.findById = jest.fn().mockReturnValue(undefined) @@ -360,7 +366,9 @@ describe("`MessageService`", () => { }) test("returns error when delete request failed", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) messageRepository.findById = jest.fn().mockReturnValue(message) const result = await subject.deleteMessage(messageId) expect(result).toEqual({ @@ -372,7 +380,7 @@ describe("`MessageService`", () => { }) test("returns error when refreshing repository failed", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(successResponse) messageRepository.findById = jest.fn().mockReturnValue(message) @@ -398,7 +406,7 @@ describe("`MessageService`", () => { const result = await subject.resendMessage(messageId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledTimes(0) + expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(0) expect(result).toEqual({ status: RequestResponseStatus.Error, error: { @@ -421,14 +429,14 @@ describe("`MessageService`", () => { phoneNumber: "+48500600700", messageType: MessageType.INBOX, }) - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValue(Result.success(pureMessage)) const result = await subject.resendMessage(messageId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ body: { number: "+48500600700", messageBody: @@ -463,9 +471,9 @@ describe("`MessageService`", () => { }) describe("`updateMessage` method", () => { - describe("`deviceManager.device` returns success status", () => { + describe("`deviceProtocolService.device` returns success status", () => { test("returns success result", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(successResponse) const result = await subject.updateMessage(message) @@ -473,7 +481,7 @@ describe("`MessageService`", () => { expect(result).toEqual(successResponse) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ body: MessagePresenter.mapToUpdatePureMessagesBody(message), endpoint: Endpoint.Messages, method: Method.Put, @@ -481,15 +489,17 @@ describe("`MessageService`", () => { }) }) - describe("`deviceManager.device` returns failed satus", () => { + describe("`deviceProtocolService.device` returns failed satus", () => { test("returns failed result", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const result = await subject.updateMessage(message) expect(result).toEqual(errorResponse) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ body: MessagePresenter.mapToUpdatePureMessagesBody(message), endpoint: Endpoint.Messages, method: Method.Put, diff --git a/libs/core/messages/services/message.service.ts b/libs/core/messages/services/message.service.ts index a15e14dce6..0f2966063a 100644 --- a/libs/core/messages/services/message.service.ts +++ b/libs/core/messages/services/message.service.ts @@ -49,7 +49,7 @@ export interface CreateMessageDataResponse { export class MessageService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private threadService: ThreadService, private messageRepository: MessageRepository ) {} @@ -58,7 +58,7 @@ export class MessageService { public async getMessage(id: string): Promise> { const response = - await this.deviceManager.device.request({ + await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Get, body: { @@ -93,7 +93,7 @@ export class MessageService { } const response = - await this.deviceManager.device.request({ + await this.deviceProtocolService.device.request({ body, endpoint: Endpoint.Messages, method: Method.Get, @@ -172,11 +172,13 @@ export class MessageService { newMessage: NewMessage ): Promise> { const result = - await this.deviceManager.device.request({ - body: MessagePresenter.mapToCreatePureMessageBody(newMessage), - endpoint: Endpoint.Messages, - method: Method.Post, - }) + await this.deviceProtocolService.device.request( + { + body: MessagePresenter.mapToCreatePureMessageBody(newMessage), + endpoint: Endpoint.Messages, + method: Method.Post, + } + ) if (!result.ok) { return { @@ -240,7 +242,7 @@ export class MessageService { } } - const result = await this.deviceManager.device.request({ + const result = await this.deviceProtocolService.device.request({ body: { category: PureMessagesCategory.message, messageID: Number(messageId), @@ -302,7 +304,7 @@ export class MessageService { } public async updateMessage(message: Message): Promise> { - return this.deviceManager.device.request({ + return this.deviceProtocolService.device.request({ body: MessagePresenter.mapToUpdatePureMessagesBody(message), endpoint: Endpoint.Messages, method: Method.Put, diff --git a/libs/core/messages/services/thread.service.test.ts b/libs/core/messages/services/thread.service.test.ts index ab067dfa8a..2d6d7c9dfa 100644 --- a/libs/core/messages/services/thread.service.test.ts +++ b/libs/core/messages/services/thread.service.test.ts @@ -18,7 +18,7 @@ import { ThreadRepository } from "Core/messages/repositories" import { Thread } from "Core/messages/dto" import { MessageType } from "Core/messages/constants" -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, @@ -30,7 +30,7 @@ const threadRepository = { delete: jest.fn(), } as unknown as ThreadRepository -const subject = new ThreadService(deviceManager, threadRepository) +const subject = new ThreadService(deviceProtocolService, threadRepository) const pureThread: PureThread = { contactID: 1, @@ -78,21 +78,25 @@ beforeEach(() => { describe("`ThreadService`", () => { describe("`getThread` method", () => { // test skipped until os part will be implemented CP-1232 - test.skip("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(successResponse) + test.skip("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(successResponse) const response = await subject.getThread("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.getThread("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Error, error: { @@ -103,14 +107,14 @@ describe("`ThreadService`", () => { }) describe("`getThreads` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(getThreadsSuccessResponse) const response = await subject.getThreads({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) expect(response.data).toMatchInlineSnapshot(` Object { @@ -132,12 +136,14 @@ describe("`ThreadService`", () => { `) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.getThreads({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Error, error: { @@ -148,25 +154,27 @@ describe("`ThreadService`", () => { }) describe("`deleteThreads` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success({ id: "1" })) const response = await subject.deleteThreads(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Ok, }) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.deleteThreads(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response).toMatchInlineSnapshot(` Object { "error": Object { @@ -182,25 +190,27 @@ describe("`ThreadService`", () => { }) describe("`toggleThreadsReadStatus` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(Result.success([thread])) const response = await subject.toggleThreadsReadStatus([thread]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Ok, }) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.toggleThreadsReadStatus([thread]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalled() + expect(deviceProtocolService.device.request).toHaveBeenCalled() expect(response).toMatchInlineSnapshot(` Object { "error": Object { @@ -226,7 +236,9 @@ describe("`ThreadService`", () => { describe("`refreshThread` method", () => { test("returns error when fetching thread failed", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.refreshThread("1") expect(response).toEqual({ status: RequestResponseStatus.Error, @@ -238,7 +250,7 @@ describe("`ThreadService`", () => { describe("when the thread was not found in the device", () => { test("removes thread from the repository and returns success response", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(getThreadsSuccessResponse) const response = await subject.refreshThread("6666") @@ -257,7 +269,7 @@ describe("`ThreadService`", () => { describe("when the thread was found in the device", () => { test("updates the thread and returns success response", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockReturnValue(getThreadsSuccessResponse) const response = await subject.refreshThread("1") diff --git a/libs/core/messages/services/thread.service.ts b/libs/core/messages/services/thread.service.ts index a8abb73126..f67ff288f2 100644 --- a/libs/core/messages/services/thread.service.ts +++ b/libs/core/messages/services/thread.service.ts @@ -29,7 +29,7 @@ export interface GetThreadsResponse { export class ThreadService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private threadRepository: ThreadRepository ) {} @@ -55,7 +55,7 @@ export class ThreadService { } const response = - await this.deviceManager.device.request({ + await this.deviceProtocolService.device.request({ body, endpoint: Endpoint.Messages, method: Method.Get, @@ -156,7 +156,7 @@ export class ThreadService { // the method is commented until os part will be implemented as CP-1232 private async getThreadRequest(id: string): Promise> { const response = - await this.deviceManager.device.request({ + await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Get, body: { @@ -182,7 +182,7 @@ export class ThreadService { threads: Thread[] ): Promise> { const results = threads.map(async (thread) => { - const { ok } = await this.deviceManager.device.request({ + const { ok } = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -229,7 +229,7 @@ export class ThreadService { threadIds: string[] ): Promise> { const results = threadIds.map(async (id) => { - const { ok } = await this.deviceManager.device.request({ + const { ok } = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Delete, body: { category: PureMessagesCategory.thread, threadID: Number(id) }, diff --git a/libs/core/outbox/factories/outbox.factory.ts b/libs/core/outbox/factories/outbox.factory.ts index 3b1edcb74f..e6d14066b9 100644 --- a/libs/core/outbox/factories/outbox.factory.ts +++ b/libs/core/outbox/factories/outbox.factory.ts @@ -25,11 +25,14 @@ export class OutboxFactory { static create( index: IndexStorage, eventEmitter: EventEmitter, - deviceManager: DeviceProtocolService + deviceProtocolService: DeviceProtocolService ): OutboxService { const contactModel = new ContactModel(index, eventEmitter) const contactRepository = new ContactRepository(contactModel) - const contactService = new ContactService(contactRepository, deviceManager) + const contactService = new ContactService( + contactRepository, + deviceProtocolService + ) const contactEntryHandlerService = new ContactEntryHandlerService( contactService, contactRepository @@ -40,9 +43,12 @@ export class OutboxFactory { const messageModel = new MessageModel(index, eventEmitter) const messageRepository = new MessageRepository(messageModel) - const threadService = new ThreadService(deviceManager, threadRepository) + const threadService = new ThreadService( + deviceProtocolService, + threadRepository + ) const messageService = new MessageService( - deviceManager, + deviceProtocolService, threadService, messageRepository ) @@ -65,6 +71,6 @@ export class OutboxFactory { [OutboxEntryType.Thread]: threadEntryHandlerService, } - return new OutboxService(deviceManager, entryHandlersMap) + return new OutboxService(deviceProtocolService, entryHandlersMap) } } diff --git a/libs/core/outbox/services/outbox.service.test.ts b/libs/core/outbox/services/outbox.service.test.ts index 0ee10c41d8..2f99ac1297 100644 --- a/libs/core/outbox/services/outbox.service.test.ts +++ b/libs/core/outbox/services/outbox.service.test.ts @@ -13,7 +13,7 @@ import { DeviceProtocolService } from "device-protocol/feature" import { OutboxEntry } from "Core/device/types/mudita-os" import { OutboxEntryChange, OutboxEntryType } from "Core/device/constants" -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn().mockResolvedValue(Result.success({ entries: [] })), }, @@ -23,7 +23,7 @@ const entryHandlersMap = { handleEntry: jest.fn(), }, } as unknown as EntryHandlersMapType -const subject = new OutboxService(deviceManager, entryHandlersMap) +const subject = new OutboxService(deviceProtocolService, entryHandlersMap) const entriesMock: OutboxEntry[] = [ { @@ -41,14 +41,14 @@ beforeEach(() => { describe("`OutboxService`", () => { describe("when Get Outbox Entries returns Contact Entry", () => { test("outbox `delete` request was called", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValueOnce(Result.success({ entries: entriesMock })) await subject.readOutboxEntries() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.Outbox, method: Method.Delete, body: { @@ -58,7 +58,7 @@ describe("`OutboxService`", () => { }) test("contact handler was called", async () => { - deviceManager.device.request = jest + deviceProtocolService.device.request = jest .fn() .mockResolvedValueOnce(Result.success({ entries: entriesMock })) diff --git a/libs/core/outbox/services/outbox.service.ts b/libs/core/outbox/services/outbox.service.ts index 67cb50f1c1..a3841200ba 100644 --- a/libs/core/outbox/services/outbox.service.ts +++ b/libs/core/outbox/services/outbox.service.ts @@ -20,7 +20,7 @@ export type EntryChangesEvent = { entry: OutboxEntry; payload: unknown } export class OutboxService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private entryHandlersMap: EntryHandlersMapType ) {} @@ -52,7 +52,7 @@ export class OutboxService { private async getOutboxEntriesRequest(): Promise< ResultObject > { - return this.deviceManager.device.request({ + return this.deviceProtocolService.device.request({ endpoint: Endpoint.Outbox, method: Method.Get, body: { @@ -64,7 +64,7 @@ export class OutboxService { private async deleteOutboxEntriesRequest( uids: number[] ): Promise> { - return this.deviceManager.device.request({ + return this.deviceProtocolService.device.request({ endpoint: Endpoint.Outbox, method: Method.Delete, body: { diff --git a/libs/core/search/search.module.ts b/libs/core/search/search.module.ts index ffc05d8a8c..08a2d16b49 100644 --- a/libs/core/search/search.module.ts +++ b/libs/core/search/search.module.ts @@ -24,7 +24,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class SearchModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -33,7 +33,7 @@ export class SearchModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, diff --git a/libs/core/settings/settings.module.ts b/libs/core/settings/settings.module.ts index 3e761cf25b..e0c3663526 100644 --- a/libs/core/settings/settings.module.ts +++ b/libs/core/settings/settings.module.ts @@ -21,7 +21,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class SettingsModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -30,7 +30,7 @@ export class SettingsModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, diff --git a/libs/core/templates/services/template.service.test.ts b/libs/core/templates/services/template.service.test.ts index d84be1d55d..7e21348682 100644 --- a/libs/core/templates/services/template.service.test.ts +++ b/libs/core/templates/services/template.service.test.ts @@ -21,13 +21,13 @@ const templateRepository = { delete: jest.fn(), } as unknown as TemplateRepository -const deviceManager = { +const deviceProtocolService = { device: { request: jest.fn(), }, } as unknown as DeviceProtocolService -const subject = new TemplateService(deviceManager, templateRepository) +const subject = new TemplateService(deviceProtocolService, templateRepository) const errorResponse: ErrorRequestResponse = { status: RequestResponseStatus.Error, @@ -65,14 +65,14 @@ beforeEach(() => { describe("`TemplateService`", () => { describe("`createTemplate` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest .fn() .mockReturnValue(successResponseWithTemplate) const response = await subject.createTemplate(newTemplate) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenNthCalledWith(1, { + expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(1, { endpoint: Endpoint.Messages, method: Method.Post, body: { @@ -84,12 +84,14 @@ describe("`TemplateService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.createTemplate(newTemplate) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Post, body: { @@ -103,12 +105,14 @@ describe("`TemplateService`", () => { }) describe("`updateTemplate` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(successResponse) + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(successResponse) const response = await subject.updateTemplate(template) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -120,12 +124,14 @@ describe("`TemplateService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.updateTemplate(template) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -138,15 +144,17 @@ describe("`TemplateService`", () => { }) }) describe("`updateTemplateOrder` method", () => { - test("map data and returns success when `deviceManager.device.request` returns success", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(successResponse) + test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(successResponse) const response = await subject.updateTemplatesOrder([ template, secondTemplate, ]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -158,18 +166,20 @@ describe("`TemplateService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenCalledTimes(2) + expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(2) }) - test("returns error when `deviceManager.device.request` returns error", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(errorResponse) + test("returns error when `deviceProtocolService.device.request` returns error", async () => { + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(errorResponse) const response = await subject.updateTemplatesOrder([ template, secondTemplate, ]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceManager.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -183,7 +193,9 @@ describe("`TemplateService`", () => { }) test("calls templateRepository update method for each updated template", async () => { - deviceManager.device.request = jest.fn().mockReturnValue(successResponse) + deviceProtocolService.device.request = jest + .fn() + .mockReturnValue(successResponse) await subject.updateTemplatesOrder([template, secondTemplate]) // AUTO DISABLED - fix me if you like :) diff --git a/libs/core/templates/services/template.service.ts b/libs/core/templates/services/template.service.ts index f4bafbb273..92fd42f167 100644 --- a/libs/core/templates/services/template.service.ts +++ b/libs/core/templates/services/template.service.ts @@ -24,7 +24,7 @@ import { export class TemplateService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private templateRepository: TemplateRepository ) {} @@ -32,23 +32,24 @@ export class TemplateService { template: NewTemplate ): Promise> { const createResponse = - await this.deviceManager.device.request({ - endpoint: Endpoint.Messages, - method: Method.Post, - body: TemplatePresenter.mapToPureNewTemplateBody(template), - }) + await this.deviceProtocolService.device.request( + { + endpoint: Endpoint.Messages, + method: Method.Post, + body: TemplatePresenter.mapToPureNewTemplateBody(template), + } + ) if (createResponse.ok && createResponse.data) { - const getResponse = await this.deviceManager.device.request( - { + const getResponse = + await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Get, body: { templateID: createResponse.data.templateID, category: MessagesCategory.template, }, - } - ) + }) if (getResponse.ok && getResponse.data) { const templateData = TemplatePresenter.mapToTemplate(getResponse.data) @@ -72,7 +73,7 @@ export class TemplateService { templateIds: string[] ): Promise { const results = templateIds.map(async (id) => { - const { ok } = await this.deviceManager.device.request({ + const { ok } = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Delete, body: { @@ -115,7 +116,7 @@ export class TemplateService { public async updateTemplate( template: Template ): Promise> { - const response = await this.deviceManager.device.request({ + const response = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Put, body: TemplatePresenter.mapToPureTemplateBody(template), @@ -140,7 +141,7 @@ export class TemplateService { templates: Template[] ): Promise { const results = templates.map(async (template) => { - const { ok } = await this.deviceManager.device.request({ + const { ok } = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Messages, method: Method.Put, body: TemplatePresenter.mapToPureTemplateOrder(template), diff --git a/libs/core/templates/template.module.ts b/libs/core/templates/template.module.ts index 232c6c1c82..af38d82b6e 100644 --- a/libs/core/templates/template.module.ts +++ b/libs/core/templates/template.module.ts @@ -19,7 +19,7 @@ import { DeviceProtocolService } from "device-protocol/feature" export class TemplateModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -28,7 +28,7 @@ export class TemplateModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -38,7 +38,7 @@ export class TemplateModule extends BaseModule { const templateModel = new TemplateModel(this.index, this.eventEmitter) const templateRepository = new TemplateRepository(templateModel) const templateService = new TemplateService( - this.deviceManager, + this.deviceProtocolService, templateRepository ) const templateController = new TemplateController(templateService) diff --git a/libs/core/update/services/device-update.service.ts b/libs/core/update/services/device-update.service.ts index 02f6273e5b..0fe9a331b3 100644 --- a/libs/core/update/services/device-update.service.ts +++ b/libs/core/update/services/device-update.service.ts @@ -21,7 +21,7 @@ import { DeviceInfoService } from "Core/device-info/services" export class DeviceUpdateService { constructor( private settingsService: SettingsService, - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private deviceFileSystem: DeviceFileSystemService, private deviceInfoService: DeviceInfoService ) {} @@ -89,7 +89,7 @@ export class DeviceUpdateService { ) } - const pureUpdateResponse = await this.deviceManager.device.request({ + const pureUpdateResponse = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Update, method: Method.Post, body: { @@ -129,7 +129,9 @@ export class DeviceUpdateService { ) } - if (this.deviceManager.device.deviceType === DeviceType.MuditaPure) { + if ( + this.deviceProtocolService.device.deviceType === DeviceType.MuditaPure + ) { const deviceUnlockedResponse = await this.waitUntilDeviceUnlocked() if (!deviceUnlockedResponse.ok) { @@ -166,7 +168,7 @@ export class DeviceUpdateService { private async getUnlockDeviceStatus(): Promise< ResultObject > { - const { ok, error } = await this.deviceManager.device.request({ + const { ok, error } = await this.deviceProtocolService.device.request({ endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -179,7 +181,7 @@ export class DeviceUpdateService { private async waitUntilDeviceRestart( index = 0, - deviceType = this.deviceManager.device.deviceType, + deviceType = this.deviceProtocolService.device.deviceType, timeout = 10000, callsMax = 60 ): Promise> { diff --git a/libs/core/update/update.module.ts b/libs/core/update/update.module.ts index 0ca199accc..5356795606 100644 --- a/libs/core/update/update.module.ts +++ b/libs/core/update/update.module.ts @@ -29,7 +29,7 @@ import { RELEASE_TIMEOUT } from "Core/update/constants/get-release-timeout.const export class UpdateModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -38,7 +38,7 @@ export class UpdateModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -54,9 +54,9 @@ export class UpdateModule extends BaseModule { const deviceUpdateService = new DeviceUpdateService( settingsService, - this.deviceManager, - new DeviceFileSystemService(this.deviceManager), - new DeviceInfoService(this.deviceManager) + this.deviceProtocolService, + new DeviceFileSystemService(this.deviceProtocolService), + new DeviceInfoService(this.deviceProtocolService) ) const deviceUpdateFilesService = new DeviceUpdateFilesService() const releaseService = new ReleaseService(createClient(RELEASE_TIMEOUT)) diff --git a/libs/device-manager/feature/src/controllers/device-manager.controller.ts b/libs/device-manager/feature/src/controllers/device-manager.controller.ts index 569136bdd6..b9964eb276 100644 --- a/libs/device-manager/feature/src/controllers/device-manager.controller.ts +++ b/libs/device-manager/feature/src/controllers/device-manager.controller.ts @@ -10,15 +10,15 @@ import { DeviceId } from "Core/device/constants/device-id" import { IpcDeviceManagerEvent } from "../constants" export class DeviceManagerController { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} @IpcEvent(IpcDeviceManagerEvent.SetActiveDevice) public setActiveDevice(id: DeviceId | undefined): ResultObject { - return this.deviceManager.setActiveDevice(id) + return this.deviceProtocolService.setActiveDevice(id) } @IpcEvent(IpcDeviceManagerEvent.ConnectDevice) public connectDevice(id: DeviceId): Promise> { - return this.deviceManager.connectDevice(id) + return this.deviceProtocolService.connectDevice(id) } } diff --git a/libs/device-manager/feature/src/device-manager.module.ts b/libs/device-manager/feature/src/device-manager.module.ts index ab77ee4a3d..2574d5bcad 100644 --- a/libs/device-manager/feature/src/device-manager.module.ts +++ b/libs/device-manager/feature/src/device-manager.module.ts @@ -9,9 +9,9 @@ import { DeviceManagerController } from "./controllers" export class DeviceManagerModule { public controllers - constructor(public deviceManager: DeviceProtocolService) { + constructor(public deviceProtocolService: DeviceProtocolService) { const deviceManagerController = new DeviceManagerController( - this.deviceManager + this.deviceProtocolService ) this.controllers = [deviceManagerController] diff --git a/libs/device-protocol/feature/src/device-protocol.module.ts b/libs/device-protocol/feature/src/device-protocol.module.ts index d600d684e9..d127f4c800 100644 --- a/libs/device-protocol/feature/src/device-protocol.module.ts +++ b/libs/device-protocol/feature/src/device-protocol.module.ts @@ -16,7 +16,7 @@ import { UsbDeviceDetectionObserver } from "./observers" export class DeviceProtocolModule extends BaseModule { constructor( public index: IndexStorage, - public deviceManager: DeviceProtocolService, + public deviceProtocolService: DeviceProtocolService, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -25,7 +25,7 @@ export class DeviceProtocolModule extends BaseModule { ) { super( index, - deviceManager, + deviceProtocolService, keyStorage, logger, ipc, @@ -34,7 +34,7 @@ export class DeviceProtocolModule extends BaseModule { ) const usbDeviceDetectionObserver = new UsbDeviceDetectionObserver( - this.deviceManager + this.deviceProtocolService ) this.initializers = [] diff --git a/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts b/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts index f95387e965..bb0e9a99cc 100644 --- a/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts +++ b/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts @@ -13,7 +13,7 @@ const intervalTime = 3000 export class UsbDeviceDetectionObserver implements Observer { private previousAttachedDevicePaths = new Set() - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} public observe(): void { void this.watchAttachedDevices() @@ -42,7 +42,8 @@ export class UsbDeviceDetectionObserver implements Observer { } private async detectDeviceStateChange(): Promise { - const attachedDevices = await this.deviceManager.getAttachedDevices() + const attachedDevices = + await this.deviceProtocolService.getAttachedDevices() const detachedDevicePaths = Array.from( this.previousAttachedDevicePaths ).filter( @@ -53,12 +54,12 @@ export class UsbDeviceDetectionObserver implements Observer { ) detachedDevicePaths.forEach((detachedDevicePath) => { - void this.deviceManager.removeDevice(detachedDevicePath) + void this.deviceProtocolService.removeDevice(detachedDevicePath) }) attachedDevices.forEach((attachedDevice) => { if (!this.previousAttachedDevicePaths.has(attachedDevice.path)) { - void this.deviceManager.addDevice(attachedDevice) + void this.deviceProtocolService.addDevice(attachedDevice) } }) diff --git a/libs/device/feature/src/lib/api-config/api-config.service.ts b/libs/device/feature/src/lib/api-config/api-config.service.ts index e3caf42058..7ea0345e7c 100644 --- a/libs/device/feature/src/lib/api-config/api-config.service.ts +++ b/libs/device/feature/src/lib/api-config/api-config.service.ts @@ -17,15 +17,15 @@ import { AppError } from "Core/core/errors" import { APIConfigError } from "./api-config-error" export class APIConfigService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} @IpcEvent(APIConfigServiceEvents.APIConfig) public async getAPIConfig( deviceId?: DeviceId ): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -51,7 +51,7 @@ export class APIConfigService { //to remove @IpcEvent(APIConfigServiceEvents.APIAny) public async getAPIAny(payload: unknown): Promise> { - const device = this.deviceManager.apiDevice + const device = this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) } diff --git a/libs/device/feature/src/lib/api-features/api-features.service.ts b/libs/device/feature/src/lib/api-features/api-features.service.ts index a439899f58..45156ac6b1 100644 --- a/libs/device/feature/src/lib/api-features/api-features.service.ts +++ b/libs/device/feature/src/lib/api-features/api-features.service.ts @@ -21,7 +21,7 @@ import { DeviceId } from "Core/device/constants/device-id" import { View } from "generic-view/utils" export class APIFeaturesService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} @IpcEvent(APIFeaturesServiceEvents.FeatureConfiguration) public async getFeatureConfiguration({ @@ -32,8 +32,8 @@ export class APIFeaturesService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -65,8 +65,8 @@ export class APIFeaturesService { deviceId?: DeviceId ): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -94,7 +94,7 @@ export class APIFeaturesService { @IpcEvent(APIFeaturesServiceEvents.FeatureData) public async getFeatureData(feature: string): Promise> { - const device = this.deviceManager.apiDevice + const device = this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) } @@ -125,8 +125,8 @@ export class APIFeaturesService { about: View }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/api-module.ts b/libs/device/feature/src/lib/api-module.ts index c2dd8b2167..20a29b946e 100644 --- a/libs/device/feature/src/lib/api-module.ts +++ b/libs/device/feature/src/lib/api-module.ts @@ -34,29 +34,34 @@ export class APIModule { private apiDataTransferService: APIDataTransferService constructor( - deviceManager: DeviceProtocolService, + deviceProtocolService: DeviceProtocolService, systemUtilsModule: SystemUtilsModule, settingsService: ISettingsService ) { this.serviceBridge = new ServiceBridge() - this.apiConfigService = new APIConfigService(deviceManager) - this.apiFeaturesService = new APIFeaturesService(deviceManager) - this.apiOutboxService = new APIOutboxService(deviceManager) - this.apiMenuService = new APIMenuService(deviceManager) + this.apiConfigService = new APIConfigService(deviceProtocolService) + this.apiFeaturesService = new APIFeaturesService(deviceProtocolService) + this.apiOutboxService = new APIOutboxService(deviceProtocolService) + this.apiMenuService = new APIMenuService(deviceProtocolService) this.serverService = new ServerService() - this.backupService = new APIBackupService(deviceManager) - this.apiDataTransferService = new APIDataTransferService(deviceManager) + this.backupService = new APIBackupService(deviceProtocolService) + this.apiDataTransferService = new APIDataTransferService( + deviceProtocolService + ) this.restoreService = new APIRestoreService( - deviceManager, + deviceProtocolService, this.serviceBridge ) this.fileTransferService = new APIFileTransferService( - deviceManager, + deviceProtocolService, + this.serviceBridge + ) + this.fileManager = new FileManager( + deviceProtocolService, this.serviceBridge ) - this.fileManager = new FileManager(deviceManager, this.serviceBridge) this.deviceSystemActionsService = new DeviceSystemActionsService( - deviceManager + deviceProtocolService ) this.serviceBridge.systemUtilsModule = systemUtilsModule this.serviceBridge.fileTransfer = this.fileTransferService diff --git a/libs/device/feature/src/lib/backup/backup.service.ts b/libs/device/feature/src/lib/backup/backup.service.ts index 0c426f4864..3f517c2fd1 100644 --- a/libs/device/feature/src/lib/backup/backup.service.ts +++ b/libs/device/feature/src/lib/backup/backup.service.ts @@ -19,7 +19,7 @@ import { import random from "lodash/random" export class APIBackupService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} @IpcEvent(APIBackupServiceEvents.StartPreBackup) public async startPreBackup({ @@ -30,8 +30,8 @@ export class APIBackupService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -62,8 +62,8 @@ export class APIBackupService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -89,8 +89,8 @@ export class APIBackupService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts b/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts index 5f246cb28d..3ef6756afc 100644 --- a/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts +++ b/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts @@ -22,7 +22,7 @@ import { import random from "lodash/random" export class APIDataTransferService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} @IpcEvent(APIDataTransferServiceEvents.StartPreDataTransfer) public async startPreDataTransfer({ @@ -33,8 +33,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -73,8 +73,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -100,8 +100,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -127,8 +127,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts b/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts index b04d9de18e..ea602221c0 100644 --- a/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts +++ b/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts @@ -10,15 +10,15 @@ import { GeneralError, DeviceSystemActionsServiceEvents } from "device/models" import { IpcEvent } from "Core/core/decorators" export class DeviceSystemActionsService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} private async sendSystemRequest( action: string, { deviceId }: { deviceId?: string } = {} ) { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/file-manager/file-manager.service.ts b/libs/device/feature/src/lib/file-manager/file-manager.service.ts index 89c690ff5d..6851cb4c9f 100644 --- a/libs/device/feature/src/lib/file-manager/file-manager.service.ts +++ b/libs/device/feature/src/lib/file-manager/file-manager.service.ts @@ -28,7 +28,7 @@ export class FileManager { private files: Record = {} constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private serviceBridge: ServiceBridge ) {} @@ -55,8 +55,8 @@ export class FileManager { @IpcEvent(FileManagerServiceEvents.GetBackupPath) public getBackupPath({ deviceId }: { deviceId?: DeviceId } = {}) { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -101,8 +101,8 @@ export class FileManager { password?: string }) { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts b/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts index 132d81eb21..e6b5b22530 100644 --- a/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts +++ b/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts @@ -38,7 +38,7 @@ const DEFAULT_MAX_REPEATS = 2 export class APIFileTransferService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private serviceBridge: ServiceBridge, private transfers: Record = {} ) {} @@ -122,8 +122,8 @@ export class APIFileTransferService { }> > { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -157,8 +157,8 @@ export class APIFileTransferService { }> > { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -191,8 +191,8 @@ export class APIFileTransferService { maxRepeats: number }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -256,8 +256,8 @@ export class APIFileTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -310,8 +310,8 @@ export class APIFileTransferService { maxRepeats: number }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -399,8 +399,8 @@ export class APIFileTransferService { }> > { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/menu/menu.service.ts b/libs/device/feature/src/lib/menu/menu.service.ts index 4b7ded54ee..3ad76585b7 100644 --- a/libs/device/feature/src/lib/menu/menu.service.ts +++ b/libs/device/feature/src/lib/menu/menu.service.ts @@ -16,15 +16,15 @@ import { import { DeviceId } from "Core/device/constants/device-id" export class APIMenuService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} @IpcEvent(APIMenuServiceEvents.GetMenuConfig) public async getMenuConfig( deviceId?: DeviceId ): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/outbox/outbox.service.ts b/libs/device/feature/src/lib/outbox/outbox.service.ts index 9ebf6a23d5..66f6b4ea07 100644 --- a/libs/device/feature/src/lib/outbox/outbox.service.ts +++ b/libs/device/feature/src/lib/outbox/outbox.service.ts @@ -16,13 +16,13 @@ import { } from "device/models" export class APIOutboxService { - constructor(private deviceManager: DeviceProtocolService) {} + constructor(private deviceProtocolService: DeviceProtocolService) {} @IpcEvent(APIOutboxServiceEvents.GetOutboxData) public async getOutboxData( deviceId: DeviceId ): Promise> { - const device = this.deviceManager.getAPIDeviceById(deviceId) + const device = this.deviceProtocolService.getAPIDeviceById(deviceId) if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) } diff --git a/libs/device/feature/src/lib/restore/restore.service.ts b/libs/device/feature/src/lib/restore/restore.service.ts index 16a9f8fd56..f1dc30e6b4 100644 --- a/libs/device/feature/src/lib/restore/restore.service.ts +++ b/libs/device/feature/src/lib/restore/restore.service.ts @@ -24,7 +24,7 @@ import { ServiceBridge } from "../service-bridge" export class APIRestoreService { constructor( - private deviceManager: DeviceProtocolService, + private deviceProtocolService: DeviceProtocolService, private serviceBridge: ServiceBridge ) {} @@ -40,8 +40,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -80,8 +80,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -107,8 +107,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -136,8 +136,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceManager.getAPIDeviceById(deviceId) - : this.deviceManager.apiDevice + ? this.deviceProtocolService.getAPIDeviceById(deviceId) + : this.deviceProtocolService.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) From fb96b1f3e80d1f3a24581f0baa1be3ce18952611 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Thu, 13 Jun 2024 06:00:23 +0200 Subject: [PATCH 006/100] [CP-2898] move useDebouncedEventsHandler to "shared/utils" --- libs/core/core/hooks/use-device-detached-effect.ts | 2 +- libs/shared/utils/src/index.ts | 1 + .../utils/src/lib}/use-debounced-events-handler.ts | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename libs/{core/core/hooks => shared/utils/src/lib}/use-debounced-events-handler.ts (100%) diff --git a/libs/core/core/hooks/use-device-detached-effect.ts b/libs/core/core/hooks/use-device-detached-effect.ts index 07e9d67c29..109418a9d4 100644 --- a/libs/core/core/hooks/use-device-detached-effect.ts +++ b/libs/core/core/hooks/use-device-detached-effect.ts @@ -25,7 +25,7 @@ import { URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" import { useDeactivateDeviceAndRedirect } from "Core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook" -import { useDebouncedEventsHandler } from "Core/core/hooks/use-debounced-events-handler" +import { useDebouncedEventsHandler } from "shared/utils" import { closeContactSupportFlow } from "Core/contact-support" export const useDeviceDetachedEffect = () => { diff --git a/libs/shared/utils/src/index.ts b/libs/shared/utils/src/index.ts index 9b03d09def..857e37930d 100644 --- a/libs/shared/utils/src/index.ts +++ b/libs/shared/utils/src/index.ts @@ -10,3 +10,4 @@ export * from "./lib/get-main-app-window" export * from "./lib/routes-history.context" export * from "./lib/main-event.constant" export * from "./lib/settings-service.interface" +export * from "./lib/use-debounced-events-handler" diff --git a/libs/core/core/hooks/use-debounced-events-handler.ts b/libs/shared/utils/src/lib/use-debounced-events-handler.ts similarity index 100% rename from libs/core/core/hooks/use-debounced-events-handler.ts rename to libs/shared/utils/src/lib/use-debounced-events-handler.ts From 000e486e137095a170fd4d2a2f811ac9e9cb9602 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Thu, 13 Jun 2024 12:56:07 +0200 Subject: [PATCH 007/100] [CP-2898] Change the strategy of the device selects (API & Core) for mds --- .../feature/src/actions/base.action.ts | 2 +- .../get-configured-core-devices.selector.ts | 15 ++++ .../get-failed-core-devices.selector.ts | 15 ++++ .../feature/src/selectors/index.ts | 2 + .../models/src/core-device.interface.ts | 4 +- .../hooks/use-device-connect-failed-effect.ts | 8 +- .../core/hooks/use-device-connected-effect.ts | 7 +- .../core/hooks/use-device-detached-effect.ts | 5 +- .../mudita-pure-initialization-modal-flow.tsx | 1 - .../devices-initialization.component.tsx | 4 +- .../device-select-drawer.component.tsx | 18 ++-- libs/core/device/modules/base-device.ts | 3 +- .../available-device-list.component.tsx | 6 +- .../components/device-list-item.component.tsx | 4 +- .../components/device-list.component.tsx | 4 +- .../src/actions/deactivate-device.action.ts | 4 +- .../device-manager-state.selector.ts | 2 +- .../get-active-device-base-data.selector.ts | 2 +- .../selectors/get-active-device.selector.ts | 4 +- .../get-available-devices.selector.ts | 4 +- .../get-configured-devices.selector.ts | 20 ++--- .../src/selectors/get-devices.selector.ts | 9 +- .../selectors/get-failed-devices.selector.ts | 12 +-- .../available-device-properties.interface.ts | 11 +++ libs/device-manager/models/src/index.ts | 1 + .../models/src}/device-base-properties.ts | 2 +- libs/device-protocol/models/src/index.ts | 1 + libs/generic-view/models/src/index.ts | 1 + libs/generic-view/models/src/lib/device.ts | 52 +++++++++++ .../lib/features/get-overview-data.actions.ts | 26 +++--- .../selectors/active-device-configuration.ts | 7 +- .../lib/selectors/active-device-menu-items.ts | 13 ++- .../lib/selectors/data-migration-devices.ts | 3 +- .../store/src/lib/selectors/index.ts | 5 +- .../lib/selectors/screen-title-selector.ts | 8 +- .../selectors/select-configured-device-ids.ts | 22 ----- .../selectors/select-configured-devices.ts | 28 ++++++ .../store/src/lib/selectors/select-devices.ts | 12 +++ .../lib/selectors/select-failed-devices.ts | 19 ++++ .../selectors/select-generic-view-state.ts | 10 +++ .../store/src/lib/views/reducer.ts | 89 +++++++------------ 41 files changed, 296 insertions(+), 169 deletions(-) create mode 100644 libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts create mode 100644 libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts create mode 100644 libs/device-manager/models/src/available-device-properties.interface.ts rename libs/{core/device/constants => device-protocol/models/src}/device-base-properties.ts (86%) create mode 100644 libs/generic-view/models/src/lib/device.ts delete mode 100644 libs/generic-view/store/src/lib/selectors/select-configured-device-ids.ts create mode 100644 libs/generic-view/store/src/lib/selectors/select-configured-devices.ts create mode 100644 libs/generic-view/store/src/lib/selectors/select-devices.ts create mode 100644 libs/generic-view/store/src/lib/selectors/select-failed-devices.ts create mode 100644 libs/generic-view/store/src/lib/selectors/select-generic-view-state.ts diff --git a/libs/core-device/feature/src/actions/base.action.ts b/libs/core-device/feature/src/actions/base.action.ts index 6d0b3dee60..3820361ca3 100644 --- a/libs/core-device/feature/src/actions/base.action.ts +++ b/libs/core-device/feature/src/actions/base.action.ts @@ -4,7 +4,7 @@ */ import { createAction } from "@reduxjs/toolkit" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" +import { DeviceBaseProperties } from "device-protocol/models" import { DeviceState, CaseColour } from "core-device/models" import { CoreDeviceEvent } from "../constants" diff --git a/libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts b/libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts new file mode 100644 index 0000000000..b2bda59478 --- /dev/null +++ b/libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { Device, DeviceState } from "core-device/models" +import { getCoreDevicesSelector } from "./get-core-devices.selector" + +export const getConfiguredCoreDevicesSelector = createSelector( + getCoreDevicesSelector, + (devices): Device[] => { + return devices.filter(({ state }) => state === DeviceState.Configured) + } +) diff --git a/libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts b/libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts new file mode 100644 index 0000000000..72ed530cd5 --- /dev/null +++ b/libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { Device, DeviceState } from "core-device/models" +import { getCoreDevicesSelector } from "./get-core-devices.selector" + +export const getFailedCoreDevicesSelector = createSelector( + getCoreDevicesSelector, + (devices): Device[] => { + return devices.filter(({ state }) => state === DeviceState.Failed) + } +) diff --git a/libs/core-device/feature/src/selectors/index.ts b/libs/core-device/feature/src/selectors/index.ts index d324907b37..63a3ecd917 100644 --- a/libs/core-device/feature/src/selectors/index.ts +++ b/libs/core-device/feature/src/selectors/index.ts @@ -4,4 +4,6 @@ */ export * from "./core-device-state.selector" +export * from "./get-configured-core-devices.selector" export * from "./get-core-devices.selector" +export * from "./get-failed-core-devices.selector" diff --git a/libs/core-device/models/src/core-device.interface.ts b/libs/core-device/models/src/core-device.interface.ts index dafa9a928d..9f6a291f4e 100644 --- a/libs/core-device/models/src/core-device.interface.ts +++ b/libs/core-device/models/src/core-device.interface.ts @@ -5,7 +5,7 @@ import { CaseColour } from "core-device/models" import { DeviceType } from "device-protocol/models" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" +import { AvailableDeviceProperties } from "device-manager/models" import { DeviceId } from "Core/device/constants/device-id" export enum DeviceState { @@ -15,7 +15,7 @@ export enum DeviceState { Failed = "FAILED", } -export interface Device extends DeviceBaseProperties { +export interface Device extends AvailableDeviceProperties { id: DeviceId serialNumber: string | undefined deviceType: DeviceType diff --git a/libs/core/core/hooks/use-device-connect-failed-effect.ts b/libs/core/core/hooks/use-device-connect-failed-effect.ts index 29baa53111..049a83ca95 100644 --- a/libs/core/core/hooks/use-device-connect-failed-effect.ts +++ b/libs/core/core/hooks/use-device-connect-failed-effect.ts @@ -7,11 +7,13 @@ import { useEffect, useCallback } from "react" import { useHistory } from "react-router-dom" import { useDispatch, useSelector } from "react-redux" import { answerMain } from "shared/utils" -import { DeviceProtocolMainEvent } from "device-protocol/models" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" -import { activeDeviceIdSelector } from "device-manager/feature" +import { + DeviceProtocolMainEvent, + DeviceBaseProperties, +} from "device-protocol/models" import { DeviceState } from "core-device/models" import { addDevice, getDeviceConfigurationRequest } from "core-device/feature" +import { activeDeviceIdSelector } from "device-manager/feature" import { Dispatch } from "Core/__deprecated__/renderer/store" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" diff --git a/libs/core/core/hooks/use-device-connected-effect.ts b/libs/core/core/hooks/use-device-connected-effect.ts index c1515351d8..88651cbfe0 100644 --- a/libs/core/core/hooks/use-device-connected-effect.ts +++ b/libs/core/core/hooks/use-device-connected-effect.ts @@ -17,10 +17,13 @@ import { configureDevice, getDeviceConfigurationRequest, } from "core-device/feature" -import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" +import { + DeviceProtocolMainEvent, + DeviceType, + DeviceBaseProperties, +} from "device-protocol/models" import { selectDialogOpenState } from "shared/app-state" import { Dispatch } from "Core/__deprecated__/renderer/store" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" diff --git a/libs/core/core/hooks/use-device-detached-effect.ts b/libs/core/core/hooks/use-device-detached-effect.ts index 109418a9d4..96a0bbf1b6 100644 --- a/libs/core/core/hooks/use-device-detached-effect.ts +++ b/libs/core/core/hooks/use-device-detached-effect.ts @@ -6,8 +6,8 @@ import { useCallback, useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" -import { answerMain } from "shared/utils" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" +import { answerMain, useDebouncedEventsHandler } from "shared/utils" +import { DeviceBaseProperties } from "device-protocol/models" import { removeDevice } from "core-device/feature" import { getDevicesSelector } from "device-manager/feature" import { selectDialogOpenState } from "shared/app-state" @@ -25,7 +25,6 @@ import { URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" import { useDeactivateDeviceAndRedirect } from "Core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook" -import { useDebouncedEventsHandler } from "shared/utils" import { closeContactSupportFlow } from "Core/contact-support" export const useDeviceDetachedEffect = () => { diff --git a/libs/core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow.tsx b/libs/core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow.tsx index 0ba0ab2963..fbdc9330cb 100644 --- a/libs/core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow.tsx +++ b/libs/core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow.tsx @@ -6,7 +6,6 @@ import React, { useEffect, useRef } from "react" import { useSelector } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" - import { deviceStatusSelector } from "Core/device/selectors/device-status.selector" import { useDeviceInitializer } from "Core/device-initialization/components/devices-initialization-modal-flows/handle-initialize-device.helper" import { initializeMuditaPure } from "Core/device-initialization/actions/initialize-mudita-pure.action" diff --git a/libs/core/device-initialization/components/devices-initialization.component.tsx b/libs/core/device-initialization/components/devices-initialization.component.tsx index 2a1b34cfd9..a09eac886e 100644 --- a/libs/core/device-initialization/components/devices-initialization.component.tsx +++ b/libs/core/device-initialization/components/devices-initialization.component.tsx @@ -8,14 +8,14 @@ import { useSelector } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" import { getActiveDevice } from "device-manager/feature" +import { AvailableDeviceProperties } from "device-manager/models" import { DeviceType } from "device-protocol/models" import { MuditaPureInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow" import { MuditaHarmonyInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-harmony-initialization-modal-flow" import { APIDeviceInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow" -import { Device } from "core-device/models" const DevicesInitializationModalFlow: FunctionComponent<{ - activeDevice?: Device + activeDevice?: AvailableDeviceProperties }> = ({ activeDevice }) => { if (activeDevice?.deviceType === DeviceType.MuditaPure) { return diff --git a/libs/core/device-select/components/device-select-drawer.component.tsx b/libs/core/device-select/components/device-select-drawer.component.tsx index 96a12c9e67..a4e0a30057 100644 --- a/libs/core/device-select/components/device-select-drawer.component.tsx +++ b/libs/core/device-select/components/device-select-drawer.component.tsx @@ -3,14 +3,19 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import "react-modern-drawer/dist/index.css" +import Drawer from "react-modern-drawer" import * as React from "react" import { useSelector, useDispatch } from "react-redux" +import { useHistory } from "react-router-dom" +import { defineMessages } from "react-intl" +import { + getFailedDevicesSelector, + setSelectDeviceDrawerOpen, +} from "device-manager/feature" import { Dispatch } from "Core/__deprecated__/renderer/store" -import Drawer from "react-modern-drawer" -import "react-modern-drawer/dist/index.css" import { FunctionComponent } from "Core/core/types/function-component.interface" import { isSelectDeviceDrawerOpenSelector } from "Core/device-select/selectors/is-select-device-drawer-open.selector" -import { setSelectDeviceDrawerOpen } from "device-manager/feature" import Text, { TextDisplayStyle, } from "Core/__deprecated__/renderer/components/core/text/text.component" @@ -24,14 +29,12 @@ import { activeDeviceIdSelector, handleDeviceActivated, } from "device-manager/feature" -import { useHistory } from "react-router-dom" import { DeviceState } from "core-device/models" import { URL_DEVICE_INITIALIZATION, URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" import { DrawerDevice } from "Core/device-select/components/drawer-device.component" -import { defineMessages } from "react-intl" import { DeviceId } from "Core/device/constants/device-id" import { ModalLayers } from "Core/modals-manager/constants/modal-layers.enum" import { useEffect } from "react" @@ -78,14 +81,15 @@ const DevicesContainer = styled("div")` const DeviceSelectDrawer: FunctionComponent = () => { const isOpen = useSelector(isSelectDeviceDrawerOpenSelector) const devices = useSelector(getAvailableDevicesSelector) + const failedDevices = useSelector(getFailedDevicesSelector) const activeDeviceId = useSelector(activeDeviceIdSelector) const dispatch = useDispatch() const history = useHistory() const handleDrawerDeviceClick = async (id: DeviceId) => { dispatch(setSelectDeviceDrawerOpen(false)) - const device = devices.find((device) => device.id === id) - if (device?.state === DeviceState.Failed) { + const failedDevice = failedDevices.find((device) => device.id === id) + if (failedDevice !== undefined) { await dispatch(handleDeviceActivated(id)) history.push(URL_ONBOARDING.troubleshooting) } else { diff --git a/libs/core/device/modules/base-device.ts b/libs/core/device/modules/base-device.ts index efcce192d0..f96532fd3c 100644 --- a/libs/core/device/modules/base-device.ts +++ b/libs/core/device/modules/base-device.ts @@ -5,9 +5,8 @@ import { PortInfo } from "serialport" import { ResultObject } from "Core/core/builder" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" +import { DeviceBaseProperties, DeviceType } from "device-protocol/models" import { DeviceId } from "Core/device/constants/device-id" -import { DeviceType } from "device-protocol/models" import { unknownSerialNumber } from "Core/device/constants/unknown-serial-number.constant" const uniqueId = (length = 16): DeviceId => { diff --git a/libs/core/discovery-device/components/available-device-list.component.tsx b/libs/core/discovery-device/components/available-device-list.component.tsx index 8483bca7f1..f52207bccc 100644 --- a/libs/core/discovery-device/components/available-device-list.component.tsx +++ b/libs/core/discovery-device/components/available-device-list.component.tsx @@ -18,6 +18,7 @@ import DeviceList from "Core/discovery-device/components/device-list.component" import { Dispatch } from "Core/__deprecated__/renderer/store" import { getAvailableDevicesSelector, + getFailedDevicesSelector, handleDeviceActivated, } from "device-manager/feature" import { @@ -54,10 +55,11 @@ const AvailableDeviceList: FunctionComponent = () => { const history = useHistory() const dispatch = useDispatch() const devices = useSelector(getAvailableDevicesSelector) + const failedDevices = useSelector(getFailedDevicesSelector) const handleDeviceClick = async (id: string) => { - const device = devices.find((device) => device.id === id) - if (device?.state === DeviceState.Failed) { + const failedDevice = failedDevices.find((device) => device.id === id) + if (failedDevice !== undefined) { await dispatch(handleDeviceActivated(id)) history.push(URL_ONBOARDING.troubleshooting) } else { diff --git a/libs/core/discovery-device/components/device-list-item.component.tsx b/libs/core/discovery-device/components/device-list-item.component.tsx index b2a251704a..e9b5036953 100644 --- a/libs/core/discovery-device/components/device-list-item.component.tsx +++ b/libs/core/discovery-device/components/device-list-item.component.tsx @@ -6,8 +6,8 @@ import React from "react" import { defineMessages } from "react-intl" import styled, { css } from "styled-components" +import { AvailableDeviceProperties } from "device-manager/models" import { FunctionComponent } from "Core/core/types/function-component.interface" -import { Device } from "core-device/models" import { backgroundColor, borderColor, @@ -93,7 +93,7 @@ export const DeviceInfoDeviceTypeName = styled(Text)` margin-bottom: 0.5rem; ` -export interface DeviceListItemProps extends Device { +export interface DeviceListItemProps extends AvailableDeviceProperties { onDeviceClick: (id: string) => void } diff --git a/libs/core/discovery-device/components/device-list.component.tsx b/libs/core/discovery-device/components/device-list.component.tsx index 3c14579b2b..a43806d3ab 100644 --- a/libs/core/discovery-device/components/device-list.component.tsx +++ b/libs/core/discovery-device/components/device-list.component.tsx @@ -6,11 +6,11 @@ import React from "react" import styled from "styled-components" import { FunctionComponent } from "Core/core/types/function-component.interface" -import { Device } from "core-device/models" +import { AvailableDeviceProperties } from "device-manager/models" import DeviceListItem from "Core/discovery-device/components/device-list-item.component" interface Props { - devices: Device[] + devices: AvailableDeviceProperties[] onDeviceClick: (id: string) => void } diff --git a/libs/device-manager/feature/src/actions/deactivate-device.action.ts b/libs/device-manager/feature/src/actions/deactivate-device.action.ts index a677671cc5..eea6dc2f89 100644 --- a/libs/device-manager/feature/src/actions/deactivate-device.action.ts +++ b/libs/device-manager/feature/src/actions/deactivate-device.action.ts @@ -4,7 +4,7 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { Device } from "core-device/models" +import { DeviceBaseProperties } from "device-protocol/models" import { DeviceManagerEvent } from "device-manager/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" @@ -17,7 +17,7 @@ import { getDevicesSelector } from "../selectors" import { setSelectDeviceDrawerOpen } from "./set-select-device-drawer-open.action" export const deactivateDevice = createAsyncThunk< - Device[], + DeviceBaseProperties[], void, { state: ReduxRootState } >(DeviceManagerEvent.DeactivateDevice, async (_, { dispatch, getState }) => { diff --git a/libs/device-manager/feature/src/selectors/device-manager-state.selector.ts b/libs/device-manager/feature/src/selectors/device-manager-state.selector.ts index 42e9a88af8..1d71ae4f62 100644 --- a/libs/device-manager/feature/src/selectors/device-manager-state.selector.ts +++ b/libs/device-manager/feature/src/selectors/device-manager-state.selector.ts @@ -3,8 +3,8 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +import { DeviceManagerState } from "device-manager/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { DeviceManagerState } from "../../../models/src/device-manager.interface" export const deviceManagerState = (state: ReduxRootState): DeviceManagerState => state.deviceManager diff --git a/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts index f9e08d9da5..20e51a5c09 100644 --- a/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts @@ -5,7 +5,7 @@ import { createSelector } from "@reduxjs/toolkit" import { getCoreDevicesSelector } from "core-device/feature" -import { DeviceBaseProperties } from "Core/device/constants/device-base-properties" +import { DeviceBaseProperties } from "device-protocol/models" import { DeviceState, HarmonyDeviceData, diff --git a/libs/device-manager/feature/src/selectors/get-active-device.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts index 07a12b4cd8..f4ed0f4bc8 100644 --- a/libs/device-manager/feature/src/selectors/get-active-device.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts @@ -4,14 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" +import { AvailableDeviceProperties } from "device-manager/models" import { deviceManagerState } from "./device-manager-state.selector" -import { Device } from "core-device/models" import { getDevicesSelector } from "./get-devices.selector" export const getActiveDevice = createSelector( getDevicesSelector, deviceManagerState, - (devices, deviceManager): Device | undefined => { + (devices, deviceManager): AvailableDeviceProperties | undefined => { const { activeDeviceId } = deviceManager return devices.find(({ id }) => id === activeDeviceId) } diff --git a/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts index 74179f75a0..363db33dad 100644 --- a/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts @@ -4,14 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { Device } from "core-device/models" +import { AvailableDeviceProperties } from "device-manager/models" import { getFailedDevicesSelector } from "./get-failed-devices.selector" import { getConfiguredDevicesSelector } from "./get-configured-devices.selector" export const getAvailableDevicesSelector = createSelector( getConfiguredDevicesSelector, getFailedDevicesSelector, - (configuredDevices, failedDevices): Device[] => { + (configuredDevices, failedDevices): AvailableDeviceProperties[] => { return [...configuredDevices, ...failedDevices] } ) diff --git a/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts index 94e072556b..8a20e169f6 100644 --- a/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts @@ -4,20 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { Device, DeviceState } from "core-device/models" -import { selectConfiguredDeviceIDs } from "generic-view/store" -import { DeviceType } from "device-protocol/models" -import { getDevicesSelector } from "./get-devices.selector" +import { AvailableDeviceProperties } from "device-manager/models" +import { selectConfiguredDevices } from "generic-view/store" +import { getConfiguredCoreDevicesSelector } from "core-device/feature" export const getConfiguredDevicesSelector = createSelector( - getDevicesSelector, - selectConfiguredDeviceIDs, - (devices, apiIds): Device[] => { - return devices.filter(({ state, deviceType, id }) => { - if (deviceType === DeviceType.APIDevice && apiIds.includes(id)) { - return true - } - return state === DeviceState.Configured - }) + getConfiguredCoreDevicesSelector, + selectConfiguredDevices, + (coreDevices, apiDevices): AvailableDeviceProperties[] => { + return [...coreDevices, ...Object.values(apiDevices)] } ) diff --git a/libs/device-manager/feature/src/selectors/get-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-devices.selector.ts index 14b7213669..c4144bccf6 100644 --- a/libs/device-manager/feature/src/selectors/get-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-devices.selector.ts @@ -4,13 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { Device } from "core-device/models" +import { DeviceBaseProperties } from "device-protocol/models" import { getCoreDevicesSelector } from "core-device/feature" +import { selectDevices } from "generic-view/store" export const getDevicesSelector = createSelector( getCoreDevicesSelector, - (coreDevices): Device[] => { - // TODO: add api devices - return coreDevices + selectDevices, + (coreDevices, apiDevices): DeviceBaseProperties[] => { + return [...coreDevices, ...Object.values(apiDevices)] } ) diff --git a/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts index 6f151e74ff..427ab3c43a 100644 --- a/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts @@ -4,12 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { getDevicesSelector } from "./get-devices.selector" -import { Device, DeviceState } from "core-device/models" +import { AvailableDeviceProperties } from "device-manager/models" +import { getFailedCoreDevicesSelector } from "core-device/feature" +import { selectFailedDevices } from "generic-view/store" export const getFailedDevicesSelector = createSelector( - getDevicesSelector, - (devices): Device[] => { - return devices.filter(({ state }) => state === DeviceState.Failed) + getFailedCoreDevicesSelector, + selectFailedDevices, + (failedCoreDevices, failedApiDevices): AvailableDeviceProperties[] => { + return [...failedCoreDevices, ...Object.values(failedApiDevices)] } ) diff --git a/libs/device-manager/models/src/available-device-properties.interface.ts b/libs/device-manager/models/src/available-device-properties.interface.ts new file mode 100644 index 0000000000..953cd95081 --- /dev/null +++ b/libs/device-manager/models/src/available-device-properties.interface.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 { DeviceBaseProperties } from "device-protocol/models" +import { CaseColour } from "core-device/models" + +export interface AvailableDeviceProperties extends DeviceBaseProperties { + caseColour?: CaseColour | undefined +} diff --git a/libs/device-manager/models/src/index.ts b/libs/device-manager/models/src/index.ts index 20c1458f7c..f0c2ff6ad6 100644 --- a/libs/device-manager/models/src/index.ts +++ b/libs/device-manager/models/src/index.ts @@ -3,5 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +export * from "./available-device-properties.interface" export * from "./device-manager.interface" export * from "./event.constant" diff --git a/libs/core/device/constants/device-base-properties.ts b/libs/device-protocol/models/src/device-base-properties.ts similarity index 86% rename from libs/core/device/constants/device-base-properties.ts rename to libs/device-protocol/models/src/device-base-properties.ts index bad32da02f..52ed8a2d17 100644 --- a/libs/core/device/constants/device-base-properties.ts +++ b/libs/device-protocol/models/src/device-base-properties.ts @@ -4,7 +4,7 @@ */ import { PortInfo } from "serialport" -import { DeviceType } from "device-protocol/models" +import { DeviceType } from "./device-type.constant" export interface DeviceBaseProperties extends PortInfo { id: string diff --git a/libs/device-protocol/models/src/index.ts b/libs/device-protocol/models/src/index.ts index f3133bbb27..9594b3b9d2 100644 --- a/libs/device-protocol/models/src/index.ts +++ b/libs/device-protocol/models/src/index.ts @@ -3,5 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +export * from "./device-base-properties" export * from "./device-protocol-main-event" export * from "./device-type.constant" diff --git a/libs/generic-view/models/src/index.ts b/libs/generic-view/models/src/index.ts index 1e650666a8..726bd10bd3 100644 --- a/libs/generic-view/models/src/index.ts +++ b/libs/generic-view/models/src/index.ts @@ -59,6 +59,7 @@ export * from "./lib/image" export * from "./lib/labeled-text" export * from "./lib/text-formatted" export * from "./lib/text-plain" +export * from "./lib/device" export * from "./lib/divider" export * from "./lib/icon" export * from "./lib/modal" diff --git a/libs/generic-view/models/src/lib/device.ts b/libs/generic-view/models/src/lib/device.ts new file mode 100644 index 0000000000..86f80208a4 --- /dev/null +++ b/libs/generic-view/models/src/lib/device.ts @@ -0,0 +1,52 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { DeviceType } from "device-protocol/models" +import { View } from "generic-view/utils" +import { AvailableDeviceProperties } from "device-manager/models" +import { ApiConfig, MenuConfig, OverviewData } from "device/models" +import { DeviceId } from "Core/device/constants/device-id" + +export type Features = { + "mc-overview"?: { + config?: View + data?: OverviewData + } + "mc-about"?: { + config?: View + data?: OverviewData + } +} & { + [key: string]: { + config?: View + data?: Record + } +} + +export interface DeviceConfiguration { + apiConfig: ApiConfig + menuConfig?: MenuConfig + features?: Features +} + +export enum DeviceState { + Connected = "CONNECTED", + Configured = "CONFIGURED", + Initialized = "INITIALIZED", + Failed = "FAILED", +} + +export interface Device + extends AvailableDeviceProperties, + Partial { + id: DeviceId + serialNumber: string | undefined + deviceType: DeviceType + state: DeviceState +} + +export interface ConfiguredDevice + extends AvailableDeviceProperties, + DeviceConfiguration {} diff --git a/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts b/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts index b0080fef96..5124e44bcf 100644 --- a/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts +++ b/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts @@ -4,12 +4,13 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { FeaturesActions } from "./featues-action-keys" import { getDeviceOSVersion, getOverviewDataRequest } from "device/feature" -import { DeviceId } from "Core/device/constants/device-id" import { generateMcAboutData, generateMcOverviewData } from "generic-view/views" import { View } from "generic-view/utils" +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { DeviceId } from "Core/device/constants/device-id" +import { selectConfiguredDevice } from "../selectors" +import { FeaturesActions } from "./featues-action-keys" export const getOverviewData = createAsyncThunk< { @@ -22,21 +23,20 @@ export const getOverviewData = createAsyncThunk< >( FeaturesActions.GetOverviewData, async ({ deviceId }, { rejectWithValue, getState }) => { - const apiConfig = - getState().genericViews.devicesConfiguration[deviceId].apiConfig + const apiConfig = selectConfiguredDevice(getState(), deviceId)?.apiConfig + + if (apiConfig === undefined) { + return rejectWithValue("no device") + } const serverResponse = await getDeviceOSVersion( apiConfig.productId, apiConfig.vendorId ) - const overviewConfig = - getState().genericViews.devicesConfiguration[deviceId]?.features?.[ - "mc-overview" - ]?.config - const aboutConfig = - getState().genericViews.devicesConfiguration[deviceId]?.features?.[ - "mc-about" - ]?.config + + const features = selectConfiguredDevice(getState(), deviceId)?.features + const overviewConfig = features?.["mc-overview"]?.config + const aboutConfig = features?.["mc-about"]?.config const response = await getOverviewDataRequest( deviceId, overviewConfig ?? ({} as View), diff --git a/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts b/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts index 9cc922d878..42fe1aa951 100644 --- a/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts +++ b/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts @@ -4,14 +4,11 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { selectConfiguredDevices } from "./select-configured-devices" import { selectActiveDevice } from "./active-device" export const selectActiveDeviceConfiguration = createSelector( - [ - selectActiveDevice, - (state: ReduxRootState) => state.genericViews.devicesConfiguration, - ], + [selectActiveDevice, selectConfiguredDevices], (activeDevice, devicesConfiguration) => { if (activeDevice) { return devicesConfiguration[activeDevice] diff --git a/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts b/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts index 8747414cd8..e61a8b9d5e 100644 --- a/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts +++ b/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts @@ -4,18 +4,15 @@ */ import { createSelector } from "@reduxjs/toolkit" - -import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { generateMenu } from "generic-view/utils" +import { selectActiveDevice } from "./active-device" +import { selectConfiguredDevices } from "./select-configured-devices" export const activeDeviceMenuItems = createSelector( - [ - (state: ReduxRootState) => state.genericViews.activeDevice, - (state: ReduxRootState) => state.genericViews.devicesConfiguration, - ], - (activeDevice, devicesConfiguration) => { + [selectActiveDevice, selectConfiguredDevices], + (activeDevice, configuredDevices) => { if (activeDevice) { - return devicesConfiguration[activeDevice].menuConfig + return configuredDevices[activeDevice].menuConfig } return undefined } diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts index b394f9eaff..f9baae52e9 100644 --- a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts +++ b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts @@ -8,6 +8,7 @@ import { createSelector } from "@reduxjs/toolkit" import pureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" import pureGreyImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" import { kompaktImg } from "Root/demo-data/kompakt-img" +import { selectConfiguredDevices } from "./select-configured-devices" import { getDeviceTypeName } from "Core/discovery-device/utils/get-device-type-name" // FIXME: The device name should be moved to the API config response of API device @@ -28,7 +29,7 @@ export const selectDataMigrationSourceDevices = createSelector( ) export const selectDataMigrationTargetDevices = createSelector( - (state: ReduxRootState) => state.genericViews.devicesConfiguration, + selectConfiguredDevices, (devices) => { return Object.values(devices) .map((device) => { diff --git a/libs/generic-view/store/src/lib/selectors/index.ts b/libs/generic-view/store/src/lib/selectors/index.ts index 185839b910..2cc2c004ee 100644 --- a/libs/generic-view/store/src/lib/selectors/index.ts +++ b/libs/generic-view/store/src/lib/selectors/index.ts @@ -4,7 +4,6 @@ */ export * from "./active-device-menu-items" -export * from "./select-configured-device-ids" export * from "./screen-title-selector" export * from "./active-device" export * from "./active-device-features" @@ -24,3 +23,7 @@ export * from "./data-migration-features" export * from "./data-migration-status" export * from "./data-migration-progress" export * from "./data-transfer-progress" +export * from "./select-configured-devices" +export * from "./select-devices" +export * from "./select-failed-devices" +export * from "./select-generic-view-state" diff --git a/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts b/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts index fc30537cf4..d1b6c78617 100644 --- a/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts +++ b/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts @@ -3,12 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { createSelector } from "reselect" +import { createSelector } from "@reduxjs/toolkit" import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { selectActiveDevice } from "./active-device" +import { selectConfiguredDevices } from "./select-configured-devices" export const screenTitleSelector = createSelector( - (state: ReduxRootState) => state.genericViews.activeDevice, - (state: ReduxRootState) => state.genericViews.devicesConfiguration, + selectActiveDevice, + selectConfiguredDevices, (state: ReduxRootState, viewKey: string) => viewKey, (activeDevice, devices, viewKey) => { const features = devices[activeDevice as keyof typeof devices]?.features diff --git a/libs/generic-view/store/src/lib/selectors/select-configured-device-ids.ts b/libs/generic-view/store/src/lib/selectors/select-configured-device-ids.ts deleted file mode 100644 index 82d7ea5a45..0000000000 --- a/libs/generic-view/store/src/lib/selectors/select-configured-device-ids.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 { createSelector } from "@reduxjs/toolkit" - -import { ReduxRootState } from "Core/__deprecated__/renderer/store" - -export const selectConfiguredDeviceIDs = createSelector( - [(state: ReduxRootState) => state.genericViews.devicesConfiguration], - (devices) => { - return Object.entries(devices) - .map(([id, data]) => { - if (data.apiConfig) { - return id - } - return null - }) - .filter(Boolean) - } -) diff --git a/libs/generic-view/store/src/lib/selectors/select-configured-devices.ts b/libs/generic-view/store/src/lib/selectors/select-configured-devices.ts new file mode 100644 index 0000000000..ee4acb234d --- /dev/null +++ b/libs/generic-view/store/src/lib/selectors/select-configured-devices.ts @@ -0,0 +1,28 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { ConfiguredDevice, DeviceState } from "generic-view/models" +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { selectDevices } from "./select-devices" + +export const selectConfiguredDevices = createSelector( + selectDevices, + (devices): Record => { + const filteredDevices = Object.fromEntries( + Object.entries(devices).filter( + ([_, data]) => data.state === DeviceState.Configured + ) + ) + + return filteredDevices as Record + } +) + +export const selectConfiguredDevice = createSelector( + selectConfiguredDevices, + (_state: ReduxRootState, id: string) => id, + (configuredDevices, id): ConfiguredDevice | undefined => configuredDevices[id] +) diff --git a/libs/generic-view/store/src/lib/selectors/select-devices.ts b/libs/generic-view/store/src/lib/selectors/select-devices.ts new file mode 100644 index 0000000000..f9c61cdc4f --- /dev/null +++ b/libs/generic-view/store/src/lib/selectors/select-devices.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { selectGenericViewState } from "./select-generic-view-state" + +export const selectDevices = createSelector( + [selectGenericViewState], + ({ devices }) => devices +) diff --git a/libs/generic-view/store/src/lib/selectors/select-failed-devices.ts b/libs/generic-view/store/src/lib/selectors/select-failed-devices.ts new file mode 100644 index 0000000000..0f7f9d517e --- /dev/null +++ b/libs/generic-view/store/src/lib/selectors/select-failed-devices.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { Device, DeviceState } from "generic-view/models" +import { selectDevices } from "./select-devices" + +export const selectFailedDevices = createSelector( + selectDevices, + (devices): Record => { + return Object.fromEntries( + Object.entries(devices).filter( + ([_, data]) => data.state === DeviceState.Failed + ) + ) + } +) diff --git a/libs/generic-view/store/src/lib/selectors/select-generic-view-state.ts b/libs/generic-view/store/src/lib/selectors/select-generic-view-state.ts new file mode 100644 index 0000000000..1184ba950d --- /dev/null +++ b/libs/generic-view/store/src/lib/selectors/select-generic-view-state.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import { GenericState } from "../views/reducer" + +export const selectGenericViewState = (state: ReduxRootState): GenericState => + state.genericViews diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index f8bd72fa39..908911ae54 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -6,7 +6,17 @@ import { createReducer } from "@reduxjs/toolkit" import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-elements" import { View } from "generic-view/utils" +import { Device, DeviceState, Features } from "generic-view/models" +import { ApiError } from "device/models" +import { DeviceId } from "Core/device/constants/device-id" +import { AppError } from "Core/core/errors" import { getAPIConfig } from "../get-api-config" +import { getOverviewData } from "../features" +import { getOverviewConfig } from "../features/get-overview-config.actions" +import { getAPIAny } from "../get-api-any" +import { getMenuConfig } from "../get-menu-config" +import { getOutboxData } from "../outbox/get-outbox-data.action" +import { getGenericConfig } from "../features/get-generic-config.actions" import { activateDevice, detachDevice, @@ -14,38 +24,8 @@ import { setViewData, setViewLayout, } from "./actions" -import { getOverviewData } from "../features" -import { getOverviewConfig } from "../features/get-overview-config.actions" -import { getAPIAny } from "../get-api-any" -import { ApiConfig, ApiError, MenuConfig, OverviewData } from "device/models" -import { getMenuConfig } from "../get-menu-config" -import { DeviceId } from "Core/device/constants/device-id" -import { getOutboxData } from "../outbox/get-outbox-data.action" -import { AppError } from "Core/core/errors" -import { getGenericConfig } from "../features/get-generic-config.actions" -type Features = { - "mc-overview"?: { - config?: View - data?: OverviewData - } - "mc-about"?: { - config?: View - data?: OverviewData - } -} & { - [key: string]: { - config?: View - data?: Record - } -} -interface DeviceConfiguration { - apiConfig: ApiConfig - menuConfig?: MenuConfig - features?: Features -} - -interface GenericState { +export interface GenericState { menu: MenuElement[] | undefined views: Record< string, @@ -58,7 +38,7 @@ interface GenericState { lastRefresh?: number activeDevice?: DeviceId pendingDevice?: DeviceId - devicesConfiguration: Record + devices: Record apiErrors: Record } @@ -66,7 +46,7 @@ const initialState: GenericState = { menu: undefined, views: {}, lastResponse: {}, - devicesConfiguration: {}, + devices: {}, apiErrors: { [ApiError.DeviceLocked]: false, }, @@ -89,13 +69,17 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { } }) builder.addCase(getAPIConfig.fulfilled, (state, action) => { - state.devicesConfiguration[action.payload.deviceId] = { + const device = state.devices[action.payload.deviceId] + + state.devices[action.payload.deviceId] = { + ...device, + state: DeviceState.Configured, apiConfig: action.payload.apiConfig, } state.lastResponse = action.payload }) builder.addCase(getMenuConfig.fulfilled, (state, action) => { - state.devicesConfiguration[action.payload.deviceId].menuConfig = + state.devices[action.payload.deviceId].menuConfig = action.payload.menuConfig state.lastResponse = action.payload state.apiErrors[ApiError.DeviceLocked] = false @@ -116,20 +100,16 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { state.lastResponse = action.payload const deviceId = action.payload.deviceId if (deviceId) { - state.devicesConfiguration[deviceId].features = { - ...state.devicesConfiguration[deviceId].features, + state.devices[deviceId].features = { + ...state.devices[deviceId].features, "mc-overview": { - config: - state.devicesConfiguration[deviceId].features?.["mc-overview"] - ?.config, + config: state.devices[deviceId].features?.["mc-overview"]?.config, data: action.payload.overviewData, }, ...(action.payload.aboutData ? { "mc-about": { - config: - state.devicesConfiguration[deviceId].features?.["mc-about"] - ?.config, + config: state.devices[deviceId].features?.["mc-about"]?.config, data: action.payload.aboutData, }, } @@ -141,20 +121,17 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { state.lastResponse = action.payload const deviceId = action.payload.deviceId if (deviceId) { - state.devicesConfiguration[deviceId].features = { - ...state.devicesConfiguration[deviceId].features, + state.devices[deviceId].features = { + ...state.devices[deviceId].features, "mc-overview": { config: action.payload.overviewConfig, - data: state.devicesConfiguration[deviceId].features?.["mc-overview"] - ?.data, + data: state.devices[deviceId].features?.["mc-overview"]?.data, }, ...(action.payload.aboutConfig ? { "mc-about": { config: action.payload.aboutConfig, - data: state.devicesConfiguration[deviceId].features?.[ - "mc-about" - ]?.data, + data: state.devices[deviceId].features?.["mc-about"]?.data, }, } : {}), @@ -167,15 +144,15 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { }) builder.addCase(activateDevice, (state, action) => { const { deviceId } = action.payload - state.activeDevice = state.devicesConfiguration?.[deviceId]?.apiConfig + state.activeDevice = state.devices?.[deviceId]?.apiConfig ? deviceId : undefined state.pendingDevice = deviceId }) builder.addCase(detachDevice, (state, action) => { const { deviceId } = action.payload - if (state.devicesConfiguration[deviceId]?.apiConfig) { - delete state.devicesConfiguration[deviceId] + if (state.devices[deviceId]?.apiConfig) { + delete state.devices[deviceId] } if (state.activeDevice === deviceId) { state.activeDevice = undefined @@ -203,11 +180,11 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { builder.addCase(getGenericConfig.fulfilled, (state, action) => { const { deviceId, feature, view } = action.payload if (deviceId) { - state.devicesConfiguration[deviceId].features = { - ...state.devicesConfiguration[deviceId].features, + state.devices[deviceId].features = { + ...state.devices[deviceId].features, [feature]: { config: view, - data: state.devicesConfiguration[deviceId].features?.[feature]?.data, + data: state.devices[deviceId].features?.[feature]?.data, }, } } From 38827c40f612d5be7a7ad27d765bd30024c92748 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 14 Jun 2024 08:11:08 +0200 Subject: [PATCH 008/100] [CP-2898] Split listeners relative to manage core device to separate effects in lib --- libs/core-device/feature/src/hooks/index.ts | 6 ++ .../use-core-device-protocol-listeners.ts | 79 +++++++++++++++++++ libs/core-device/feature/src/index.ts | 1 + .../apps/base-app/base-app.component.tsx | 2 + .../hooks/use-device-connect-failed-effect.ts | 36 +++------ .../core/hooks/use-device-connected-effect.ts | 15 +--- .../core/hooks/use-device-detached-effect.ts | 7 +- .../device-select-drawer.component.tsx | 1 - .../available-device-list.component.tsx | 1 - 9 files changed, 102 insertions(+), 46 deletions(-) create mode 100644 libs/core-device/feature/src/hooks/index.ts create mode 100644 libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts diff --git a/libs/core-device/feature/src/hooks/index.ts b/libs/core-device/feature/src/hooks/index.ts new file mode 100644 index 0000000000..e975497e8b --- /dev/null +++ b/libs/core-device/feature/src/hooks/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./use-core-device-protocol-listeners" diff --git a/libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts b/libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts new file mode 100644 index 0000000000..7988783d2c --- /dev/null +++ b/libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts @@ -0,0 +1,79 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { useCallback, useEffect } from "react" +import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" +import { useDispatch } from "react-redux" +import { answerMain, useDebouncedEventsHandler } from "shared/utils" +import { DeviceBaseProperties } from "device-protocol/models" +import { DeviceState } from "core-device/models" +import { Dispatch } from "Core/__deprecated__/renderer/store" +import { addDevice, configureDevice, removeDevice } from "../actions" +import { getDeviceConfigurationRequest } from "../requests" + +export const useCoreDeviceProtocolListeners = () => { + const dispatch = useDispatch() + const handleDevicesDetached = useHandleDevicesDetached() + const batchDeviceDetachedEvents = + useDebouncedEventsHandler(handleDevicesDetached) + + useEffect(() => { + return answerMain( + DeviceProtocolMainEvent.DeviceConnected, + (properties) => { + const { deviceType } = properties + if (deviceType === DeviceType.APIDevice) { + return + } + + dispatch(addDevice(properties)) + dispatch(configureDevice(properties.id)) + } + ) + }, [dispatch]) + + useEffect(() => { + return answerMain( + DeviceProtocolMainEvent.DeviceConnectFailed, + async (properties) => { + const { deviceType } = properties + if (deviceType === DeviceType.APIDevice) { + return + } + + const result = await getDeviceConfigurationRequest(properties.id) + const caseColour = result.ok ? result.data.caseColour : undefined + + dispatch( + addDevice({ ...properties, caseColour, state: DeviceState.Failed }) + ) + } + ) + }, [dispatch]) + + useEffect(() => { + return answerMain( + DeviceProtocolMainEvent.DeviceDetached, + batchDeviceDetachedEvents + ) + }, [dispatch, batchDeviceDetachedEvents]) +} + +const useHandleDevicesDetached = () => { + const dispatch = useDispatch() + + return useCallback( + async (deviceDetachedEvents: DeviceBaseProperties[]) => { + for (const event of deviceDetachedEvents) { + const { deviceType } = event + if (deviceType === DeviceType.APIDevice) { + return + } + dispatch(removeDevice(event)) + } + }, + [dispatch] + ) +} diff --git a/libs/core-device/feature/src/index.ts b/libs/core-device/feature/src/index.ts index ef3ecbcae5..80b5e6ceb5 100644 --- a/libs/core-device/feature/src/index.ts +++ b/libs/core-device/feature/src/index.ts @@ -4,6 +4,7 @@ */ export * from "./actions" +export * from "./hooks" export * from "./reducers" export * from "./requests" export * from "./selectors" diff --git a/libs/core/core/components/apps/base-app/base-app.component.tsx b/libs/core/core/components/apps/base-app/base-app.component.tsx index fab405da17..31e21f192f 100644 --- a/libs/core/core/components/apps/base-app/base-app.component.tsx +++ b/libs/core/core/components/apps/base-app/base-app.component.tsx @@ -24,6 +24,7 @@ import { useAppEventsListeners, } from "generic-view/store" import { useOnlineListener } from "shared/app-state" +import { useCoreDeviceProtocolListeners } from "core-device/feature" const BaseApp: FunctionComponent = () => { useRouterListener() @@ -36,6 +37,7 @@ const BaseApp: FunctionComponent = () => { useWatchOutboxEntriesEffect() useWatchUnlockStatus() useDiscoveryRedirectEffect() + useCoreDeviceProtocolListeners() // API useAPISerialPortListeners() useAppEventsListeners() diff --git a/libs/core/core/hooks/use-device-connect-failed-effect.ts b/libs/core/core/hooks/use-device-connect-failed-effect.ts index 049a83ca95..8257b4ddf8 100644 --- a/libs/core/core/hooks/use-device-connect-failed-effect.ts +++ b/libs/core/core/hooks/use-device-connect-failed-effect.ts @@ -7,12 +7,8 @@ import { useEffect, useCallback } from "react" import { useHistory } from "react-router-dom" import { useDispatch, useSelector } from "react-redux" import { answerMain } from "shared/utils" -import { - DeviceProtocolMainEvent, - DeviceBaseProperties, -} from "device-protocol/models" -import { DeviceState } from "core-device/models" -import { addDevice, getDeviceConfigurationRequest } from "core-device/feature" +import { DeviceProtocolMainEvent } from "device-protocol/models" +import { DeviceBaseProperties } from "device-protocol/models" import { activeDeviceIdSelector } from "device-manager/feature" import { Dispatch } from "Core/__deprecated__/renderer/store" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" @@ -46,27 +42,17 @@ export const useDeviceConnectFailedEffect = () => { activeDeviceProcessing, ]) - const handleDeviceConnectFailed = useCallback( - async (properties: DeviceBaseProperties) => { - const result = await getDeviceConfigurationRequest(properties.id) - const caseColour = result.ok ? result.data.caseColour : undefined + const handleDeviceConnectFailed = useCallback(async () => { + if (activeDeviceId) { + return + } - dispatch( - addDevice({ ...properties, caseColour, state: DeviceState.Failed }) - ) + if (shouldSkipProcessing()) { + return + } - if (activeDeviceId) { - return - } - - if (shouldSkipProcessing()) { - return - } - - history.push(URL_DISCOVERY_DEVICE.root) - }, - [dispatch, activeDeviceId, shouldSkipProcessing, history] - ) + history.push(URL_DISCOVERY_DEVICE.root) + }, [activeDeviceId, shouldSkipProcessing, history]) useEffect(() => { return answerMain( diff --git a/libs/core/core/hooks/use-device-connected-effect.ts b/libs/core/core/hooks/use-device-connected-effect.ts index 88651cbfe0..63aa93f6ae 100644 --- a/libs/core/core/hooks/use-device-connected-effect.ts +++ b/libs/core/core/hooks/use-device-connected-effect.ts @@ -12,16 +12,8 @@ import { setActiveDevice, getDevicesSelector, } from "device-manager/feature" -import { - addDevice, - configureDevice, - getDeviceConfigurationRequest, -} from "core-device/feature" -import { - DeviceProtocolMainEvent, - DeviceType, - DeviceBaseProperties, -} from "device-protocol/models" +import { getDeviceConfigurationRequest } from "core-device/feature" +import { DeviceProtocolMainEvent, DeviceType, DeviceBaseProperties } from "device-protocol/models" import { selectDialogOpenState } from "shared/app-state" import { Dispatch } from "Core/__deprecated__/renderer/store" import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" @@ -50,9 +42,6 @@ export const useDeviceConnectedEffect = () => { useEffect(() => { const handler = async (properties: DeviceBaseProperties) => { - dispatch(addDevice(properties)) - dispatch(configureDevice(properties.id)) - if (activeDeviceId) { await continueProcess(properties) return diff --git a/libs/core/core/hooks/use-device-detached-effect.ts b/libs/core/core/hooks/use-device-detached-effect.ts index 96a0bbf1b6..a6ab192ebf 100644 --- a/libs/core/core/hooks/use-device-detached-effect.ts +++ b/libs/core/core/hooks/use-device-detached-effect.ts @@ -8,7 +8,6 @@ import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" import { answerMain, useDebouncedEventsHandler } from "shared/utils" import { DeviceBaseProperties } from "device-protocol/models" -import { removeDevice } from "core-device/feature" import { getDevicesSelector } from "device-manager/feature" import { selectDialogOpenState } from "shared/app-state" import { DeviceProtocolMainEvent } from "device-protocol/models" @@ -48,14 +47,10 @@ const useHandleDevicesDetached = () => { return useCallback( async (deviceDetachedEvents: DeviceBaseProperties[]) => { - for (const event of deviceDetachedEvents) { - dispatch(removeDevice(event)) - } - await processActiveDevicesDetachment(deviceDetachedEvents) processSingleDeviceRemaining(deviceDetachedEvents) }, - [dispatch, processActiveDevicesDetachment, processSingleDeviceRemaining] + [processActiveDevicesDetachment, processSingleDeviceRemaining] ) } diff --git a/libs/core/device-select/components/device-select-drawer.component.tsx b/libs/core/device-select/components/device-select-drawer.component.tsx index a4e0a30057..cf611e8a3d 100644 --- a/libs/core/device-select/components/device-select-drawer.component.tsx +++ b/libs/core/device-select/components/device-select-drawer.component.tsx @@ -29,7 +29,6 @@ import { activeDeviceIdSelector, handleDeviceActivated, } from "device-manager/feature" -import { DeviceState } from "core-device/models" import { URL_DEVICE_INITIALIZATION, URL_ONBOARDING, diff --git a/libs/core/discovery-device/components/available-device-list.component.tsx b/libs/core/discovery-device/components/available-device-list.component.tsx index f52207bccc..2bdd183b07 100644 --- a/libs/core/discovery-device/components/available-device-list.component.tsx +++ b/libs/core/discovery-device/components/available-device-list.component.tsx @@ -9,7 +9,6 @@ import styled from "styled-components" import { useHistory } from "react-router-dom" import { useDispatch, useSelector } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" -import { DeviceState } from "core-device/models" import Text, { TextDisplayStyle, } from "Core/__deprecated__/renderer/components/core/text/text.component" From b89044d53f0bd5ef0fb34b3ef64ccba3fc2699e0 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 14 Jun 2024 08:13:11 +0200 Subject: [PATCH 009/100] [CP-2898] Add modifiers reducer to manage api devices --- .../store/src/lib/action-names.ts | 3 +- .../hooks/use-api-serial-port-listeners.ts | 61 ++++++++++++------- .../store/src/lib/views/actions.ts | 14 +++-- .../store/src/lib/views/reducer.ts | 27 ++++---- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/libs/generic-view/store/src/lib/action-names.ts b/libs/generic-view/store/src/lib/action-names.ts index e57ffa6d9e..84a260b913 100644 --- a/libs/generic-view/store/src/lib/action-names.ts +++ b/libs/generic-view/store/src/lib/action-names.ts @@ -11,8 +11,9 @@ export enum ActionName { SetMenu = "generic-views/set-menu", SetViewLayout = "generic-views/set-view-layout", SetViewData = "generic-views/set-view-data", + AddDevice = "generic-views/add-device", + RemoveDevice = "generic-views/remove-device", ActivateDevice = "generic-views/activate-device", - DetachDevice = "generic-views/detach-device", OpenModal = "generic-modals/open-modal", CloseModal = "generic-modals/close-modal", CloseAllModals = "generic-modals/close-all-modals", diff --git a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts index 6804640e0a..d3e14f0927 100644 --- a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts +++ b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts @@ -3,14 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { useEffect } from "react" -import { Device } from "core-device/models" -import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" +import { useCallback, useEffect } from "react" import { useDispatch, useSelector } from "react-redux" -import { answerMain } from "shared/utils" -import { detachDevice } from "../views/actions" -import { getAPIConfig } from "../get-api-config" +import { answerMain, useDebouncedEventsHandler } from "shared/utils" +import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" +import { DeviceState } from "generic-view/models" +import { DeviceBaseProperties } from "device-protocol/models" import { Dispatch } from "Core/__deprecated__/renderer/store" +import { addDevice, removeDevice } from "../views/actions" +import { getAPIConfig } from "../get-api-config" import { setBackupProcessStatus } from "../backup/actions" import { closeAllModals } from "../modals/actions" import { selectBackupProcessStatus } from "../selectors" @@ -18,50 +19,66 @@ import { clearDataMigrationDevice } from "../data-migration/clear-data-migration export const useAPISerialPortListeners = () => { const dispatch = useDispatch() - const backupProcess = useSelector(selectBackupProcessStatus) + const handleDevicesDetached = useHandleDevicesDetached() + + const batchDeviceDetachedEvents = + useDebouncedEventsHandler(handleDevicesDetached) useEffect(() => { - const unregisterFailListener = answerMain( + const unregisterFailListener = answerMain( DeviceProtocolMainEvent.DeviceConnectFailed, (properties) => { const { deviceType } = properties if (deviceType !== DeviceType.APIDevice) { return } - // todo: connection error handling - console.log(properties) + dispatch(addDevice({ ...properties, state: DeviceState.Failed })) } ) - const unregisterConnectListener = answerMain( + const unregisterConnectListener = answerMain( DeviceProtocolMainEvent.DeviceConnected, (properties) => { const { id, deviceType } = properties if (deviceType !== DeviceType.APIDevice) { return } + dispatch(addDevice(properties)) dispatch(getAPIConfig({ deviceId: id })) } ) - const unregisterDetachedListener = answerMain( + const unregisterDetachedListener = answerMain( DeviceProtocolMainEvent.DeviceDetached, - async (properties) => { - const { id, deviceType } = properties + batchDeviceDetachedEvents + ) + + return () => { + unregisterDetachedListener() + unregisterConnectListener() + unregisterFailListener() + } + }, [dispatch, batchDeviceDetachedEvents]) +} + +const useHandleDevicesDetached = () => { + const dispatch = useDispatch() + const backupProcess = useSelector(selectBackupProcessStatus) + + return useCallback( + async (deviceDetachedEvents: DeviceBaseProperties[]) => { + for (const event of deviceDetachedEvents) { + const { deviceType, id } = event dispatch(clearDataMigrationDevice(id)) if (deviceType !== DeviceType.APIDevice) { return } - dispatch(detachDevice({ deviceId: id })) + dispatch(removeDevice(event)) dispatch(closeAllModals()) if (backupProcess) { dispatch(setBackupProcessStatus("FAILED")) } } - ) - return () => { - unregisterDetachedListener() - unregisterConnectListener() - unregisterFailListener() - } - }, [backupProcess, dispatch]) + }, + [dispatch, backupProcess] + ) } diff --git a/libs/generic-view/store/src/lib/views/actions.ts b/libs/generic-view/store/src/lib/views/actions.ts index 7f7af36dd9..b18b1a0396 100644 --- a/libs/generic-view/store/src/lib/views/actions.ts +++ b/libs/generic-view/store/src/lib/views/actions.ts @@ -7,8 +7,18 @@ import { createAction } from "@reduxjs/toolkit" import { DeviceId } from "Core/device/constants/device-id" import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-elements" import { View } from "generic-view/utils" +import { DeviceBaseProperties } from "device-protocol/models" +import { DeviceState } from "generic-view/models" import { ActionName } from "../action-names" +export const addDevice = createAction< + DeviceBaseProperties & Partial<{ state: DeviceState.Failed }> +>(ActionName.AddDevice) + +export const removeDevice = createAction( + ActionName.RemoveDevice +) + export const setMenu = createAction(ActionName.SetMenu) export const setViewLayout = createAction<{ feature: string @@ -23,7 +33,3 @@ export const setViewData = createAction<{ export const activateDevice = createAction<{ deviceId: DeviceId }>(ActionName.ActivateDevice) - -export const detachDevice = createAction<{ - deviceId: DeviceId -}>(ActionName.DetachDevice) diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index 908911ae54..97a9de126a 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -19,7 +19,8 @@ import { getOutboxData } from "../outbox/get-outbox-data.action" import { getGenericConfig } from "../features/get-generic-config.actions" import { activateDevice, - detachDevice, + addDevice, + removeDevice, setMenu, setViewData, setViewLayout, @@ -37,7 +38,6 @@ export interface GenericState { lastResponse: unknown lastRefresh?: number activeDevice?: DeviceId - pendingDevice?: DeviceId devices: Record apiErrors: Record } @@ -68,6 +68,12 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { data: action.payload.data, } }) + builder.addCase(addDevice, (state, action) => { + state.devices[action.payload.id] = { + ...action.payload, + state: DeviceState.Connected, + } + }) builder.addCase(getAPIConfig.fulfilled, (state, action) => { const device = state.devices[action.payload.deviceId] @@ -137,9 +143,8 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { : {}), } as Features } - if (state.activeDevice === undefined && state.pendingDevice === deviceId) { + if (state.activeDevice === undefined) { state.activeDevice = deviceId - state.pendingDevice = undefined } }) builder.addCase(activateDevice, (state, action) => { @@ -147,19 +152,9 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { state.activeDevice = state.devices?.[deviceId]?.apiConfig ? deviceId : undefined - state.pendingDevice = deviceId }) - builder.addCase(detachDevice, (state, action) => { - const { deviceId } = action.payload - if (state.devices[deviceId]?.apiConfig) { - delete state.devices[deviceId] - } - if (state.activeDevice === deviceId) { - state.activeDevice = undefined - } - if (state.pendingDevice === deviceId) { - state.pendingDevice = undefined - } + builder.addCase(removeDevice, (state, action) => { + delete state.devices[action.payload.id] }) builder.addCase(getOutboxData.fulfilled, (state, action) => { const { deviceId, timestamp } = action.payload From 677f266d214c3cdf6fc5be5918ab4cb96e32a5b7 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 14 Jun 2024 08:14:08 +0200 Subject: [PATCH 010/100] [CP-2898] Handle error case when getAPIConfig request rejected --- libs/generic-view/store/src/lib/views/reducer.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index 97a9de126a..1d2a6c4ca9 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -84,6 +84,17 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { } state.lastResponse = action.payload }) + builder.addCase(getAPIConfig.rejected, (state, action) => { + const id = action.meta.arg.deviceId + const device = state.devices[id] + + state.devices[id] = { + ...device, + state: DeviceState.Failed, + } + + state.lastResponse = action.payload + }) builder.addCase(getMenuConfig.fulfilled, (state, action) => { state.devices[action.payload.deviceId].menuConfig = action.payload.menuConfig From 6210b374da6c356516a05a35c1037ebdc3bd54ad Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 12:06:11 +0200 Subject: [PATCH 011/100] [CP-2898] Split Device Manager into Multiple Modules (#1927) --- libs/core/core/hooks/use-device-connected-effect.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/core/core/hooks/use-device-connected-effect.ts b/libs/core/core/hooks/use-device-connected-effect.ts index 63aa93f6ae..46de855ad3 100644 --- a/libs/core/core/hooks/use-device-connected-effect.ts +++ b/libs/core/core/hooks/use-device-connected-effect.ts @@ -13,7 +13,11 @@ import { getDevicesSelector, } from "device-manager/feature" import { getDeviceConfigurationRequest } from "core-device/feature" -import { DeviceProtocolMainEvent, DeviceType, DeviceBaseProperties } from "device-protocol/models" +import { + DeviceProtocolMainEvent, + DeviceType, + DeviceBaseProperties, +} from "device-protocol/models" import { selectDialogOpenState } from "shared/app-state" import { Dispatch } from "Core/__deprecated__/renderer/store" import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" From 22f10e5facb875cc3f15a6e5f64ead3c3259d3dc Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 14 Jun 2024 09:52:09 +0200 Subject: [PATCH 012/100] [CP-2898] active-device-registry generated --- libs/active-device-registry/feature/.babelrc | 20 ++++++++++++++++ .../feature/.eslintrc.json | 18 ++++++++++++++ libs/active-device-registry/feature/README.md | 7 ++++++ .../feature/jest.config.ts | 11 +++++++++ .../feature/project.json | 20 ++++++++++++++++ .../feature/src/index.ts | 6 +++++ .../feature/tsconfig.json | 20 ++++++++++++++++ .../feature/tsconfig.lib.json | 24 +++++++++++++++++++ .../feature/tsconfig.spec.json | 20 ++++++++++++++++ libs/active-device-registry/models/.babelrc | 20 ++++++++++++++++ .../models/.eslintrc.json | 18 ++++++++++++++ libs/active-device-registry/models/README.md | 7 ++++++ .../models/jest.config.ts | 11 +++++++++ .../models/project.json | 20 ++++++++++++++++ .../models/src/index.ts | 6 +++++ .../models/tsconfig.json | 20 ++++++++++++++++ .../models/tsconfig.lib.json | 24 +++++++++++++++++++ .../models/tsconfig.spec.json | 20 ++++++++++++++++ tsconfig.base.json | 6 +++++ 19 files changed, 298 insertions(+) create mode 100644 libs/active-device-registry/feature/.babelrc create mode 100644 libs/active-device-registry/feature/.eslintrc.json create mode 100644 libs/active-device-registry/feature/README.md create mode 100644 libs/active-device-registry/feature/jest.config.ts create mode 100644 libs/active-device-registry/feature/project.json create mode 100644 libs/active-device-registry/feature/src/index.ts create mode 100644 libs/active-device-registry/feature/tsconfig.json create mode 100644 libs/active-device-registry/feature/tsconfig.lib.json create mode 100644 libs/active-device-registry/feature/tsconfig.spec.json create mode 100644 libs/active-device-registry/models/.babelrc create mode 100644 libs/active-device-registry/models/.eslintrc.json create mode 100644 libs/active-device-registry/models/README.md create mode 100644 libs/active-device-registry/models/jest.config.ts create mode 100644 libs/active-device-registry/models/project.json create mode 100644 libs/active-device-registry/models/src/index.ts create mode 100644 libs/active-device-registry/models/tsconfig.json create mode 100644 libs/active-device-registry/models/tsconfig.lib.json create mode 100644 libs/active-device-registry/models/tsconfig.spec.json diff --git a/libs/active-device-registry/feature/.babelrc b/libs/active-device-registry/feature/.babelrc new file mode 100644 index 0000000000..ef4889c1ab --- /dev/null +++ b/libs/active-device-registry/feature/.babelrc @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [ + [ + "styled-components", + { + "pure": true, + "ssr": true + } + ] + ] +} diff --git a/libs/active-device-registry/feature/.eslintrc.json b/libs/active-device-registry/feature/.eslintrc.json new file mode 100644 index 0000000000..cacbe26215 --- /dev/null +++ b/libs/active-device-registry/feature/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/active-device-registry/feature/README.md b/libs/active-device-registry/feature/README.md new file mode 100644 index 0000000000..fa965afb1c --- /dev/null +++ b/libs/active-device-registry/feature/README.md @@ -0,0 +1,7 @@ +# active-device-registry-feature + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test active-device-registry-feature` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/active-device-registry/feature/jest.config.ts b/libs/active-device-registry/feature/jest.config.ts new file mode 100644 index 0000000000..8f857c9e58 --- /dev/null +++ b/libs/active-device-registry/feature/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "active-device-registry-feature", + preset: "../../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../../coverage/libs/active-device-registry/feature", +} diff --git a/libs/active-device-registry/feature/project.json b/libs/active-device-registry/feature/project.json new file mode 100644 index 0000000000..0141ee0b5d --- /dev/null +++ b/libs/active-device-registry/feature/project.json @@ -0,0 +1,20 @@ +{ + "name": "active-device-registry-feature", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/active-device-registry/feature/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/active-device-registry/feature/jest.config.ts" + } + } + } +} diff --git a/libs/active-device-registry/feature/src/index.ts b/libs/active-device-registry/feature/src/index.ts new file mode 100644 index 0000000000..083cb1b3ef --- /dev/null +++ b/libs/active-device-registry/feature/src/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./lib/active-device-registry-feature" diff --git a/libs/active-device-registry/feature/tsconfig.json b/libs/active-device-registry/feature/tsconfig.json new file mode 100644 index 0000000000..4daaf45cd3 --- /dev/null +++ b/libs/active-device-registry/feature/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../../tsconfig.base.json" +} diff --git a/libs/active-device-registry/feature/tsconfig.lib.json b/libs/active-device-registry/feature/tsconfig.lib.json new file mode 100644 index 0000000000..21799b3e6b --- /dev/null +++ b/libs/active-device-registry/feature/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/active-device-registry/feature/tsconfig.spec.json b/libs/active-device-registry/feature/tsconfig.spec.json new file mode 100644 index 0000000000..25b7af8f6d --- /dev/null +++ b/libs/active-device-registry/feature/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/libs/active-device-registry/models/.babelrc b/libs/active-device-registry/models/.babelrc new file mode 100644 index 0000000000..ef4889c1ab --- /dev/null +++ b/libs/active-device-registry/models/.babelrc @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [ + [ + "styled-components", + { + "pure": true, + "ssr": true + } + ] + ] +} diff --git a/libs/active-device-registry/models/.eslintrc.json b/libs/active-device-registry/models/.eslintrc.json new file mode 100644 index 0000000000..cacbe26215 --- /dev/null +++ b/libs/active-device-registry/models/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../../.eslintrc.js"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/active-device-registry/models/README.md b/libs/active-device-registry/models/README.md new file mode 100644 index 0000000000..e491313413 --- /dev/null +++ b/libs/active-device-registry/models/README.md @@ -0,0 +1,7 @@ +# active-device-registry-models + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test active-device-registry-models` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/active-device-registry/models/jest.config.ts b/libs/active-device-registry/models/jest.config.ts new file mode 100644 index 0000000000..bd4c266fcf --- /dev/null +++ b/libs/active-device-registry/models/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: "active-device-registry-models", + preset: "../../../jest.preset.js", + transform: { + "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", + "^.+\\.[tj]sx?$": ["babel-jest", { presets: ["@nx/react/babel"] }], + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx"], + coverageDirectory: "../../../coverage/libs/active-device-registry/models", +} diff --git a/libs/active-device-registry/models/project.json b/libs/active-device-registry/models/project.json new file mode 100644 index 0000000000..c9ebedf2b2 --- /dev/null +++ b/libs/active-device-registry/models/project.json @@ -0,0 +1,20 @@ +{ + "name": "active-device-registry-models", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/active-device-registry/models/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/active-device-registry/models/jest.config.ts" + } + } + } +} diff --git a/libs/active-device-registry/models/src/index.ts b/libs/active-device-registry/models/src/index.ts new file mode 100644 index 0000000000..1189d43f72 --- /dev/null +++ b/libs/active-device-registry/models/src/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./lib/active-device-registry-models" diff --git a/libs/active-device-registry/models/tsconfig.json b/libs/active-device-registry/models/tsconfig.json new file mode 100644 index 0000000000..4daaf45cd3 --- /dev/null +++ b/libs/active-device-registry/models/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": false, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../../tsconfig.base.json" +} diff --git a/libs/active-device-registry/models/tsconfig.lib.json b/libs/active-device-registry/models/tsconfig.lib.json new file mode 100644 index 0000000000..21799b3e6b --- /dev/null +++ b/libs/active-device-registry/models/tsconfig.lib.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": [ + "node", + + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "jest.config.ts", + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/**/*.spec.tsx", + "src/**/*.test.tsx", + "src/**/*.spec.js", + "src/**/*.test.js", + "src/**/*.spec.jsx", + "src/**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/active-device-registry/models/tsconfig.spec.json b/libs/active-device-registry/models/tsconfig.spec.json new file mode 100644 index 0000000000..25b7af8f6d --- /dev/null +++ b/libs/active-device-registry/models/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 958953fb0a..08cfa6bfc4 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -28,6 +28,12 @@ "E2E/*": ["./apps/mudita-center-e2e/src/*"], "Libs/*": ["./libs/*"], "Root/*": ["./*"], + "active-device-registry/feature": [ + "libs/active-device-registry/feature/src/index.ts" + ], + "active-device-registry/models": [ + "libs/active-device-registry/models/src/index.ts" + ], "core-device/feature": ["libs/core-device/feature/src/index.ts"], "core-device/models": ["libs/core-device/models/src/index.ts"], "device-manager/feature": ["libs/device-manager/feature/src/index.ts"], From 773b58a1ea5a6ab32acb2ef7d098c2f770d1be3a Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 14 Jun 2024 10:36:00 +0200 Subject: [PATCH 013/100] [CP-2898] split active-device-registry from device-manager --- .../feature/src/actions/index.ts | 6 ++++ .../src/actions/set-active-device.action.ts | 8 ++--- .../src/active-device-registry.module.ts | 19 +++++++++++ .../src/constants/controller.constant.ts | 8 +++++ .../feature/src/constants/event.constant.ts | 8 +++++ .../feature/src/constants/index.ts | 7 ++++ .../active-device-registry.controller.ts | 19 +++++++++++ .../feature/src/controllers/index.ts | 6 ++++ .../feature/src/index.ts | 5 ++- .../active-device-registry.reducer.ts | 24 ++++++++++++++ .../feature/src/reducers/index.ts | 6 ++++ .../feature/src/requests/index.ts | 6 ++++ .../src/requests/set-active-device.request.ts | 4 +-- .../selectors/active-device-id.selector.ts | 8 ++--- .../active-device-registry-state.selector.ts | 10 ++++++ .../feature/src/selectors/index.ts | 8 +++++ .../is-active-device-set.selector.ts | 8 ++--- .../src/active-device-registry.interface.ts | 10 ++++++ .../models/src/index.ts | 2 +- .../components/rest/menu/menu.test.tsx | 11 +++++-- .../__deprecated__/renderer/store/reducers.ts | 2 ++ .../actions/delete-contacts.action.test.ts | 6 ++-- .../actions/import-contact.action.test.ts | 6 ++-- libs/core/core/application.module.ts | 4 +++ .../check-for-update.action.test.ts | 10 +++--- .../download-updates.action.test.ts | 32 +++++++++++++------ .../start-update-os.action.test.ts | 19 +++++++---- .../src/actions/deactivate-device.action.ts | 4 +-- .../actions/handle-device-activated.action.ts | 6 ++-- .../feature/src/actions/index.ts | 2 +- .../src/constants/controller.constant.ts | 1 - .../controllers/device-manager.controller.ts | 5 --- .../src/reducers/device-manager.reducer.ts | 15 --------- .../feature/src/requests/index.ts | 1 - .../get-active-device-base-data.selector.ts | 7 ++-- .../selectors/get-active-device.selector.ts | 7 ++-- .../feature/src/selectors/index.ts | 4 +-- .../models/src/device-manager.interface.ts | 3 -- .../models/src/event.constant.ts | 1 - 39 files changed, 230 insertions(+), 88 deletions(-) create mode 100644 libs/active-device-registry/feature/src/actions/index.ts rename libs/{device-manager => active-device-registry}/feature/src/actions/set-active-device.action.ts (67%) create mode 100644 libs/active-device-registry/feature/src/active-device-registry.module.ts create mode 100644 libs/active-device-registry/feature/src/constants/controller.constant.ts create mode 100644 libs/active-device-registry/feature/src/constants/event.constant.ts create mode 100644 libs/active-device-registry/feature/src/constants/index.ts create mode 100644 libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts create mode 100644 libs/active-device-registry/feature/src/controllers/index.ts create mode 100644 libs/active-device-registry/feature/src/reducers/active-device-registry.reducer.ts create mode 100644 libs/active-device-registry/feature/src/reducers/index.ts create mode 100644 libs/active-device-registry/feature/src/requests/index.ts rename libs/{device-manager => active-device-registry}/feature/src/requests/set-active-device.request.ts (75%) rename libs/{device-manager => active-device-registry}/feature/src/selectors/active-device-id.selector.ts (54%) create mode 100644 libs/active-device-registry/feature/src/selectors/active-device-registry-state.selector.ts create mode 100644 libs/active-device-registry/feature/src/selectors/index.ts rename libs/{device-manager => active-device-registry}/feature/src/selectors/is-active-device-set.selector.ts (60%) create mode 100644 libs/active-device-registry/models/src/active-device-registry.interface.ts diff --git a/libs/active-device-registry/feature/src/actions/index.ts b/libs/active-device-registry/feature/src/actions/index.ts new file mode 100644 index 0000000000..676125a458 --- /dev/null +++ b/libs/active-device-registry/feature/src/actions/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./set-active-device.action"; diff --git a/libs/device-manager/feature/src/actions/set-active-device.action.ts b/libs/active-device-registry/feature/src/actions/set-active-device.action.ts similarity index 67% rename from libs/device-manager/feature/src/actions/set-active-device.action.ts rename to libs/active-device-registry/feature/src/actions/set-active-device.action.ts index 7bf5c77648..1a171104fe 100644 --- a/libs/device-manager/feature/src/actions/set-active-device.action.ts +++ b/libs/active-device-registry/feature/src/actions/set-active-device.action.ts @@ -4,19 +4,17 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { cleanBackupProcess, cleanRestoreProcess } from "generic-view/store" -import { DeviceManagerEvent } from "device-manager/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { DeviceId } from "Core/device/constants/device-id" import { setActiveDeviceRequest } from "../requests" +import { ActiveDeviceRegistryEvent } from "../constants" + export const setActiveDevice = createAsyncThunk< DeviceId | undefined, DeviceId | undefined, { state: ReduxRootState } ->(DeviceManagerEvent.SetActiveDevice, async (payload, { dispatch }) => { +>(ActiveDeviceRegistryEvent.SetActiveDevice, async (payload, { dispatch }) => { await setActiveDeviceRequest(payload) - dispatch(cleanBackupProcess()) - dispatch(cleanRestoreProcess()) return payload }) diff --git a/libs/active-device-registry/feature/src/active-device-registry.module.ts b/libs/active-device-registry/feature/src/active-device-registry.module.ts new file mode 100644 index 0000000000..a43f19f5b7 --- /dev/null +++ b/libs/active-device-registry/feature/src/active-device-registry.module.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { DeviceProtocolService } from "device-protocol/feature" +import { ActiveDeviceRegistryController } from "./controllers" + +export class ActiveDeviceRegistryModule { + public controllers + + constructor(public deviceProtocolService: DeviceProtocolService) { + const activeDeviceRegistryController = new ActiveDeviceRegistryController( + this.deviceProtocolService + ) + + this.controllers = [activeDeviceRegistryController] + } +} diff --git a/libs/active-device-registry/feature/src/constants/controller.constant.ts b/libs/active-device-registry/feature/src/constants/controller.constant.ts new file mode 100644 index 0000000000..6914b07bb0 --- /dev/null +++ b/libs/active-device-registry/feature/src/constants/controller.constant.ts @@ -0,0 +1,8 @@ +/** + * 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 IpcActiveDeviceRegistryEvent { + SetActiveDevice = "active-device-registry/set-active-device", +} diff --git a/libs/active-device-registry/feature/src/constants/event.constant.ts b/libs/active-device-registry/feature/src/constants/event.constant.ts new file mode 100644 index 0000000000..5054edbcc1 --- /dev/null +++ b/libs/active-device-registry/feature/src/constants/event.constant.ts @@ -0,0 +1,8 @@ +/** + * 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 ActiveDeviceRegistryEvent { + SetActiveDevice = "active-device-registry/set-active-device", +} diff --git a/libs/active-device-registry/feature/src/constants/index.ts b/libs/active-device-registry/feature/src/constants/index.ts new file mode 100644 index 0000000000..5a48343da1 --- /dev/null +++ b/libs/active-device-registry/feature/src/constants/index.ts @@ -0,0 +1,7 @@ +/** + * 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 "./event.constant" diff --git a/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts b/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts new file mode 100644 index 0000000000..077a928cda --- /dev/null +++ b/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { IpcEvent } from "Core/core/decorators" +import { DeviceProtocolService } from "device-protocol/feature" +import { ResultObject } from "Core/core/builder" +import { DeviceId } from "Core/device/constants/device-id" +import { IpcActiveDeviceRegistryEvent } from "../constants" + +export class ActiveDeviceRegistryController { + constructor(private deviceProtocolService: DeviceProtocolService) {} + + @IpcEvent(IpcActiveDeviceRegistryEvent.SetActiveDevice) + public setActiveDevice(id: DeviceId | undefined): ResultObject { + return this.deviceProtocolService.setActiveDevice(id) + } +} diff --git a/libs/active-device-registry/feature/src/controllers/index.ts b/libs/active-device-registry/feature/src/controllers/index.ts new file mode 100644 index 0000000000..a428b87f03 --- /dev/null +++ b/libs/active-device-registry/feature/src/controllers/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./active-device-registry.controller" diff --git a/libs/active-device-registry/feature/src/index.ts b/libs/active-device-registry/feature/src/index.ts index 083cb1b3ef..83e18aeceb 100644 --- a/libs/active-device-registry/feature/src/index.ts +++ b/libs/active-device-registry/feature/src/index.ts @@ -3,4 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -// export * from "./lib/active-device-registry-feature" +export * from "./actions" +export * from "./reducers" +export * from "./selectors" +export * from "./active-device-registry.module" diff --git a/libs/active-device-registry/feature/src/reducers/active-device-registry.reducer.ts b/libs/active-device-registry/feature/src/reducers/active-device-registry.reducer.ts new file mode 100644 index 0000000000..83b4c0a07b --- /dev/null +++ b/libs/active-device-registry/feature/src/reducers/active-device-registry.reducer.ts @@ -0,0 +1,24 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createReducer } from "@reduxjs/toolkit" +import { ActiveDeviceRegistryState } from "active-device-registry/models" +import { setActiveDevice } from "../actions" + +export const initialState: ActiveDeviceRegistryState = { + activeDeviceId: undefined, +} + +export const activeDeviceRegistryReducer = createReducer( + initialState, + (builder) => { + builder.addCase(setActiveDevice.fulfilled, (state, action) => { + return { + ...state, + activeDeviceId: action.payload, + } + }) + } +) diff --git a/libs/active-device-registry/feature/src/reducers/index.ts b/libs/active-device-registry/feature/src/reducers/index.ts new file mode 100644 index 0000000000..73250716eb --- /dev/null +++ b/libs/active-device-registry/feature/src/reducers/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./active-device-registry.reducer" diff --git a/libs/active-device-registry/feature/src/requests/index.ts b/libs/active-device-registry/feature/src/requests/index.ts new file mode 100644 index 0000000000..7de1bf4d87 --- /dev/null +++ b/libs/active-device-registry/feature/src/requests/index.ts @@ -0,0 +1,6 @@ +/** + * 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 "./set-active-device.request" diff --git a/libs/device-manager/feature/src/requests/set-active-device.request.ts b/libs/active-device-registry/feature/src/requests/set-active-device.request.ts similarity index 75% rename from libs/device-manager/feature/src/requests/set-active-device.request.ts rename to libs/active-device-registry/feature/src/requests/set-active-device.request.ts index 30001e898b..0639919deb 100644 --- a/libs/device-manager/feature/src/requests/set-active-device.request.ts +++ b/libs/active-device-registry/feature/src/requests/set-active-device.request.ts @@ -6,10 +6,10 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" -import { IpcDeviceManagerEvent } from "../constants" +import { IpcActiveDeviceRegistryEvent } from "../constants" export const setActiveDeviceRequest = async ( id: DeviceId | undefined ): Promise> => { - return ipcRenderer.callMain(IpcDeviceManagerEvent.SetActiveDevice, id) + return ipcRenderer.callMain(IpcActiveDeviceRegistryEvent.SetActiveDevice, id) } diff --git a/libs/device-manager/feature/src/selectors/active-device-id.selector.ts b/libs/active-device-registry/feature/src/selectors/active-device-id.selector.ts similarity index 54% rename from libs/device-manager/feature/src/selectors/active-device-id.selector.ts rename to libs/active-device-registry/feature/src/selectors/active-device-id.selector.ts index 8fa81c1042..99d81b4108 100644 --- a/libs/device-manager/feature/src/selectors/active-device-id.selector.ts +++ b/libs/active-device-registry/feature/src/selectors/active-device-id.selector.ts @@ -4,11 +4,11 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "./device-manager-state.selector" +import { activeDeviceRegistryState } from "./active-device-registry-state.selector" export const activeDeviceIdSelector = createSelector( - deviceManagerState, - (deviceManager): string | undefined => { - return deviceManager.activeDeviceId + activeDeviceRegistryState, + (activeDeviceRegistryState): string | undefined => { + return activeDeviceRegistryState.activeDeviceId } ) diff --git a/libs/active-device-registry/feature/src/selectors/active-device-registry-state.selector.ts b/libs/active-device-registry/feature/src/selectors/active-device-registry-state.selector.ts new file mode 100644 index 0000000000..d4f89d7305 --- /dev/null +++ b/libs/active-device-registry/feature/src/selectors/active-device-registry-state.selector.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { ActiveDeviceRegistryState } from "active-device-registry/models" +import { ReduxRootState } from "Core/__deprecated__/renderer/store" + +export const activeDeviceRegistryState = (state: ReduxRootState): ActiveDeviceRegistryState => + state.activeDeviceRegistry diff --git a/libs/active-device-registry/feature/src/selectors/index.ts b/libs/active-device-registry/feature/src/selectors/index.ts new file mode 100644 index 0000000000..927e191c43 --- /dev/null +++ b/libs/active-device-registry/feature/src/selectors/index.ts @@ -0,0 +1,8 @@ +/** + * 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 "./active-device-id.selector"; +export * from "./active-device-registry-state.selector"; +export * from "./is-active-device-set.selector"; diff --git a/libs/device-manager/feature/src/selectors/is-active-device-set.selector.ts b/libs/active-device-registry/feature/src/selectors/is-active-device-set.selector.ts similarity index 60% rename from libs/device-manager/feature/src/selectors/is-active-device-set.selector.ts rename to libs/active-device-registry/feature/src/selectors/is-active-device-set.selector.ts index 65842e6fcb..325207ca8c 100644 --- a/libs/device-manager/feature/src/selectors/is-active-device-set.selector.ts +++ b/libs/active-device-registry/feature/src/selectors/is-active-device-set.selector.ts @@ -4,11 +4,11 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { deviceManagerState } from "./device-manager-state.selector" +import { activeDeviceIdSelector } from "./active-device-id.selector" export const isActiveDeviceSet = createSelector( - deviceManagerState, - (deviceManager): boolean => { - return deviceManager.activeDeviceId !== undefined + activeDeviceIdSelector, + (activeDeviceId): boolean => { + return activeDeviceId !== undefined } ) diff --git a/libs/active-device-registry/models/src/active-device-registry.interface.ts b/libs/active-device-registry/models/src/active-device-registry.interface.ts new file mode 100644 index 0000000000..c282c2e45e --- /dev/null +++ b/libs/active-device-registry/models/src/active-device-registry.interface.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { DeviceId } from "Core/device/constants/device-id" + +export interface ActiveDeviceRegistryState { + activeDeviceId: DeviceId | undefined +} diff --git a/libs/active-device-registry/models/src/index.ts b/libs/active-device-registry/models/src/index.ts index 1189d43f72..b761a81f81 100644 --- a/libs/active-device-registry/models/src/index.ts +++ b/libs/active-device-registry/models/src/index.ts @@ -3,4 +3,4 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -// export * from "./lib/active-device-registry-models" +export * from "./active-device-registry.interface" diff --git a/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx b/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx index 69d51e03ae..711ad0831f 100644 --- a/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx +++ b/libs/core/__deprecated__/renderer/components/rest/menu/menu.test.tsx @@ -26,6 +26,7 @@ import { DeviceInitializationState, DeviceInitializationStatus, } from "Core/device-initialization/reducers/device-initialization.interface" +import { ActiveDeviceRegistryState } from "active-device-registry/models" jest.mock("Core/settings/store/schemas/generate-application-id", () => ({ generateApplicationId: () => "123", @@ -40,6 +41,9 @@ const defaultState = { deviceType: DeviceType.MuditaPure, } as unknown as DeviceState, deviceManager: {} as unknown as DeviceManagerState, + activeDeviceRegistry: { + activeDeviceId: undefined, + } as unknown as ActiveDeviceRegistryState, coreDevice: { devices: [], } as unknown as CoreDeviceState, @@ -51,6 +55,7 @@ const defaultState = { }, genericViews: { menu: [], + devices: [], }, } as unknown as ReduxRootState @@ -139,9 +144,9 @@ describe("Device: Mudita pure", () => { }, ], } as unknown as CoreDeviceState, - deviceManager: { - activeDeviceId: "1", - } as unknown as DeviceManagerState, + activeDeviceRegistry: { + activeDeviceId: undefined, + } as unknown as ActiveDeviceRegistryState, }, { deviceFeaturesVisible: true, diff --git a/libs/core/__deprecated__/renderer/store/reducers.ts b/libs/core/__deprecated__/renderer/store/reducers.ts index 6c95435819..ca9d052800 100644 --- a/libs/core/__deprecated__/renderer/store/reducers.ts +++ b/libs/core/__deprecated__/renderer/store/reducers.ts @@ -34,6 +34,7 @@ import { externalProvidersReducer } from "generic-view/store" import { appStateReducer } from "shared/app-state" +import { activeDeviceRegistryReducer } from "active-device-registry/feature" export const reducers = { device: deviceReducer, @@ -55,6 +56,7 @@ export const reducers = { appInitialization: appInitializationReducer, coreDevice: coreDeviceReducer, deviceManager: deviceManagerReducer, + activeDeviceRegistry: activeDeviceRegistryReducer, genericViews: genericViewsReducer, genericModals: genericModalsReducer, genericBackups: genericBackupsReducer, diff --git a/libs/core/contacts/actions/delete-contacts.action.test.ts b/libs/core/contacts/actions/delete-contacts.action.test.ts index 44cc83121d..7d71bdb0b6 100644 --- a/libs/core/contacts/actions/delete-contacts.action.test.ts +++ b/libs/core/contacts/actions/delete-contacts.action.test.ts @@ -65,7 +65,7 @@ describe("async `deleteContacts` ", () => { ) const mockStore = createMockStore([thunk])({ contacts: initialState, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) @@ -99,7 +99,7 @@ describe("async `deleteContacts` ", () => { ) const mockStore = createMockStore([thunk])({ contacts: initialState, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) @@ -127,7 +127,7 @@ describe("async `deleteContacts` ", () => { ) const mockStore = createMockStore([thunk])({ contacts: initialState, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) diff --git a/libs/core/contacts/actions/import-contact.action.test.ts b/libs/core/contacts/actions/import-contact.action.test.ts index bb2bc830c7..4b12b3f36d 100644 --- a/libs/core/contacts/actions/import-contact.action.test.ts +++ b/libs/core/contacts/actions/import-contact.action.test.ts @@ -83,7 +83,7 @@ describe("async `importContact` ", () => { ) const mockStore = createMockStore([thunk])({ contacts: initialState, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: importContactArg.activeDeviceId, }, }) @@ -117,7 +117,7 @@ describe("async `importContact` ", () => { ) const mockStore = createMockStore([thunk])({ contacts: initialState, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: importContactArg.activeDeviceId, }, }) @@ -153,7 +153,7 @@ describe("async `importContact` ", () => { ) const mockStore = createMockStore([thunk])({ contacts: initialState, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: importContactArg.activeDeviceId, }, }) diff --git a/libs/core/core/application.module.ts b/libs/core/core/application.module.ts index 7ef07c69ad..8dfb5c4c93 100644 --- a/libs/core/core/application.module.ts +++ b/libs/core/core/application.module.ts @@ -52,6 +52,7 @@ import { MockDeviceResolverService, mockServiceEnabled } from "e2e-mock-server" import { ApplicationUpdaterModule } from "electron/application-updater" import { CoreDeviceModule } from "core-device/feature" import { DeviceManagerModule } from "device-manager/feature" +import { ActiveDeviceRegistryModule } from "active-device-registry/feature" import { createSettingsService } from "Core/settings/containers" export class ApplicationModule { @@ -138,6 +139,9 @@ export class ApplicationModule { this.controllerInitializer.initialize( new DeviceManagerModule(this.deviceProtocolService).controllers ) + this.controllerInitializer.initialize( + new ActiveDeviceRegistryModule(this.deviceProtocolService).controllers + ) } lateInitialization(): void { diff --git a/libs/core/update/actions/check-for-update/check-for-update.action.test.ts b/libs/core/update/actions/check-for-update/check-for-update.action.test.ts index 24a21c193a..537ed85f95 100644 --- a/libs/core/update/actions/check-for-update/check-for-update.action.test.ts +++ b/libs/core/update/actions/check-for-update/check-for-update.action.test.ts @@ -84,7 +84,7 @@ describe("when fetching all releases fails", () => { osVersion: "1.2.0", }, }, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) @@ -120,7 +120,7 @@ describe("when latest release os version is not greater than current os version" osVersion: "1.1.0", }, }, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) @@ -166,7 +166,7 @@ describe("when latest release os version is greater than current os version", () osVersion: "1.2.0", }, }, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) @@ -237,7 +237,7 @@ describe("when latest release contains information about mandatory releases", () osVersion: "1.2.0", }, }, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) @@ -288,7 +288,7 @@ describe("when fetching mandatory releases fails", () => { osVersion: "1.2.0", }, }, - deviceManager: { + activeDeviceRegistry: { activeDeviceId: "", }, }) diff --git a/libs/core/update/actions/download-updates/download-updates.action.test.ts b/libs/core/update/actions/download-updates/download-updates.action.test.ts index 5ed65e3951..9c0a6da9b6 100644 --- a/libs/core/update/actions/download-updates/download-updates.action.test.ts +++ b/libs/core/update/actions/download-updates/download-updates.action.test.ts @@ -4,6 +4,10 @@ */ import { AnyAction } from "@reduxjs/toolkit" +import createMockStore from "redux-mock-store" +import thunk from "redux-thunk" +import { CoreDeviceState } from "core-device/models" +import { ActiveDeviceRegistryState } from "active-device-registry/models" import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import { downloadUpdates } from "Core/update/actions/download-updates/download-updates.action" @@ -22,11 +26,7 @@ import { import { testError } from "Core/__deprecated__/renderer/store/constants" import * as downloadOsUpdateRequestModule from "Core/update/requests/download-os-update.request" import * as osUpdateAlreadyDownloadedCheckModule from "Core/update/requests/os-update-already-downloaded.request" -import createMockStore from "redux-mock-store" -import thunk from "redux-thunk" import { trackOsDownload } from "Core/analytic-data-tracker/helpers/track-os-download" -import { CoreDeviceState } from "core-device/models" -import { DeviceManagerState } from "device-manager/models" jest.mock("Core/analytic-data-tracker/helpers/track-os-download") @@ -68,9 +68,9 @@ const mockedCoreDeviceState = { devices: [{ id: "1" }], } as unknown as CoreDeviceState -const mockedDeviceManagerState = { +const mockedActiveDeviceRegistryState = { activeDeviceId: "1", -} as unknown as DeviceManagerState +} as unknown as ActiveDeviceRegistryState const params = { releases: [mockedRelease, mockedRelease2] } @@ -133,7 +133,10 @@ describe("when some of the updates have been downloaded before", () => { }, }, coreDevice: mockedCoreDeviceState, - deviceManager: mockedDeviceManagerState, + activeDeviceRegistry: mockedActiveDeviceRegistryState, + genericViews: { + devices: [], + } }) const { @@ -193,7 +196,10 @@ describe("when update downloads successfully", () => { }, }, coreDevice: mockedCoreDeviceState, - deviceManager: mockedDeviceManagerState, + activeDeviceRegistry: mockedActiveDeviceRegistryState, + genericViews: { + devices: [], + } }) const { @@ -249,7 +255,10 @@ describe("when download is cancelled by user", () => { }, }, coreDevice: mockedCoreDeviceState, - deviceManager: mockedDeviceManagerState, + activeDeviceRegistry: mockedActiveDeviceRegistryState, + genericViews: { + devices: [], + } }) const { @@ -298,7 +307,10 @@ describe("when download failed", () => { }, }, coreDevice: mockedCoreDeviceState, - deviceManager: mockedDeviceManagerState, + activeDeviceRegistry: mockedActiveDeviceRegistryState, + genericViews: { + devices: [], + } }) const { diff --git a/libs/core/update/actions/start-update-os/start-update-os.action.test.ts b/libs/core/update/actions/start-update-os/start-update-os.action.test.ts index 74c846856e..7fe7f81ab5 100644 --- a/libs/core/update/actions/start-update-os/start-update-os.action.test.ts +++ b/libs/core/update/actions/start-update-os/start-update-os.action.test.ts @@ -6,6 +6,9 @@ import { AnyAction } from "@reduxjs/toolkit" import createMockStore from "redux-mock-store" import thunk from "redux-thunk" +import { DeviceType } from "device-protocol/models" +import { ActiveDeviceRegistryState } from "active-device-registry/models" +import { GenericState } from "generic-view/store" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { @@ -27,10 +30,8 @@ import { TrackOsUpdateState, } from "Core/analytic-data-tracker/helpers" import { setRestartingStatus } from "Core/device" -import { DeviceType } from "device-protocol/models" import { CoreDeviceState } from "core-device/models" import { startUpdateOs } from "Core/update/actions" -import { DeviceManagerState } from "device-manager/models" jest.mock("Core/update/requests/remove-downloaded-os-updates.request") jest.mock("Core/analytic-data-tracker/helpers/track-os-update") @@ -179,9 +180,12 @@ describe("when all updating os requests return success status", () => { }, ], } as unknown as CoreDeviceState, - deviceManager: { + genericViews: { + devices: [] + } as unknown as GenericState, + activeDeviceRegistry: { activeDeviceId: "1", - } as unknown as DeviceManagerState, + } as unknown as ActiveDeviceRegistryState, }) beforeEach(() => { @@ -293,9 +297,12 @@ describe("when updating os request return failure status", () => { }, ], } as unknown as CoreDeviceState, - deviceManager: { + genericViews: { + devices: [] + } as unknown as GenericState, + activeDeviceRegistry: { activeDeviceId: "1", - } as unknown as DeviceManagerState, + } as unknown as ActiveDeviceRegistryState, }) test("action is rejected", async () => { diff --git a/libs/device-manager/feature/src/actions/deactivate-device.action.ts b/libs/device-manager/feature/src/actions/deactivate-device.action.ts index eea6dc2f89..23c25859a3 100644 --- a/libs/device-manager/feature/src/actions/deactivate-device.action.ts +++ b/libs/device-manager/feature/src/actions/deactivate-device.action.ts @@ -6,13 +6,13 @@ import { createAsyncThunk } from "@reduxjs/toolkit" import { DeviceBaseProperties } from "device-protocol/models" import { DeviceManagerEvent } from "device-manager/models" +import { setActiveDevice } from "active-device-registry/feature" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" import { setDeviceInitializationStatus } from "Core/device-initialization/actions/base.action" import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" import { MetadataKey, setValue } from "Core/metadata" -import { setActiveDeviceRequest } from "../requests" import { getDevicesSelector } from "../selectors" import { setSelectDeviceDrawerOpen } from "./set-select-device-drawer-open.action" @@ -21,7 +21,7 @@ export const deactivateDevice = createAsyncThunk< void, { state: ReduxRootState } >(DeviceManagerEvent.DeactivateDevice, async (_, { dispatch, getState }) => { - await setActiveDeviceRequest(undefined) + dispatch(setActiveDevice(undefined)) dispatch(setSelectDeviceDrawerOpen(false)) dispatch(setDiscoveryStatus(DiscoveryStatus.Idle)) dispatch(setDeviceInitializationStatus(DeviceInitializationStatus.Idle)) diff --git a/libs/device-manager/feature/src/actions/handle-device-activated.action.ts b/libs/device-manager/feature/src/actions/handle-device-activated.action.ts index 9c0240fdec..0f28d493e3 100644 --- a/libs/device-manager/feature/src/actions/handle-device-activated.action.ts +++ b/libs/device-manager/feature/src/actions/handle-device-activated.action.ts @@ -4,13 +4,13 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { activateDevice } from "generic-view/store" +import { activateDevice, cleanBackupProcess, cleanRestoreProcess } from "generic-view/store" import { DeviceManagerEvent } from "device-manager/models" +import { setActiveDevice } from "active-device-registry/feature" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { DeviceId } from "Core/device/constants/device-id" import { setDiscoveryStatus } from "Core/discovery-device/actions/base.action" import { DiscoveryStatus } from "Core/discovery-device/reducers/discovery-device.interface" -import { setActiveDevice } from "./set-active-device.action" export const handleDeviceActivated = createAsyncThunk< void, @@ -18,6 +18,8 @@ export const handleDeviceActivated = createAsyncThunk< { state: ReduxRootState } >(DeviceManagerEvent.HandleDeviceActivated, async (deviceId, { dispatch }) => { await dispatch(setActiveDevice(deviceId)) + dispatch(cleanBackupProcess()) + dispatch(cleanRestoreProcess()) setDiscoveryStatus(DiscoveryStatus.Discovered) dispatch(activateDevice({ deviceId })) }) diff --git a/libs/device-manager/feature/src/actions/index.ts b/libs/device-manager/feature/src/actions/index.ts index 3d19d717d8..c98bd660d8 100644 --- a/libs/device-manager/feature/src/actions/index.ts +++ b/libs/device-manager/feature/src/actions/index.ts @@ -6,5 +6,5 @@ export * from "./connect-device.action" export * from "./deactivate-device.action" export * from "./handle-device-activated.action" -export * from "./set-active-device.action" +export * from "../../../../active-device-registry/feature/src/actions/set-active-device.action" export * from "./set-select-device-drawer-open.action" diff --git a/libs/device-manager/feature/src/constants/controller.constant.ts b/libs/device-manager/feature/src/constants/controller.constant.ts index 6f916e884c..afa8860120 100644 --- a/libs/device-manager/feature/src/constants/controller.constant.ts +++ b/libs/device-manager/feature/src/constants/controller.constant.ts @@ -4,6 +4,5 @@ */ export enum IpcDeviceManagerEvent { - SetActiveDevice = "device-manager_set-active-device", ConnectDevice = "device-manager_connect-device", } diff --git a/libs/device-manager/feature/src/controllers/device-manager.controller.ts b/libs/device-manager/feature/src/controllers/device-manager.controller.ts index b9964eb276..740ebb0a63 100644 --- a/libs/device-manager/feature/src/controllers/device-manager.controller.ts +++ b/libs/device-manager/feature/src/controllers/device-manager.controller.ts @@ -12,11 +12,6 @@ import { IpcDeviceManagerEvent } from "../constants" export class DeviceManagerController { constructor(private deviceProtocolService: DeviceProtocolService) {} - @IpcEvent(IpcDeviceManagerEvent.SetActiveDevice) - public setActiveDevice(id: DeviceId | undefined): ResultObject { - return this.deviceProtocolService.setActiveDevice(id) - } - @IpcEvent(IpcDeviceManagerEvent.ConnectDevice) public connectDevice(id: DeviceId): Promise> { return this.deviceProtocolService.connectDevice(id) diff --git a/libs/device-manager/feature/src/reducers/device-manager.reducer.ts b/libs/device-manager/feature/src/reducers/device-manager.reducer.ts index 2a037917b0..4156f7d649 100644 --- a/libs/device-manager/feature/src/reducers/device-manager.reducer.ts +++ b/libs/device-manager/feature/src/reducers/device-manager.reducer.ts @@ -6,13 +6,10 @@ import { createReducer } from "@reduxjs/toolkit" import { DeviceManagerState } from "device-manager/models" import { - setActiveDevice, - deactivateDevice, setSelectDeviceDrawerOpen, } from "../actions" export const initialState: DeviceManagerState = { - activeDeviceId: undefined, selectDeviceDrawerOpen: false, } @@ -20,18 +17,6 @@ export const deviceManagerReducer = createReducer( initialState, (builder) => { builder - .addCase(setActiveDevice.fulfilled, (state, action) => { - return { - ...state, - activeDeviceId: action.payload, - } - }) - .addCase(deactivateDevice.fulfilled, (state) => { - return { - ...state, - activeDeviceId: undefined, - } - }) .addCase(setSelectDeviceDrawerOpen, (state, action) => { return { ...state, diff --git a/libs/device-manager/feature/src/requests/index.ts b/libs/device-manager/feature/src/requests/index.ts index 07f35b725e..0a3139b8ad 100644 --- a/libs/device-manager/feature/src/requests/index.ts +++ b/libs/device-manager/feature/src/requests/index.ts @@ -4,4 +4,3 @@ */ export * from "./connect-device.request" -export * from "./set-active-device.request" diff --git a/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts index 20e51a5c09..6e0e649911 100644 --- a/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device-base-data.selector.ts @@ -6,6 +6,7 @@ import { createSelector } from "@reduxjs/toolkit" import { getCoreDevicesSelector } from "core-device/feature" import { DeviceBaseProperties } from "device-protocol/models" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { DeviceState, HarmonyDeviceData, @@ -13,7 +14,6 @@ import { PureDeviceData, } from "Core/device" import { deviceStateSelector } from "Core/device/selectors" -import { deviceManagerState } from "./device-manager-state.selector" export interface DeviceBaseData extends DeviceBaseProperties, @@ -23,10 +23,9 @@ export interface DeviceBaseData export const getActiveDeviceBaseDataSelector = createSelector( getCoreDevicesSelector, - deviceManagerState, + activeDeviceIdSelector, deviceStateSelector, - (coreDevices, deviceManager, deviceState): DeviceBaseData | undefined => { - const { activeDeviceId } = deviceManager + (coreDevices, activeDeviceId, deviceState): DeviceBaseData | undefined => { const activeDevice = coreDevices.find(({ id }) => id === activeDeviceId) if (activeDevice === undefined) { diff --git a/libs/device-manager/feature/src/selectors/get-active-device.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts index f4ed0f4bc8..888e6b6d41 100644 --- a/libs/device-manager/feature/src/selectors/get-active-device.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts @@ -5,14 +5,13 @@ import { createSelector } from "@reduxjs/toolkit" import { AvailableDeviceProperties } from "device-manager/models" -import { deviceManagerState } from "./device-manager-state.selector" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { getDevicesSelector } from "./get-devices.selector" export const getActiveDevice = createSelector( getDevicesSelector, - deviceManagerState, - (devices, deviceManager): AvailableDeviceProperties | undefined => { - const { activeDeviceId } = deviceManager + activeDeviceIdSelector, + (devices, activeDeviceId): AvailableDeviceProperties | undefined => { return devices.find(({ id }) => id === activeDeviceId) } ) diff --git a/libs/device-manager/feature/src/selectors/index.ts b/libs/device-manager/feature/src/selectors/index.ts index 67e0379a91..0279b46394 100644 --- a/libs/device-manager/feature/src/selectors/index.ts +++ b/libs/device-manager/feature/src/selectors/index.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export * from "./active-device-id.selector" +export * from "../../../../active-device-registry/feature/src/selectors/active-device-id.selector" export * from "./device-manager-state.selector" export * from "./get-active-device-type.selector" export * from "./get-active-device.selector" @@ -14,5 +14,5 @@ export * from "./get-configured-devices.selector" export * from "./get-devices.selector" export * from "./get-failed-devices.selector" export * from "./is-active-device-attached.selector" -export * from "./is-active-device-set.selector" +export * from "../../../../active-device-registry/feature/src/selectors/is-active-device-set.selector" export * from "./is-device-list-empty.selector" diff --git a/libs/device-manager/models/src/device-manager.interface.ts b/libs/device-manager/models/src/device-manager.interface.ts index 5c9670ed3f..6dcdb00a26 100644 --- a/libs/device-manager/models/src/device-manager.interface.ts +++ b/libs/device-manager/models/src/device-manager.interface.ts @@ -3,9 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceId } from "Core/device/constants/device-id" - export interface DeviceManagerState { - activeDeviceId: DeviceId | undefined selectDeviceDrawerOpen: boolean } diff --git a/libs/device-manager/models/src/event.constant.ts b/libs/device-manager/models/src/event.constant.ts index c86bf2abe9..c54730b64e 100644 --- a/libs/device-manager/models/src/event.constant.ts +++ b/libs/device-manager/models/src/event.constant.ts @@ -7,6 +7,5 @@ export enum DeviceManagerEvent { ConnectDevice = "device-manager_connect-device", DeactivateDevice = "device-manager_deactivate-device", HandleDeviceActivated = "device-manager_handle-device-activated", - SetActiveDevice = "device-manager_set-active-device", SetSelectDeviceDrawerOpen = "device-manager_set-select-device-drawer-open", } From 66806defc358fd50620aa44c151e0309d9e0dd26 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Sat, 15 Jun 2024 09:50:51 +0200 Subject: [PATCH 014/100] [CP-2898] Eliminate duplicate activeDevice after merging state slices --- .../src/actions/set-active-device.action.ts | 1 - .../rest/menu/menu-bottom.component.tsx | 2 +- .../wrappers/layout-blank-wrapper.tsx | 2 +- .../actions/delete-contacts.action.ts | 2 +- .../contacts/actions/import-contact.action.ts | 2 +- .../contacts/contacts.component.tsx | 2 +- .../hooks/use-device-connect-failed-effect.ts | 6 +- .../core/hooks/use-device-connected-effect.ts | 6 +- .../core/hooks/use-device-detached-effect.ts | 6 +- .../hooks/use-discovery-redirect-effect.ts | 3 +- .../actions/initialize-mudita-pure.action.ts | 6 +- .../device-select-drawer.component.tsx | 2 +- .../is-active-device-processing.selector.ts | 2 +- .../device-connecting.component.tsx | 3 +- .../check-for-update.action.ts | 2 +- .../actions/handle-device-activated.action.ts | 3 +- .../feature/src/actions/index.ts | 1 - .../feature/src/selectors/index.ts | 2 - .../src/lib/modals/backup-error-modal.tsx | 6 +- .../modals/import-contacts-error-modal.tsx | 6 +- .../src/lib/modals/restore-error-modal.tsx | 4 +- .../store/src/lib/action-names.ts | 1 - .../src/lib/backup/create-backup.action.ts | 4 +- .../lib/backup/refresh-backup-list.action.ts | 6 +- .../src/lib/backup/restore-backup.action.ts | 9 +- .../transfer-data-to-device.action.ts | 3 +- .../lib/hooks/use-locked-device-handler.ts | 4 +- .../store/src/lib/hooks/use-outbox.ts | 10 +- .../start-data-transfer-to-device.action.ts | 5 +- .../selectors/active-device-configuration.ts | 10 +- .../lib/selectors/active-device-menu-items.ts | 10 +- .../store/src/lib/selectors/active-device.ts | 14 --- .../lib/selectors/data-migration-devices.ts | 3 +- .../store/src/lib/selectors/device-backups.ts | 8 +- .../store/src/lib/selectors/index.ts | 2 +- .../lib/selectors/screen-title-selector.ts | 13 +-- .../selectors/select-active-api-device-id.ts | 19 ++++ .../store/src/lib/views/actions.ts | 9 +- .../store/src/lib/views/reducer.ts | 95 +++++++------------ 39 files changed, 133 insertions(+), 161 deletions(-) delete mode 100644 libs/generic-view/store/src/lib/selectors/active-device.ts create mode 100644 libs/generic-view/store/src/lib/selectors/select-active-api-device-id.ts diff --git a/libs/active-device-registry/feature/src/actions/set-active-device.action.ts b/libs/active-device-registry/feature/src/actions/set-active-device.action.ts index 1a171104fe..b5fde246dd 100644 --- a/libs/active-device-registry/feature/src/actions/set-active-device.action.ts +++ b/libs/active-device-registry/feature/src/actions/set-active-device.action.ts @@ -9,7 +9,6 @@ import { DeviceId } from "Core/device/constants/device-id" import { setActiveDeviceRequest } from "../requests" import { ActiveDeviceRegistryEvent } from "../constants" - export const setActiveDevice = createAsyncThunk< DeviceId | undefined, DeviceId | undefined, diff --git a/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx b/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx index 90db5ef1db..bbc15738dd 100644 --- a/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx +++ b/libs/core/__deprecated__/renderer/components/rest/menu/menu-bottom.component.tsx @@ -10,8 +10,8 @@ import styled from "styled-components" import { getDevicesSelector, setSelectDeviceDrawerOpen, - activeDeviceIdSelector, } from "device-manager/feature" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { FunctionComponent } from "Core/core/types/function-component.interface" import { MenuGroupTestIds } from "Core/__deprecated__/renderer/components/rest/menu/menu-group-test-ids.enum" import Loader from "Core/__deprecated__/renderer/components/core/loader/loader.component" diff --git a/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx b/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx index 71933fd251..7cd2ae72ce 100644 --- a/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx +++ b/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx @@ -87,7 +87,7 @@ const mapStateToProps = ( state.update.needsForceUpdate || state.update.forceUpdateState === State.Loading || state.update.updateOsState === State.Loading || - state.genericViews.activeDevice + state.activeDeviceRegistry.activeDeviceId ), recoveryMode: ownProps.recoveryMode, onClose: ownProps.onClose, diff --git a/libs/core/contacts/actions/delete-contacts.action.ts b/libs/core/contacts/actions/delete-contacts.action.ts index 03ceb634b8..c8bcfc96e8 100644 --- a/libs/core/contacts/actions/delete-contacts.action.ts +++ b/libs/core/contacts/actions/delete-contacts.action.ts @@ -4,7 +4,7 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { isActiveDeviceSet } from "device-manager/feature" +import { isActiveDeviceSet } from "active-device-registry/feature" import { deleteContactsInState } from "Core/contacts/actions/base.action" import { ContactsEvent } from "Core/contacts/constants" import { ContactID } from "Core/contacts/reducers" diff --git a/libs/core/contacts/actions/import-contact.action.ts b/libs/core/contacts/actions/import-contact.action.ts index 8e4f6eb222..09756c04b7 100644 --- a/libs/core/contacts/actions/import-contact.action.ts +++ b/libs/core/contacts/actions/import-contact.action.ts @@ -12,7 +12,7 @@ import { } from "Core/contacts/requests" import { AppError } from "Core/core/errors" import { RequestResponseStatus } from "Core/core/types/request-response.interface" -import { activeDeviceIdSelector } from "device-manager/feature" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { ReduxRootState } from "Core/__deprecated__/renderer/store" export interface ImportContactArg { diff --git a/libs/core/contacts/components/contacts/contacts.component.tsx b/libs/core/contacts/components/contacts/contacts.component.tsx index ca89335c54..29b9c3812c 100644 --- a/libs/core/contacts/components/contacts/contacts.component.tsx +++ b/libs/core/contacts/components/contacts/contacts.component.tsx @@ -57,7 +57,7 @@ import { filterContacts } from "Core/contacts/helpers/filter-contacts/filter-con import { AppError } from "Core/core/errors" import { RequestResponseStatus } from "Core/core/types" import createFile from "Core/__deprecated__/renderer/utils/create-file/create-file" -import { activeDeviceIdSelector } from "device-manager/feature" +import { activeDeviceIdSelector } from "active-device-registry/feature" const allPossibleFormErrorCausedByAPI: FormError[] = [ { diff --git a/libs/core/core/hooks/use-device-connect-failed-effect.ts b/libs/core/core/hooks/use-device-connect-failed-effect.ts index 8257b4ddf8..c2223b950b 100644 --- a/libs/core/core/hooks/use-device-connect-failed-effect.ts +++ b/libs/core/core/hooks/use-device-connect-failed-effect.ts @@ -5,12 +5,11 @@ import { useEffect, useCallback } from "react" import { useHistory } from "react-router-dom" -import { useDispatch, useSelector } from "react-redux" +import { useSelector } from "react-redux" import { answerMain } from "shared/utils" import { DeviceProtocolMainEvent } from "device-protocol/models" import { DeviceBaseProperties } from "device-protocol/models" -import { activeDeviceIdSelector } from "device-manager/feature" -import { Dispatch } from "Core/__deprecated__/renderer/store" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { isDiscoveryDeviceInProgress } from "Core/discovery-device/selectors/is-discovery-device-in-progress.selector" @@ -19,7 +18,6 @@ import { isInitializationAppInProgress } from "Core/app-initialization/selectors export const useDeviceConnectFailedEffect = () => { const history = useHistory() - const dispatch = useDispatch() const activeDeviceProcessing = useSelector(isActiveDeviceProcessingSelector) const activeDeviceId = useSelector(activeDeviceIdSelector) const discoveryDeviceInProgress = useSelector(isDiscoveryDeviceInProgress) diff --git a/libs/core/core/hooks/use-device-connected-effect.ts b/libs/core/core/hooks/use-device-connected-effect.ts index 46de855ad3..6cd0c1cb83 100644 --- a/libs/core/core/hooks/use-device-connected-effect.ts +++ b/libs/core/core/hooks/use-device-connected-effect.ts @@ -7,11 +7,11 @@ import { useCallback, useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" import { answerMain } from "shared/utils" +import { getDevicesSelector } from "device-manager/feature" import { - activeDeviceIdSelector, setActiveDevice, - getDevicesSelector, -} from "device-manager/feature" + activeDeviceIdSelector, +} from "active-device-registry/feature" import { getDeviceConfigurationRequest } from "core-device/feature" import { DeviceProtocolMainEvent, diff --git a/libs/core/core/hooks/use-device-detached-effect.ts b/libs/core/core/hooks/use-device-detached-effect.ts index a6ab192ebf..f217180fc8 100644 --- a/libs/core/core/hooks/use-device-detached-effect.ts +++ b/libs/core/core/hooks/use-device-detached-effect.ts @@ -12,10 +12,8 @@ import { getDevicesSelector } from "device-manager/feature" import { selectDialogOpenState } from "shared/app-state" import { DeviceProtocolMainEvent } from "device-protocol/models" import { Dispatch, ReduxRootState } from "Core/__deprecated__/renderer/store" -import { - activeDeviceIdSelector, - deactivateDevice, -} from "device-manager/feature" +import { deactivateDevice } from "device-manager/feature" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import modalService from "Core/__deprecated__/renderer/components/core/modal/modal.service" import { cancelOsDownload } from "Core/update/requests" diff --git a/libs/core/core/hooks/use-discovery-redirect-effect.ts b/libs/core/core/hooks/use-discovery-redirect-effect.ts index 9a91378489..bf2616a437 100644 --- a/libs/core/core/hooks/use-discovery-redirect-effect.ts +++ b/libs/core/core/hooks/use-discovery-redirect-effect.ts @@ -6,7 +6,8 @@ import { useEffect, useRef } from "react" import { useSelector } from "react-redux" import { useHistory } from "react-router-dom" -import { isDeviceListEmpty, isActiveDeviceSet } from "device-manager/feature" +import { isDeviceListEmpty } from "device-manager/feature" +import { isActiveDeviceSet } from "active-device-registry/feature" import { isDiscoveryDeviceInProgress } from "Core/discovery-device/selectors/is-discovery-device-in-progress.selector" import { isInitializationDeviceInProgress } from "Core/device-initialization/selectors/is-initialization-device-in-progress.selector" import { URL_DISCOVERY_DEVICE } from "Core/__deprecated__/renderer/constants/urls" diff --git a/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts b/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts index 0ebfa98153..d03f54047d 100644 --- a/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts +++ b/libs/core/device-initialization/actions/initialize-mudita-pure.action.ts @@ -13,10 +13,8 @@ import { AppError } from "Core/core/errors" import { DeviceInitializationError } from "Core/device-initialization/constants/errors.enum" import { loadSettings } from "Core/settings/actions" import { configureDevice } from "core-device/feature" -import { - activeDeviceIdSelector, - isActiveDeviceAttachedSelector, -} from "device-manager/feature" +import { isActiveDeviceAttachedSelector } from "device-manager/feature" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { isActiveDeviceProcessingSelector } from "Core/device/selectors/is-active-device-processing.selector" import { getCrashDump } from "Core/crash-dump" import { checkForForceUpdateNeed } from "Core/update/actions" diff --git a/libs/core/device-select/components/device-select-drawer.component.tsx b/libs/core/device-select/components/device-select-drawer.component.tsx index cf611e8a3d..f32527ee0d 100644 --- a/libs/core/device-select/components/device-select-drawer.component.tsx +++ b/libs/core/device-select/components/device-select-drawer.component.tsx @@ -26,9 +26,9 @@ import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon import { getAvailableDevicesSelector, deactivateDevice, - activeDeviceIdSelector, handleDeviceActivated, } from "device-manager/feature" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { URL_DEVICE_INITIALIZATION, URL_ONBOARDING, diff --git a/libs/core/device/selectors/is-active-device-processing.selector.ts b/libs/core/device/selectors/is-active-device-processing.selector.ts index 05bdf84f61..e979522506 100644 --- a/libs/core/device/selectors/is-active-device-processing.selector.ts +++ b/libs/core/device/selectors/is-active-device-processing.selector.ts @@ -4,7 +4,7 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { isActiveDeviceSet } from "device-manager/feature" +import { isActiveDeviceSet } from "active-device-registry/feature" import { backupStateSelector } from "Core/backup" import { updateStateSelector } from "Core/update/selectors/update-state-selector" import { State } from "Core/core/constants" diff --git a/libs/core/discovery-device/components/device-connecting.component.tsx b/libs/core/discovery-device/components/device-connecting.component.tsx index 093a498625..8549b90867 100644 --- a/libs/core/discovery-device/components/device-connecting.component.tsx +++ b/libs/core/discovery-device/components/device-connecting.component.tsx @@ -10,7 +10,8 @@ import { delay } from "shared/utils" import { FunctionComponent } from "Core/core/types/function-component.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" import { TmpDispatch } from "Core/__deprecated__/renderer/store" -import { activeDeviceIdSelector, connectDevice } from "device-manager/feature" +import { connectDevice } from "device-manager/feature" +import { activeDeviceIdSelector } from "active-device-registry/feature" import { URL_DEVICE_INITIALIZATION, URL_DISCOVERY_DEVICE, diff --git a/libs/core/update/actions/check-for-update/check-for-update.action.ts b/libs/core/update/actions/check-for-update/check-for-update.action.ts index 8b770fa7fe..e58364c1a5 100644 --- a/libs/core/update/actions/check-for-update/check-for-update.action.ts +++ b/libs/core/update/actions/check-for-update/check-for-update.action.ts @@ -21,7 +21,7 @@ import { osUpdateAlreadyDownloadedCheck, } from "Core/update/requests" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { isActiveDeviceSet } from "device-manager/feature" +import { isActiveDeviceSet } from "active-device-registry/feature" interface Params { deviceType: DeviceType diff --git a/libs/device-manager/feature/src/actions/handle-device-activated.action.ts b/libs/device-manager/feature/src/actions/handle-device-activated.action.ts index 0f28d493e3..4a47e60e71 100644 --- a/libs/device-manager/feature/src/actions/handle-device-activated.action.ts +++ b/libs/device-manager/feature/src/actions/handle-device-activated.action.ts @@ -4,7 +4,7 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { activateDevice, cleanBackupProcess, cleanRestoreProcess } from "generic-view/store" +import { cleanBackupProcess, cleanRestoreProcess } from "generic-view/store" import { DeviceManagerEvent } from "device-manager/models" import { setActiveDevice } from "active-device-registry/feature" import { ReduxRootState } from "Core/__deprecated__/renderer/store" @@ -21,5 +21,4 @@ export const handleDeviceActivated = createAsyncThunk< dispatch(cleanBackupProcess()) dispatch(cleanRestoreProcess()) setDiscoveryStatus(DiscoveryStatus.Discovered) - dispatch(activateDevice({ deviceId })) }) diff --git a/libs/device-manager/feature/src/actions/index.ts b/libs/device-manager/feature/src/actions/index.ts index c98bd660d8..a8ccfe3242 100644 --- a/libs/device-manager/feature/src/actions/index.ts +++ b/libs/device-manager/feature/src/actions/index.ts @@ -6,5 +6,4 @@ export * from "./connect-device.action" export * from "./deactivate-device.action" export * from "./handle-device-activated.action" -export * from "../../../../active-device-registry/feature/src/actions/set-active-device.action" export * from "./set-select-device-drawer-open.action" diff --git a/libs/device-manager/feature/src/selectors/index.ts b/libs/device-manager/feature/src/selectors/index.ts index 0279b46394..5477b51189 100644 --- a/libs/device-manager/feature/src/selectors/index.ts +++ b/libs/device-manager/feature/src/selectors/index.ts @@ -3,7 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export * from "../../../../active-device-registry/feature/src/selectors/active-device-id.selector" export * from "./device-manager-state.selector" export * from "./get-active-device-type.selector" export * from "./get-active-device.selector" @@ -14,5 +13,4 @@ export * from "./get-configured-devices.selector" export * from "./get-devices.selector" export * from "./get-failed-devices.selector" export * from "./is-active-device-attached.selector" -export * from "../../../../active-device-registry/feature/src/selectors/is-active-device-set.selector" export * from "./is-device-list-empty.selector" diff --git a/libs/generic-view/feature/src/lib/modals/backup-error-modal.tsx b/libs/generic-view/feature/src/lib/modals/backup-error-modal.tsx index 22aaabefd3..5b70209ed1 100644 --- a/libs/generic-view/feature/src/lib/modals/backup-error-modal.tsx +++ b/libs/generic-view/feature/src/lib/modals/backup-error-modal.tsx @@ -8,15 +8,15 @@ import { BackupError, Modal } from "generic-view/ui" import { useDispatch, useSelector } from "react-redux" import { cleanBackupProcess, - selectActiveDevice, + selectActiveApiDeviceId, selectBackupProcessStatus, } from "generic-view/store" const BackupErrorModal: FunctionComponent = () => { const dispatch = useDispatch() - const activeDevice = useSelector(selectActiveDevice) + const activeDeviceId = useSelector(selectActiveApiDeviceId) const backupStatus = useSelector(selectBackupProcessStatus) - const opened = backupStatus === "FAILED" && !activeDevice + const opened = backupStatus === "FAILED" && !activeDeviceId const onClose = () => { dispatch(cleanBackupProcess()) diff --git a/libs/generic-view/feature/src/lib/modals/import-contacts-error-modal.tsx b/libs/generic-view/feature/src/lib/modals/import-contacts-error-modal.tsx index d3c450e074..2dd7167c03 100644 --- a/libs/generic-view/feature/src/lib/modals/import-contacts-error-modal.tsx +++ b/libs/generic-view/feature/src/lib/modals/import-contacts-error-modal.tsx @@ -9,14 +9,14 @@ import { useDispatch, useSelector } from "react-redux" import { cleanImportProcess, importStatusSelector, - selectActiveDevice, + selectActiveApiDeviceId, } from "generic-view/store" const ImportContactsErrorModal: FunctionComponent = () => { const dispatch = useDispatch() - const activeDevice = useSelector(selectActiveDevice) + const activeDeviceId = useSelector(selectActiveApiDeviceId) const importStatus = useSelector(importStatusSelector) - const opened = importStatus === "FAILED" && !activeDevice + const opened = importStatus === "FAILED" && !activeDeviceId const onClose = () => { dispatch(cleanImportProcess()) diff --git a/libs/generic-view/feature/src/lib/modals/restore-error-modal.tsx b/libs/generic-view/feature/src/lib/modals/restore-error-modal.tsx index e0bb0fcddc..3272fbb530 100644 --- a/libs/generic-view/feature/src/lib/modals/restore-error-modal.tsx +++ b/libs/generic-view/feature/src/lib/modals/restore-error-modal.tsx @@ -8,13 +8,13 @@ import { BackupRestoreError, Modal } from "generic-view/ui" import { useDispatch, useSelector } from "react-redux" import { cleanRestoreProcess, - selectActiveDevice, + selectActiveApiDeviceId, selectBackupRestoreStatus, } from "generic-view/store" const RestoreErrorModal: FunctionComponent = () => { const dispatch = useDispatch() - const activeDevice = useSelector(selectActiveDevice) + const activeDevice = useSelector(selectActiveApiDeviceId) const restoreStatus = useSelector(selectBackupRestoreStatus) const opened = restoreStatus === "FAILED" && !activeDevice diff --git a/libs/generic-view/store/src/lib/action-names.ts b/libs/generic-view/store/src/lib/action-names.ts index 84a260b913..edc773494e 100644 --- a/libs/generic-view/store/src/lib/action-names.ts +++ b/libs/generic-view/store/src/lib/action-names.ts @@ -13,7 +13,6 @@ export enum ActionName { SetViewData = "generic-views/set-view-data", AddDevice = "generic-views/add-device", RemoveDevice = "generic-views/remove-device", - ActivateDevice = "generic-views/activate-device", OpenModal = "generic-modals/open-modal", CloseModal = "generic-modals/close-modal", CloseAllModals = "generic-modals/close-all-modals", diff --git a/libs/generic-view/store/src/lib/backup/create-backup.action.ts b/libs/generic-view/store/src/lib/backup/create-backup.action.ts index 414a1a91c4..e9bf7d6cb3 100644 --- a/libs/generic-view/store/src/lib/backup/create-backup.action.ts +++ b/libs/generic-view/store/src/lib/backup/create-backup.action.ts @@ -12,9 +12,9 @@ import { sendClearRequest, startPreBackupRequest, } from "device/feature" - import { ActionName } from "../action-names" import { getFile } from "../file-transfer/get-file.action" +import { selectActiveApiDeviceId } from "../selectors" import { setBackupProcess, setBackupProcessFileStatus, @@ -61,7 +61,7 @@ export const createBackup = createAsyncThunk< }) ) - const deviceId = getState().genericViews.activeDevice + const deviceId = selectActiveApiDeviceId(getState()) if (deviceId === undefined || aborted) { return rejectWithValue(undefined) diff --git a/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts b/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts index 3fe54fec83..7ed6ff9a40 100644 --- a/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts +++ b/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts @@ -4,11 +4,11 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { readBackupDirectoryRequest } from "device/feature" import { DeviceId } from "Core/device/constants/device-id" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { readBackupDirectoryRequest } from "device/feature" - import { ActionName } from "../action-names" +import { selectActiveApiDeviceId } from "../selectors" import { Backup } from "./reducer" export const refreshBackupList = createAsyncThunk< @@ -20,7 +20,7 @@ export const refreshBackupList = createAsyncThunk< async (_, { getState, dispatch, rejectWithValue }) => { const refreshTimestamp = new Date().getTime() - const deviceId = getState().genericViews.activeDevice + const deviceId = selectActiveApiDeviceId(getState()) if (!deviceId) { return rejectWithValue(undefined) } diff --git a/libs/generic-view/store/src/lib/backup/restore-backup.action.ts b/libs/generic-view/store/src/lib/backup/restore-backup.action.ts index c4c5063758..d40ebb2884 100644 --- a/libs/generic-view/store/src/lib/backup/restore-backup.action.ts +++ b/libs/generic-view/store/src/lib/backup/restore-backup.action.ts @@ -4,7 +4,7 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import intersection from "lodash/intersection" import { cancelRestoreRequest, checkRestoreRequest, @@ -13,11 +13,12 @@ import { startRestorePreSendFileRequest, startRestoreRequest, } from "device/feature" -import intersection from "lodash/intersection" +import { RestoreFeature } from "generic-view/models" +import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { ActionName } from "../action-names" import { sendFile } from "../file-transfer/send-file.action" +import { selectActiveApiDeviceId } from "../selectors" import { setRestoreProcessFileStatus, setRestoreProcessStatus } from "./actions" -import { RestoreFeature } from "generic-view/models" export const restoreBackup = createAsyncThunk< undefined, @@ -46,7 +47,7 @@ export const restoreBackup = createAsyncThunk< } signal.addEventListener("abort", abortListener) - const deviceId = getState().genericViews.activeDevice + const deviceId = selectActiveApiDeviceId(getState()) const restoreFileId = getState().genericBackups.restoreProcess?.restoreFileId diff --git a/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts b/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts index cfd928eea8..cd5543729a 100644 --- a/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts +++ b/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts @@ -23,6 +23,7 @@ import { } from "./actions" import { isEmpty } from "lodash" import { DataTransfer } from "./reducer" +import { selectActiveApiDeviceId } from "generic-view/store" export type DomainData = { domain: Extract @@ -56,7 +57,7 @@ export const transferDataToDevice = createAsyncThunk< } signal.addEventListener("abort", abortListener) - const deviceId = getState().genericViews.activeDevice + const deviceId = selectActiveApiDeviceId(getState()) if (!deviceId) { return handleError() diff --git a/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts b/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts index 92af9ff9e9..3a50e04490 100644 --- a/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts +++ b/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts @@ -8,7 +8,7 @@ import { setDeviceInitializationStatus } from "Core/device-initialization/action import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" import { useDispatch, useSelector } from "react-redux" import { - selectActiveDevice, + selectActiveApiDeviceId, selectActiveDeviceFeatures, selectApiError, } from "../selectors" @@ -18,7 +18,7 @@ import { getAPIConfig } from "../get-api-config" export const useLockedDeviceHandler = () => { const dispatch = useDispatch() - const deviceId = useSelector(selectActiveDevice) + const deviceId = useSelector(selectActiveApiDeviceId) const deviceLocked = useSelector((state: ReduxRootState) => { return selectApiError(state, ApiError.DeviceLocked) }) diff --git a/libs/generic-view/store/src/lib/hooks/use-outbox.ts b/libs/generic-view/store/src/lib/hooks/use-outbox.ts index e3024cbcc9..f7be926140 100644 --- a/libs/generic-view/store/src/lib/hooks/use-outbox.ts +++ b/libs/generic-view/store/src/lib/hooks/use-outbox.ts @@ -7,20 +7,20 @@ import { Dispatch } from "Core/__deprecated__/renderer/store" import { useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { getOutboxData } from "../outbox/get-outbox-data.action" -import { selectActiveDevice } from "../selectors/active-device" +import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-id" import { selectLastRefreshTimestamp } from "../selectors/select-last-refresh-timestamp" import { useLockedDeviceHandler } from "./use-locked-device-handler" export const useOutbox = () => { const dispatch = useDispatch() - const activeDevice = useSelector(selectActiveDevice) + const activeDeviceId = useSelector(selectActiveApiDeviceId) const lastRefreshTimestamp = useSelector(selectLastRefreshTimestamp) useLockedDeviceHandler() useEffect(() => { - if (activeDevice) { + if (activeDeviceId) { const outboxTimeout = setTimeout(() => { - dispatch(getOutboxData({ deviceId: activeDevice })) + dispatch(getOutboxData({ deviceId: activeDeviceId })) }, 2000) return () => { @@ -29,7 +29,7 @@ export const useOutbox = () => { } return // eslint-disable-next-line react-hooks/exhaustive-deps - }, [activeDevice, lastRefreshTimestamp]) + }, [activeDeviceId, lastRefreshTimestamp]) } export const OutboxWrapper = () => { diff --git a/libs/generic-view/store/src/lib/imports/start-data-transfer-to-device.action.ts b/libs/generic-view/store/src/lib/imports/start-data-transfer-to-device.action.ts index 3ac8ab87e8..ff48cac595 100644 --- a/libs/generic-view/store/src/lib/imports/start-data-transfer-to-device.action.ts +++ b/libs/generic-view/store/src/lib/imports/start-data-transfer-to-device.action.ts @@ -5,7 +5,6 @@ import { createAsyncThunk } from "@reduxjs/toolkit" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { ActionName } from "../action-names" import { DataTransferDomain, UnifiedContact } from "device/models" import { cancelDataTransferRequest, @@ -15,7 +14,9 @@ import { startPreDataTransferRequest, startPreSendWithDataFileRequest, } from "device/feature" +import { ActionName } from "../action-names" import { sendFile } from "../file-transfer/send-file.action" +import { selectActiveApiDeviceId } from "../selectors" import { setDataTransferProcessFileStatus, setDataTransferProcessStatus, @@ -45,7 +46,7 @@ export const startDataTransferToDevice = createAsyncThunk< } signal.addEventListener("abort", abortListener) - const deviceId = getState().genericViews.activeDevice + const deviceId = selectActiveApiDeviceId(getState()) const activeProvider = getState().genericImport.currentImportProvider if (!deviceId || !activeProvider) { diff --git a/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts b/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts index 42fe1aa951..38694c8535 100644 --- a/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts +++ b/libs/generic-view/store/src/lib/selectors/active-device-configuration.ts @@ -5,13 +5,13 @@ import { createSelector } from "@reduxjs/toolkit" import { selectConfiguredDevices } from "./select-configured-devices" -import { selectActiveDevice } from "./active-device" +import { selectActiveApiDeviceId } from "./select-active-api-device-id" export const selectActiveDeviceConfiguration = createSelector( - [selectActiveDevice, selectConfiguredDevices], - (activeDevice, devicesConfiguration) => { - if (activeDevice) { - return devicesConfiguration[activeDevice] + [selectActiveApiDeviceId, selectConfiguredDevices], + (activeDeviceId, devicesConfiguration) => { + if (activeDeviceId) { + return devicesConfiguration[activeDeviceId] } return undefined } diff --git a/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts b/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts index e61a8b9d5e..2c263569ae 100644 --- a/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts +++ b/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts @@ -5,14 +5,14 @@ import { createSelector } from "@reduxjs/toolkit" import { generateMenu } from "generic-view/utils" -import { selectActiveDevice } from "./active-device" +import { selectActiveApiDeviceId } from "./select-active-api-device-id" import { selectConfiguredDevices } from "./select-configured-devices" export const activeDeviceMenuItems = createSelector( - [selectActiveDevice, selectConfiguredDevices], - (activeDevice, configuredDevices) => { - if (activeDevice) { - return configuredDevices[activeDevice].menuConfig + [selectActiveApiDeviceId, selectConfiguredDevices], + (activeDeviceId, configuredDevices) => { + if (activeDeviceId) { + return configuredDevices[activeDeviceId].menuConfig } return undefined } diff --git a/libs/generic-view/store/src/lib/selectors/active-device.ts b/libs/generic-view/store/src/lib/selectors/active-device.ts deleted file mode 100644 index e3a14a22ce..0000000000 --- a/libs/generic-view/store/src/lib/selectors/active-device.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 - */ - -import { createSelector } from "@reduxjs/toolkit" -import { ReduxRootState } from "Core/__deprecated__/renderer/store" - -export const selectActiveDevice = createSelector( - [(state: ReduxRootState) => state.genericViews.activeDevice], - (activeDevice) => { - return activeDevice - } -) diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts index f9baae52e9..0a8a700c99 100644 --- a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts +++ b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts @@ -9,6 +9,7 @@ import pureBlackImage from "Core/__deprecated__/renderer/images/pure-black-rende import pureGreyImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" import { kompaktImg } from "Root/demo-data/kompakt-img" import { selectConfiguredDevices } from "./select-configured-devices" +import { selectActiveApiDeviceId } from "./select-active-api-device-id" import { getDeviceTypeName } from "Core/discovery-device/utils/get-device-type-name" // FIXME: The device name should be moved to the API config response of API device @@ -57,7 +58,7 @@ export const selectDataMigrationSourceDevice = createSelector( export const selectDataMigrationTargetDevice = createSelector( selectDataMigrationTargetDevices, - (state: ReduxRootState) => state.genericViews.activeDevice, + selectActiveApiDeviceId, (devices, activeDeviceId) => { return devices.find((device) => device?.serialNumber === activeDeviceId) } diff --git a/libs/generic-view/store/src/lib/selectors/device-backups.ts b/libs/generic-view/store/src/lib/selectors/device-backups.ts index c0e976ef81..17d577c8ab 100644 --- a/libs/generic-view/store/src/lib/selectors/device-backups.ts +++ b/libs/generic-view/store/src/lib/selectors/device-backups.ts @@ -4,15 +4,15 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { selectActiveDevice } from "./active-device" +import { selectActiveApiDeviceId } from "./select-active-api-device-id" import { ReduxRootState } from "Core/__deprecated__/renderer/store" export const selectDeviceBackups = createSelector( - selectActiveDevice, + selectActiveApiDeviceId, (state: ReduxRootState) => state.genericBackups.backups, - (activeDevice, backups) => { + (activeDeviceId, backups) => { return backups - .filter((backup) => backup.serialNumber === activeDevice) + .filter((backup) => backup.serialNumber === activeDeviceId) .sort((a, b) => b.date.getTime() - a.date.getTime()) } ) diff --git a/libs/generic-view/store/src/lib/selectors/index.ts b/libs/generic-view/store/src/lib/selectors/index.ts index 2cc2c004ee..f62f8fd044 100644 --- a/libs/generic-view/store/src/lib/selectors/index.ts +++ b/libs/generic-view/store/src/lib/selectors/index.ts @@ -5,7 +5,7 @@ export * from "./active-device-menu-items" export * from "./screen-title-selector" -export * from "./active-device" +export * from "./select-active-api-device-id" export * from "./active-device-features" export * from "./component" export * from "./view" diff --git a/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts b/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts index d1b6c78617..d299026875 100644 --- a/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts +++ b/libs/generic-view/store/src/lib/selectors/screen-title-selector.ts @@ -5,16 +5,17 @@ import { createSelector } from "@reduxjs/toolkit" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { selectActiveDevice } from "./active-device" +import { selectActiveApiDeviceId } from "./select-active-api-device-id" import { selectConfiguredDevices } from "./select-configured-devices" export const screenTitleSelector = createSelector( - selectActiveDevice, + selectActiveApiDeviceId, selectConfiguredDevices, (state: ReduxRootState, viewKey: string) => viewKey, - (activeDevice, devices, viewKey) => { - const features = devices[activeDevice as keyof typeof devices]?.features - return features?.[viewKey as keyof typeof features]?.config?.main - .screenTitle + (activeDeviceId, devices, viewKey) => { + const features = activeDeviceId + ? devices[activeDeviceId]?.features + : undefined + return features?.[viewKey]?.config?.main.screenTitle } ) diff --git a/libs/generic-view/store/src/lib/selectors/select-active-api-device-id.ts b/libs/generic-view/store/src/lib/selectors/select-active-api-device-id.ts new file mode 100644 index 0000000000..9652b02fc9 --- /dev/null +++ b/libs/generic-view/store/src/lib/selectors/select-active-api-device-id.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { activeDeviceIdSelector } from "active-device-registry/feature" +import { selectDevices } from "./select-devices" + +export const selectActiveApiDeviceId = createSelector( + [selectDevices, activeDeviceIdSelector], + (devices, activeDeviceId) => { + if (activeDeviceId && devices[activeDeviceId]) { + return activeDeviceId + } else { + return undefined + } + } +) diff --git a/libs/generic-view/store/src/lib/views/actions.ts b/libs/generic-view/store/src/lib/views/actions.ts index b18b1a0396..1df100e20d 100644 --- a/libs/generic-view/store/src/lib/views/actions.ts +++ b/libs/generic-view/store/src/lib/views/actions.ts @@ -4,11 +4,10 @@ */ import { createAction } from "@reduxjs/toolkit" -import { DeviceId } from "Core/device/constants/device-id" -import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-elements" import { View } from "generic-view/utils" -import { DeviceBaseProperties } from "device-protocol/models" import { DeviceState } from "generic-view/models" +import { DeviceBaseProperties } from "device-protocol/models" +import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-elements" import { ActionName } from "../action-names" export const addDevice = createAction< @@ -29,7 +28,3 @@ export const setViewData = createAction<{ feature: string data: Record }>(ActionName.SetViewData) - -export const activateDevice = createAction<{ - deviceId: DeviceId -}>(ActionName.ActivateDevice) diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index 1d2a6c4ca9..ef1b2c788e 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -18,7 +18,6 @@ import { getMenuConfig } from "../get-menu-config" import { getOutboxData } from "../outbox/get-outbox-data.action" import { getGenericConfig } from "../features/get-generic-config.actions" import { - activateDevice, addDevice, removeDevice, setMenu, @@ -37,7 +36,6 @@ export interface GenericState { > lastResponse: unknown lastRefresh?: number - activeDevice?: DeviceId devices: Record apiErrors: Record } @@ -116,62 +114,45 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { builder.addCase(getOverviewData.fulfilled, (state, action) => { state.lastResponse = action.payload const deviceId = action.payload.deviceId - if (deviceId) { - state.devices[deviceId].features = { - ...state.devices[deviceId].features, - "mc-overview": { - config: state.devices[deviceId].features?.["mc-overview"]?.config, - data: action.payload.overviewData, - }, - ...(action.payload.aboutData - ? { - "mc-about": { - config: state.devices[deviceId].features?.["mc-about"]?.config, - data: action.payload.aboutData, - }, - } - : {}), - } + state.devices[deviceId].features = { + ...state.devices[deviceId].features, + "mc-overview": { + config: state.devices[deviceId].features?.["mc-overview"]?.config, + data: action.payload.overviewData, + }, + ...(action.payload.aboutData + ? { + "mc-about": { + config: state.devices[deviceId].features?.["mc-about"]?.config, + data: action.payload.aboutData, + }, + } + : {}), } }) builder.addCase(getOverviewConfig.fulfilled, (state, action) => { state.lastResponse = action.payload const deviceId = action.payload.deviceId - if (deviceId) { - state.devices[deviceId].features = { - ...state.devices[deviceId].features, - "mc-overview": { - config: action.payload.overviewConfig, - data: state.devices[deviceId].features?.["mc-overview"]?.data, - }, - ...(action.payload.aboutConfig - ? { - "mc-about": { - config: action.payload.aboutConfig, - data: state.devices[deviceId].features?.["mc-about"]?.data, - }, - } - : {}), - } as Features - } - if (state.activeDevice === undefined) { - state.activeDevice = deviceId - } - }) - builder.addCase(activateDevice, (state, action) => { - const { deviceId } = action.payload - state.activeDevice = state.devices?.[deviceId]?.apiConfig - ? deviceId - : undefined + state.devices[deviceId].features = { + ...state.devices[deviceId].features, + "mc-overview": { + config: action.payload.overviewConfig, + data: state.devices[deviceId].features?.["mc-overview"]?.data, + }, + ...(action.payload.aboutConfig + ? { + "mc-about": { + config: action.payload.aboutConfig, + data: state.devices[deviceId].features?.["mc-about"]?.data, + }, + } + : {}), + } as Features }) builder.addCase(removeDevice, (state, action) => { delete state.devices[action.payload.id] }) builder.addCase(getOutboxData.fulfilled, (state, action) => { - const { deviceId, timestamp } = action.payload - if (state.activeDevice === deviceId) { - state.lastRefresh = timestamp - } state.apiErrors[ApiError.DeviceLocked] = false }) builder.addCase(getOutboxData.rejected, (state, action) => { @@ -179,20 +160,16 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { deviceId: DeviceId timestamp: number } - if (state.activeDevice === deviceId) { - state.lastRefresh = timestamp - } + state.lastRefresh = timestamp }) builder.addCase(getGenericConfig.fulfilled, (state, action) => { const { deviceId, feature, view } = action.payload - if (deviceId) { - state.devices[deviceId].features = { - ...state.devices[deviceId].features, - [feature]: { - config: view, - data: state.devices[deviceId].features?.[feature]?.data, - }, - } + state.devices[deviceId].features = { + ...state.devices[deviceId].features, + [feature]: { + config: view, + data: state.devices[deviceId].features?.[feature]?.data, + }, } }) }) From 5f243c67ea98237e30d377cec00a54cbc63aae44 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Sun, 16 Jun 2024 08:20:38 +0200 Subject: [PATCH 015/100] [CP-2898] Resolve conflicts after rebase with develop --- .../store/src/lib/backup/create-backup.action.ts | 2 +- .../store/src/lib/backup/refresh-backup-list.action.ts | 2 +- .../store/src/lib/backup/restore-backup.action.ts | 2 +- .../store/src/lib/data-migration/actions.ts | 2 +- .../data-migration-percentage-progress.interface.ts | 10 ++++++++++ .../src/lib/data-migration/perform-data.migration.ts | 7 +------ .../data-transfer/transfer-data-to-device.action.ts | 2 +- .../src/lib/features/get-overview-data.actions.ts | 2 +- .../src/lib/hooks/use-api-serial-port-listeners.ts | 2 +- .../store/src/lib/hooks/use-locked-device-handler.ts | 10 ++++------ .../store/src/lib/hooks/use-screen-title.ts | 2 +- .../store/src/lib/selectors/data-migration-progress.ts | 2 +- 12 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 libs/generic-view/store/src/lib/data-migration/data-migration-percentage-progress.interface.ts diff --git a/libs/generic-view/store/src/lib/backup/create-backup.action.ts b/libs/generic-view/store/src/lib/backup/create-backup.action.ts index e9bf7d6cb3..06ffd020fc 100644 --- a/libs/generic-view/store/src/lib/backup/create-backup.action.ts +++ b/libs/generic-view/store/src/lib/backup/create-backup.action.ts @@ -14,7 +14,7 @@ import { } from "device/feature" import { ActionName } from "../action-names" import { getFile } from "../file-transfer/get-file.action" -import { selectActiveApiDeviceId } from "../selectors" +import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-id" import { setBackupProcess, setBackupProcessFileStatus, diff --git a/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts b/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts index 7ed6ff9a40..8fa3abed20 100644 --- a/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts +++ b/libs/generic-view/store/src/lib/backup/refresh-backup-list.action.ts @@ -8,7 +8,7 @@ import { readBackupDirectoryRequest } from "device/feature" import { DeviceId } from "Core/device/constants/device-id" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { ActionName } from "../action-names" -import { selectActiveApiDeviceId } from "../selectors" +import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-id" import { Backup } from "./reducer" export const refreshBackupList = createAsyncThunk< diff --git a/libs/generic-view/store/src/lib/backup/restore-backup.action.ts b/libs/generic-view/store/src/lib/backup/restore-backup.action.ts index d40ebb2884..777c6c29b2 100644 --- a/libs/generic-view/store/src/lib/backup/restore-backup.action.ts +++ b/libs/generic-view/store/src/lib/backup/restore-backup.action.ts @@ -17,7 +17,7 @@ import { RestoreFeature } from "generic-view/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { ActionName } from "../action-names" import { sendFile } from "../file-transfer/send-file.action" -import { selectActiveApiDeviceId } from "../selectors" +import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-id" import { setRestoreProcessFileStatus, setRestoreProcessStatus } from "./actions" export const restoreBackup = createAsyncThunk< diff --git a/libs/generic-view/store/src/lib/data-migration/actions.ts b/libs/generic-view/store/src/lib/data-migration/actions.ts index 6d54a8557e..b4e935dbdb 100644 --- a/libs/generic-view/store/src/lib/data-migration/actions.ts +++ b/libs/generic-view/store/src/lib/data-migration/actions.ts @@ -7,7 +7,7 @@ import { createAction } from "@reduxjs/toolkit" import { ActionName } from "../action-names" import { DataMigrationFeature } from "generic-view/models" import { DataMigrationStatus } from "./reducer" -import { DataMigrationPercentageProgress } from "./perform-data.migration" +import { DataMigrationPercentageProgress } from "./data-migration-percentage-progress.interface" export const setSourceDevice = createAction( ActionName.SetDataMigrationSourceDevice diff --git a/libs/generic-view/store/src/lib/data-migration/data-migration-percentage-progress.interface.ts b/libs/generic-view/store/src/lib/data-migration/data-migration-percentage-progress.interface.ts new file mode 100644 index 0000000000..d62920e62e --- /dev/null +++ b/libs/generic-view/store/src/lib/data-migration/data-migration-percentage-progress.interface.ts @@ -0,0 +1,10 @@ +/** + * 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 DataMigrationPercentageProgress { + CollectingData = 1, + TransferringData = 10, + Finished = 100, +} diff --git a/libs/generic-view/store/src/lib/data-migration/perform-data.migration.ts b/libs/generic-view/store/src/lib/data-migration/perform-data.migration.ts index ef0acd2610..85acc014af 100644 --- a/libs/generic-view/store/src/lib/data-migration/perform-data.migration.ts +++ b/libs/generic-view/store/src/lib/data-migration/perform-data.migration.ts @@ -20,12 +20,7 @@ import { } from "../data-transfer/transfer-data-to-device.action" import logger from "Core/__deprecated__/main/utils/logger" import { DataMigrationStatus } from "./reducer" - -export enum DataMigrationPercentageProgress { - CollectingData = 1, - TransferringData = 10, - Finished = 100, -} +import { DataMigrationPercentageProgress } from "./data-migration-percentage-progress.interface" export const performDataMigration = createAsyncThunk< void, diff --git a/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts b/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts index cd5543729a..261a5b96b6 100644 --- a/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts +++ b/libs/generic-view/store/src/lib/data-transfer/transfer-data-to-device.action.ts @@ -23,7 +23,7 @@ import { } from "./actions" import { isEmpty } from "lodash" import { DataTransfer } from "./reducer" -import { selectActiveApiDeviceId } from "generic-view/store" +import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-id" export type DomainData = { domain: Extract diff --git a/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts b/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts index 5124e44bcf..640c1e543a 100644 --- a/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts +++ b/libs/generic-view/store/src/lib/features/get-overview-data.actions.ts @@ -9,7 +9,7 @@ import { generateMcAboutData, generateMcOverviewData } from "generic-view/views" import { View } from "generic-view/utils" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { DeviceId } from "Core/device/constants/device-id" -import { selectConfiguredDevice } from "../selectors" +import { selectConfiguredDevice } from "../selectors/select-configured-devices" import { FeaturesActions } from "./featues-action-keys" export const getOverviewData = createAsyncThunk< diff --git a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts index d3e14f0927..35ab0cd7d8 100644 --- a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts +++ b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts @@ -14,7 +14,7 @@ import { addDevice, removeDevice } from "../views/actions" import { getAPIConfig } from "../get-api-config" import { setBackupProcessStatus } from "../backup/actions" import { closeAllModals } from "../modals/actions" -import { selectBackupProcessStatus } from "../selectors" +import { selectBackupProcessStatus } from "../selectors/backup-process-status" import { clearDataMigrationDevice } from "../data-migration/clear-data-migration.action" export const useAPISerialPortListeners = () => { diff --git a/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts b/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts index 3a50e04490..7f06e891a4 100644 --- a/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts +++ b/libs/generic-view/store/src/lib/hooks/use-locked-device-handler.ts @@ -4,14 +4,12 @@ */ import { useEffect } from "react" +import { useDispatch, useSelector } from "react-redux" import { setDeviceInitializationStatus } from "Core/device-initialization/actions/base.action" import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" -import { useDispatch, useSelector } from "react-redux" -import { - selectActiveApiDeviceId, - selectActiveDeviceFeatures, - selectApiError, -} from "../selectors" +import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-id" +import { selectActiveDeviceFeatures } from "../selectors/active-device-features" +import { selectApiError } from "../selectors/api-error" import { Dispatch, ReduxRootState } from "Core/__deprecated__/renderer/store" import { ApiError } from "device/models" import { getAPIConfig } from "../get-api-config" diff --git a/libs/generic-view/store/src/lib/hooks/use-screen-title.ts b/libs/generic-view/store/src/lib/hooks/use-screen-title.ts index 3c9f8c836f..9f81243935 100644 --- a/libs/generic-view/store/src/lib/hooks/use-screen-title.ts +++ b/libs/generic-view/store/src/lib/hooks/use-screen-title.ts @@ -5,7 +5,7 @@ import { useSelector } from "react-redux" import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { screenTitleSelector } from "../selectors" +import { screenTitleSelector } from "../selectors/screen-title-selector" export const useScreenTitle = (viewKey: string) => { return useSelector((state: ReduxRootState) => { diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts b/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts index a12d2e3f82..72d61cf7e1 100644 --- a/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts +++ b/libs/generic-view/store/src/lib/selectors/data-migration-progress.ts @@ -5,8 +5,8 @@ import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { createSelector } from "@reduxjs/toolkit" -import { DataMigrationPercentageProgress } from "../data-migration/perform-data.migration" import { selectDataTransferProgress } from "./data-transfer-progress" +import { DataMigrationPercentageProgress } from "../data-migration/data-migration-percentage-progress.interface" export const selectDataMigrationProgress = createSelector( selectDataTransferProgress, From 63464a0624d151c9014b57c5229821e40167235f Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Wed, 12 Jun 2024 08:37:48 +0200 Subject: [PATCH 016/100] [CP-2898] Commit broken png imports to fix --- .../store/src/lib/selectors/data-migration-devices.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts index 0a8a700c99..9d1dbeeb75 100644 --- a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts +++ b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts @@ -5,8 +5,9 @@ import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { createSelector } from "@reduxjs/toolkit" -import pureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" -import pureGreyImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" +// TODO: fix imports +// import pureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" +// import pureGreyImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" import { kompaktImg } from "Root/demo-data/kompakt-img" import { selectConfiguredDevices } from "./select-configured-devices" import { selectActiveApiDeviceId } from "./select-active-api-device-id" @@ -24,7 +25,8 @@ export const selectDataMigrationSourceDevices = createSelector( .filter(({ deviceType }) => deviceType === "MuditaPure") .map((device) => ({ name: getDeviceTypeName(device.deviceType!), - image: device.caseColour === "black" ? pureBlackImage : pureGreyImage, + // image: device.caseColour === "black" ? pureBlackImage : pureGreyImage, + image: kompaktImg, serialNumber: device.serialNumber!, })) ) From f4ba9854e3d54397ec866d10bd9d9086dbe62661 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 11 Jun 2024 16:36:59 +0200 Subject: [PATCH 017/100] [CP-2898] wip --- .../services/device-resolver.service.test.ts | 39 ------------------- .../validators/port-info.validator.test.ts | 35 ----------------- 2 files changed, 74 deletions(-) delete mode 100644 libs/device-protocol/feature/src/services/device-resolver.service.test.ts delete mode 100644 libs/device-protocol/feature/src/validators/port-info.validator.test.ts diff --git a/libs/device-protocol/feature/src/services/device-resolver.service.test.ts b/libs/device-protocol/feature/src/services/device-resolver.service.test.ts deleted file mode 100644 index 94420a02e7..0000000000 --- a/libs/device-protocol/feature/src/services/device-resolver.service.test.ts +++ /dev/null @@ -1,39 +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 { DeviceType } from "device-protocol/models" -import { ProductID } from "Core/device/constants" -import { DeviceResolverService } from "../services" - -const subject = new DeviceResolverService() - -describe("Pure descriptor", () => { - test.each([ProductID.MuditaPureDeprecated])( - "returns Device with MuditaPure device type if %s productID has been provided", - (productId) => { - expect( - subject.resolve({ productId, path: "/dev/123" })?.deviceType - ).toEqual(DeviceType.MuditaPure) - } - ) -}) - -describe("Harmony descriptor", () => { - test("returns Device with MuditaPure device type if 0300 productID has been provided", () => { - expect( - subject.resolve({ productId: ProductID.MuditaHarmony, path: "/dev/123" }) - ?.deviceType - ).toEqual(DeviceType.MuditaHarmony) - }) -}) - -//TODO: temporary, remove in future -describe.skip("Unknown descriptor", () => { - test("returns undefined if unknown product id has been provided", () => { - expect( - subject.resolve({ productId: "0000", path: "/dev/123" }) - ).toBeUndefined() - }) -}) diff --git a/libs/device-protocol/feature/src/validators/port-info.validator.test.ts b/libs/device-protocol/feature/src/validators/port-info.validator.test.ts deleted file mode 100644 index 6733cc73f6..0000000000 --- a/libs/device-protocol/feature/src/validators/port-info.validator.test.ts +++ /dev/null @@ -1,35 +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 { PortInfoValidator } from "./port-info.validator" - -test("isVendorId function works properly", () => { - expect(PortInfoValidator.isVendorIdValid({ vendorId: "3310" })).toBeTruthy() - expect(PortInfoValidator.isVendorIdValid({ vendorId: undefined })).toBeFalsy() - expect(PortInfoValidator.isVendorIdValid({})).toBeFalsy() -}) - -test("isProductId function works properly", () => { - expect(PortInfoValidator.isProductIdValid({ productId: "0100" })).toBeTruthy() - expect( - PortInfoValidator.isProductIdValid({ productId: undefined }) - ).toBeFalsy() - expect(PortInfoValidator.isProductIdValid({})).toBeFalsy() -}) - -test("isPortInfoMatch function works properly", () => { - expect( - PortInfoValidator.isPortInfoMatch({ vendorId: "3310", productId: "0100" }) - ).toBeTruthy() - expect( - PortInfoValidator.isPortInfoMatch({ vendorId: "3310", productId: "AAAA" }) - ).toBeFalsy() - expect( - PortInfoValidator.isPortInfoMatch({ vendorId: "bbbb", productId: "0100" }) - ).toBeFalsy() - expect(PortInfoValidator.isPortInfoMatch({ vendorId: "3310" })).toBeFalsy() - expect(PortInfoValidator.isPortInfoMatch({ productId: "0100" })).toBeFalsy() - expect(PortInfoValidator.isPortInfoMatch({})).toBeFalsy() -}) From 02b5309591f0f6b9f22ac167737b861a77a7cc18 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 09:05:55 +0200 Subject: [PATCH 018/100] [CP-2898] PNG fixed --- .../device-preview/device-image.component.tsx | 7 ++----- .../src/lib/selectors/data-migration-devices.ts | 12 +++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libs/core/overview/components/device-preview/device-image.component.tsx b/libs/core/overview/components/device-preview/device-image.component.tsx index db1e460b7a..3265a64d77 100644 --- a/libs/core/overview/components/device-preview/device-image.component.tsx +++ b/libs/core/overview/components/device-preview/device-image.component.tsx @@ -9,11 +9,8 @@ import { DeviceType } from "device-protocol/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import Image from "Core/__deprecated__/renderer/components/core/image/image.component" import { DeviceTestIds } from "Core/overview/components/device-preview/device-preview-test-ids.enum" -// TODO: fix imports -// import PureGrayImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" -// import PureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" -import PureGrayImage from "Core/__deprecated__/renderer/images/harmony-gray-render.png" -import PureBlackImage from "Core/__deprecated__/renderer/images/harmony-black-render.png" +import PureGrayImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" +import PureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" import KompaktBlackImage from "Core/__deprecated__/renderer/images/kompakt-black-render.png" import HarmonyGrayImage from "Core/__deprecated__/renderer/images/harmony-gray-render.png" import HarmonyBlackImage from "Core/__deprecated__/renderer/images/harmony-black-render.png" diff --git a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts index 9d1dbeeb75..cab92d50b8 100644 --- a/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts +++ b/libs/generic-view/store/src/lib/selectors/data-migration-devices.ts @@ -3,15 +3,14 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { createSelector } from "@reduxjs/toolkit" -// TODO: fix imports -// import pureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" -// import pureGreyImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" import { kompaktImg } from "Root/demo-data/kompakt-img" +import { ReduxRootState } from "Core/__deprecated__/renderer/store" +import pureBlackImage from "Core/__deprecated__/renderer/images/pure-black-render.png" +import pureGreyImage from "Core/__deprecated__/renderer/images/pure-gray-render.png" +import { getDeviceTypeName } from "Core/discovery-device/utils/get-device-type-name" import { selectConfiguredDevices } from "./select-configured-devices" import { selectActiveApiDeviceId } from "./select-active-api-device-id" -import { getDeviceTypeName } from "Core/discovery-device/utils/get-device-type-name" // FIXME: The device name should be moved to the API config response of API device const messages = { @@ -25,8 +24,7 @@ export const selectDataMigrationSourceDevices = createSelector( .filter(({ deviceType }) => deviceType === "MuditaPure") .map((device) => ({ name: getDeviceTypeName(device.deviceType!), - // image: device.caseColour === "black" ? pureBlackImage : pureGreyImage, - image: kompaktImg, + image: device.caseColour === "black" ? pureBlackImage : pureGreyImage, serialNumber: device.serialNumber!, })) ) From 175127fd70a5017c51d5734629ef2e29bfe09c3f Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 09:07:47 +0200 Subject: [PATCH 019/100] [CP-2898] displayname & sourceRootin config fixed --- libs/core-device/models/jest.config.ts | 2 +- libs/device-manager/feature/jest.config.ts | 2 +- libs/device-manager/feature/project.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/core-device/models/jest.config.ts b/libs/core-device/models/jest.config.ts index 49b89837b3..12d1051c4d 100644 --- a/libs/core-device/models/jest.config.ts +++ b/libs/core-device/models/jest.config.ts @@ -1,6 +1,6 @@ /* eslint-disable */ export default { - displayName: "models", + displayName: "core-device-models", preset: "../../../jest.preset.js", transform: { "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", diff --git a/libs/device-manager/feature/jest.config.ts b/libs/device-manager/feature/jest.config.ts index 3c506b81fb..c14617760b 100644 --- a/libs/device-manager/feature/jest.config.ts +++ b/libs/device-manager/feature/jest.config.ts @@ -1,6 +1,6 @@ /* eslint-disable */ export default { - displayName: "feature", + displayName: "device-manager-feature", preset: "../../../jest.preset.js", transform: { "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nx/react/plugins/jest", diff --git a/libs/device-manager/feature/project.json b/libs/device-manager/feature/project.json index 93b0f6c6fe..a9da5395ce 100644 --- a/libs/device-manager/feature/project.json +++ b/libs/device-manager/feature/project.json @@ -1,7 +1,7 @@ { "name": "device-manager-feature", "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/device-manager-feature/src", + "sourceRoot": "libs/device-manager/feature/src", "projectType": "library", "tags": [], "targets": { From 9e862168b4bcd75527c586c39f455856d81642a6 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 09:08:06 +0200 Subject: [PATCH 020/100] Revert "[CP-2898] wip" This reverts commit 54ef882693300f1531a358694a75a9577e31325a. --- .../services/device-resolver.service.test.ts | 39 +++++++++++++++++++ .../validators/port-info.validator.test.ts | 35 +++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 libs/device-protocol/feature/src/services/device-resolver.service.test.ts create mode 100644 libs/device-protocol/feature/src/validators/port-info.validator.test.ts diff --git a/libs/device-protocol/feature/src/services/device-resolver.service.test.ts b/libs/device-protocol/feature/src/services/device-resolver.service.test.ts new file mode 100644 index 0000000000..94420a02e7 --- /dev/null +++ b/libs/device-protocol/feature/src/services/device-resolver.service.test.ts @@ -0,0 +1,39 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { DeviceType } from "device-protocol/models" +import { ProductID } from "Core/device/constants" +import { DeviceResolverService } from "../services" + +const subject = new DeviceResolverService() + +describe("Pure descriptor", () => { + test.each([ProductID.MuditaPureDeprecated])( + "returns Device with MuditaPure device type if %s productID has been provided", + (productId) => { + expect( + subject.resolve({ productId, path: "/dev/123" })?.deviceType + ).toEqual(DeviceType.MuditaPure) + } + ) +}) + +describe("Harmony descriptor", () => { + test("returns Device with MuditaPure device type if 0300 productID has been provided", () => { + expect( + subject.resolve({ productId: ProductID.MuditaHarmony, path: "/dev/123" }) + ?.deviceType + ).toEqual(DeviceType.MuditaHarmony) + }) +}) + +//TODO: temporary, remove in future +describe.skip("Unknown descriptor", () => { + test("returns undefined if unknown product id has been provided", () => { + expect( + subject.resolve({ productId: "0000", path: "/dev/123" }) + ).toBeUndefined() + }) +}) diff --git a/libs/device-protocol/feature/src/validators/port-info.validator.test.ts b/libs/device-protocol/feature/src/validators/port-info.validator.test.ts new file mode 100644 index 0000000000..6733cc73f6 --- /dev/null +++ b/libs/device-protocol/feature/src/validators/port-info.validator.test.ts @@ -0,0 +1,35 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { PortInfoValidator } from "./port-info.validator" + +test("isVendorId function works properly", () => { + expect(PortInfoValidator.isVendorIdValid({ vendorId: "3310" })).toBeTruthy() + expect(PortInfoValidator.isVendorIdValid({ vendorId: undefined })).toBeFalsy() + expect(PortInfoValidator.isVendorIdValid({})).toBeFalsy() +}) + +test("isProductId function works properly", () => { + expect(PortInfoValidator.isProductIdValid({ productId: "0100" })).toBeTruthy() + expect( + PortInfoValidator.isProductIdValid({ productId: undefined }) + ).toBeFalsy() + expect(PortInfoValidator.isProductIdValid({})).toBeFalsy() +}) + +test("isPortInfoMatch function works properly", () => { + expect( + PortInfoValidator.isPortInfoMatch({ vendorId: "3310", productId: "0100" }) + ).toBeTruthy() + expect( + PortInfoValidator.isPortInfoMatch({ vendorId: "3310", productId: "AAAA" }) + ).toBeFalsy() + expect( + PortInfoValidator.isPortInfoMatch({ vendorId: "bbbb", productId: "0100" }) + ).toBeFalsy() + expect(PortInfoValidator.isPortInfoMatch({ vendorId: "3310" })).toBeFalsy() + expect(PortInfoValidator.isPortInfoMatch({ productId: "0100" })).toBeFalsy() + expect(PortInfoValidator.isPortInfoMatch({})).toBeFalsy() +}) From 9e0e75a075a15f7528fc2113d3b75127ad1fe990 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 09:40:28 +0200 Subject: [PATCH 021/100] [CP-2898] fix tests in device-protocol --- {libs/core/__mocks__ => __mocks__}/p-queue.ts | 0 jest.preset.js | 2 ++ jest.setup.js | 6 ++++++ jest/jest.config.core.js | 1 + 4 files changed, 9 insertions(+) rename {libs/core/__mocks__ => __mocks__}/p-queue.ts (100%) create mode 100644 jest.setup.js diff --git a/libs/core/__mocks__/p-queue.ts b/__mocks__/p-queue.ts similarity index 100% rename from libs/core/__mocks__/p-queue.ts rename to __mocks__/p-queue.ts diff --git a/jest.preset.js b/jest.preset.js index 5add69934a..983cc58c6e 100644 --- a/jest.preset.js +++ b/jest.preset.js @@ -11,5 +11,7 @@ module.exports = { ...nxPreset.moduleNameMapper, "App/(.*)": `${__dirname}/apps/mudita-center/src/$1`, "Core/(.*)": `${__dirname}/libs/core/$1`, + "p-queue$": `${__dirname}/__mocks__/p-queue.ts`, }, + setupFilesAfterEnv: [`${__dirname}/jest.setup.js`], } diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 0000000000..25b5da26e7 --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,6 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +require("reflect-metadata") diff --git a/jest/jest.config.core.js b/jest/jest.config.core.js index a7527932bc..155b2144cd 100644 --- a/jest/jest.config.core.js +++ b/jest/jest.config.core.js @@ -19,6 +19,7 @@ module.exports = { "Core/(.*)": "/libs/core/$1", "Cypress/(.*)": "/apps/mudita-center/cypress/$1", "Storybook/(.*)": "/apps/mudita-center/.storybook/$1", + "p-queue$": `${__dirname}/__mocks__/p-queue.ts`, }, rootDir: "../", moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], From 547eb41b272b3c61fee6211def2e134245c8b811 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 10:34:47 +0200 Subject: [PATCH 022/100] [CP-2898] improve useHandleDevicesDetached logic to handle just api deviceDetachedEvents --- .../hooks/use-api-serial-port-listeners.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts index 35ab0cd7d8..c41c8aa038 100644 --- a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts +++ b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts @@ -66,17 +66,24 @@ const useHandleDevicesDetached = () => { return useCallback( async (deviceDetachedEvents: DeviceBaseProperties[]) => { for (const event of deviceDetachedEvents) { - const { deviceType, id } = event - dispatch(clearDataMigrationDevice(id)) + dispatch(clearDataMigrationDevice(event.id)) + } - if (deviceType !== DeviceType.APIDevice) { - return - } + const apiEvents = deviceDetachedEvents.filter( + ({ deviceType }) => deviceType !== DeviceType.APIDevice + ) + + if (apiEvents.length === 0) { + return + } + + for (const event of apiEvents) { dispatch(removeDevice(event)) - dispatch(closeAllModals()) - if (backupProcess) { - dispatch(setBackupProcessStatus("FAILED")) - } + } + + dispatch(closeAllModals()) + if (backupProcess) { + dispatch(setBackupProcessStatus("FAILED")) } }, [dispatch, backupProcess] From 18798077986a391012608f2573bdecab3ef4af58 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 11:23:55 +0200 Subject: [PATCH 023/100] [CP-2898] Rename deviceProtocolService to deviceProtocol --- .../src/active-device-registry.module.ts | 6 +- .../active-device-registry.controller.ts | 6 +- .../src/controllers/core-device.controller.ts | 6 +- .../feature/src/core-device.module.ts | 6 +- .../analytic-data-tracker.module.ts | 6 +- libs/core/backup/backup.module.ts | 22 ++-- .../services/backup-create.service.test.ts | 22 ++-- .../backup/services/backup-create.service.ts | 8 +- .../services/backup-restore.service.test.ts | 24 ++-- .../backup/services/backup-restore.service.ts | 8 +- .../backup/services/base-backup.service.ts | 6 +- .../services/sync-backup-create.service.ts | 18 +-- libs/core/contacts/contact.module.ts | 8 +- .../contacts/services/contact.service.test.ts | 58 ++++----- .../core/contacts/services/contact.service.ts | 30 +++-- libs/core/core/application.module.ts | 15 ++- libs/core/core/module/base.module.ts | 4 +- libs/core/core/types/module.type.ts | 4 +- libs/core/crash-dump/crash-dump.module.ts | 10 +- .../services/crash-dump.service.test.ts | 59 +++++---- .../crash-dump/services/crash-dump.service.ts | 16 ++- libs/core/data-sync/data-sync.module.ts | 8 +- .../data-sync/services/data-sync.service.ts | 8 +- libs/core/desktop/desktop.module.ts | 6 +- .../commands/base.command.ts | 4 +- .../commands/file-delete.command.test.ts | 16 +-- .../commands/file-delete.command.ts | 16 ++- .../commands/file-upload.command.test.ts | 26 ++-- .../commands/file-upload.command.ts | 28 ++--- .../commands/retrieve-files.command.test.ts | 16 +-- .../commands/retrieve-files.command.ts | 2 +- .../device-file-system.module.ts | 8 +- .../device-file-system.service.test.ts | 18 +-- .../services/device-file-system.service.ts | 64 +++++----- libs/core/device-info/device-info.module.ts | 8 +- .../services/device-info.service.ts | 12 +- libs/core/device-log/device-log.module.ts | 10 +- .../services/device-log.service.test.ts | 21 ++-- .../device-log/services/device-log.service.ts | 20 ++-- libs/core/device/device.module.ts | 8 +- libs/core/device/services/device.service.ts | 27 ++--- .../files-manager/files-manager.module.ts | 12 +- .../index-storage/index-storage.module.ts | 6 +- libs/core/messages/message.module.ts | 4 +- .../messages/services/message.service.test.ts | 112 ++++++++---------- .../core/messages/services/message.service.ts | 24 ++-- .../messages/services/thread.service.test.ts | 74 +++++------- libs/core/messages/services/thread.service.ts | 12 +- libs/core/outbox/factories/outbox.factory.ts | 18 +-- libs/core/outbox/outbox.module.ts | 4 +- .../outbox/services/outbox.service.test.ts | 14 +-- libs/core/outbox/services/outbox.service.ts | 8 +- libs/core/search/search.module.ts | 6 +- libs/core/settings/settings.module.ts | 6 +- .../services/template.service.test.ts | 60 ++++------ .../templates/services/template.service.ts | 24 ++-- libs/core/templates/template.module.ts | 8 +- .../update/services/device-update.service.ts | 14 +-- libs/core/update/update.module.ts | 12 +- .../controllers/device-manager.controller.ts | 6 +- .../feature/src/device-manager.module.ts | 6 +- .../feature/src/device-protocol.module.ts | 8 +- .../usb-device-detection.observer.ts | 11 +- ...protocol.service.ts => device-protocol.ts} | 2 +- .../feature/src/services/index.ts | 2 +- .../src/lib/api-config/api-config.service.ts | 10 +- .../lib/api-features/api-features.service.ts | 18 +-- libs/device/feature/src/lib/api-module.ts | 29 ++--- .../feature/src/lib/backup/backup.service.ts | 16 +-- .../data-transfer/data-transfer.service.ts | 20 ++-- .../device-system-actions.service.ts | 8 +- .../lib/file-manager/file-manager.service.ts | 12 +- .../file-transfer/file-transfer.service.ts | 28 ++--- .../feature/src/lib/menu/menu.service.ts | 8 +- .../feature/src/lib/outbox/outbox.service.ts | 6 +- .../src/lib/restore/restore.service.ts | 20 ++-- 76 files changed, 603 insertions(+), 693 deletions(-) rename libs/device-protocol/feature/src/services/{device-protocol.service.ts => device-protocol.ts} (99%) diff --git a/libs/active-device-registry/feature/src/active-device-registry.module.ts b/libs/active-device-registry/feature/src/active-device-registry.module.ts index a43f19f5b7..605badb179 100644 --- a/libs/active-device-registry/feature/src/active-device-registry.module.ts +++ b/libs/active-device-registry/feature/src/active-device-registry.module.ts @@ -3,15 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { ActiveDeviceRegistryController } from "./controllers" export class ActiveDeviceRegistryModule { public controllers - constructor(public deviceProtocolService: DeviceProtocolService) { + constructor(public deviceProtocol: DeviceProtocol) { const activeDeviceRegistryController = new ActiveDeviceRegistryController( - this.deviceProtocolService + this.deviceProtocol ) this.controllers = [activeDeviceRegistryController] diff --git a/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts b/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts index 077a928cda..1d07112039 100644 --- a/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts +++ b/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts @@ -4,16 +4,16 @@ */ import { IpcEvent } from "Core/core/decorators" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" import { IpcActiveDeviceRegistryEvent } from "../constants" export class ActiveDeviceRegistryController { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(IpcActiveDeviceRegistryEvent.SetActiveDevice) public setActiveDevice(id: DeviceId | undefined): ResultObject { - return this.deviceProtocolService.setActiveDevice(id) + return this.deviceProtocol.setActiveDevice(id) } } diff --git a/libs/core-device/feature/src/controllers/core-device.controller.ts b/libs/core-device/feature/src/controllers/core-device.controller.ts index 289f3457dc..6debfbceb2 100644 --- a/libs/core-device/feature/src/controllers/core-device.controller.ts +++ b/libs/core-device/feature/src/controllers/core-device.controller.ts @@ -4,7 +4,7 @@ */ import { IpcEvent } from "Core/core/decorators" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Result, ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" import { DeviceInfo } from "Core/device/types/mudita-os" @@ -24,7 +24,7 @@ export interface DeviceConfiguration { export class CoreDeviceController { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private deviceCacheConfigurationService: DeviceCacheConfigurationService ) {} @@ -38,7 +38,7 @@ export class CoreDeviceController { return Result.success(deviceConfigurationCached) } - const result = await this.deviceProtocolService.request(id, { + const result = await this.deviceProtocol.request(id, { endpoint: Endpoint.DeviceInfo, method: Method.Get, options: { diff --git a/libs/core-device/feature/src/core-device.module.ts b/libs/core-device/feature/src/core-device.module.ts index 19cf84d3d8..69cad99ca6 100644 --- a/libs/core-device/feature/src/core-device.module.ts +++ b/libs/core-device/feature/src/core-device.module.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { DeviceCacheConfigurationService } from "./services" import { CoreDeviceController } from "./controllers" @@ -12,11 +12,11 @@ export class CoreDeviceModule { public controllers constructor( - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public fileSystem: FileSystemService ) { const deviceManagerController = new CoreDeviceController( - this.deviceProtocolService, + this.deviceProtocol, new DeviceCacheConfigurationService(this.fileSystem) ) diff --git a/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts b/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts index 7457c37fa5..006b6c2a76 100644 --- a/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts +++ b/libs/core/analytic-data-tracker/analytic-data-tracker.module.ts @@ -5,7 +5,7 @@ import { EventEmitter } from "events" import { MainProcessIpc } from "electron-better-ipc" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { BaseModule } from "Core/core/module" import { IndexStorage } from "Core/index-storage/types" import { MetadataStore } from "Core/metadata" @@ -20,7 +20,7 @@ const siteId = Number(process.env.ANALYTICS_API_SITE_ID) export class AnalyticDataTrackerModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -29,7 +29,7 @@ export class AnalyticDataTrackerModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, diff --git a/libs/core/backup/backup.module.ts b/libs/core/backup/backup.module.ts index aaa996fef6..75a723a378 100644 --- a/libs/core/backup/backup.module.ts +++ b/libs/core/backup/backup.module.ts @@ -17,7 +17,7 @@ import { LoadBackupService, } from "Core/backup/services" import { BackupController } from "Core/backup/controllers" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { FileManagerService } from "Core/files-manager/services" import { FileDeleteCommand } from "Core/device-file-system/commands/file-delete.command" import { @@ -29,7 +29,7 @@ import { DeviceInfoService } from "Core/device-info/services" export class BackupModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -38,7 +38,7 @@ export class BackupModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -46,32 +46,30 @@ export class BackupModule extends BaseModule { fileSystem ) - const deviceFileSystem = new DeviceFileSystemService( - this.deviceProtocolService - ) + const deviceFileSystem = new DeviceFileSystemService(this.deviceProtocol) const fileManagerService = new FileManagerService( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileDeleteCommand(this.deviceProtocolService), + new FileDeleteCommand(this.deviceProtocol), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new RetrieveFilesCommand(this.deviceProtocolService), + new RetrieveFilesCommand(this.deviceProtocol), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileUploadCommand(this.deviceProtocolService, this.fileSystem) + new FileUploadCommand(this.deviceProtocol, this.fileSystem) ) - const deviceInfoService = new DeviceInfoService(this.deviceProtocolService) + const deviceInfoService = new DeviceInfoService(this.deviceProtocol) const backupCreateService = new BackupCreateService( - this.deviceProtocolService, + this.deviceProtocol, deviceFileSystem, fileManagerService, deviceInfoService, this.keyStorage ) const backupRestoreService = new BackupRestoreService( - this.deviceProtocolService, + this.deviceProtocol, deviceFileSystem, deviceInfoService, fileSystem diff --git a/libs/core/backup/services/backup-create.service.test.ts b/libs/core/backup/services/backup-create.service.test.ts index 4a80838277..680f45af28 100644 --- a/libs/core/backup/services/backup-create.service.test.ts +++ b/libs/core/backup/services/backup-create.service.test.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Endpoint, Method } from "core-device/models" import { BackupCategory, PhoneLockCategory } from "Core/device" import { Result } from "Core/core/builder" @@ -25,11 +25,11 @@ const updaterStatusSuccessMock: UpdaterStatus = { successful: true, } -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const deviceFileSystemAdapter = { downloadDeviceFilesLocally: jest.fn(), @@ -50,7 +50,7 @@ const deviceInfoService = { } as unknown as DeviceInfoService const subject = new BackupCreateService( - deviceProtocolService, + deviceProtocol, deviceFileSystemAdapter, fileManagerService, deviceInfoService, @@ -63,7 +63,7 @@ beforeEach(() => { describe("Backup process happy path", () => { test("Returns the `Result.success` object with backup data", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -114,14 +114,14 @@ describe("Backup process happy path", () => { expect(result).toEqual(Result.success(["/user/backup/backup.tar"])) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(1, { + expect(deviceProtocol.device.request).toHaveBeenNthCalledWith(1, { endpoint: Endpoint.Backup, method: Method.Post, body: { category: BackupCategory.Backup }, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(2, { + expect(deviceProtocol.device.request).toHaveBeenNthCalledWith(2, { endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -194,7 +194,7 @@ describe("Backup process failed path", () => { }) test("Returns the `Result.failed` with `BackupError.CannotReachBackupLocation` if `DeviceInfo` endpoint return error status", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(Result.failed(new AppError("", ""))) deviceInfoService.getDeviceInfo = jest.fn().mockResolvedValue( @@ -226,7 +226,7 @@ describe("Backup process failed path", () => { }) test("Returns the `Result.failed` with `BackupError.CannotReachBackupLocation` if `Backup` endpoint return error status", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(Result.failed(new AppError("", ""))) deviceInfoService.getDeviceInfo = jest.fn().mockResolvedValue( @@ -259,7 +259,7 @@ describe("Backup process failed path", () => { }) test("Returns the `Result.failed` with `BackupError.BackupProcessFailed` if `deviceFileSystem.downloadFile` returns error status", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -312,7 +312,7 @@ describe("Backup process failed path", () => { }, 10000) test("Returns the `Result.failed` with `BackupError.BackupDownloadFailed` if `deviceFileSystem.downloadDeviceFilesLocally` returns error status", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( diff --git a/libs/core/backup/services/backup-create.service.ts b/libs/core/backup/services/backup-create.service.ts index 78d824a85a..27a5388f5a 100644 --- a/libs/core/backup/services/backup-create.service.ts +++ b/libs/core/backup/services/backup-create.service.ts @@ -4,7 +4,7 @@ */ import { Endpoint, Method } from "core-device/models" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { BackupCategory } from "Core/device/constants" import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" @@ -19,13 +19,13 @@ import { DeviceInfoService } from "Core/device-info/services" export class BackupCreateService extends BaseBackupService { constructor( - protected deviceProtocolService: DeviceProtocolService, + protected deviceProtocol: DeviceProtocol, protected deviceFileSystem: DeviceFileSystemService, protected fileManagerService: FileManagerService, protected deviceInfoService: DeviceInfoService, private keyStorage: MetadataStore ) { - super(deviceProtocolService, deviceFileSystem, deviceInfoService) + super(deviceProtocol, deviceFileSystem, deviceInfoService) } public async createBackup( @@ -109,7 +109,7 @@ export class BackupCreateService extends BaseBackupService { ) } - const backupResponse = await this.deviceProtocolService.device.request({ + const backupResponse = await this.deviceProtocol.device.request({ endpoint: Endpoint.Backup, method: Method.Post, body: { diff --git a/libs/core/backup/services/backup-restore.service.test.ts b/libs/core/backup/services/backup-restore.service.test.ts index fa3f5151be..aedd2b3297 100644 --- a/libs/core/backup/services/backup-restore.service.test.ts +++ b/libs/core/backup/services/backup-restore.service.test.ts @@ -6,7 +6,7 @@ import fs from "fs" import path from "path" import { Endpoint, Method } from "core-device/models" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { BackupRestoreService } from "Core/backup/services/backup-restore.service" @@ -61,11 +61,11 @@ const updaterStatusSuccessForAnotherOperationMock: UpdaterStatus = { successful: true, } -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const deviceFileSystemAdapter = { uploadFile: jest.fn(), @@ -84,7 +84,7 @@ const deviceInfoService = { } as unknown as DeviceInfoService const subject = new BackupRestoreService( - deviceProtocolService, + deviceProtocol, deviceFileSystemAdapter, deviceInfoService, fileSystemServiceMock @@ -111,7 +111,7 @@ describe("Restore process happy path", () => { .mockResolvedValueOnce( Result.success(JSON.stringify(updaterStatusSuccessMock)) ) - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -162,14 +162,14 @@ describe("Restore process happy path", () => { }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(1, { + expect(deviceProtocol.device.request).toHaveBeenNthCalledWith(1, { endpoint: Endpoint.Restore, method: Method.Post, body: { restore: "fileBase.tar" }, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(2, { + expect(deviceProtocol.device.request).toHaveBeenNthCalledWith(2, { endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -263,7 +263,7 @@ describe("Backup restoring failed path", () => { deviceFileSystemAdapter.uploadFile = jest .fn() .mockResolvedValueOnce(Result.success(true)) - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -275,7 +275,7 @@ describe("Backup restoring failed path", () => { return Result.failed(new AppError("", "")) }) - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(Result.failed(new AppError("", ""))) deviceInfoService.getDeviceInfo = jest.fn().mockResolvedValue( @@ -310,7 +310,7 @@ describe("Backup restoring failed path", () => { deviceFileSystemAdapter.downloadFile = jest .fn() .mockResolvedValueOnce(Result.failed(new AppError("", ""))) - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -371,7 +371,7 @@ describe("Backup restoring failed path", () => { JSON.stringify(updaterStatusSuccessForAnotherOperationMock) ) ) - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( @@ -430,7 +430,7 @@ describe("Backup restoring failed path", () => { .mockResolvedValueOnce( Result.success(JSON.stringify(updaterStatusFailedMock)) ) - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation((config: { endpoint: Endpoint; method: Method }) => { if ( diff --git a/libs/core/backup/services/backup-restore.service.ts b/libs/core/backup/services/backup-restore.service.ts index 7251e19eac..5c3711d5f6 100644 --- a/libs/core/backup/services/backup-restore.service.ts +++ b/libs/core/backup/services/backup-restore.service.ts @@ -10,19 +10,19 @@ import CryptoFileService from "Core/file-system/services/crypto-file-service/cry import { RestoreDeviceBackup } from "Core/backup/types" import { BackupError, Operation } from "Core/backup/constants" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { BaseBackupService } from "Core/backup/services/base-backup.service" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { DeviceInfoService } from "Core/device-info/services" export class BackupRestoreService extends BaseBackupService { constructor( - protected deviceProtocolService: DeviceProtocolService, + protected deviceProtocol: DeviceProtocol, protected deviceFileSystem: DeviceFileSystemService, protected deviceInfoService: DeviceInfoService, private fileSystem: FileSystemService ) { - super(deviceProtocolService, deviceFileSystem, deviceInfoService) + super(deviceProtocol, deviceFileSystem, deviceInfoService) } public async restoreBackup({ @@ -74,7 +74,7 @@ export class BackupRestoreService extends BaseBackupService { ) } - const restoreResult = await this.deviceProtocolService.device.request({ + const restoreResult = await this.deviceProtocol.device.request({ endpoint: Endpoint.Restore, method: Method.Post, body: { diff --git a/libs/core/backup/services/base-backup.service.ts b/libs/core/backup/services/base-backup.service.ts index 2f6a62c9ee..c8f862728c 100644 --- a/libs/core/backup/services/base-backup.service.ts +++ b/libs/core/backup/services/base-backup.service.ts @@ -9,7 +9,7 @@ import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import { Operation, BackupError } from "Core/backup/constants" import { UpdaterStatus } from "Core/backup/dto" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceFileSystemService } from "Core/device-file-system/services" import { DeviceInfoService } from "Core/device-info/services" @@ -18,7 +18,7 @@ export class BaseBackupService { private REQUEST_TIME_OUT = 5000 constructor( - protected deviceProtocolService: DeviceProtocolService, + protected deviceProtocol: DeviceProtocol, protected deviceFileSystem: DeviceFileSystemService, protected deviceInfoService: DeviceInfoService ) {} @@ -127,7 +127,7 @@ export class BaseBackupService { return false } - const response = await this.deviceProtocolService.device.request({ + const response = await this.deviceProtocol.device.request({ endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, diff --git a/libs/core/backup/services/sync-backup-create.service.ts b/libs/core/backup/services/sync-backup-create.service.ts index 09eeebfd17..bf69389bbc 100644 --- a/libs/core/backup/services/sync-backup-create.service.ts +++ b/libs/core/backup/services/sync-backup-create.service.ts @@ -8,7 +8,7 @@ import { AppError } from "Core/core/errors" import { BackupError } from "Core/backup/constants" import { MetadataStore, MetadataKey } from "Core/metadata" import { TokenOptions } from "Core/file-system/services/crypto-file-service/crypto-file-service" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceFileSystemService } from "Core/device-file-system/services" import { Endpoint, Method } from "core-device/models" import { BackupCategory, BackupState } from "Core/device" @@ -27,14 +27,14 @@ export interface createSyncBackupOptions export class SyncBackupCreateService { constructor( - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public deviceFileSystem: DeviceFileSystemService, private keyStorage: MetadataStore ) {} public async createSyncBackup( options: createSyncBackupOptions, - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { if (this.keyStorage.getValue(MetadataKey.BackupInProgress)) { return Result.failed( @@ -81,9 +81,9 @@ export class SyncBackupCreateService { } private async runDeviceSyncBackup( - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { - const deviceResponse = await this.deviceProtocolService.request( + const deviceResponse = await this.deviceProtocol.request( deviceId, { endpoint: Endpoint.DeviceInfo, @@ -101,7 +101,7 @@ export class SyncBackupCreateService { } // id field as backup response is a deprecated field after Pure_1.6.0 & Harmony_1.9.0 (UDM releases) - const backupResponse = await this.deviceProtocolService.request<{ + const backupResponse = await this.deviceProtocol.request<{ id?: string }>(deviceId, { endpoint: Endpoint.Backup, @@ -151,7 +151,7 @@ export class SyncBackupCreateService { private async waitUntilBackupDeviceFinished( id: string, iteration = 0, - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { try { const result = await this.getBackupDeviceStatus( @@ -181,9 +181,9 @@ export class SyncBackupCreateService { public async getBackupDeviceStatus( config: GetBackupDeviceStatusRequestConfigBody, - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { - return await this.deviceProtocolService.request(deviceId, { + return await this.deviceProtocol.request(deviceId, { endpoint: Endpoint.Backup, method: Method.Get, body: { diff --git a/libs/core/contacts/contact.module.ts b/libs/core/contacts/contact.module.ts index 73f5366529..b40eaaf173 100644 --- a/libs/core/contacts/contact.module.ts +++ b/libs/core/contacts/contact.module.ts @@ -14,12 +14,12 @@ import { ContactModel } from "Core/contacts/models" import { ContactController } from "Core/contacts/controllers" import { ContactService } from "Core/contacts/services" import { ContactRepository } from "Core/contacts/repositories" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class ContactModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -28,7 +28,7 @@ export class ContactModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -39,7 +39,7 @@ export class ContactModule extends BaseModule { const contactRepository = new ContactRepository(contactModel) const contactService = new ContactService( contactRepository, - this.deviceProtocolService + this.deviceProtocol ) const contactController = new ContactController(contactService) diff --git a/libs/core/contacts/services/contact.service.test.ts b/libs/core/contacts/services/contact.service.test.ts index 0464f509aa..280145de17 100644 --- a/libs/core/contacts/services/contact.service.test.ts +++ b/libs/core/contacts/services/contact.service.test.ts @@ -8,7 +8,7 @@ import { AppError } from "Core/core/errors" import { DeviceCommunicationError } from "core-device/models" import { ContactService } from "Core/contacts/services/contact.service" import { ContactRepository } from "Core/contacts/repositories" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { Contact as PureContact } from "Core/device/types/mudita-os" import { Contact } from "Core/contacts/reducers" @@ -19,13 +19,13 @@ const contactRepository = { delete: jest.fn(), } as unknown as ContactRepository -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol -const subject = new ContactService(contactRepository, deviceProtocolService) +const subject = new ContactService(contactRepository, deviceProtocol) const pureContact: PureContact = { id: 19, @@ -63,63 +63,59 @@ beforeEach(() => { describe("`ContactService`", () => { describe("`getContact` method", () => { test("map data and returns success when `device.request` returns success", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(pureContact)) const response = await subject.getContact("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) expect(response.data).toEqual(contact) }) test("returns error when `device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.getContact("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`getContacts` method", () => { test("map data and returns success when `device.request` returns success", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success({ entries: [pureContact] })) const response = await subject.getContacts() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) expect(response.data).toEqual([contact]) }) test("returns error when `device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.getContacts() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`createContact` method", () => { test("returns success and `repository.create` is called when `device.request` returns success", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success({ id: pureContact.id })) const response = await subject.createContact(contact) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.create).toHaveBeenCalled() @@ -128,13 +124,11 @@ describe("`ContactService`", () => { }) test("returns error when `device.request` returns error`", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.createContact(contact) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.create).not.toHaveBeenCalled() @@ -144,7 +138,7 @@ describe("`ContactService`", () => { describe("`editContact` method", () => { test("returns success and `repository.update` is called when `device.request` and `isContactValid` returns success", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(pureContact)) @@ -177,14 +171,12 @@ describe("`ContactService`", () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any .spyOn(subject as unknown as { isContactValid: any }, "isContactValid") .mockImplementation(() => successResponse) - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.editContact(contact) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.update).not.toHaveBeenCalled() @@ -194,14 +186,12 @@ describe("`ContactService`", () => { describe("`deleteContacts` method", () => { test("returns success and `repository.delete` is called when `device.request` returns success", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(successResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(successResponse) const response = await subject.deleteContacts(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.delete).toHaveBeenCalled() @@ -209,14 +199,12 @@ describe("`ContactService`", () => { }) test("returns error with ids when `device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.deleteContacts(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method expect(contactRepository.delete).not.toHaveBeenCalled() diff --git a/libs/core/contacts/services/contact.service.ts b/libs/core/contacts/services/contact.service.ts index ee438d386d..ed68ade0df 100644 --- a/libs/core/contacts/services/contact.service.ts +++ b/libs/core/contacts/services/contact.service.ts @@ -10,7 +10,7 @@ import { CreateContactResponseBody, CreateContactErrorResponseBody, } from "Core/device/types/mudita-os" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Contact, ContactID } from "Core/contacts/reducers" import { ContactRepository } from "Core/contacts/repositories" import { ContactPresenter } from "Core/contacts/presenters" @@ -23,12 +23,12 @@ import { ResultObject } from "Core/core/builder" export class ContactService { constructor( private contactRepository: ContactRepository, - private deviceProtocolService: DeviceProtocolService + private deviceProtocol: DeviceProtocol ) {} public async getContact(id: string): Promise> { const response = - await this.deviceProtocolService.device.request({ + await this.deviceProtocol.device.request({ endpoint: Endpoint.Contacts, method: Method.Get, body: { @@ -51,7 +51,7 @@ export class ContactService { public async getContacts(): Promise> { const response = - await this.deviceProtocolService.device.request({ + await this.deviceProtocol.device.request({ endpoint: Endpoint.Contacts, method: Method.Get, }) @@ -90,16 +90,14 @@ export class ContactService { //workaround const result = - await this.deviceProtocolService.device.request( - { - endpoint: Endpoint.Contacts, - method: Method.Post, - body: ContactPresenter.mapToPureContact(newContact), - options: { - connectionTimeOut: 5000, - }, - } - ) + await this.deviceProtocol.device.request({ + endpoint: Endpoint.Contacts, + method: Method.Post, + body: ContactPresenter.mapToPureContact(newContact), + options: { + connectionTimeOut: 5000, + }, + }) if (this.isInternalServerError(result)) { return { @@ -162,7 +160,7 @@ export class ContactService { return isContactValidResponse } - const result = await this.deviceProtocolService.device.request({ + const result = await this.deviceProtocol.device.request({ endpoint: Endpoint.Contacts, method: Method.Put, body: ContactPresenter.mapToPureContact(contact), @@ -222,7 +220,7 @@ export class ContactService { const successIds = [] for (const id of contactIds) { - const result = await this.deviceProtocolService.device.request({ + const result = await this.deviceProtocol.device.request({ endpoint: Endpoint.Contacts, method: Method.Delete, body: { id: Number(id) }, diff --git a/libs/core/core/application.module.ts b/libs/core/core/application.module.ts index 8dfb5c4c93..9e7f5908b4 100644 --- a/libs/core/core/application.module.ts +++ b/libs/core/core/application.module.ts @@ -41,7 +41,7 @@ import { DeviceLogModule } from "Core/device-log/device-log.module" import { DeviceModule } from "Core/device/device.module" import { DeviceProtocolModule, - DeviceProtocolService, + DeviceProtocol, DeviceResolverService, } from "device-protocol/feature" import { APIModule } from "device/feature" @@ -95,7 +95,7 @@ export class ApplicationModule { private apiModule: APIModule - private deviceProtocolService = new DeviceProtocolService( + private deviceProtocol = new DeviceProtocol( mockServiceEnabled ? new MockDeviceResolverService() : new DeviceResolverService(), @@ -119,7 +119,7 @@ export class ApplicationModule { this.modules.forEach(this.initModule) this.apiModule = new APIModule( - this.deviceProtocolService, + this.deviceProtocol, this.systemUtilsModule, createSettingsService() ) @@ -133,14 +133,13 @@ export class ApplicationModule { ) this.controllerInitializer.initialize(new OnlineStatusModule().controllers) this.controllerInitializer.initialize( - new CoreDeviceModule(this.deviceProtocolService, this.fileSystem) - .controllers + new CoreDeviceModule(this.deviceProtocol, this.fileSystem).controllers ) this.controllerInitializer.initialize( - new DeviceManagerModule(this.deviceProtocolService).controllers + new DeviceManagerModule(this.deviceProtocol).controllers ) this.controllerInitializer.initialize( - new ActiveDeviceRegistryModule(this.deviceProtocolService).controllers + new ActiveDeviceRegistryModule(this.deviceProtocol).controllers ) } @@ -151,7 +150,7 @@ export class ApplicationModule { private initModule = (module: Module): void => { const instance = new module( this.index, - this.deviceProtocolService, + this.deviceProtocol, this.keyStorage, this.logger, this.ipc, diff --git a/libs/core/core/module/base.module.ts b/libs/core/core/module/base.module.ts index 74bb4ec1b1..a4c4feb6b4 100644 --- a/libs/core/core/module/base.module.ts +++ b/libs/core/core/module/base.module.ts @@ -9,7 +9,7 @@ import { MetadataStore } from "Core/metadata/services" import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { IndexStorage } from "Core/index-storage/types" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Controller, Model, @@ -27,7 +27,7 @@ export class BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/core/types/module.type.ts b/libs/core/core/types/module.type.ts index 9b1562aee1..3b1f821aa8 100644 --- a/libs/core/core/types/module.type.ts +++ b/libs/core/core/types/module.type.ts @@ -15,13 +15,13 @@ import { Model } from "./model.type" import { Repository } from "./repository.type" import { Observer } from "./observer.type" import { Initializer } from "./initializer.type" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export interface Module { // eslint-disable-next-line @typescript-eslint/no-misused-new new ( index: IndexStorage, - deviceProtocolService: DeviceProtocolService, + deviceProtocol: DeviceProtocol, keyStorage: MetadataStore, logger: AppLogger, ipc: MainProcessIpc, diff --git a/libs/core/crash-dump/crash-dump.module.ts b/libs/core/crash-dump/crash-dump.module.ts index fcdbd7f3a9..9326484a40 100644 --- a/libs/core/crash-dump/crash-dump.module.ts +++ b/libs/core/crash-dump/crash-dump.module.ts @@ -14,7 +14,7 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { CrashDumpController } from "Core/crash-dump/controllers" import { CrashDumpService } from "Core/crash-dump/services" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class CrashDumpModule extends BaseModule { private crashDumpController: CrashDumpController @@ -22,7 +22,7 @@ export class CrashDumpModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -31,7 +31,7 @@ export class CrashDumpModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -46,8 +46,8 @@ export class CrashDumpModule extends BaseModule { } this.crashDumpService = new CrashDumpService( - this.deviceProtocolService, - new DeviceFileSystemService(this.deviceProtocolService) + this.deviceProtocol, + new DeviceFileSystemService(this.deviceProtocol) ) this.crashDumpController = new CrashDumpController( this.crashDumpService, diff --git a/libs/core/crash-dump/services/crash-dump.service.test.ts b/libs/core/crash-dump/services/crash-dump.service.test.ts index cbe33841b2..78591f2a8a 100644 --- a/libs/core/crash-dump/services/crash-dump.service.test.ts +++ b/libs/core/crash-dump/services/crash-dump.service.test.ts @@ -6,25 +6,22 @@ import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { DeviceCommunicationError } from "core-device/models" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { CrashDumpService } from "Core/crash-dump/services/crash-dump.service" import { DeviceFileSystemService } from "Core/device-file-system/services" import { RequestResponseStatus } from "Core/core/types/request-response.interface" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const deviceFileSystemMock = { downloadDeviceFilesLocally: jest.fn(), } as unknown as DeviceFileSystemService -const subject = new CrashDumpService( - deviceProtocolService, - deviceFileSystemMock -) +const subject = new CrashDumpService(deviceProtocol, deviceFileSystemMock) afterEach(() => { jest.resetAllMocks() @@ -32,7 +29,7 @@ afterEach(() => { describe("Method: getDeviceCrashDumpFiles", () => { test("returns list of files if `Endpoint.DeviceInfo` endpoint returns `success` and list of files", async () => { - deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( + deviceProtocol.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -40,35 +37,35 @@ describe("Method: getDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect(await subject.getDeviceCrashDumpFiles()).toEqual({ data: ["/sys/crash_dumps/crashdump.hex"], status: RequestResponseStatus.Ok, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() }) test("returns empty list of files if if data key isn't exists", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValueOnce(Result.success(undefined)) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect(await subject.getDeviceCrashDumpFiles()).toEqual({ data: [], status: RequestResponseStatus.Ok, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() }) test("returns an `Error` status if status isn't equal to `Ok`", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValueOnce( Result.failed( @@ -81,19 +78,19 @@ describe("Method: getDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect(await subject.getDeviceCrashDumpFiles()).toEqual({ status: RequestResponseStatus.Error, }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() }) }) describe("Method: downloadDeviceCrashDumpFiles", () => { test("returns local files urls if `downloadDeviceFilesLocally` returns `success` status and files list exists", async () => { - deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( + deviceProtocol.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -106,7 +103,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -120,7 +117,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -131,7 +128,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `success` status if `getDeviceFiles` returns empty data", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValueOnce(Result.success(undefined)) ;( @@ -140,7 +137,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -154,7 +151,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -163,13 +160,13 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `Error` status if `getDeviceFiles` returns `Error` status", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValueOnce(Result.failed({} as AppError)) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -182,7 +179,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -191,7 +188,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `Error` status if `downloadDeviceFilesLocally` returns empty data", async () => { - deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( + deviceProtocol.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -205,7 +202,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -218,7 +215,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -229,7 +226,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { }) test("returns an `Error` status if `downloadDeviceFilesLocally` returns `Error` status", async () => { - deviceProtocolService.device.request = jest.fn().mockReturnValueOnce( + deviceProtocol.device.request = jest.fn().mockReturnValueOnce( Result.success({ files: ["/sys/crash_dumps/crashdump.hex"], }) @@ -242,7 +239,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method @@ -255,7 +252,7 @@ describe("Method: downloadDeviceCrashDumpFiles", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method diff --git a/libs/core/crash-dump/services/crash-dump.service.ts b/libs/core/crash-dump/services/crash-dump.service.ts index fe587c98c1..b1727d25bd 100644 --- a/libs/core/crash-dump/services/crash-dump.service.ts +++ b/libs/core/crash-dump/services/crash-dump.service.ts @@ -14,11 +14,11 @@ import { RequestResponse, RequestResponseStatus, } from "Core/core/types/request-response.interface" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class CrashDumpService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private deviceFileSystem: DeviceFileSystemService ) {} @@ -87,12 +87,10 @@ export class CrashDumpService { public async getDiagnosticFileList( fileList: DiagnosticsFileList ): Promise> { - return this.deviceProtocolService.device.request( - { - endpoint: Endpoint.DeviceInfo, - method: Method.Get, - body: { fileList }, - } - ) + return this.deviceProtocol.device.request({ + endpoint: Endpoint.DeviceInfo, + method: Method.Get, + body: { fileList }, + }) } } diff --git a/libs/core/data-sync/data-sync.module.ts b/libs/core/data-sync/data-sync.module.ts index 173a830673..71a81a6e0e 100644 --- a/libs/core/data-sync/data-sync.module.ts +++ b/libs/core/data-sync/data-sync.module.ts @@ -12,7 +12,7 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DataSyncService } from "Core/data-sync/services/data-sync.service" import { DataSyncController } from "Core/data-sync/controllers" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class DataSyncModule extends BaseModule { private dataSyncService: DataSyncService @@ -20,7 +20,7 @@ export class DataSyncModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -29,7 +29,7 @@ export class DataSyncModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -39,7 +39,7 @@ export class DataSyncModule extends BaseModule { this.dataSyncService = new DataSyncService( this.index, - this.deviceProtocolService, + this.deviceProtocol, this.keyStorage, this.fileSystem ) diff --git a/libs/core/data-sync/services/data-sync.service.ts b/libs/core/data-sync/services/data-sync.service.ts index e3c92ec4ad..d3008cca10 100644 --- a/libs/core/data-sync/services/data-sync.service.ts +++ b/libs/core/data-sync/services/data-sync.service.ts @@ -8,7 +8,7 @@ import { DeviceFileSystemService } from "Core/device-file-system/services" import getAppPath from "Core/__deprecated__/main/utils/get-app-path" import { IndexStorage } from "Core/index-storage/types" import { DataIndex } from "Core/index-storage/constants" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { MetadataStore } from "Core/metadata/services" import { ContactIndexer, @@ -35,13 +35,13 @@ export class DataSyncService { constructor( private index: IndexStorage, - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private keyStorage: MetadataStore, private fileSystemStorage: FileSystemService ) { this.syncBackupCreateService = new SyncBackupCreateService( - this.deviceProtocolService, - new DeviceFileSystemService(this.deviceProtocolService), + this.deviceProtocol, + new DeviceFileSystemService(this.deviceProtocol), this.keyStorage ) diff --git a/libs/core/desktop/desktop.module.ts b/libs/core/desktop/desktop.module.ts index a8e17a3f23..a03b0c98a9 100644 --- a/libs/core/desktop/desktop.module.ts +++ b/libs/core/desktop/desktop.module.ts @@ -10,14 +10,14 @@ import { FileSystemService } from "Core/file-system/services/file-system.service import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DesktopController } from "Core/desktop/desktop.controller" import { DesktopService } from "Core/desktop/desktop.service" export class DesktopModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DesktopModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, diff --git a/libs/core/device-file-system/commands/base.command.ts b/libs/core/device-file-system/commands/base.command.ts index 310588b62b..f2b0fb0b15 100644 --- a/libs/core/device-file-system/commands/base.command.ts +++ b/libs/core/device-file-system/commands/base.command.ts @@ -4,10 +4,10 @@ */ import * as CRC32 from "crc-32" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export abstract class BaseCommand { - constructor(public deviceProtocolService: DeviceProtocolService) {} + constructor(public deviceProtocol: DeviceProtocol) {} public countCRC32(buffer: Buffer | Uint8Array): string { const crc = CRC32.buf(buffer) diff --git a/libs/core/device-file-system/commands/file-delete.command.test.ts b/libs/core/device-file-system/commands/file-delete.command.test.ts index 478587315a..4053a43bda 100644 --- a/libs/core/device-file-system/commands/file-delete.command.test.ts +++ b/libs/core/device-file-system/commands/file-delete.command.test.ts @@ -4,19 +4,19 @@ */ import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { AppError } from "Core/core/errors" import { Result, ResultObject, SuccessResult } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { FileDeleteCommand } from "Core/device-file-system/commands/file-delete.command" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol -const subject = new FileDeleteCommand(deviceProtocolService) +const subject = new FileDeleteCommand(deviceProtocol) const successResponse: ResultObject = Result.success(undefined) @@ -37,7 +37,7 @@ beforeEach(() => { describe("`FileDeleteCommand`", () => { describe("when `DeviceManager.device.request` returns success response", () => { beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(successResponse) }) @@ -47,7 +47,7 @@ describe("`FileDeleteCommand`", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Delete, body: { @@ -60,7 +60,7 @@ describe("`FileDeleteCommand`", () => { describe("when `DeviceManager.device.request` returns failed response", () => { beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(failedResponse) }) @@ -70,7 +70,7 @@ describe("`FileDeleteCommand`", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Delete, body: { diff --git a/libs/core/device-file-system/commands/file-delete.command.ts b/libs/core/device-file-system/commands/file-delete.command.ts index ec9bb58a1c..7f4af75284 100644 --- a/libs/core/device-file-system/commands/file-delete.command.ts +++ b/libs/core/device-file-system/commands/file-delete.command.ts @@ -14,15 +14,13 @@ import { DeviceFileSystemError } from "Core/device-file-system/constants" export class FileDeleteCommand extends BaseCommand { public async exec(path: string): Promise> { const { ok, error } = - await this.deviceProtocolService.device.request( - { - endpoint: Endpoint.FileSystem, - method: Method.Delete, - body: { - removeFile: path, - }, - } - ) + await this.deviceProtocol.device.request({ + endpoint: Endpoint.FileSystem, + method: Method.Delete, + body: { + removeFile: path, + }, + }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access diff --git a/libs/core/device-file-system/commands/file-upload.command.test.ts b/libs/core/device-file-system/commands/file-upload.command.test.ts index 12e0021f35..cb31963d20 100644 --- a/libs/core/device-file-system/commands/file-upload.command.test.ts +++ b/libs/core/device-file-system/commands/file-upload.command.test.ts @@ -8,25 +8,25 @@ import path from "path" import mock from "mock-fs" import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { FileUploadCommand } from "Core/device-file-system/commands/file-upload.command" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { DeviceFileSystemError } from "Core/device-file-system/constants" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const fileSystemService = { readFile: jest.fn(), getFileSize: jest.fn(), } as unknown as FileSystemService -const subject = new FileUploadCommand(deviceProtocolService, fileSystemService) +const subject = new FileUploadCommand(deviceProtocol, fileSystemService) const successResponse: ResultObject<{ txID: string @@ -88,7 +88,7 @@ describe("When requested file is unreadable", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).not.toHaveBeenCalled() + expect(deviceProtocol.device.request).not.toHaveBeenCalled() expect(result).toEqual( Result.failed( new AppError( @@ -130,7 +130,7 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(successResponse) }) @@ -143,7 +143,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -169,7 +169,7 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(failedResponse) }) @@ -182,7 +182,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -215,7 +215,7 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockImplementation(({ body }) => { // AUTO DISABLED - fix me if you like :) @@ -238,7 +238,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -271,7 +271,7 @@ describe("When requested file is valid", () => { mock.restore() }) beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(failedResponseWithInsufficientStorage) }) @@ -284,7 +284,7 @@ describe("When requested file is valid", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { diff --git a/libs/core/device-file-system/commands/file-upload.command.ts b/libs/core/device-file-system/commands/file-upload.command.ts index 0977f996fd..a4cf81a7a1 100644 --- a/libs/core/device-file-system/commands/file-upload.command.ts +++ b/libs/core/device-file-system/commands/file-upload.command.ts @@ -6,7 +6,7 @@ import path from "path" import { Endpoint, Method } from "core-device/models" import { PutFileSystemResponseBody } from "Core/device/types/mudita-os" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { FileSystemService } from "Core/file-system/services/file-system.service.refactored" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" @@ -16,10 +16,10 @@ import { DeviceFileSystemError } from "Core/device-file-system/constants" export class FileUploadCommand extends BaseCommand { constructor( - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public fileSystemService: FileSystemService ) { - super(deviceProtocolService) + super(deviceProtocol) } public async exec( @@ -53,17 +53,15 @@ export class FileUploadCommand extends BaseCommand { const fileName = path.basename(filePath) const response = - await this.deviceProtocolService.device.request( - { - endpoint: Endpoint.FileSystem, - method: Method.Put, - body: { - fileSize, - fileCrc32, - fileName: [directory, fileName].join("/"), - }, - } - ) + await this.deviceProtocol.device.request({ + endpoint: Endpoint.FileSystem, + method: Method.Put, + body: { + fileSize, + fileCrc32, + fileName: [directory, fileName].join("/"), + }, + }) if (!response.ok || response.data === undefined) { if ( @@ -105,7 +103,7 @@ export class FileUploadCommand extends BaseCommand { const chunkedBufferSize = Buffer.byteLength(chunkedBuffer) const lastChunk = chunkedBufferSize < chunkSize - const response = await this.deviceProtocolService.device.request({ + const response = await this.deviceProtocol.device.request({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { diff --git a/libs/core/device-file-system/commands/retrieve-files.command.test.ts b/libs/core/device-file-system/commands/retrieve-files.command.test.ts index ca88cb5779..74d1bf35d4 100644 --- a/libs/core/device-file-system/commands/retrieve-files.command.test.ts +++ b/libs/core/device-file-system/commands/retrieve-files.command.test.ts @@ -5,19 +5,19 @@ import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { RetrieveFilesCommand } from "Core/device-file-system/commands/retrieve-files.command" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { AppError } from "Core/core/errors" import { Result, ResultObject } from "Core/core/builder" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { DeviceFileSystemError } from "Core/device-file-system/constants" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol -const subject = new RetrieveFilesCommand(deviceProtocolService) +const subject = new RetrieveFilesCommand(deviceProtocol) const responseData: Record = { ["/test/directory"]: [ @@ -46,7 +46,7 @@ beforeEach(() => { describe("When `DeviceManager.device.request` returns success response", () => { beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValueOnce(successResponse) }) @@ -56,7 +56,7 @@ describe("When `DeviceManager.device.request` returns success response", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Get, body: { @@ -69,7 +69,7 @@ describe("When `DeviceManager.device.request` returns success response", () => { describe("When `DeviceManager.device.request` returns failed response", () => { beforeEach(() => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValueOnce(failedResponse) }) @@ -79,7 +79,7 @@ describe("When `DeviceManager.device.request` returns failed response", () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.FileSystem, method: Method.Get, body: { diff --git a/libs/core/device-file-system/commands/retrieve-files.command.ts b/libs/core/device-file-system/commands/retrieve-files.command.ts index fc52ec3cb9..eb74f410e3 100644 --- a/libs/core/device-file-system/commands/retrieve-files.command.ts +++ b/libs/core/device-file-system/commands/retrieve-files.command.ts @@ -16,7 +16,7 @@ export class RetrieveFilesCommand extends BaseCommand { directory: string ): Promise | undefined>> { const result = - await this.deviceProtocolService.device.request( + await this.deviceProtocol.device.request( { endpoint: Endpoint.FileSystem, method: Method.Get, diff --git a/libs/core/device-file-system/device-file-system.module.ts b/libs/core/device-file-system/device-file-system.module.ts index e0a1c3ff41..b828514abf 100644 --- a/libs/core/device-file-system/device-file-system.module.ts +++ b/libs/core/device-file-system/device-file-system.module.ts @@ -12,12 +12,12 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DeviceFileSystemController } from "Core/device-file-system/controllers" import { DeviceFileSystemService } from "Core/device-file-system/services" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class DeviceFileSystemModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DeviceFileSystemModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -35,7 +35,7 @@ export class DeviceFileSystemModule extends BaseModule { ) const deviceFileSystemService = new DeviceFileSystemService( - this.deviceProtocolService + this.deviceProtocol ) const deviceFileSystemController = new DeviceFileSystemController( deviceFileSystemService diff --git a/libs/core/device-file-system/services/device-file-system.service.test.ts b/libs/core/device-file-system/services/device-file-system.service.test.ts index fc4e2e49a5..79ccf0ba10 100644 --- a/libs/core/device-file-system/services/device-file-system.service.test.ts +++ b/libs/core/device-file-system/services/device-file-system.service.test.ts @@ -7,7 +7,7 @@ import path from "path" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { DeviceCommunicationError } from "core-device/models" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DownloadFileSystemRequestConfig, GetFileSystemRequestConfig, @@ -22,21 +22,21 @@ import { } from "Root/jest/testing-support/mocks/diagnostic-data.mock" import { DeviceFileSystemService } from "Core/device-file-system/services/device-file-system.service" -const deviceProtocolService = { +const deviceProtocol = { request: jest.fn(), device: { id: "abc123", }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol -const deviceFileSystem = new DeviceFileSystemService(deviceProtocolService) +const deviceFileSystem = new DeviceFileSystemService(deviceProtocol) beforeEach(() => { jest.clearAllMocks() }) test("downloading file handle properly chunks data", async () => { - deviceProtocolService.request = jest + deviceProtocol.request = jest .fn() .mockImplementation( ( @@ -84,7 +84,7 @@ test("downloading file handle properly chunks data", async () => { }) test("downloading file handle properly chunks data if fileSize is less than chunkSize", async () => { - deviceProtocolService.request = jest + deviceProtocol.request = jest .fn() .mockImplementation( ( @@ -125,7 +125,7 @@ test("downloading file handle properly chunks data if fileSize is less than chun }) test("downloading file return error when part of the chunks data is broken", async () => { - deviceProtocolService.request = jest + deviceProtocol.request = jest .fn() .mockImplementation( ( @@ -169,7 +169,7 @@ test("downloading file return error when part of the chunks data is broken", asy }) test("downloading file returns error properly", async () => { - deviceProtocolService.request = jest.fn().mockImplementation(() => { + deviceProtocol.request = jest.fn().mockImplementation(() => { return Result.failed( new AppError( DeviceCommunicationError.RequestFailed, @@ -185,7 +185,7 @@ test("downloading file returns error properly", async () => { }) test("upload file file handle properly chunks data", async () => { - deviceProtocolService.request = jest + deviceProtocol.request = jest .fn() .mockImplementation( ( diff --git a/libs/core/device-file-system/services/device-file-system.service.ts b/libs/core/device-file-system/services/device-file-system.service.ts index b1fad9b97b..f72fedf7ef 100644 --- a/libs/core/device-file-system/services/device-file-system.service.ts +++ b/libs/core/device-file-system/services/device-file-system.service.ts @@ -9,7 +9,7 @@ import path from "path" import { AppError } from "Core/core/errors" import { ResultObject, Result } from "Core/core/builder" import { Endpoint, Method } from "core-device/models" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import logger from "Core/__deprecated__/main/utils/logger" import countCRC32 from "Core/device-file-system/helpers/count-crc32" import { FileSystemService } from "Core/file-system/services/file-system.service" @@ -27,12 +27,12 @@ import { } from "Core/device-file-system/dto" export class DeviceFileSystemService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} public async downloadDeviceFilesLocally( filePaths: string[], options: DownloadDeviceFileLocallyOptions, - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { const data: string[] = [] @@ -61,7 +61,7 @@ export class DeviceFileSystemService { public async downloadDeviceFiles( filePaths: string[], - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { const data: DeviceFile[] = [] for (let i = 0; i < filePaths.length; i++) { @@ -81,11 +81,11 @@ export class DeviceFileSystemService { public async downloadFile( filePath: string, - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { try { const { ok, data } = - await this.deviceProtocolService.request(deviceId, { + await this.deviceProtocol.request(deviceId, { endpoint: Endpoint.FileSystem, method: Method.Get, body: { @@ -157,17 +157,15 @@ export class DeviceFileSystemService { const fileSize = Buffer.byteLength(data) const fileCrc32 = countCRC32(data) const response = - await this.deviceProtocolService.device.request( - { - endpoint: Endpoint.FileSystem, - method: Method.Put, - body: { - fileSize, - fileCrc32, - fileName: targetPath, - }, - } - ) + await this.deviceProtocol.device.request({ + endpoint: Endpoint.FileSystem, + method: Method.Put, + body: { + fileSize, + fileCrc32, + fileName: targetPath, + }, + }) if (!response.ok || response.data === undefined) { return Result.failed( @@ -192,17 +190,15 @@ export class DeviceFileSystemService { const fileCrc32 = countCRC32(fileBuffer) const { ok, data } = - await this.deviceProtocolService.device.request( - { - endpoint: Endpoint.FileSystem, - method: Method.Put, - body: { - fileSize, - fileCrc32, - fileName: targetPath, - }, - } - ) + await this.deviceProtocol.device.request({ + endpoint: Endpoint.FileSystem, + method: Method.Put, + body: { + fileSize, + fileCrc32, + fileName: targetPath, + }, + }) if (!ok || data === undefined) { return Result.failed( @@ -233,7 +229,7 @@ export class DeviceFileSystemService { return Result.failed(new AppError("", "")) } - const { ok } = await this.deviceProtocolService.device.request({ + const { ok } = await this.deviceProtocol.device.request({ endpoint: Endpoint.FileSystem, method: Method.Delete, body: { @@ -251,7 +247,7 @@ export class DeviceFileSystemService { private async downloadDeviceFileLocally( filePath: string, options: DownloadDeviceFileLocallyOptions, - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { const { data: result, ok } = await this.downloadFile(filePath, deviceId) @@ -321,7 +317,7 @@ export class DeviceFileSystemService { const chunkedBufferSize = Buffer.byteLength(chunkedBuffer) const lastChunk = chunkedBufferSize < chunkSize - const response = await this.deviceProtocolService.device.request({ + const response = await this.deviceProtocol.device.request({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -372,7 +368,7 @@ export class DeviceFileSystemService { const lastChunk = nread < chunkSize const dataBuffer = lastChunk ? buffer.slice(0, nread) : buffer - const response = await this.deviceProtocolService.device.request({ + const response = await this.deviceProtocol.device.request({ endpoint: Endpoint.FileSystem, method: Method.Put, body: { @@ -408,10 +404,10 @@ export class DeviceFileSystemService { chunkLength: number, chunkNo = 1, chunkedString = "", - deviceId = this.deviceProtocolService.device.id + deviceId = this.deviceProtocol.device.id ): Promise> { const { ok, data } = - await this.deviceProtocolService.request( + await this.deviceProtocol.request( deviceId, { endpoint: Endpoint.FileSystem, diff --git a/libs/core/device-info/device-info.module.ts b/libs/core/device-info/device-info.module.ts index 76718a1905..abef8179a5 100644 --- a/libs/core/device-info/device-info.module.ts +++ b/libs/core/device-info/device-info.module.ts @@ -12,12 +12,12 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DeviceInfoService } from "Core/device-info/services" import { DeviceInfoController } from "Core/device-info/controllers" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class DeviceInfoModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DeviceInfoModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -34,7 +34,7 @@ export class DeviceInfoModule extends BaseModule { fileSystem ) - const deviceInfoService = new DeviceInfoService(this.deviceProtocolService) + const deviceInfoService = new DeviceInfoService(this.deviceProtocol) const deviceInfoController = new DeviceInfoController(deviceInfoService) this.controllers = [deviceInfoController] diff --git a/libs/core/device-info/services/device-info.service.ts b/libs/core/device-info/services/device-info.service.ts index 990a430f67..a4e687aac7 100644 --- a/libs/core/device-info/services/device-info.service.ts +++ b/libs/core/device-info/services/device-info.service.ts @@ -7,7 +7,7 @@ import { Result, ResultObject } from "Core/core/builder" import { AppError } from "Core/core/errors" import { DeviceInfo } from "Core/device-info/dto" import { DeviceInfoPresenter } from "Core/device-info/presenters" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Endpoint, Method, DeviceCommunicationError } from "core-device/models" import { DeviceInfo as DeviceInfoRaw, @@ -16,12 +16,12 @@ import { import { DeviceId } from "Core/device/constants/device-id" export class DeviceInfoService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} private async getDeviceInfoRequest( - deviceId: DeviceId = this.deviceProtocolService.device.id + deviceId: DeviceId = this.deviceProtocol.device.id ): Promise> { - return this.deviceProtocolService.request(deviceId, { + return this.deviceProtocol.request(deviceId, { endpoint: Endpoint.DeviceInfo, method: Method.Get, }) @@ -37,8 +37,8 @@ export class DeviceInfoService { return response } const device = deviceId - ? this.deviceProtocolService.getCoreDeviceById(deviceId) - : this.deviceProtocolService.device + ? this.deviceProtocol.getCoreDeviceById(deviceId) + : this.deviceProtocol.device if (!device) { return Result.failed(new AppError("", "")) diff --git a/libs/core/device-log/device-log.module.ts b/libs/core/device-log/device-log.module.ts index 1f8132c41f..2ecda83053 100644 --- a/libs/core/device-log/device-log.module.ts +++ b/libs/core/device-log/device-log.module.ts @@ -13,12 +13,12 @@ import { BaseModule } from "Core/core/module" import { DeviceFileSystemService } from "Core/device-file-system/services" import { DeviceLogService } from "Core/device-log/services" import { DeviceLogController } from "Core/device-log/controllers" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class DeviceLogModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -27,7 +27,7 @@ export class DeviceLogModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -36,8 +36,8 @@ export class DeviceLogModule extends BaseModule { ) const deviceLogService = new DeviceLogService( - this.deviceProtocolService, - new DeviceFileSystemService(this.deviceProtocolService) + this.deviceProtocol, + new DeviceFileSystemService(this.deviceProtocol) ) const deviceLogController = new DeviceLogController(deviceLogService) diff --git a/libs/core/device-log/services/device-log.service.test.ts b/libs/core/device-log/services/device-log.service.test.ts index 3eaa202d94..fab2b090e1 100644 --- a/libs/core/device-log/services/device-log.service.test.ts +++ b/libs/core/device-log/services/device-log.service.test.ts @@ -10,7 +10,7 @@ import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { GetDeviceFilesResponseBody } from "Core/device/types/mudita-os" import { DeviceLogService } from "Core/device-log/services/device-log.service" import { DeviceEnumError } from "Core/device-log/constants" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceFileSystemService } from "Core/device-file-system/services" import { RequestResponseStatus } from "Core/core/types/request-response.interface" import { @@ -18,20 +18,17 @@ import { secondsPartDecodeLog, } from "Root/jest/testing-support/mocks/diagnostic-data.mock" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const deviceFileSystemMock = { downloadDeviceFiles: jest.fn(), } as unknown as DeviceFileSystemService -const subject = new DeviceLogService( - deviceProtocolService, - deviceFileSystemMock -) +const subject = new DeviceLogService(deviceProtocol, deviceFileSystemMock) const deviceInfoErrorResponse: ResultObject = Result.failed( new AppError(DeviceCommunicationError.RequestFailed, "Something went wrong", { @@ -44,7 +41,7 @@ const deviceInfoSuccessResponse: ResultObject = describe("Method: `downloadDeviceLogs`", () => { test("returns Result.failed if DeviceInfo endpoint response with error", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValueOnce(deviceInfoErrorResponse) @@ -60,7 +57,7 @@ describe("Method: `downloadDeviceLogs`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.DeviceInfo, method: Method.Get, body: { @@ -73,7 +70,7 @@ describe("Method: `downloadDeviceLogs`", () => { }) test("returns Result.failed if `downloadDeviceFiles` returns empty data", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValueOnce(deviceInfoSuccessResponse) deviceFileSystemMock.downloadDeviceFiles = jest @@ -92,7 +89,7 @@ describe("Method: `downloadDeviceLogs`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.DeviceInfo, method: Method.Get, body: { @@ -107,7 +104,7 @@ describe("Method: `downloadDeviceLogs`", () => { }) test("returns Result.success if `downloadDeviceFiles` returns file data", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValueOnce(deviceInfoSuccessResponse) deviceFileSystemMock.downloadDeviceFiles = jest.fn().mockResolvedValueOnce( diff --git a/libs/core/device-log/services/device-log.service.ts b/libs/core/device-log/services/device-log.service.ts index e1e4354683..884c13bdae 100644 --- a/libs/core/device-log/services/device-log.service.ts +++ b/libs/core/device-log/services/device-log.service.ts @@ -13,11 +13,11 @@ import { transformDeviceFilesByOption } from "Core/device-log/helpers" import { DeviceFile } from "Core/device-file-system/dto" import { DeviceEnumError } from "Core/device-log/constants" import { DeviceFilesOption } from "Core/device-file-system/types" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class DeviceLogService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private deviceFileSystem: DeviceFileSystemService ) {} @@ -26,15 +26,13 @@ export class DeviceLogService { ): Promise> { try { const files = - await this.deviceProtocolService.device.request( - { - endpoint: Endpoint.DeviceInfo, - method: Method.Get, - body: { - fileList: DiagnosticsFileList.LOGS, - }, - } - ) + await this.deviceProtocol.device.request({ + endpoint: Endpoint.DeviceInfo, + method: Method.Get, + body: { + fileList: DiagnosticsFileList.LOGS, + }, + }) if (!files.data || !files.ok) { return Result.failed( diff --git a/libs/core/device/device.module.ts b/libs/core/device/device.module.ts index ea817af725..d96b51412b 100644 --- a/libs/core/device/device.module.ts +++ b/libs/core/device/device.module.ts @@ -12,12 +12,12 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DeviceService } from "Core/device/services" import { DeviceController } from "Core/device/controllers" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class DeviceModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -26,7 +26,7 @@ export class DeviceModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -34,7 +34,7 @@ export class DeviceModule extends BaseModule { fileSystem ) - const deviceService = new DeviceService(this.deviceProtocolService) + const deviceService = new DeviceService(this.deviceProtocol) const deviceController = new DeviceController(deviceService) this.controllers = [deviceController] diff --git a/libs/core/device/services/device.service.ts b/libs/core/device/services/device.service.ts index dccbab1f8e..e312474b9d 100644 --- a/libs/core/device/services/device.service.ts +++ b/libs/core/device/services/device.service.ts @@ -8,17 +8,17 @@ import { PhoneLockCategory } from "Core/device/constants" import { DeviceCommunicationError, Endpoint, Method } from "core-device/models" import { PhoneLockTime } from "Core/device/dto" import { GetPhoneLockTimeResponseBody } from "Core/device/types/mudita-os" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" export class DeviceService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} public async unlock( code: string, - deviceId: DeviceId = this.deviceProtocolService.device.id + deviceId: DeviceId = this.deviceProtocol.device.id ): Promise> { - const response = await this.deviceProtocolService.request(deviceId, { + const response = await this.deviceProtocol.request(deviceId, { endpoint: Endpoint.Security, method: Method.Put, body: { @@ -30,9 +30,9 @@ export class DeviceService { } public async unlockStatus( - deviceId: DeviceId = this.deviceProtocolService.device.id + deviceId: DeviceId = this.deviceProtocol.device.id ): Promise> { - return this.deviceProtocolService.request(deviceId, { + return this.deviceProtocol.request(deviceId, { endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -40,15 +40,12 @@ export class DeviceService { } public async unlockTime( - deviceId: DeviceId = this.deviceProtocolService.device.id + deviceId: DeviceId = this.deviceProtocol.device.id ): Promise> { - return this.deviceProtocolService.request( - deviceId, - { - endpoint: Endpoint.Security, - method: Method.Get, - body: { category: PhoneLockCategory.Time }, - } - ) + return this.deviceProtocol.request(deviceId, { + endpoint: Endpoint.Security, + method: Method.Get, + body: { category: PhoneLockCategory.Time }, + }) } } diff --git a/libs/core/files-manager/files-manager.module.ts b/libs/core/files-manager/files-manager.module.ts index b850c0b5f9..4a7e26ea98 100644 --- a/libs/core/files-manager/files-manager.module.ts +++ b/libs/core/files-manager/files-manager.module.ts @@ -17,14 +17,14 @@ import { FileUploadCommand, } from "Core/device-file-system/commands" import { FileDeleteCommand } from "Core/device-file-system/commands/file-delete.command" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class FilesManagerModule extends BaseModule { private readonly filesManagerController: FilesManagerController constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -33,7 +33,7 @@ export class FilesManagerModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -44,13 +44,13 @@ export class FilesManagerModule extends BaseModule { const fileManagerService = new FileManagerService( // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileDeleteCommand(this.deviceProtocolService), + new FileDeleteCommand(this.deviceProtocol), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new RetrieveFilesCommand(this.deviceProtocolService), + new RetrieveFilesCommand(this.deviceProtocol), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-call - new FileUploadCommand(this.deviceProtocolService, this.fileSystem) + new FileUploadCommand(this.deviceProtocol, this.fileSystem) ) this.filesManagerController = new FilesManagerController(fileManagerService) diff --git a/libs/core/index-storage/index-storage.module.ts b/libs/core/index-storage/index-storage.module.ts index 5a0fca6dce..d38927c9d5 100644 --- a/libs/core/index-storage/index-storage.module.ts +++ b/libs/core/index-storage/index-storage.module.ts @@ -11,7 +11,7 @@ import { FileSystemService } from "Core/file-system/services/file-system.service import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { IndexStorageService } from "Core/index-storage/services" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { IndexStorageController } from "Core/index-storage/controllers" export class IndexStorageModule extends BaseModule { @@ -20,7 +20,7 @@ export class IndexStorageModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -29,7 +29,7 @@ export class IndexStorageModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, diff --git a/libs/core/messages/message.module.ts b/libs/core/messages/message.module.ts index 657e5ff2ed..51f8dd2561 100644 --- a/libs/core/messages/message.module.ts +++ b/libs/core/messages/message.module.ts @@ -14,12 +14,12 @@ import { MessageModel, ThreadModel } from "Core/messages/models" import { MessageService, ThreadService } from "Core/messages/services" import { MessageController, ThreadController } from "Core/messages/controllers" import { MessageRepository, ThreadRepository } from "Core/messages/repositories" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class MessageModule extends BaseModule { constructor( public index: IndexStorage, - public deviceModule: DeviceProtocolService, + public deviceModule: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/messages/services/message.service.test.ts b/libs/core/messages/services/message.service.test.ts index 7182fc6363..4dc5d7c777 100644 --- a/libs/core/messages/services/message.service.test.ts +++ b/libs/core/messages/services/message.service.test.ts @@ -24,15 +24,15 @@ import { import { MessageRepository } from "Core/messages/repositories" import { MessageService } from "Core/messages/services/message.service" import { ThreadService } from "Core/messages/services/thread.service" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import assert from "assert" import { MessageType as MessageTypeFromDTO } from "Core/messages/constants" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const threadService = { getThreads: jest.fn(), @@ -45,7 +45,7 @@ const messageRepository = { } as unknown as MessageRepository const subject = new MessageService( - deviceProtocolService, + deviceProtocol, threadService, messageRepository ) @@ -117,70 +117,66 @@ beforeEach(() => { describe("`MessageService`", () => { describe("`getMessage` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const response = await subject.getMessage("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.getMessage("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`getMessages` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success({ entries: [pureMessage] })) const response = await subject.getMessages({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.getMessages({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) describe("`createMessage` method", () => { describe("when message is lower than 469 bytes", () => { - test("the `deviceProtocolService.device.request` is called once", async () => { - deviceProtocolService.device.request = jest + test("the `deviceProtocol.device.request` is called once", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const response = await subject.createMessage(newMessageWithThreadId) expect(response.status).toEqual(RequestResponseStatus.Ok) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(1) + expect(deviceProtocol.device.request).toHaveBeenCalledTimes(1) }) }) describe("when message is bigger than 469 bytes", () => { - test("the `deviceProtocolService.device.request` is called more than once", async () => { - deviceProtocolService.device.request = jest + test("the `deviceProtocol.device.request` is called more than once", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const newLongMessageWithThreadId: NewMessage = { @@ -191,14 +187,14 @@ describe("`MessageService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(2) + expect(deviceProtocol.device.request).toHaveBeenCalledTimes(2) }) }) describe("when every part of the message is sent successfully", () => { - describe("when `deviceProtocolService.device.request` returns success with acceptable pure message type", () => { + describe("when `deviceProtocol.device.request` returns success with acceptable pure message type", () => { test("return in response just message when threadId is known", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) const response = await subject.createMessage( @@ -206,7 +202,7 @@ describe("`MessageService`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) assert(response.data?.messageParts) @@ -217,7 +213,7 @@ describe("`MessageService`", () => { }) test("return in response message and thread when threadId isn't known", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(pureMessage)) threadService.getThreads = jest.fn().mockReturnValue({ @@ -229,7 +225,7 @@ describe("`MessageService`", () => { ) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) assert(response.data?.messageParts) @@ -241,9 +237,9 @@ describe("`MessageService`", () => { }) }) - describe("when `deviceProtocolService.device.request` returns success with no acceptable pure message type", () => { + describe("when `deviceProtocol.device.request` returns success with no acceptable pure message type", () => { test("method returns error", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue( Result.success({ ...pureMessage, messageType: MessageType.UNKNOWN }) @@ -251,27 +247,25 @@ describe("`MessageService`", () => { const response = await subject.createMessage(newMessageWithThreadId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) - describe("when `deviceProtocolService.device.request` returns error", () => { + describe("when `deviceProtocol.device.request` returns error", () => { test("method returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.createMessage(newMessageWithThreadId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) }) - describe("when `deviceProtocolService.device.request` returns error for the second message", () => { + describe("when `deviceProtocol.device.request` returns error for the second message", () => { test("method returns error", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValueOnce({ ...successResponse, @@ -281,7 +275,7 @@ describe("`MessageService`", () => { const response = await subject.createMessage(newLongMessageWithThreadId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Error) }) @@ -294,7 +288,7 @@ describe("`MessageService`", () => { describe("when everything is fine", () => { let result: unknown beforeEach(async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success(undefined)) messageRepository.findById = jest.fn().mockReturnValue(message) @@ -310,10 +304,10 @@ describe("`MessageService`", () => { test("construct proper delete request to device service and calls proper repository method", async () => { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(1) + expect(deviceProtocol.device.request).toHaveBeenCalledTimes(1) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ body: { category: PureMessagesCategory.message, messageID: 123, @@ -351,7 +345,7 @@ describe("`MessageService`", () => { describe("when an error appears", () => { test("returns error when message was not found in the repository", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(successResponse) messageRepository.findById = jest.fn().mockReturnValue(undefined) @@ -366,9 +360,7 @@ describe("`MessageService`", () => { }) test("returns error when delete request failed", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) messageRepository.findById = jest.fn().mockReturnValue(message) const result = await subject.deleteMessage(messageId) expect(result).toEqual({ @@ -380,7 +372,7 @@ describe("`MessageService`", () => { }) test("returns error when refreshing repository failed", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(successResponse) messageRepository.findById = jest.fn().mockReturnValue(message) @@ -406,7 +398,7 @@ describe("`MessageService`", () => { const result = await subject.resendMessage(messageId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(0) + expect(deviceProtocol.device.request).toHaveBeenCalledTimes(0) expect(result).toEqual({ status: RequestResponseStatus.Error, error: { @@ -429,14 +421,14 @@ describe("`MessageService`", () => { phoneNumber: "+48500600700", messageType: MessageType.INBOX, }) - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValue(Result.success(pureMessage)) const result = await subject.resendMessage(messageId) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ body: { number: "+48500600700", messageBody: @@ -471,9 +463,9 @@ describe("`MessageService`", () => { }) describe("`updateMessage` method", () => { - describe("`deviceProtocolService.device` returns success status", () => { + describe("`deviceProtocol.device` returns success status", () => { test("returns success result", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(successResponse) const result = await subject.updateMessage(message) @@ -481,7 +473,7 @@ describe("`MessageService`", () => { expect(result).toEqual(successResponse) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ body: MessagePresenter.mapToUpdatePureMessagesBody(message), endpoint: Endpoint.Messages, method: Method.Put, @@ -489,17 +481,15 @@ describe("`MessageService`", () => { }) }) - describe("`deviceProtocolService.device` returns failed satus", () => { + describe("`deviceProtocol.device` returns failed satus", () => { test("returns failed result", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const result = await subject.updateMessage(message) expect(result).toEqual(errorResponse) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ body: MessagePresenter.mapToUpdatePureMessagesBody(message), endpoint: Endpoint.Messages, method: Method.Put, diff --git a/libs/core/messages/services/message.service.ts b/libs/core/messages/services/message.service.ts index 0f2966063a..a8043f584c 100644 --- a/libs/core/messages/services/message.service.ts +++ b/libs/core/messages/services/message.service.ts @@ -30,7 +30,7 @@ import { } from "Core/messages/presenters" import { MessageRepository } from "Core/messages/repositories" import { ThreadService } from "Core/messages/services/thread.service" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { mapToRawNumber, splitMessageByBytesSize } from "Core/messages/helpers" export interface GetMessagesByThreadIdResponse { @@ -49,7 +49,7 @@ export interface CreateMessageDataResponse { export class MessageService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private threadService: ThreadService, private messageRepository: MessageRepository ) {} @@ -58,7 +58,7 @@ export class MessageService { public async getMessage(id: string): Promise> { const response = - await this.deviceProtocolService.device.request({ + await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Get, body: { @@ -93,7 +93,7 @@ export class MessageService { } const response = - await this.deviceProtocolService.device.request({ + await this.deviceProtocol.device.request({ body, endpoint: Endpoint.Messages, method: Method.Get, @@ -172,13 +172,11 @@ export class MessageService { newMessage: NewMessage ): Promise> { const result = - await this.deviceProtocolService.device.request( - { - body: MessagePresenter.mapToCreatePureMessageBody(newMessage), - endpoint: Endpoint.Messages, - method: Method.Post, - } - ) + await this.deviceProtocol.device.request({ + body: MessagePresenter.mapToCreatePureMessageBody(newMessage), + endpoint: Endpoint.Messages, + method: Method.Post, + }) if (!result.ok) { return { @@ -242,7 +240,7 @@ export class MessageService { } } - const result = await this.deviceProtocolService.device.request({ + const result = await this.deviceProtocol.device.request({ body: { category: PureMessagesCategory.message, messageID: Number(messageId), @@ -304,7 +302,7 @@ export class MessageService { } public async updateMessage(message: Message): Promise> { - return this.deviceProtocolService.device.request({ + return this.deviceProtocol.device.request({ body: MessagePresenter.mapToUpdatePureMessagesBody(message), endpoint: Endpoint.Messages, method: Method.Put, diff --git a/libs/core/messages/services/thread.service.test.ts b/libs/core/messages/services/thread.service.test.ts index 2d6d7c9dfa..268904abfd 100644 --- a/libs/core/messages/services/thread.service.test.ts +++ b/libs/core/messages/services/thread.service.test.ts @@ -12,17 +12,17 @@ import { SuccessRequestResponse, } from "Core/core/types/request-response.interface" import { ThreadService } from "Core/messages/services/thread.service" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { ThreadPresenter } from "Core/messages/presenters" import { ThreadRepository } from "Core/messages/repositories" import { Thread } from "Core/messages/dto" import { MessageType } from "Core/messages/constants" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const threadRepository = { create: jest.fn(), @@ -30,7 +30,7 @@ const threadRepository = { delete: jest.fn(), } as unknown as ThreadRepository -const subject = new ThreadService(deviceProtocolService, threadRepository) +const subject = new ThreadService(deviceProtocol, threadRepository) const pureThread: PureThread = { contactID: 1, @@ -78,25 +78,21 @@ beforeEach(() => { describe("`ThreadService`", () => { describe("`getThread` method", () => { // test skipped until os part will be implemented CP-1232 - test.skip("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(successResponse) + test.skip("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(successResponse) const response = await subject.getThread("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.getThread("1") // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Error, error: { @@ -107,14 +103,14 @@ describe("`ThreadService`", () => { }) describe("`getThreads` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(getThreadsSuccessResponse) const response = await subject.getThreads({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response.status).toEqual(RequestResponseStatus.Ok) expect(response.data).toMatchInlineSnapshot(` Object { @@ -136,14 +132,12 @@ describe("`ThreadService`", () => { `) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.getThreads({ limit: 1, offset: 0 }) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Error, error: { @@ -154,27 +148,25 @@ describe("`ThreadService`", () => { }) describe("`deleteThreads` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success({ id: "1" })) const response = await subject.deleteThreads(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Ok, }) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.deleteThreads(["1"]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response).toMatchInlineSnapshot(` Object { "error": Object { @@ -190,27 +182,25 @@ describe("`ThreadService`", () => { }) describe("`toggleThreadsReadStatus` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(Result.success([thread])) const response = await subject.toggleThreadsReadStatus([thread]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response).toEqual({ status: RequestResponseStatus.Ok, }) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.toggleThreadsReadStatus([thread]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalled() + expect(deviceProtocol.device.request).toHaveBeenCalled() expect(response).toMatchInlineSnapshot(` Object { "error": Object { @@ -236,9 +226,7 @@ describe("`ThreadService`", () => { describe("`refreshThread` method", () => { test("returns error when fetching thread failed", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.refreshThread("1") expect(response).toEqual({ status: RequestResponseStatus.Error, @@ -250,7 +238,7 @@ describe("`ThreadService`", () => { describe("when the thread was not found in the device", () => { test("removes thread from the repository and returns success response", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(getThreadsSuccessResponse) const response = await subject.refreshThread("6666") @@ -269,7 +257,7 @@ describe("`ThreadService`", () => { describe("when the thread was found in the device", () => { test("updates the thread and returns success response", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockReturnValue(getThreadsSuccessResponse) const response = await subject.refreshThread("1") diff --git a/libs/core/messages/services/thread.service.ts b/libs/core/messages/services/thread.service.ts index f67ff288f2..a75316b29d 100644 --- a/libs/core/messages/services/thread.service.ts +++ b/libs/core/messages/services/thread.service.ts @@ -4,7 +4,7 @@ */ import { Thread } from "Core/messages/dto" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { GetThreadsRequestConfig, PaginationBody, @@ -29,7 +29,7 @@ export interface GetThreadsResponse { export class ThreadService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private threadRepository: ThreadRepository ) {} @@ -55,7 +55,7 @@ export class ThreadService { } const response = - await this.deviceProtocolService.device.request({ + await this.deviceProtocol.device.request({ body, endpoint: Endpoint.Messages, method: Method.Get, @@ -156,7 +156,7 @@ export class ThreadService { // the method is commented until os part will be implemented as CP-1232 private async getThreadRequest(id: string): Promise> { const response = - await this.deviceProtocolService.device.request({ + await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Get, body: { @@ -182,7 +182,7 @@ export class ThreadService { threads: Thread[] ): Promise> { const results = threads.map(async (thread) => { - const { ok } = await this.deviceProtocolService.device.request({ + const { ok } = await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -229,7 +229,7 @@ export class ThreadService { threadIds: string[] ): Promise> { const results = threadIds.map(async (id) => { - const { ok } = await this.deviceProtocolService.device.request({ + const { ok } = await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Delete, body: { category: PureMessagesCategory.thread, threadID: Number(id) }, diff --git a/libs/core/outbox/factories/outbox.factory.ts b/libs/core/outbox/factories/outbox.factory.ts index e6d14066b9..eb603dd0b6 100644 --- a/libs/core/outbox/factories/outbox.factory.ts +++ b/libs/core/outbox/factories/outbox.factory.ts @@ -5,7 +5,7 @@ import { EventEmitter } from "events" import { OutboxEntryType } from "Core/device/constants" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { IndexStorage } from "Core/index-storage/types" import { EntryHandlersMapType, @@ -25,14 +25,11 @@ export class OutboxFactory { static create( index: IndexStorage, eventEmitter: EventEmitter, - deviceProtocolService: DeviceProtocolService + deviceProtocol: DeviceProtocol ): OutboxService { const contactModel = new ContactModel(index, eventEmitter) const contactRepository = new ContactRepository(contactModel) - const contactService = new ContactService( - contactRepository, - deviceProtocolService - ) + const contactService = new ContactService(contactRepository, deviceProtocol) const contactEntryHandlerService = new ContactEntryHandlerService( contactService, contactRepository @@ -43,12 +40,9 @@ export class OutboxFactory { const messageModel = new MessageModel(index, eventEmitter) const messageRepository = new MessageRepository(messageModel) - const threadService = new ThreadService( - deviceProtocolService, - threadRepository - ) + const threadService = new ThreadService(deviceProtocol, threadRepository) const messageService = new MessageService( - deviceProtocolService, + deviceProtocol, threadService, messageRepository ) @@ -71,6 +65,6 @@ export class OutboxFactory { [OutboxEntryType.Thread]: threadEntryHandlerService, } - return new OutboxService(deviceProtocolService, entryHandlersMap) + return new OutboxService(deviceProtocol, entryHandlersMap) } } diff --git a/libs/core/outbox/outbox.module.ts b/libs/core/outbox/outbox.module.ts index 08479b4381..0ccf2531b9 100644 --- a/libs/core/outbox/outbox.module.ts +++ b/libs/core/outbox/outbox.module.ts @@ -11,13 +11,13 @@ import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { OutboxFactory } from "Core/outbox/factories" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { IndexStorageController } from "Core/outbox/controllers" export class OutboxModule extends BaseModule { constructor( public index: IndexStorage, - public deviceModule: DeviceProtocolService, + public deviceModule: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, diff --git a/libs/core/outbox/services/outbox.service.test.ts b/libs/core/outbox/services/outbox.service.test.ts index 2f99ac1297..377d9d5d4b 100644 --- a/libs/core/outbox/services/outbox.service.test.ts +++ b/libs/core/outbox/services/outbox.service.test.ts @@ -9,21 +9,21 @@ import { EntryHandlersMapType, OutboxService, } from "Core/outbox/services/outbox.service" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { OutboxEntry } from "Core/device/types/mudita-os" import { OutboxEntryChange, OutboxEntryType } from "Core/device/constants" -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn().mockResolvedValue(Result.success({ entries: [] })), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol const entryHandlersMap = { [OutboxEntryType.Contact]: { handleEntry: jest.fn(), }, } as unknown as EntryHandlersMapType -const subject = new OutboxService(deviceProtocolService, entryHandlersMap) +const subject = new OutboxService(deviceProtocol, entryHandlersMap) const entriesMock: OutboxEntry[] = [ { @@ -41,14 +41,14 @@ beforeEach(() => { describe("`OutboxService`", () => { describe("when Get Outbox Entries returns Contact Entry", () => { test("outbox `delete` request was called", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValueOnce(Result.success({ entries: entriesMock })) await subject.readOutboxEntries() // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenCalledWith({ endpoint: Endpoint.Outbox, method: Method.Delete, body: { @@ -58,7 +58,7 @@ describe("`OutboxService`", () => { }) test("contact handler was called", async () => { - deviceProtocolService.device.request = jest + deviceProtocol.device.request = jest .fn() .mockResolvedValueOnce(Result.success({ entries: entriesMock })) diff --git a/libs/core/outbox/services/outbox.service.ts b/libs/core/outbox/services/outbox.service.ts index a3841200ba..efd603be91 100644 --- a/libs/core/outbox/services/outbox.service.ts +++ b/libs/core/outbox/services/outbox.service.ts @@ -11,7 +11,7 @@ import { } from "Core/device/types/mudita-os" import { OutboxEntryType, OutboxCategory } from "Core/device/constants" import { asyncNoop } from "Core/__deprecated__/renderer/utils/noop" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { EntryHandler } from "Core/outbox/services/entry-handler.type" export type EntryHandlersMapType = Record @@ -20,7 +20,7 @@ export type EntryChangesEvent = { entry: OutboxEntry; payload: unknown } export class OutboxService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private entryHandlersMap: EntryHandlersMapType ) {} @@ -52,7 +52,7 @@ export class OutboxService { private async getOutboxEntriesRequest(): Promise< ResultObject > { - return this.deviceProtocolService.device.request({ + return this.deviceProtocol.device.request({ endpoint: Endpoint.Outbox, method: Method.Get, body: { @@ -64,7 +64,7 @@ export class OutboxService { private async deleteOutboxEntriesRequest( uids: number[] ): Promise> { - return this.deviceProtocolService.device.request({ + return this.deviceProtocol.device.request({ endpoint: Endpoint.Outbox, method: Method.Delete, body: { diff --git a/libs/core/search/search.module.ts b/libs/core/search/search.module.ts index 08a2d16b49..065840850e 100644 --- a/libs/core/search/search.module.ts +++ b/libs/core/search/search.module.ts @@ -19,12 +19,12 @@ import { import { SearcherMediator } from "Core/search/mediators" import { SearchService } from "Core/search/services/search.service" import { SearchController } from "Core/search/controllers/search.controller" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class SearchModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -33,7 +33,7 @@ export class SearchModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, diff --git a/libs/core/settings/settings.module.ts b/libs/core/settings/settings.module.ts index e0c3663526..4596589950 100644 --- a/libs/core/settings/settings.module.ts +++ b/libs/core/settings/settings.module.ts @@ -16,12 +16,12 @@ import { } from "Core/settings/controllers" import { ConfigurationService } from "Core/settings/services" import { getSettingsService } from "Core/settings/containers/settings.container" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class SettingsModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -30,7 +30,7 @@ export class SettingsModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, diff --git a/libs/core/templates/services/template.service.test.ts b/libs/core/templates/services/template.service.test.ts index 7e21348682..66b0db8d4b 100644 --- a/libs/core/templates/services/template.service.test.ts +++ b/libs/core/templates/services/template.service.test.ts @@ -8,7 +8,7 @@ import { Result, ResultObject } from "Core/core/builder" import { MessagesCategory } from "Core/device/constants" import { TemplateService } from "Core/templates/services/template.service" import { TemplateRepository } from "Core/templates/repositories" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { ErrorRequestResponse, RequestResponseStatus, @@ -21,13 +21,13 @@ const templateRepository = { delete: jest.fn(), } as unknown as TemplateRepository -const deviceProtocolService = { +const deviceProtocol = { device: { request: jest.fn(), }, -} as unknown as DeviceProtocolService +} as unknown as DeviceProtocol -const subject = new TemplateService(deviceProtocolService, templateRepository) +const subject = new TemplateService(deviceProtocol, templateRepository) const errorResponse: ErrorRequestResponse = { status: RequestResponseStatus.Error, @@ -65,14 +65,14 @@ beforeEach(() => { describe("`TemplateService`", () => { describe("`createTemplate` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest .fn() .mockReturnValue(successResponseWithTemplate) const response = await subject.createTemplate(newTemplate) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenNthCalledWith(1, { + expect(deviceProtocol.device.request).toHaveBeenNthCalledWith(1, { endpoint: Endpoint.Messages, method: Method.Post, body: { @@ -84,14 +84,12 @@ describe("`TemplateService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.createTemplate(newTemplate) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Post, body: { @@ -105,14 +103,12 @@ describe("`TemplateService`", () => { }) describe("`updateTemplate` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(successResponse) + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(successResponse) const response = await subject.updateTemplate(template) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -124,14 +120,12 @@ describe("`TemplateService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.updateTemplate(template) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -144,17 +138,15 @@ describe("`TemplateService`", () => { }) }) describe("`updateTemplateOrder` method", () => { - test("map data and returns success when `deviceProtocolService.device.request` returns success", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(successResponse) + test("map data and returns success when `deviceProtocol.device.request` returns success", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(successResponse) const response = await subject.updateTemplatesOrder([ template, secondTemplate, ]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -166,20 +158,18 @@ describe("`TemplateService`", () => { expect(response.status).toEqual(RequestResponseStatus.Ok) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenCalledTimes(2) + expect(deviceProtocol.device.request).toHaveBeenCalledTimes(2) }) - test("returns error when `deviceProtocolService.device.request` returns error", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(errorResponse) + test("returns error when `deviceProtocol.device.request` returns error", async () => { + deviceProtocol.device.request = jest.fn().mockReturnValue(errorResponse) const response = await subject.updateTemplatesOrder([ template, secondTemplate, ]) // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/unbound-method - expect(deviceProtocolService.device.request).toHaveBeenLastCalledWith({ + expect(deviceProtocol.device.request).toHaveBeenLastCalledWith({ endpoint: Endpoint.Messages, method: Method.Put, body: { @@ -193,9 +183,7 @@ describe("`TemplateService`", () => { }) test("calls templateRepository update method for each updated template", async () => { - deviceProtocolService.device.request = jest - .fn() - .mockReturnValue(successResponse) + deviceProtocol.device.request = jest.fn().mockReturnValue(successResponse) await subject.updateTemplatesOrder([template, secondTemplate]) // AUTO DISABLED - fix me if you like :) diff --git a/libs/core/templates/services/template.service.ts b/libs/core/templates/services/template.service.ts index 92fd42f167..ae119f19f1 100644 --- a/libs/core/templates/services/template.service.ts +++ b/libs/core/templates/services/template.service.ts @@ -5,7 +5,7 @@ import { Endpoint, Method } from "core-device/models" import { NewTemplate, Template } from "Core/templates/dto" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { MessagesCategory } from "Core/device/constants" import { CreateTemplateResponseBody, @@ -24,7 +24,7 @@ import { export class TemplateService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private templateRepository: TemplateRepository ) {} @@ -32,17 +32,15 @@ export class TemplateService { template: NewTemplate ): Promise> { const createResponse = - await this.deviceProtocolService.device.request( - { - endpoint: Endpoint.Messages, - method: Method.Post, - body: TemplatePresenter.mapToPureNewTemplateBody(template), - } - ) + await this.deviceProtocol.device.request({ + endpoint: Endpoint.Messages, + method: Method.Post, + body: TemplatePresenter.mapToPureNewTemplateBody(template), + }) if (createResponse.ok && createResponse.data) { const getResponse = - await this.deviceProtocolService.device.request({ + await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Get, body: { @@ -73,7 +71,7 @@ export class TemplateService { templateIds: string[] ): Promise { const results = templateIds.map(async (id) => { - const { ok } = await this.deviceProtocolService.device.request({ + const { ok } = await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Delete, body: { @@ -116,7 +114,7 @@ export class TemplateService { public async updateTemplate( template: Template ): Promise> { - const response = await this.deviceProtocolService.device.request({ + const response = await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Put, body: TemplatePresenter.mapToPureTemplateBody(template), @@ -141,7 +139,7 @@ export class TemplateService { templates: Template[] ): Promise { const results = templates.map(async (template) => { - const { ok } = await this.deviceProtocolService.device.request({ + const { ok } = await this.deviceProtocol.device.request({ endpoint: Endpoint.Messages, method: Method.Put, body: TemplatePresenter.mapToPureTemplateOrder(template), diff --git a/libs/core/templates/template.module.ts b/libs/core/templates/template.module.ts index af38d82b6e..89e5eb0d1f 100644 --- a/libs/core/templates/template.module.ts +++ b/libs/core/templates/template.module.ts @@ -14,12 +14,12 @@ import { TemplateModel } from "Core/templates/models" import { TemplateRepository } from "Core/templates/repositories" import { TemplateService } from "Core/templates/services" import { TemplateController } from "Core/templates/controllers" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" export class TemplateModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -28,7 +28,7 @@ export class TemplateModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -38,7 +38,7 @@ export class TemplateModule extends BaseModule { const templateModel = new TemplateModel(this.index, this.eventEmitter) const templateRepository = new TemplateRepository(templateModel) const templateService = new TemplateService( - this.deviceProtocolService, + this.deviceProtocol, templateRepository ) const templateController = new TemplateController(templateService) diff --git a/libs/core/update/services/device-update.service.ts b/libs/core/update/services/device-update.service.ts index 0fe9a331b3..dd2d194eee 100644 --- a/libs/core/update/services/device-update.service.ts +++ b/libs/core/update/services/device-update.service.ts @@ -14,14 +14,14 @@ import { SettingsService } from "Core/settings/services" import { UpdateErrorServiceErrors } from "Core/update/constants" import { UpdateOS } from "Core/update/dto" import { join } from "path" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import * as fs from "fs" import { DeviceInfoService } from "Core/device-info/services" export class DeviceUpdateService { constructor( private settingsService: SettingsService, - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private deviceFileSystem: DeviceFileSystemService, private deviceInfoService: DeviceInfoService ) {} @@ -89,7 +89,7 @@ export class DeviceUpdateService { ) } - const pureUpdateResponse = await this.deviceProtocolService.device.request({ + const pureUpdateResponse = await this.deviceProtocol.device.request({ endpoint: Endpoint.Update, method: Method.Post, body: { @@ -129,9 +129,7 @@ export class DeviceUpdateService { ) } - if ( - this.deviceProtocolService.device.deviceType === DeviceType.MuditaPure - ) { + if (this.deviceProtocol.device.deviceType === DeviceType.MuditaPure) { const deviceUnlockedResponse = await this.waitUntilDeviceUnlocked() if (!deviceUnlockedResponse.ok) { @@ -168,7 +166,7 @@ export class DeviceUpdateService { private async getUnlockDeviceStatus(): Promise< ResultObject > { - const { ok, error } = await this.deviceProtocolService.device.request({ + const { ok, error } = await this.deviceProtocol.device.request({ endpoint: Endpoint.Security, method: Method.Get, body: { category: PhoneLockCategory.Status }, @@ -181,7 +179,7 @@ export class DeviceUpdateService { private async waitUntilDeviceRestart( index = 0, - deviceType = this.deviceProtocolService.device.deviceType, + deviceType = this.deviceProtocol.device.deviceType, timeout = 10000, callsMax = 60 ): Promise> { diff --git a/libs/core/update/update.module.ts b/libs/core/update/update.module.ts index 5356795606..6afbaf3497 100644 --- a/libs/core/update/update.module.ts +++ b/libs/core/update/update.module.ts @@ -22,14 +22,14 @@ import { ReleasesController, DeviceUpdateController, } from "Core/update/controllers" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceInfoService } from "Core/device-info/services" import { RELEASE_TIMEOUT } from "Core/update/constants/get-release-timeout.constant" export class UpdateModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -38,7 +38,7 @@ export class UpdateModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -54,9 +54,9 @@ export class UpdateModule extends BaseModule { const deviceUpdateService = new DeviceUpdateService( settingsService, - this.deviceProtocolService, - new DeviceFileSystemService(this.deviceProtocolService), - new DeviceInfoService(this.deviceProtocolService) + this.deviceProtocol, + new DeviceFileSystemService(this.deviceProtocol), + new DeviceInfoService(this.deviceProtocol) ) const deviceUpdateFilesService = new DeviceUpdateFilesService() const releaseService = new ReleaseService(createClient(RELEASE_TIMEOUT)) diff --git a/libs/device-manager/feature/src/controllers/device-manager.controller.ts b/libs/device-manager/feature/src/controllers/device-manager.controller.ts index 740ebb0a63..ea98fa124f 100644 --- a/libs/device-manager/feature/src/controllers/device-manager.controller.ts +++ b/libs/device-manager/feature/src/controllers/device-manager.controller.ts @@ -4,16 +4,16 @@ */ import { IpcEvent } from "Core/core/decorators" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" import { IpcDeviceManagerEvent } from "../constants" export class DeviceManagerController { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(IpcDeviceManagerEvent.ConnectDevice) public connectDevice(id: DeviceId): Promise> { - return this.deviceProtocolService.connectDevice(id) + return this.deviceProtocol.connectDevice(id) } } diff --git a/libs/device-manager/feature/src/device-manager.module.ts b/libs/device-manager/feature/src/device-manager.module.ts index 2574d5bcad..4e558361d8 100644 --- a/libs/device-manager/feature/src/device-manager.module.ts +++ b/libs/device-manager/feature/src/device-manager.module.ts @@ -3,15 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceManagerController } from "./controllers" export class DeviceManagerModule { public controllers - constructor(public deviceProtocolService: DeviceProtocolService) { + constructor(public deviceProtocol: DeviceProtocol) { const deviceManagerController = new DeviceManagerController( - this.deviceProtocolService + this.deviceProtocol ) this.controllers = [deviceManagerController] diff --git a/libs/device-protocol/feature/src/device-protocol.module.ts b/libs/device-protocol/feature/src/device-protocol.module.ts index d127f4c800..8208d302bf 100644 --- a/libs/device-protocol/feature/src/device-protocol.module.ts +++ b/libs/device-protocol/feature/src/device-protocol.module.ts @@ -10,13 +10,13 @@ import { FileSystemService } from "Core/file-system/services/file-system.service import { AppLogger } from "Core/__deprecated__/main/utils/logger" import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" -import { DeviceProtocolService } from "./services" +import { DeviceProtocol } from "./services" import { UsbDeviceDetectionObserver } from "./observers" export class DeviceProtocolModule extends BaseModule { constructor( public index: IndexStorage, - public deviceProtocolService: DeviceProtocolService, + public deviceProtocol: DeviceProtocol, public keyStorage: MetadataStore, public logger: AppLogger, public ipc: MainProcessIpc, @@ -25,7 +25,7 @@ export class DeviceProtocolModule extends BaseModule { ) { super( index, - deviceProtocolService, + deviceProtocol, keyStorage, logger, ipc, @@ -34,7 +34,7 @@ export class DeviceProtocolModule extends BaseModule { ) const usbDeviceDetectionObserver = new UsbDeviceDetectionObserver( - this.deviceProtocolService + this.deviceProtocol ) this.initializers = [] diff --git a/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts b/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts index bb0e9a99cc..3d8cf2411d 100644 --- a/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts +++ b/libs/device-protocol/feature/src/observers/usb-device-detection.observer.ts @@ -7,13 +7,13 @@ import { Observer } from "Core/core/types" import { ipcMain } from "electron-better-ipc" import { ApiSerialPortToRendererEvents } from "device/models" import { SerialPortDeviceAdapterEvent } from "Core/device/modules/mudita-os/adapters" -import { DeviceProtocolService } from "../services" +import { DeviceProtocol } from "../services" const intervalTime = 3000 export class UsbDeviceDetectionObserver implements Observer { private previousAttachedDevicePaths = new Set() - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} public observe(): void { void this.watchAttachedDevices() @@ -42,8 +42,7 @@ export class UsbDeviceDetectionObserver implements Observer { } private async detectDeviceStateChange(): Promise { - const attachedDevices = - await this.deviceProtocolService.getAttachedDevices() + const attachedDevices = await this.deviceProtocol.getAttachedDevices() const detachedDevicePaths = Array.from( this.previousAttachedDevicePaths ).filter( @@ -54,12 +53,12 @@ export class UsbDeviceDetectionObserver implements Observer { ) detachedDevicePaths.forEach((detachedDevicePath) => { - void this.deviceProtocolService.removeDevice(detachedDevicePath) + void this.deviceProtocol.removeDevice(detachedDevicePath) }) attachedDevices.forEach((attachedDevice) => { if (!this.previousAttachedDevicePaths.has(attachedDevice.path)) { - void this.deviceProtocolService.addDevice(attachedDevice) + void this.deviceProtocol.addDevice(attachedDevice) } }) diff --git a/libs/device-protocol/feature/src/services/device-protocol.service.ts b/libs/device-protocol/feature/src/services/device-protocol.ts similarity index 99% rename from libs/device-protocol/feature/src/services/device-protocol.service.ts rename to libs/device-protocol/feature/src/services/device-protocol.ts index bcadd13a73..5df9dd7b56 100644 --- a/libs/device-protocol/feature/src/services/device-protocol.service.ts +++ b/libs/device-protocol/feature/src/services/device-protocol.ts @@ -25,7 +25,7 @@ import { DeviceManagerError } from "../constants" import { PortInfoValidator } from "../validators" import { IDeviceResolverService } from "./device-resolver.service" -export class DeviceProtocolService { +export class DeviceProtocol { public activeDevice: BaseDevice | undefined public devicesMap = new Map() diff --git a/libs/device-protocol/feature/src/services/index.ts b/libs/device-protocol/feature/src/services/index.ts index 3154cff802..125a4615a4 100644 --- a/libs/device-protocol/feature/src/services/index.ts +++ b/libs/device-protocol/feature/src/services/index.ts @@ -3,5 +3,5 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export * from "./device-protocol.service" +export * from "./device-protocol" export * from "./device-resolver.service" diff --git a/libs/device/feature/src/lib/api-config/api-config.service.ts b/libs/device/feature/src/lib/api-config/api-config.service.ts index 7ea0345e7c..4001edab65 100644 --- a/libs/device/feature/src/lib/api-config/api-config.service.ts +++ b/libs/device/feature/src/lib/api-config/api-config.service.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { @@ -17,15 +17,15 @@ import { AppError } from "Core/core/errors" import { APIConfigError } from "./api-config-error" export class APIConfigService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(APIConfigServiceEvents.APIConfig) public async getAPIConfig( deviceId?: DeviceId ): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -51,7 +51,7 @@ export class APIConfigService { //to remove @IpcEvent(APIConfigServiceEvents.APIAny) public async getAPIAny(payload: unknown): Promise> { - const device = this.deviceProtocolService.apiDevice + const device = this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) } diff --git a/libs/device/feature/src/lib/api-features/api-features.service.ts b/libs/device/feature/src/lib/api-features/api-features.service.ts index 45156ac6b1..8922873958 100644 --- a/libs/device/feature/src/lib/api-features/api-features.service.ts +++ b/libs/device/feature/src/lib/api-features/api-features.service.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { @@ -21,7 +21,7 @@ import { DeviceId } from "Core/device/constants/device-id" import { View } from "generic-view/utils" export class APIFeaturesService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(APIFeaturesServiceEvents.FeatureConfiguration) public async getFeatureConfiguration({ @@ -32,8 +32,8 @@ export class APIFeaturesService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -65,8 +65,8 @@ export class APIFeaturesService { deviceId?: DeviceId ): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -94,7 +94,7 @@ export class APIFeaturesService { @IpcEvent(APIFeaturesServiceEvents.FeatureData) public async getFeatureData(feature: string): Promise> { - const device = this.deviceProtocolService.apiDevice + const device = this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) } @@ -125,8 +125,8 @@ export class APIFeaturesService { about: View }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/api-module.ts b/libs/device/feature/src/lib/api-module.ts index 20a29b946e..4341dfe354 100644 --- a/libs/device/feature/src/lib/api-module.ts +++ b/libs/device/feature/src/lib/api-module.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { APIConfigService } from "./api-config/api-config.service" import { APIFeaturesService } from "./api-features/api-features.service" import { APIBackupService } from "./backup" @@ -34,34 +34,29 @@ export class APIModule { private apiDataTransferService: APIDataTransferService constructor( - deviceProtocolService: DeviceProtocolService, + deviceProtocol: DeviceProtocol, systemUtilsModule: SystemUtilsModule, settingsService: ISettingsService ) { this.serviceBridge = new ServiceBridge() - this.apiConfigService = new APIConfigService(deviceProtocolService) - this.apiFeaturesService = new APIFeaturesService(deviceProtocolService) - this.apiOutboxService = new APIOutboxService(deviceProtocolService) - this.apiMenuService = new APIMenuService(deviceProtocolService) + this.apiConfigService = new APIConfigService(deviceProtocol) + this.apiFeaturesService = new APIFeaturesService(deviceProtocol) + this.apiOutboxService = new APIOutboxService(deviceProtocol) + this.apiMenuService = new APIMenuService(deviceProtocol) this.serverService = new ServerService() - this.backupService = new APIBackupService(deviceProtocolService) - this.apiDataTransferService = new APIDataTransferService( - deviceProtocolService - ) + this.backupService = new APIBackupService(deviceProtocol) + this.apiDataTransferService = new APIDataTransferService(deviceProtocol) this.restoreService = new APIRestoreService( - deviceProtocolService, + deviceProtocol, this.serviceBridge ) this.fileTransferService = new APIFileTransferService( - deviceProtocolService, - this.serviceBridge - ) - this.fileManager = new FileManager( - deviceProtocolService, + deviceProtocol, this.serviceBridge ) + this.fileManager = new FileManager(deviceProtocol, this.serviceBridge) this.deviceSystemActionsService = new DeviceSystemActionsService( - deviceProtocolService + deviceProtocol ) this.serviceBridge.systemUtilsModule = systemUtilsModule this.serviceBridge.fileTransfer = this.fileTransferService diff --git a/libs/device/feature/src/lib/backup/backup.service.ts b/libs/device/feature/src/lib/backup/backup.service.ts index 3f517c2fd1..4ad07f0e3b 100644 --- a/libs/device/feature/src/lib/backup/backup.service.ts +++ b/libs/device/feature/src/lib/backup/backup.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiResponse } from "Core/device/types/mudita-os" import { @@ -19,7 +19,7 @@ import { import random from "lodash/random" export class APIBackupService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(APIBackupServiceEvents.StartPreBackup) public async startPreBackup({ @@ -30,8 +30,8 @@ export class APIBackupService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -62,8 +62,8 @@ export class APIBackupService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -89,8 +89,8 @@ export class APIBackupService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts b/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts index 3ef6756afc..638660e0fb 100644 --- a/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts +++ b/libs/device/feature/src/lib/data-transfer/data-transfer.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiResponse } from "Core/device/types/mudita-os" import { @@ -22,7 +22,7 @@ import { import random from "lodash/random" export class APIDataTransferService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(APIDataTransferServiceEvents.StartPreDataTransfer) public async startPreDataTransfer({ @@ -33,8 +33,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -73,8 +73,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -100,8 +100,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -127,8 +127,8 @@ export class APIDataTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts b/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts index ea602221c0..2cfb5d75c2 100644 --- a/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts +++ b/libs/device/feature/src/lib/device-system-actions/device-system-actions.service.ts @@ -3,22 +3,22 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { Result } from "Core/core/builder" import { AppError } from "Core/core/errors" import { GeneralError, DeviceSystemActionsServiceEvents } from "device/models" import { IpcEvent } from "Core/core/decorators" export class DeviceSystemActionsService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} private async sendSystemRequest( action: string, { deviceId }: { deviceId?: string } = {} ) { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/file-manager/file-manager.service.ts b/libs/device/feature/src/lib/file-manager/file-manager.service.ts index 6851cb4c9f..e5bdd10852 100644 --- a/libs/device/feature/src/lib/file-manager/file-manager.service.ts +++ b/libs/device/feature/src/lib/file-manager/file-manager.service.ts @@ -8,7 +8,7 @@ import { IpcEvent } from "Core/core/decorators" import { ServiceBridge } from "../service-bridge" import { FileManagerServiceEvents, GeneralError } from "device/models" import { AppError } from "Core/core/errors" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import packageInfo from "../../../../../../apps/mudita-center/package.json" import { @@ -28,7 +28,7 @@ export class FileManager { private files: Record = {} constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private serviceBridge: ServiceBridge ) {} @@ -55,8 +55,8 @@ export class FileManager { @IpcEvent(FileManagerServiceEvents.GetBackupPath) public getBackupPath({ deviceId }: { deviceId?: DeviceId } = {}) { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -101,8 +101,8 @@ export class FileManager { password?: string }) { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts b/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts index e6b5b22530..d9a7c29103 100644 --- a/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts +++ b/libs/device/feature/src/lib/file-transfer/file-transfer.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError, AppErrorType } from "Core/core/errors" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiFileTransferError, @@ -38,7 +38,7 @@ const DEFAULT_MAX_REPEATS = 2 export class APIFileTransferService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private serviceBridge: ServiceBridge, private transfers: Record = {} ) {} @@ -122,8 +122,8 @@ export class APIFileTransferService { }> > { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -157,8 +157,8 @@ export class APIFileTransferService { }> > { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -191,8 +191,8 @@ export class APIFileTransferService { maxRepeats: number }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -256,8 +256,8 @@ export class APIFileTransferService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -310,8 +310,8 @@ export class APIFileTransferService { maxRepeats: number }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -399,8 +399,8 @@ export class APIFileTransferService { }> > { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/menu/menu.service.ts b/libs/device/feature/src/lib/menu/menu.service.ts index 3ad76585b7..196b4b3286 100644 --- a/libs/device/feature/src/lib/menu/menu.service.ts +++ b/libs/device/feature/src/lib/menu/menu.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { APIMenuServiceEvents, GeneralError, @@ -16,15 +16,15 @@ import { import { DeviceId } from "Core/device/constants/device-id" export class APIMenuService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(APIMenuServiceEvents.GetMenuConfig) public async getMenuConfig( deviceId?: DeviceId ): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) diff --git a/libs/device/feature/src/lib/outbox/outbox.service.ts b/libs/device/feature/src/lib/outbox/outbox.service.ts index 66f6b4ea07..71b4d0df4d 100644 --- a/libs/device/feature/src/lib/outbox/outbox.service.ts +++ b/libs/device/feature/src/lib/outbox/outbox.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { APIOutboxServiceEvents, @@ -16,13 +16,13 @@ import { } from "device/models" export class APIOutboxService { - constructor(private deviceProtocolService: DeviceProtocolService) {} + constructor(private deviceProtocol: DeviceProtocol) {} @IpcEvent(APIOutboxServiceEvents.GetOutboxData) public async getOutboxData( deviceId: DeviceId ): Promise> { - const device = this.deviceProtocolService.getAPIDeviceById(deviceId) + const device = this.deviceProtocol.getAPIDeviceById(deviceId) if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) } diff --git a/libs/device/feature/src/lib/restore/restore.service.ts b/libs/device/feature/src/lib/restore/restore.service.ts index f1dc30e6b4..c25fbdf353 100644 --- a/libs/device/feature/src/lib/restore/restore.service.ts +++ b/libs/device/feature/src/lib/restore/restore.service.ts @@ -6,7 +6,7 @@ import { Result, ResultObject } from "Core/core/builder" import { IpcEvent } from "Core/core/decorators" import { AppError } from "Core/core/errors" -import { DeviceProtocolService } from "device-protocol/feature" +import { DeviceProtocol } from "device-protocol/feature" import { DeviceId } from "Core/device/constants/device-id" import { ApiResponse } from "Core/device/types/mudita-os" import { @@ -24,7 +24,7 @@ import { ServiceBridge } from "../service-bridge" export class APIRestoreService { constructor( - private deviceProtocolService: DeviceProtocolService, + private deviceProtocol: DeviceProtocol, private serviceBridge: ServiceBridge ) {} @@ -40,8 +40,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -80,8 +80,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -107,8 +107,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) @@ -136,8 +136,8 @@ export class APIRestoreService { deviceId?: DeviceId }): Promise> { const device = deviceId - ? this.deviceProtocolService.getAPIDeviceById(deviceId) - : this.deviceProtocolService.apiDevice + ? this.deviceProtocol.getAPIDeviceById(deviceId) + : this.deviceProtocol.apiDevice if (!device) { return Result.failed(new AppError(GeneralError.NoDevice, "")) From af05798d1d55f7c5b4fd63ee893ac393c8416b88 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 18 Jun 2024 12:05:24 +0200 Subject: [PATCH 024/100] [CP-2898] Fixed lastRefresh mechanism to handle race condition --- .../store/src/lib/action-names.ts | 1 + .../src/lib/outbox/get-outbox-data.action.ts | 53 +++++++++++-------- .../store/src/lib/views/actions.ts | 2 + .../store/src/lib/views/reducer.ts | 13 ++--- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/libs/generic-view/store/src/lib/action-names.ts b/libs/generic-view/store/src/lib/action-names.ts index edc773494e..ff92f9e4ca 100644 --- a/libs/generic-view/store/src/lib/action-names.ts +++ b/libs/generic-view/store/src/lib/action-names.ts @@ -11,6 +11,7 @@ export enum ActionName { SetMenu = "generic-views/set-menu", SetViewLayout = "generic-views/set-view-layout", SetViewData = "generic-views/set-view-data", + SetLastRefresh = "generic-views/set-last-refresh", AddDevice = "generic-views/add-device", RemoveDevice = "generic-views/remove-device", OpenModal = "generic-modals/open-modal", diff --git a/libs/generic-view/store/src/lib/outbox/get-outbox-data.action.ts b/libs/generic-view/store/src/lib/outbox/get-outbox-data.action.ts index 06e6f7d12d..3480f44de3 100644 --- a/libs/generic-view/store/src/lib/outbox/get-outbox-data.action.ts +++ b/libs/generic-view/store/src/lib/outbox/get-outbox-data.action.ts @@ -8,9 +8,12 @@ import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { getOutboxDataRequest } from "device/feature" import { Outbox } from "device/models" import { DeviceId } from "Core/device/constants/device-id" +import { AppError } from "Core/core/errors" import { ActionName } from "../action-names" import { getSingleFeatures } from "../features/get-single-feature" import { getSingleFeatureData } from "../features/get-single-feature-data" +import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-id" +import { setLastRefresh } from "../views/actions" export const getOutboxData = createAsyncThunk< { @@ -22,31 +25,37 @@ export const getOutboxData = createAsyncThunk< { state: ReduxRootState } >( ActionName.GetOutboxData, - async ({ deviceId }, { rejectWithValue, dispatch }) => { + async ({ deviceId }, { rejectWithValue, dispatch, getState }) => { const response = await getOutboxDataRequest(deviceId) - if (response.ok) { - const featuresToFullReload = response.data.features - const dataToReload = response.data.data.filter((feature) => { - return !featuresToFullReload.includes(feature) - }) - - featuresToFullReload.forEach(async (feature) => { - await dispatch(getSingleFeatures({ deviceId, feature })) - }) - dataToReload.forEach(async (feature) => { - await dispatch(getSingleFeatureData({ deviceId, feature })) - }) - - return { - deviceId, - data: response.data, - timestamp: new Date().getTime(), - } + + if (selectActiveApiDeviceId(getState()) === deviceId) { + dispatch(setLastRefresh(new Date().getTime())) + } + + if (!response.ok) { + return rejectWithValue(new AppError("")) } - return rejectWithValue({ + + const featuresToFullReload = response.data.features + const dataToReload = response.data.data.filter((feature) => { + return !featuresToFullReload.includes(feature) + }) + + featuresToFullReload.forEach(async (feature) => { + await dispatch(getSingleFeatures({ deviceId, feature })) + }) + dataToReload.forEach(async (feature) => { + await dispatch(getSingleFeatureData({ deviceId, feature })) + }) + + if (selectActiveApiDeviceId(getState()) === deviceId) { + dispatch(setLastRefresh(new Date().getTime())) + } + + return { deviceId, - data: response.error, + data: response.data, timestamp: new Date().getTime(), - }) + } } ) diff --git a/libs/generic-view/store/src/lib/views/actions.ts b/libs/generic-view/store/src/lib/views/actions.ts index 1df100e20d..412e957bfa 100644 --- a/libs/generic-view/store/src/lib/views/actions.ts +++ b/libs/generic-view/store/src/lib/views/actions.ts @@ -28,3 +28,5 @@ export const setViewData = createAction<{ feature: string data: Record }>(ActionName.SetViewData) + +export const setLastRefresh = createAction(ActionName.SetLastRefresh) diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index ef1b2c788e..4a186af390 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -8,7 +8,6 @@ import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-element import { View } from "generic-view/utils" import { Device, DeviceState, Features } from "generic-view/models" import { ApiError } from "device/models" -import { DeviceId } from "Core/device/constants/device-id" import { AppError } from "Core/core/errors" import { getAPIConfig } from "../get-api-config" import { getOverviewData } from "../features" @@ -19,7 +18,7 @@ import { getOutboxData } from "../outbox/get-outbox-data.action" import { getGenericConfig } from "../features/get-generic-config.actions" import { addDevice, - removeDevice, + removeDevice, setLastRefresh, setMenu, setViewData, setViewLayout, @@ -152,16 +151,12 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { builder.addCase(removeDevice, (state, action) => { delete state.devices[action.payload.id] }) + builder.addCase(setLastRefresh, (state, action) => { + state.lastRefresh = action.payload + }) builder.addCase(getOutboxData.fulfilled, (state, action) => { state.apiErrors[ApiError.DeviceLocked] = false }) - builder.addCase(getOutboxData.rejected, (state, action) => { - const { deviceId, timestamp } = action.payload as { - deviceId: DeviceId - timestamp: number - } - state.lastRefresh = timestamp - }) builder.addCase(getGenericConfig.fulfilled, (state, action) => { const { deviceId, feature, view } = action.payload state.devices[deviceId].features = { From 8bec5c2472f4f87b973a6b9d307ffb9f4a403921 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 21 Jun 2024 09:28:19 +0200 Subject: [PATCH 025/100] Revert "disable HttpClientService for axios.create (#1932)" This reverts commit be20b3565a449b78163510ca58589d5ef4bbe2fd. --- libs/shared/http-client/src/lib/http-client.factory.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/shared/http-client/src/lib/http-client.factory.ts b/libs/shared/http-client/src/lib/http-client.factory.ts index 3b040fdff0..6784a1f764 100644 --- a/libs/shared/http-client/src/lib/http-client.factory.ts +++ b/libs/shared/http-client/src/lib/http-client.factory.ts @@ -3,15 +3,16 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import axios, { AxiosRequestConfig } from "axios" +import { AxiosRequestConfig } from "axios" import { mockHttpStateService, mockServiceEnabled } from "e2e-mock-server" +import { HttpClientService } from "./http-client.service" import { BaseHttpClientService } from "./base-http-client.service" import { MockHttpClientService } from "./mock-http-client.service" -export class HttpClient { - static create(config?: AxiosRequestConfig): BaseHttpClientService { +export class HttpClient{ + static create (config?: AxiosRequestConfig): BaseHttpClientService { return mockServiceEnabled ? new MockHttpClientService(mockHttpStateService) - : axios.create(config) + : new HttpClientService(config) } } From b0272a226846681eb754e80fb6a58dba3486d172 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 21 Jun 2024 10:45:25 +0200 Subject: [PATCH 026/100] [CP-2898] Fixed detached for API device --- .../store/src/lib/hooks/use-api-serial-port-listeners.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts index c41c8aa038..2000ede6d7 100644 --- a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts +++ b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts @@ -70,7 +70,7 @@ const useHandleDevicesDetached = () => { } const apiEvents = deviceDetachedEvents.filter( - ({ deviceType }) => deviceType !== DeviceType.APIDevice + ({ deviceType }) => deviceType === DeviceType.APIDevice ) if (apiEvents.length === 0) { From a9c84b511fa4dbc85384f405c40b2b5f756ed1ff Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Mon, 24 Jun 2024 08:49:07 +0200 Subject: [PATCH 027/100] [CP-2901] Rename AvailableDeviceProperties to DeviceProperties --- libs/core-device/models/src/core-device.interface.ts | 4 ++-- .../components/devices-initialization.component.tsx | 4 ++-- .../components/device-list-item.component.tsx | 4 ++-- .../discovery-device/components/device-list.component.tsx | 4 ++-- .../feature/src/selectors/get-active-device.selector.ts | 4 ++-- .../feature/src/selectors/get-available-devices.selector.ts | 4 ++-- .../src/selectors/get-configured-devices.selector.ts | 4 ++-- .../feature/src/selectors/get-failed-devices.selector.ts | 4 ++-- ...operties.interface.ts => device-properties.interface.ts} | 4 ++-- libs/device-manager/models/src/index.ts | 2 +- libs/generic-view/models/src/lib/device.ts | 6 +++--- 11 files changed, 22 insertions(+), 22 deletions(-) rename libs/device-manager/models/src/{available-device-properties.interface.ts => device-properties.interface.ts} (70%) diff --git a/libs/core-device/models/src/core-device.interface.ts b/libs/core-device/models/src/core-device.interface.ts index 9f6a291f4e..5c1245ffb5 100644 --- a/libs/core-device/models/src/core-device.interface.ts +++ b/libs/core-device/models/src/core-device.interface.ts @@ -5,7 +5,7 @@ import { CaseColour } from "core-device/models" import { DeviceType } from "device-protocol/models" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { DeviceId } from "Core/device/constants/device-id" export enum DeviceState { @@ -15,7 +15,7 @@ export enum DeviceState { Failed = "FAILED", } -export interface Device extends AvailableDeviceProperties { +export interface Device extends DeviceProperties { id: DeviceId serialNumber: string | undefined deviceType: DeviceType diff --git a/libs/core/device-initialization/components/devices-initialization.component.tsx b/libs/core/device-initialization/components/devices-initialization.component.tsx index a09eac886e..c9f63a8bdf 100644 --- a/libs/core/device-initialization/components/devices-initialization.component.tsx +++ b/libs/core/device-initialization/components/devices-initialization.component.tsx @@ -8,14 +8,14 @@ import { useSelector } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" import { getActiveDevice } from "device-manager/feature" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { DeviceType } from "device-protocol/models" import { MuditaPureInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow" import { MuditaHarmonyInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-harmony-initialization-modal-flow" import { APIDeviceInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow" const DevicesInitializationModalFlow: FunctionComponent<{ - activeDevice?: AvailableDeviceProperties + activeDevice?: DeviceProperties }> = ({ activeDevice }) => { if (activeDevice?.deviceType === DeviceType.MuditaPure) { return diff --git a/libs/core/discovery-device/components/device-list-item.component.tsx b/libs/core/discovery-device/components/device-list-item.component.tsx index e9b5036953..f079ce5517 100644 --- a/libs/core/discovery-device/components/device-list-item.component.tsx +++ b/libs/core/discovery-device/components/device-list-item.component.tsx @@ -6,7 +6,7 @@ import React from "react" import { defineMessages } from "react-intl" import styled, { css } from "styled-components" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { FunctionComponent } from "Core/core/types/function-component.interface" import { backgroundColor, @@ -93,7 +93,7 @@ export const DeviceInfoDeviceTypeName = styled(Text)` margin-bottom: 0.5rem; ` -export interface DeviceListItemProps extends AvailableDeviceProperties { +export interface DeviceListItemProps extends DeviceProperties { onDeviceClick: (id: string) => void } diff --git a/libs/core/discovery-device/components/device-list.component.tsx b/libs/core/discovery-device/components/device-list.component.tsx index a43806d3ab..7c5fdef215 100644 --- a/libs/core/discovery-device/components/device-list.component.tsx +++ b/libs/core/discovery-device/components/device-list.component.tsx @@ -6,11 +6,11 @@ import React from "react" import styled from "styled-components" import { FunctionComponent } from "Core/core/types/function-component.interface" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import DeviceListItem from "Core/discovery-device/components/device-list-item.component" interface Props { - devices: AvailableDeviceProperties[] + devices: DeviceProperties[] onDeviceClick: (id: string) => void } diff --git a/libs/device-manager/feature/src/selectors/get-active-device.selector.ts b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts index 888e6b6d41..9ff588aac7 100644 --- a/libs/device-manager/feature/src/selectors/get-active-device.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-active-device.selector.ts @@ -4,14 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { activeDeviceIdSelector } from "active-device-registry/feature" import { getDevicesSelector } from "./get-devices.selector" export const getActiveDevice = createSelector( getDevicesSelector, activeDeviceIdSelector, - (devices, activeDeviceId): AvailableDeviceProperties | undefined => { + (devices, activeDeviceId): DeviceProperties | undefined => { return devices.find(({ id }) => id === activeDeviceId) } ) diff --git a/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts index 363db33dad..63f6c52c6e 100644 --- a/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-available-devices.selector.ts @@ -4,14 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { getFailedDevicesSelector } from "./get-failed-devices.selector" import { getConfiguredDevicesSelector } from "./get-configured-devices.selector" export const getAvailableDevicesSelector = createSelector( getConfiguredDevicesSelector, getFailedDevicesSelector, - (configuredDevices, failedDevices): AvailableDeviceProperties[] => { + (configuredDevices, failedDevices): DeviceProperties[] => { return [...configuredDevices, ...failedDevices] } ) diff --git a/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts index 8a20e169f6..4b665912c0 100644 --- a/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-configured-devices.selector.ts @@ -4,14 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { selectConfiguredDevices } from "generic-view/store" import { getConfiguredCoreDevicesSelector } from "core-device/feature" export const getConfiguredDevicesSelector = createSelector( getConfiguredCoreDevicesSelector, selectConfiguredDevices, - (coreDevices, apiDevices): AvailableDeviceProperties[] => { + (coreDevices, apiDevices): DeviceProperties[] => { return [...coreDevices, ...Object.values(apiDevices)] } ) diff --git a/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts index 427ab3c43a..412b7490d9 100644 --- a/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-failed-devices.selector.ts @@ -4,14 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { getFailedCoreDevicesSelector } from "core-device/feature" import { selectFailedDevices } from "generic-view/store" export const getFailedDevicesSelector = createSelector( getFailedCoreDevicesSelector, selectFailedDevices, - (failedCoreDevices, failedApiDevices): AvailableDeviceProperties[] => { + (failedCoreDevices, failedApiDevices): DeviceProperties[] => { return [...failedCoreDevices, ...Object.values(failedApiDevices)] } ) diff --git a/libs/device-manager/models/src/available-device-properties.interface.ts b/libs/device-manager/models/src/device-properties.interface.ts similarity index 70% rename from libs/device-manager/models/src/available-device-properties.interface.ts rename to libs/device-manager/models/src/device-properties.interface.ts index 953cd95081..4e15705e14 100644 --- a/libs/device-manager/models/src/available-device-properties.interface.ts +++ b/libs/device-manager/models/src/device-properties.interface.ts @@ -6,6 +6,6 @@ import { DeviceBaseProperties } from "device-protocol/models" import { CaseColour } from "core-device/models" -export interface AvailableDeviceProperties extends DeviceBaseProperties { - caseColour?: CaseColour | undefined +export interface DeviceProperties extends DeviceBaseProperties { + caseColour?: CaseColour } diff --git a/libs/device-manager/models/src/index.ts b/libs/device-manager/models/src/index.ts index f0c2ff6ad6..c23cf9ca59 100644 --- a/libs/device-manager/models/src/index.ts +++ b/libs/device-manager/models/src/index.ts @@ -3,6 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export * from "./available-device-properties.interface" +export * from "./device-properties.interface" export * from "./device-manager.interface" export * from "./event.constant" diff --git a/libs/generic-view/models/src/lib/device.ts b/libs/generic-view/models/src/lib/device.ts index 86f80208a4..bbfd2d99d7 100644 --- a/libs/generic-view/models/src/lib/device.ts +++ b/libs/generic-view/models/src/lib/device.ts @@ -5,7 +5,7 @@ import { DeviceType } from "device-protocol/models" import { View } from "generic-view/utils" -import { AvailableDeviceProperties } from "device-manager/models" +import { DeviceProperties } from "device-manager/models" import { ApiConfig, MenuConfig, OverviewData } from "device/models" import { DeviceId } from "Core/device/constants/device-id" @@ -39,7 +39,7 @@ export enum DeviceState { } export interface Device - extends AvailableDeviceProperties, + extends DeviceProperties, Partial { id: DeviceId serialNumber: string | undefined @@ -48,5 +48,5 @@ export interface Device } export interface ConfiguredDevice - extends AvailableDeviceProperties, + extends DeviceProperties, DeviceConfiguration {} From ef4dfa141e4f3144d6de75d2dc08ad288bd6e140 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Wed, 26 Jun 2024 09:42:38 +0200 Subject: [PATCH 028/100] [CP-2901] `DeviceState` moved to `device-manager` domain --- libs/core-device/feature/src/actions/base.action.ts | 3 ++- .../src/hooks/use-core-device-protocol-listeners.ts | 5 ++--- .../feature/src/reducers/core-device.reducer.ts | 3 ++- .../src/selectors/get-configured-core-devices.selector.ts | 3 ++- .../src/selectors/get-failed-core-devices.selector.ts | 3 ++- libs/core-device/models/src/core-device.interface.ts | 8 -------- .../components/devices-initialization.component.tsx | 5 ++--- .../feature/src/actions/connect-device.action.ts | 3 +-- .../feature/src/selectors/get-devices.selector.ts | 4 ++-- .../models/src/device-properties.interface.ts | 8 ++++++++ libs/generic-view/models/src/lib/device.ts | 8 -------- .../store/src/lib/hooks/use-api-serial-port-listeners.ts | 2 +- .../store/src/lib/selectors/select-configured-devices.ts | 3 ++- .../store/src/lib/selectors/select-failed-devices.ts | 3 ++- libs/generic-view/store/src/lib/views/actions.ts | 2 +- libs/generic-view/store/src/lib/views/reducer.ts | 3 ++- 16 files changed, 31 insertions(+), 35 deletions(-) diff --git a/libs/core-device/feature/src/actions/base.action.ts b/libs/core-device/feature/src/actions/base.action.ts index 3820361ca3..219849917b 100644 --- a/libs/core-device/feature/src/actions/base.action.ts +++ b/libs/core-device/feature/src/actions/base.action.ts @@ -5,7 +5,8 @@ import { createAction } from "@reduxjs/toolkit" import { DeviceBaseProperties } from "device-protocol/models" -import { DeviceState, CaseColour } from "core-device/models" +import { DeviceState } from "device-manager/models" +import { CaseColour } from "core-device/models" import { CoreDeviceEvent } from "../constants" export const addDevice = createAction< diff --git a/libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts b/libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts index 7988783d2c..1124bd3afd 100644 --- a/libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts +++ b/libs/core-device/feature/src/hooks/use-core-device-protocol-listeners.ts @@ -4,11 +4,10 @@ */ import { useCallback, useEffect } from "react" -import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" import { useDispatch } from "react-redux" import { answerMain, useDebouncedEventsHandler } from "shared/utils" -import { DeviceBaseProperties } from "device-protocol/models" -import { DeviceState } from "core-device/models" +import { DeviceState } from "device-manager/models" +import { DeviceProtocolMainEvent, DeviceType, DeviceBaseProperties } from "device-protocol/models" import { Dispatch } from "Core/__deprecated__/renderer/store" import { addDevice, configureDevice, removeDevice } from "../actions" import { getDeviceConfigurationRequest } from "../requests" diff --git a/libs/core-device/feature/src/reducers/core-device.reducer.ts b/libs/core-device/feature/src/reducers/core-device.reducer.ts index 5cf6bcfab6..123fe0ed36 100644 --- a/libs/core-device/feature/src/reducers/core-device.reducer.ts +++ b/libs/core-device/feature/src/reducers/core-device.reducer.ts @@ -4,7 +4,8 @@ */ import { createReducer } from "@reduxjs/toolkit" -import { Device, CoreDeviceState, DeviceState } from "core-device/models" +import { DeviceState } from "device-manager/models" +import { Device, CoreDeviceState } from "core-device/models" import { addDevice, removeDevice, diff --git a/libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts b/libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts index b2bda59478..d1fbffa9c7 100644 --- a/libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts +++ b/libs/core-device/feature/src/selectors/get-configured-core-devices.selector.ts @@ -4,7 +4,8 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { Device, DeviceState } from "core-device/models" +import { Device } from "core-device/models" +import { DeviceState } from "device-manager/models" import { getCoreDevicesSelector } from "./get-core-devices.selector" export const getConfiguredCoreDevicesSelector = createSelector( diff --git a/libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts b/libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts index 72ed530cd5..8230b8d17c 100644 --- a/libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts +++ b/libs/core-device/feature/src/selectors/get-failed-core-devices.selector.ts @@ -4,7 +4,8 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { Device, DeviceState } from "core-device/models" +import { Device } from "core-device/models" +import { DeviceState } from "device-manager/models" import { getCoreDevicesSelector } from "./get-core-devices.selector" export const getFailedCoreDevicesSelector = createSelector( diff --git a/libs/core-device/models/src/core-device.interface.ts b/libs/core-device/models/src/core-device.interface.ts index 5c1245ffb5..6d7a6fc182 100644 --- a/libs/core-device/models/src/core-device.interface.ts +++ b/libs/core-device/models/src/core-device.interface.ts @@ -8,19 +8,11 @@ import { DeviceType } from "device-protocol/models" import { DeviceProperties } from "device-manager/models" import { DeviceId } from "Core/device/constants/device-id" -export enum DeviceState { - Connected = "CONNECTED", - Configured = "CONFIGURED", - Initialized = "INITIALIZED", - Failed = "FAILED", -} - export interface Device extends DeviceProperties { id: DeviceId serialNumber: string | undefined deviceType: DeviceType caseColour: CaseColour | undefined - state: DeviceState } export interface CoreDeviceState { diff --git a/libs/core/device-initialization/components/devices-initialization.component.tsx b/libs/core/device-initialization/components/devices-initialization.component.tsx index c9f63a8bdf..6f8f328bb8 100644 --- a/libs/core/device-initialization/components/devices-initialization.component.tsx +++ b/libs/core/device-initialization/components/devices-initialization.component.tsx @@ -8,14 +8,13 @@ import { useSelector } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" import { getActiveDevice } from "device-manager/feature" -import { DeviceProperties } from "device-manager/models" -import { DeviceType } from "device-protocol/models" +import { DeviceBaseProperties, DeviceType } from "device-protocol/models" import { MuditaPureInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow" import { MuditaHarmonyInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-harmony-initialization-modal-flow" import { APIDeviceInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow" const DevicesInitializationModalFlow: FunctionComponent<{ - activeDevice?: DeviceProperties + activeDevice?: DeviceBaseProperties }> = ({ activeDevice }) => { if (activeDevice?.deviceType === DeviceType.MuditaPure) { return diff --git a/libs/device-manager/feature/src/actions/connect-device.action.ts b/libs/device-manager/feature/src/actions/connect-device.action.ts index 20ac9f8453..72125e6e83 100644 --- a/libs/device-manager/feature/src/actions/connect-device.action.ts +++ b/libs/device-manager/feature/src/actions/connect-device.action.ts @@ -4,9 +4,8 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" -import { DeviceManagerEvent } from "device-manager/models" +import { DeviceManagerEvent, DeviceState } from "device-manager/models" import { setDeviceState } from "core-device/feature" -import { DeviceState } from "core-device/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { DeviceId } from "Core/device/constants/device-id" import { connectDeviceRequest } from "../requests" diff --git a/libs/device-manager/feature/src/selectors/get-devices.selector.ts b/libs/device-manager/feature/src/selectors/get-devices.selector.ts index c4144bccf6..55e461e6ea 100644 --- a/libs/device-manager/feature/src/selectors/get-devices.selector.ts +++ b/libs/device-manager/feature/src/selectors/get-devices.selector.ts @@ -4,14 +4,14 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { DeviceBaseProperties } from "device-protocol/models" +import { DeviceProperties } from "device-manager/models" import { getCoreDevicesSelector } from "core-device/feature" import { selectDevices } from "generic-view/store" export const getDevicesSelector = createSelector( getCoreDevicesSelector, selectDevices, - (coreDevices, apiDevices): DeviceBaseProperties[] => { + (coreDevices, apiDevices): DeviceProperties[] => { return [...coreDevices, ...Object.values(apiDevices)] } ) diff --git a/libs/device-manager/models/src/device-properties.interface.ts b/libs/device-manager/models/src/device-properties.interface.ts index 4e15705e14..5db02d84ed 100644 --- a/libs/device-manager/models/src/device-properties.interface.ts +++ b/libs/device-manager/models/src/device-properties.interface.ts @@ -6,6 +6,14 @@ import { DeviceBaseProperties } from "device-protocol/models" import { CaseColour } from "core-device/models" +export enum DeviceState { + Connected = "CONNECTED", + Configured = "CONFIGURED", + Initialized = "INITIALIZED", + Failed = "FAILED", +} + export interface DeviceProperties extends DeviceBaseProperties { caseColour?: CaseColour + state: DeviceState } diff --git a/libs/generic-view/models/src/lib/device.ts b/libs/generic-view/models/src/lib/device.ts index bbfd2d99d7..f53139f291 100644 --- a/libs/generic-view/models/src/lib/device.ts +++ b/libs/generic-view/models/src/lib/device.ts @@ -31,20 +31,12 @@ export interface DeviceConfiguration { features?: Features } -export enum DeviceState { - Connected = "CONNECTED", - Configured = "CONFIGURED", - Initialized = "INITIALIZED", - Failed = "FAILED", -} - export interface Device extends DeviceProperties, Partial { id: DeviceId serialNumber: string | undefined deviceType: DeviceType - state: DeviceState } export interface ConfiguredDevice diff --git a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts index 2000ede6d7..f11a9e29c1 100644 --- a/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts +++ b/libs/generic-view/store/src/lib/hooks/use-api-serial-port-listeners.ts @@ -7,7 +7,7 @@ import { useCallback, useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { answerMain, useDebouncedEventsHandler } from "shared/utils" import { DeviceProtocolMainEvent, DeviceType } from "device-protocol/models" -import { DeviceState } from "generic-view/models" +import { DeviceState } from "device-manager/models" import { DeviceBaseProperties } from "device-protocol/models" import { Dispatch } from "Core/__deprecated__/renderer/store" import { addDevice, removeDevice } from "../views/actions" diff --git a/libs/generic-view/store/src/lib/selectors/select-configured-devices.ts b/libs/generic-view/store/src/lib/selectors/select-configured-devices.ts index ee4acb234d..8a9ba360d3 100644 --- a/libs/generic-view/store/src/lib/selectors/select-configured-devices.ts +++ b/libs/generic-view/store/src/lib/selectors/select-configured-devices.ts @@ -4,7 +4,8 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { ConfiguredDevice, DeviceState } from "generic-view/models" +import { ConfiguredDevice } from "generic-view/models" +import { DeviceState } from "device-manager/models" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { selectDevices } from "./select-devices" diff --git a/libs/generic-view/store/src/lib/selectors/select-failed-devices.ts b/libs/generic-view/store/src/lib/selectors/select-failed-devices.ts index 0f7f9d517e..5379aef5c3 100644 --- a/libs/generic-view/store/src/lib/selectors/select-failed-devices.ts +++ b/libs/generic-view/store/src/lib/selectors/select-failed-devices.ts @@ -4,7 +4,8 @@ */ import { createSelector } from "@reduxjs/toolkit" -import { Device, DeviceState } from "generic-view/models" +import { Device } from "generic-view/models" +import { DeviceState } from "device-manager/models" import { selectDevices } from "./select-devices" export const selectFailedDevices = createSelector( diff --git a/libs/generic-view/store/src/lib/views/actions.ts b/libs/generic-view/store/src/lib/views/actions.ts index 412e957bfa..4a3c278805 100644 --- a/libs/generic-view/store/src/lib/views/actions.ts +++ b/libs/generic-view/store/src/lib/views/actions.ts @@ -5,7 +5,7 @@ import { createAction } from "@reduxjs/toolkit" import { View } from "generic-view/utils" -import { DeviceState } from "generic-view/models" +import { DeviceState } from "device-manager/models" import { DeviceBaseProperties } from "device-protocol/models" import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-elements" import { ActionName } from "../action-names" diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index 4a186af390..be8e4cede0 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -6,7 +6,8 @@ import { createReducer } from "@reduxjs/toolkit" import { MenuElement } from "Core/__deprecated__/renderer/constants/menu-elements" import { View } from "generic-view/utils" -import { Device, DeviceState, Features } from "generic-view/models" +import { DeviceState } from "device-manager/models" +import { Device, Features } from "generic-view/models" import { ApiError } from "device/models" import { AppError } from "Core/core/errors" import { getAPIConfig } from "../get-api-config" From df70d1a16dcc502d2970778b8d78116ddb846e69 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Wed, 26 Jun 2024 10:12:26 +0200 Subject: [PATCH 029/100] [CP-2901] Handle error from `getMenuConfig` request when device is in `"initialized"` state --- .../devices-initialization.component.tsx | 18 ++++++++++++++++-- .../feature/src/selectors/index.ts | 1 + .../is-active-device-failed.selector.ts | 15 +++++++++++++++ .../lib/selectors/active-device-menu-items.ts | 14 ++++++-------- .../store/src/lib/views/reducer.ts | 11 ++++++++++- 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 libs/device-manager/feature/src/selectors/is-active-device-failed.selector.ts diff --git a/libs/core/device-initialization/components/devices-initialization.component.tsx b/libs/core/device-initialization/components/devices-initialization.component.tsx index 6f8f328bb8..f90a7d74e5 100644 --- a/libs/core/device-initialization/components/devices-initialization.component.tsx +++ b/libs/core/device-initialization/components/devices-initialization.component.tsx @@ -3,11 +3,16 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import React from "react" +import React, { useEffect } from "react" import { useSelector } from "react-redux" +import { useHistory } from "react-router-dom" import { FunctionComponent } from "Core/core/types/function-component.interface" import ConnectingContent from "Core/connecting/components/connecting-content.component" -import { getActiveDevice } from "device-manager/feature" +import { URL_ONBOARDING } from "Core/__deprecated__/renderer/constants/urls" +import { + getActiveDevice, + isActiveDeviceFailedSelector, +} from "device-manager/feature" import { DeviceBaseProperties, DeviceType } from "device-protocol/models" import { MuditaPureInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-pure-initialization-modal-flow" import { MuditaHarmonyInitializationModalFlow } from "Core/device-initialization/components/devices-initialization-modal-flows/mudita-harmony-initialization-modal-flow" @@ -28,7 +33,16 @@ const DevicesInitializationModalFlow: FunctionComponent<{ } const DevicesInitialization: FunctionComponent = () => { + const history = useHistory() const activeDevice = useSelector(getActiveDevice) + const activeDeviceFailedSelector = useSelector(isActiveDeviceFailedSelector) + + useEffect(() => { + if (activeDeviceFailedSelector) { + history.push(URL_ONBOARDING.troubleshooting) + } + }, [activeDeviceFailedSelector, history]) + return ( <> diff --git a/libs/device-manager/feature/src/selectors/index.ts b/libs/device-manager/feature/src/selectors/index.ts index 5477b51189..39fd59b6a8 100644 --- a/libs/device-manager/feature/src/selectors/index.ts +++ b/libs/device-manager/feature/src/selectors/index.ts @@ -13,4 +13,5 @@ export * from "./get-configured-devices.selector" export * from "./get-devices.selector" export * from "./get-failed-devices.selector" export * from "./is-active-device-attached.selector" +export * from "./is-active-device-failed.selector" export * from "./is-device-list-empty.selector" diff --git a/libs/device-manager/feature/src/selectors/is-active-device-failed.selector.ts b/libs/device-manager/feature/src/selectors/is-active-device-failed.selector.ts new file mode 100644 index 0000000000..d060490fea --- /dev/null +++ b/libs/device-manager/feature/src/selectors/is-active-device-failed.selector.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { DeviceState } from "device-manager/models" +import { getActiveDevice } from "./get-active-device.selector" + +export const isActiveDeviceFailedSelector = createSelector( + getActiveDevice, + (activeDevice): boolean => { + return activeDevice?.state === DeviceState.Failed + } +) diff --git a/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts b/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts index 2c263569ae..963c4b5789 100644 --- a/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts +++ b/libs/generic-view/store/src/lib/selectors/active-device-menu-items.ts @@ -5,16 +5,14 @@ import { createSelector } from "@reduxjs/toolkit" import { generateMenu } from "generic-view/utils" -import { selectActiveApiDeviceId } from "./select-active-api-device-id" -import { selectConfiguredDevices } from "./select-configured-devices" +import { selectActiveDeviceConfiguration } from "./active-device-configuration" export const activeDeviceMenuItems = createSelector( - [selectActiveApiDeviceId, selectConfiguredDevices], - (activeDeviceId, configuredDevices) => { - if (activeDeviceId) { - return configuredDevices[activeDeviceId].menuConfig - } - return undefined + [selectActiveDeviceConfiguration], + (activeDeviceConfiguration) => { + return activeDeviceConfiguration + ? activeDeviceConfiguration.menuConfig + : undefined } ) diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index be8e4cede0..b809d8211a 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -19,7 +19,8 @@ import { getOutboxData } from "../outbox/get-outbox-data.action" import { getGenericConfig } from "../features/get-generic-config.actions" import { addDevice, - removeDevice, setLastRefresh, + removeDevice, + setLastRefresh, setMenu, setViewData, setViewLayout, @@ -107,6 +108,14 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { if (apiError && ApiError[apiError]) { state.apiErrors[apiError] = true } + + const id = action.meta.arg.deviceId + const device = state.devices[id] + + state.devices[id] = { + ...device, + state: DeviceState.Failed, + } }) builder.addCase(getAPIAny.fulfilled, (state, action) => { state.lastResponse = action.payload From e1d897462274d6ad7635ab7a3a910f78c1380fbe Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Wed, 26 Jun 2024 10:45:02 +0200 Subject: [PATCH 030/100] [CP-2901] connectionTimeOut added to GetMenuConfig & APIConfig --- .../feature/src/lib/api-config/api-config.service.ts | 3 +++ libs/device/feature/src/lib/menu/menu.service.ts | 3 +++ libs/device/models/src/lib/api-request.model.ts | 1 + libs/generic-view/store/src/lib/views/reducer.ts | 12 +++++++----- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libs/device/feature/src/lib/api-config/api-config.service.ts b/libs/device/feature/src/lib/api-config/api-config.service.ts index 4001edab65..a3962aee92 100644 --- a/libs/device/feature/src/lib/api-config/api-config.service.ts +++ b/libs/device/feature/src/lib/api-config/api-config.service.ts @@ -35,6 +35,9 @@ export class APIConfigService { endpoint: "API_CONFIGURATION", method: "GET", body: {}, + options: { + connectionTimeOut: 1000 + } }) if (response.ok) { diff --git a/libs/device/feature/src/lib/menu/menu.service.ts b/libs/device/feature/src/lib/menu/menu.service.ts index 196b4b3286..898abc7907 100644 --- a/libs/device/feature/src/lib/menu/menu.service.ts +++ b/libs/device/feature/src/lib/menu/menu.service.ts @@ -36,6 +36,9 @@ export class APIMenuService { body: { lang: "en-US", }, + options: { + connectionTimeOut: 1000 + } }) if (response.ok) { const menuConfig = MenuConfigValidator.safeParse(response.data.body) diff --git a/libs/device/models/src/lib/api-request.model.ts b/libs/device/models/src/lib/api-request.model.ts index eb4ce4f9a0..9bca8acd77 100644 --- a/libs/device/models/src/lib/api-request.model.ts +++ b/libs/device/models/src/lib/api-request.model.ts @@ -58,6 +58,7 @@ export interface APIRequestWithPayload< Body = Record > extends APIRequestConfig { body?: Body + options?: { connectionTimeOut?: number } } export interface APIRequestData { diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index b809d8211a..c22a45bb0b 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -109,12 +109,14 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { state.apiErrors[apiError] = true } - const id = action.meta.arg.deviceId - const device = state.devices[id] + if(apiError !== ApiError.DeviceLocked){ + const id = action.meta.arg.deviceId + const device = state.devices[id] - state.devices[id] = { - ...device, - state: DeviceState.Failed, + state.devices[id] = { + ...device, + state: DeviceState.Failed, + } } }) builder.addCase(getAPIAny.fulfilled, (state, action) => { From 56935529e3acf96b383eb7e7d98a3118d517b79a Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 28 Jun 2024 09:00:35 +0200 Subject: [PATCH 031/100] [CP-2897] Implement Alternative Device Deactivation Strategy --- .../core/hooks/use-device-connected-effect.ts | 13 ++++++- .../api-device-initialization-modal-flow.tsx | 34 +++++++++++++------ .../feature/src/selectors/index.ts | 1 + .../is-active-api-device-locked.selector.ts | 19 +++++++++++ .../store/src/lib/selectors/index.ts | 1 + .../is-device-locked-error.selector.ts | 15 ++++++++ .../store/src/lib/views/reducer.ts | 2 +- 7 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 libs/device-manager/feature/src/selectors/is-active-api-device-locked.selector.ts create mode 100644 libs/generic-view/store/src/lib/selectors/is-device-locked-error.selector.ts diff --git a/libs/core/core/hooks/use-device-connected-effect.ts b/libs/core/core/hooks/use-device-connected-effect.ts index 6cd0c1cb83..aa5a220142 100644 --- a/libs/core/core/hooks/use-device-connected-effect.ts +++ b/libs/core/core/hooks/use-device-connected-effect.ts @@ -7,7 +7,11 @@ import { useCallback, useEffect } from "react" import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" import { answerMain } from "shared/utils" -import { getDevicesSelector } from "device-manager/feature" +import { + deactivateDevice, + getDevicesSelector, + isActiveApiDeviceLockedSelector, +} from "device-manager/feature" import { setActiveDevice, activeDeviceIdSelector, @@ -40,12 +44,18 @@ export const useDeviceConnectedEffect = () => { const dispatch = useDispatch() const activeDeviceId = useSelector(activeDeviceIdSelector) + const activeApiDeviceLocked = useSelector(isActiveApiDeviceLockedSelector) const shouldDiscoverySkipOnConnect = useDiscoverySkipOnConnect() const continueProcess = useContinueProcess() useEffect(() => { const handler = async (properties: DeviceBaseProperties) => { + if (activeApiDeviceLocked) { + await dispatch(deactivateDevice()) + dispatch(setDiscoveryStatus(DiscoveryStatus.Aborted)) + } + if (activeDeviceId) { await continueProcess(properties) return @@ -66,6 +76,7 @@ export const useDeviceConnectedEffect = () => { activeDeviceId, continueProcess, shouldDiscoverySkipOnConnect, + activeApiDeviceLocked, ]) } diff --git a/libs/core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow.tsx b/libs/core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow.tsx index 1946557bcb..b25337cff1 100644 --- a/libs/core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow.tsx +++ b/libs/core/device-initialization/components/devices-initialization-modal-flows/api-device-initialization-modal-flow.tsx @@ -8,8 +8,13 @@ import React, { useCallback, useEffect, useMemo, useRef } from "react" import { useDispatch, useSelector } from "react-redux" import { useHistory } from "react-router-dom" -import { FunctionComponent } from "Core/core/types/function-component.interface" -import { Dispatch, ReduxRootState } from "Core/__deprecated__/renderer/store" +import { defineMessages } from "react-intl" +import ReactModal from "react-modal" +import styled from "styled-components" +import { useFilteredRoutesHistory } from "shared/utils" +import { useDataMigrationDeviceSelector } from "shared/feature" +import { ApiError } from "device/models" +import { getDevicesSelector } from "device-manager/feature" import { selectActiveDeviceMenuElements, selectApiError, @@ -17,25 +22,22 @@ import { selectDataMigrationTargetDevice, setSourceDevice, } from "generic-view/store" -import { ApiError } from "device/models" -import { intl } from "Core/__deprecated__/renderer/utils/intl" -import { defineMessages } from "react-intl" import { Modal, SpinnerLoader } from "generic-view/ui" import { GenericThemeProvider } from "generic-view/theme" import { ButtonAction, IconType } from "generic-view/utils" +import { FunctionComponent } from "Core/core/types/function-component.interface" +import { Dispatch, ReduxRootState } from "Core/__deprecated__/renderer/store" +import { intl } from "Core/__deprecated__/renderer/utils/intl" import { ModalLayers } from "Core/modals-manager/constants/modal-layers.enum" -import ReactModal from "react-modal" -import styled from "styled-components" import { URL_DEVICE_INITIALIZATION, URL_DISCOVERY_DEVICE, URL_MAIN, URL_ONBOARDING, } from "Core/__deprecated__/renderer/constants/urls" -import { useFilteredRoutesHistory } from "shared/utils" import { setDeviceInitializationStatus } from "Core/device-initialization/actions/base.action" import { DeviceInitializationStatus } from "Core/device-initialization/reducers/device-initialization.interface" -import { useDataMigrationDeviceSelector } from "shared/feature" +import { useDeactivateDeviceAndRedirect } from "Core/overview/components/overview-screens/pure-overview/use-deactivate-device-and-redirect.hook" const messages = defineMessages({ connectingModalParagraph: { @@ -52,6 +54,8 @@ const messages = defineMessages({ export const APIDeviceInitializationModalFlow: FunctionComponent = () => { const history = useHistory() const dispatch = useDispatch() + const devices = useSelector(getDevicesSelector) + const deactivateDeviceAndRedirect = useDeactivateDeviceAndRedirect() const selectDevice = useDataMigrationDeviceSelector() const firstRenderTime = useRef(Date.now()) const deviceLocked = useSelector((state: ReduxRootState) => { @@ -101,10 +105,20 @@ export const APIDeviceInitializationModalFlow: FunctionComponent = () => { URL_MAIN.dataMigration ) dispatch(setSourceDevice(undefined)) + } else if (devices.length > 1) { + await deactivateDeviceAndRedirect() } else { history.push(pathToGoBack || URL_MAIN.news) } - }, [dataMigrationSourceDevice, dispatch, history, pathToGoBack, selectDevice]) + }, [ + dataMigrationSourceDevice, + dispatch, + history, + pathToGoBack, + selectDevice, + devices.length, + deactivateDeviceAndRedirect, + ]) const modalCloseAction: ButtonAction = { type: "custom", diff --git a/libs/device-manager/feature/src/selectors/index.ts b/libs/device-manager/feature/src/selectors/index.ts index 39fd59b6a8..3ce76ac830 100644 --- a/libs/device-manager/feature/src/selectors/index.ts +++ b/libs/device-manager/feature/src/selectors/index.ts @@ -12,6 +12,7 @@ export * from "./get-available-devices.selector" export * from "./get-configured-devices.selector" export * from "./get-devices.selector" export * from "./get-failed-devices.selector" +export * from "./is-active-api-device-locked.selector" export * from "./is-active-device-attached.selector" export * from "./is-active-device-failed.selector" export * from "./is-device-list-empty.selector" diff --git a/libs/device-manager/feature/src/selectors/is-active-api-device-locked.selector.ts b/libs/device-manager/feature/src/selectors/is-active-api-device-locked.selector.ts new file mode 100644 index 0000000000..abb3029d0d --- /dev/null +++ b/libs/device-manager/feature/src/selectors/is-active-api-device-locked.selector.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { DeviceType } from "device-protocol/models" +import { isDeviceLockedErrorSelector } from "generic-view/store" +import { getActiveDevice } from "./get-active-device.selector" + +export const isActiveApiDeviceLockedSelector = createSelector( + getActiveDevice, + isDeviceLockedErrorSelector, + (activeDevice, deviceLockedError): boolean => { + return ( + activeDevice?.deviceType === DeviceType.APIDevice && deviceLockedError + ) + } +) diff --git a/libs/generic-view/store/src/lib/selectors/index.ts b/libs/generic-view/store/src/lib/selectors/index.ts index f62f8fd044..f371e62e7f 100644 --- a/libs/generic-view/store/src/lib/selectors/index.ts +++ b/libs/generic-view/store/src/lib/selectors/index.ts @@ -18,6 +18,7 @@ export * from "./backup-restore" export * from "./import-status-selector" export * from "./import-contacts-selector" export * from "./import-contacts-progress" +export * from "./is-device-locked-error.selector" export * from "./data-migration-devices" export * from "./data-migration-features" export * from "./data-migration-status" diff --git a/libs/generic-view/store/src/lib/selectors/is-device-locked-error.selector.ts b/libs/generic-view/store/src/lib/selectors/is-device-locked-error.selector.ts new file mode 100644 index 0000000000..8e149df76d --- /dev/null +++ b/libs/generic-view/store/src/lib/selectors/is-device-locked-error.selector.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { createSelector } from "@reduxjs/toolkit" +import { ApiError } from "device/models" +import { selectGenericViewState } from "./select-generic-view-state" + +export const isDeviceLockedErrorSelector = createSelector( + selectGenericViewState, + (genericState): boolean => { + return genericState.apiErrors[ApiError.DeviceLocked] + } +) diff --git a/libs/generic-view/store/src/lib/views/reducer.ts b/libs/generic-view/store/src/lib/views/reducer.ts index c22a45bb0b..4957d9fd36 100644 --- a/libs/generic-view/store/src/lib/views/reducer.ts +++ b/libs/generic-view/store/src/lib/views/reducer.ts @@ -109,7 +109,7 @@ export const genericViewsReducer = createReducer(initialState, (builder) => { state.apiErrors[apiError] = true } - if(apiError !== ApiError.DeviceLocked){ + if (apiError !== ApiError.DeviceLocked) { const id = action.meta.arg.deviceId const device = state.devices[id] From 9915421b121b131dccfa4085984a570aa2b4c01e Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 28 Jun 2024 16:21:06 +0200 Subject: [PATCH 032/100] [CP-2902] Merge both file-system-dialogs to single implementation --- libs/core/core/application.module.ts | 5 +- .../feature/src/lib/file-manager/index.ts | 1 - .../lib/imports/import-contacts-from.file.ts | 18 ++++--- libs/shared/app-state/src/index.ts | 1 - .../lib/dialog-file-system/error.constant.ts | 8 --- .../file-system-dialog.controller.ts | 19 ------- .../file-system-dialog.module.ts | 22 -------- .../file-system-dialog.service.test.ts | 42 --------------- .../file-system-dialog.service.ts | 46 ---------------- .../dialog-file-system/get-paths.action.ts | 4 +- .../dialog-file-system/get-paths.request.ts | 15 ------ libs/system-utils/feature/src/index.ts | 1 + .../lib/file-dialog/file-dialog.service.ts | 52 +++++++++++++------ .../src/lib/file-dialog/open-file.request.ts} | 10 ++-- libs/system-utils/models/src/index.ts | 1 + .../src/lib/file-dialog-service-error.ts} | 4 +- .../src/lib/file-dialog-service-events.ts | 2 +- 17 files changed, 59 insertions(+), 192 deletions(-) delete mode 100644 libs/shared/app-state/src/lib/dialog-file-system/error.constant.ts delete mode 100644 libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.controller.ts delete mode 100644 libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.module.ts delete mode 100644 libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.service.test.ts delete mode 100644 libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.service.ts delete mode 100644 libs/shared/app-state/src/lib/dialog-file-system/get-paths.request.ts rename libs/{device/feature/src/lib/file-manager/select-single-file.request.ts => system-utils/feature/src/lib/file-dialog/open-file.request.ts} (65%) rename libs/{shared/app-state/src/lib/dialog-file-system/controller.constant.ts => system-utils/models/src/lib/file-dialog-service-error.ts} (64%) diff --git a/libs/core/core/application.module.ts b/libs/core/core/application.module.ts index 9e7f5908b4..200c6238dc 100644 --- a/libs/core/core/application.module.ts +++ b/libs/core/core/application.module.ts @@ -46,7 +46,7 @@ import { } from "device-protocol/feature" import { APIModule } from "device/feature" import { DesktopModule } from "Core/desktop/desktop.module" -import { FileSystemDialogModule, OnlineStatusModule } from "shared/app-state" +import { OnlineStatusModule } from "shared/app-state" import { SystemUtilsModule } from "system-utils/feature" import { MockDeviceResolverService, mockServiceEnabled } from "e2e-mock-server" import { ApplicationUpdaterModule } from "electron/application-updater" @@ -124,9 +124,6 @@ export class ApplicationModule { createSettingsService() ) this.controllerInitializer.initialize(this.apiModule.getAPIServices()) - this.controllerInitializer.initialize( - FileSystemDialogModule.getControllers() - ) this.controllerInitializer.initialize(this.systemUtilsModule.getServices()) this.controllerInitializer.initialize( new ApplicationUpdaterModule().controllers diff --git a/libs/device/feature/src/lib/file-manager/index.ts b/libs/device/feature/src/lib/file-manager/index.ts index 88c24f9955..3ee3964211 100644 --- a/libs/device/feature/src/lib/file-manager/index.ts +++ b/libs/device/feature/src/lib/file-manager/index.ts @@ -14,4 +14,3 @@ export * from "./clear-file.request" export * from "./get-backup-path.request" export * from "./secure-backup-password.request" export * from "./read-and-get-file.request" -export * from "./select-single-file.request" diff --git a/libs/generic-view/store/src/lib/imports/import-contacts-from.file.ts b/libs/generic-view/store/src/lib/imports/import-contacts-from.file.ts index d7fa3e21db..2de1e5dd97 100644 --- a/libs/generic-view/store/src/lib/imports/import-contacts-from.file.ts +++ b/libs/generic-view/store/src/lib/imports/import-contacts-from.file.ts @@ -7,7 +7,8 @@ import { createAsyncThunk } from "@reduxjs/toolkit" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { ActionName } from "../action-names" import { UnifiedContact } from "device/models" -import { readAndGetFileRequest, selectSingleFileRequest } from "device/feature" +import { readAndGetFileRequest } from "device/feature" +import { openFileRequest } from "system-utils/feature" import { detect } from "jschardet" import { parseCsv } from "./contacts-mappers/csv/parse-csv" import { mapCsv } from "./contacts-mappers/csv/map-csv" @@ -49,7 +50,8 @@ export const importContactsFromFile = createAsyncThunk< return rejectWithValue(intl.formatMessage(messages.errorMessage)) } try { - const filePathResult = await selectSingleFileRequest({ + const openFileResult = await openFileRequest({ + properties: ["openFile"], title: intl.formatMessage(messages.dialogTitle), filters: [ { @@ -58,17 +60,19 @@ export const importContactsFromFile = createAsyncThunk< }, ], }) - if (!filePathResult.ok) { + if (!openFileResult.ok) { cleanImportProcess() return rejectWithValue("cancelled") } - const fileResponse = await readAndGetFileRequest(filePathResult.data) + const filePath = openFileResult.data[0] + + const fileResponse = await readAndGetFileRequest(filePath) if (!fileResponse.ok) { return handleError() } - const fileBuffer = Buffer.from(fileResponse.data) + const fileBuffer = Buffer.from(filePath) const { encoding } = detect(fileBuffer) const content = fileBuffer.toString(encoding as BufferEncoding) @@ -77,9 +81,9 @@ export const importContactsFromFile = createAsyncThunk< } switch (true) { - case filePathResult.data.endsWith(".csv"): + case filePath.endsWith(".csv"): return mapCsv(parseCsv(content)).map(addMissingFields) - case filePathResult.data.endsWith(".vcf"): + case filePath.endsWith(".vcf"): return mapVcard(parseVcard(content)).map(addMissingFields) default: return handleError() diff --git a/libs/shared/app-state/src/index.ts b/libs/shared/app-state/src/index.ts index c1e65a8c73..283856480a 100644 --- a/libs/shared/app-state/src/index.ts +++ b/libs/shared/app-state/src/index.ts @@ -4,7 +4,6 @@ */ export * from "./lib/dialog-file-system/get-paths.action" -export * from "./lib/dialog-file-system/file-system-dialog.module" export * from "./lib/online-status/use-online-listener" export * from "./lib/online-status/online-status.module" export * from "./lib/online-status/online-status.requests" diff --git a/libs/shared/app-state/src/lib/dialog-file-system/error.constant.ts b/libs/shared/app-state/src/lib/dialog-file-system/error.constant.ts deleted file mode 100644 index 5d789bf6e6..0000000000 --- a/libs/shared/app-state/src/lib/dialog-file-system/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 FileSystemDialogError { - GetPath = "file-system-dialog_get-paths-error", -} diff --git a/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.controller.ts b/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.controller.ts deleted file mode 100644 index a612f09dc6..0000000000 --- a/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.controller.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 { OpenDialogOptions } from "electron" -import { IpcEvent } from "Core/core/decorators" -import { ResultObject } from "Core/core/builder" -import { IpcFileSystemDialogEvent } from "./controller.constant" -import { FileSystemDialogService } from "./file-system-dialog.service" - -export class FileSystemDialogController { - constructor(private filesSystemDialogService: FileSystemDialogService) {} - - @IpcEvent(IpcFileSystemDialogEvent.GetPaths) - public async getPaths(options: OpenDialogOptions): Promise> { - return this.filesSystemDialogService.getPaths(options) - } -} diff --git a/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.module.ts b/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.module.ts deleted file mode 100644 index 71c58b2db1..0000000000 --- a/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.module.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 { BrowserWindow } from "electron" -import { getMainAppWindow } from "shared/utils" -import { FileSystemDialogService } from "./file-system-dialog.service" -import { FileSystemDialogController } from "./file-system-dialog.controller" - -export class FileSystemDialogModule { - constructor() {} - - static getControllers() { - const window = getMainAppWindow() as BrowserWindow - const filesSystemDialogService = new FileSystemDialogService(window) - const fileSystemDialogController = new FileSystemDialogController( - filesSystemDialogService - ) - return [fileSystemDialogController] - } -} diff --git a/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.service.test.ts b/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.service.test.ts deleted file mode 100644 index 3640493bae..0000000000 --- a/libs/shared/app-state/src/lib/dialog-file-system/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, BrowserWindow } from "electron" -import { Result } from "Core/core/builder" -import { AppError } from "Core/core/errors" -import { FileSystemDialogService } from "./file-system-dialog.service" -import { FileSystemDialogError } from "./error.constant" - -jest.mock("electron", () => ({ - dialog: { - showOpenDialog: jest.fn(), - }, -})) - -const subject = new FileSystemDialogService({} as BrowserWindow) - -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(FileSystemDialogError.GetPath, "Luke, I'm your error") - ) - ) -}) diff --git a/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.service.ts b/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.service.ts deleted file mode 100644 index c317eee102..0000000000 --- a/libs/shared/app-state/src/lib/dialog-file-system/file-system-dialog.service.ts +++ /dev/null @@ -1,46 +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 { BrowserWindow, dialog, OpenDialogOptions } from "electron" -import { intl } from "Core/__deprecated__/renderer/utils/intl" -import { AppError } from "Core/core/errors" -import { Result, ResultObject } from "Core/core/builder" -import { FileSystemDialogError } from "./error.constant" - -const defaultOptions: OpenDialogOptions = { - title: intl.formatMessage({ id: "component.dialog.title" }), - filters: [], - properties: [], -} - -export class FileSystemDialogService { - private lastSelectedPath: string | undefined - - constructor(private mainApplicationWindow: BrowserWindow) {} - public async getPaths( - options: OpenDialogOptions = defaultOptions - ): Promise> { - try { - const openDialogOptions = { - ...defaultOptions, - ...options, - defaultPath: options.defaultPath || this.lastSelectedPath - } - const result = await dialog.showOpenDialog( - this.mainApplicationWindow, - openDialogOptions - ) - this.lastSelectedPath = result.filePaths[0] - return Result.success(result.filePaths) - } catch (error) { - return Result.failed( - new AppError( - FileSystemDialogError.GetPath, - error ? (error as Error).message : "Something went wrong" - ) - ) - } - } -} diff --git a/libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.ts b/libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.ts index 9e5a2a8d32..122c6044ac 100644 --- a/libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.ts +++ b/libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.ts @@ -5,15 +5,15 @@ import { OpenDialogOptions } from "electron" import { createAsyncThunk } from "@reduxjs/toolkit" +import { openFileRequest } from "system-utils/feature" import { ResultObject } from "Core/core/builder" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { ActionName } from "../action-name" -import { getPathsRequest } from "./get-paths.request" export const getPaths = createAsyncThunk< ResultObject, OpenDialogOptions, { state: ReduxRootState } >(ActionName.GetPaths, (options) => { - return getPathsRequest(options) + return openFileRequest(options) }) diff --git a/libs/shared/app-state/src/lib/dialog-file-system/get-paths.request.ts b/libs/shared/app-state/src/lib/dialog-file-system/get-paths.request.ts deleted file mode 100644 index 2b73b08248..0000000000 --- a/libs/shared/app-state/src/lib/dialog-file-system/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 { OpenDialogOptions } from "electron" -import { ipcRenderer } from "electron-better-ipc" -import { ResultObject } from "Core/core/builder" -import { IpcFileSystemDialogEvent } from "./controller.constant" - -export const getPathsRequest = async ( - options: OpenDialogOptions -): Promise> => { - return ipcRenderer.callMain(IpcFileSystemDialogEvent.GetPaths, options) -} diff --git a/libs/system-utils/feature/src/index.ts b/libs/system-utils/feature/src/index.ts index 01a4f31c0e..f7d1a5656d 100644 --- a/libs/system-utils/feature/src/index.ts +++ b/libs/system-utils/feature/src/index.ts @@ -4,3 +4,4 @@ */ export * from "./lib/system-utils.module" +export * from "./lib/file-dialog/open-file.request" diff --git a/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts b/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts index f941d3adf2..de567d2d47 100644 --- a/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts +++ b/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts @@ -4,32 +4,50 @@ */ import { dialog, OpenDialogOptions, BrowserWindow } from "electron" +import { FileDialogServiceEvents, FileDialogError } from "system-utils/models" import { IpcEvent } from "Core/core/decorators" -import { FileDialogServiceEvents } from "system-utils/models" -import { Result } from "Core/core/builder" +import { Result, ResultObject } from "Core/core/builder" +import { intl } from "Core/__deprecated__/renderer/utils/intl" import { AppError } from "Core/core/errors" -import { GeneralError } from "device/models" + +const defaultOptions: OpenDialogOptions = { + title: intl.formatMessage({ id: "component.dialog.title" }), + filters: [], + properties: [], +} export class FileDialog { + private lastSelectedPath: string | undefined + constructor() {} - @IpcEvent(FileDialogServiceEvents.SelectSingleFile) - public openFile({ - options, - }: { options?: Omit } = {}) { - const selectedFile = dialog.showOpenDialogSync( - BrowserWindow.getFocusedWindow() as BrowserWindow, - { - properties: ["openFile"], - title: "Open File", - filters: [{ name: "All Files", extensions: ["*"] }], + @IpcEvent(FileDialogServiceEvents.OpenFile) + public async openFile({ + options = defaultOptions, + }: { + options?: OpenDialogOptions + }): Promise> { + try { + const openDialogOptions = { + ...defaultOptions, ...options, + defaultPath: options.defaultPath || this.lastSelectedPath, } - ) - if (!selectedFile || selectedFile.length === 0) { - return Result.failed(new AppError(GeneralError.UserCancelled)) + const result = await dialog.showOpenDialog( + BrowserWindow.getFocusedWindow() as BrowserWindow, + openDialogOptions + ) + this.lastSelectedPath = result.filePaths[0] + + return Result.success(result.filePaths) + } catch (error) { + return Result.failed( + new AppError( + FileDialogError.OpenFile, + error ? (error as Error).message : undefined + ) + ) } - return Result.success(selectedFile[0]) } } diff --git a/libs/device/feature/src/lib/file-manager/select-single-file.request.ts b/libs/system-utils/feature/src/lib/file-dialog/open-file.request.ts similarity index 65% rename from libs/device/feature/src/lib/file-manager/select-single-file.request.ts rename to libs/system-utils/feature/src/lib/file-dialog/open-file.request.ts index ac098d96ea..ebb031aaa9 100644 --- a/libs/device/feature/src/lib/file-manager/select-single-file.request.ts +++ b/libs/system-utils/feature/src/lib/file-dialog/open-file.request.ts @@ -3,15 +3,15 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { ResultObject } from "Core/core/builder" import { ipcRenderer } from "electron-better-ipc" import { OpenDialogOptions } from "electron" import { FileDialogServiceEvents } from "system-utils/models" +import { ResultObject } from "Core/core/builder" -export const selectSingleFileRequest = ( - options: Omit -): Promise> => { - return ipcRenderer.callMain(FileDialogServiceEvents.SelectSingleFile, { +export const openFileRequest = ( + options: OpenDialogOptions +): Promise> => { + return ipcRenderer.callMain(FileDialogServiceEvents.OpenFile, { options, }) } diff --git a/libs/system-utils/models/src/index.ts b/libs/system-utils/models/src/index.ts index 58babe21e8..2928ccfd92 100644 --- a/libs/system-utils/models/src/index.ts +++ b/libs/system-utils/models/src/index.ts @@ -4,4 +4,5 @@ */ export * from "./lib/directory-service-events" +export * from "./lib/file-dialog-service-error" export * from "./lib/file-dialog-service-events" diff --git a/libs/shared/app-state/src/lib/dialog-file-system/controller.constant.ts b/libs/system-utils/models/src/lib/file-dialog-service-error.ts similarity index 64% rename from libs/shared/app-state/src/lib/dialog-file-system/controller.constant.ts rename to libs/system-utils/models/src/lib/file-dialog-service-error.ts index c8f296d035..babae1e975 100644 --- a/libs/shared/app-state/src/lib/dialog-file-system/controller.constant.ts +++ b/libs/system-utils/models/src/lib/file-dialog-service-error.ts @@ -3,6 +3,6 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export enum IpcFileSystemDialogEvent { - GetPaths = "file-system-dialog_get-paths", +export enum FileDialogError { + OpenFile = "file-dialog/open-file-error", } diff --git a/libs/system-utils/models/src/lib/file-dialog-service-events.ts b/libs/system-utils/models/src/lib/file-dialog-service-events.ts index 5ea55f1fee..f0713073cd 100644 --- a/libs/system-utils/models/src/lib/file-dialog-service-events.ts +++ b/libs/system-utils/models/src/lib/file-dialog-service-events.ts @@ -4,5 +4,5 @@ */ export enum FileDialogServiceEvents { - SelectSingleFile = "directoryservice-open-file", + OpenFile = "file-dialog/open-file", } From a95633ea4f053153dbeba4791ff8d50624827eac Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Fri, 28 Jun 2024 16:51:45 +0200 Subject: [PATCH 033/100] [CP-2902] Add global listener for file dialog open and close events (strategy changed) --- .../contacts/contacts.component.test.tsx | 2 +- .../contacts/contacts.component.tsx | 11 +++----- .../components/contacts/contacts.interface.ts | 4 +-- .../components/contacts/contacts.stories.tsx | 2 +- libs/core/contacts/contacts.container.tsx | 20 +++++++++----- .../apps/base-app/base-app.component.tsx | 3 ++- .../actions/get-paths-wrapper.ts | 22 ---------------- .../actions/upload-file.action.ts | 8 +++--- .../components/backup/backup.component.tsx | 21 +++++---------- libs/shared/app-state/src/index.ts | 2 +- libs/shared/app-state/src/lib/action-name.ts | 2 +- .../app-state/src/lib/app-state.reducer.ts | 14 +++------- .../dialog-file-system/get-paths.action.ts | 19 -------------- .../src/lib/dialog-open-status/base.action.ts | 11 ++++++++ .../use-file-dialog-event-listener.ts | 26 +++++++++++++++++++ .../utils/src/lib/call-renderer.helper.ts | 2 ++ .../lib/file-dialog/file-dialog.service.ts | 23 +++++++++++++--- .../src/lib/file-dialog/open-file.request.ts | 4 +-- .../src/lib/file-dialog-service-events.ts | 7 ++++- 19 files changed, 107 insertions(+), 96 deletions(-) delete mode 100644 libs/core/files-manager/actions/get-paths-wrapper.ts delete mode 100644 libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.ts create mode 100644 libs/shared/app-state/src/lib/dialog-open-status/base.action.ts create mode 100644 libs/shared/app-state/src/lib/dialog-open-status/use-file-dialog-event-listener.ts diff --git a/libs/core/contacts/components/contacts/contacts.component.test.tsx b/libs/core/contacts/components/contacts/contacts.component.test.tsx index bf7679260f..c24e15e9ab 100644 --- a/libs/core/contacts/components/contacts/contacts.component.test.tsx +++ b/libs/core/contacts/components/contacts/contacts.component.test.tsx @@ -176,7 +176,7 @@ const defaultProps: Props = { selectAllItems: jest.fn(), toggleItem: jest.fn(), closeImportWindow: jest.fn(), - getPaths: jest.fn(), + openFileRequest: jest.fn(), } const renderer = (extraProps?: Partial) => { diff --git a/libs/core/contacts/components/contacts/contacts.component.tsx b/libs/core/contacts/components/contacts/contacts.component.tsx index 29b9c3812c..2cf50007ea 100644 --- a/libs/core/contacts/components/contacts/contacts.component.tsx +++ b/libs/core/contacts/components/contacts/contacts.component.tsx @@ -23,10 +23,7 @@ import { ContactSection } from "Core/contacts/components/contacts/contacts.style import { defineMessages } from "react-intl" import useURLSearchParams from "Core/__deprecated__/renderer/utils/hooks/use-url-search-params" import findContactByPhoneNumber from "Core/contacts/helpers/find-contact-by-phone-number/find-contact-by-phone-number" -import { - ExternalProvider, - Provider, -} from "generic-view/store" +import { ExternalProvider, Provider } from "generic-view/store" import delayResponse from "@appnroll/delay-response" import { ErrorDataModal, @@ -99,7 +96,7 @@ const Contacts: FunctionComponent = ({ editContact, deleteContacts, authorize, - getPaths, + openFileRequest, exportContacts, addNewContactsToState, resetAllItems, @@ -433,7 +430,7 @@ const Contacts: FunctionComponent = ({ // Synchronization, step 2a: file select const importFromFile = async () => { - const { payload: getPathsPayload } = await getPaths({ + const openFileResult = await openFileRequest({ filters: [ { name: "vcf", @@ -442,7 +439,7 @@ const Contacts: FunctionComponent = ({ ], properties: ["openFile", "multiSelections"], }) - const { ok, data: paths } = getPathsPayload + const { ok, data: paths } = openFileResult const files = ok && paths !== undefined ? paths.map((path) => createFile(path)) : [] diff --git a/libs/core/contacts/components/contacts/contacts.interface.ts b/libs/core/contacts/components/contacts/contacts.interface.ts index 3561b3c187..1f9b86f3fb 100644 --- a/libs/core/contacts/components/contacts/contacts.interface.ts +++ b/libs/core/contacts/components/contacts/contacts.interface.ts @@ -68,9 +68,9 @@ export interface ContactsProps { resultState: ResultState contactList: ContactCategory[] closeImportWindow: (provider: ExternalProvider) => Promise - getPaths: ( + openFileRequest: ( options: OpenDialogOptions - ) => Promise>> + ) => Promise> } export interface NewContactResponse extends NewContact { diff --git a/libs/core/contacts/components/contacts/contacts.stories.tsx b/libs/core/contacts/components/contacts/contacts.stories.tsx index 0e547f2607..fd46fb35ae 100644 --- a/libs/core/contacts/components/contacts/contacts.stories.tsx +++ b/libs/core/contacts/components/contacts/contacts.stories.tsx @@ -90,7 +90,7 @@ const ContactsComponent = ({ selectAllItems={noop} toggleItem={noop} closeImportWindow={noop} - getPaths={noop} + openFileRequest={noop} /> ) diff --git a/libs/core/contacts/contacts.container.tsx b/libs/core/contacts/contacts.container.tsx index a83ffece93..7cb8b09002 100644 --- a/libs/core/contacts/contacts.container.tsx +++ b/libs/core/contacts/contacts.container.tsx @@ -43,9 +43,13 @@ import { selectAllItems, toggleItem, } from "Core/contacts/actions" -import { getPaths } from "shared/app-state" -import { googleGetContacts, outlookGetContacts, ExternalProvider, - Provider, } from "generic-view/store" +import { openFileRequest } from "system-utils/feature" +import { + googleGetContacts, + outlookGetContacts, + ExternalProvider, + Provider, +} from "generic-view/store" const mapStateToProps = (state: RootModel & ReduxRootState) => { const { contacts, auth } = state @@ -82,7 +86,8 @@ const mapDispatchToProps = (dispatch: TmpDispatch) => { contacts = // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/await-thenable - (await dispatch(googleGetContacts())).payload as unknown as Contact[] + (await dispatch(googleGetContacts())) + .payload as unknown as Contact[] return getContacts(contactDatabaseFactory(contacts)) case Provider.Apple: return @@ -90,7 +95,8 @@ const mapDispatchToProps = (dispatch: TmpDispatch) => { contacts = // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/await-thenable - (await dispatch(outlookGetContacts())).payload as unknown as Contact[] + (await dispatch(outlookGetContacts())) + .payload as unknown as Contact[] return getContacts(contactDatabaseFactory(contacts)) } }, @@ -151,10 +157,10 @@ const mapDispatchToProps = (dispatch: TmpDispatch) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call void dispatch(closeWindow(provider)) }, - getPaths: (options: OpenDialogOptions) => + openFileRequest: (options: OpenDialogOptions) => // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call - dispatch(getPaths(options)), + openFileRequest(options), } } diff --git a/libs/core/core/components/apps/base-app/base-app.component.tsx b/libs/core/core/components/apps/base-app/base-app.component.tsx index 31e21f192f..c32d58c4af 100644 --- a/libs/core/core/components/apps/base-app/base-app.component.tsx +++ b/libs/core/core/components/apps/base-app/base-app.component.tsx @@ -23,7 +23,7 @@ import { useBackupList, useAppEventsListeners, } from "generic-view/store" -import { useOnlineListener } from "shared/app-state" +import { useFileDialogEventListener, useOnlineListener } from "shared/app-state" import { useCoreDeviceProtocolListeners } from "core-device/feature" const BaseApp: FunctionComponent = () => { @@ -42,6 +42,7 @@ const BaseApp: FunctionComponent = () => { useAPISerialPortListeners() useAppEventsListeners() useBackupList() + useFileDialogEventListener() return ( <> diff --git a/libs/core/files-manager/actions/get-paths-wrapper.ts b/libs/core/files-manager/actions/get-paths-wrapper.ts deleted file mode 100644 index af90892d5b..0000000000 --- a/libs/core/files-manager/actions/get-paths-wrapper.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 { OpenDialogOptions } from "electron" -import { PayloadAction } from "@reduxjs/toolkit" -import { getPaths } from "shared/app-state" -import { ResultObject } from "Core/core/builder" -import { TmpDispatch } from "Core/__deprecated__/renderer/store" - -/** - * `getPathsWrapper` simplifies testing the `getPaths` thunk by isolating dispatch calls, - * addressing challenges with mocking `shared/app-state`. It streamlines unit testing, - * minimizing the need for direct involvement of the store and external APIs. - */ -export const getPathsWrapper = async ( - dispatch: TmpDispatch, - options: OpenDialogOptions -): Promise>> => - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - dispatch(getPaths(options)) diff --git a/libs/core/files-manager/actions/upload-file.action.ts b/libs/core/files-manager/actions/upload-file.action.ts index 32396b19c6..5aa1bbd40a 100644 --- a/libs/core/files-manager/actions/upload-file.action.ts +++ b/libs/core/files-manager/actions/upload-file.action.ts @@ -11,7 +11,7 @@ import { FilesManagerError, FilesManagerEvent, } from "Core/files-manager/constants" -import { getPathsWrapper } from "Core/files-manager/actions/get-paths-wrapper" +import { openFileRequest } from "system-utils/feature" import { uploadFilesRequest } from "Core/files-manager/requests" import { getFiles } from "Core/files-manager/actions/get-files.action" import { @@ -36,7 +36,7 @@ export const uploadFile = createAsyncThunk< FilesManagerEvent.UploadFiles, async (_, { getState, dispatch, rejectWithValue }) => { dispatch(setUploadBlocked(true)) - const { payload: getPathsPayload } = await getPathsWrapper(dispatch, { + const openFileResult = await openFileRequest({ filters: [ { name: "Audio", @@ -56,12 +56,12 @@ export const uploadFile = createAsyncThunk< return rejectWithValue("files are not yet loaded") } - if (!getPathsPayload.ok || !getPathsPayload.data) { + if (!openFileResult.ok || !openFileResult.data) { dispatch(setUploadBlocked(false)) return rejectWithValue("no files to upload") } - const filePaths = getPathsPayload.data + const filePaths = openFileResult.data if (filePaths.length === 0) { dispatch(setUploadBlocked(false)) diff --git a/libs/core/settings/components/backup/backup.component.tsx b/libs/core/settings/components/backup/backup.component.tsx index 02b362ddcb..677e417a57 100644 --- a/libs/core/settings/components/backup/backup.component.tsx +++ b/libs/core/settings/components/backup/backup.component.tsx @@ -4,13 +4,9 @@ */ import React from "react" -import { useDispatch } from "react-redux" -import { PayloadAction } from "@reduxjs/toolkit" +import { openFileRequest } from "system-utils/feature" import { FunctionComponent } from "Core/core/types/function-component.interface" import BackupUI from "Core/settings/components/backup/backup-ui.component" -import { TmpDispatch } from "Core/__deprecated__/renderer/store" -import { getPaths } from "shared/app-state" -import { ResultObject } from "Core/core/builder" export interface BackupProps { setOsBackupLocation: (value: string) => void @@ -21,16 +17,13 @@ export const Backup: FunctionComponent = ({ setOsBackupLocation, osBackupLocation, }) => { - const dispatch = useDispatch() - const openDialog = async () => { - const { payload: getPathsPayload } = (await dispatch( - getPaths({ - properties: ["openDirectory"], - defaultPath: osBackupLocation, - }) - )) as PayloadAction> - const location = getPathsPayload.ok && (getPathsPayload.data as string[])[0] + const openFileResult = await openFileRequest({ + properties: ["openDirectory"], + defaultPath: osBackupLocation, + }) + + const location = openFileResult.ok && openFileResult.data[0] if (location) { setOsBackupLocation(location) diff --git a/libs/shared/app-state/src/index.ts b/libs/shared/app-state/src/index.ts index 283856480a..8ebc04d860 100644 --- a/libs/shared/app-state/src/index.ts +++ b/libs/shared/app-state/src/index.ts @@ -3,7 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export * from "./lib/dialog-file-system/get-paths.action" +export * from "./lib/dialog-open-status/use-file-dialog-event-listener" export * from "./lib/online-status/use-online-listener" export * from "./lib/online-status/online-status.module" export * from "./lib/online-status/online-status.requests" diff --git a/libs/shared/app-state/src/lib/action-name.ts b/libs/shared/app-state/src/lib/action-name.ts index 812492d0bc..79ca19774f 100644 --- a/libs/shared/app-state/src/lib/action-name.ts +++ b/libs/shared/app-state/src/lib/action-name.ts @@ -5,5 +5,5 @@ export enum ActionName { UpdateOnlineStatus = "app-state/update-online-status", - GetPaths = "app-state/get-paths", + UpdateDialogOpenStatus = "app-state/update-dialog-open-status", } diff --git a/libs/shared/app-state/src/lib/app-state.reducer.ts b/libs/shared/app-state/src/lib/app-state.reducer.ts index d2944fe91c..85ae2b109d 100644 --- a/libs/shared/app-state/src/lib/app-state.reducer.ts +++ b/libs/shared/app-state/src/lib/app-state.reducer.ts @@ -4,8 +4,8 @@ */ import { createReducer } from "@reduxjs/toolkit" -import { getPaths } from "./dialog-file-system/get-paths.action" import { updateOnlineStatus } from "./online-status/base.action" +import { updateDialogOpenStatus } from "./dialog-open-status/base.action" export interface AppState { dialogOpen: boolean @@ -18,16 +18,10 @@ const initialState: AppState = { } export const appStateReducer = createReducer(initialState, (builder) => { - builder.addCase(getPaths.pending, (state) => { - state.dialogOpen = true - }) - builder.addCase(getPaths.fulfilled, (state) => { - state.dialogOpen = false - }) - builder.addCase(getPaths.rejected, (state) => { - state.dialogOpen = false - }) builder.addCase(updateOnlineStatus, (state, action) => { state.online = action.payload }) + builder.addCase(updateDialogOpenStatus, (state, action) => { + state.dialogOpen = action.payload + }) }) diff --git a/libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.ts b/libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.ts deleted file mode 100644 index 122c6044ac..0000000000 --- a/libs/shared/app-state/src/lib/dialog-file-system/get-paths.action.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 { OpenDialogOptions } from "electron" -import { createAsyncThunk } from "@reduxjs/toolkit" -import { openFileRequest } from "system-utils/feature" -import { ResultObject } from "Core/core/builder" -import { ReduxRootState } from "Core/__deprecated__/renderer/store" -import { ActionName } from "../action-name" - -export const getPaths = createAsyncThunk< - ResultObject, - OpenDialogOptions, - { state: ReduxRootState } ->(ActionName.GetPaths, (options) => { - return openFileRequest(options) -}) diff --git a/libs/shared/app-state/src/lib/dialog-open-status/base.action.ts b/libs/shared/app-state/src/lib/dialog-open-status/base.action.ts new file mode 100644 index 0000000000..f49e0d9f2e --- /dev/null +++ b/libs/shared/app-state/src/lib/dialog-open-status/base.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 { ActionName } from "../action-name" + +export const updateDialogOpenStatus = createAction( + ActionName.UpdateDialogOpenStatus +) diff --git a/libs/shared/app-state/src/lib/dialog-open-status/use-file-dialog-event-listener.ts b/libs/shared/app-state/src/lib/dialog-open-status/use-file-dialog-event-listener.ts new file mode 100644 index 0000000000..5a5a49082c --- /dev/null +++ b/libs/shared/app-state/src/lib/dialog-open-status/use-file-dialog-event-listener.ts @@ -0,0 +1,26 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { useEffect } from "react" +import { useDispatch } from "react-redux" +import { answerMain } from "shared/utils" +import { FileDialogToRendererEvents } from "system-utils/models" +import { updateDialogOpenStatus } from "./base.action" + +export const useFileDialogEventListener = () => { + const dispatch = useDispatch() + + useEffect(() => { + return answerMain(FileDialogToRendererEvents.FileDialogOpened, () => { + dispatch(updateDialogOpenStatus(true)) + }) + }, [dispatch]) + + useEffect(() => { + return answerMain(FileDialogToRendererEvents.FileDialogClosed, () => { + dispatch(updateDialogOpenStatus(false)) + }) + }, [dispatch]) +} diff --git a/libs/shared/utils/src/lib/call-renderer.helper.ts b/libs/shared/utils/src/lib/call-renderer.helper.ts index add028924e..0cf14ffb91 100644 --- a/libs/shared/utils/src/lib/call-renderer.helper.ts +++ b/libs/shared/utils/src/lib/call-renderer.helper.ts @@ -11,6 +11,7 @@ import { LoggerFactory } from "Core/core/factories" import { PureStrategyMainEvent } from "Core/device/strategies" import { getMainAppWindow } from "./get-main-app-window" import { AppEvents } from "./main-event.constant" +import { FileDialogToRendererEvents } from "system-utils/models" const logger = LoggerFactory.getInstance() @@ -20,6 +21,7 @@ export type CallRendererEvent = | AppEvents | PureStrategyMainEvent | AppUpdateEvent + | FileDialogToRendererEvents export const callRenderer = (event: CallRendererEvent, payload?: unknown) => { const win = getMainAppWindow() diff --git a/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts b/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts index de567d2d47..90c044982c 100644 --- a/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts +++ b/libs/system-utils/feature/src/lib/file-dialog/file-dialog.service.ts @@ -4,11 +4,16 @@ */ import { dialog, OpenDialogOptions, BrowserWindow } from "electron" -import { FileDialogServiceEvents, FileDialogError } from "system-utils/models" +import { + FileDialogToMainEvents, + FileDialogError, + FileDialogToRendererEvents, +} from "system-utils/models" import { IpcEvent } from "Core/core/decorators" import { Result, ResultObject } from "Core/core/builder" import { intl } from "Core/__deprecated__/renderer/utils/intl" import { AppError } from "Core/core/errors" +import { callRenderer } from "shared/utils" const defaultOptions: OpenDialogOptions = { title: intl.formatMessage({ id: "component.dialog.title" }), @@ -21,12 +26,24 @@ export class FileDialog { constructor() {} - @IpcEvent(FileDialogServiceEvents.OpenFile) + @IpcEvent(FileDialogToMainEvents.OpenFile) public async openFile({ - options = defaultOptions, + options, }: { options?: OpenDialogOptions }): Promise> { + callRenderer(FileDialogToRendererEvents.FileDialogOpened) + + const result = await this.performOpenFile(options) + + callRenderer(FileDialogToRendererEvents.FileDialogClosed) + + return result + } + + public async performOpenFile( + options: OpenDialogOptions = defaultOptions + ): Promise> { try { const openDialogOptions = { ...defaultOptions, diff --git a/libs/system-utils/feature/src/lib/file-dialog/open-file.request.ts b/libs/system-utils/feature/src/lib/file-dialog/open-file.request.ts index ebb031aaa9..f86f3cd819 100644 --- a/libs/system-utils/feature/src/lib/file-dialog/open-file.request.ts +++ b/libs/system-utils/feature/src/lib/file-dialog/open-file.request.ts @@ -5,13 +5,13 @@ import { ipcRenderer } from "electron-better-ipc" import { OpenDialogOptions } from "electron" -import { FileDialogServiceEvents } from "system-utils/models" +import { FileDialogToMainEvents } from "system-utils/models" import { ResultObject } from "Core/core/builder" export const openFileRequest = ( options: OpenDialogOptions ): Promise> => { - return ipcRenderer.callMain(FileDialogServiceEvents.OpenFile, { + return ipcRenderer.callMain(FileDialogToMainEvents.OpenFile, { options, }) } diff --git a/libs/system-utils/models/src/lib/file-dialog-service-events.ts b/libs/system-utils/models/src/lib/file-dialog-service-events.ts index f0713073cd..75fee6dba0 100644 --- a/libs/system-utils/models/src/lib/file-dialog-service-events.ts +++ b/libs/system-utils/models/src/lib/file-dialog-service-events.ts @@ -3,6 +3,11 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export enum FileDialogServiceEvents { +export enum FileDialogToMainEvents { OpenFile = "file-dialog/open-file", } + +export enum FileDialogToRendererEvents { + FileDialogOpened = "file-dialog/file-dialog-opened", + FileDialogClosed = "file-dialog/file-dialog-closed", +} From 9b4f63e78827477f552d42c680a52c1fbcde6128 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Sat, 29 Jun 2024 08:20:23 +0200 Subject: [PATCH 034/100] [CP-2845] Kompakt's loader after selection Pure or Harmony as an active device --- .../wrappers/layout-blank-wrapper.tsx | 37 ++------ .../connecting-content.component.tsx | 87 +++++++++---------- .../apps/base-app/base-app-routes.tsx | 4 +- .../api-device-initialization-modal-flow.tsx | 37 +------- .../devices-initialization.component.tsx | 4 +- .../passcode-modal-ui.component.tsx | 1 + .../get-modal-dialog-style.helper.ts | 10 ++- .../modal-dialog/modal-dialog.component.tsx | 53 ++++++----- .../modal-dialog/modal-dialog.interface.ts | 1 + 9 files changed, 90 insertions(+), 144 deletions(-) diff --git a/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx b/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx index 7cd2ae72ce..217358f38b 100644 --- a/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx +++ b/libs/core/__deprecated__/renderer/wrappers/layout-blank-wrapper.tsx @@ -5,7 +5,6 @@ import * as React from "react" import styled from "styled-components" -import { connect } from "react-redux" import { FunctionComponent } from "Core/core/types/function-component.interface" import { textColor, @@ -18,8 +17,6 @@ import Text, { } from "Core/__deprecated__/renderer/components/core/text/text.component" import { LayoutBlankWrapperTestIds } from "Core/__deprecated__/renderer/wrappers/wrappers-test-ids.enum" import { IconType } from "Core/__deprecated__/renderer/components/core/icon/icon-type" -import { RootState, ReduxRootState } from "Core/__deprecated__/renderer/store" -import { State } from "Core/core/constants" import { useHandleActiveDeviceAborted } from "Core/overview/components/overview-screens/pure-overview/use-handle-active-device-aborted.hook" import { DisplayStyle } from "Core/__deprecated__/renderer/components/core/button/button.config" import { Close } from "Core/__deprecated__/renderer/components/core/modal/modal.styled.elements" @@ -64,41 +61,19 @@ const Header = styled.header` } ` -interface ComponentProps { - recoveryMode?: boolean - onClose?: () => void -} -interface StateProps { - closeable: boolean -} - -type Props = ComponentProps & StateProps - const MainTitle = styled(Text)` padding-top: 0.3rem; ` -const mapStateToProps = ( - state: RootState & ReduxRootState, - ownProps: ComponentProps -): Props => { - return { - closeable: !( - state.update.needsForceUpdate || - state.update.forceUpdateState === State.Loading || - state.update.updateOsState === State.Loading || - state.activeDeviceRegistry.activeDeviceId - ), - recoveryMode: ownProps.recoveryMode, - onClose: ownProps.onClose, - } +interface Props { + closeable?: boolean + onClose?: () => void } const LayoutBlankWrapper: FunctionComponent = ({ children, - recoveryMode, onClose, - closeable, + closeable = true, }) => { const handleActiveDeviceAborted = useHandleActiveDeviceAborted() @@ -115,7 +90,7 @@ const LayoutBlankWrapper: FunctionComponent = ({ displayStyle={TextDisplayStyle.Paragraph3} message={{ id: "module.onboarding.mainTitle" }} /> - {!recoveryMode && closeable && ( + {closeable && ( = ({ ) } -export default connect(mapStateToProps)(LayoutBlankWrapper) +export default LayoutBlankWrapper diff --git a/libs/core/connecting/components/connecting-content.component.tsx b/libs/core/connecting/components/connecting-content.component.tsx index 12d785adca..47ab4af107 100644 --- a/libs/core/connecting/components/connecting-content.component.tsx +++ b/libs/core/connecting/components/connecting-content.component.tsx @@ -3,42 +3,44 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ + import React from "react" +import styled from "styled-components" +import { defineMessages } from "react-intl" +import { SpinnerLoader } from "generic-view/ui" +import { GenericThemeProvider } from "generic-view/theme" import { FunctionComponent } from "Core/core/types/function-component.interface" -import Text, { - TextDisplayStyle, -} from "Core/__deprecated__/renderer/components/core/text/text.component" +import { intl } from "Core/__deprecated__/renderer/utils/intl" -import Loader from "Core/__deprecated__/renderer/components/core/loader/loader.component" -import { LoaderType } from "Core/__deprecated__/renderer/components/core/loader/loader.interface" -import styled from "styled-components" -import { backgroundColor } from "Core/core/styles/theming/theme-getters" +const messages = defineMessages({ + connectingMessage: { + id: "module.onboarding.connectingMessage", + }, + connectingLongMessage: { + id: "module.onboarding.connectingLongMessage", + }, +}) export const Container = styled.section` - display: grid; - grid-template-areas: "Header" "Main" "Footer"; - grid-row-gap: 0; - grid-template-rows: 6.5rem 1fr 14rem; - - main { - grid-area: Main; - text-align: center; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - } -` - -const LoaderWrapper = styled.div` - width: 20rem; - height: 20rem; display: flex; - border-radius: 50%; + flex-direction: column; align-items: center; justify-content: center; - background-color: ${backgroundColor("icon")}; - margin-bottom: 4rem; + background-color: rgba(0, 0, 0, 0.3); + position: absolute; + top: 0; + left: 0; + width: 100%; + overflow: auto; +` + +const ConnectingText = styled.p` + font-size: ${({ theme }) => theme.fontSize.headline3}; + line-height: ${({ theme }) => theme.lineHeight.headline3}; + color: ${({ theme }) => theme.color.white}; + font-weight: ${({ theme }) => theme.fontWeight.bold}; + margin: 2.4rem 0 0; ` interface Props { @@ -46,23 +48,20 @@ interface Props { longerConnection?: boolean } -const ConnectingContent: FunctionComponent = ({ longerConnection = false }) => { +const ConnectingContent: FunctionComponent = ({ + longerConnection = false, +}) => { return ( - -
- - - - -
-
+ + + + + {longerConnection + ? intl.formatMessage(messages.connectingLongMessage) + : intl.formatMessage(messages.connectingMessage)} + + + ) } diff --git a/libs/core/core/components/apps/base-app/base-app-routes.tsx b/libs/core/core/components/apps/base-app/base-app-routes.tsx index 890c298948..064c3a6a75 100644 --- a/libs/core/core/components/apps/base-app/base-app-routes.tsx +++ b/libs/core/core/components/apps/base-app/base-app-routes.tsx @@ -59,7 +59,7 @@ export default () => ( - + ( - + { return ( - - - - {intl.formatMessage(messages.connectingModalParagraph)} - - theme.color.grey6}; ` - -const ConnectingText = styled.p` - font-size: ${({ theme }) => theme.fontSize.headline3}; - line-height: ${({ theme }) => theme.lineHeight.headline3}; - color: ${({ theme }) => theme.color.white}; - font-weight: ${({ theme }) => theme.fontWeight.bold}; - margin: 2.4rem 0 0; -` diff --git a/libs/core/device-initialization/components/devices-initialization.component.tsx b/libs/core/device-initialization/components/devices-initialization.component.tsx index f90a7d74e5..0b2a2bbfd3 100644 --- a/libs/core/device-initialization/components/devices-initialization.component.tsx +++ b/libs/core/device-initialization/components/devices-initialization.component.tsx @@ -46,9 +46,7 @@ const DevicesInitialization: FunctionComponent = () => { return ( <> - {activeDevice?.deviceType !== DeviceType.APIDevice && ( - - )} + ) } diff --git a/libs/core/device-initialization/components/passcode-modal/passcode-modal-ui.component.tsx b/libs/core/device-initialization/components/passcode-modal/passcode-modal-ui.component.tsx index 50bad38cc6..75506bff82 100644 --- a/libs/core/device-initialization/components/passcode-modal/passcode-modal-ui.component.tsx +++ b/libs/core/device-initialization/components/passcode-modal/passcode-modal-ui.component.tsx @@ -94,6 +94,7 @@ const PasscodeModalUI: FunctionComponent = ({ closeButton={false} closeModal={canBeClosed ? close : undefined} title={muditaLogo} + noOverlayBg={true} > diff --git a/libs/core/ui/components/modal-dialog/get-modal-dialog-style.helper.ts b/libs/core/ui/components/modal-dialog/get-modal-dialog-style.helper.ts index f641beab8f..16b8fa761a 100644 --- a/libs/core/ui/components/modal-dialog/get-modal-dialog-style.helper.ts +++ b/libs/core/ui/components/modal-dialog/get-modal-dialog-style.helper.ts @@ -3,9 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import muditaTheme, { - Theme, -} from "Core/core/styles/theming/theme" +import muditaTheme, { Theme } from "Core/core/styles/theming/theme" import { backgroundColor, zIndex as getZIndex, @@ -16,6 +14,7 @@ import { Styles } from "react-modal" export interface GetModalDialogStyleProps { size: ModalProps["size"] + noOverlayBg?: boolean zIndex?: number theme?: Theme } @@ -49,12 +48,15 @@ export const getModalDialogStyle = ({ zIndex, size, theme = muditaTheme, + noOverlayBg = false, }: GetModalDialogStyleProps): Styles => { return { overlay: { // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - backgroundColor: backgroundColor("modalBackdrop")({ theme }), + backgroundColor: noOverlayBg + ? "transparent" + : backgroundColor("modalBackdrop")({ theme }), // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment zIndex: zIndex ? zIndex : getZIndex("modalBackdrop")({ theme }), diff --git a/libs/core/ui/components/modal-dialog/modal-dialog.component.tsx b/libs/core/ui/components/modal-dialog/modal-dialog.component.tsx index ef8641f8e1..cc88ae784a 100644 --- a/libs/core/ui/components/modal-dialog/modal-dialog.component.tsx +++ b/libs/core/ui/components/modal-dialog/modal-dialog.component.tsx @@ -65,6 +65,7 @@ export const ModalDialog: FunctionComponent = withTheme( actionButtonSize, actionButtonDisabled, theme, + noOverlayBg, ...props }) => { const closeModalByButtonClick = () => { @@ -87,39 +88,43 @@ export const ModalDialog: FunctionComponent = withTheme( isOpen={open} // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - style={getModalDialogStyle({ zIndex: layer, size, theme })} + style={getModalDialogStyle({ zIndex: layer, size, theme, noOverlayBg })} shouldCloseOnOverlayClick={false} // AUTO DISABLED - fix me if you like :) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment onAfterClose={onClose} {...props} > - {(title || subtitle || closeModal) &&
- {title && - {title} - } - {Boolean(closeModal) && close} - - {subtitle} - -
} + {title && ( + + {title} + + )} + {Boolean(closeModal) && close} + + {subtitle} + + + )} {children} {actionButtonLabel || closeButton ? ( // AUTO DISABLED - fix me if you like :) diff --git a/libs/core/ui/components/modal-dialog/modal-dialog.interface.ts b/libs/core/ui/components/modal-dialog/modal-dialog.interface.ts index 7fab4979b0..9109e4af14 100644 --- a/libs/core/ui/components/modal-dialog/modal-dialog.interface.ts +++ b/libs/core/ui/components/modal-dialog/modal-dialog.interface.ts @@ -14,6 +14,7 @@ export interface ModalDialogProps extends Omit, ModalProps { close?: ComponentProps closeModal?: () => void open: boolean + noOverlayBg?: boolean theme?: GetModalDialogStyleProps["theme"] layer?: ModalLayers } From e2e66c942f8016290b380afc32e3801a28764369 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 2 Jul 2024 08:38:43 +0200 Subject: [PATCH 035/100] [CP-2936] Reduced controller boilerplate in online-status module --- .../src/lib/mock-application-updater.service.ts | 4 ++-- .../online-status/online-status.controller.ts | 17 ----------------- .../lib/online-status/online-status.module.ts | 3 +-- .../lib/online-status/online-status.service.ts | 12 ++++++++++-- 4 files changed, 13 insertions(+), 23 deletions(-) delete mode 100644 libs/shared/app-state/src/lib/online-status/online-status.controller.ts diff --git a/libs/electron/application-updater/src/lib/mock-application-updater.service.ts b/libs/electron/application-updater/src/lib/mock-application-updater.service.ts index 13cd2d221c..1b965b622a 100644 --- a/libs/electron/application-updater/src/lib/mock-application-updater.service.ts +++ b/libs/electron/application-updater/src/lib/mock-application-updater.service.ts @@ -4,12 +4,12 @@ */ import { MockUpdaterStateService } from "e2e-mock-server" -import { OnlineStatusService } from "shared/app-state" +import { IOnlineStatusService } from "shared/app-state" import { BaseApplicationUpdaterService } from "./base-application-updater.service" export class MockApplicationUpdaterService extends BaseApplicationUpdaterService { constructor( - private onlineStatusService: OnlineStatusService, + private onlineStatusService: IOnlineStatusService, private mockUpdaterStateService: MockUpdaterStateService ) { super() diff --git a/libs/shared/app-state/src/lib/online-status/online-status.controller.ts b/libs/shared/app-state/src/lib/online-status/online-status.controller.ts deleted file mode 100644 index 6efcb1783c..0000000000 --- a/libs/shared/app-state/src/lib/online-status/online-status.controller.ts +++ /dev/null @@ -1,17 +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 { IpcEvent } from "Core/core/decorators" -import { IpcOnlineStatusEvent } from "./online-status.event" -import { OnlineStatusService } from "./online-status.service" - -export class OnlineStatusController { - constructor(private onlineStatusService: OnlineStatusService) {} - - @IpcEvent(IpcOnlineStatusEvent.UpdateOnlineStatus) - public async updateOnlineStatus(value: boolean): Promise { - this.onlineStatusService.online = value - } -} diff --git a/libs/shared/app-state/src/lib/online-status/online-status.module.ts b/libs/shared/app-state/src/lib/online-status/online-status.module.ts index 74391affd9..91ea57fffb 100644 --- a/libs/shared/app-state/src/lib/online-status/online-status.module.ts +++ b/libs/shared/app-state/src/lib/online-status/online-status.module.ts @@ -3,13 +3,12 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { OnlineStatusController } from "./online-status.controller" import { onlineStatusService } from "./online-status.service" export class OnlineStatusModule { public controllers constructor() { - this.controllers = [new OnlineStatusController(onlineStatusService)] + this.controllers = [onlineStatusService] } } diff --git a/libs/shared/app-state/src/lib/online-status/online-status.service.ts b/libs/shared/app-state/src/lib/online-status/online-status.service.ts index 53cf95128b..1889d5fd00 100644 --- a/libs/shared/app-state/src/lib/online-status/online-status.service.ts +++ b/libs/shared/app-state/src/lib/online-status/online-status.service.ts @@ -3,14 +3,22 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export class OnlineStatusService { +import { IpcEvent } from "Core/core/decorators" +import { IpcOnlineStatusEvent } from "./online-status.event" + +export interface IOnlineStatusService { + online: boolean; +} + +class OnlineStatusService implements IOnlineStatusService { private _online: boolean = false get online(): boolean { return this._online } - set online(value: boolean) { + @IpcEvent(IpcOnlineStatusEvent.UpdateOnlineStatus) + updateOnlineStatus(value: boolean) { this._online = value } } From 0bd12cbeb28dec3d0e04884b4004e7cf535aa0bf Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 2 Jul 2024 08:46:53 +0200 Subject: [PATCH 036/100] [CP-2936] Reduced controller boilerplate in application-updater module --- .../src/lib/application-updater.controller.ts | 27 ------------------- .../src/lib/application-updater.module.ts | 3 +-- .../src/lib/application-updater.service.ts | 6 +++++ .../lib/mock-application-updater.service.ts | 6 +++++ 4 files changed, 13 insertions(+), 29 deletions(-) delete mode 100644 libs/electron/application-updater/src/lib/application-updater.controller.ts diff --git a/libs/electron/application-updater/src/lib/application-updater.controller.ts b/libs/electron/application-updater/src/lib/application-updater.controller.ts deleted file mode 100644 index cd045899c6..0000000000 --- a/libs/electron/application-updater/src/lib/application-updater.controller.ts +++ /dev/null @@ -1,27 +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 { IpcEvent } from "Core/core/decorators" -import { IpcApplicationUpdaterEvent } from "./ipc-application-updater.event" -import { BaseApplicationUpdaterService } from "./base-application-updater.service" - -export class ApplicationUpdaterController { - constructor( - private applicationUpdaterService: BaseApplicationUpdaterService - ) {} - - @IpcEvent(IpcApplicationUpdaterEvent.Check) - public async check(): Promise { - return this.applicationUpdaterService.checkForUpdatesAndNotify() - } - @IpcEvent(IpcApplicationUpdaterEvent.Install) - public async install(): Promise { - return this.applicationUpdaterService.quitAndInstall() - } - @IpcEvent(IpcApplicationUpdaterEvent.Download) - public async download(): Promise { - return this.applicationUpdaterService.downloadUpdate() - } -} diff --git a/libs/electron/application-updater/src/lib/application-updater.module.ts b/libs/electron/application-updater/src/lib/application-updater.module.ts index c455708a5f..5d67ce966b 100644 --- a/libs/electron/application-updater/src/lib/application-updater.module.ts +++ b/libs/electron/application-updater/src/lib/application-updater.module.ts @@ -5,7 +5,6 @@ import { mockServiceEnabled, mockUpdaterStateService } from "e2e-mock-server" import { onlineStatusService } from "shared/app-state" -import { ApplicationUpdaterController } from "./application-updater.controller" import { ApplicationUpdaterService } from "./application-updater.service" import { BaseApplicationUpdaterService } from "./base-application-updater.service" import { MockApplicationUpdaterService } from "./mock-application-updater.service" @@ -17,7 +16,7 @@ export class ApplicationUpdaterModule { const applicationUpdaterService = this.resolveApplicationUpdaterService() this.controllers = [ - new ApplicationUpdaterController(applicationUpdaterService), + applicationUpdaterService, ] } diff --git a/libs/electron/application-updater/src/lib/application-updater.service.ts b/libs/electron/application-updater/src/lib/application-updater.service.ts index f52418bf71..3d90fa0b04 100644 --- a/libs/electron/application-updater/src/lib/application-updater.service.ts +++ b/libs/electron/application-updater/src/lib/application-updater.service.ts @@ -5,7 +5,9 @@ import { autoUpdater } from "electron-updater" import logger from "Core/__deprecated__/main/utils/logger" +import { IpcEvent } from "Core/core/decorators" import { BaseApplicationUpdaterService } from "./base-application-updater.service" +import { IpcApplicationUpdaterEvent } from "./ipc-application-updater.event" const token = process.env.GITHUB_ACCESS_TOKEN const repo = process.env.RELEASES_REPOSITORY_NAME @@ -18,13 +20,17 @@ export class ApplicationUpdaterService extends BaseApplicationUpdaterService { this.mountListeners() } + @IpcEvent(IpcApplicationUpdaterEvent.Install) public quitAndInstall(): void { autoUpdater.quitAndInstall(true, true) } + @IpcEvent(IpcApplicationUpdaterEvent.Download) public async downloadUpdate(): Promise { await autoUpdater.downloadUpdate() } + + @IpcEvent(IpcApplicationUpdaterEvent.Check) public async checkForUpdatesAndNotify(): Promise { await autoUpdater.checkForUpdatesAndNotify() } diff --git a/libs/electron/application-updater/src/lib/mock-application-updater.service.ts b/libs/electron/application-updater/src/lib/mock-application-updater.service.ts index 1b965b622a..c765fb73c6 100644 --- a/libs/electron/application-updater/src/lib/mock-application-updater.service.ts +++ b/libs/electron/application-updater/src/lib/mock-application-updater.service.ts @@ -5,7 +5,9 @@ import { MockUpdaterStateService } from "e2e-mock-server" import { IOnlineStatusService } from "shared/app-state" +import { IpcEvent } from "Core/core/decorators" import { BaseApplicationUpdaterService } from "./base-application-updater.service" +import { IpcApplicationUpdaterEvent } from "./ipc-application-updater.event" export class MockApplicationUpdaterService extends BaseApplicationUpdaterService { constructor( @@ -14,14 +16,18 @@ export class MockApplicationUpdaterService extends BaseApplicationUpdaterService ) { super() } + + @IpcEvent(IpcApplicationUpdaterEvent.Install) public quitAndInstall(): void { this.onError() } + @IpcEvent(IpcApplicationUpdaterEvent.Download) public async downloadUpdate(): Promise { this.onError() } + @IpcEvent(IpcApplicationUpdaterEvent.Check) public async checkForUpdatesAndNotify(): Promise { if (!this.onlineStatusService.online) { return this.onError() From 02d69228e11d95e30b4b503a89478e27f7d054ac Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Tue, 2 Jul 2024 10:04:30 +0200 Subject: [PATCH 037/100] [CP-2936] Reduced controller boilerplate by moved request layers to device-protocol domain --- .../src/actions/set-active-device.action.ts | 2 +- .../src/active-device-registry.module.ts | 19 ---------- .../feature/src/constants/index.ts | 1 - .../feature/src/controllers/index.ts | 6 --- .../feature/src/index.ts | 1 - libs/core/core/application.module.ts | 38 +++++++++++-------- .../src/actions/connect-device.action.ts | 2 +- .../controllers/device-manager.controller.ts | 19 ---------- .../feature/src/controllers/index.ts | 6 --- .../feature/src/device-manager.module.ts | 19 ---------- libs/device-manager/feature/src/index.ts | 1 - .../feature/src/requests/index.ts | 6 --- .../src/constants/controller.constant.ts | 5 ++- .../feature/src/device-protocol.module.ts | 3 +- libs/device-protocol/feature/src/index.ts | 1 + .../src/requests/connect-device.request.ts | 4 +- .../feature/src/requests/index.ts | 1 + .../src/requests/set-active-device.request.ts | 4 +- .../feature/src/serial-port-list.helper.ts | 16 -------- .../src/services/device-protocol.service.ts} | 15 +++++--- .../feature/src/services/device-protocol.ts | 5 ++- .../feature/src/services/index.ts | 1 + .../src/services/serial-port.service.ts | 16 ++++++++ libs/e2e-mock/server/src/index.ts | 1 + .../src/lib/mock-serial-port.service.ts | 14 +++++++ 25 files changed, 81 insertions(+), 125 deletions(-) delete mode 100644 libs/active-device-registry/feature/src/active-device-registry.module.ts delete mode 100644 libs/active-device-registry/feature/src/controllers/index.ts delete mode 100644 libs/device-manager/feature/src/controllers/device-manager.controller.ts delete mode 100644 libs/device-manager/feature/src/controllers/index.ts delete mode 100644 libs/device-manager/feature/src/device-manager.module.ts delete mode 100644 libs/device-manager/feature/src/requests/index.ts rename libs/{active-device-registry => device-protocol}/feature/src/constants/controller.constant.ts (51%) rename libs/{device-manager => device-protocol}/feature/src/requests/connect-device.request.ts (73%) rename libs/{active-device-registry => device-protocol}/feature/src/requests/index.ts (82%) rename libs/{active-device-registry => device-protocol}/feature/src/requests/set-active-device.request.ts (74%) delete mode 100644 libs/device-protocol/feature/src/serial-port-list.helper.ts rename libs/{active-device-registry/feature/src/controllers/active-device-registry.controller.ts => device-protocol/feature/src/services/device-protocol.service.ts} (56%) create mode 100644 libs/device-protocol/feature/src/services/serial-port.service.ts create mode 100644 libs/e2e-mock/server/src/lib/mock-serial-port.service.ts diff --git a/libs/active-device-registry/feature/src/actions/set-active-device.action.ts b/libs/active-device-registry/feature/src/actions/set-active-device.action.ts index b5fde246dd..c784df583e 100644 --- a/libs/active-device-registry/feature/src/actions/set-active-device.action.ts +++ b/libs/active-device-registry/feature/src/actions/set-active-device.action.ts @@ -4,9 +4,9 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { setActiveDeviceRequest } from "device-protocol/feature" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { DeviceId } from "Core/device/constants/device-id" -import { setActiveDeviceRequest } from "../requests" import { ActiveDeviceRegistryEvent } from "../constants" export const setActiveDevice = createAsyncThunk< diff --git a/libs/active-device-registry/feature/src/active-device-registry.module.ts b/libs/active-device-registry/feature/src/active-device-registry.module.ts deleted file mode 100644 index 605badb179..0000000000 --- a/libs/active-device-registry/feature/src/active-device-registry.module.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 { DeviceProtocol } from "device-protocol/feature" -import { ActiveDeviceRegistryController } from "./controllers" - -export class ActiveDeviceRegistryModule { - public controllers - - constructor(public deviceProtocol: DeviceProtocol) { - const activeDeviceRegistryController = new ActiveDeviceRegistryController( - this.deviceProtocol - ) - - this.controllers = [activeDeviceRegistryController] - } -} diff --git a/libs/active-device-registry/feature/src/constants/index.ts b/libs/active-device-registry/feature/src/constants/index.ts index 5a48343da1..fd9c217d57 100644 --- a/libs/active-device-registry/feature/src/constants/index.ts +++ b/libs/active-device-registry/feature/src/constants/index.ts @@ -3,5 +3,4 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export * from "./controller.constant" export * from "./event.constant" diff --git a/libs/active-device-registry/feature/src/controllers/index.ts b/libs/active-device-registry/feature/src/controllers/index.ts deleted file mode 100644 index a428b87f03..0000000000 --- a/libs/active-device-registry/feature/src/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 "./active-device-registry.controller" diff --git a/libs/active-device-registry/feature/src/index.ts b/libs/active-device-registry/feature/src/index.ts index 83e18aeceb..ed357a32d6 100644 --- a/libs/active-device-registry/feature/src/index.ts +++ b/libs/active-device-registry/feature/src/index.ts @@ -6,4 +6,3 @@ export * from "./actions" export * from "./reducers" export * from "./selectors" -export * from "./active-device-registry.module" diff --git a/libs/core/core/application.module.ts b/libs/core/core/application.module.ts index 200c6238dc..d1329d2921 100644 --- a/libs/core/core/application.module.ts +++ b/libs/core/core/application.module.ts @@ -43,16 +43,19 @@ import { DeviceProtocolModule, DeviceProtocol, DeviceResolverService, + SerialPortService, } from "device-protocol/feature" import { APIModule } from "device/feature" import { DesktopModule } from "Core/desktop/desktop.module" import { OnlineStatusModule } from "shared/app-state" import { SystemUtilsModule } from "system-utils/feature" -import { MockDeviceResolverService, mockServiceEnabled } from "e2e-mock-server" +import { + MockDeviceResolverService, + mockServiceEnabled, + MockSerialPortService, +} from "e2e-mock-server" import { ApplicationUpdaterModule } from "electron/application-updater" import { CoreDeviceModule } from "core-device/feature" -import { DeviceManagerModule } from "device-manager/feature" -import { ActiveDeviceRegistryModule } from "active-device-registry/feature" import { createSettingsService } from "Core/settings/containers" export class ApplicationModule { @@ -95,12 +98,7 @@ export class ApplicationModule { private apiModule: APIModule - private deviceProtocol = new DeviceProtocol( - mockServiceEnabled - ? new MockDeviceResolverService() - : new DeviceResolverService(), - this.eventEmitter - ) + private deviceProtocol = this.resolveDeviceProtocol() private systemUtilsModule = new SystemUtilsModule() constructor( @@ -132,12 +130,6 @@ export class ApplicationModule { this.controllerInitializer.initialize( new CoreDeviceModule(this.deviceProtocol, this.fileSystem).controllers ) - this.controllerInitializer.initialize( - new DeviceManagerModule(this.deviceProtocol).controllers - ) - this.controllerInitializer.initialize( - new ActiveDeviceRegistryModule(this.deviceProtocol).controllers - ) } lateInitialization(): void { @@ -161,4 +153,20 @@ export class ApplicationModule { this.observerInitializer.initialize(instance.observers) this.controllerInitializer.initialize(instance.controllers) } + + private resolveDeviceProtocol(): DeviceProtocol { + if (mockServiceEnabled) { + return new DeviceProtocol( + new MockSerialPortService(), + new MockDeviceResolverService(), + this.eventEmitter + ) + } else { + return new DeviceProtocol( + new SerialPortService(), + new DeviceResolverService(), + this.eventEmitter + ) + } + } } diff --git a/libs/device-manager/feature/src/actions/connect-device.action.ts b/libs/device-manager/feature/src/actions/connect-device.action.ts index 72125e6e83..89cd039c7d 100644 --- a/libs/device-manager/feature/src/actions/connect-device.action.ts +++ b/libs/device-manager/feature/src/actions/connect-device.action.ts @@ -4,11 +4,11 @@ */ import { createAsyncThunk } from "@reduxjs/toolkit" +import { connectDeviceRequest } from "device-protocol/feature" import { DeviceManagerEvent, DeviceState } from "device-manager/models" import { setDeviceState } from "core-device/feature" import { ReduxRootState } from "Core/__deprecated__/renderer/store" import { DeviceId } from "Core/device/constants/device-id" -import { connectDeviceRequest } from "../requests" export const connectDevice = createAsyncThunk< boolean, diff --git a/libs/device-manager/feature/src/controllers/device-manager.controller.ts b/libs/device-manager/feature/src/controllers/device-manager.controller.ts deleted file mode 100644 index ea98fa124f..0000000000 --- a/libs/device-manager/feature/src/controllers/device-manager.controller.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 { IpcEvent } from "Core/core/decorators" -import { DeviceProtocol } from "device-protocol/feature" -import { ResultObject } from "Core/core/builder" -import { DeviceId } from "Core/device/constants/device-id" -import { IpcDeviceManagerEvent } from "../constants" - -export class DeviceManagerController { - constructor(private deviceProtocol: DeviceProtocol) {} - - @IpcEvent(IpcDeviceManagerEvent.ConnectDevice) - public connectDevice(id: DeviceId): Promise> { - return this.deviceProtocol.connectDevice(id) - } -} diff --git a/libs/device-manager/feature/src/controllers/index.ts b/libs/device-manager/feature/src/controllers/index.ts deleted file mode 100644 index 086f1e6a9c..0000000000 --- a/libs/device-manager/feature/src/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 "./device-manager.controller" diff --git a/libs/device-manager/feature/src/device-manager.module.ts b/libs/device-manager/feature/src/device-manager.module.ts deleted file mode 100644 index 4e558361d8..0000000000 --- a/libs/device-manager/feature/src/device-manager.module.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 { DeviceProtocol } from "device-protocol/feature" -import { DeviceManagerController } from "./controllers" - -export class DeviceManagerModule { - public controllers - - constructor(public deviceProtocol: DeviceProtocol) { - const deviceManagerController = new DeviceManagerController( - this.deviceProtocol - ) - - this.controllers = [deviceManagerController] - } -} diff --git a/libs/device-manager/feature/src/index.ts b/libs/device-manager/feature/src/index.ts index b6d66a48d4..74112c6701 100644 --- a/libs/device-manager/feature/src/index.ts +++ b/libs/device-manager/feature/src/index.ts @@ -6,4 +6,3 @@ export * from "./actions" export * from "./selectors" export * from "./reducers" -export * from "./device-manager.module" diff --git a/libs/device-manager/feature/src/requests/index.ts b/libs/device-manager/feature/src/requests/index.ts deleted file mode 100644 index 0a3139b8ad..0000000000 --- a/libs/device-manager/feature/src/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 "./connect-device.request" diff --git a/libs/active-device-registry/feature/src/constants/controller.constant.ts b/libs/device-protocol/feature/src/constants/controller.constant.ts similarity index 51% rename from libs/active-device-registry/feature/src/constants/controller.constant.ts rename to libs/device-protocol/feature/src/constants/controller.constant.ts index 6914b07bb0..189ddc233f 100644 --- a/libs/active-device-registry/feature/src/constants/controller.constant.ts +++ b/libs/device-protocol/feature/src/constants/controller.constant.ts @@ -3,6 +3,7 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -export enum IpcActiveDeviceRegistryEvent { - SetActiveDevice = "active-device-registry/set-active-device", +export enum IpcDeviceProtocolEvent { + SetActiveDevice = "device-protocol/set-active-device", + ConnectDevice = "device-protocol/connect-device", } diff --git a/libs/device-protocol/feature/src/device-protocol.module.ts b/libs/device-protocol/feature/src/device-protocol.module.ts index 8208d302bf..dcf4644d2b 100644 --- a/libs/device-protocol/feature/src/device-protocol.module.ts +++ b/libs/device-protocol/feature/src/device-protocol.module.ts @@ -12,6 +12,7 @@ import { IndexStorage } from "Core/index-storage/types" import { BaseModule } from "Core/core/module" import { DeviceProtocol } from "./services" import { UsbDeviceDetectionObserver } from "./observers" +import { DeviceProtocolService } from "./services/device-protocol.service" export class DeviceProtocolModule extends BaseModule { constructor( @@ -39,6 +40,6 @@ export class DeviceProtocolModule extends BaseModule { this.initializers = [] this.observers = [usbDeviceDetectionObserver] - this.controllers = [] + this.controllers = [new DeviceProtocolService(this.deviceProtocol)] } } diff --git a/libs/device-protocol/feature/src/index.ts b/libs/device-protocol/feature/src/index.ts index 878afe26b3..5d2fca06cf 100644 --- a/libs/device-protocol/feature/src/index.ts +++ b/libs/device-protocol/feature/src/index.ts @@ -4,4 +4,5 @@ */ export * from "./device-protocol.module" +export * from "./requests" export * from "./services" diff --git a/libs/device-manager/feature/src/requests/connect-device.request.ts b/libs/device-protocol/feature/src/requests/connect-device.request.ts similarity index 73% rename from libs/device-manager/feature/src/requests/connect-device.request.ts rename to libs/device-protocol/feature/src/requests/connect-device.request.ts index 8d9889b49b..1343cfef69 100644 --- a/libs/device-manager/feature/src/requests/connect-device.request.ts +++ b/libs/device-protocol/feature/src/requests/connect-device.request.ts @@ -6,10 +6,10 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" -import { IpcDeviceManagerEvent } from "../constants" +import { IpcDeviceProtocolEvent } from "../constants/controller.constant" export const connectDeviceRequest = async ( id: DeviceId ): Promise> => { - return ipcRenderer.callMain(IpcDeviceManagerEvent.ConnectDevice, id) + return ipcRenderer.callMain(IpcDeviceProtocolEvent.ConnectDevice, id) } diff --git a/libs/active-device-registry/feature/src/requests/index.ts b/libs/device-protocol/feature/src/requests/index.ts similarity index 82% rename from libs/active-device-registry/feature/src/requests/index.ts rename to libs/device-protocol/feature/src/requests/index.ts index 7de1bf4d87..07f35b725e 100644 --- a/libs/active-device-registry/feature/src/requests/index.ts +++ b/libs/device-protocol/feature/src/requests/index.ts @@ -3,4 +3,5 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ +export * from "./connect-device.request" export * from "./set-active-device.request" diff --git a/libs/active-device-registry/feature/src/requests/set-active-device.request.ts b/libs/device-protocol/feature/src/requests/set-active-device.request.ts similarity index 74% rename from libs/active-device-registry/feature/src/requests/set-active-device.request.ts rename to libs/device-protocol/feature/src/requests/set-active-device.request.ts index 0639919deb..7df53bb597 100644 --- a/libs/active-device-registry/feature/src/requests/set-active-device.request.ts +++ b/libs/device-protocol/feature/src/requests/set-active-device.request.ts @@ -6,10 +6,10 @@ import { ipcRenderer } from "electron-better-ipc" import { ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" -import { IpcActiveDeviceRegistryEvent } from "../constants" +import { IpcDeviceProtocolEvent } from "../constants/controller.constant" export const setActiveDeviceRequest = async ( id: DeviceId | undefined ): Promise> => { - return ipcRenderer.callMain(IpcActiveDeviceRegistryEvent.SetActiveDevice, id) + return ipcRenderer.callMain(IpcDeviceProtocolEvent.SetActiveDevice, id) } diff --git a/libs/device-protocol/feature/src/serial-port-list.helper.ts b/libs/device-protocol/feature/src/serial-port-list.helper.ts deleted file mode 100644 index a8b3b3706f..0000000000 --- a/libs/device-protocol/feature/src/serial-port-list.helper.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 { getMockedDevices, mockServiceEnabled } from "e2e-mock-server" -import SerialPort, { PortInfo } from "serialport" - -export const getSerialPortList = () => { - if (mockServiceEnabled) { - return new Promise((resolve) => { - resolve(getMockedDevices()) - }) - } - return SerialPort.list() -} diff --git a/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts b/libs/device-protocol/feature/src/services/device-protocol.service.ts similarity index 56% rename from libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts rename to libs/device-protocol/feature/src/services/device-protocol.service.ts index 1d07112039..17a188a3cf 100644 --- a/libs/active-device-registry/feature/src/controllers/active-device-registry.controller.ts +++ b/libs/device-protocol/feature/src/services/device-protocol.service.ts @@ -3,17 +3,22 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { IpcEvent } from "Core/core/decorators" -import { DeviceProtocol } from "device-protocol/feature" import { ResultObject } from "Core/core/builder" import { DeviceId } from "Core/device/constants/device-id" -import { IpcActiveDeviceRegistryEvent } from "../constants" +import { IpcEvent } from "Core/core/decorators" +import { IpcDeviceProtocolEvent } from "../constants/controller.constant" +import { DeviceProtocol } from "./device-protocol" -export class ActiveDeviceRegistryController { +export class DeviceProtocolService { constructor(private deviceProtocol: DeviceProtocol) {} - @IpcEvent(IpcActiveDeviceRegistryEvent.SetActiveDevice) + @IpcEvent(IpcDeviceProtocolEvent.SetActiveDevice) public setActiveDevice(id: DeviceId | undefined): ResultObject { return this.deviceProtocol.setActiveDevice(id) } + + @IpcEvent(IpcDeviceProtocolEvent.ConnectDevice) + public connectDevice(id: DeviceId): Promise> { + return this.deviceProtocol.connectDevice(id) + } } diff --git a/libs/device-protocol/feature/src/services/device-protocol.ts b/libs/device-protocol/feature/src/services/device-protocol.ts index 5df9dd7b56..be78c51d57 100644 --- a/libs/device-protocol/feature/src/services/device-protocol.ts +++ b/libs/device-protocol/feature/src/services/device-protocol.ts @@ -20,7 +20,7 @@ import { CoreDevice } from "Core/device/modules/core-device" import { RequestConfig } from "Core/device/types/mudita-os" import { MockCoreDevice } from "Core/device/modules/mock-core-device" import { PortInfo } from "../types" -import { getSerialPortList } from "../serial-port-list.helper" +import { ISerialPortService } from "./serial-port.service" import { DeviceManagerError } from "../constants" import { PortInfoValidator } from "../validators" import { IDeviceResolverService } from "./device-resolver.service" @@ -32,6 +32,7 @@ export class DeviceProtocol { private mutex = new Mutex() constructor( + private serialPortService: ISerialPortService, private deviceResolver: IDeviceResolverService, protected eventEmitter: EventEmitter ) {} @@ -202,7 +203,7 @@ export class DeviceProtocol { @log("==== device manager: list ====", { space: 0 }) private getSerialPortList(): Promise { - return getSerialPortList() + return this.serialPortService.list() } private getDeviceByPath(path: string): BaseDevice | undefined { diff --git a/libs/device-protocol/feature/src/services/index.ts b/libs/device-protocol/feature/src/services/index.ts index 125a4615a4..fb5629fe01 100644 --- a/libs/device-protocol/feature/src/services/index.ts +++ b/libs/device-protocol/feature/src/services/index.ts @@ -5,3 +5,4 @@ export * from "./device-protocol" export * from "./device-resolver.service" +export * from "./serial-port.service" diff --git a/libs/device-protocol/feature/src/services/serial-port.service.ts b/libs/device-protocol/feature/src/services/serial-port.service.ts new file mode 100644 index 0000000000..5c6a60a6ff --- /dev/null +++ b/libs/device-protocol/feature/src/services/serial-port.service.ts @@ -0,0 +1,16 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import SerialPort from "serialport" + +export interface ISerialPortService { + list(): Promise +} + +export class SerialPortService implements ISerialPortService { + list(): Promise { + return SerialPort.list() + } +} diff --git a/libs/e2e-mock/server/src/index.ts b/libs/e2e-mock/server/src/index.ts index c7066d6942..ef223decf3 100644 --- a/libs/e2e-mock/server/src/index.ts +++ b/libs/e2e-mock/server/src/index.ts @@ -8,4 +8,5 @@ export * from "./lib/server" export { getMockedDevices } from "./lib/mock-descriptor/mock-descriptor" export * from "./lib/mock-data-resolver-service" export * from "./lib/mock-http-state.service" +export * from "./lib/mock-serial-port.service" export * from "./lib/mock-descriptor/mock-descriptor-validators" diff --git a/libs/e2e-mock/server/src/lib/mock-serial-port.service.ts b/libs/e2e-mock/server/src/lib/mock-serial-port.service.ts new file mode 100644 index 0000000000..6c83124540 --- /dev/null +++ b/libs/e2e-mock/server/src/lib/mock-serial-port.service.ts @@ -0,0 +1,14 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import SerialPort from "serialport" +import { ISerialPortService } from "Libs/device-protocol/feature/src/services/serial-port.service" +import { getMockedDevices } from "./mock-descriptor/mock-descriptor" + +export class MockSerialPortService implements ISerialPortService { + async list(): Promise { + return getMockedDevices() + } +} From ae9c2d976ff353d4e33de3f984a888b42ad3eeb9 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Thu, 27 Jun 2024 15:59:18 +0200 Subject: [PATCH 038/100] [CP-2749] Extended `MockUpdaterStateService` to handle downloaded state --- libs/e2e-mock/server/README.md | 18 +++++++++++++++++- .../src/lib/mock-updater-state.service.ts | 12 ++++++++---- .../lib/mock-application-updater.service.ts | 17 +++++++++++------ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/libs/e2e-mock/server/README.md b/libs/e2e-mock/server/README.md index 35be3b3273..a14a2b20f9 100644 --- a/libs/e2e-mock/server/README.md +++ b/libs/e2e-mock/server/README.md @@ -47,7 +47,7 @@ E2EMockClient.mockHttpResponse({ The `setMockUpdateState` function is a method provided by the `E2EMockClient` to simulate different update states of the application, use the following command: ```javascript -E2EMockClient.setMockUpdateState({ available: boolean, version?: string }) +E2EMockClient.setMockUpdateState({ available: boolean, downloaded?: boolean, version?: string }) ``` ### Parameters @@ -55,6 +55,8 @@ E2EMockClient.setMockUpdateState({ available: boolean, version?: string }) - `version` (string, optional): This parameter specifies the version of the update that is available. It is only required if `available` is set to `true`. +- `downloaded` (boolean, optional): This parameter indicates whether the download process was successful (`true`) or not (`false`). When downloaded is `true`, the modal shows in-progress indefinitely, and in the production environment, the application closes to complete the installation process. When downloaded is `false`, the application displays an error message. + ## Usage Examples ### No Update Available @@ -71,6 +73,20 @@ To set the response indicating that an update is available with a specified vers E2EMockClient.setMockUpdateState({ available: true, version: "4.0.0" }) ``` +### Update Available with Download Failure + +To set the response indicating that an update is available with a specified version, but the download process fails, use the following command: +```javascript +E2EMockClient.setMockUpdateState({ available: true, version: "4.0.0", downloaded: false }) +``` + +### Update Available with Successful Download + +To set the response indicating that an update is available with a specified version and the download process is successful, use the following command: +```javascript +E2EMockClient.setMockUpdateState({ available: true, version: "4.0.0", downloaded: true }) +``` + ### Required Mudita Center Update To set the response indicating that an update is available and a Mudita Center update is required for versions lower than 3.0.0, use the following commands: diff --git a/libs/e2e-mock/server/src/lib/mock-updater-state.service.ts b/libs/e2e-mock/server/src/lib/mock-updater-state.service.ts index 95abbb67da..79a0c9d489 100644 --- a/libs/e2e-mock/server/src/lib/mock-updater-state.service.ts +++ b/libs/e2e-mock/server/src/lib/mock-updater-state.service.ts @@ -5,20 +5,24 @@ export interface UpdateState { available: boolean + downloaded?: boolean version?: string } +const defaultUpdateState: UpdateState = { + available: false, + downloaded: true, +} + export class MockUpdaterStateService { - private _updateState: UpdateState = { - available: false, - } + private _updateState = { ...defaultUpdateState } get updateState(): UpdateState { return this._updateState } set updateState(value: UpdateState) { - this._updateState = value + this._updateState = { ...defaultUpdateState, ...value } } } diff --git a/libs/electron/application-updater/src/lib/mock-application-updater.service.ts b/libs/electron/application-updater/src/lib/mock-application-updater.service.ts index c765fb73c6..db469ef009 100644 --- a/libs/electron/application-updater/src/lib/mock-application-updater.service.ts +++ b/libs/electron/application-updater/src/lib/mock-application-updater.service.ts @@ -16,15 +16,15 @@ export class MockApplicationUpdaterService extends BaseApplicationUpdaterService ) { super() } - - @IpcEvent(IpcApplicationUpdaterEvent.Install) - public quitAndInstall(): void { - this.onError() - } + public quitAndInstall(): void {} @IpcEvent(IpcApplicationUpdaterEvent.Download) public async downloadUpdate(): Promise { - this.onError() + if (this.isUpdateDownloaded()) { + this.onUpdateDownloaded() + } else { + this.onError() + } } @IpcEvent(IpcApplicationUpdaterEvent.Check) @@ -39,6 +39,11 @@ export class MockApplicationUpdaterService extends BaseApplicationUpdaterService this.onUpdateNotAvailable() } } + + private isUpdateDownloaded(): boolean { + return this.mockUpdaterStateService.updateState.downloaded ?? true + } + private isUpdateAvailable(): boolean { return this.mockUpdaterStateService.updateState.available } From c69d20558da1669b26b44cc200a461215348cfb5 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Mon, 8 Jul 2024 09:28:07 +0200 Subject: [PATCH 039/100] [CP-2940] Allow Opening of Developer Tools in Mock Environment (#1934) --- .env.example | 6 +++ .github/workflows/nexus-development.yml | 3 ++ .github/workflows/nexus-feature-branch.yml | 3 ++ .github/workflows/nexus-mock-development.yml | 2 + .../workflows/nexus-mock-pre-production.yml | 2 + .github/workflows/nexus-mock-production.yml | 2 + apps/mudita-center/src/main.ts | 44 +++++++------------ libs/shared/utils/src/index.ts | 5 ++- .../src/lib/open-dev-tools-once-dom-ready.ts | 24 ++++++++++ .../src/lib/prevent-default-shortcuts.ts | 25 +++++++++++ .../utils/src/lib/register-shortcuts.ts | 25 +++++++++++ 11 files changed, 113 insertions(+), 28 deletions(-) create mode 100644 libs/shared/utils/src/lib/open-dev-tools-once-dom-ready.ts create mode 100644 libs/shared/utils/src/lib/prevent-default-shortcuts.ts create mode 100644 libs/shared/utils/src/lib/register-shortcuts.ts diff --git a/.env.example b/.env.example index da38ca1c0b..9d40dd199a 100644 --- a/.env.example +++ b/.env.example @@ -72,3 +72,9 @@ MATOMO_TO_GSHEET_SITE_ID= # [Optional] Set 1 run application with mock server MOCK_SERVICE_ENABLED= + +# [Optional] Enable shortcut for opening DevTools. Disabled by default, set "1" to enable +DEV_TOOLS_SHORTCUT_ENABLED= + +# [Optional] Automatically open DevTools on startup. Disabled by default, set "1" to enable +DEV_TOOLS_AUTO_OPEN_ENABLED= diff --git a/.github/workflows/nexus-development.yml b/.github/workflows/nexus-development.yml index 9ad74baf69..9e82ff77c7 100644 --- a/.github/workflows/nexus-development.yml +++ b/.github/workflows/nexus-development.yml @@ -43,6 +43,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" LOCALAPPDATA: "" shell: cmd run: | @@ -72,6 +73,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" run: | printenv > .env - name: Setup Env for Linux @@ -98,6 +100,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" run: | printenv > .env - name: Changing app version in packages.json for Linux diff --git a/.github/workflows/nexus-feature-branch.yml b/.github/workflows/nexus-feature-branch.yml index 224e482a63..888bbb7175 100644 --- a/.github/workflows/nexus-feature-branch.yml +++ b/.github/workflows/nexus-feature-branch.yml @@ -43,6 +43,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" LOCALAPPDATA: "" shell: cmd run: | @@ -72,6 +73,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" run: | printenv > .env - name: Setup Env for Linux @@ -98,6 +100,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" run: | printenv > .env - name: Changing app version in packages.json for Linux diff --git a/.github/workflows/nexus-mock-development.yml b/.github/workflows/nexus-mock-development.yml index dcfb923f8b..8f673c575a 100644 --- a/.github/workflows/nexus-mock-development.yml +++ b/.github/workflows/nexus-mock-development.yml @@ -43,6 +43,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" LOCALAPPDATA: "" MOCK_SERVICE_ENABLED: "1" shell: cmd @@ -73,6 +74,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" MOCK_SERVICE_ENABLED: "1" run: | printenv > .env diff --git a/.github/workflows/nexus-mock-pre-production.yml b/.github/workflows/nexus-mock-pre-production.yml index d32697c93a..84a84350e4 100644 --- a/.github/workflows/nexus-mock-pre-production.yml +++ b/.github/workflows/nexus-mock-pre-production.yml @@ -45,6 +45,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" LOCALAPPDATA: "" MOCK_SERVICE_ENABLED: "1" shell: cmd @@ -75,6 +76,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" MOCK_SERVICE_ENABLED: "1" run: | printenv > .env diff --git a/.github/workflows/nexus-mock-production.yml b/.github/workflows/nexus-mock-production.yml index febb639529..91dccf2920 100644 --- a/.github/workflows/nexus-mock-production.yml +++ b/.github/workflows/nexus-mock-production.yml @@ -45,6 +45,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" LOCALAPPDATA: "" MOCK_SERVICE_ENABLED: "1" shell: cmd @@ -75,6 +76,7 @@ jobs: DEV_DEVICE_LOGGER_ENABLED: ${{ secrets.DEV_DEVICE_LOGGER_ENABLED }} FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} + DEV_TOOLS_SHORTCUT_ENABLED: "1" MOCK_SERVICE_ENABLED: "1" run: | printenv > .env diff --git a/apps/mudita-center/src/main.ts b/apps/mudita-center/src/main.ts index 3ee2751737..bc6c41fec9 100644 --- a/apps/mudita-center/src/main.ts +++ b/apps/mudita-center/src/main.ts @@ -80,7 +80,14 @@ import installExtension, { REDUX_DEVTOOLS, REACT_DEVELOPER_TOOLS, } from "electron-devtools-installer" -import { AppEvents, callRenderer, getMainAppWindow } from "shared/utils" +import { + AppEvents, + callRenderer, + getMainAppWindow, + openDevToolsOnceDomReady, + preventDefaultShortcuts, + registerShortcuts, +} from "shared/utils" import { mockServiceEnabled, startServer, stopServer } from "e2e-mock-server" // AUTO DISABLED - fix me if you like :) @@ -184,12 +191,6 @@ const createWindow = async () => { require("@electron/remote/main").enable(win.webContents) win.removeMenu() - win.webContents.on("before-input-event", (event, input) => { - if ((input.control || input.meta) && input.key.toLowerCase() === "r") { - event.preventDefault() - } - }) - win.on("closed", () => { win = null app.exit() @@ -250,26 +251,9 @@ const createWindow = async () => { } }) - if (productionEnvironment) { - win.webContents.once("dom-ready", () => { - appModules.lateInitialization() - }) - } else { - // Open DevTools, see https://github.com/electron/electron/issues/12438 for why we wait for dom-ready - win.webContents.once("dom-ready", () => { - // AUTO DISABLED - fix me if you like :) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - win!.webContents.openDevTools() - appModules.lateInitialization() - }) - - win.webContents.once("dom-ready", () => { - win!.webContents.once("devtools-opened", () => { - win!.focus() - }) - win!.webContents.openDevTools() - }) - } + win.webContents.once("dom-ready", () => { + appModules.lateInitialization() + }) logger.updateMetadata() } @@ -281,6 +265,12 @@ if (!gotTheLock) { // eslint-disable-next-line @typescript-eslint/no-misused-promises app.on("ready", createWindow) + app.on("browser-window-created", (_event, window) => { + preventDefaultShortcuts(window) + registerShortcuts(window) + openDevToolsOnceDomReady(window) + }) + app.on("before-quit", () => { stopServer() }) diff --git a/libs/shared/utils/src/index.ts b/libs/shared/utils/src/index.ts index 857e37930d..1234138677 100644 --- a/libs/shared/utils/src/index.ts +++ b/libs/shared/utils/src/index.ts @@ -7,7 +7,10 @@ export * from "./lib/answer-main" export * from "./lib/call-renderer.helper" export * from "./lib/delay" export * from "./lib/get-main-app-window" -export * from "./lib/routes-history.context" export * from "./lib/main-event.constant" +export * from "./lib/open-dev-tools-once-dom-ready" +export * from "./lib/prevent-default-shortcuts" +export * from "./lib/register-shortcuts" +export * from "./lib/routes-history.context" export * from "./lib/settings-service.interface" export * from "./lib/use-debounced-events-handler" diff --git a/libs/shared/utils/src/lib/open-dev-tools-once-dom-ready.ts b/libs/shared/utils/src/lib/open-dev-tools-once-dom-ready.ts new file mode 100644 index 0000000000..ae211c1959 --- /dev/null +++ b/libs/shared/utils/src/lib/open-dev-tools-once-dom-ready.ts @@ -0,0 +1,24 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { BrowserWindow } from "electron" + +export function openDevToolsOnceDomReady(win: BrowserWindow) { + if (process.env.DEV_TOOLS_AUTO_OPEN_ENABLED !== "1") { + return + } + + // Open DevTools, see https://github.com/electron/electron/issues/12438 for why we wait for dom-ready + win.webContents.once("dom-ready", () => { + win.webContents.openDevTools() + }) + + win.webContents.once("dom-ready", () => { + win.webContents.once("devtools-opened", () => { + win.focus() + }) + win.webContents.openDevTools() + }) +} diff --git a/libs/shared/utils/src/lib/prevent-default-shortcuts.ts b/libs/shared/utils/src/lib/prevent-default-shortcuts.ts new file mode 100644 index 0000000000..ab4127000a --- /dev/null +++ b/libs/shared/utils/src/lib/prevent-default-shortcuts.ts @@ -0,0 +1,25 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { BrowserWindow } from "electron" + +export function preventDefaultShortcuts(win: BrowserWindow) { + win.webContents.on("before-input-event", (event, input) => { + const { control, meta } = input + const key = input.key.toLowerCase() + + // Prevent default refresh shortcut (Ctrl+R or Cmd+R) + if ((control || meta) && key === "r") { + event.preventDefault() + } + + // Prevent default DevTools shortcut (Ctrl+Shift+I or Cmd+Opt+I) and 'dead' key issue + // This is necessary because removing the menu in Windows/Linux disables the shortcut, + // but on macOS, the shortcut still works. Therefore, we need to explicitly prevent it. + if ((control || meta) && (key === "dead" || key === "i")) { + event.preventDefault() + } + }) +} diff --git a/libs/shared/utils/src/lib/register-shortcuts.ts b/libs/shared/utils/src/lib/register-shortcuts.ts new file mode 100644 index 0000000000..4f64456642 --- /dev/null +++ b/libs/shared/utils/src/lib/register-shortcuts.ts @@ -0,0 +1,25 @@ +/** + * Copyright (c) Mudita sp. z o.o. All rights reserved. + * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md + */ + +import { BrowserWindow, globalShortcut } from "electron" + +export function registerShortcuts(win: BrowserWindow) { + if (process.env.DEV_TOOLS_SHORTCUT_ENABLED !== "1") { + return + } + + const devToolsShortcutKey = + process.platform === "darwin" ? "Command+Option+I" : "Ctrl+Shift+I" + + win.on("focus", () => { + globalShortcut.register(devToolsShortcutKey, () => { + win.webContents.toggleDevTools() + }) + }) + + win.on("blur", () => { + globalShortcut.unregister(devToolsShortcutKey) + }) +} From 779cf78f0c1234c9a4f1876a6b6e6b84ae609ac5 Mon Sep 17 00:00:00 2001 From: Daniel Karski Date: Mon, 8 Jul 2024 11:14:57 +0200 Subject: [PATCH 040/100] [CP-2940] Allow Opening of Developer Tools in Mock Environment - vol.2 (#1960) --- .github/workflows/nexus-mock-development.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/nexus-mock-development.yml b/.github/workflows/nexus-mock-development.yml index 8f673c575a..e6a3ca56ac 100644 --- a/.github/workflows/nexus-mock-development.yml +++ b/.github/workflows/nexus-mock-development.yml @@ -103,6 +103,7 @@ jobs: FEATURE_TOGGLE_RELEASE_ENVIRONMENT: ${{ secrets.FEATURE_TOGGLE_RELEASE_ENVIRONMENT }} MUDITA_CENTER_PRERELEASE_ENABLED: ${{ secrets.MUDITA_CENTER_PRERELEASE_ENABLED }} MOCK_SERVICE_ENABLED: "1" + DEV_TOOLS_SHORTCUT_ENABLED: "1" run: | printenv > .env - name: Changing app version in packages.json for Linux From 8a225aa97714f8ac177cf364d311722bb5213a87 Mon Sep 17 00:00:00 2001 From: robertmudi <158469469+robertmudi@users.noreply.github.com> Date: Wed, 10 Jul 2024 11:26:46 +0200 Subject: [PATCH 041/100] [CP-2753] added new test - kompakt-overview (#1936) Use Kompakt mocking system and verify design of an overview page --- .../src/consts/regex-const.ts | 1 + .../src/page-objects/overview-kompakt.page.ts | 64 +++++++- .../src/page-objects/overview.page.ts | 138 +++++------------- .../src/page-objects/tabs.page.ts | 26 ++-- .../src/specs/overview/kompakt-overview.ts | 129 ++++++++++++++++ .../consts/test-filenames.const.ts | 1 + apps/mudita-center-e2e/wdio.conf.ts | 13 +- .../responses/src/lib/overview-responses.ts | 18 +++ .../ui/src/lib/blocks/block-box.tsx | 2 +- .../ui/src/lib/buttons/button-text.tsx | 7 +- .../ui/src/lib/data-rows/image.tsx | 6 +- .../lib/predefined/overview-os-version.tsx | 19 ++- .../utils/src/lib/models/api-fc.types.ts | 2 +- 13 files changed, 291 insertions(+), 135 deletions(-) create mode 100644 apps/mudita-center-e2e/src/specs/overview/kompakt-overview.ts diff --git a/apps/mudita-center-e2e/src/consts/regex-const.ts b/apps/mudita-center-e2e/src/consts/regex-const.ts index e5740a4bea..57013bbc11 100644 --- a/apps/mudita-center-e2e/src/consts/regex-const.ts +++ b/apps/mudita-center-e2e/src/consts/regex-const.ts @@ -6,6 +6,7 @@ export const linkRegex: RegExp = /^(https?:\/\/)(mudita.com\/community|forum.mudita.com\/t).*$/ export const newsImageRegex: RegExp = /(^data:image;base64)/ +export const kompaktImageRegex: RegExp = /(^data:image\/png;base64)/ export const newsDateRegex: RegExp = /^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(\s{1})([1-9]|[12][0-9]|3[01])(,{1})(\s{1})([2-9][0-9][0-9][0-9])$/ export const commentsRegex: RegExp = /^(\d+)(\s{1})(COMMENTS|COMMENT)$/ diff --git a/apps/mudita-center-e2e/src/page-objects/overview-kompakt.page.ts b/apps/mudita-center-e2e/src/page-objects/overview-kompakt.page.ts index 606b247560..c88fb5da68 100644 --- a/apps/mudita-center-e2e/src/page-objects/overview-kompakt.page.ts +++ b/apps/mudita-center-e2e/src/page-objects/overview-kompakt.page.ts @@ -3,9 +3,67 @@ * For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md */ -import { ChainablePromiseElement } from "webdriverio" -import OverviewPage from "./overview.page" +import { OverviewPage } from "./overview.page" -class OverviewKompaktPage extends OverviewPage {} +class OverviewKompaktPage extends OverviewPage { + public get aboutYourDevice() { + return $('[data-testid="button-text_summary-about"]') + } + public get sarInformationButtonKompakt() { + return $('[data-testid="button-text_sarmodal-button"]') + } + + public get sarInformationPopup() { + return $("/html/body/div[10]/div/div") + } + + public get sarInformationPopupCloseButton() { + return $('[data-testid="icon-close"]') + } + + public get backupInfo() { + return $(`//div[@componentkey="backupbackup-info"]/p`) + } + + public get serialNumberLabel() { + return $(`//div[@componentkey="summary-serial-number"]/p[1]`) + } + + public get serialNumberValue() { + return $(`//div[@componentkey="summary-serial-number"]/p[2]`) + } + + public get kompaktImage() { + return $('[data-testid="generic-view-image"]') + } + + public get kompaktSignalIcon() { + return $('[data-testid="icon-network-signal-2"]') + } + + public get kompaktNetworkName() { + return $('[data-testid="icon-text"]') + } + + public get kompaktBatteryIcon() { + return $('//div[@data-testid="icon-battery-charging-2"]') + } + + public get kompaktBatteryLevelValue() { + return $('//h3[text()="Status"]/..//h4[@data-testid="icon-text"]') + } + + public get kompaktSimCard1() { + return $('[data-testid="icon-subtext"]') + } + + public get kompaktOsVersion() { + return $('[data-testid="version"]') + } + + public get kompaktOsVersionLabel() { + return $('[data-testid="version-label"]') + } +} export default new OverviewKompaktPage() diff --git a/apps/mudita-center-e2e/src/page-objects/overview.page.ts b/apps/mudita-center-e2e/src/page-objects/overview.page.ts index 4aae54d5d6..939ac4e4be 100644 --- a/apps/mudita-center-e2e/src/page-objects/overview.page.ts +++ b/apps/mudita-center-e2e/src/page-objects/overview.page.ts @@ -6,207 +6,139 @@ import { ChainablePromiseElement } from "webdriverio" import Page from "./page" -class OverviewPage extends Page { - public get currentDeviceVersion(): ChainablePromiseElement< - Promise - > { +export class OverviewPage extends Page { + public get currentDeviceVersion() { return $("p*=MuditaOS") } - public get checkingForUpdateLoader(): ChainablePromiseElement< - Promise - > { + public get checkingForUpdateLoader() { return $("h4*=Checking for MuditaOS update...") } - public get downloadUpdateLoader(): ChainablePromiseElement< - Promise - > { + public get downloadUpdateLoader() { return $("*=Downloading update...") } - public get updateStatusLoader(): ChainablePromiseElement< - Promise - > { + public get updateStatusLoader() { return $("p*=Updating MuditaOS…") } - public get updateCompletedStatus(): ChainablePromiseElement< - Promise - > { + public get updateCompletedStatus() { return $("p*=Update completed!") } - public get checkForUpdateButton(): ChainablePromiseElement< - Promise - > { + public get checkForUpdateButton() { return $("button*=Check for updates") } - public get downloadUpdateNowButton(): ChainablePromiseElement< - Promise - > { + public get downloadUpdateNowButton() { return $('[data-testid="modal-action-button"]*=Download now') } - public get updateNowButton(): ChainablePromiseElement< - Promise - > { + public get updateNowButton() { return $('[data-testid="modal-action-button"]*=Update now') } - public get aboutYourPureButton(): ChainablePromiseElement< - Promise - > { + public get aboutYourPureButton() { return $("p*=About your Pure") } - public get checkSARInformationButton(): ChainablePromiseElement< - Promise - > { + public get checkSARInformationButton() { return $("p*=Check SAR information") } - public get sarWrapper(): ChainablePromiseElement< - Promise - > { + public get sarWrapper() { return $('[data-testid="sar-wrapper"]') } - public get backToOverviewButton(): ChainablePromiseElement< - Promise - > { + public get backToOverviewButton() { return $("p*=Back to Overview") } - public get createBackupButton(): ChainablePromiseElement< - Promise - > { + public get createBackupButton() { return $("p*=Create backup") } - public get restoreBackupButton(): ChainablePromiseElement< - Promise - > { + public get restoreBackupButton() { return $("p*=Restore last backup") } - public get locationTextLabel(): ChainablePromiseElement< - Promise - > { + public get locationTextLabel() { return $('[data-testid="location"]') } - public get batteryLevel(): ChainablePromiseElement< - Promise - > { + public get batteryLevel() { return $('[data-testid="battery-level"]') } - public get fullBatteryIcon(): ChainablePromiseElement< - Promise - > { + public get fullBatteryIcon() { return $('[data-testid="icon-FullBattery"]') } - public get veryHighBatteryIcon(): ChainablePromiseElement< - Promise - > { + public get veryHighBatteryIcon() { return $('[data-testid="icon-VeryHighBattery"]') } - public get highBatteryIcon(): ChainablePromiseElement< - Promise - > { + public get highBatteryIcon() { return $('[data-testid="icon-HighBattery"]') } - public get mediumBatteryIcon(): ChainablePromiseElement< - Promise - > { + public get mediumBatteryIcon() { return $('[data-testid="icon-MediumBattery"]') } - public get lowBatteryIcon(): ChainablePromiseElement< - Promise - > { + public get lowBatteryIcon() { return $('[data-testid="icon-LowBattery"]') } - public get veryLowBatteryIcon(): ChainablePromiseElement< - Promise - > { + public get veryLowBatteryIcon() { return $('[data-testid="icon-VeryLowBattery"]') } - public get noRangeIcon(): ChainablePromiseElement< - Promise - > { + public get noRangeIcon() { return $('[data-testid="icon-NoRange"]') } - public get LowRangeIcon(): ChainablePromiseElement< - Promise - > { + public get LowRangeIcon() { return $('[data-testid="icon-LowRange"]') } - public get MediumRangeIcon(): ChainablePromiseElement< - Promise - > { + public get MediumRangeIcon() { return $('[data-testid="icon-MediumRange"]') } - public get HighRangeIcon(): ChainablePromiseElement< - Promise - > { + public get HighRangeIcon() { return $('[data-testid="icon-HighRange"]') } - public get VeryHighRangeIcon(): ChainablePromiseElement< - Promise - > { + public get VeryHighRangeIcon() { return $('[data-testid="icon-VeryHighRange"]') } - public get disconnectButton(): ChainablePromiseElement< - Promise - > { + public get disconnectButton() { return $('[data-testid="disconnect-button"]') } - public get networkName(): ChainablePromiseElement< - Promise - > { + public get networkName() { return $('[data-testid="network-name"]') } - public get pureGrayImage(): ChainablePromiseElement< - Promise - > { + public get pureGrayImage() { return $('[data-testid="pure-gray"]') } - public get pureBlackImage(): ChainablePromiseElement< - Promise - > { + public get pureBlackImage() { return $('[data-testid="pure-black"]') } - public get aboutYourPureSerialNumber(): ChainablePromiseElement< - Promise - > { + public get aboutYourPureSerialNumber() { return $('[data-testid="serial-number-value"]') } - public get overviewSerialNumber(): ChainablePromiseElement< - Promise - > { + public get overviewSerialNumber() { return $('[data-testid="device-serial-number"]') } - public get muditaOSVersion(): ChainablePromiseElement< - Promise - > { + public get muditaOSVersion() { return $('[data-testid="os-version"]') } } diff --git a/apps/mudita-center-e2e/src/page-objects/tabs.page.ts b/apps/mudita-center-e2e/src/page-objects/tabs.page.ts index 18481f4abd..795cb7a1d1 100644 --- a/apps/mudita-center-e2e/src/page-objects/tabs.page.ts +++ b/apps/mudita-center-e2e/src/page-objects/tabs.page.ts @@ -7,15 +7,11 @@ import { ChainablePromiseElement } from "webdriverio" import Page from "./page" class NavigationTabs extends Page { - public get muditaNewsTab(): ChainablePromiseElement< - Promise - > { + public get muditaNewsTab() { return $('[data-testid="icon-MenuNews"]') } - public get overviewTab(): ChainablePromiseElement< - Promise - > { + public get overviewTab() { return $('[data-testid="overview-link"]') } @@ -23,9 +19,11 @@ class NavigationTabs extends Page { await this.overviewTab.click() } - public get messagesTab(): ChainablePromiseElement< - Promise - > { + public get overviewKompaktTab() { + return $('[data-testid="icon-MenuOverview"]') + } + + public get messagesTab() { return $('[data-testid="overview-menu-link"]') } @@ -34,9 +32,7 @@ class NavigationTabs extends Page { await this.messagesTab.click() } - public get contactsTab(): ChainablePromiseElement< - Promise - > { + public get contactsTab() { return $('[data-testid="contacts-menu-link"]') } @@ -45,9 +41,7 @@ class NavigationTabs extends Page { await this.contactsTab.click() } - public get settingsTab(): ChainablePromiseElement< - Promise - > { + public get settingsTab() { return $('[data-testid="icon-MenuSettings"]') } @@ -55,7 +49,7 @@ class NavigationTabs extends Page { await this.settingsTab.click() } - public get helpTab(): ChainablePromiseElement> { + public get helpTab() { return $('[data-testid="help-menu-button"]') } diff --git a/apps/mudita-center-e2e/src/specs/overview/kompakt-overview.ts b/apps/mudita-center-e2e/src/specs/overview/kompakt-overview.ts new file mode 100644 index 0000000000..5004d33818 --- /dev/null +++ b/apps/mudita-center-e2e/src/specs/overview/kompakt-overview.ts @@ -0,0 +1,129 @@ +import { E2EMockClient } from "../../../../../libs/e2e-mock/client/src" +import { overviewDataWithOneSimCard } from "../../../../../libs/e2e-mock/responses/src" +import OverviewPage from "../../page-objects/overview.page" +import OverviewKompaktPage from "../../page-objects/overview-kompakt.page" +import HomePage from "../../page-objects/home.page" +import tabsPage from "../../page-objects/tabs.page" +import { kompaktImageRegex } from "../../consts/regex-const" + +describe("E2E mock sample - overview view", () => { + before(async () => { + E2EMockClient.connect() + //wait for a connection to be established + await browser.waitUntil(() => { + return E2EMockClient.checkConnection() + }) + }) + + after(() => { + E2EMockClient.stopServer() + E2EMockClient.disconnect() + }) + + it("Connect device", async () => { + E2EMockClient.mockResponse({ + path: "path-1", + body: overviewDataWithOneSimCard, + endpoint: "FEATURE_DATA", + method: "GET", + status: 200, + }) + E2EMockClient.addDevice({ + path: "path-1", + serialNumber: "first-serial-number", + }) + + await browser.pause(6000) + const menuItem = await $(`//a[@href="#/generic/mc-overview"]`) + + await menuItem.waitForDisplayed({ timeout: 10000 }) + await expect(menuItem).toBeDisplayed() + }) + + it("Verify Overview Page", async () => { + const kompaktImage = await OverviewKompaktPage.kompaktImage + await expect(kompaktImage).toBeDisplayed + console.log(kompaktImage) + await expect(kompaktImage).toHaveAttribute("src", kompaktImageRegex) + + const kompaktOsVersion = await OverviewKompaktPage.kompaktOsVersion + await expect(kompaktOsVersion).toBeDisplayed + + const kompaktOsVersionLabel = + await OverviewKompaktPage.kompaktOsVersionLabel + await expect(kompaktOsVersionLabel).toBeDisplayed + + const serialNumberLabel = await OverviewKompaktPage.serialNumberLabel + const serialNumberValue = await OverviewKompaktPage.serialNumberValue + await expect(serialNumberLabel).toHaveText("Serial number") + await expect(serialNumberValue).toHaveText( + overviewDataWithOneSimCard.summary.about.serialNumber.text.toString() + ) + + const aboutYourDevice = await OverviewKompaktPage.aboutYourDevice + await expect(aboutYourDevice).toBeDisplayed + console.log(aboutYourDevice) + await expect(aboutYourDevice).toBeClickable + await aboutYourDevice.click() + + const sarInformationButtonKompakt = + await OverviewKompaktPage.sarInformationButtonKompakt + const sarInformationPopup = await OverviewKompaktPage.sarInformationPopup + await expect(sarInformationButtonKompakt).toBeDisplayed + await sarInformationButtonKompakt.click() + await expect(sarInformationPopup).toBeDisplayed + + const sarInformationPopupCloseButton = + await OverviewKompaktPage.sarInformationPopupCloseButton + await sarInformationPopupCloseButton.click() + + const createBackupButton = await OverviewPage.createBackupButton + await expect(createBackupButton).toBeDisplayed + await expect(createBackupButton).toBeClickable + + const backupInfo = await OverviewKompaktPage.backupInfo + await expect(backupInfo).toBeDisplayed + const str: string = + "\tYou haven’t backed up your device yet.\n Create a backup file to protect against data loss.\n" + const backupInfoText: string = str.trim() + + const kompaktBatteryIcon = await OverviewKompaktPage.kompaktBatteryIcon + await expect(kompaktBatteryIcon).toBeDisplayed + + const kompaktBatteryLevelValue = + await OverviewKompaktPage.kompaktBatteryLevelValue + await expect(kompaktBatteryLevelValue).toBeDisplayed + const batteryValNum: string = "100%" + const batteryValue: string = batteryValNum + + const kompaktNetworkName = await OverviewKompaktPage.kompaktNetworkName + await expect(kompaktNetworkName).toBeDisplayed + const strNetwork: string = "T-Mobile" + const networkName: string = strNetwork + + const kompaktSignalIcon = await OverviewKompaktPage.kompaktSignalIcon + await expect(kompaktSignalIcon).toBeDisplayed + const strSignal: string = "network-signal-2" + const signalValue: string = strSignal + + const kompaktSimCard1 = await OverviewKompaktPage.kompaktSimCard1 + await expect(kompaktSimCard1).toBeDisplayed + const sim1: string = "SIM 1" + const simInfo: string = sim1 + }) + + it("Click between Tabs and check them", async () => { + const muditaNewsTab = await tabsPage.muditaNewsTab + await muditaNewsTab.waitForClickable() + await muditaNewsTab.click() + + const overviewKompaktTab = await tabsPage.overviewKompaktTab + await overviewKompaktTab.waitForClickable() + await overviewKompaktTab.click() + }) + + it("Disconnect the device and check if Welcome screen is present", async () => { + E2EMockClient.removeDevice("path-1") + await HomePage.homeHeader.waitForDisplayed() + }) +}) diff --git a/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts b/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts index 10e4e12dc3..e451d0cea2 100644 --- a/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts +++ b/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts @@ -18,5 +18,6 @@ export enum TestFilesPaths { privacyPolicyTest = "src/specs/settings/privacy-policy.e2e.ts", licenseTest = "src/specs/settings/license.e2e.ts", helpWindowCheckOfflineTest = "src/specs/help/help-window-check-offline.e2e.ts", + kompaktOverview = "src/specs/overview/kompakt-overview.ts", } export const toRelativePath = (path: string) => `./${path}` diff --git a/apps/mudita-center-e2e/wdio.conf.ts b/apps/mudita-center-e2e/wdio.conf.ts index e51198e7c5..080dc69d46 100644 --- a/apps/mudita-center-e2e/wdio.conf.ts +++ b/apps/mudita-center-e2e/wdio.conf.ts @@ -67,6 +67,7 @@ export const config: Options.Testrunner = { toRelativePath(TestFilesPaths.privacyPolicyTest), toRelativePath(TestFilesPaths.licenseTest), toRelativePath(TestFilesPaths.helpWindowCheckOfflineTest), + toRelativePath(TestFilesPaths.kompaktOverview), ], suites: { standalone: [ @@ -76,16 +77,17 @@ export const config: Options.Testrunner = { toRelativePath(TestFilesPaths.newsPageOnlineTest), toRelativePath(TestFilesPaths.termsOfServiceTest), toRelativePath(TestFilesPaths.backupLocationTest), - toRelativePath(TestFilesPaths.mcCheckForUpdatesOfflineTest), toRelativePath(TestFilesPaths.homePageTestDeviceNotConnectedTest), - toRelativePath(TestFilesPaths.newsPageOnlineTest), - toRelativePath(TestFilesPaths.termsOfServiceTest), - toRelativePath(TestFilesPaths.e2eMockSample), toRelativePath(TestFilesPaths.privacyPolicyTest), toRelativePath(TestFilesPaths.licenseTest), toRelativePath(TestFilesPaths.helpWindowCheckOfflineTest), ], - mock: [toRelativePath(TestFilesPaths.e2eMockSample)], + mock: [ + toRelativePath(TestFilesPaths.newsPageOfflineTest), + toRelativePath(TestFilesPaths.mcCheckForUpdatesOfflineTest), + toRelativePath(TestFilesPaths.e2eMockSample), + toRelativePath(TestFilesPaths.kompaktOverview), + ], multidevicePureHarmony: [], multideviceSingleHarmony: [], multideviceSinglePure: [], @@ -108,6 +110,7 @@ export const config: Options.Testrunner = { toRelativePath(TestFilesPaths.privacyPolicyTest), toRelativePath(TestFilesPaths.licenseTest), toRelativePath(TestFilesPaths.helpWindowCheckOfflineTest), + toRelativePath(TestFilesPaths.kompaktOverview), ], }, // Patterns to exclude. diff --git a/libs/e2e-mock/responses/src/lib/overview-responses.ts b/libs/e2e-mock/responses/src/lib/overview-responses.ts index 1afb5b64cc..64322604de 100644 --- a/libs/e2e-mock/responses/src/lib/overview-responses.ts +++ b/libs/e2e-mock/responses/src/lib/overview-responses.ts @@ -20,3 +20,21 @@ export const overviewDataWithoutBadge = { "airplane-mode": { icon: "airplane-mode", text: "Airplane mode" }, }, } + +export const overviewDataWithOneSimCard = { + summary: { + about: { + serialNumber: { text: "0123456789ABCDEF" }, + imei1: { text: "864055030138811" }, + imei2: { text: "864055030138829" }, + sar: { + text: "### SAR\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sed aliquet ligula, viverra feugiat massa. In hac habitasse platea dictumst.\n\n1. Interdum et malesuada fames ac ante ipsum primis in faucibus.\n2. Suspendisse consectetur, nibh non consequat hendrerit, nibh felis commodo lacus, id auctor ante purus vitae justo.\n3. Cras purus neque, pharetra vitae nulla ac, mollis facilisis felis. Sed sit amet ex diam.\n\n> Sed accumsan sem nec iaculis euismod.", + }, + }, + }, + sections: { + battery: { icon: "battery-charging-5", text: "100%", subText: "" }, + update: { text: "ANDROID 12", version: "0.3.0" }, + "airplane-mode": { icon: "network-signal-2", text: "T-Mobile" }, + }, +} diff --git a/libs/generic-view/ui/src/lib/blocks/block-box.tsx b/libs/generic-view/ui/src/lib/blocks/block-box.tsx index 205f99f77e..8add72bafe 100644 --- a/libs/generic-view/ui/src/lib/blocks/block-box.tsx +++ b/libs/generic-view/ui/src/lib/blocks/block-box.tsx @@ -16,7 +16,7 @@ export const BlockBox: APIFC = ({ ...props }) => { return ( - + {config?.title && ( {config.title} diff --git a/libs/generic-view/ui/src/lib/buttons/button-text.tsx b/libs/generic-view/ui/src/lib/buttons/button-text.tsx index e2859d2930..078187c4da 100644 --- a/libs/generic-view/ui/src/lib/buttons/button-text.tsx +++ b/libs/generic-view/ui/src/lib/buttons/button-text.tsx @@ -17,7 +17,12 @@ export const ButtonText: APIFC = ({ ...props }) => { return ( -