main.py 63 KB

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