1
0

view-model.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 {
  6. toolNavigation
  7. } = require('../tools/index.js')
  8. const protocolImplementation = require('./protocol-implementation.js')
  9. function getSettingsPageState(
  10. settingsState = settingsService.getState(),
  11. themeState = themeService.getState(),
  12. transportState = transport.getState(),
  13. bootloaderState = bootloaderService.getState()
  14. ) {
  15. const nightModeEnabledSwitch = settingsState.nightModeFollowSystem
  16. ? themeState.themeMode === 'dark'
  17. : settingsState.nightModeEnabled
  18. const protocolMode = settingsState.protocolMode || settingsService.PROTOCOL_MODE.STORAGE_ACCESS
  19. const protocolOptions = settingsService.PROTOCOL_OPTIONS
  20. const protocolIndex = Math.max(0, protocolOptions.findIndex((option) => (
  21. option.key === protocolMode
  22. )))
  23. const protocol = protocolOptions[protocolIndex] || protocolOptions[0]
  24. const isNoProtocol = settingsService.isNoProtocol(protocol.key)
  25. const isModbusProtocol = settingsService.isModbusProtocol(protocol.key)
  26. const isStorageAccessProtocol = settingsService.isStorageAccessProtocol(protocol.key)
  27. return {
  28. ...settingsState,
  29. ...themeState,
  30. ...bootloaderState,
  31. connectedDevice: transportState.connectedDevice,
  32. isNoProtocol,
  33. isModbusProtocol,
  34. isStorageAccessProtocol,
  35. nightModeEnabledSwitch,
  36. statusPollMaxInterval: settingsService.STATUS_POLL_MAX_INTERVAL,
  37. statusPollMinInterval: settingsService.STATUS_POLL_MIN_INTERVAL,
  38. parameterMinPacketLength: settingsService.PARAMETER_MIN_PACKET_LENGTH,
  39. protocolIndex,
  40. storageProtocolImplementationEntryMeta: '从机实现与结构体定义参考',
  41. storageProtocolImplementationView: protocolImplementation.VIEW_ID,
  42. protocolOptions,
  43. protocolText: protocol.label,
  44. toolEntries: toolNavigation.getToolEntries()
  45. }
  46. }
  47. module.exports = {
  48. getSettingsPageState
  49. }