main.py 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. import os
  2. import random
  3. import string
  4. import traceback
  5. import shutil
  6. import uuid
  7. from flask import Flask, request
  8. app = Flask(__name__)
  9. app.base_project = {
  10. "android": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCode",
  11. "android_flutter": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeFlutter-Android",
  12. "android_ionic": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeIonic-Android",
  13. "android_react": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeReact-Android",
  14. "ios": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCode-iOS",
  15. "ios_flutter": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeFlutter-iOS",
  16. "ios_ionic": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeIonic-iOS",
  17. "ios_react": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeReact-iOS"
  18. }
  19. app.temp_folder = "/Users/maronakins/Documents/EmbedFeatures/BuildExample"
  20. app.zip_folder = "/Users/maronakins/Documents/EmbedFeatures/uploads"
  21. # app.ssl = ('/usr/src/app/ssl/STAR_newuniverse_io.crt', '/usr/src/app/ssl/STAR_newuniverse.io.key')
  22. app.ssl = None
  23. app.verbose = True
  24. def vprint(*data):
  25. if app.verbose:
  26. print(*data)
  27. def indented_str(n, s, line=True, spaces=4) -> str:
  28. return " " * n * spaces + s + os.linesep if line else ""
  29. def create_folder(platform, uid):
  30. path = os.path.join(app.temp_folder, uid)
  31. if not os.path.exists(path):
  32. os.mkdir(path)
  33. else:
  34. shutil.rmtree(path)
  35. os.mkdir(path)
  36. vprint(path)
  37. base_project = app.base_project[platform]
  38. base_project_name = os.path.basename(base_project)
  39. path_dest = os.path.join(path, base_project_name)
  40. if not os.path.exists(path_dest):
  41. shutil.copytree(base_project, path_dest)
  42. return path_dest
  43. def change(platform: str, mode: str, path_dest: str, features: dict, security: dict):
  44. if platform == "android":
  45. main_act_path = os.path.join(path_dest,
  46. "app/src/main/java/com/example/nexilissamplecodeburger/MainActivity.java")
  47. xml_menu_path = os.path.join(path_dest, "app/src/main/res/menu/menu_main.xml")
  48. with open(main_act_path, "r") as f:
  49. lines = f.readlines()
  50. with open(main_act_path, "w") as f:
  51. for line in lines:
  52. if "//FEATURES" in line:
  53. f.write(indented_str(2, "if (id == R.id.action_settings) {"))
  54. f.write(indented_str(3, "API.openSettings();"))
  55. f.write(indented_str(3, "return true;"))
  56. f.write(indented_str(2, "}"))
  57. f.write(indented_str(2, "if (id == R.id.action_profile) {"))
  58. f.write(indented_str(3, "API.openProfile();"))
  59. f.write(indented_str(3, "return true;"))
  60. f.write(indented_str(2, "}"))
  61. if features["cc"]["status"]:
  62. f.write(indented_str(2, "if (id == R.id.action_cc) {"))
  63. f.write(indented_str(3, "API.openContactCenter();"))
  64. f.write(indented_str(3, "return true;"))
  65. f.write(indented_str(2, "}"))
  66. else:
  67. f.write(indented_str(2, "// if (id == R.id.action_cc) {"))
  68. f.write(indented_str(3, "// API.openContactCenter();"))
  69. f.write(indented_str(3, "// return true;"))
  70. f.write(indented_str(2, "// }"))
  71. if features["nc"]["status"]:
  72. f.write(indented_str(2, "if (id == R.id.action_nc) {"))
  73. f.write(indented_str(3, "API.openNotificationCenter();"))
  74. f.write(indented_str(3, "return true;"))
  75. f.write(indented_str(2, "}"))
  76. else:
  77. f.write(indented_str(2, "// if (id == R.id.action_nc) {"))
  78. f.write(indented_str(3, "// API.openNotificationCenter();"))
  79. f.write(indented_str(3, "// return true;"))
  80. f.write(indented_str(2, "// }"))
  81. if features["im"]["status"]:
  82. f.write(indented_str(2, "if (id == R.id.action_chats) {"))
  83. f.write(indented_str(3, "API.openChat();"))
  84. f.write(indented_str(3, "return true;"))
  85. f.write(indented_str(2, "}"))
  86. else:
  87. f.write(indented_str(2, "// if (id == R.id.action_chats) {"))
  88. f.write(indented_str(3, "// API.openChat();"))
  89. f.write(indented_str(3, "// return true;"))
  90. f.write(indented_str(2, "// }"))
  91. if features["call"]["status"]:
  92. f.write(indented_str(2, "if (id == R.id.action_call) {"))
  93. f.write(indented_str(3, "API.openCall();"))
  94. f.write(indented_str(3, "return true;"))
  95. f.write(indented_str(2, "}"))
  96. else:
  97. f.write(indented_str(2, "// if (id == R.id.action_call) {"))
  98. f.write(indented_str(3, "// API.openCall();"))
  99. f.write(indented_str(3, "// return true;"))
  100. f.write(indented_str(2, "// }"))
  101. if features["ls"]["status"]:
  102. f.write(indented_str(2, "if (id == R.id.action_ls) {"))
  103. f.write(indented_str(3, "API.openOptionsStreaming();"))
  104. f.write(indented_str(3, "return true;"))
  105. f.write(indented_str(2, "}"))
  106. else:
  107. f.write(indented_str(2, "// if (id == R.id.action_ls) {"))
  108. f.write(indented_str(3, "// API.openOptionsStreaming();"))
  109. f.write(indented_str(3, "// return true;"))
  110. f.write(indented_str(2, "// }"))
  111. elif "//SECURITY" in line:
  112. if security["show_security"]:
  113. f.write(indented_str(2, "API.setShowSecurityShieldDialog(true);"))
  114. f.write(os.linesep)
  115. else:
  116. f.write(indented_str(2, "// API.setShowSecurityShieldDialog(true);"))
  117. f.write(os.linesep)
  118. if security["emulator"]:
  119. f.write(indented_str(2, "API.setCheckEmulator(true);"))
  120. f.write(os.linesep)
  121. else:
  122. f.write(indented_str(2, "// API.setCheckEmulator(true);"))
  123. f.write(os.linesep)
  124. if security["debug"]:
  125. f.write(indented_str(2, "API.setCheckAdb(true);"))
  126. f.write(os.linesep)
  127. if security["sim_swap"]:
  128. f.write(indented_str(2,
  129. "API.setCheckSimCardSwapListener(MainActivity.this, new SimCardDetectionCallback() {"))
  130. f.write(os.linesep)
  131. f.write(indented_str(3, "@Override"))
  132. f.write(indented_str(3, "public boolean onSimCardChange() {"))
  133. f.write(indented_str(4, "return false;"))
  134. f.write(indented_str(3, "}"))
  135. f.write(os.linesep)
  136. f.write(indented_str(3, "@Override"))
  137. f.write(indented_str(3, "public void onError(String s) {"))
  138. f.write(os.linesep)
  139. f.write(indented_str(3, "}"))
  140. f.write(indented_str(2, "});"))
  141. f.write(os.linesep)
  142. else:
  143. f.write(indented_str(2,
  144. "/* API.setCheckSimCardSwapListener(MainActivity.this, new SimCardDetectionCallback() {"))
  145. f.write(os.linesep)
  146. f.write(indented_str(3, "@Override"))
  147. f.write(indented_str(3, "public boolean onSimCardChange() {"))
  148. f.write(indented_str(4, "return false;"))
  149. f.write(indented_str(3, "}"))
  150. f.write(os.linesep)
  151. f.write(indented_str(3, "@Override"))
  152. f.write(indented_str(3, "public void onError(String s) {"))
  153. f.write(os.linesep)
  154. f.write(indented_str(3, "}"))
  155. f.write(indented_str(2, "}); */"))
  156. f.write(os.linesep)
  157. if security["malware"]:
  158. f.write(indented_str(2, "API.setCheckMalware(true);"))
  159. f.write(os.linesep)
  160. else:
  161. f.write(indented_str(2, "// API.setCheckMalware(true);"))
  162. f.write(os.linesep)
  163. if security["capture"]:
  164. f.write(indented_str(2, "API.setPreventScreenCapture(true);"))
  165. f.write(os.linesep)
  166. else:
  167. f.write(indented_str(2, "// API.setPreventScreenCapture(true);"))
  168. f.write(os.linesep)
  169. if security["call_forwarding"]:
  170. f.write(indented_str(2, "API.setCheckCallForwarding(true);"))
  171. f.write(os.linesep)
  172. else:
  173. f.write(indented_str(2, "// API.setCheckCallForwarding(true);"))
  174. f.write(os.linesep)
  175. if security["secure_folder"]:
  176. f.write(indented_str(2, "API.openSecureFolder();"))
  177. f.write(os.linesep)
  178. else:
  179. f.write(indented_str(2, "// API.openSecureFolder();"))
  180. f.write(os.linesep)
  181. elif "//SMS" in line:
  182. if features["sms"]["status"]:
  183. f.write(indented_str(2, "API.setEnabledSMS(true);"))
  184. else:
  185. f.write(indented_str(2, "// API.setEnabledSMS(true);"))
  186. elif "//EMAIL" in line:
  187. if features["email"]["status"]:
  188. f.write(indented_str(2, "API.setEnabledEmail(true);"))
  189. else:
  190. f.write(indented_str(2, "// API.setEnabledEmail(true);"))
  191. elif "//BREAK" in line:
  192. if mode == "floating":
  193. f.write("}")
  194. break
  195. else:
  196. f.write(indented_str(0,""))
  197. elif "//FLOATING" in line:
  198. if mode == "floating":
  199. f.write(indented_str(6, "ArrayList<FloatingButton> fb = new ArrayList<>();"))
  200. if features["cc"]["status"]:
  201. f.write(indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.CONTACT_CENTER, ""));'))
  202. else:
  203. f.write(indented_str(6,
  204. '// fb.add(new FloatingButton(FloatingButton.FEATURE.CONTACT_CENTER, ""));'))
  205. if features["nc"]["status"]:
  206. f.write(indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.NOTIF_CENTER, ""));'))
  207. else:
  208. f.write(indented_str(6,
  209. '// fb.add(new FloatingButton(FloatingButton.FEATURE.NOTIF_CENTER, ""));'))
  210. if features["im"]["status"]:
  211. f.write(
  212. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.MESSAGING, ""));'))
  213. else:
  214. f.write(indented_str(6,
  215. '// fb.add(new FloatingButton(FloatingButton.FEATURE.MESSAGING, ""));'))
  216. if features["call"]["status"]:
  217. f.write(
  218. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.AUDIO_VIDEO_CALL, ""));'))
  219. else:
  220. f.write(indented_str(6,
  221. '// fb.add(new FloatingButton(FloatingButton.FEATURE.AUDIO_VIDEO_CALL, ""));'))
  222. if features["ls"]["status"]:
  223. f.write(
  224. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.STREAMING, ""));'))
  225. else:
  226. f.write(indented_str(6,
  227. '// fb.add(new FloatingButton(FloatingButton.FEATURE.STREAMING, ""));'))
  228. f.write(indented_str(6,
  229. 'API.configureFloating(fb);'))
  230. else:
  231. f.write(indented_str(0, ""))
  232. elif "API.connect" in line:
  233. if mode == "floating":
  234. replaced = line.replace("0", "1")
  235. f.write(replaced)
  236. else:
  237. f.write(line)
  238. else:
  239. f.write(line)
  240. with open(xml_menu_path, "r") as f:
  241. lines = f.readlines()
  242. with open(xml_menu_path, "w") as f:
  243. for line in lines:
  244. if "<!-- FEATURES -->" in line:
  245. n = 100
  246. f.write(indented_str(1, "<item"))
  247. f.write(indented_str(2, 'android:id="@+id/action_settings"'))
  248. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  249. f.write(indented_str(2, 'android:title="Settings"'))
  250. f.write(indented_str(2, 'app:showAsAction="never" />'))
  251. n = n + 1
  252. f.write(indented_str(1, "<item"))
  253. f.write(indented_str(2, 'android:id="@+id/action_profile"'))
  254. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  255. f.write(indented_str(2, 'android:title="Profile"'))
  256. f.write(indented_str(2, 'app:showAsAction="never" />'))
  257. n = n + 1
  258. if features["cc"]["status"]:
  259. f.write(indented_str(1, "<item"))
  260. f.write(indented_str(2, 'android:id="@+id/action_cc"'))
  261. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  262. f.write(indented_str(2, 'android:title="Contact Center"'))
  263. f.write(indented_str(2, 'app:showAsAction="never" />'))
  264. n = n + 1
  265. else:
  266. f.write(indented_str(1, "<!-- <item"))
  267. f.write(indented_str(2, 'android:id="@+id/action_cc"'))
  268. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  269. f.write(indented_str(2, 'android:title="Contact Center"'))
  270. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  271. n = n + 1
  272. if features["nc"]["status"]:
  273. f.write(indented_str(1, "<item"))
  274. f.write(indented_str(2, 'android:id="@+id/action_nc"'))
  275. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  276. f.write(indented_str(2, 'android:title="Notification Center"'))
  277. f.write(indented_str(2, 'app:showAsAction="never" />'))
  278. n = n + 1
  279. else:
  280. f.write(indented_str(1, "<!-- <item"))
  281. f.write(indented_str(2, 'android:id="@+id/action_nc"'))
  282. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  283. f.write(indented_str(2, 'android:title="Notification Center"'))
  284. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  285. n = n + 1
  286. if features["im"]["status"]:
  287. f.write(indented_str(1, "<item"))
  288. f.write(indented_str(2, 'android:id="@+id/action_chats"'))
  289. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  290. f.write(indented_str(2, 'android:title="Instant Messaging"'))
  291. f.write(indented_str(2, 'app:showAsAction="never" />'))
  292. n = n + 1
  293. else:
  294. f.write(indented_str(1, "<!-- <item"))
  295. f.write(indented_str(2, 'android:id="@+id/action_chats"'))
  296. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  297. f.write(indented_str(2, 'android:title="Instant Messaging"'))
  298. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  299. n = n + 1
  300. if features["call"]["status"]:
  301. f.write(indented_str(1, "<item"))
  302. f.write(indented_str(2, 'android:id="@+id/action_call"'))
  303. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  304. f.write(indented_str(2, 'android:title="Call"'))
  305. f.write(indented_str(2, 'app:showAsAction="never" />'))
  306. n = n + 1
  307. else:
  308. f.write(indented_str(1, "<!-- <item"))
  309. f.write(indented_str(2, 'android:id="@+id/action_call"'))
  310. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  311. f.write(indented_str(2, 'android:title="Call"'))
  312. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  313. n = n + 1
  314. if features["ls"]["status"]:
  315. f.write(indented_str(1, "<item"))
  316. f.write(indented_str(2, 'android:id="@+id/action_ls"'))
  317. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  318. f.write(indented_str(2, 'android:title="Streaming"'))
  319. f.write(indented_str(2, 'app:showAsAction="never" />'))
  320. n = n + 1
  321. else:
  322. f.write(indented_str(1, "<!-- <item"))
  323. f.write(indented_str(2, 'android:id="@+id/action_ls"'))
  324. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  325. f.write(indented_str(2, 'android:title="Streaming"'))
  326. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  327. n = n + 1
  328. else:
  329. f.write(line)
  330. elif platform == "android_flutter":
  331. main_act_path = os.path.join(path_dest, "lib/main.dart")
  332. with open(main_act_path, "r") as f:
  333. lines = f.readlines()
  334. with open(main_act_path, "w") as f:
  335. features_str = []
  336. for line in lines:
  337. if "'Features List'" in line:
  338. features_str.append("Settings")
  339. features_str.append("Profile")
  340. if features["cc"]["status"]:
  341. features_str.append("'Contact Center'")
  342. else:
  343. features_str.append("// 'Contact Center'")
  344. if features["nc"]["status"]:
  345. features_str.append("'Notification Center'")
  346. else:
  347. features_str.append("// 'Notification Center'")
  348. if features["im"]["status"]:
  349. features_str.append("'Instant Messaging'")
  350. else:
  351. features_str.append("// 'Instant Messaging'")
  352. if features["call"]["status"]:
  353. features_str.append("'Call'")
  354. else:
  355. features_str.append("// 'Call'")
  356. if features["ls"]["status"]:
  357. features_str.append("'Streaming'")
  358. else:
  359. features_str.append("// 'Streaming'")
  360. for feature_str in features_str:
  361. f.write(indented_str(8, f"{feature_str},", spaces=2))
  362. elif "//FEATURES" in line:
  363. f.write(indented_str(3, 'case "Settings":', spaces=2))
  364. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  365. f.write(indented_str(4, "break;", spaces=2))
  366. f.write(indented_str(3, 'case "Profile":', spaces=2))
  367. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  368. f.write(indented_str(4, "break;", spaces=2))
  369. if features["cc"]["status"]:
  370. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  371. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  372. f.write(indented_str(4, "break;", spaces=2))
  373. else:
  374. f.write(indented_str(3, '// case "Contact Center":', spaces=2))
  375. f.write(indented_str(4, '// nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  376. f.write(indented_str(4, "// break;", spaces=2))
  377. if features["nc"]["status"]:
  378. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  379. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  380. f.write(indented_str(4, "break;", spaces=2))
  381. else:
  382. f.write(indented_str(3, '// case "Notification Center":', spaces=2))
  383. f.write(indented_str(4, '// nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  384. f.write(indented_str(4, "// break;", spaces=2))
  385. if features["im"]["status"]:
  386. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  387. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  388. f.write(indented_str(4, "break;", spaces=2))
  389. else:
  390. f.write(indented_str(3, '// case "Instant Messaging":', spaces=2))
  391. f.write(indented_str(4, '// nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  392. f.write(indented_str(4, "// break;", spaces=2))
  393. if features["call"]["status"]:
  394. f.write(indented_str(3, 'case "Call":', spaces=2))
  395. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  396. f.write(indented_str(4, "break;", spaces=2))
  397. else:
  398. f.write(indented_str(3, '// case "Call":', spaces=2))
  399. f.write(indented_str(4, '// nativeChannel.invokeMethod("openCall");', spaces=2))
  400. f.write(indented_str(4, "// break;", spaces=2))
  401. if features["ls"]["status"]:
  402. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  403. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  404. f.write(indented_str(4, "break;", spaces=2))
  405. else:
  406. f.write(indented_str(3, '// case "Streaming":', spaces=2))
  407. f.write(indented_str(4, '// nativeChannel.invokeMethod("openStreaming");', spaces=2))
  408. f.write(indented_str(4, "// break;", spaces=2))
  409. else:
  410. f.write(line)
  411. elif platform == "android_ionic":
  412. main_act_path = os.path.join(path_dest,"src/app/app.component.ts")
  413. with open(main_act_path, "r") as f:
  414. lines = f.readlines()
  415. with open(main_act_path, "w") as f:
  416. for line in lines:
  417. if "//FEATURES" in line:
  418. f.write(indented_str(4, '{', spaces=2))
  419. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  420. f.write(indented_str(5, "handler: () => {", spaces=2))
  421. f.write(indented_str(6, "this.openSettings();", spaces=2))
  422. f.write(indented_str(5, "},", spaces=2))
  423. f.write(indented_str(4, "},", spaces=2))
  424. f.write(indented_str(4, '{', spaces=2))
  425. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  426. f.write(indented_str(5, "handler: () => {", spaces=2))
  427. f.write(indented_str(6, "this.openProfile();", spaces=2))
  428. f.write(indented_str(5, "},", spaces=2))
  429. f.write(indented_str(4, "},", spaces=2))
  430. if features["cc"]["status"]:
  431. f.write(indented_str(4, '{', spaces=2))
  432. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  433. f.write(indented_str(5, "handler: () => {", spaces=2))
  434. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  435. f.write(indented_str(5, "},", spaces=2))
  436. f.write(indented_str(4, "},", spaces=2))
  437. else:
  438. f.write(indented_str(4, '// {', spaces=2))
  439. f.write(indented_str(5, "// text: 'Contact Center',", spaces=2))
  440. f.write(indented_str(5, "// handler: () => {", spaces=2))
  441. f.write(indented_str(6, "// this.openContactCenter();", spaces=2))
  442. f.write(indented_str(5, "// },", spaces=2))
  443. f.write(indented_str(4, "// },", spaces=2))
  444. if features["nc"]["status"]:
  445. f.write(indented_str(4, '{', spaces=2))
  446. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  447. f.write(indented_str(5, "handler: () => {", spaces=2))
  448. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  449. f.write(indented_str(5, "},", spaces=2))
  450. f.write(indented_str(4, "},", spaces=2))
  451. else:
  452. f.write(indented_str(4, '// {', spaces=2))
  453. f.write(indented_str(5, "// text: 'Notification Center',", spaces=2))
  454. f.write(indented_str(5, "// handler: () => {", spaces=2))
  455. f.write(indented_str(6, "// this.openNotificationCenter();", spaces=2))
  456. f.write(indented_str(5, "// },", spaces=2))
  457. f.write(indented_str(4, "// },", spaces=2))
  458. if features["im"]["status"]:
  459. f.write(indented_str(4, '{', spaces=2))
  460. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  461. f.write(indented_str(5, "handler: () => {", spaces=2))
  462. f.write(indented_str(6, "this.openChat();", spaces=2))
  463. f.write(indented_str(5, "},", spaces=2))
  464. f.write(indented_str(4, "},", spaces=2))
  465. else:
  466. f.write(indented_str(4, '// {', spaces=2))
  467. f.write(indented_str(5, "// text: 'Instant Messaging',", spaces=2))
  468. f.write(indented_str(5, "// handler: () => {", spaces=2))
  469. f.write(indented_str(6, "// this.openChat();", spaces=2))
  470. f.write(indented_str(5, "// },", spaces=2))
  471. f.write(indented_str(4, "// },", spaces=2))
  472. if features["call"]["status"]:
  473. f.write(indented_str(4, '{', spaces=2))
  474. f.write(indented_str(5, "text: 'Call',", spaces=2))
  475. f.write(indented_str(5, "handler: () => {", spaces=2))
  476. f.write(indented_str(6, "this.openCall();", spaces=2))
  477. f.write(indented_str(5, "},", spaces=2))
  478. f.write(indented_str(4, "},", spaces=2))
  479. else:
  480. f.write(indented_str(4, '// {', spaces=2))
  481. f.write(indented_str(5, "// text: 'Call',", spaces=2))
  482. f.write(indented_str(5, "// handler: () => {", spaces=2))
  483. f.write(indented_str(6, "// this.openCall();", spaces=2))
  484. f.write(indented_str(5, "// },", spaces=2))
  485. f.write(indented_str(4, "// },", spaces=2))
  486. if features["ls"]["status"]:
  487. f.write(indented_str(4, '{', spaces=2))
  488. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  489. f.write(indented_str(5, "handler: () => {", spaces=2))
  490. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  491. f.write(indented_str(5, "},", spaces=2))
  492. f.write(indented_str(4, "},", spaces=2))
  493. else:
  494. f.write(indented_str(4, '// {', spaces=2))
  495. f.write(indented_str(5, "// text: 'Streaming',", spaces=2))
  496. f.write(indented_str(5, "// handler: () => {", spaces=2))
  497. f.write(indented_str(6, "// this.openStreaming();", spaces=2))
  498. f.write(indented_str(5, "// },", spaces=2))
  499. f.write(indented_str(4, "// },", spaces=2))
  500. else:
  501. f.write(line)
  502. elif platform == "android_react":
  503. main_act_path = os.path.join(path_dest, "App.tsx")
  504. with open(main_act_path, "r") as f:
  505. lines = f.readlines()
  506. with open(main_act_path, "w") as f:
  507. for line in lines:
  508. if "'Features'" in line:
  509. f.write(indented_str(4, "'Setting',", spaces=2))
  510. f.write(indented_str(4, "'Profile',", spaces=2))
  511. if features["cc"]["status"]:
  512. f.write(indented_str(4, "'Contact Center',", spaces=2))
  513. else:
  514. f.write(indented_str(4, "// 'Contact Center',", spaces=2))
  515. if features["nc"]["status"]:
  516. f.write(indented_str(4, "'Notification Center',", spaces=2))
  517. else:
  518. f.write(indented_str(4, "// 'Notification Center',", spaces=2))
  519. if features["im"]["status"]:
  520. f.write(indented_str(4, "'Chat',", spaces=2))
  521. else:
  522. f.write(indented_str(4, "// 'Chat',", spaces=2))
  523. if features["call"]["status"]:
  524. f.write(indented_str(4, "'Call',", spaces=2))
  525. else:
  526. f.write(indented_str(4, "// 'Call',", spaces=2))
  527. if features["ls"]["status"]:
  528. f.write(indented_str(4, "'Live Streaming',", spaces=2))
  529. else:
  530. f.write(indented_str(4, "// 'Live Streaming',", spaces=2))
  531. elif "//FEATURES1" in line:
  532. n = 0
  533. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  534. f.write(indented_str(6, "CallNative.openSetting();", spaces=2))
  535. f.write(indented_str(5, "}", spaces=2))
  536. n = n + 1
  537. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  538. f.write(indented_str(6, "CallNative.openProfile();", spaces=2))
  539. f.write(indented_str(5, "}", spaces=2))
  540. n = n + 1
  541. if features["cc"]["status"]:
  542. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  543. f.write(indented_str(6, "CallNative.openContactCenter();", spaces=2))
  544. f.write(indented_str(5, "}", spaces=2))
  545. n = n + 1
  546. else:
  547. f.write(indented_str(5, "// if (buttonIndex === 2) {", spaces=2))
  548. f.write(indented_str(6, "// CallNative.openContactCenter();", spaces=2))
  549. f.write(indented_str(5, "// }", spaces=2))
  550. if features["nc"]["status"]:
  551. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  552. f.write(indented_str(6, "CallNative.openNotificationCenter();", spaces=2))
  553. f.write(indented_str(5, "}", spaces=2))
  554. n = n + 1
  555. else:
  556. f.write(indented_str(5, "// if (buttonIndex === 3) {", spaces=2))
  557. f.write(indented_str(6, "// CallNative.openNotificationCenter();", spaces=2))
  558. f.write(indented_str(5, "// }", spaces=2))
  559. if features["im"]["status"]:
  560. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  561. f.write(indented_str(6, "CallNative.openChat();", spaces=2))
  562. f.write(indented_str(5, "}", spaces=2))
  563. n = n + 1
  564. else:
  565. f.write(indented_str(5, "// if (buttonIndex === 4) {", spaces=2))
  566. f.write(indented_str(6, "// CallNative.openChat();", spaces=2))
  567. f.write(indented_str(5, "// }", spaces=2))
  568. if features["call"]["status"]:
  569. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  570. f.write(indented_str(6, "CallNative.openCall();", spaces=2))
  571. f.write(indented_str(5, "}", spaces=2))
  572. n = n + 1
  573. else:
  574. f.write(indented_str(5, "// if (buttonIndex === 5) {", spaces=2))
  575. f.write(indented_str(6, "// CallNative.openCall();", spaces=2))
  576. f.write(indented_str(5, "// }", spaces=2))
  577. if features["ls"]["status"]:
  578. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  579. f.write(indented_str(6, "CallNative.openStreaming();", spaces=2))
  580. f.write(indented_str(5, "}", spaces=2))
  581. n = n + 1
  582. else:
  583. f.write(indented_str(5, "// if (buttonIndex === 6) {", spaces=2))
  584. f.write(indented_str(6, "// CallNative.openStreaming();", spaces=2))
  585. f.write(indented_str(5, "// }", spaces=2))
  586. elif "//FEATURES2" in line:
  587. n = 0
  588. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  589. f.write(indented_str(3, "try {", spaces=2))
  590. f.write(indented_str(4, "CallNative.openSetting();", spaces=2))
  591. f.write(indented_str(3, "} catch (e) {", spaces=2))
  592. f.write(indented_str(4, "console.log(e);", spaces=2))
  593. f.write(indented_str(3, "}", spaces=2))
  594. f.write(indented_str(2, "}", spaces=2))
  595. n = n + 1
  596. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  597. f.write(indented_str(3, "try {", spaces=2))
  598. f.write(indented_str(4, "CallNative.openProfile();", spaces=2))
  599. f.write(indented_str(3, "} catch (e) {", spaces=2))
  600. f.write(indented_str(4, "console.log(e);", spaces=2))
  601. f.write(indented_str(3, "}", spaces=2))
  602. f.write(indented_str(2, "}", spaces=2))
  603. n = n + 1
  604. if features["cc"]["status"]:
  605. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  606. f.write(indented_str(3, "try {", spaces=2))
  607. f.write(indented_str(4, "CallNative.openContactCenter();", spaces=2))
  608. f.write(indented_str(3, "} catch (e) {", spaces=2))
  609. f.write(indented_str(4, "console.log(e);", spaces=2))
  610. f.write(indented_str(3, "}", spaces=2))
  611. f.write(indented_str(2, "}", spaces=2))
  612. n = n + 1
  613. else:
  614. f.write(indented_str(2, "// if (buttonIndex === 2) {", spaces=2))
  615. f.write(indented_str(3, "// try {", spaces=2))
  616. f.write(indented_str(4, "// CallNative.openContactCenter();", spaces=2))
  617. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  618. f.write(indented_str(4, "// console.log(e);", spaces=2))
  619. f.write(indented_str(3, "// }", spaces=2))
  620. f.write(indented_str(2, "// }", spaces=2))
  621. if features["nc"]["status"]:
  622. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  623. f.write(indented_str(3, "try {", spaces=2))
  624. f.write(indented_str(4, "CallNative.openNotificationCenter();", spaces=2))
  625. f.write(indented_str(3, "} catch (e) {", spaces=2))
  626. f.write(indented_str(4, "console.log(e);", spaces=2))
  627. f.write(indented_str(3, "}", spaces=2))
  628. f.write(indented_str(2, "}", spaces=2))
  629. n = n + 1
  630. else:
  631. f.write(indented_str(2, "// if (buttonIndex === 3) {", spaces=2))
  632. f.write(indented_str(3, "// try {", spaces=2))
  633. f.write(indented_str(4, "// CallNative.openNotificationCenter();", spaces=2))
  634. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  635. f.write(indented_str(4, "// console.log(e);", spaces=2))
  636. f.write(indented_str(3, "// }", spaces=2))
  637. f.write(indented_str(2, "// }", spaces=2))
  638. if features["im"]["status"]:
  639. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  640. f.write(indented_str(3, "try {", spaces=2))
  641. f.write(indented_str(4, "CallNative.openChat();", spaces=2))
  642. f.write(indented_str(3, "} catch (e) {", spaces=2))
  643. f.write(indented_str(4, "console.log(e);", spaces=2))
  644. f.write(indented_str(3, "}", spaces=2))
  645. f.write(indented_str(2, "}", spaces=2))
  646. n = n + 1
  647. else:
  648. f.write(indented_str(2, "// if (buttonIndex === 4) {", spaces=2))
  649. f.write(indented_str(3, "// try {", spaces=2))
  650. f.write(indented_str(4, "// CallNative.openChat();", spaces=2))
  651. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  652. f.write(indented_str(4, "// console.log(e);", spaces=2))
  653. f.write(indented_str(3, "// }", spaces=2))
  654. f.write(indented_str(2, "// }", spaces=2))
  655. if features["call"]["status"]:
  656. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  657. f.write(indented_str(3, "try {", spaces=2))
  658. f.write(indented_str(4, "CallNative.openCall();", spaces=2))
  659. f.write(indented_str(3, "} catch (e) {", spaces=2))
  660. f.write(indented_str(4, "console.log(e);", spaces=2))
  661. f.write(indented_str(3, "}", spaces=2))
  662. f.write(indented_str(2, "}", spaces=2))
  663. n = n + 1
  664. else:
  665. f.write(indented_str(2, "// if (buttonIndex === 5) {", spaces=2))
  666. f.write(indented_str(3, "// try {", spaces=2))
  667. f.write(indented_str(4, "// CallNative.openCall();", spaces=2))
  668. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  669. f.write(indented_str(4, "// console.log(e);", spaces=2))
  670. f.write(indented_str(3, "// }", spaces=2))
  671. f.write(indented_str(2, "// }", spaces=2))
  672. if features["ls"]["status"]:
  673. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  674. f.write(indented_str(3, "try {", spaces=2))
  675. f.write(indented_str(4, "CallNative.openStreaming();", spaces=2))
  676. f.write(indented_str(3, "} catch (e) {", spaces=2))
  677. f.write(indented_str(4, "console.log(e);", spaces=2))
  678. f.write(indented_str(3, "}", spaces=2))
  679. f.write(indented_str(2, "}", spaces=2))
  680. n = n + 1
  681. else:
  682. f.write(indented_str(2, "// if (buttonIndex === {n}) {", spaces=2))
  683. f.write(indented_str(3, "// try {", spaces=2))
  684. f.write(indented_str(4, "// CallNative.openStreaming();", spaces=2))
  685. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  686. f.write(indented_str(4, "// console.log(e);", spaces=2))
  687. f.write(indented_str(3, "// }", spaces=2))
  688. f.write(indented_str(2, "// }", spaces=2))
  689. elif "//FEATURES3" in line:
  690. n = 0
  691. f.write(indented_str(5, "<Button", spaces=2))
  692. f.write(indented_str(6, 'title="Setting"', spaces=2))
  693. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  694. f.write(indented_str(5, "/>", spaces=2))
  695. n = n + 1
  696. f.write(indented_str(5, "<Button", spaces=2))
  697. f.write(indented_str(6, 'title="Profile"', spaces=2))
  698. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  699. f.write(indented_str(5, "/>", spaces=2))
  700. n = n + 1
  701. if features["cc"]["status"]:
  702. f.write(indented_str(5, "<Button", spaces=2))
  703. f.write(indented_str(6, 'title="Contact Center"', spaces=2))
  704. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  705. f.write(indented_str(5, "/>", spaces=2))
  706. n = n + 1
  707. else:
  708. f.write(indented_str(5, "{/* <Button", spaces=2))
  709. f.write(indented_str(6, 'title="Contact Center"', spaces=2))
  710. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(2)}}', spaces=2))
  711. f.write(indented_str(5, "/> */}", spaces=2))
  712. if features["nc"]["status"]:
  713. f.write(indented_str(5, "<Button", spaces=2))
  714. f.write(indented_str(6, 'title="Notification Center"', spaces=2))
  715. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  716. f.write(indented_str(5, "/>", spaces=2))
  717. n = n + 1
  718. else:
  719. f.write(indented_str(5, "{/* <Button", spaces=2))
  720. f.write(indented_str(6, 'title="Notification Center"', spaces=2))
  721. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(3)}}', spaces=2))
  722. f.write(indented_str(5, "/> */}", spaces=2))
  723. if features["im"]["status"]:
  724. f.write(indented_str(5, "<Button", spaces=2))
  725. f.write(indented_str(6, 'title="Chat"', spaces=2))
  726. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  727. f.write(indented_str(5, "/>", spaces=2))
  728. n = n + 1
  729. else:
  730. f.write(indented_str(5, "{/* <Button", spaces=2))
  731. f.write(indented_str(6, 'title="Chat"', spaces=2))
  732. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(4)}}', spaces=2))
  733. f.write(indented_str(5, "/> */}", spaces=2))
  734. if features["call"]["status"]:
  735. f.write(indented_str(5, "<Button", spaces=2))
  736. f.write(indented_str(6, 'title="Call"', spaces=2))
  737. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  738. f.write(indented_str(5, "/>", spaces=2))
  739. n = n + 1
  740. else:
  741. f.write(indented_str(5, "{/* <Button", spaces=2))
  742. f.write(indented_str(6, 'title="Call"', spaces=2))
  743. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(5)}}', spaces=2))
  744. f.write(indented_str(5, "/> */}", spaces=2))
  745. if features["ls"]["status"]:
  746. f.write(indented_str(5, "<Button", spaces=2))
  747. f.write(indented_str(6, 'title="Live Streaming"', spaces=2))
  748. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  749. f.write(indented_str(5, "/>", spaces=2))
  750. n = n + 1
  751. else:
  752. f.write(indented_str(5, "{/* <Button", spaces=2))
  753. f.write(indented_str(6, 'title="Live Streaming"', spaces=2))
  754. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(5)}}', spaces=2))
  755. f.write(indented_str(5, "/> */}", spaces=2))
  756. else:
  757. f.write(line)
  758. elif platform == "ios":
  759. main_act_path = os.path.join(path_dest, "ExampleCode/ViewController.swift")
  760. with open(main_act_path, "r") as f:
  761. lines = f.readlines()
  762. with open(main_act_path, "w") as f:
  763. for line in lines:
  764. if "//FEATURES" in line:
  765. f.write(indented_str(3, 'UIAction(title: "Setting".localized(), handler: {(_) in'))
  766. f.write(indented_str(4, "APIS.openSetting();"))
  767. f.write(indented_str(3, "}),"))
  768. f.write(indented_str(3, 'UIAction(title: "Profile".localized(), handler: {(_) in'))
  769. f.write(indented_str(4, "APIS.openProfile();"))
  770. f.write(indented_str(3, "}),"))
  771. if features["cc"]["status"]:
  772. f.write(indented_str(3, 'UIAction(title: "Contact Center".localized(), handler: {(_) in'))
  773. f.write(indented_str(4, "APIS.openContactCenter();"))
  774. f.write(indented_str(3, "}),"))
  775. else:
  776. f.write(indented_str(3, '// UIAction(title: "Contact Center".localized(), handler: {(_) in'))
  777. f.write(indented_str(4, "// APIS.openContactCenter();"))
  778. f.write(indented_str(3, "// }),"))
  779. if features["nc"]["status"]:
  780. f.write(indented_str(3, 'UIAction(title: "Notification Center".localized(), handler: {(_) in'))
  781. f.write(indented_str(4, "APIS.openNotificationCenter();"))
  782. f.write(indented_str(3, "}),"))
  783. else:
  784. f.write(indented_str(3, '// UIAction(title: "Notification Center".localized(), handler: {(_) in'))
  785. f.write(indented_str(4, "// APIS.openNotificationCenter();"))
  786. f.write(indented_str(3, "// }),"))
  787. if features["im"]["status"]:
  788. f.write(indented_str(3, 'UIAction(title: "Chat".localized(), handler: {(_) in'))
  789. f.write(indented_str(4, "APIS.openChat();"))
  790. f.write(indented_str(3, "}),"))
  791. else:
  792. f.write(indented_str(3, '// UIAction(title: "Chat".localized(), handler: {(_) in'))
  793. f.write(indented_str(4, "// APIS.openChat();"))
  794. f.write(indented_str(3, "// }),"))
  795. if features["call"]["status"]:
  796. f.write(indented_str(3, 'UIAction(title: "Call".localized(), handler: {(_) in'))
  797. f.write(indented_str(4, "APIS.openCall();"))
  798. f.write(indented_str(3, "}),"))
  799. else:
  800. f.write(indented_str(3, '// UIAction(title: "Call".localized(), handler: {(_) in'))
  801. f.write(indented_str(4, "// APIS.openCall();"))
  802. f.write(indented_str(3, "// }),"))
  803. if features["ls"]["status"]:
  804. f.write(indented_str(3, 'UIAction(title: "Live Streaming".localized(), handler: {(_) in'))
  805. f.write(indented_str(4, "APIS.openStreaming();"))
  806. f.write(indented_str(3, "}),"))
  807. else:
  808. f.write(indented_str(3, '// UIAction(title: "Live Streaming".localized(), handler: {(_) in'))
  809. f.write(indented_str(4, "// APIS.openStreaming();"))
  810. f.write(indented_str(3, "// }),"))
  811. else:
  812. f.write(line)
  813. elif platform == "ios_flutter":
  814. main_act_path = os.path.join(path_dest, "lib/main.dart")
  815. with open(main_act_path, "r") as f:
  816. lines = f.readlines()
  817. with open(main_act_path, "w") as f:
  818. features_str = []
  819. for line in lines:
  820. if "'Features List'" in line:
  821. features_str.append("Settings")
  822. features_str.append("Profile")
  823. if features["cc"]["status"]:
  824. features_str.append("'Contact Center'")
  825. else:
  826. features_str.append("// 'Contact Center'")
  827. if features["nc"]["status"]:
  828. features_str.append("'Notification Center'")
  829. else:
  830. features_str.append("// 'Notification Center'")
  831. if features["im"]["status"]:
  832. features_str.append("'Instant Messaging'")
  833. else:
  834. features_str.append("// 'Instant Messaging'")
  835. if features["call"]["status"]:
  836. features_str.append("'Call'")
  837. else:
  838. features_str.append("// 'Call'")
  839. if features["ls"]["status"]:
  840. features_str.append("'Streaming'")
  841. else:
  842. features_str.append("// 'Streaming'")
  843. for feature_str in features_str:
  844. f.write(indented_str(8, f"{feature_str},", spaces=2))
  845. elif "//FEATURES" in line:
  846. f.write(indented_str(3, 'case "Settings":', spaces=2))
  847. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  848. f.write(indented_str(4, "break;", spaces=2))
  849. f.write(indented_str(3, 'case "Profile":', spaces=2))
  850. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  851. f.write(indented_str(4, "break;", spaces=2))
  852. if features["cc"]["status"]:
  853. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  854. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  855. f.write(indented_str(4, "break;", spaces=2))
  856. else:
  857. f.write(indented_str(3, '// case "Contact Center":', spaces=2))
  858. f.write(indented_str(4, '// nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  859. f.write(indented_str(4, "// break;", spaces=2))
  860. if features["nc"]["status"]:
  861. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  862. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  863. f.write(indented_str(4, "break;", spaces=2))
  864. else:
  865. f.write(indented_str(3, '// case "Notification Center":', spaces=2))
  866. f.write(indented_str(4, '// nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  867. f.write(indented_str(4, "// break;", spaces=2))
  868. if features["im"]["status"]:
  869. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  870. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  871. f.write(indented_str(4, "break;", spaces=2))
  872. else:
  873. f.write(indented_str(3, '// case "Instant Messaging":', spaces=2))
  874. f.write(indented_str(4, '// nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  875. f.write(indented_str(4, "// break;", spaces=2))
  876. if features["call"]["status"]:
  877. f.write(indented_str(3, 'case "Call":', spaces=2))
  878. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  879. f.write(indented_str(4, "break;", spaces=2))
  880. else:
  881. f.write(indented_str(3, '// case "Call":', spaces=2))
  882. f.write(indented_str(4, '// nativeChannel.invokeMethod("openCall");', spaces=2))
  883. f.write(indented_str(4, "// break;", spaces=2))
  884. if features["ls"]["status"]:
  885. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  886. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  887. f.write(indented_str(4, "break;", spaces=2))
  888. else:
  889. f.write(indented_str(3, '// case "Streaming":', spaces=2))
  890. f.write(indented_str(4, '// nativeChannel.invokeMethod("openStreaming");', spaces=2))
  891. f.write(indented_str(4, "// break;", spaces=2))
  892. else:
  893. f.write(line)
  894. elif platform == "ios_ionic":
  895. main_act_path = os.path.join(path_dest, "src/app/app.component.ts")
  896. with open(main_act_path, "r") as f:
  897. lines = f.readlines()
  898. with open(main_act_path, "w") as f:
  899. for line in lines:
  900. if "//FEATURES" in line:
  901. f.write(indented_str(4, '{', spaces=2))
  902. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  903. f.write(indented_str(5, "handler: () => {", spaces=2))
  904. f.write(indented_str(6, "this.openSettings();", spaces=2))
  905. f.write(indented_str(5, "},", spaces=2))
  906. f.write(indented_str(4, "},", spaces=2))
  907. f.write(indented_str(4, '{', spaces=2))
  908. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  909. f.write(indented_str(5, "handler: () => {", spaces=2))
  910. f.write(indented_str(6, "this.openProfile();", spaces=2))
  911. f.write(indented_str(5, "},", spaces=2))
  912. f.write(indented_str(4, "},", spaces=2))
  913. if features["cc"]["status"]:
  914. f.write(indented_str(4, '{', spaces=2))
  915. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  916. f.write(indented_str(5, "handler: () => {", spaces=2))
  917. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  918. f.write(indented_str(5, "},", spaces=2))
  919. f.write(indented_str(4, "},", spaces=2))
  920. else:
  921. f.write(indented_str(4, '// {', spaces=2))
  922. f.write(indented_str(5, "// text: 'Contact Center',", spaces=2))
  923. f.write(indented_str(5, "// handler: () => {", spaces=2))
  924. f.write(indented_str(6, "// this.openContactCenter();", spaces=2))
  925. f.write(indented_str(5, "// },", spaces=2))
  926. f.write(indented_str(4, "// },", spaces=2))
  927. if features["nc"]["status"]:
  928. f.write(indented_str(4, '{', spaces=2))
  929. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  930. f.write(indented_str(5, "handler: () => {", spaces=2))
  931. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  932. f.write(indented_str(5, "},", spaces=2))
  933. f.write(indented_str(4, "},", spaces=2))
  934. else:
  935. f.write(indented_str(4, '// {', spaces=2))
  936. f.write(indented_str(5, "// text: 'Notification Center',", spaces=2))
  937. f.write(indented_str(5, "// handler: () => {", spaces=2))
  938. f.write(indented_str(6, "// this.openNotificationCenter();", spaces=2))
  939. f.write(indented_str(5, "// },", spaces=2))
  940. f.write(indented_str(4, "// },", spaces=2))
  941. if features["im"]["status"]:
  942. f.write(indented_str(4, '{', spaces=2))
  943. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  944. f.write(indented_str(5, "handler: () => {", spaces=2))
  945. f.write(indented_str(6, "this.openChat();", spaces=2))
  946. f.write(indented_str(5, "},", spaces=2))
  947. f.write(indented_str(4, "},", spaces=2))
  948. else:
  949. f.write(indented_str(4, '// {', spaces=2))
  950. f.write(indented_str(5, "// text: 'Instant Messaging',", spaces=2))
  951. f.write(indented_str(5, "// handler: () => {", spaces=2))
  952. f.write(indented_str(6, "// this.openChat();", spaces=2))
  953. f.write(indented_str(5, "// },", spaces=2))
  954. f.write(indented_str(4, "// },", spaces=2))
  955. if features["call"]["status"]:
  956. f.write(indented_str(4, '{', spaces=2))
  957. f.write(indented_str(5, "text: 'Call',", spaces=2))
  958. f.write(indented_str(5, "handler: () => {", spaces=2))
  959. f.write(indented_str(6, "this.openCall();", spaces=2))
  960. f.write(indented_str(5, "},", spaces=2))
  961. f.write(indented_str(4, "},", spaces=2))
  962. else:
  963. f.write(indented_str(4, '// {', spaces=2))
  964. f.write(indented_str(5, "// text: 'Call',", spaces=2))
  965. f.write(indented_str(5, "// handler: () => {", spaces=2))
  966. f.write(indented_str(6, "// this.openCall();", spaces=2))
  967. f.write(indented_str(5, "// },", spaces=2))
  968. f.write(indented_str(4, "// },", spaces=2))
  969. if features["ls"]["status"]:
  970. f.write(indented_str(4, '{', spaces=2))
  971. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  972. f.write(indented_str(5, "handler: () => {", spaces=2))
  973. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  974. f.write(indented_str(5, "},", spaces=2))
  975. f.write(indented_str(4, "},", spaces=2))
  976. else:
  977. f.write(indented_str(4, '// {', spaces=2))
  978. f.write(indented_str(5, "// text: 'Streaming',", spaces=2))
  979. f.write(indented_str(5, "// handler: () => {", spaces=2))
  980. f.write(indented_str(6, "// this.openStreaming();", spaces=2))
  981. f.write(indented_str(5, "// },", spaces=2))
  982. f.write(indented_str(4, "// },", spaces=2))
  983. else:
  984. f.write(line)
  985. elif platform == "ios_react":
  986. pass
  987. def deliver_zip(path_dest, uid):
  988. rand_name = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(32))
  989. zip_name = f"{rand_name}"
  990. new_dir = os.path.join(app.zip_folder, zip_name)
  991. try:
  992. shutil.make_archive(new_dir, 'zip', path_dest)
  993. project_path = os.path.join(app.temp_folder, uid)
  994. shutil.rmtree(project_path)
  995. return {"status": "0", "name": zip_name + ".zip"}
  996. except Exception as e:
  997. return {"status": "4", "message": "Deliver ZIP failed"}
  998. @app.route('/', methods=["GET", "POST"])
  999. def build_project():
  1000. vprint('==============================================================')
  1001. if request.method == 'POST':
  1002. platform = "android"
  1003. mode = "burger"
  1004. feature_dict = {
  1005. "im": {
  1006. "android_name": "action_chats",
  1007. "status": False
  1008. },
  1009. "cc": {
  1010. "android_name": "action_cc",
  1011. "status": False
  1012. },
  1013. "call": {
  1014. "android_name": "action_call",
  1015. "status": False
  1016. },
  1017. "ls": {
  1018. "android_name": "action_ls",
  1019. "status": False
  1020. },
  1021. "settings": {
  1022. "android_name": "action_settings",
  1023. "status": False
  1024. },
  1025. "nc": {
  1026. "android_name": "action_nc",
  1027. "status": False
  1028. },
  1029. "sms": {
  1030. "status": False
  1031. },
  1032. "email": {
  1033. "status": False
  1034. },
  1035. }
  1036. security_dict = {
  1037. "malware": False,
  1038. "clone": False,
  1039. "emulator": False,
  1040. "debug": False,
  1041. "sim_swap": False,
  1042. "capture": False,
  1043. "call_forwarding": False,
  1044. "secure_folder": False,
  1045. "show_security": False,
  1046. }
  1047. try:
  1048. if "feature_im" in request.form:
  1049. feature_dict["im"]["status"] = request.form["feature_im"] == "1"
  1050. if "feature_cc" in request.form:
  1051. feature_dict["cc"]["status"] = request.form["feature_cc"] == "1"
  1052. if "feature_vc" in request.form:
  1053. feature_dict["call"]["status"] = request.form["feature_vc"] == "1"
  1054. if "feature_ac" in request.form:
  1055. feature_dict["call"]["status"] = request.form["feature_ac"] == "1"
  1056. if "feature_ls" in request.form:
  1057. feature_dict["ls"]["status"] = request.form["feature_ls"] == "1"
  1058. if "feature_nc" in request.form:
  1059. feature_dict["nc"]["status"] = request.form["feature_nc"] == "1"
  1060. if "feature_sms" in request.form:
  1061. feature_dict["sms"]["status"] = request.form["feature_sms"] == "1"
  1062. if "feature_email" in request.form:
  1063. feature_dict["email"]["status"] = request.form["feature_email"] == "1"
  1064. if "feature_settings" in request.form:
  1065. feature_dict["settings"]["status"] = request.form["feature_settings"] == "1"
  1066. if "security_malware" in request.form:
  1067. security_dict["malware"] = request.form["security_malware"] == "1"
  1068. if "security_clone" in request.form:
  1069. security_dict["clone"] = request.form["security_clone"] == "1"
  1070. if "security_emulator" in request.form:
  1071. security_dict["emulator"] = request.form["security_emulator"] == "1"
  1072. if "security_debug" in request.form:
  1073. security_dict["debug"] = request.form["security_debug"] == "1"
  1074. if "security_sim_swap" in request.form:
  1075. security_dict["sim_swap"] = request.form["security_sim_swap"] == "1"
  1076. if "security_capture" in request.form:
  1077. security_dict["capture"] = request.form["security_capture"] == "1"
  1078. if "security_call_forwarding" in request.form:
  1079. security_dict["call_forwarding"] = request.form["security_call_forwarding"] == "1"
  1080. if "security_secure_folder" in request.form:
  1081. security_dict["secure_folder"] = request.form["security_secure_folder"] == "1"
  1082. if "show_security" in request.form:
  1083. security_dict["show_security"] = request.form["show_security"] == "1"
  1084. else:
  1085. security_dict["show_security"] = (security_dict["malware"] or security_dict["clone"]
  1086. or security_dict["emulator"] or security_dict["debug"]
  1087. or security_dict["sim_swap"] or security_dict["capture"]
  1088. or security_dict["call_forwarding"]
  1089. or security_dict["secure_folder"])
  1090. if "platform" in request.form:
  1091. platform = request.form["platform"]
  1092. if "mode" in request.form:
  1093. mode = request.form["mode"]
  1094. except BaseException as e:
  1095. vprint(traceback.format_exc())
  1096. return {"status": "1", "message": "Parameter mismatch\n{}\n".format(str(e))}, 400
  1097. try:
  1098. uu_id = str(uuid.uuid4())
  1099. path_dest = create_folder(platform, uu_id)
  1100. change(platform, mode, path_dest, feature_dict, security_dict)
  1101. return deliver_zip(path_dest, uu_id)
  1102. except BaseException as e:
  1103. vprint(traceback.format_exc())
  1104. return {"status": "2", "message": "Process failure\n{}\n".format(str(e))}, 200
  1105. else:
  1106. if 'e' in request.args:
  1107. return request.args['e']
  1108. return "Hello World!"
  1109. if __name__ == '__main__':
  1110. app.run(host='0.0.0.0', port=8056, debug=app.verbose, ssl_context=app.ssl)