diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp index 78cd3da5b3..3e7ab5e52b 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.cpp @@ -517,7 +517,7 @@ namespace se { return false; } - void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port) + void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait) { //IDEA: } diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp index dc11691541..7f811e637d 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/ScriptEngine.hpp @@ -239,8 +239,9 @@ namespace se { * @brief Enables JavaScript debugger * @param[in] serverAddr The address of debugger server. * @param[in] port The port of debugger server will use. + * @param[in] isWait Whether wait debugger attach when loading. */ - void enableDebugger(const std::string& serverAddr, uint32_t port); + void enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait = false); /** * @brief Tests whether JavaScript debugger is enabled diff --git a/native/cocos/scripting/js-bindings/jswrapper/config.hpp b/native/cocos/scripting/js-bindings/jswrapper/config.hpp index 5db11c33c6..bff4a64d79 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/config.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/config.hpp @@ -31,8 +31,6 @@ #define SCRIPT_ENGINE_CHAKRACORE 4 #define SCRIPT_ENGINE_V8_ON_MAC 1 // default using v8 on macOS, set 0 to disable -#define V8_DEBUG_WAIT_FOR_CONNECT 0 // the program will be hung up until debug attach if you enable it, set 1 to enable -#define JSB_DEFAULT_DEBUGGER_PORT 5086 #if defined(__APPLE__) #include diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.hpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.hpp index 1c286d4bf9..7799b69f3b 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.hpp @@ -239,8 +239,9 @@ namespace se { * @brief Enables JavaScript debugger * @param[in] serverAddr The address of debugger server. * @param[in] port The port of debugger server will use. + * @param[in] isWait Whether wait debugger attach when loading. */ - void enableDebugger(const std::string& serverAddr, uint32_t port); + void enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait = false); /** * @brief Tests whether JavaScript debugger is enabled diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.mm b/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.mm index aa56ac0f1b..db28e6c03e 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.mm +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/ScriptEngine.mm @@ -643,7 +643,7 @@ namespace se { //IDEA: } - void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port) + void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait) { // empty implementation _isDebuggerEnabled = true; diff --git a/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.cpp b/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.cpp index 740a69ab23..0241f7067e 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.cpp @@ -1213,7 +1213,7 @@ namespace se { _exceptionCallback = cb; } - void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port) + void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait) { _debuggerServerAddr = serverAddr; _debuggerServerPort = port; diff --git a/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.hpp b/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.hpp index 2c5bf9ef33..ee6f2287e4 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/sm/ScriptEngine.hpp @@ -236,8 +236,9 @@ namespace se { * @brief Enables JavaScript debugger * @param[in] serverAddr The address of debugger server. * @param[in] port The port of debugger server will use. + * @param[in] isWait Whether wait debugger attach when loading. */ - void enableDebugger(const std::string& serverAddr, uint32_t port); + void enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait = false); /** * @brief Tests whether JavaScript debugger is enabled diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.cpp index add7edfce3..0deb2c845e 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.cpp @@ -562,7 +562,7 @@ namespace se { _env = node::CreateEnvironment(_isolateData, _context.Get(_isolate), 0, nullptr, 0, nullptr); node::DebugOptions options; - options.set_wait_for_connect(V8_DEBUG_WAIT_FOR_CONNECT); + options.set_wait_for_connect(_isWaitForConnect);// the program will be hung up until debug attach if _isWaitForConnect = true options.set_inspector_enabled(true); options.set_port((int)_debuggerServerPort); options.set_host_name(_debuggerServerAddr.c_str()); @@ -722,10 +722,11 @@ namespace se { return _context.Get(_isolate); } - void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port) + void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait) { _debuggerServerAddr = serverAddr; _debuggerServerPort = port; + _isWaitForConnect = isWait; } bool ScriptEngine::isDebuggerEnabled() const diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp b/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp index 3a21f08051..05e8650580 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp @@ -263,9 +263,9 @@ namespace se { /** * @brief Enables JavaScript debugger * @param[in] serverAddr The address of debugger server. - * @param[in] port The port of debugger server will use. + * @param[in] isWait Whether wait debugger attach when loading. */ - void enableDebugger(const std::string& serverAddr, uint32_t port); + void enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait = false); /** * @brief Tests whether JavaScript debugger is enabled @@ -325,6 +325,7 @@ namespace se { std::string _debuggerServerAddr; uint32_t _debuggerServerPort; + bool _isWaitForConnect; uint32_t _vmId; diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp index d7754dda35..6f965466a1 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -171,13 +171,13 @@ void jsb_init_file_operation_delegate() } } -bool jsb_enable_debugger(const std::string& debuggerServerAddr, uint32_t port) +bool jsb_enable_debugger(const std::string& debuggerServerAddr, uint32_t port, bool isWaitForConnect) { if (debuggerServerAddr.empty() || port == 0) return false; auto se = se::ScriptEngine::getInstance(); - se->enableDebugger(debuggerServerAddr.c_str(), port); + se->enableDebugger(debuggerServerAddr.c_str(), port, isWaitForConnect); // For debugger main loop class SimpleRunLoop diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.h b/native/cocos/scripting/js-bindings/manual/jsb_global.h index 59006db34c..75a45aea25 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.h +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.h @@ -39,7 +39,7 @@ extern se::Object* __glObj; bool jsb_register_global_variables(se::Object* global); void jsb_init_file_operation_delegate(); -bool jsb_enable_debugger(const std::string& debuggerServerAddr, uint32_t port); +bool jsb_enable_debugger(const std::string& debuggerServerAddr, uint32_t port, bool isWaitForConnect = false); bool jsb_set_extend_property(const char* ns, const char* clsName); bool jsb_run_script(const std::string& filePath, se::Value* rval = nullptr); bool jsb_run_script_module(const std::string& filePath, se::Value* rval = nullptr); diff --git a/native/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp b/native/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp index 569f884322..715b7a900e 100755 --- a/native/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp +++ b/native/templates/js-template-default/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -66,7 +66,7 @@ bool AppDelegate::applicationDidFinishLaunching() #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) // Enable debugger here - jsb_enable_debugger("0.0.0.0", JSB_DEFAULT_DEBUGGER_PORT); + jsb_enable_debugger("0.0.0.0", 6086, false); #endif se->setExceptionCallback([](const char* location, const char* message, const char* stack){ diff --git a/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp b/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp index 569f884322..715b7a900e 100755 --- a/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp +++ b/native/templates/js-template-link/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -66,7 +66,7 @@ bool AppDelegate::applicationDidFinishLaunching() #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) // Enable debugger here - jsb_enable_debugger("0.0.0.0", JSB_DEFAULT_DEBUGGER_PORT); + jsb_enable_debugger("0.0.0.0", 6086, false); #endif se->setExceptionCallback([](const char* location, const char* message, const char* stack){ diff --git a/native/tools/simulator/config.json b/native/tools/simulator/config.json index 6b6a7d02bc..f864efad26 100644 --- a/native/tools/simulator/config.json +++ b/native/tools/simulator/config.json @@ -1,14 +1,15 @@ { "init_cfg":{ - "isLandscape": true, - "isWindowTop": false, - "name": "Simulator", - "width": 960, - "height": 640, - "entry": "main.js", - "consolePort": 6050, - "uploadPort": 6060, - "debugPort": 5086 + "isLandscape": true, + "isWindowTop": false, + "waitForConnect": false, + "name": "Simulator", + "width": 960, + "height": 640, + "entry": "main.js", + "consolePort": 6050, + "uploadPort": 6060, + "debugPort": 5086 }, "simulator_screen_size": [ { diff --git a/native/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp b/native/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp index ab8b1e8795..d93038e8f8 100755 --- a/native/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp +++ b/native/tools/simulator/frameworks/runtime-src/Classes/ide-support/RuntimeJsImpl.cpp @@ -36,6 +36,7 @@ #include "runtime/ConfigParser.h" // config #include "runtime/Runtime.h" #include "runtime/FileServer.h" +#include "runtime/ConfigParser.h" // js #include "cocos/scripting/js-bindings/jswrapper/SeApi.h" @@ -172,7 +173,8 @@ bool RuntimeJsImpl::initJsEnv() #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) // Enable debugger here - jsb_enable_debugger("127.0.0.1", JSB_DEFAULT_DEBUGGER_PORT); + auto parser = ConfigParser::getInstance(); + jsb_enable_debugger("0.0.0.0", parser->getDebugPort(), parser->isWaitForConnect()); #endif se->setExceptionCallback([](const char* location, const char* message, const char* stack){ diff --git a/native/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp b/native/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp index 5920349d98..e285d42f6a 100755 --- a/native/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp +++ b/native/tools/simulator/libsimulator/lib/ProjectConfig/ProjectConfig.cpp @@ -63,7 +63,7 @@ ProjectConfig::ProjectConfig() , _packagePath("") , _frameSize(960, 640) , _frameScale(1.0f) - , _showConsole(true) + , _showConsole(false) , _loadPrecompiledFramework(false) , _writeDebugLogToFile(false) , _windowOffset(0, 0) diff --git a/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.cpp b/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.cpp index 7e3b65fbd5..d418d37906 100755 --- a/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.cpp +++ b/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.cpp @@ -124,6 +124,10 @@ void ConfigParser::readConfig(const string &filepath) { _isWindowTop= objectInitView["isWindowTop"].GetBool(); } + if (objectInitView.HasMember("waitForConnect") && objectInitView["waitForConnect"].IsBool()) + { + _isWaitForConnect= objectInitView["waitForConnect"].GetBool(); + } } } if (_docRootjson.HasMember("simulator_screen_size")) @@ -185,6 +189,12 @@ bool ConfigParser::isWindowTop() { return _isWindowTop; } + +bool ConfigParser::isWaitForConnect() +{ + return _isWaitForConnect; +} + void ConfigParser::setConsolePort(int port) { if (port > 0) diff --git a/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.h b/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.h index ca6f4503cf..b132bf0fa7 100755 --- a/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.h +++ b/native/tools/simulator/libsimulator/lib/runtime/ConfigParser.h @@ -60,6 +60,7 @@ public: int getDebugPort(); bool isLanscape(); bool isWindowTop(); + bool isWaitForConnect(); void setEntryFile(const std::string &file); void setInitViewSize(const cocos2d::Size &size); @@ -76,6 +77,7 @@ private: string _entryfile; bool _isLandscape; bool _isWindowTop; + bool _isWaitForConnect; int _consolePort; int _uploadPort; int _debugPort;