main.py 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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, 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. else:
  192. f.write(line)
  193. with open(xml_menu_path, "r") as f:
  194. lines = f.readlines()
  195. with open(xml_menu_path, "w") as f:
  196. for line in lines:
  197. if "<!-- FEATURES -->" in line:
  198. n = 100
  199. f.write(indented_str(1, "<item"))
  200. f.write(indented_str(2, 'android:id="@+id/action_settings"'))
  201. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  202. f.write(indented_str(2, 'android:title="Settings"'))
  203. f.write(indented_str(2, 'app:showAsAction="never" />'))
  204. n = n + 1
  205. f.write(indented_str(1, "<item"))
  206. f.write(indented_str(2, 'android:id="@+id/action_profile"'))
  207. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  208. f.write(indented_str(2, 'android:title="Profile"'))
  209. f.write(indented_str(2, 'app:showAsAction="never" />'))
  210. n = n + 1
  211. if features["cc"]["status"]:
  212. f.write(indented_str(1, "<item"))
  213. f.write(indented_str(2, 'android:id="@+id/action_cc"'))
  214. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  215. f.write(indented_str(2, 'android:title="Contact Center"'))
  216. f.write(indented_str(2, 'app:showAsAction="never" />'))
  217. n = n + 1
  218. else:
  219. f.write(indented_str(1, "<!-- <item"))
  220. f.write(indented_str(2, 'android:id="@+id/action_cc"'))
  221. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  222. f.write(indented_str(2, 'android:title="Contact Center"'))
  223. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  224. n = n + 1
  225. if features["nc"]["status"]:
  226. f.write(indented_str(1, "<item"))
  227. f.write(indented_str(2, 'android:id="@+id/action_nc"'))
  228. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  229. f.write(indented_str(2, 'android:title="Notification Center"'))
  230. f.write(indented_str(2, 'app:showAsAction="never" />'))
  231. n = n + 1
  232. else:
  233. f.write(indented_str(1, "<!-- <item"))
  234. f.write(indented_str(2, 'android:id="@+id/action_nc"'))
  235. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  236. f.write(indented_str(2, 'android:title="Notification Center"'))
  237. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  238. n = n + 1
  239. if features["im"]["status"]:
  240. f.write(indented_str(1, "<item"))
  241. f.write(indented_str(2, 'android:id="@+id/action_chats"'))
  242. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  243. f.write(indented_str(2, 'android:title="Instant Messaging"'))
  244. f.write(indented_str(2, 'app:showAsAction="never" />'))
  245. n = n + 1
  246. else:
  247. f.write(indented_str(1, "<!-- <item"))
  248. f.write(indented_str(2, 'android:id="@+id/action_chats"'))
  249. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  250. f.write(indented_str(2, 'android:title="Instant Messaging"'))
  251. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  252. n = n + 1
  253. if features["call"]["status"]:
  254. f.write(indented_str(1, "<item"))
  255. f.write(indented_str(2, 'android:id="@+id/action_call"'))
  256. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  257. f.write(indented_str(2, 'android:title="Call"'))
  258. f.write(indented_str(2, 'app:showAsAction="never" />'))
  259. n = n + 1
  260. else:
  261. f.write(indented_str(1, "<!-- <item"))
  262. f.write(indented_str(2, 'android:id="@+id/action_call"'))
  263. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  264. f.write(indented_str(2, 'android:title="Call"'))
  265. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  266. n = n + 1
  267. if features["ls"]["status"]:
  268. f.write(indented_str(1, "<item"))
  269. f.write(indented_str(2, 'android:id="@+id/action_ls"'))
  270. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  271. f.write(indented_str(2, 'android:title="Streaming"'))
  272. f.write(indented_str(2, 'app:showAsAction="never" />'))
  273. n = n + 1
  274. else:
  275. f.write(indented_str(1, "<!-- <item"))
  276. f.write(indented_str(2, 'android:id="@+id/action_ls"'))
  277. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  278. f.write(indented_str(2, 'android:title="Streaming"'))
  279. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  280. n = n + 1
  281. else:
  282. f.write(line)
  283. elif platform == "android_flutter":
  284. main_act_path = os.path.join(path_dest, "lib/main.dart")
  285. with open(main_act_path, "r") as f:
  286. lines = f.readlines()
  287. with open(main_act_path, "w") as f:
  288. features_str = []
  289. for line in lines:
  290. if "'Features List'" in line:
  291. features_str.append("Settings")
  292. features_str.append("Profile")
  293. if features["cc"]["status"]:
  294. features_str.append("'Contact Center'")
  295. else:
  296. features_str.append("// 'Contact Center'")
  297. if features["nc"]["status"]:
  298. features_str.append("'Notification Center'")
  299. else:
  300. features_str.append("// 'Notification Center'")
  301. if features["im"]["status"]:
  302. features_str.append("'Instant Messaging'")
  303. else:
  304. features_str.append("// 'Instant Messaging'")
  305. if features["call"]["status"]:
  306. features_str.append("'Call'")
  307. else:
  308. features_str.append("// 'Call'")
  309. if features["ls"]["status"]:
  310. features_str.append("'Streaming'")
  311. else:
  312. features_str.append("// 'Streaming'")
  313. for feature_str in features_str:
  314. f.write(indented_str(8, f"{feature_str},", spaces=2))
  315. elif "//FEATURES" in line:
  316. f.write(indented_str(3, 'case "Settings":', spaces=2))
  317. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  318. f.write(indented_str(4, "break;", spaces=2))
  319. f.write(indented_str(3, 'case "Profile":', spaces=2))
  320. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  321. f.write(indented_str(4, "break;", spaces=2))
  322. if features["cc"]["status"]:
  323. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  324. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  325. f.write(indented_str(4, "break;", spaces=2))
  326. else:
  327. f.write(indented_str(3, '// case "Contact Center":', spaces=2))
  328. f.write(indented_str(4, '// nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  329. f.write(indented_str(4, "// break;", spaces=2))
  330. if features["nc"]["status"]:
  331. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  332. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  333. f.write(indented_str(4, "break;", spaces=2))
  334. else:
  335. f.write(indented_str(3, '// case "Notification Center":', spaces=2))
  336. f.write(indented_str(4, '// nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  337. f.write(indented_str(4, "// break;", spaces=2))
  338. if features["im"]["status"]:
  339. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  340. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  341. f.write(indented_str(4, "break;", spaces=2))
  342. else:
  343. f.write(indented_str(3, '// case "Instant Messaging":', spaces=2))
  344. f.write(indented_str(4, '// nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  345. f.write(indented_str(4, "// break;", spaces=2))
  346. if features["call"]["status"]:
  347. f.write(indented_str(3, 'case "Call":', spaces=2))
  348. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  349. f.write(indented_str(4, "break;", spaces=2))
  350. else:
  351. f.write(indented_str(3, '// case "Call":', spaces=2))
  352. f.write(indented_str(4, '// nativeChannel.invokeMethod("openCall");', spaces=2))
  353. f.write(indented_str(4, "// break;", spaces=2))
  354. if features["ls"]["status"]:
  355. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  356. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  357. f.write(indented_str(4, "break;", spaces=2))
  358. else:
  359. f.write(indented_str(3, '// case "Streaming":', spaces=2))
  360. f.write(indented_str(4, '// nativeChannel.invokeMethod("openStreaming");', spaces=2))
  361. f.write(indented_str(4, "// break;", spaces=2))
  362. else:
  363. f.write(line)
  364. elif platform == "android_ionic":
  365. main_act_path = os.path.join(path_dest,"src/app/app.component.ts")
  366. with open(main_act_path, "r") as f:
  367. lines = f.readlines()
  368. with open(main_act_path, "w") as f:
  369. for line in lines:
  370. if "//FEATURES" in line:
  371. f.write(indented_str(4, '{', spaces=2))
  372. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  373. f.write(indented_str(5, "handler: () => {", spaces=2))
  374. f.write(indented_str(6, "this.openSettings();", spaces=2))
  375. f.write(indented_str(5, "},", spaces=2))
  376. f.write(indented_str(4, "},", spaces=2))
  377. f.write(indented_str(4, '{', spaces=2))
  378. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  379. f.write(indented_str(5, "handler: () => {", spaces=2))
  380. f.write(indented_str(6, "this.openProfile();", spaces=2))
  381. f.write(indented_str(5, "},", spaces=2))
  382. f.write(indented_str(4, "},", spaces=2))
  383. if features["cc"]["status"]:
  384. f.write(indented_str(4, '{', spaces=2))
  385. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  386. f.write(indented_str(5, "handler: () => {", spaces=2))
  387. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  388. f.write(indented_str(5, "},", spaces=2))
  389. f.write(indented_str(4, "},", spaces=2))
  390. else:
  391. f.write(indented_str(4, '// {', spaces=2))
  392. f.write(indented_str(5, "// text: 'Contact Center',", spaces=2))
  393. f.write(indented_str(5, "// handler: () => {", spaces=2))
  394. f.write(indented_str(6, "// this.openContactCenter();", spaces=2))
  395. f.write(indented_str(5, "// },", spaces=2))
  396. f.write(indented_str(4, "// },", spaces=2))
  397. if features["nc"]["status"]:
  398. f.write(indented_str(4, '{', spaces=2))
  399. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  400. f.write(indented_str(5, "handler: () => {", spaces=2))
  401. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  402. f.write(indented_str(5, "},", spaces=2))
  403. f.write(indented_str(4, "},", spaces=2))
  404. else:
  405. f.write(indented_str(4, '// {', spaces=2))
  406. f.write(indented_str(5, "// text: 'Notification Center',", spaces=2))
  407. f.write(indented_str(5, "// handler: () => {", spaces=2))
  408. f.write(indented_str(6, "// this.openNotificationCenter();", spaces=2))
  409. f.write(indented_str(5, "// },", spaces=2))
  410. f.write(indented_str(4, "// },", spaces=2))
  411. if features["im"]["status"]:
  412. f.write(indented_str(4, '{', spaces=2))
  413. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  414. f.write(indented_str(5, "handler: () => {", spaces=2))
  415. f.write(indented_str(6, "this.openChat();", spaces=2))
  416. f.write(indented_str(5, "},", spaces=2))
  417. f.write(indented_str(4, "},", spaces=2))
  418. else:
  419. f.write(indented_str(4, '// {', spaces=2))
  420. f.write(indented_str(5, "// text: 'Instant Messaging',", spaces=2))
  421. f.write(indented_str(5, "// handler: () => {", spaces=2))
  422. f.write(indented_str(6, "// this.openChat();", spaces=2))
  423. f.write(indented_str(5, "// },", spaces=2))
  424. f.write(indented_str(4, "// },", spaces=2))
  425. if features["call"]["status"]:
  426. f.write(indented_str(4, '{', spaces=2))
  427. f.write(indented_str(5, "text: 'Call',", spaces=2))
  428. f.write(indented_str(5, "handler: () => {", spaces=2))
  429. f.write(indented_str(6, "this.openCall();", spaces=2))
  430. f.write(indented_str(5, "},", spaces=2))
  431. f.write(indented_str(4, "},", spaces=2))
  432. else:
  433. f.write(indented_str(4, '// {', spaces=2))
  434. f.write(indented_str(5, "// text: 'Call',", spaces=2))
  435. f.write(indented_str(5, "// handler: () => {", spaces=2))
  436. f.write(indented_str(6, "// this.openCall();", spaces=2))
  437. f.write(indented_str(5, "// },", spaces=2))
  438. f.write(indented_str(4, "// },", spaces=2))
  439. if features["ls"]["status"]:
  440. f.write(indented_str(4, '{', spaces=2))
  441. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  442. f.write(indented_str(5, "handler: () => {", spaces=2))
  443. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  444. f.write(indented_str(5, "},", spaces=2))
  445. f.write(indented_str(4, "},", spaces=2))
  446. else:
  447. f.write(indented_str(4, '// {', spaces=2))
  448. f.write(indented_str(5, "// text: 'Streaming',", spaces=2))
  449. f.write(indented_str(5, "// handler: () => {", spaces=2))
  450. f.write(indented_str(6, "// this.openStreaming();", spaces=2))
  451. f.write(indented_str(5, "// },", spaces=2))
  452. f.write(indented_str(4, "// },", spaces=2))
  453. else:
  454. f.write(line)
  455. elif platform == "android_react":
  456. main_act_path = os.path.join(path_dest, "App.tsx")
  457. with open(main_act_path, "r") as f:
  458. lines = f.readlines()
  459. with open(main_act_path, "w") as f:
  460. for line in lines:
  461. if "'Features'" in line:
  462. f.write(indented_str(4, "'Setting',", spaces=2))
  463. f.write(indented_str(4, "'Profile',", spaces=2))
  464. if features["cc"]["status"]:
  465. f.write(indented_str(4, "'Contact Center',", spaces=2))
  466. else:
  467. f.write(indented_str(4, "// 'Contact Center',", spaces=2))
  468. if features["nc"]["status"]:
  469. f.write(indented_str(4, "'Notification Center',", spaces=2))
  470. else:
  471. f.write(indented_str(4, "// 'Notification Center',", spaces=2))
  472. if features["im"]["status"]:
  473. f.write(indented_str(4, "'Chat',", spaces=2))
  474. else:
  475. f.write(indented_str(4, "// 'Chat',", spaces=2))
  476. if features["call"]["status"]:
  477. f.write(indented_str(4, "'Call',", spaces=2))
  478. else:
  479. f.write(indented_str(4, "// 'Call',", spaces=2))
  480. if features["ls"]["status"]:
  481. f.write(indented_str(4, "'Live Streaming',", spaces=2))
  482. else:
  483. f.write(indented_str(4, "// 'Live Streaming',", spaces=2))
  484. elif "//FEATURES1" in line:
  485. n = 0
  486. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  487. f.write(indented_str(6, "CallNative.openSetting();", spaces=2))
  488. f.write(indented_str(5, "}", spaces=2))
  489. n = n + 1
  490. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  491. f.write(indented_str(6, "CallNative.openProfile();", spaces=2))
  492. f.write(indented_str(5, "}", spaces=2))
  493. n = n + 1
  494. if features["cc"]["status"]:
  495. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  496. f.write(indented_str(6, "CallNative.openContactCenter();", spaces=2))
  497. f.write(indented_str(5, "}", spaces=2))
  498. n = n + 1
  499. else:
  500. f.write(indented_str(5, "// if (buttonIndex === 2) {", spaces=2))
  501. f.write(indented_str(6, "// CallNative.openContactCenter();", spaces=2))
  502. f.write(indented_str(5, "// }", spaces=2))
  503. if features["nc"]["status"]:
  504. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  505. f.write(indented_str(6, "CallNative.openNotificationCenter();", spaces=2))
  506. f.write(indented_str(5, "}", spaces=2))
  507. n = n + 1
  508. else:
  509. f.write(indented_str(5, "// if (buttonIndex === 3) {", spaces=2))
  510. f.write(indented_str(6, "// CallNative.openNotificationCenter();", spaces=2))
  511. f.write(indented_str(5, "// }", spaces=2))
  512. if features["im"]["status"]:
  513. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  514. f.write(indented_str(6, "CallNative.openChat();", spaces=2))
  515. f.write(indented_str(5, "}", spaces=2))
  516. n = n + 1
  517. else:
  518. f.write(indented_str(5, "// if (buttonIndex === 4) {", spaces=2))
  519. f.write(indented_str(6, "// CallNative.openChat();", spaces=2))
  520. f.write(indented_str(5, "// }", spaces=2))
  521. if features["call"]["status"]:
  522. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  523. f.write(indented_str(6, "CallNative.openCall();", spaces=2))
  524. f.write(indented_str(5, "}", spaces=2))
  525. n = n + 1
  526. else:
  527. f.write(indented_str(5, "// if (buttonIndex === 5) {", spaces=2))
  528. f.write(indented_str(6, "// CallNative.openCall();", spaces=2))
  529. f.write(indented_str(5, "// }", spaces=2))
  530. if features["ls"]["status"]:
  531. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  532. f.write(indented_str(6, "CallNative.openStreaming();", spaces=2))
  533. f.write(indented_str(5, "}", spaces=2))
  534. n = n + 1
  535. else:
  536. f.write(indented_str(5, "// if (buttonIndex === 6) {", spaces=2))
  537. f.write(indented_str(6, "// CallNative.openStreaming();", spaces=2))
  538. f.write(indented_str(5, "// }", spaces=2))
  539. elif "//FEATURES2" in line:
  540. n = 0
  541. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  542. f.write(indented_str(3, "try {", spaces=2))
  543. f.write(indented_str(4, "CallNative.openSetting();", spaces=2))
  544. f.write(indented_str(3, "} catch (e) {", spaces=2))
  545. f.write(indented_str(4, "console.log(e);", spaces=2))
  546. f.write(indented_str(3, "}", spaces=2))
  547. f.write(indented_str(2, "}", spaces=2))
  548. n = n + 1
  549. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  550. f.write(indented_str(3, "try {", spaces=2))
  551. f.write(indented_str(4, "CallNative.openProfile();", spaces=2))
  552. f.write(indented_str(3, "} catch (e) {", spaces=2))
  553. f.write(indented_str(4, "console.log(e);", spaces=2))
  554. f.write(indented_str(3, "}", spaces=2))
  555. f.write(indented_str(2, "}", spaces=2))
  556. n = n + 1
  557. if features["cc"]["status"]:
  558. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  559. f.write(indented_str(3, "try {", spaces=2))
  560. f.write(indented_str(4, "CallNative.openContactCenter();", spaces=2))
  561. f.write(indented_str(3, "} catch (e) {", spaces=2))
  562. f.write(indented_str(4, "console.log(e);", spaces=2))
  563. f.write(indented_str(3, "}", spaces=2))
  564. f.write(indented_str(2, "}", spaces=2))
  565. n = n + 1
  566. else:
  567. f.write(indented_str(2, "// if (buttonIndex === 2) {", spaces=2))
  568. f.write(indented_str(3, "// try {", spaces=2))
  569. f.write(indented_str(4, "// CallNative.openContactCenter();", spaces=2))
  570. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  571. f.write(indented_str(4, "// console.log(e);", spaces=2))
  572. f.write(indented_str(3, "// }", spaces=2))
  573. f.write(indented_str(2, "// }", spaces=2))
  574. if features["nc"]["status"]:
  575. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  576. f.write(indented_str(3, "try {", spaces=2))
  577. f.write(indented_str(4, "CallNative.openNotificationCenter();", spaces=2))
  578. f.write(indented_str(3, "} catch (e) {", spaces=2))
  579. f.write(indented_str(4, "console.log(e);", spaces=2))
  580. f.write(indented_str(3, "}", spaces=2))
  581. f.write(indented_str(2, "}", spaces=2))
  582. n = n + 1
  583. else:
  584. f.write(indented_str(2, "// if (buttonIndex === 3) {", spaces=2))
  585. f.write(indented_str(3, "// try {", spaces=2))
  586. f.write(indented_str(4, "// CallNative.openNotificationCenter();", spaces=2))
  587. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  588. f.write(indented_str(4, "// console.log(e);", spaces=2))
  589. f.write(indented_str(3, "// }", spaces=2))
  590. f.write(indented_str(2, "// }", spaces=2))
  591. if features["im"]["status"]:
  592. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  593. f.write(indented_str(3, "try {", spaces=2))
  594. f.write(indented_str(4, "CallNative.openChat();", spaces=2))
  595. f.write(indented_str(3, "} catch (e) {", spaces=2))
  596. f.write(indented_str(4, "console.log(e);", spaces=2))
  597. f.write(indented_str(3, "}", spaces=2))
  598. f.write(indented_str(2, "}", spaces=2))
  599. n = n + 1
  600. else:
  601. f.write(indented_str(2, "// if (buttonIndex === 4) {", spaces=2))
  602. f.write(indented_str(3, "// try {", spaces=2))
  603. f.write(indented_str(4, "// CallNative.openChat();", spaces=2))
  604. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  605. f.write(indented_str(4, "// console.log(e);", spaces=2))
  606. f.write(indented_str(3, "// }", spaces=2))
  607. f.write(indented_str(2, "// }", spaces=2))
  608. if features["call"]["status"]:
  609. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  610. f.write(indented_str(3, "try {", spaces=2))
  611. f.write(indented_str(4, "CallNative.openCall();", spaces=2))
  612. f.write(indented_str(3, "} catch (e) {", spaces=2))
  613. f.write(indented_str(4, "console.log(e);", spaces=2))
  614. f.write(indented_str(3, "}", spaces=2))
  615. f.write(indented_str(2, "}", spaces=2))
  616. n = n + 1
  617. else:
  618. f.write(indented_str(2, "// if (buttonIndex === 5) {", spaces=2))
  619. f.write(indented_str(3, "// try {", spaces=2))
  620. f.write(indented_str(4, "// CallNative.openCall();", spaces=2))
  621. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  622. f.write(indented_str(4, "// console.log(e);", spaces=2))
  623. f.write(indented_str(3, "// }", spaces=2))
  624. f.write(indented_str(2, "// }", spaces=2))
  625. if features["ls"]["status"]:
  626. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  627. f.write(indented_str(3, "try {", spaces=2))
  628. f.write(indented_str(4, "CallNative.openStreaming();", spaces=2))
  629. f.write(indented_str(3, "} catch (e) {", spaces=2))
  630. f.write(indented_str(4, "console.log(e);", spaces=2))
  631. f.write(indented_str(3, "}", spaces=2))
  632. f.write(indented_str(2, "}", spaces=2))
  633. n = n + 1
  634. else:
  635. f.write(indented_str(2, "// if (buttonIndex === {n}) {", spaces=2))
  636. f.write(indented_str(3, "// try {", spaces=2))
  637. f.write(indented_str(4, "// CallNative.openStreaming();", spaces=2))
  638. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  639. f.write(indented_str(4, "// console.log(e);", spaces=2))
  640. f.write(indented_str(3, "// }", spaces=2))
  641. f.write(indented_str(2, "// }", spaces=2))
  642. elif "//FEATURES3" in line:
  643. n = 0
  644. f.write(indented_str(5, "<Button", spaces=2))
  645. f.write(indented_str(6, 'title="Setting"', spaces=2))
  646. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  647. f.write(indented_str(5, "/>", spaces=2))
  648. n = n + 1
  649. f.write(indented_str(5, "<Button", spaces=2))
  650. f.write(indented_str(6, 'title="Profile"', spaces=2))
  651. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  652. f.write(indented_str(5, "/>", spaces=2))
  653. n = n + 1
  654. if features["cc"]["status"]:
  655. f.write(indented_str(5, "<Button", spaces=2))
  656. f.write(indented_str(6, 'title="Contact Center"', spaces=2))
  657. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  658. f.write(indented_str(5, "/>", spaces=2))
  659. n = n + 1
  660. else:
  661. f.write(indented_str(5, "{/* <Button", spaces=2))
  662. f.write(indented_str(6, 'title="Contact Center"', spaces=2))
  663. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(2)}}', spaces=2))
  664. f.write(indented_str(5, "/> */}", spaces=2))
  665. if features["nc"]["status"]:
  666. f.write(indented_str(5, "<Button", spaces=2))
  667. f.write(indented_str(6, 'title="Notification Center"', spaces=2))
  668. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  669. f.write(indented_str(5, "/>", spaces=2))
  670. n = n + 1
  671. else:
  672. f.write(indented_str(5, "{/* <Button", spaces=2))
  673. f.write(indented_str(6, 'title="Notification Center"', spaces=2))
  674. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(3)}}', spaces=2))
  675. f.write(indented_str(5, "/> */}", spaces=2))
  676. if features["im"]["status"]:
  677. f.write(indented_str(5, "<Button", spaces=2))
  678. f.write(indented_str(6, 'title="Chat"', spaces=2))
  679. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  680. f.write(indented_str(5, "/>", spaces=2))
  681. n = n + 1
  682. else:
  683. f.write(indented_str(5, "{/* <Button", spaces=2))
  684. f.write(indented_str(6, 'title="Chat"', spaces=2))
  685. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(4)}}', spaces=2))
  686. f.write(indented_str(5, "/> */}", spaces=2))
  687. if features["call"]["status"]:
  688. f.write(indented_str(5, "<Button", spaces=2))
  689. f.write(indented_str(6, 'title="Call"', spaces=2))
  690. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  691. f.write(indented_str(5, "/>", spaces=2))
  692. n = n + 1
  693. else:
  694. f.write(indented_str(5, "{/* <Button", spaces=2))
  695. f.write(indented_str(6, 'title="Call"', spaces=2))
  696. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(5)}}', spaces=2))
  697. f.write(indented_str(5, "/> */}", spaces=2))
  698. if features["ls"]["status"]:
  699. f.write(indented_str(5, "<Button", spaces=2))
  700. f.write(indented_str(6, 'title="Live Streaming"', spaces=2))
  701. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  702. f.write(indented_str(5, "/>", spaces=2))
  703. n = n + 1
  704. else:
  705. f.write(indented_str(5, "{/* <Button", spaces=2))
  706. f.write(indented_str(6, 'title="Live Streaming"', spaces=2))
  707. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(5)}}', spaces=2))
  708. f.write(indented_str(5, "/> */}", spaces=2))
  709. else:
  710. f.write(line)
  711. elif platform == "ios":
  712. main_act_path = os.path.join(path_dest, "ExampleCode/ViewController.swift")
  713. with open(main_act_path, "r") as f:
  714. lines = f.readlines()
  715. with open(main_act_path, "w") as f:
  716. for line in lines:
  717. if "//FEATURES" in line:
  718. f.write(indented_str(3, 'UIAction(title: "Setting".localized(), handler: {(_) in'))
  719. f.write(indented_str(4, "APIS.openSetting();"))
  720. f.write(indented_str(3, "}),"))
  721. f.write(indented_str(3, 'UIAction(title: "Profile".localized(), handler: {(_) in'))
  722. f.write(indented_str(4, "APIS.openProfile();"))
  723. f.write(indented_str(3, "}),"))
  724. if features["cc"]["status"]:
  725. f.write(indented_str(3, 'UIAction(title: "Contact Center".localized(), handler: {(_) in'))
  726. f.write(indented_str(4, "APIS.openContactCenter();"))
  727. f.write(indented_str(3, "}),"))
  728. else:
  729. f.write(indented_str(3, '// UIAction(title: "Contact Center".localized(), handler: {(_) in'))
  730. f.write(indented_str(4, "// APIS.openContactCenter();"))
  731. f.write(indented_str(3, "// }),"))
  732. if features["nc"]["status"]:
  733. f.write(indented_str(3, 'UIAction(title: "Notification Center".localized(), handler: {(_) in'))
  734. f.write(indented_str(4, "APIS.openNotificationCenter();"))
  735. f.write(indented_str(3, "}),"))
  736. else:
  737. f.write(indented_str(3, '// UIAction(title: "Notification Center".localized(), handler: {(_) in'))
  738. f.write(indented_str(4, "// APIS.openNotificationCenter();"))
  739. f.write(indented_str(3, "// }),"))
  740. if features["im"]["status"]:
  741. f.write(indented_str(3, 'UIAction(title: "Chat".localized(), handler: {(_) in'))
  742. f.write(indented_str(4, "APIS.openChat();"))
  743. f.write(indented_str(3, "}),"))
  744. else:
  745. f.write(indented_str(3, '// UIAction(title: "Chat".localized(), handler: {(_) in'))
  746. f.write(indented_str(4, "// APIS.openChat();"))
  747. f.write(indented_str(3, "// }),"))
  748. if features["call"]["status"]:
  749. f.write(indented_str(3, 'UIAction(title: "Call".localized(), handler: {(_) in'))
  750. f.write(indented_str(4, "APIS.openCall();"))
  751. f.write(indented_str(3, "}),"))
  752. else:
  753. f.write(indented_str(3, '// UIAction(title: "Call".localized(), handler: {(_) in'))
  754. f.write(indented_str(4, "// APIS.openCall();"))
  755. f.write(indented_str(3, "// }),"))
  756. if features["ls"]["status"]:
  757. f.write(indented_str(3, 'UIAction(title: "Live Streaming".localized(), handler: {(_) in'))
  758. f.write(indented_str(4, "APIS.openStreaming();"))
  759. f.write(indented_str(3, "}),"))
  760. else:
  761. f.write(indented_str(3, '// UIAction(title: "Live Streaming".localized(), handler: {(_) in'))
  762. f.write(indented_str(4, "// APIS.openStreaming();"))
  763. f.write(indented_str(3, "// }),"))
  764. else:
  765. f.write(line)
  766. elif platform == "ios_flutter":
  767. main_act_path = os.path.join(path_dest, "lib/main.dart")
  768. with open(main_act_path, "r") as f:
  769. lines = f.readlines()
  770. with open(main_act_path, "w") as f:
  771. features_str = []
  772. for line in lines:
  773. if "'Features List'" in line:
  774. features_str.append("Settings")
  775. features_str.append("Profile")
  776. if features["cc"]["status"]:
  777. features_str.append("'Contact Center'")
  778. else:
  779. features_str.append("// 'Contact Center'")
  780. if features["nc"]["status"]:
  781. features_str.append("'Notification Center'")
  782. else:
  783. features_str.append("// 'Notification Center'")
  784. if features["im"]["status"]:
  785. features_str.append("'Instant Messaging'")
  786. else:
  787. features_str.append("// 'Instant Messaging'")
  788. if features["call"]["status"]:
  789. features_str.append("'Call'")
  790. else:
  791. features_str.append("// 'Call'")
  792. if features["ls"]["status"]:
  793. features_str.append("'Streaming'")
  794. else:
  795. features_str.append("// 'Streaming'")
  796. for feature_str in features_str:
  797. f.write(indented_str(8, f"{feature_str},", spaces=2))
  798. elif "//FEATURES" in line:
  799. f.write(indented_str(3, 'case "Settings":', spaces=2))
  800. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  801. f.write(indented_str(4, "break;", spaces=2))
  802. f.write(indented_str(3, 'case "Profile":', spaces=2))
  803. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  804. f.write(indented_str(4, "break;", spaces=2))
  805. if features["cc"]["status"]:
  806. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  807. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  808. f.write(indented_str(4, "break;", spaces=2))
  809. else:
  810. f.write(indented_str(3, '// case "Contact Center":', spaces=2))
  811. f.write(indented_str(4, '// nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  812. f.write(indented_str(4, "// break;", spaces=2))
  813. if features["nc"]["status"]:
  814. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  815. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  816. f.write(indented_str(4, "break;", spaces=2))
  817. else:
  818. f.write(indented_str(3, '// case "Notification Center":', spaces=2))
  819. f.write(indented_str(4, '// nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  820. f.write(indented_str(4, "// break;", spaces=2))
  821. if features["im"]["status"]:
  822. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  823. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  824. f.write(indented_str(4, "break;", spaces=2))
  825. else:
  826. f.write(indented_str(3, '// case "Instant Messaging":', spaces=2))
  827. f.write(indented_str(4, '// nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  828. f.write(indented_str(4, "// break;", spaces=2))
  829. if features["call"]["status"]:
  830. f.write(indented_str(3, 'case "Call":', spaces=2))
  831. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  832. f.write(indented_str(4, "break;", spaces=2))
  833. else:
  834. f.write(indented_str(3, '// case "Call":', spaces=2))
  835. f.write(indented_str(4, '// nativeChannel.invokeMethod("openCall");', spaces=2))
  836. f.write(indented_str(4, "// break;", spaces=2))
  837. if features["ls"]["status"]:
  838. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  839. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  840. f.write(indented_str(4, "break;", spaces=2))
  841. else:
  842. f.write(indented_str(3, '// case "Streaming":', spaces=2))
  843. f.write(indented_str(4, '// nativeChannel.invokeMethod("openStreaming");', spaces=2))
  844. f.write(indented_str(4, "// break;", spaces=2))
  845. else:
  846. f.write(line)
  847. elif platform == "ios_ionic":
  848. main_act_path = os.path.join(path_dest, "src/app/app.component.ts")
  849. with open(main_act_path, "r") as f:
  850. lines = f.readlines()
  851. with open(main_act_path, "w") as f:
  852. for line in lines:
  853. if "//FEATURES" in line:
  854. f.write(indented_str(4, '{', spaces=2))
  855. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  856. f.write(indented_str(5, "handler: () => {", spaces=2))
  857. f.write(indented_str(6, "this.openSettings();", spaces=2))
  858. f.write(indented_str(5, "},", spaces=2))
  859. f.write(indented_str(4, "},", spaces=2))
  860. f.write(indented_str(4, '{', spaces=2))
  861. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  862. f.write(indented_str(5, "handler: () => {", spaces=2))
  863. f.write(indented_str(6, "this.openProfile();", spaces=2))
  864. f.write(indented_str(5, "},", spaces=2))
  865. f.write(indented_str(4, "},", spaces=2))
  866. if features["cc"]["status"]:
  867. f.write(indented_str(4, '{', spaces=2))
  868. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  869. f.write(indented_str(5, "handler: () => {", spaces=2))
  870. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  871. f.write(indented_str(5, "},", spaces=2))
  872. f.write(indented_str(4, "},", spaces=2))
  873. else:
  874. f.write(indented_str(4, '// {', spaces=2))
  875. f.write(indented_str(5, "// text: 'Contact Center',", spaces=2))
  876. f.write(indented_str(5, "// handler: () => {", spaces=2))
  877. f.write(indented_str(6, "// this.openContactCenter();", spaces=2))
  878. f.write(indented_str(5, "// },", spaces=2))
  879. f.write(indented_str(4, "// },", spaces=2))
  880. if features["nc"]["status"]:
  881. f.write(indented_str(4, '{', spaces=2))
  882. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  883. f.write(indented_str(5, "handler: () => {", spaces=2))
  884. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  885. f.write(indented_str(5, "},", spaces=2))
  886. f.write(indented_str(4, "},", spaces=2))
  887. else:
  888. f.write(indented_str(4, '// {', spaces=2))
  889. f.write(indented_str(5, "// text: 'Notification Center',", spaces=2))
  890. f.write(indented_str(5, "// handler: () => {", spaces=2))
  891. f.write(indented_str(6, "// this.openNotificationCenter();", spaces=2))
  892. f.write(indented_str(5, "// },", spaces=2))
  893. f.write(indented_str(4, "// },", spaces=2))
  894. if features["im"]["status"]:
  895. f.write(indented_str(4, '{', spaces=2))
  896. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  897. f.write(indented_str(5, "handler: () => {", spaces=2))
  898. f.write(indented_str(6, "this.openChat();", spaces=2))
  899. f.write(indented_str(5, "},", spaces=2))
  900. f.write(indented_str(4, "},", spaces=2))
  901. else:
  902. f.write(indented_str(4, '// {', spaces=2))
  903. f.write(indented_str(5, "// text: 'Instant Messaging',", spaces=2))
  904. f.write(indented_str(5, "// handler: () => {", spaces=2))
  905. f.write(indented_str(6, "// this.openChat();", spaces=2))
  906. f.write(indented_str(5, "// },", spaces=2))
  907. f.write(indented_str(4, "// },", spaces=2))
  908. if features["call"]["status"]:
  909. f.write(indented_str(4, '{', spaces=2))
  910. f.write(indented_str(5, "text: 'Call',", spaces=2))
  911. f.write(indented_str(5, "handler: () => {", spaces=2))
  912. f.write(indented_str(6, "this.openCall();", spaces=2))
  913. f.write(indented_str(5, "},", spaces=2))
  914. f.write(indented_str(4, "},", spaces=2))
  915. else:
  916. f.write(indented_str(4, '// {', spaces=2))
  917. f.write(indented_str(5, "// text: 'Call',", spaces=2))
  918. f.write(indented_str(5, "// handler: () => {", spaces=2))
  919. f.write(indented_str(6, "// this.openCall();", spaces=2))
  920. f.write(indented_str(5, "// },", spaces=2))
  921. f.write(indented_str(4, "// },", spaces=2))
  922. if features["ls"]["status"]:
  923. f.write(indented_str(4, '{', spaces=2))
  924. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  925. f.write(indented_str(5, "handler: () => {", spaces=2))
  926. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  927. f.write(indented_str(5, "},", spaces=2))
  928. f.write(indented_str(4, "},", spaces=2))
  929. else:
  930. f.write(indented_str(4, '// {', spaces=2))
  931. f.write(indented_str(5, "// text: 'Streaming',", spaces=2))
  932. f.write(indented_str(5, "// handler: () => {", spaces=2))
  933. f.write(indented_str(6, "// this.openStreaming();", spaces=2))
  934. f.write(indented_str(5, "// },", spaces=2))
  935. f.write(indented_str(4, "// },", spaces=2))
  936. else:
  937. f.write(line)
  938. elif platform == "ios_react":
  939. pass
  940. def deliver_zip(path_dest, uid):
  941. rand_name = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(32))
  942. zip_name = f"{rand_name}"
  943. new_dir = os.path.join(app.zip_folder, zip_name)
  944. try:
  945. shutil.make_archive(new_dir, 'zip', path_dest)
  946. project_path = os.path.join(app.temp_folder, uid)
  947. shutil.rmtree(project_path)
  948. return {"status": "0", "name": zip_name + ".zip"}
  949. except Exception as e:
  950. return {"status": "4", "message": "Deliver ZIP failed"}
  951. @app.route('/', methods=["GET", "POST"])
  952. def build_project():
  953. vprint('==============================================================')
  954. if request.method == 'POST':
  955. platform = "android"
  956. feature_dict = {
  957. "im": {
  958. "android_name": "action_chats",
  959. "status": False
  960. },
  961. "cc": {
  962. "android_name": "action_cc",
  963. "status": False
  964. },
  965. "call": {
  966. "android_name": "action_call",
  967. "status": False
  968. },
  969. "ls": {
  970. "android_name": "action_ls",
  971. "status": False
  972. },
  973. "settings": {
  974. "android_name": "action_settings",
  975. "status": False
  976. },
  977. "nc": {
  978. "android_name": "action_nc",
  979. "status": False
  980. },
  981. "sms": {
  982. "status": False
  983. },
  984. "email": {
  985. "status": False
  986. },
  987. }
  988. security_dict = {
  989. "malware": False,
  990. "clone": False,
  991. "emulator": False,
  992. "debug": False,
  993. "sim_swap": False,
  994. "capture": False,
  995. "call_forwarding": False,
  996. "secure_folder": False,
  997. "show_security": False,
  998. }
  999. try:
  1000. if "feature_im" in request.form:
  1001. feature_dict["im"]["status"] = request.form["feature_im"] == "1"
  1002. if "feature_cc" in request.form:
  1003. feature_dict["cc"]["status"] = request.form["feature_cc"] == "1"
  1004. if "feature_vc" in request.form:
  1005. feature_dict["call"]["status"] = request.form["feature_vc"] == "1"
  1006. if "feature_ac" in request.form:
  1007. feature_dict["call"]["status"] = request.form["feature_ac"] == "1"
  1008. if "feature_ls" in request.form:
  1009. feature_dict["ls"]["status"] = request.form["feature_ls"] == "1"
  1010. if "feature_nc" in request.form:
  1011. feature_dict["nc"]["status"] = request.form["feature_nc"] == "1"
  1012. if "feature_sms" in request.form:
  1013. feature_dict["sms"]["status"] = request.form["feature_sms"] == "1"
  1014. if "feature_email" in request.form:
  1015. feature_dict["email"]["status"] = request.form["feature_email"] == "1"
  1016. if "feature_settings" in request.form:
  1017. feature_dict["settings"]["status"] = request.form["feature_settings"] == "1"
  1018. if "security_malware" in request.form:
  1019. security_dict["malware"] = request.form["security_malware"] == "1"
  1020. if "security_clone" in request.form:
  1021. security_dict["clone"] = request.form["security_clone"] == "1"
  1022. if "security_emulator" in request.form:
  1023. security_dict["emulator"] = request.form["security_emulator"] == "1"
  1024. if "security_debug" in request.form:
  1025. security_dict["debug"] = request.form["security_debug"] == "1"
  1026. if "security_sim_swap" in request.form:
  1027. security_dict["sim_swap"] = request.form["security_sim_swap"] == "1"
  1028. if "security_capture" in request.form:
  1029. security_dict["capture"] = request.form["security_capture"] == "1"
  1030. if "security_call_forwarding" in request.form:
  1031. security_dict["call_forwarding"] = request.form["security_call_forwarding"] == "1"
  1032. if "security_secure_folder" in request.form:
  1033. security_dict["secure_folder"] = request.form["security_secure_folder"] == "1"
  1034. if "show_security" in request.form:
  1035. security_dict["show_security"] = request.form["show_security"] == "1"
  1036. else:
  1037. security_dict["show_security"] = (security_dict["malware"] or security_dict["clone"]
  1038. or security_dict["emulator"] or security_dict["debug"]
  1039. or security_dict["sim_swap"] or security_dict["capture"]
  1040. or security_dict["call_forwarding"]
  1041. or security_dict["secure_folder"])
  1042. if "platform" in request.form:
  1043. platform = request.form["platform"]
  1044. except BaseException as e:
  1045. vprint(traceback.format_exc())
  1046. return {"status": "1", "message": "Parameter mismatch\n{}\n".format(str(e))}, 400
  1047. try:
  1048. uu_id = str(uuid.uuid4())
  1049. path_dest = create_folder(platform, uu_id)
  1050. change(platform, path_dest, feature_dict, security_dict)
  1051. return deliver_zip(path_dest, uu_id)
  1052. except BaseException as e:
  1053. vprint(traceback.format_exc())
  1054. return {"status": "2", "message": "Process failure\n{}\n".format(str(e))}, 200
  1055. else:
  1056. if 'e' in request.args:
  1057. return request.args['e']
  1058. return "Hello World!"
  1059. if __name__ == '__main__':
  1060. app.run(host='0.0.0.0', port=8056, debug=app.verbose, ssl_context=app.ssl)