StorageInfoScreen.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {FsUtils} from "../lib/FsUtils";
  2. import {t, extendLocale} from "../lib/i18n";
  3. extendLocale({
  4. "storage_total": {
  5. "en-US": "Total",
  6. "zh-CN": "总空间",
  7. "zh-TW": "手環容量",
  8. "ru-RU": "Всего",
  9. "de-DE": "Gesamt"
  10. },
  11. "storage_free": {
  12. "en-US": "Free",
  13. "zh-CN": "余空间",
  14. "zh-TW": "可用空間",
  15. "ru-RU": "Свободно",
  16. "de-DE": "Frei"
  17. },
  18. "storage_system": {
  19. "en-US": "ZeppOS",
  20. "zh-CN": "系统固件",
  21. "zh-TW": "系統韌體",
  22. "ru-RU": "ZeppOS",
  23. "de-DE": "ZeppOS"
  24. },
  25. "storage_watchface": {
  26. "en-US": "Watchfaces",
  27. "zh-CN": "JS表盘",
  28. "zh-TW": "JS錶盤",
  29. "ru-RU": "Циферблаты",
  30. "de-DE": "Ziffernblätter"
  31. },
  32. "storage_app": {
  33. "en-US": "Apps",
  34. "zh-CN": "JS应用",
  35. "zh-TW": "JS應用",
  36. "ru-RU": "Приложения",
  37. "de-DE": "Apps"
  38. },
  39. "storage_unknown": {
  40. "en-US": "Unknown",
  41. "zh-CN": "未知",
  42. "zh-TW": "未知",
  43. "ru-RU": "Неизвестно",
  44. "de-DE": "Unbekannt"
  45. },
  46. })
  47. class StorageInfoScreen {
  48. cupStyle = {
  49. x: 16,
  50. y: 72,
  51. w: 32,
  52. h: 320,
  53. color: 0x111111
  54. }
  55. start() {
  56. const storage = hmSetting.getDiskInfo();
  57. const config = [
  58. {
  59. key: "total",
  60. color: 0x999999,
  61. },
  62. {
  63. key: "free",
  64. color: 0xAAAAAA,
  65. },
  66. {
  67. key: "system",
  68. color: 0xFFCC80
  69. },
  70. {
  71. key: "watchface",
  72. color: 0x4fc3f7,
  73. },
  74. {
  75. key: "app",
  76. color: 0xFFAB91,
  77. },
  78. {
  79. key: "unknown",
  80. color: 0x616161,
  81. },
  82. ];
  83. // Calc unknown
  84. storage.unknown = storage.total;
  85. for(let i in config)
  86. if(config[i].key !== "total" && config[i].key !== "unknown")
  87. storage.unknown -= storage[config[i].key]
  88. let posY = 56, usedY = 0;
  89. hmUI.createWidget(hmUI.widget.FILL_RECT, this.cupStyle);
  90. for (let i in config) {
  91. const currentRow = config[i];
  92. if(storage[currentRow.key] == 0) continue;
  93. // Text
  94. hmUI.createWidget(hmUI.widget.TEXT, {
  95. x: 72,
  96. y: posY,
  97. w: 120,
  98. h: 24,
  99. color: currentRow.color,
  100. text: t("storage_" + currentRow.key),
  101. });
  102. hmUI.createWidget(hmUI.widget.TEXT, {
  103. x: 72,
  104. y: posY + 24,
  105. w: 120,
  106. h: 48,
  107. text_size: 24,
  108. color: 0xffffff,
  109. text: FsUtils.printBytes(storage[currentRow.key]),
  110. });
  111. posY += 64;
  112. // Visual
  113. if (currentRow.key != "free" && currentRow.key != "total") {
  114. let height = Math.round(
  115. this.cupStyle.h * (storage[currentRow.key] / storage.total)
  116. );
  117. if(height < 2) continue;
  118. hmUI.createWidget(hmUI.widget.FILL_RECT, {
  119. ...(this.cupStyle),
  120. y: this.cupStyle.y + this.cupStyle.h - usedY - height,
  121. h: height,
  122. color: currentRow.color,
  123. });
  124. usedY += height;
  125. }
  126. }
  127. }
  128. }
  129. let __$$app$$__ = __$$hmAppManager$$__.currentApp;
  130. let __$$module$$__ = __$$app$$__.current;
  131. __$$module$$__.module = DeviceRuntimeCore.Page({
  132. onInit(p) {
  133. new StorageInfoScreen().start();
  134. }
  135. });