view-model.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 protocolMode = settingsService.isModbusProtocol(settingsState.protocolMode)
  16. ? settingsService.PROTOCOL_MODE.MODBUS_RTU
  17. : settingsService.PROTOCOL_MODE.STORAGE_ACCESS
  18. const protocolOptions = settingsService.PROTOCOL_OPTIONS
  19. const protocolIndex = Math.max(0, protocolOptions.findIndex((option) => (
  20. option.key === protocolMode
  21. )))
  22. const protocol = protocolOptions[protocolIndex] || protocolOptions[0]
  23. const isModbusProtocol = settingsService.isModbusProtocol(protocol.key)
  24. const isStorageAccessProtocol = settingsService.isStorageAccessProtocol(protocol.key)
  25. return {
  26. ...settingsState,
  27. ...themeState,
  28. ...bootloaderState,
  29. connectedDevice: transportState.connectedDevice,
  30. isModbusProtocol,
  31. isStorageAccessProtocol,
  32. nightModeEnabledSwitch,
  33. statusPollMaxInterval: settingsService.STATUS_POLL_MAX_INTERVAL,
  34. statusPollMinInterval: settingsService.STATUS_POLL_MIN_INTERVAL,
  35. parameterMinPacketLength: settingsService.PARAMETER_MIN_PACKET_LENGTH,
  36. protocolIndex,
  37. protocolOptions,
  38. protocolText: protocol.label,
  39. toolEntries: toolNavigation.getToolEntries()
  40. }
  41. }
  42. module.exports = {
  43. getSettingsPageState
  44. }