view-model.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const settingsService = require('../../store/settings-store.js')
  2. const themeService = require('../../store/theme-store.js')
  3. const transport = require('../../transport/ble-core.js')
  4. const bootloaderService = require('../bootloader/service.js')
  5. const toolNavigation = require('../tools/navigation.js')
  6. function getSettingsPageState(
  7. settingsState = settingsService.getState(),
  8. themeState = themeService.getState(),
  9. transportState = transport.getState(),
  10. bootloaderState = bootloaderService.getState()
  11. ) {
  12. const nightModeEnabledSwitch = settingsState.nightModeFollowSystem
  13. ? themeState.themeMode === 'dark'
  14. : settingsState.nightModeEnabled
  15. const modbusProtocolOptions = settingsService.MODBUS_PROTOCOL_OPTIONS
  16. const modbusProtocolIndex = Math.max(0, modbusProtocolOptions.findIndex((option) => (
  17. option.key === settingsState.modbusProtocolMode
  18. )))
  19. const modbusProtocol = modbusProtocolOptions[modbusProtocolIndex] || modbusProtocolOptions[0]
  20. return {
  21. ...settingsState,
  22. ...themeState,
  23. ...bootloaderState,
  24. connectedDevice: transportState.connectedDevice,
  25. genericModbusMinPacketLength: settingsService.GENERIC_MODBUS_MIN_PACKET_LENGTH,
  26. isGenericProtocol: modbusProtocol.key === 'generic',
  27. isPrivateProtocol: modbusProtocol.key === 'private',
  28. modbusProtocolIndex,
  29. modbusProtocolOptions,
  30. modbusProtocolText: modbusProtocol.label,
  31. nightModeEnabledSwitch,
  32. statusPollMaxInterval: settingsService.STATUS_POLL_MAX_INTERVAL,
  33. statusPollMinInterval: settingsService.STATUS_POLL_MIN_INTERVAL,
  34. toolEntries: toolNavigation.getToolEntries()
  35. }
  36. }
  37. module.exports = {
  38. getSettingsPageState
  39. }