Эх сурвалжийг харах

#IQRV #comment [Chromium] 使用另一种方式启动浏览器,解决加载库问题

gifur 3 жил өмнө
parent
commit
21f6cf7664

+ 10 - 7
Module/mod_chromium/CModTools.cpp

@@ -701,7 +701,7 @@ namespace Chromium {
 		if (AdUrlRet.first)
 		{
 			auto strAdCmd = generateAdCmd(AdUrlRet.second);
-			auto openAdRet = openCef(strAdCmd);
+			auto openAdRet = openCef(strAdCmd, false, !(m_UseUOSBrowser == 2));
 			if (Error_Succeed != openAdRet.first)
 				return std::make_pair(false, "open Ad err!");
 			else
@@ -737,7 +737,7 @@ namespace Chromium {
 
 			auto strCmdLine = generateMainCmd(mainUrlRet.second);
 
-			auto openCefRet = openCef(strCmdLine, m_UseUOSBrowser == 0);//with guard
+			auto openCefRet = openCef(strCmdLine, m_UseUOSBrowser == 0, !(m_UseUOSBrowser == 2));//with guard
 			if (Error_Succeed == openCefRet.first) {
                 LogWarn(Severity_Middle, Error_Debug, LOG_EVT_CHROMIUM_OPEN_MAIN_URL,
                         CSimpleStringA::Format("StartChromiumBrowser %s", mainUrlRet.second.c_str()));
@@ -1243,7 +1243,7 @@ namespace Chromium {
 #endif
 	}
 
-	std::pair<ErrorCodeEnum, int> CModTools::openCef(std::string cmdline, bool isGuard)
+	std::pair<ErrorCodeEnum, int> CModTools::openCef(std::string cmdline, bool isGuard, bool usingSystemCmd)
 	{
 		if (isGuard) {
 			//mod_chromium相当于cefclient的守护进程
@@ -1258,11 +1258,14 @@ namespace Chromium {
 				DbgEx("startProcessInJob failed!");
 			return std::make_pair(std::get<0>(startRet) ? Error_Succeed : Error_Unexpect, std::get<1>(startRet));
 #else
-			auto systemStartChromium = [](std::string str) {
-				//system(str.c_str());
-				SystemRunTest(str);
+			auto systemStartChromium = [](std::string str, bool systemCmd) {
+				if (systemCmd) {
+					system(str.c_str());
+				} else {
+                    SystemRunTest(str);
+				}
 			};
-			boost::thread(systemStartChromium, cmdline).detach();
+			boost::thread(systemStartChromium, cmdline, usingSystemCmd).detach();
 #endif
 		}
 		return std::make_pair(Error_Succeed, 0);

+ 1 - 1
Module/mod_chromium/CModTools.h

@@ -81,7 +81,7 @@ namespace Chromium {
 		std::string getAdditionalUOSBrowserSettings(int nBrowswerType, int nMonitorType = 0);
 		std::pair<bool, std::string> GenerateErrPage(ERR_PAGE_REASON errType,
 			std::tuple < std::string, std::string> norParam, std::tuple<std::string, std::string, std::string, DWORD, DWORD> exParam);
-		std::pair<ErrorCodeEnum, int> openCef(std::string cmdline, bool isGuard = false);
+		std::pair<ErrorCodeEnum, int> openCef(std::string cmdline, bool isGuard = false, bool usingSystemCmd = true);
 		void cefClientGuardian(std::string cmdline);
 		std::pair<ErrorCodeEnum, int> openCefByFreerdp(std::string cmdline, bool isGuard = false);
 		void openCefByFreerdpGuardian(std::string cmdline);

+ 16 - 1
Module/mod_chromium/SystemRun.cpp

@@ -21,9 +21,14 @@ void SystemRunTest(const std::string& systemCmd)
 #else
 
     do {
-        char app[MAX_PATH] = { '\0' };
+        char app[2048] = { '\0' };
+        char szldPath[1024] = { '\0' };
+        size_t szldLen = 1023;
         tk_process_t* process = NULL;
         tk_process_option_t option;
+
+        const int ldRet = toolkit_getenv("LD_LIBRARY_PATH", szldPath, &szldLen);
+
         option.exit_cb = NULL;
         option.file = NULL;
         option.flags = 0;
@@ -31,6 +36,13 @@ void SystemRunTest(const std::string& systemCmd)
         sprintf(app, "%s", systemCmd.c_str());
         option.params = app;
 
+        if (ldRet == 0) {
+            Dbg("get library path: %s", szldPath);
+            toolkit_unsetenv("LD_LIBRARY_PATH");
+        } else {
+            Dbg("GetEnv of LD_LIBRARY_PATH failed: %s", toolkit_strerror(ldRet));
+        }
+
         const int res = process_spawn(&option, &process);
         if (0 == res) {
             Dbg("execute {%s} suc pid: %d", app, process->pid);
@@ -38,6 +50,9 @@ void SystemRunTest(const std::string& systemCmd)
         } else {
             Dbg("execute {%s} failed: %d", app, res);
         }
+        if (ldRet == 0) {
+            toolkit_setenv("LD_LIBRARY_PATH", szldPath);
+        }
     } while (false);
 
 #endif