AppEditScreen.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import {FsUtils} from "../lib/FsUtils";
  2. import {t, extendLocale} from "../lib/i18n";
  3. import {SettingsListScreen} from "../utils/SettingsListScreen";
  4. extendLocale({
  5. "action_uninstall": {
  6. "en-US": "Uninstall",
  7. "zh-CN": "卸载",
  8. "zh-TW": "卸載",
  9. "ru-RU": "Удалить",
  10. "de-DE": "Deinstallieren"
  11. },
  12. "uninstall_complete": {
  13. "en-US": "Uninstalled",
  14. "zh-CN": "已卸载",
  15. "zh-TW": "已卸載",
  16. "ru-RU": "Удалено",
  17. "de-DE": "Deinstalliert"
  18. },
  19. "apps_notice_uninstall": {
  20. "en-US": "Please reboot device to finish",
  21. "zh-CN": "请重启设备以完成",
  22. "zh-TW": "請重啟設備以完成",
  23. "ru-RU": "Перезагрузите устройство для завершения",
  24. "de-DE": "Bitte das Gerät neustarten um abzuschließen"
  25. },
  26. "field_size": {
  27. "en-US": "Size",
  28. "zh-CN": "应用程序大小",
  29. "zh-TW": "應用程序大小",
  30. "ru-RU": "Размер",
  31. "de-DE": "Größe"
  32. },
  33. "field_vendor": {
  34. "en-US": "Vendor",
  35. "zh-TW": "小販",
  36. "zh-CN": "小贩",
  37. "ru-RU": "Разработчик",
  38. "de-DE": "Hersteller"
  39. },
  40. "file_size_ext": {
  41. "en-US": "Size (ext. config)",
  42. "zh-CN": "大小(外部文件)",
  43. "zh-TW": "大小(外部文件)",
  44. "ru-RU": "Размер (внешн. файлы)",
  45. "de-DE": "Größe (ext. config)"
  46. },
  47. "conf_full": {
  48. "en-US": "Don't keep ext. files on uninstall",
  49. "zh-CN": "卸载时删除外部文件",
  50. "zh-TW": "卸載時刪除外部文件",
  51. "ru-RU": "Также удалять внешние файлы",
  52. "de-DE": "ext Dateien bei Deinstallation NICHT bebehalten"
  53. },
  54. "headline_adv": {
  55. "en-US": "Advanced",
  56. "zh-CN": "先进的",
  57. "zh-TW": "先進的",
  58. "ru-RU": "Дополнительно",
  59. "de-DE": "Erweitert"
  60. }
  61. })
  62. class AppEditScreen extends SettingsListScreen {
  63. dontKeepSettings = true;
  64. constructor(dirname) {
  65. super();
  66. this.dirname = dirname;
  67. this.path = "/storage/js_apps/" + dirname;
  68. this.appConfig = {};
  69. }
  70. build() {
  71. this.preloadAll();
  72. let size = FsUtils.sizeTree(this.path);
  73. this.image(this.iconPath, 100);
  74. this.h1(this.appConfig.app.appName);
  75. this.baseColor = 0xFF8888;
  76. this.clickableItem(t("action_uninstall"), "menu/delete.png", () => {
  77. this.uninstall();
  78. })
  79. this.baseColor = 0xFFFFFF;
  80. this.field(t("field_vendor"), this.appConfig.app.vender);
  81. this.field(t("field_size"), FsUtils.printBytes(size));
  82. if(this.appConfig.externalFilesList) {
  83. let configSize = 0;
  84. for(const path of this.appConfig.externalFilesList) {
  85. const [st, e] = FsUtils.stat(path);
  86. if(st !== null && st.size) configSize += st.size;
  87. }
  88. this.headline(t("headline_adv"));
  89. this.field(t("file_size_ext"), FsUtils.printBytes(configSize));
  90. this.checkbox(t("conf_full"), this, "dontKeepSettings");
  91. }
  92. this._prepareFinishGroup();
  93. }
  94. preloadAll() {
  95. try {
  96. this.appConfig = FsUtils.fetchJSON(this.path + '/app.json');
  97. let icon = this.path + "/assets/" + this.appConfig.app.icon;
  98. this.iconPath = this._prepareTempFile(icon);
  99. } catch (e) {
  100. console.log(e);
  101. }
  102. }
  103. _prepareFinishGroup() {
  104. const group = hmUI.createWidget(hmUI.widget.GROUP, {
  105. x: 0,
  106. y: 0,
  107. w: 192,
  108. h: 482
  109. });
  110. group.createWidget(hmUI.widget.FILL_RECT, {
  111. x: 0,
  112. y: 0,
  113. w: 192,
  114. h: 482,
  115. color: 0x0
  116. });
  117. group.createWidget(hmUI.widget.TEXT, {
  118. x: 0,
  119. y: 120,
  120. w: 192,
  121. h: 48,
  122. text_size: 26,
  123. text_style: hmUI.text_style.WRAP,
  124. align_h: hmUI.align.CENTER_H,
  125. color: 0x66BB6A,
  126. text: t("uninstall_complete")
  127. });
  128. group.createWidget(hmUI.widget.TEXT, {
  129. x: 0,
  130. y: 180,
  131. w: 192,
  132. h: 80,
  133. text_size: 20,
  134. text_style: hmUI.text_style.WRAP,
  135. align_h: hmUI.align.CENTER_H,
  136. color: 0xffffff,
  137. text: t("apps_notice_uninstall")
  138. });
  139. group.createWidget(hmUI.widget.IMG, {
  140. x: 0,
  141. y: 320,
  142. w: 192,
  143. h: 48,
  144. pos_x: (192-48)/2,
  145. pos_y: 0,
  146. src: "i_next.png"
  147. }).addEventListener(hmUI.event.CLICK_UP, () => {
  148. hmApp.startApp({
  149. url: "Settings_systemScreen",
  150. native: true
  151. });
  152. });
  153. group.setProperty(hmUI.prop.VISIBLE, false);
  154. this.finishGroup = group;
  155. }
  156. _prepareTempFile(sourcePath) {
  157. const current = hmFS.SysProGetChars("mmk_tb_temp");
  158. if(current) {
  159. const path = FsUtils.fullPath(current);
  160. hmFS.remove(path);
  161. }
  162. if(sourcePath === "") return "";
  163. const data = FsUtils.read(sourcePath);
  164. const newFile = "temp_" + Math.round(Math.random() * 100000) + ".png";
  165. const dest = hmFS.open_asset(newFile, hmFS.O_WRONLY | hmFS.O_CREAT);
  166. hmFS.seek(dest, 0, hmFS.SEEK_SET);
  167. hmFS.write(dest, data, 0, data.byteLength);
  168. hmFS.close(dest);
  169. hmFS.SysProSetChars("mmk_tb_temp", newFile);
  170. return newFile;
  171. }
  172. uninstall() {
  173. FsUtils.rmTree("/storage/js_apps/" + this.dirname);
  174. FsUtils.rmTree("/storage/js_apps/data" + this.dirname);
  175. if(this.appConfig.externalFilesList) {
  176. for(const path of this.appConfig.externalFilesList) {
  177. try {
  178. hmFS.remove(path);
  179. } catch(e) {
  180. console.log(e);
  181. }
  182. }
  183. }
  184. hmApp.setLayerY(0);
  185. hmUI.setLayerScrolling(false);
  186. this.finishGroup.setProperty(hmUI.prop.VISIBLE, true);
  187. }
  188. }
  189. let __$$app$$__ = __$$hmAppManager$$__.currentApp;
  190. let __$$module$$__ = __$$app$$__.current;
  191. __$$module$$__.module = DeviceRuntimeCore.Page({
  192. onInit(dirname) {
  193. this.screen = new AppEditScreen(dirname);
  194. this.screen.start();
  195. }
  196. });