export.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. /**************************************************************************/
  2. /* export.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. EXPORT_MODE_THREADS_GDNATIVE = 3,
  250. };
  251. String _get_template_name(ExportMode p_mode, bool p_debug) const {
  252. String name = "webassembly";
  253. if (p_mode & EXPORT_MODE_GDNATIVE) {
  254. name += "_gdnative";
  255. }
  256. if (p_mode & EXPORT_MODE_THREADS) {
  257. name += "_threads";
  258. }
  259. if (p_debug) {
  260. name += "_debug.zip";
  261. } else {
  262. name += "_release.zip";
  263. }
  264. return name;
  265. }
  266. Ref<Image> _get_project_icon() const {
  267. Ref<Image> icon;
  268. icon.instance();
  269. const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
  270. if (icon_path.empty() || ImageLoader::load_image(icon_path, icon) != OK) {
  271. return EditorNode::get_singleton()->get_editor_theme()->get_icon("DefaultProjectIcon", "EditorIcons")->get_data();
  272. }
  273. return icon;
  274. }
  275. Ref<Image> _get_project_splash() const {
  276. Ref<Image> splash;
  277. splash.instance();
  278. const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
  279. if (splash_path.empty() || ImageLoader::load_image(splash_path, splash) != OK) {
  280. return Ref<Image>(memnew(Image(boot_splash_png)));
  281. }
  282. return splash;
  283. }
  284. Error _extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa);
  285. void _replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template);
  286. 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);
  287. Error _add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr);
  288. Error _build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects);
  289. Error _write_or_error(const uint8_t *p_content, int p_len, String p_path);
  290. static void _server_thread_poll(void *data);
  291. public:
  292. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  293. virtual void get_export_options(List<ExportOption> *r_options);
  294. virtual String get_name() const;
  295. virtual String get_os_name() const;
  296. virtual Ref<Texture> get_logo() const;
  297. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  298. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
  299. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
  300. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  301. virtual bool poll_export();
  302. virtual int get_options_count() const;
  303. virtual String get_option_label(int p_index) const { return p_index ? TTR("Stop HTTP Server") : TTR("Run in Browser"); }
  304. 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."); }
  305. virtual Ref<ImageTexture> get_option_icon(int p_index) const;
  306. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags);
  307. virtual Ref<Texture> get_run_icon() const;
  308. virtual void get_platform_features(List<String> *r_features) {
  309. r_features->push_back("web");
  310. r_features->push_back(get_os_name());
  311. }
  312. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
  313. }
  314. EditorExportPlatformJavaScript();
  315. ~EditorExportPlatformJavaScript();
  316. };
  317. Error EditorExportPlatformJavaScript::_extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa) {
  318. FileAccess *src_f = nullptr;
  319. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  320. unzFile pkg = unzOpen2(p_template.utf8().get_data(), &io);
  321. if (!pkg) {
  322. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not open template for export: \"%s\"."), p_template));
  323. return ERR_FILE_NOT_FOUND;
  324. }
  325. if (unzGoToFirstFile(pkg) != UNZ_OK) {
  326. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Invalid export template: \"%s\"."), p_template));
  327. unzClose(pkg);
  328. return ERR_FILE_CORRUPT;
  329. }
  330. do {
  331. //get filename
  332. unz_file_info info;
  333. char fname[16384];
  334. unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
  335. String file = String::utf8(fname);
  336. // Skip folders.
  337. if (file.ends_with("/")) {
  338. continue;
  339. }
  340. // Skip service worker and offline page if not exporting pwa.
  341. if (!pwa && (file == "godot.service.worker.js" || file == "godot.offline.html")) {
  342. continue;
  343. }
  344. Vector<uint8_t> data;
  345. data.resize(info.uncompressed_size);
  346. //read
  347. unzOpenCurrentFile(pkg);
  348. unzReadCurrentFile(pkg, data.ptrw(), data.size());
  349. unzCloseCurrentFile(pkg);
  350. //write
  351. String dst = p_dir.plus_file(file.replace("godot", p_name));
  352. FileAccess *f = FileAccess::open(dst, FileAccess::WRITE);
  353. if (!f) {
  354. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not write file: \"%s\"."), dst));
  355. unzClose(pkg);
  356. return ERR_FILE_CANT_WRITE;
  357. }
  358. f->store_buffer(data.ptr(), data.size());
  359. memdelete(f);
  360. } while (unzGoToNextFile(pkg) == UNZ_OK);
  361. unzClose(pkg);
  362. return OK;
  363. }
  364. Error EditorExportPlatformJavaScript::_write_or_error(const uint8_t *p_content, int p_size, String p_path) {
  365. FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE);
  366. if (!f) {
  367. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), p_path));
  368. return ERR_FILE_CANT_WRITE;
  369. }
  370. f->store_buffer(p_content, p_size);
  371. memdelete(f);
  372. return OK;
  373. }
  374. void EditorExportPlatformJavaScript::_replace_strings(Map<String, String> p_replaces, Vector<uint8_t> &r_template) {
  375. String str_template = String::utf8(reinterpret_cast<const char *>(r_template.ptr()), r_template.size());
  376. String out;
  377. Vector<String> lines = str_template.split("\n");
  378. for (int i = 0; i < lines.size(); i++) {
  379. String current_line = lines[i];
  380. for (Map<String, String>::Element *E = p_replaces.front(); E; E = E->next()) {
  381. current_line = current_line.replace(E->key(), E->get());
  382. }
  383. out += current_line + "\n";
  384. }
  385. CharString cs = out.utf8();
  386. r_template.resize(cs.length());
  387. for (int i = 0; i < cs.length(); i++) {
  388. r_template.write[i] = cs[i];
  389. }
  390. }
  391. 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) {
  392. // Engine.js config
  393. Dictionary config;
  394. Array libs;
  395. for (int i = 0; i < p_shared_objects.size(); i++) {
  396. libs.push_back(p_shared_objects[i].path.get_file());
  397. }
  398. Vector<String> flags;
  399. gen_export_flags(flags, p_flags & (~DEBUG_FLAG_REMOTE_DEBUG) & (~DEBUG_FLAG_DUMB_CLIENT));
  400. Array args;
  401. for (int i = 0; i < flags.size(); i++) {
  402. args.push_back(flags[i]);
  403. }
  404. config["canvasResizePolicy"] = p_preset->get("html/canvas_resize_policy");
  405. config["experimentalVK"] = p_preset->get("html/experimental_virtual_keyboard");
  406. config["focusCanvas"] = p_preset->get("html/focus_canvas_on_start");
  407. config["gdnativeLibs"] = libs;
  408. config["executable"] = p_name;
  409. config["args"] = args;
  410. config["fileSizes"] = p_file_sizes;
  411. String head_include;
  412. if (p_preset->get("html/export_icon")) {
  413. head_include += "<link id='-gd-engine-icon' rel='icon' type='image/png' href='" + p_name + ".icon.png' />\n";
  414. head_include += "<link rel='apple-touch-icon' href='" + p_name + ".apple-touch-icon.png'/>\n";
  415. }
  416. if (p_preset->get("progressive_web_app/enabled")) {
  417. head_include += "<link rel='manifest' href='" + p_name + ".manifest.json'>\n";
  418. config["serviceWorker"] = p_name + ".service.worker.js";
  419. }
  420. // Replaces HTML string
  421. const String str_config = JSON::print(config);
  422. const String custom_head_include = p_preset->get("html/head_include");
  423. Map<String, String> replaces;
  424. replaces["$GODOT_URL"] = p_name + ".js";
  425. replaces["$GODOT_PROJECT_NAME"] = ProjectSettings::get_singleton()->get_setting("application/config/name");
  426. replaces["$GODOT_HEAD_INCLUDE"] = head_include + custom_head_include;
  427. replaces["$GODOT_CONFIG"] = str_config;
  428. _replace_strings(replaces, p_html);
  429. }
  430. Error EditorExportPlatformJavaScript::_add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr) {
  431. const String name = p_path.get_file().get_basename();
  432. const String icon_name = vformat("%s.%dx%d.png", name, p_size, p_size);
  433. const String icon_dest = p_path.get_base_dir().plus_file(icon_name);
  434. Ref<Image> icon;
  435. if (!p_icon.empty()) {
  436. icon.instance();
  437. const Error err = ImageLoader::load_image(p_icon, icon);
  438. if (err != OK) {
  439. add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not read file: \"%s\"."), p_icon));
  440. return err;
  441. }
  442. if (icon->get_width() != p_size || icon->get_height() != p_size) {
  443. icon->resize(p_size, p_size);
  444. }
  445. } else {
  446. icon = _get_project_icon();
  447. icon->resize(p_size, p_size);
  448. }
  449. const Error err = icon->save_png(icon_dest);
  450. if (err != OK) {
  451. add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not write file: \"%s\"."), icon_dest));
  452. return err;
  453. }
  454. Dictionary icon_dict;
  455. icon_dict["sizes"] = vformat("%dx%d", p_size, p_size);
  456. icon_dict["type"] = "image/png";
  457. icon_dict["src"] = icon_name;
  458. r_arr.push_back(icon_dict);
  459. return err;
  460. }
  461. Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects) {
  462. String proj_name = ProjectSettings::get_singleton()->get_setting("application/config/name");
  463. if (proj_name.empty()) {
  464. proj_name = "Godot Game";
  465. }
  466. // Service worker
  467. const String dir = p_path.get_base_dir();
  468. const String name = p_path.get_file().get_basename();
  469. const ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  470. Map<String, String> replaces;
  471. replaces["@GODOT_VERSION@"] = String::num_int64(OS::get_singleton()->get_unix_time()) + "|" + String::num_int64(OS::get_singleton()->get_ticks_usec());
  472. replaces["@GODOT_NAME@"] = proj_name.substr(0, 16);
  473. replaces["@GODOT_OFFLINE_PAGE@"] = name + ".offline.html";
  474. // Files cached during worker install.
  475. Array cache_files;
  476. cache_files.push_back(name + ".html");
  477. cache_files.push_back(name + ".js");
  478. cache_files.push_back(name + ".offline.html");
  479. if (p_preset->get("html/export_icon")) {
  480. cache_files.push_back(name + ".icon.png");
  481. cache_files.push_back(name + ".apple-touch-icon.png");
  482. }
  483. if (mode & EXPORT_MODE_THREADS) {
  484. cache_files.push_back(name + ".worker.js");
  485. cache_files.push_back(name + ".audio.worklet.js");
  486. }
  487. replaces["@GODOT_CACHE@"] = JSON::print(cache_files);
  488. // Heavy files that are cached on demand.
  489. Array opt_cache_files;
  490. opt_cache_files.push_back(name + ".wasm");
  491. opt_cache_files.push_back(name + ".pck");
  492. if (mode & EXPORT_MODE_GDNATIVE) {
  493. opt_cache_files.push_back(name + ".side.wasm");
  494. for (int i = 0; i < p_shared_objects.size(); i++) {
  495. opt_cache_files.push_back(p_shared_objects[i].path.get_file());
  496. }
  497. }
  498. replaces["@GODOT_OPT_CACHE@"] = JSON::print(opt_cache_files);
  499. const String sw_path = dir.plus_file(name + ".service.worker.js");
  500. Vector<uint8_t> sw;
  501. {
  502. FileAccess *f = FileAccess::open(sw_path, FileAccess::READ);
  503. if (!f) {
  504. add_message(EXPORT_MESSAGE_ERROR, TTR("PWA"), vformat(TTR("Could not read file: \"%s\"."), sw_path));
  505. return ERR_FILE_CANT_READ;
  506. }
  507. sw.resize(f->get_len());
  508. f->get_buffer(sw.ptrw(), sw.size());
  509. memdelete(f);
  510. f = nullptr;
  511. }
  512. _replace_strings(replaces, sw);
  513. Error err = _write_or_error(sw.ptr(), sw.size(), dir.plus_file(name + ".service.worker.js"));
  514. if (err != OK) {
  515. return err;
  516. }
  517. // Custom offline page
  518. const String offline_page = p_preset->get("progressive_web_app/offline_page");
  519. if (!offline_page.empty()) {
  520. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  521. const String offline_dest = dir.plus_file(name + ".offline.html");
  522. err = da->copy(ProjectSettings::get_singleton()->globalize_path(offline_page), offline_dest);
  523. if (err != OK) {
  524. add_message(EXPORT_MESSAGE_ERROR, TTR("PWA"), vformat(TTR("Could not read file: \"%s\"."), offline_dest));
  525. return err;
  526. }
  527. }
  528. // Manifest
  529. const char *modes[4] = { "fullscreen", "standalone", "minimal-ui", "browser" };
  530. const char *orientations[3] = { "any", "landscape", "portrait" };
  531. const int display = CLAMP(int(p_preset->get("progressive_web_app/display")), 0, 4);
  532. const int orientation = CLAMP(int(p_preset->get("progressive_web_app/orientation")), 0, 3);
  533. Dictionary manifest;
  534. manifest["name"] = proj_name;
  535. manifest["start_url"] = "./" + name + ".html";
  536. manifest["display"] = String::utf8(modes[display]);
  537. manifest["orientation"] = String::utf8(orientations[orientation]);
  538. manifest["background_color"] = "#" + p_preset->get("progressive_web_app/background_color").operator Color().to_html(false);
  539. Array icons_arr;
  540. const String icon144_path = p_preset->get("progressive_web_app/icon_144x144");
  541. err = _add_manifest_icon(p_path, icon144_path, 144, icons_arr);
  542. if (err != OK) {
  543. return err;
  544. }
  545. const String icon180_path = p_preset->get("progressive_web_app/icon_180x180");
  546. err = _add_manifest_icon(p_path, icon180_path, 180, icons_arr);
  547. if (err != OK) {
  548. return err;
  549. }
  550. const String icon512_path = p_preset->get("progressive_web_app/icon_512x512");
  551. err = _add_manifest_icon(p_path, icon512_path, 512, icons_arr);
  552. if (err != OK) {
  553. return err;
  554. }
  555. manifest["icons"] = icons_arr;
  556. CharString cs = JSON::print(manifest).utf8();
  557. err = _write_or_error((const uint8_t *)cs.get_data(), cs.length(), dir.plus_file(name + ".manifest.json"));
  558. if (err != OK) {
  559. return err;
  560. }
  561. return OK;
  562. }
  563. void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  564. if (p_preset->get("vram_texture_compression/for_desktop")) {
  565. r_features->push_back("s3tc");
  566. }
  567. if (p_preset->get("vram_texture_compression/for_mobile")) {
  568. String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
  569. if (driver == "GLES2") {
  570. r_features->push_back("etc");
  571. } else if (driver == "GLES3") {
  572. r_features->push_back("etc2");
  573. if (ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2")) {
  574. r_features->push_back("etc");
  575. }
  576. }
  577. }
  578. ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  579. if (mode & EXPORT_MODE_THREADS) {
  580. r_features->push_back("threads");
  581. }
  582. if (mode & EXPORT_MODE_GDNATIVE) {
  583. r_features->push_back("wasm32");
  584. }
  585. }
  586. void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
  587. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  588. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  589. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "variant/export_type", PROPERTY_HINT_ENUM, "Regular,Threads,GDNative"), 0)); // Export type.
  590. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_desktop"), true)); // S3TC
  591. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_mobile"), false)); // ETC or ETC2, depending on renderer
  592. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/export_icon"), true));
  593. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_FILE, "*.html"), ""));
  594. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), ""));
  595. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "html/canvas_resize_policy", PROPERTY_HINT_ENUM, "None,Project,Adaptive"), 2));
  596. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/focus_canvas_on_start"), true));
  597. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "html/experimental_virtual_keyboard"), false));
  598. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "progressive_web_app/enabled"), false));
  599. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/offline_page", PROPERTY_HINT_FILE, "*.html"), ""));
  600. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/display", PROPERTY_HINT_ENUM, "Fullscreen,Standalone,Minimal Ui,Browser"), 1));
  601. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "progressive_web_app/orientation", PROPERTY_HINT_ENUM, "Any,Landscape,Portrait"), 0));
  602. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_144x144", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), ""));
  603. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_180x180", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), ""));
  604. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "progressive_web_app/icon_512x512", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), ""));
  605. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "progressive_web_app/background_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color()));
  606. }
  607. String EditorExportPlatformJavaScript::get_name() const {
  608. return "HTML5";
  609. }
  610. String EditorExportPlatformJavaScript::get_os_name() const {
  611. return "HTML5";
  612. }
  613. Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
  614. return logo;
  615. }
  616. bool EditorExportPlatformJavaScript::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  617. String err;
  618. bool valid = false;
  619. ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  620. // Look for export templates (first official, and if defined custom templates).
  621. bool dvalid = exists_export_template(_get_template_name(mode, true), &err);
  622. bool rvalid = exists_export_template(_get_template_name(mode, false), &err);
  623. if (p_preset->get("custom_template/debug") != "") {
  624. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  625. if (!dvalid) {
  626. err += TTR("Custom debug template not found.") + "\n";
  627. }
  628. }
  629. if (p_preset->get("custom_template/release") != "") {
  630. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  631. if (!rvalid) {
  632. err += TTR("Custom release template not found.") + "\n";
  633. }
  634. }
  635. valid = dvalid || rvalid;
  636. r_missing_templates = !valid;
  637. if (!err.empty()) {
  638. r_error = err;
  639. }
  640. return valid;
  641. }
  642. bool EditorExportPlatformJavaScript::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  643. String err;
  644. bool valid = true;
  645. // Validate the project configuration.
  646. if (p_preset->get("vram_texture_compression/for_mobile")) {
  647. String etc_error = test_etc2();
  648. if (etc_error != String()) {
  649. valid = false;
  650. err += etc_error;
  651. }
  652. }
  653. if (!err.empty()) {
  654. r_error = err;
  655. }
  656. return valid;
  657. }
  658. List<String> EditorExportPlatformJavaScript::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  659. List<String> list;
  660. list.push_back("html");
  661. return list;
  662. }
  663. Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  664. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  665. const String custom_debug = p_preset->get("custom_template/debug");
  666. const String custom_release = p_preset->get("custom_template/release");
  667. const String custom_html = p_preset->get("html/custom_html_shell");
  668. const bool export_icon = p_preset->get("html/export_icon");
  669. const bool pwa = p_preset->get("progressive_web_app/enabled");
  670. const String base_dir = p_path.get_base_dir();
  671. const String base_path = p_path.get_basename();
  672. const String base_name = p_path.get_file().get_basename();
  673. // Find the correct template
  674. String template_path = p_debug ? custom_debug : custom_release;
  675. template_path = template_path.strip_edges();
  676. if (template_path == String()) {
  677. ExportMode mode = (ExportMode)(int)p_preset->get("variant/export_type");
  678. template_path = find_export_template(_get_template_name(mode, p_debug));
  679. }
  680. if (!DirAccess::exists(base_dir)) {
  681. return ERR_FILE_BAD_PATH;
  682. }
  683. if (template_path != String() && !FileAccess::exists(template_path)) {
  684. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Template file not found: \"%s\"."), template_path));
  685. return ERR_FILE_NOT_FOUND;
  686. }
  687. // Export pck and shared objects
  688. Vector<SharedObject> shared_objects;
  689. String pck_path = base_path + ".pck";
  690. Error error = save_pack(p_preset, pck_path, &shared_objects);
  691. if (error != OK) {
  692. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), pck_path));
  693. return error;
  694. }
  695. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  696. for (int i = 0; i < shared_objects.size(); i++) {
  697. String dst = base_dir.plus_file(shared_objects[i].path.get_file());
  698. error = da->copy(shared_objects[i].path, dst);
  699. if (error != OK) {
  700. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), shared_objects[i].path.get_file()));
  701. memdelete(da);
  702. return error;
  703. }
  704. }
  705. memdelete(da);
  706. da = nullptr;
  707. // Extract templates.
  708. error = _extract_template(template_path, base_dir, base_name, pwa);
  709. if (error) {
  710. return error;
  711. }
  712. // Parse generated file sizes (pck and wasm, to help show a meaningful loading bar).
  713. Dictionary file_sizes;
  714. FileAccess *f = nullptr;
  715. f = FileAccess::open(pck_path, FileAccess::READ);
  716. if (f) {
  717. file_sizes[pck_path.get_file()] = (uint64_t)f->get_len();
  718. memdelete(f);
  719. f = nullptr;
  720. }
  721. f = FileAccess::open(base_path + ".wasm", FileAccess::READ);
  722. if (f) {
  723. file_sizes[base_name + ".wasm"] = (uint64_t)f->get_len();
  724. memdelete(f);
  725. f = nullptr;
  726. }
  727. // Read the HTML shell file (custom or from template).
  728. const String html_path = custom_html.empty() ? base_path + ".html" : custom_html;
  729. Vector<uint8_t> html;
  730. f = FileAccess::open(html_path, FileAccess::READ);
  731. if (!f) {
  732. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not read HTML shell: \"%s\"."), html_path));
  733. return ERR_FILE_CANT_READ;
  734. }
  735. html.resize(f->get_len());
  736. f->get_buffer(html.ptrw(), html.size());
  737. memdelete(f);
  738. f = nullptr;
  739. // Generate HTML file with replaced strings.
  740. _fix_html(html, p_preset, base_name, p_debug, p_flags, shared_objects, file_sizes);
  741. Error err = _write_or_error(html.ptr(), html.size(), p_path);
  742. if (err != OK) {
  743. return err;
  744. }
  745. html.resize(0);
  746. // Export splash (why?)
  747. Ref<Image> splash = _get_project_splash();
  748. const String splash_png_path = base_path + ".png";
  749. if (splash->save_png(splash_png_path) != OK) {
  750. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), splash_png_path));
  751. return ERR_FILE_CANT_WRITE;
  752. }
  753. // Save a favicon that can be accessed without waiting for the project to finish loading.
  754. // This way, the favicon can be displayed immediately when loading the page.
  755. if (export_icon) {
  756. Ref<Image> favicon = _get_project_icon();
  757. const String favicon_png_path = base_path + ".icon.png";
  758. if (favicon->save_png(favicon_png_path) != OK) {
  759. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), favicon_png_path));
  760. return ERR_FILE_CANT_WRITE;
  761. }
  762. favicon->resize(180, 180);
  763. const String apple_icon_png_path = base_path + ".apple-touch-icon.png";
  764. if (favicon->save_png(apple_icon_png_path) != OK) {
  765. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), apple_icon_png_path));
  766. return ERR_FILE_CANT_WRITE;
  767. }
  768. }
  769. // Generate the PWA worker and manifest
  770. if (pwa) {
  771. err = _build_pwa(p_preset, p_path, shared_objects);
  772. if (err != OK) {
  773. return err;
  774. }
  775. }
  776. return OK;
  777. }
  778. bool EditorExportPlatformJavaScript::poll_export() {
  779. Ref<EditorExportPreset> preset;
  780. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  781. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  782. if (ep->is_runnable() && ep->get_platform() == this) {
  783. preset = ep;
  784. break;
  785. }
  786. }
  787. int prev = menu_options;
  788. menu_options = preset.is_valid();
  789. if (server->is_listening()) {
  790. if (menu_options == 0) {
  791. MutexLock lock(server_lock);
  792. server->stop();
  793. } else {
  794. menu_options += 1;
  795. }
  796. }
  797. return menu_options != prev;
  798. }
  799. Ref<ImageTexture> EditorExportPlatformJavaScript::get_option_icon(int p_index) const {
  800. return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
  801. }
  802. int EditorExportPlatformJavaScript::get_options_count() const {
  803. return menu_options;
  804. }
  805. Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
  806. if (p_option == 1) {
  807. MutexLock lock(server_lock);
  808. server->stop();
  809. return OK;
  810. }
  811. const String dest = EditorSettings::get_singleton()->get_cache_dir().plus_file("web");
  812. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  813. if (!da->dir_exists(dest)) {
  814. Error err = da->make_dir_recursive(dest);
  815. if (err != OK) {
  816. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), vformat(TTR("Could not create HTTP server directory: %s."), dest));
  817. return err;
  818. }
  819. }
  820. const String basepath = dest.plus_file("tmp_js_export");
  821. Error err = export_project(p_preset, true, basepath + ".html", p_debug_flags);
  822. if (err != OK) {
  823. // Export generates several files, clean them up on failure.
  824. DirAccess::remove_file_or_error(basepath + ".html");
  825. DirAccess::remove_file_or_error(basepath + ".offline.html");
  826. DirAccess::remove_file_or_error(basepath + ".js");
  827. DirAccess::remove_file_or_error(basepath + ".worker.js");
  828. DirAccess::remove_file_or_error(basepath + ".audio.worklet.js");
  829. DirAccess::remove_file_or_error(basepath + ".service.worker.js");
  830. DirAccess::remove_file_or_error(basepath + ".pck");
  831. DirAccess::remove_file_or_error(basepath + ".png");
  832. DirAccess::remove_file_or_error(basepath + ".side.wasm");
  833. DirAccess::remove_file_or_error(basepath + ".wasm");
  834. DirAccess::remove_file_or_error(basepath + ".icon.png");
  835. DirAccess::remove_file_or_error(basepath + ".apple-touch-icon.png");
  836. return err;
  837. }
  838. const uint16_t bind_port = EDITOR_GET("export/web/http_port");
  839. // Resolve host if needed.
  840. const String bind_host = EDITOR_GET("export/web/http_host");
  841. IP_Address bind_ip;
  842. if (bind_host.is_valid_ip_address()) {
  843. bind_ip = bind_host;
  844. } else {
  845. bind_ip = IP::get_singleton()->resolve_hostname(bind_host);
  846. }
  847. 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'.");
  848. const bool use_ssl = EDITOR_GET("export/web/use_ssl");
  849. const String ssl_key = EDITOR_GET("export/web/ssl_key");
  850. const String ssl_cert = EDITOR_GET("export/web/ssl_certificate");
  851. // Restart server.
  852. {
  853. MutexLock lock(server_lock);
  854. server->stop();
  855. err = server->listen(bind_port, bind_ip, use_ssl, ssl_key, ssl_cert);
  856. }
  857. if (err != OK) {
  858. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), vformat(TTR("Error starting HTTP server: %d."), err));
  859. return err;
  860. }
  861. OS::get_singleton()->shell_open(String((use_ssl ? "https://" : "http://") + bind_host + ":" + itos(bind_port) + "/tmp_js_export.html"));
  862. // FIXME: Find out how to clean up export files after running the successfully
  863. // exported game. Might not be trivial.
  864. return OK;
  865. }
  866. Ref<Texture> EditorExportPlatformJavaScript::get_run_icon() const {
  867. return run_icon;
  868. }
  869. void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
  870. EditorExportPlatformJavaScript *ej = (EditorExportPlatformJavaScript *)data;
  871. while (!ej->server_quit) {
  872. OS::get_singleton()->delay_usec(1000);
  873. {
  874. MutexLock lock(ej->server_lock);
  875. ej->server->poll();
  876. }
  877. }
  878. }
  879. EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
  880. server.instance();
  881. server_thread.start(_server_thread_poll, this);
  882. Ref<Image> img = memnew(Image(_javascript_logo));
  883. logo.instance();
  884. logo->create_from_image(img);
  885. img = Ref<Image>(memnew(Image(_javascript_run_icon)));
  886. run_icon.instance();
  887. run_icon->create_from_image(img);
  888. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  889. if (theme.is_valid()) {
  890. stop_icon = theme->get_icon("Stop", "EditorIcons");
  891. } else {
  892. stop_icon.instance();
  893. }
  894. }
  895. EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
  896. server->stop();
  897. server_quit = true;
  898. server_thread.wait_to_finish();
  899. }
  900. void register_javascript_exporter() {
  901. #ifndef ANDROID_ENABLED
  902. EDITOR_DEF("export/web/http_host", "localhost");
  903. EDITOR_DEF("export/web/http_port", 8060);
  904. EDITOR_DEF("export/web/use_ssl", false);
  905. EDITOR_DEF("export/web/ssl_key", "");
  906. EDITOR_DEF("export/web/ssl_certificate", "");
  907. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "export/web/http_port", PROPERTY_HINT_RANGE, "1,65535,1"));
  908. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/web/ssl_key", PROPERTY_HINT_GLOBAL_FILE, "*.key"));
  909. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/web/ssl_certificate", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem"));
  910. #endif
  911. Ref<EditorExportPlatformJavaScript> platform;
  912. platform.instance();
  913. EditorExport::get_singleton()->add_export_platform(platform);
  914. }