export.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "export.h"
  31. #include "core/io/image_loader.h"
  32. #include "core/io/json.h"
  33. #include "core/io/stream_peer_ssl.h"
  34. #include "core/io/tcp_server.h"
  35. #include "core/io/zip_io.h"
  36. #include "editor/editor_export.h"
  37. #include "editor/editor_node.h"
  38. #include "main/splash.gen.h"
  39. #include "platform/javascript/logo.gen.h"
  40. #include "platform/javascript/run_icon.gen.h"
  41. class EditorHTTPServer : public Reference {
  42. private:
  43. Ref<TCP_Server> server;
  44. Map<String, String> mimes;
  45. Ref<StreamPeerTCP> tcp;
  46. Ref<StreamPeerSSL> ssl;
  47. Ref<StreamPeer> peer;
  48. Ref<CryptoKey> key;
  49. Ref<X509Certificate> cert;
  50. bool use_ssl = false;
  51. uint64_t time = 0;
  52. uint8_t req_buf[4096];
  53. int req_pos = 0;
  54. void _clear_client() {
  55. peer = Ref<StreamPeer>();
  56. ssl = Ref<StreamPeerSSL>();
  57. tcp = Ref<StreamPeerTCP>();
  58. memset(req_buf, 0, sizeof(req_buf));
  59. time = 0;
  60. req_pos = 0;
  61. }
  62. void _set_internal_certs(Ref<Crypto> p_crypto) {
  63. const String cache_path = EditorSettings::get_singleton()->get_cache_dir();
  64. const String key_path = cache_path.plus_file("html5_server.key");
  65. const String crt_path = cache_path.plus_file("html5_server.crt");
  66. bool regen = !FileAccess::exists(key_path) || !FileAccess::exists(crt_path);
  67. if (!regen) {
  68. key = Ref<CryptoKey>(CryptoKey::create());
  69. cert = Ref<X509Certificate>(X509Certificate::create());
  70. if (key->load(key_path) != OK || cert->load(crt_path) != OK) {
  71. regen = true;
  72. }
  73. }
  74. if (regen) {
  75. key = p_crypto->generate_rsa(2048);
  76. key->save(key_path);
  77. cert = p_crypto->generate_self_signed_certificate(key, "CN=godot-debug.local,O=A Game Dev,C=XXA", "20140101000000", "20340101000000");
  78. cert->save(crt_path);
  79. }
  80. }
  81. public:
  82. EditorHTTPServer() {
  83. mimes["html"] = "text/html";
  84. mimes["js"] = "application/javascript";
  85. mimes["json"] = "application/json";
  86. mimes["pck"] = "application/octet-stream";
  87. mimes["png"] = "image/png";
  88. mimes["svg"] = "image/svg";
  89. mimes["wasm"] = "application/wasm";
  90. server.instance();
  91. stop();
  92. }
  93. void stop() {
  94. server->stop();
  95. _clear_client();
  96. }
  97. Error listen(int p_port, IP_Address p_address, bool p_use_ssl, String p_ssl_key, String p_ssl_cert) {
  98. use_ssl = p_use_ssl;
  99. if (use_ssl) {
  100. Ref<Crypto> crypto = Crypto::create();
  101. if (crypto.is_null()) {
  102. return ERR_UNAVAILABLE;
  103. }
  104. if (!p_ssl_key.empty() && !p_ssl_cert.empty()) {
  105. key = Ref<CryptoKey>(CryptoKey::create());
  106. Error err = key->load(p_ssl_key);
  107. ERR_FAIL_COND_V(err != OK, err);
  108. cert = Ref<X509Certificate>(X509Certificate::create());
  109. err = cert->load(p_ssl_cert);
  110. ERR_FAIL_COND_V(err != OK, err);
  111. } else {
  112. _set_internal_certs(crypto);
  113. }
  114. }
  115. return server->listen(p_port, p_address);
  116. }
  117. bool is_listening() const {
  118. return server->is_listening();
  119. }
  120. void _send_response() {
  121. Vector<String> psa = String((char *)req_buf).split("\r\n");
  122. int len = psa.size();
  123. ERR_FAIL_COND_MSG(len < 4, "Not enough response headers, got: " + itos(len) + ", expected >= 4.");
  124. Vector<String> req = psa[0].split(" ", false);
  125. ERR_FAIL_COND_MSG(req.size() < 2, "Invalid protocol or status code.");
  126. // Wrong protocol
  127. ERR_FAIL_COND_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", "Invalid method or HTTP version.");
  128. const int query_index = req[1].find_char('?');
  129. const String path = (query_index == -1) ? req[1] : req[1].substr(0, query_index);
  130. const String req_file = path.get_file();
  131. const String req_ext = path.get_extension();
  132. const String cache_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("web");
  133. const String filepath = cache_path.plus_file(req_file);
  134. if (!mimes.has(req_ext) || !FileAccess::exists(filepath)) {
  135. String s = "HTTP/1.1 404 Not Found\r\n";
  136. s += "Connection: Close\r\n";
  137. s += "\r\n";
  138. CharString cs = s.utf8();
  139. peer->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
  140. return;
  141. }
  142. const String ctype = mimes[req_ext];
  143. FileAccess *f = FileAccess::open(filepath, FileAccess::READ);
  144. ERR_FAIL_COND(!f);
  145. String s = "HTTP/1.1 200 OK\r\n";
  146. s += "Connection: Close\r\n";
  147. s += "Content-Type: " + ctype + "\r\n";
  148. s += "Access-Control-Allow-Origin: *\r\n";
  149. s += "Cross-Origin-Opener-Policy: same-origin\r\n";
  150. s += "Cross-Origin-Embedder-Policy: require-corp\r\n";
  151. s += "Cache-Control: no-store, max-age=0\r\n";
  152. s += "\r\n";
  153. CharString cs = s.utf8();
  154. Error err = peer->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
  155. if (err != OK) {
  156. memdelete(f);
  157. ERR_FAIL();
  158. }
  159. while (true) {
  160. uint8_t bytes[4096];
  161. uint64_t read = f->get_buffer(bytes, 4096);
  162. if (read == 0) {
  163. break;
  164. }
  165. err = peer->put_data(bytes, read);
  166. if (err != OK) {
  167. memdelete(f);
  168. ERR_FAIL();
  169. }
  170. }
  171. memdelete(f);
  172. }
  173. void poll() {
  174. if (!server->is_listening()) {
  175. return;
  176. }
  177. if (tcp.is_null()) {
  178. if (!server->is_connection_available()) {
  179. return;
  180. }
  181. tcp = server->take_connection();
  182. peer = tcp;
  183. time = OS::get_singleton()->get_ticks_usec();
  184. }
  185. if (OS::get_singleton()->get_ticks_usec() - time > 1000000) {
  186. _clear_client();
  187. return;
  188. }
  189. if (tcp->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
  190. return;
  191. }
  192. if (use_ssl) {
  193. if (ssl.is_null()) {
  194. ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create());
  195. peer = ssl;
  196. ssl->set_blocking_handshake_enabled(false);
  197. if (ssl->accept_stream(tcp, key, cert) != OK) {
  198. _clear_client();
  199. return;
  200. }
  201. }
  202. ssl->poll();
  203. if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) {
  204. // Still handshaking, keep waiting.
  205. return;
  206. }
  207. if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
  208. _clear_client();
  209. return;
  210. }
  211. }
  212. while (true) {
  213. char *r = (char *)req_buf;
  214. int l = req_pos - 1;
  215. if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') {
  216. _send_response();
  217. _clear_client();
  218. return;
  219. }
  220. int read = 0;
  221. ERR_FAIL_COND(req_pos >= 4096);
  222. Error err = peer->get_partial_data(&req_buf[req_pos], 1, read);
  223. if (err != OK) {
  224. // Got an error
  225. _clear_client();
  226. return;
  227. } else if (read != 1) {
  228. // Busy, wait next poll
  229. return;
  230. }
  231. req_pos += read;
  232. }
  233. }
  234. };
  235. class EditorExportPlatformJavaScript : public EditorExportPlatform {
  236. GDCLASS(EditorExportPlatformJavaScript, EditorExportPlatform);
  237. Ref<ImageTexture> logo;
  238. Ref<ImageTexture> run_icon;
  239. Ref<ImageTexture> stop_icon;
  240. int menu_options = 0;
  241. Ref<EditorHTTPServer> server;
  242. bool server_quit = false;
  243. Mutex server_lock;
  244. Thread server_thread;
  245. enum ExportMode {
  246. EXPORT_MODE_NORMAL = 0,
  247. EXPORT_MODE_THREADS = 1,
  248. EXPORT_MODE_GDNATIVE = 2,
  249. };
  250. String _get_template_name(ExportMode p_mode, bool p_debug) const {
  251. String name = "webassembly";
  252. switch (p_mode) {
  253. case EXPORT_MODE_THREADS:
  254. name += "_threads";
  255. break;
  256. case EXPORT_MODE_GDNATIVE:
  257. name += "_gdnative";
  258. break;
  259. default:
  260. break;
  261. }
  262. if (p_debug) {
  263. name += "_debug.zip";
  264. } else {
  265. name += "_release.zip";
  266. }
  267. return name;
  268. }
  269. Ref<Image> _get_project_icon() const {
  270. Ref<Image> icon;
  271. icon.instance();
  272. const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
  273. if (icon_path.empty() || ImageLoader::load_image(icon_path, icon) != OK) {
  274. return EditorNode::get_singleton()->get_editor_theme()->get_icon("DefaultProjectIcon", "EditorIcons")->get_data();
  275. }
  276. return icon;
  277. }
  278. Ref<Image> _get_project_splash() const {
  279. Ref<Image> splash;
  280. splash.instance();
  281. const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
  282. if (splash_path.empty() || ImageLoader::load_image(splash_path, splash) != OK) {
  283. return Ref<Image>(memnew(Image(boot_splash_png)));
  284. }
  285. return splash;
  286. }
  287. Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);
  288. void _replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template);
  289. void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes);
  290. Error _add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr);
  291. Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);
  292. Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);
  293. static void _server_thread_poll(void *data);
  294. public:
  295. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  296. virtual void get_export_options(List<ExportOption> *r_options);
  297. virtual String get_name() const;
  298. virtual String get_os_name() const;
  299. virtual Ref<Texture> get_logo() const;
  300. virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  301. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
  302. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  303. virtual bool poll_export();
  304. virtual int get_options_count() const;
  305. virtual String get_option_label(int p_index) const { return p_index ? TTR("Stop HTTP Server") : TTR("Run in Browser"); }
  306. virtual String get_option_tooltip(int p_index) const { return p_index ? TTR("Stop HTTP Server") : TTR("Run exported HTML in the system's default browser."); }
  307. virtual Ref<ImageTexture> get_option_icon(int p_index) const;
  308. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags);
  309. virtual Ref<Texture> get_run_icon() const;
  310. virtual void get_platform_features(List<String> *r_features) {
  311. r_features->push_back("web");
  312. r_features->push_back(get_os_name());
  313. }
  314. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
  315. }
  316. EditorExportPlatformJavaScript();
  317. ~EditorExportPlatformJavaScript();
  318. };
  319. Error EditorExportPlatformJavaScript::_extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa) {
  320. FileAccess *src_f = nullptr;
  321. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  322. unzFile pkg = unzOpen2(p_template.utf8().get_data(), &io);
  323. if (!pkg) {
  324. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not open template for export: \"%s\"."), p_template));
  325. return ERR_FILE_NOT_FOUND;
  326. }
  327. if (unzGoToFirstFile(pkg) != UNZ_OK) {
  328. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Invalid export template: \"%s\"."), p_template));
  329. unzClose(pkg);
  330. return ERR_FILE_CORRUPT;
  331. }
  332. do {
  333. //get filename
  334. unz_file_info info;
  335. char fname[16384];
  336. unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
  337. String file = String::utf8(fname);
  338. // Skip folders.
  339. if (file.ends_with("/")) {
  340. continue;
  341. }
  342. // Skip service worker and offline page if not exporting pwa.
  343. if (!pwa && (file == "godot.service.worker.js" || file == "godot.offline.html")) {
  344. continue;
  345. }
  346. Vector<uint8_t> data;
  347. data.resize(info.uncompressed_size);
  348. //read
  349. unzOpenCurrentFile(pkg);
  350. unzReadCurrentFile(pkg, data.ptrw(), data.size());
  351. unzCloseCurrentFile(pkg);
  352. //write
  353. String dst = p_dir.plus_file(file.replace("godot", p_name));
  354. FileAccess *f = FileAccess::open(dst, FileAccess::WRITE);
  355. if (!f) {
  356. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not write file: \"%s\"."), dst));
  357. unzClose(pkg);
  358. return ERR_FILE_CANT_WRITE;
  359. }
  360. f->store_buffer(data.ptr(), data.size());
  361. memdelete(f);
  362. } while (unzGoToNextFile(pkg) == UNZ_OK);
  363. unzClose(pkg);
  364. return OK;
  365. }
  366. Error EditorExportPlatformJavaScript::_write_or_error(const uint8_t *p_content, int p_size, String p_path) {
  367. FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE);
  368. if (!f) {
  369. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), p_path));
  370. return ERR_FILE_CANT_WRITE;
  371. }
  372. f->store_buffer(p_content, p_size);
  373. memdelete(f);
  374. return OK;
  375. }
  376. void EditorExportPlatformJavaScript::_replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template) {
  377. String str_template = String::utf8(reinterpret_cast<const char *>(r_template.ptr()), r_template.size());
  378. String out;
  379. Vector<String> lines = str_template.split("\n");
  380. for (int i = 0; i < lines.size(); i++) {
  381. String current_line = lines[i];
  382. for (Map<String, String>::Element *E = p_replaces.front(); E; E = E->next()) {
  383. current_line = current_line.replace(E->key(), E->get());
  384. }
  385. out += current_line + "\n";
  386. }
  387. CharString cs = out.utf8();
  388. r_template.resize(cs.length());
  389. for (int i = 0; i < cs.length(); i++) {
  390. r_template.write[i] = cs[i];
  391. }
  392. }
  393. void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes) {
  394. // Engine.js config
  395. Dictionary config;
  396. Array libs;
  397. for (int i = 0; i < p_shared_objects.size(); i++) {
  398. libs.push_back(p_shared_objects[i].path.get_file());
  399. }
  400. Vector<String> flags;
  401. gen_export_flags(flags, p_flags & (~DEBUG_FLAG_REMOTE_DEBUG) & (~DEBUG_FLAG_DUMB_CLIENT));
  402. Array args;
  403. for (int i = 0; i < flags.size(); i++) {
  404. args.push_back(flags[i]);
  405. }
  406. config["canvasResizePolicy"] = p_preset->get("html/canvas_resize_policy");
  407. config["experimentalVK"] = p_preset->get("html/experimental_virtual_keyboard");
  408. config["focusCanvas"] = p_preset->get("html/focus_canvas_on_start");
  409. config["gdnativeLibs"] = libs;
  410. config["executable"] = p_name;
  411. config["args"] = args;
  412. config["fileSizes"] = p_file_sizes;
  413. String head_include;
  414. if (p_preset->get("html/export_icon")) {
  415. head_include += "<link id='-gd-engine-icon' rel='icon' type='image/png' href='" + p_name + ".icon.png' />\n";
  416. head_include += "<link rel='apple-touch-icon' href='" + p_name + ".apple-touch-icon.png'/>\n";
  417. }
  418. if (p_preset->get("progressive_web_app/enabled")) {
  419. head_include += "<link rel='manifest' href='" + p_name + ".manifest.json'>\n";
  420. config["serviceWorker"] = p_name + ".service.worker.js";
  421. }
  422. // Replaces HTML string
  423. const String str_config = JSON::print(config);
  424. const String custom_head_include = p_preset->get("html/head_include");
  425. Map<String, String> replaces;
  426. replaces["$GODOT_URL"] = p_name + ".js";
  427. replaces["$GODOT_PROJECT_NAME"] = ProjectSettings::get_singleton()->get_setting("application/config/name");
  428. replaces["$GODOT_HEAD_INCLUDE"] = head_include + custom_head_include;
  429. replaces["$GODOT_CONFIG"] = str_config;
  430. _replace_strings(replaces, p_html);
  431. }
  432. Error EditorExportPlatformJavaScript::_add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr) {
  433. const String name = p_path.get_file().get_basename();
  434. const String icon_name = vformat("%s.%dx%d.png", name, p_size, p_size);
  435. const String icon_dest = p_path.get_base_dir().plus_file(icon_name);
  436. Ref<Image> icon;
  437. if (!p_icon.empty()) {
  438. icon.instance();
  439. const Error err = ImageLoader::load_image(p_icon, icon);
  440. if (err != OK) {
  441. add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not read file: \"%s\"."), p_icon));
  442. return err;
  443. }
  444. if (icon->get_width() != p_size || icon->get_height() != p_size) {
  445. icon->resize(p_size, p_size);
  446. }
  447. } else {
  448. icon = _get_project_icon();
  449. icon->resize(p_size, p_size);
  450. }
  451. const Error err = icon->save_png(icon_dest);
  452. if (err != OK) {
  453. add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not write file: \"%s\"."), icon_dest));
  454. return err;
  455. }
  456. Dictionary icon_dict;
  457. icon_dict["sizes"] = vformat("%dx%d", p_size, p_size);
  458. icon_dict["type"] = "image/png";
  459. icon_dict["src"] = icon_name;
  460. r_arr.push_back(icon_dict);
  461. return err;
  462. }
  463. Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects) {
  464. String proj_name = ProjectSettings::get_singleton()->get_setting("application/config/name");
  465. if (proj_name.empty()) {
  466. proj_name = "Godot Game";
  467. }
  468. // Service worker
  469. const String dir = p_path.get_base_dir();
  470. const String name = p_path.get_file().get_basename();
  471. const ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  472. Map<String, String> replaces;
  473. replaces["@GODOT_VERSION@"] = String::num_int64(OS::get_singleton()->get_unix_time()) + "|" + String::num_int64(OS::get_singleton()->get_ticks_usec());
  474. replaces["@GODOT_NAME@"] = proj_name.substr(0, 16);
  475. replaces["@GODOT_OFFLINE_PAGE@"] = name + ".offline.html";
  476. // Files cached during worker install.
  477. Array cache_files;
  478. cache_files.push_back(name + ".html");
  479. cache_files.push_back(name + ".js");
  480. cache_files.push_back(name + ".offline.html");
  481. if (p_preset->get("html/export_icon")) {
  482. cache_files.push_back(name + ".icon.png");
  483. cache_files.push_back(name + ".apple-touch-icon.png");
  484. }
  485. if (mode == EXPORT_MODE_THREADS) {
  486. cache_files.push_back(name + ".worker.js");
  487. cache_files.push_back(name + ".audio.worklet.js");
  488. }
  489. replaces["@GODOT_CACHE@"] = JSON::print(cache_files);
  490. // Heavy files that are cached on demand.
  491. Array opt_cache_files;
  492. opt_cache_files.push_back(name + ".wasm");
  493. opt_cache_files.push_back(name + ".pck");
  494. if (mode == EXPORT_MODE_GDNATIVE) {
  495. opt_cache_files.push_back(name + ".side.wasm");
  496. for (int i = 0; i < p_shared_objects.size(); i++) {
  497. opt_cache_files.push_back(p_shared_objects[i].path.get_file());
  498. }
  499. }
  500. replaces["@GODOT_OPT_CACHE@"] = JSON::print(opt_cache_files);
  501. const String sw_path = dir.plus_file(name + ".service.worker.js");
  502. Vector<uint8_t> sw;
  503. {
  504. FileAccess *f = FileAccess::open(sw_path, FileAccess::READ);
  505. if (!f) {
  506. add_message(EXPORT_MESSAGE_ERROR, TTR("PWA"), vformat(TTR("Could not read file: \"%s\"."), sw_path));
  507. return ERR_FILE_CANT_READ;
  508. }
  509. sw.resize(f->get_len());
  510. f->get_buffer(sw.ptrw(), sw.size());
  511. memdelete(f);
  512. f = nullptr;
  513. }
  514. _replace_strings(replaces, sw);
  515. Error err = _write_or_error(sw.ptr(), sw.size(), dir.plus_file(name + ".service.worker.js"));
  516. if (err != OK) {
  517. return err;
  518. }
  519. // Custom offline page
  520. const String offline_page = p_preset->get("progressive_web_app/offline_page");
  521. if (!offline_page.empty()) {
  522. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  523. const String offline_dest = dir.plus_file(name + ".offline.html");
  524. err = da->copy(ProjectSettings::get_singleton()->globalize_path(offline_page), offline_dest);
  525. if (err != OK) {
  526. add_message(EXPORT_MESSAGE_ERROR, TTR("PWA"), vformat(TTR("Could not read file: \"%s\"."), offline_dest));
  527. return err;
  528. }
  529. }
  530. // Manifest
  531. const char *modes[4] = { "fullscreen", "standalone", "minimal-ui", "browser" };
  532. const char *orientations[3] = { "any", "landscape", "portrait" };
  533. const int display = CLAMP(int(p_preset->get("progressive_web_app/display")), 0, 4);
  534. const int orientation = CLAMP(int(p_preset->get("progressive_web_app/orientation")), 0, 3);
  535. Dictionary manifest;
  536. manifest["name"] = proj_name;
  537. manifest["start_url"] = "./" + name + ".html";
  538. manifest["display"] = String::utf8(modes[display]);
  539. manifest["orientation"] = String::utf8(orientations[orientation]);
  540. manifest["background_color"] = "#" + p_preset->get("progressive_web_app/background_color").operator Color().to_html(false);
  541. Array icons_arr;
  542. const String icon144_path = p_preset->get("progressive_web_app/icon_144x144");
  543. err = _add_manifest_icon(p_path, icon144_path, 144, icons_arr);
  544. if (err != OK) {
  545. return err;
  546. }
  547. const String icon180_path = p_preset->get("progressive_web_app/icon_180x180");
  548. err = _add_manifest_icon(p_path, icon180_path, 180, icons_arr);
  549. if (err != OK) {
  550. return err;
  551. }
  552. const String icon512_path = p_preset->get("progressive_web_app/icon_512x512");
  553. err = _add_manifest_icon(p_path, icon512_path, 512, icons_arr);
  554. if (err != OK) {
  555. return err;
  556. }
  557. manifest["icons"] = icons_arr;
  558. CharString cs = JSON::print(manifest).utf8();
  559. err = _write_or_error((const uint8_t *)cs.get_data(), cs.length(), dir.plus_file(name + ".manifest.json"));
  560. if (err != OK) {
  561. return err;
  562. }
  563. return OK;
  564. }
  565. void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  566. if (p_preset->get("vram_texture_compression/for_desktop")) {
  567. r_features->push_back("s3tc");
  568. }
  569. if (p_preset->get("vram_texture_compression/for_mobile")) {
  570. String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
  571. if (driver == "GLES2") {
  572. r_features->push_back("etc");
  573. } else if (driver == "GLES3") {
  574. r_features->push_back("etc2");
  575. if (ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2")) {
  576. r_features->push_back("etc");
  577. }
  578. }
  579. }
  580. ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  581. if (mode == EXPORT_MODE_THREADS) {
  582. r_features->push_back("threads");
  583. } else if (mode == EXPORT_MODE_GDNATIVE) {
  584. r_features->push_back("wasm32");
  585. }
  586. }
  587. void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
  588. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  589. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  590. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "variant/export_type", PROPERTY_HINT_ENUM, "Regular,Threads,GDNative"), 0)); // Export type.
  591. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_desktop"), true)); // S3TC
  592. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_mobile"), false)); // ETC or ETC2, depending on renderer
  593. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/export_icon"), true));
  594. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_FILE, "*.html"), ""));
  595. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), ""));
  596. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "html/canvas_resize_policy", PROPERTY_HINT_ENUM, "None,Project,Adaptive"), 2));
  597. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/focus_canvas_on_start"), true));
  598. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/experimental_virtual_keyboard"), false));
  599. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "progressive_web_app/enabled"), false));
  600. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/offline_page", PROPERTY_HINT_FILE, "*.html"), ""));
  601. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/display", PROPERTY_HINT_ENUM, "Fullscreen,Standalone,Minimal Ui,Browser"), 1));
  602. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/orientation", PROPERTY_HINT_ENUM, "Any,Landscape,Portrait"), 0));
  603. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_144x144", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), ""));
  604. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_180x180", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), ""));
  605. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_512x512", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), ""));
  606. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "progressive_web_app/background_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color()));
  607. }
  608. String EditorExportPlatformJavaScript::get_name() const {
  609. return "HTML5";
  610. }
  611. String EditorExportPlatformJavaScript::get_os_name() const {
  612. return "HTML5";
  613. }
  614. Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
  615. return logo;
  616. }
  617. bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  618. String err;
  619. bool valid = false;
  620. ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  621. // Look for export templates (first official, and if defined custom templates).
  622. bool dvalid = exists_export_template(_get_template_name(mode, true), &err);
  623. bool rvalid = exists_export_template(_get_template_name(mode, false), &err);
  624. if (p_preset->get("custom_template/debug") != "") {
  625. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  626. if (!dvalid) {
  627. err += TTR("Custom debug template not found.") + "\n";
  628. }
  629. }
  630. if (p_preset->get("custom_template/release") != "") {
  631. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  632. if (!rvalid) {
  633. err += TTR("Custom release template not found.") + "\n";
  634. }
  635. }
  636. valid = dvalid || rvalid;
  637. r_missing_templates = !valid;
  638. // Validate the rest of the configuration.
  639. if (p_preset->get("vram_texture_compression/for_mobile")) {
  640. String etc_error = test_etc2();
  641. if (etc_error != String()) {
  642. valid = false;
  643. err += etc_error;
  644. }
  645. }
  646. if (!err.empty()) {
  647. r_error = err;
  648. }
  649. return valid;
  650. }
  651. List<String> EditorExportPlatformJavaScript::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  652. List<String> list;
  653. list.push_back("html");
  654. return list;
  655. }
  656. Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  657. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  658. const String custom_debug = p_preset->get("custom_template/debug");
  659. const String custom_release = p_preset->get("custom_template/release");
  660. const String custom_html = p_preset->get("html/custom_html_shell");
  661. const bool export_icon = p_preset->get("html/export_icon");
  662. const bool pwa = p_preset->get("progressive_web_app/enabled");
  663. const String base_dir = p_path.get_base_dir();
  664. const String base_path = p_path.get_basename();
  665. const String base_name = p_path.get_file().get_basename();
  666. // Find the correct template
  667. String template_path = p_debug ? custom_debug : custom_release;
  668. template_path = template_path.strip_edges();
  669. if (template_path == String()) {
  670. ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  671. template_path = find_export_template(_get_template_name(mode, p_debug));
  672. }
  673. if (!DirAccess::exists(base_dir)) {
  674. return ERR_FILE_BAD_PATH;
  675. }
  676. if (template_path != String() && !FileAccess::exists(template_path)) {
  677. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Template file not found: \"%s\"."), template_path));
  678. return ERR_FILE_NOT_FOUND;
  679. }
  680. // Export pck and shared objects
  681. Vector<SharedObject> shared_objects;
  682. String pck_path = base_path + ".pck";
  683. Error error = save_pack(p_preset, pck_path, &shared_objects);
  684. if (error != OK) {
  685. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), pck_path));
  686. return error;
  687. }
  688. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  689. for (int i = 0; i < shared_objects.size(); i++) {
  690. String dst = base_dir.plus_file(shared_objects[i].path.get_file());
  691. error = da->copy(shared_objects[i].path, dst);
  692. if (error != OK) {
  693. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), shared_objects[i].path.get_file()));
  694. memdelete(da);
  695. return error;
  696. }
  697. }
  698. memdelete(da);
  699. da = nullptr;
  700. // Extract templates.
  701. error = _extract_template(template_path, base_dir, base_name, pwa);
  702. if (error) {
  703. return error;
  704. }
  705. // Parse generated file sizes (pck and wasm, to help show a meaningful loading bar).
  706. Dictionary file_sizes;
  707. FileAccess *f = nullptr;
  708. f = FileAccess::open(pck_path, FileAccess::READ);
  709. if (f) {
  710. file_sizes[pck_path.get_file()] = (uint64_t)f->get_len();
  711. memdelete(f);
  712. f = nullptr;
  713. }
  714. f = FileAccess::open(base_path + ".wasm", FileAccess::READ);
  715. if (f) {
  716. file_sizes[base_name + ".wasm"] = (uint64_t)f->get_len();
  717. memdelete(f);
  718. f = nullptr;
  719. }
  720. // Read the HTML shell file (custom or from template).
  721. const String html_path = custom_html.empty() ? base_path + ".html" : custom_html;
  722. Vector<uint8_t> html;
  723. f = FileAccess::open(html_path, FileAccess::READ);
  724. if (!f) {
  725. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not read HTML shell: \"%s\"."), html_path));
  726. return ERR_FILE_CANT_READ;
  727. }
  728. html.resize(f->get_len());
  729. f->get_buffer(html.ptrw(), html.size());
  730. memdelete(f);
  731. f = nullptr;
  732. // Generate HTML file with replaced strings.
  733. _fix_html(html, p_preset, base_name, p_debug, p_flags, shared_objects, file_sizes);
  734. Error err = _write_or_error(html.ptr(), html.size(), p_path);
  735. if (err != OK) {
  736. return err;
  737. }
  738. html.resize(0);
  739. // Export splash (why?)
  740. Ref<Image> splash = _get_project_splash();
  741. const String splash_png_path = base_path + ".png";
  742. if (splash->save_png(splash_png_path) != OK) {
  743. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), splash_png_path));
  744. return ERR_FILE_CANT_WRITE;
  745. }
  746. // Save a favicon that can be accessed without waiting for the project to finish loading.
  747. // This way, the favicon can be displayed immediately when loading the page.
  748. if (export_icon) {
  749. Ref<Image> favicon = _get_project_icon();
  750. const String favicon_png_path = base_path + ".icon.png";
  751. if (favicon->save_png(favicon_png_path) != OK) {
  752. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), favicon_png_path));
  753. return ERR_FILE_CANT_WRITE;
  754. }
  755. favicon->resize(180, 180);
  756. const String apple_icon_png_path = base_path + ".apple-touch-icon.png";
  757. if (favicon->save_png(apple_icon_png_path) != OK) {
  758. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), apple_icon_png_path));
  759. return ERR_FILE_CANT_WRITE;
  760. }
  761. }
  762. // Generate the PWA worker and manifest
  763. if (pwa) {
  764. err = _build_pwa(p_preset, p_path, shared_objects);
  765. if (err != OK) {
  766. return err;
  767. }
  768. }
  769. return OK;
  770. }
  771. bool EditorExportPlatformJavaScript::poll_export() {
  772. Ref<EditorExportPreset> preset;
  773. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  774. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  775. if (ep->is_runnable() && ep->get_platform() == this) {
  776. preset = ep;
  777. break;
  778. }
  779. }
  780. int prev = menu_options;
  781. menu_options = preset.is_valid();
  782. if (server->is_listening()) {
  783. if (menu_options == 0) {
  784. MutexLock lock(server_lock);
  785. server->stop();
  786. } else {
  787. menu_options += 1;
  788. }
  789. }
  790. return menu_options != prev;
  791. }
  792. Ref<ImageTexture> EditorExportPlatformJavaScript::get_option_icon(int p_index) const {
  793. return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
  794. }
  795. int EditorExportPlatformJavaScript::get_options_count() const {
  796. return menu_options;
  797. }
  798. Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
  799. if (p_option == 1) {
  800. MutexLock lock(server_lock);
  801. server->stop();
  802. return OK;
  803. }
  804. const String dest = EditorSettings::get_singleton()->get_cache_dir().plus_file("web");
  805. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  806. if (!da->dir_exists(dest)) {
  807. Error err = da->make_dir_recursive(dest);
  808. if (err != OK) {
  809. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), vformat(TTR("Could not create HTTP server directory: %s."), dest));
  810. return err;
  811. }
  812. }
  813. const String basepath = dest.plus_file("tmp_js_export");
  814. Error err = export_project(p_preset, true, basepath + ".html", p_debug_flags);
  815. if (err != OK) {
  816. // Export generates several files, clean them up on failure.
  817. DirAccess::remove_file_or_error(basepath + ".html");
  818. DirAccess::remove_file_or_error(basepath + ".offline.html");
  819. DirAccess::remove_file_or_error(basepath + ".js");
  820. DirAccess::remove_file_or_error(basepath + ".worker.js");
  821. DirAccess::remove_file_or_error(basepath + ".audio.worklet.js");
  822. DirAccess::remove_file_or_error(basepath + ".service.worker.js");
  823. DirAccess::remove_file_or_error(basepath + ".pck");
  824. DirAccess::remove_file_or_error(basepath + ".png");
  825. DirAccess::remove_file_or_error(basepath + ".side.wasm");
  826. DirAccess::remove_file_or_error(basepath + ".wasm");
  827. DirAccess::remove_file_or_error(basepath + ".icon.png");
  828. DirAccess::remove_file_or_error(basepath + ".apple-touch-icon.png");
  829. return err;
  830. }
  831. const uint16_t bind_port = EDITOR_GET("export/web/http_port");
  832. // Resolve host if needed.
  833. const String bind_host = EDITOR_GET("export/web/http_host");
  834. IP_Address bind_ip;
  835. if (bind_host.is_valid_ip_address()) {
  836. bind_ip = bind_host;
  837. } else {
  838. bind_ip = IP::get_singleton()->resolve_hostname(bind_host);
  839. }
  840. ERR_FAIL_COND_V_MSG(!bind_ip.is_valid(), ERR_INVALID_PARAMETER, "Invalid editor setting 'export/web/http_host': '" + bind_host + "'. Try using '127.0.0.1'.");
  841. const bool use_ssl = EDITOR_GET("export/web/use_ssl");
  842. const String ssl_key = EDITOR_GET("export/web/ssl_key");
  843. const String ssl_cert = EDITOR_GET("export/web/ssl_certificate");
  844. // Restart server.
  845. {
  846. MutexLock lock(server_lock);
  847. server->stop();
  848. err = server->listen(bind_port, bind_ip, use_ssl, ssl_key, ssl_cert);
  849. }
  850. if (err != OK) {
  851. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), vformat(TTR("Error starting HTTP server: %d."), err));
  852. return err;
  853. }
  854. OS::get_singleton()->shell_open(String((use_ssl ? "https://" : "http://") + bind_host + ":" + itos(bind_port) + "/tmp_js_export.html"));
  855. // FIXME: Find out how to clean up export files after running the successfully
  856. // exported game. Might not be trivial.
  857. return OK;
  858. }
  859. Ref<Texture> EditorExportPlatformJavaScript::get_run_icon() const {
  860. return run_icon;
  861. }
  862. void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
  863. EditorExportPlatformJavaScript *ej = (EditorExportPlatformJavaScript *)data;
  864. while (!ej->server_quit) {
  865. OS::get_singleton()->delay_usec(1000);
  866. {
  867. MutexLock lock(ej->server_lock);
  868. ej->server->poll();
  869. }
  870. }
  871. }
  872. EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
  873. server.instance();
  874. server_thread.start(_server_thread_poll, this);
  875. Ref<Image> img = memnew(Image(_javascript_logo));
  876. logo.instance();
  877. logo->create_from_image(img);
  878. img = Ref<Image>(memnew(Image(_javascript_run_icon)));
  879. run_icon.instance();
  880. run_icon->create_from_image(img);
  881. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  882. if (theme.is_valid()) {
  883. stop_icon = theme->get_icon("Stop", "EditorIcons");
  884. } else {
  885. stop_icon.instance();
  886. }
  887. }
  888. EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
  889. server->stop();
  890. server_quit = true;
  891. server_thread.wait_to_finish();
  892. }
  893. void register_javascript_exporter() {
  894. EDITOR_DEF("export/web/http_host", "localhost");
  895. EDITOR_DEF("export/web/http_port", 8060);
  896. EDITOR_DEF("export/web/use_ssl", false);
  897. EDITOR_DEF("export/web/ssl_key", "");
  898. EDITOR_DEF("export/web/ssl_certificate", "");
  899. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "export/web/http_port", PROPERTY_HINT_RANGE, "1,65535,1"));
  900. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/web/ssl_key", PROPERTY_HINT_GLOBAL_FILE, "*.key"));
  901. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/web/ssl_certificate", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem"));
  902. Ref<EditorExportPlatformJavaScript> platform;
  903. platform.instance();
  904. EditorExport::get_singleton()->add_export_platform(platform);
  905. }