export.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "core/io/tcp_server.h"
  31. #include "core/io/zip_io.h"
  32. #include "editor/editor_export.h"
  33. #include "editor/editor_node.h"
  34. #include "main/splash.gen.h"
  35. #include "platform/javascript/logo.gen.h"
  36. #include "platform/javascript/run_icon.gen.h"
  37. #define EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE "webassembly_release.zip"
  38. #define EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG "webassembly_debug.zip"
  39. class EditorHTTPServer : public Reference {
  40. private:
  41. Ref<TCP_Server> server;
  42. Ref<StreamPeerTCP> connection;
  43. uint64_t time;
  44. uint8_t req_buf[4096];
  45. int req_pos;
  46. void _clear_client() {
  47. connection = Ref<StreamPeerTCP>();
  48. memset(req_buf, 0, sizeof(req_buf));
  49. time = 0;
  50. req_pos = 0;
  51. }
  52. public:
  53. EditorHTTPServer() {
  54. server.instance();
  55. stop();
  56. }
  57. void stop() {
  58. server->stop();
  59. _clear_client();
  60. }
  61. Error listen(int p_port, IP_Address p_address) {
  62. return server->listen(p_port, p_address);
  63. }
  64. bool is_listening() const {
  65. return server->is_listening();
  66. }
  67. void _send_response() {
  68. Vector<String> psa = String((char *)req_buf).split("\r\n");
  69. int len = psa.size();
  70. ERR_FAIL_COND_MSG(len < 4, "Not enough response headers, got: " + itos(len) + ", expected >= 4.");
  71. Vector<String> req = psa[0].split(" ", false);
  72. ERR_FAIL_COND_MSG(req.size() < 2, "Invalid protocol or status code.");
  73. // Wrong protocol
  74. ERR_FAIL_COND_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", "Invalid method or HTTP version.");
  75. String filepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export");
  76. String basereq = "/tmp_js_export";
  77. if (req[1] == basereq + ".html") {
  78. filepath += ".html";
  79. } else if (req[1] == basereq + ".js") {
  80. filepath += ".js";
  81. } else if (req[1] == basereq + ".pck") {
  82. filepath += ".pck";
  83. } else if (req[1] == basereq + ".png") {
  84. filepath += ".png";
  85. } else if (req[1] == basereq + ".wasm") {
  86. filepath += ".wasm";
  87. } else {
  88. String s = "HTTP/1.1 404 Not Found\r\n";
  89. s += "Connection: Close\r\n";
  90. s += "\r\n";
  91. CharString cs = s.utf8();
  92. connection->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
  93. return;
  94. }
  95. FileAccess *f = FileAccess::open(filepath, FileAccess::READ);
  96. ERR_FAIL_COND(!f);
  97. String s = "HTTP/1.1 200 OK\r\n";
  98. s += "Connection: Close\r\n";
  99. s += "\r\n";
  100. CharString cs = s.utf8();
  101. Error err = connection->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
  102. ERR_FAIL_COND(err != OK);
  103. while (true) {
  104. uint8_t bytes[4096];
  105. int read = f->get_buffer(bytes, 4096);
  106. if (read < 1) {
  107. break;
  108. }
  109. err = connection->put_data(bytes, read);
  110. ERR_FAIL_COND(err != OK);
  111. }
  112. }
  113. void poll() {
  114. if (!server->is_listening())
  115. return;
  116. if (connection.is_null()) {
  117. if (!server->is_connection_available())
  118. return;
  119. connection = server->take_connection();
  120. time = OS::get_singleton()->get_ticks_usec();
  121. }
  122. if (OS::get_singleton()->get_ticks_usec() - time > 1000000) {
  123. _clear_client();
  124. return;
  125. }
  126. if (connection->get_status() != StreamPeerTCP::STATUS_CONNECTED)
  127. return;
  128. while (true) {
  129. char *r = (char *)req_buf;
  130. int l = req_pos - 1;
  131. if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') {
  132. _send_response();
  133. _clear_client();
  134. return;
  135. }
  136. int read = 0;
  137. ERR_FAIL_COND(req_pos >= 4096);
  138. Error err = connection->get_partial_data(&req_buf[req_pos], 1, read);
  139. if (err != OK) {
  140. // Got an error
  141. _clear_client();
  142. return;
  143. } else if (read != 1) {
  144. // Busy, wait next poll
  145. return;
  146. }
  147. req_pos += read;
  148. }
  149. }
  150. };
  151. class EditorExportPlatformJavaScript : public EditorExportPlatform {
  152. GDCLASS(EditorExportPlatformJavaScript, EditorExportPlatform);
  153. Ref<ImageTexture> logo;
  154. Ref<ImageTexture> run_icon;
  155. Ref<ImageTexture> stop_icon;
  156. int menu_options;
  157. void _fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug);
  158. private:
  159. Ref<EditorHTTPServer> server;
  160. bool server_quit;
  161. Mutex *server_lock;
  162. Thread *server_thread;
  163. static void _server_thread_poll(void *data);
  164. public:
  165. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  166. virtual void get_export_options(List<ExportOption> *r_options);
  167. virtual String get_name() const;
  168. virtual String get_os_name() const;
  169. virtual Ref<Texture> get_logo() const;
  170. virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  171. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
  172. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  173. virtual bool poll_export();
  174. virtual int get_options_count() const;
  175. virtual String get_option_label(int p_index) const { return p_index ? TTR("Stop HTTP Server") : TTR("Run in Browser"); }
  176. 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."); }
  177. virtual Ref<ImageTexture> get_option_icon(int p_index) const;
  178. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags);
  179. virtual Ref<Texture> get_run_icon() const;
  180. virtual void get_platform_features(List<String> *r_features) {
  181. r_features->push_back("web");
  182. r_features->push_back(get_os_name());
  183. }
  184. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
  185. }
  186. EditorExportPlatformJavaScript();
  187. ~EditorExportPlatformJavaScript();
  188. };
  189. void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug) {
  190. String str_template = String::utf8(reinterpret_cast<const char *>(p_html.ptr()), p_html.size());
  191. String str_export;
  192. Vector<String> lines = str_template.split("\n");
  193. for (int i = 0; i < lines.size(); i++) {
  194. String current_line = lines[i];
  195. current_line = current_line.replace("$GODOT_BASENAME", p_name);
  196. current_line = current_line.replace("$GODOT_HEAD_INCLUDE", p_preset->get("html/head_include"));
  197. current_line = current_line.replace("$GODOT_DEBUG_ENABLED", p_debug ? "true" : "false");
  198. str_export += current_line + "\n";
  199. }
  200. CharString cs = str_export.utf8();
  201. p_html.resize(cs.length());
  202. for (int i = 0; i < cs.length(); i++) {
  203. p_html.write[i] = cs[i];
  204. }
  205. }
  206. void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  207. if (p_preset->get("vram_texture_compression/for_desktop")) {
  208. r_features->push_back("s3tc");
  209. }
  210. if (p_preset->get("vram_texture_compression/for_mobile")) {
  211. String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
  212. if (driver == "GLES2") {
  213. r_features->push_back("etc");
  214. } else if (driver == "GLES3") {
  215. r_features->push_back("etc2");
  216. if (ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2")) {
  217. r_features->push_back("etc");
  218. }
  219. }
  220. }
  221. }
  222. void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
  223. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_desktop"), true)); // S3TC
  224. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "vram_texture_compression/for_mobile"), false)); // ETC or ETC2, depending on renderer
  225. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_FILE, "*.html"), ""));
  226. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), ""));
  227. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  228. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  229. }
  230. String EditorExportPlatformJavaScript::get_name() const {
  231. return "HTML5";
  232. }
  233. String EditorExportPlatformJavaScript::get_os_name() const {
  234. return "HTML5";
  235. }
  236. Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
  237. return logo;
  238. }
  239. bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  240. bool valid = false;
  241. String err;
  242. if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE) != "")
  243. valid = true;
  244. else if (find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG) != "")
  245. valid = true;
  246. if (p_preset->get("custom_template/debug") != "") {
  247. if (FileAccess::exists(p_preset->get("custom_template/debug"))) {
  248. valid = true;
  249. } else {
  250. err += TTR("Custom debug template not found.") + "\n";
  251. }
  252. }
  253. if (p_preset->get("custom_template/release") != "") {
  254. if (FileAccess::exists(p_preset->get("custom_template/release"))) {
  255. valid = true;
  256. } else {
  257. err += TTR("Custom release template not found.") + "\n";
  258. }
  259. }
  260. r_missing_templates = !valid;
  261. if (p_preset->get("vram_texture_compression/for_mobile")) {
  262. String etc_error = test_etc2();
  263. if (etc_error != String()) {
  264. valid = false;
  265. err += etc_error;
  266. }
  267. }
  268. if (!err.empty())
  269. r_error = err;
  270. return valid;
  271. }
  272. List<String> EditorExportPlatformJavaScript::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  273. List<String> list;
  274. list.push_back("html");
  275. return list;
  276. }
  277. Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  278. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  279. String custom_debug = p_preset->get("custom_template/debug");
  280. String custom_release = p_preset->get("custom_template/release");
  281. String custom_html = p_preset->get("html/custom_html_shell");
  282. String template_path = p_debug ? custom_debug : custom_release;
  283. template_path = template_path.strip_edges();
  284. if (template_path == String()) {
  285. if (p_debug)
  286. template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG);
  287. else
  288. template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE);
  289. }
  290. if (!DirAccess::exists(p_path.get_base_dir())) {
  291. return ERR_FILE_BAD_PATH;
  292. }
  293. if (template_path != String() && !FileAccess::exists(template_path)) {
  294. EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path);
  295. return ERR_FILE_NOT_FOUND;
  296. }
  297. String pck_path = p_path.get_basename() + ".pck";
  298. Error error = save_pack(p_preset, pck_path);
  299. if (error != OK) {
  300. EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + pck_path);
  301. return error;
  302. }
  303. FileAccess *src_f = NULL;
  304. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  305. unzFile pkg = unzOpen2(template_path.utf8().get_data(), &io);
  306. if (!pkg) {
  307. EditorNode::get_singleton()->show_warning(TTR("Could not open template for export:") + "\n" + template_path);
  308. return ERR_FILE_NOT_FOUND;
  309. }
  310. if (unzGoToFirstFile(pkg) != UNZ_OK) {
  311. EditorNode::get_singleton()->show_warning(TTR("Invalid export template:") + "\n" + template_path);
  312. unzClose(pkg);
  313. return ERR_FILE_CORRUPT;
  314. }
  315. do {
  316. //get filename
  317. unz_file_info info;
  318. char fname[16384];
  319. unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
  320. String file = fname;
  321. Vector<uint8_t> data;
  322. data.resize(info.uncompressed_size);
  323. //read
  324. unzOpenCurrentFile(pkg);
  325. unzReadCurrentFile(pkg, data.ptrw(), data.size());
  326. unzCloseCurrentFile(pkg);
  327. //write
  328. if (file == "godot.html") {
  329. if (!custom_html.empty()) {
  330. continue;
  331. }
  332. _fix_html(data, p_preset, p_path.get_file().get_basename(), p_debug);
  333. file = p_path.get_file();
  334. } else if (file == "godot.js") {
  335. file = p_path.get_file().get_basename() + ".js";
  336. } else if (file == "godot.wasm") {
  337. file = p_path.get_file().get_basename() + ".wasm";
  338. }
  339. String dst = p_path.get_base_dir().plus_file(file);
  340. FileAccess *f = FileAccess::open(dst, FileAccess::WRITE);
  341. if (!f) {
  342. EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + dst);
  343. unzClose(pkg);
  344. return ERR_FILE_CANT_WRITE;
  345. }
  346. f->store_buffer(data.ptr(), data.size());
  347. memdelete(f);
  348. } while (unzGoToNextFile(pkg) == UNZ_OK);
  349. unzClose(pkg);
  350. if (!custom_html.empty()) {
  351. FileAccess *f = FileAccess::open(custom_html, FileAccess::READ);
  352. if (!f) {
  353. EditorNode::get_singleton()->show_warning(TTR("Could not read custom HTML shell:") + "\n" + custom_html);
  354. return ERR_FILE_CANT_READ;
  355. }
  356. Vector<uint8_t> buf;
  357. buf.resize(f->get_len());
  358. f->get_buffer(buf.ptrw(), buf.size());
  359. memdelete(f);
  360. _fix_html(buf, p_preset, p_path.get_file().get_basename(), p_debug);
  361. f = FileAccess::open(p_path, FileAccess::WRITE);
  362. if (!f) {
  363. EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + p_path);
  364. return ERR_FILE_CANT_WRITE;
  365. }
  366. f->store_buffer(buf.ptr(), buf.size());
  367. memdelete(f);
  368. }
  369. Ref<Image> splash;
  370. String splash_path = GLOBAL_GET("application/boot_splash/image");
  371. splash_path = splash_path.strip_edges();
  372. if (!splash_path.empty()) {
  373. splash.instance();
  374. Error err = splash->load(splash_path);
  375. if (err) {
  376. EditorNode::get_singleton()->show_warning(TTR("Could not read boot splash image file:") + "\n" + splash_path + "\n" + TTR("Using default boot splash image."));
  377. splash.unref();
  378. }
  379. }
  380. if (splash.is_null()) {
  381. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  382. }
  383. String png_path = p_path.get_base_dir().plus_file(p_path.get_file().get_basename() + ".png");
  384. if (splash->save_png(png_path) != OK) {
  385. EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + png_path);
  386. return ERR_FILE_CANT_WRITE;
  387. }
  388. return OK;
  389. }
  390. bool EditorExportPlatformJavaScript::poll_export() {
  391. Ref<EditorExportPreset> preset;
  392. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  393. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  394. if (ep->is_runnable() && ep->get_platform() == this) {
  395. preset = ep;
  396. break;
  397. }
  398. }
  399. int prev = menu_options;
  400. menu_options = preset.is_valid();
  401. if (server->is_listening()) {
  402. if (menu_options == 0) {
  403. server_lock->lock();
  404. server->stop();
  405. server_lock->unlock();
  406. } else {
  407. menu_options += 1;
  408. }
  409. }
  410. return menu_options != prev;
  411. }
  412. Ref<ImageTexture> EditorExportPlatformJavaScript::get_option_icon(int p_index) const {
  413. return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
  414. }
  415. int EditorExportPlatformJavaScript::get_options_count() const {
  416. return menu_options;
  417. }
  418. Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
  419. if (p_option == 1) {
  420. server_lock->lock();
  421. server->stop();
  422. server_lock->unlock();
  423. return OK;
  424. }
  425. String basepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export");
  426. String path = basepath + ".html";
  427. Error err = export_project(p_preset, true, path, p_debug_flags);
  428. if (err != OK) {
  429. // Export generates several files, clean them up on failure.
  430. DirAccess::remove_file_or_error(basepath + ".html");
  431. DirAccess::remove_file_or_error(basepath + ".js");
  432. DirAccess::remove_file_or_error(basepath + ".pck");
  433. DirAccess::remove_file_or_error(basepath + ".png");
  434. DirAccess::remove_file_or_error(basepath + ".wasm");
  435. return err;
  436. }
  437. IP_Address bind_ip;
  438. uint16_t bind_port = EDITOR_GET("export/web/http_port");
  439. // Resolve host if needed.
  440. String bind_host = EDITOR_GET("export/web/http_host");
  441. if (bind_host.is_valid_ip_address()) {
  442. bind_ip = bind_host;
  443. } else {
  444. bind_ip = IP::get_singleton()->resolve_hostname(bind_host);
  445. }
  446. 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'.");
  447. // Restart server.
  448. server_lock->lock();
  449. server->stop();
  450. err = server->listen(bind_port, bind_ip);
  451. server_lock->unlock();
  452. ERR_FAIL_COND_V_MSG(err != OK, err, "Unable to start HTTP server.");
  453. OS::get_singleton()->shell_open(String("http://" + bind_host + ":" + itos(bind_port) + "/tmp_js_export.html"));
  454. // FIXME: Find out how to clean up export files after running the successfully
  455. // exported game. Might not be trivial.
  456. return OK;
  457. }
  458. Ref<Texture> EditorExportPlatformJavaScript::get_run_icon() const {
  459. return run_icon;
  460. }
  461. void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
  462. EditorExportPlatformJavaScript *ej = (EditorExportPlatformJavaScript *)data;
  463. while (!ej->server_quit) {
  464. OS::get_singleton()->delay_usec(1000);
  465. ej->server_lock->lock();
  466. ej->server->poll();
  467. ej->server_lock->unlock();
  468. }
  469. }
  470. EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
  471. server.instance();
  472. server_quit = false;
  473. server_lock = Mutex::create();
  474. server_thread = Thread::create(_server_thread_poll, this);
  475. Ref<Image> img = memnew(Image(_javascript_logo));
  476. logo.instance();
  477. logo->create_from_image(img);
  478. img = Ref<Image>(memnew(Image(_javascript_run_icon)));
  479. run_icon.instance();
  480. run_icon->create_from_image(img);
  481. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  482. if (theme.is_valid())
  483. stop_icon = theme->get_icon("Stop", "EditorIcons");
  484. else
  485. stop_icon.instance();
  486. menu_options = 0;
  487. }
  488. EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
  489. server->stop();
  490. server_quit = true;
  491. Thread::wait_to_finish(server_thread);
  492. memdelete(server_lock);
  493. memdelete(server_thread);
  494. }
  495. void register_javascript_exporter() {
  496. EDITOR_DEF("export/web/http_host", "localhost");
  497. EDITOR_DEF("export/web/http_port", 8060);
  498. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "export/web/http_port", PROPERTY_HINT_RANGE, "1,65535,1"));
  499. Ref<EditorExportPlatformJavaScript> platform;
  500. platform.instance();
  501. EditorExport::get_singleton()->add_export_platform(platform);
  502. }