无滞留进程

This commit is contained in:
JackLee 2025-03-30 20:46:30 +08:00
parent 0245968901
commit 0bd903f5fd
5 changed files with 39 additions and 48 deletions

Binary file not shown.

View File

@ -17,6 +17,7 @@
<file name="vk_swiftshader.dll" loadFrom=".\cef_binary\vk_swiftshader.dll"></file>
<file name="vk_swiftshader_icd.json" loadFrom=".\cef_binary\vk_swiftshader_icd.json"></file>
<file name="vulkan-1.dll" loadFrom=".\cef_binary\vulkan-1.dll"></file>
<file name="ffmpegsumo.dll" loadFrom=".\cef_binary\ffmpegsumo.dll"></file>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>

View File

@ -52,10 +52,7 @@ CefWidget::CefWidget(QWidget *parent)
m_Layout->setStretch(1, 8);
setBaseSize(QSize(width(),height()));
setLayout(m_Layout);
setWindowFlags(Qt::Window); // 使用标准窗口样式
setAttribute(Qt::WA_TranslucentBackground, false);
initBrowser();
setObjectName("CefWidget");
}
CefWidget::~CefWidget()
@ -71,7 +68,7 @@ void CefWidget::initBrowser()
}
setting.setWindowlessFrameRate(1000);
setting.setHardwareAcceleration(true);
m_CefWidget = new CefViewWidget("about:blank", &setting, this);
m_CefWidget = new QCefView("about:blank", &setting, this);
connect(m_CefWidget, &QCefView::invokeMethod, this, &CefWidget::onInvokeMethod);
connect(m_CefWidget, &QCefView::cefUrlRequest, this, &CefWidget::onQCefUrlRequest);
connect(m_CefWidget, &QCefView::cefQueryRequest, this, &CefWidget::onQCefQueryRequest);
@ -156,6 +153,7 @@ void CefWidget::onInvokeMethod(const QCefBrowserId &browserId,
}
else
{
}
}

View File

@ -7,8 +7,8 @@
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
//#include <QCefView.h>
#include "CefViewWidget.h"
#include <QCefView.h>
//#include "CefViewWidget.h"
class CefWidget : public QWidget
{
Q_OBJECT
@ -32,14 +32,12 @@ private:
QLineEdit* m_TextToUrl={};
QPushButton* m_BtnToUrl={};
QPushButton* m_BtnToString={};
CefViewWidget* m_CefWidget ={};
QCefView* m_CefWidget ={};
QCefSetting setting;
bool DevMode=true;
QString html_template;
protected:
void createLeftCefView();
// QCefView slots
protected slots:
public slots:
void onInvokeMethod(const QCefBrowserId& browserId,
const QCefFrameId& frameId,
const QString& method,
@ -60,7 +58,7 @@ protected slots:
const QString& errorMsg,
const QString& failedUrl);
//ui slots
protected slots:
public slots:
void onBtnShowDevToolsClicked();
void onBtnSetFocusClicked();
void onBtnCallJSCodeClicked();

View File

@ -5,10 +5,9 @@
#include "sui_base_ex.h"
#include "ctai.h"
#include <QApplication>
#include <QStandardPaths>
#include <QCefContext.h>
#include "QCefWidget/CefWidget.h"
#define DEBUG_PRINT true
#define DEBUG_PRINT false
void debug_print_argv(int argc, char *argv[])
{
if (!argc)
@ -63,22 +62,19 @@ void initConfig(int argc, char *argv[], QCefConfig &config, QString currentDir)
config.setCachePath(currentDir + "/user/userCache");
config.setResourceDirectoryPath(currentDir + "/cef_binary");
config.setLocalesDirectoryPath(currentDir + "/cef_binary/locales");
config.setBridgeObjectName("CallBridge");
config.setBuiltinSchemeName("CefView");
// 浏览器标识
config.setUserAgent("Mozilla/5.0 (Windows NT 10.0; CEF/3.2272.2035) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 SoftwareInformer/1.6.1400");
// 日志输出级别
config.setLogLevel(QCefConfig::LOGSEVERITY_VERBOSE);
// 桥名字
config.setBridgeObjectName("CtaiClient");
// 内置的协议方案名称
config.setBuiltinSchemeName("Ctai");
// 无窗口渲染模式
// config.setWindowlessRenderingEnabled(true);
config.setWindowlessRenderingEnabled(false);
// 远程Debug端口
// config.setRemoteDebuggingPort(9000);
// 请求头的语言
config.setAcceptLanguageList("zh-CN");
// 允许忽略 localhost 上的 TLS/SSL 错误
config.addCommandLineSwitch("allow-insecure-localhost");
config.addCommandLineSwitch("ignore-certificate-errors-spki-list");
config.addCommandLineSwitch("ignore-ssl-errors");
// 单进程模式
@ -86,25 +82,22 @@ void initConfig(int argc, char *argv[], QCefConfig &config, QString currentDir)
// 启用GPU加速
config.addCommandLineSwitch("enable-gpu");
// GPU加速合成
config.addCommandLineSwitch("enable-gpu-compositing");
//config.addCommandLineSwitch("enable-gpu-compositing");
// 在进程中使用GPU渲染-开启后只有一个进程
config.addCommandLineSwitch("in-process-gpu");
//config.addCommandLineSwitch("in-process-gpu");
// 无头模式
// config.addCommandLineSwitch("headless");
// 密钥链
config.addCommandLineSwitch("use-mock-keychain");
// chrome运行时环境
config.addCommandLineSwitch("enable-chrome-runtime");
// Alloy 风格
config.addCommandLineSwitch("use-alloy-style");
// 离屏渲染
// config.addCommandLineSwitch("off-screen-rendering-enabled");
config.addCommandLineSwitch("off-screen-rendering-enabled");
// 网络服务In进程
config.addCommandLineSwitchWithValue("enable-features", "NetworkServiceInProcess");
//config.addCommandLineSwitchWithValue("enable-features", "NetworkServiceInProcess");
// 语言
config.addCommandLineSwitchWithValue("lang", "zh-CN");
// 跨域进行远程
// config.addCommandLineSwitchWithValue("remote-allow-origins", "*");
// 禁用沙盒
config.addCommandLineSwitchWithValue("no-sandbox", "ture");
// 渲染进程限制
@ -112,7 +105,8 @@ void initConfig(int argc, char *argv[], QCefConfig &config, QString currentDir)
// 外部消息循环
config.addCommandLineSwitchWithValue("external-message-pump", "false");
// 多线程消息循环
config.addCommandLineSwitchWithValue("multi-threaded-message-loop", "true");
config.addCommandLineSwitchWithValue("multi-threaded-message-loop", "false");
}
int main(int argc, char *argv[])
{
@ -128,25 +122,25 @@ int main(int argc, char *argv[])
QCefContext cefContext(&a, argc, argv, &config);
CefWidget cw;
cw.show();
qputenv("QT_QPA_PLATFORM", "windows:fontengine=freetype");
// 加载语言包
QTranslator qtBaseTranslator;
if (!qtBaseTranslator.load(QStringLiteral(":/res/translator/qtbase_zh_CN.qm")))
{
// 处理加载翻译文件失败的情况
qDebug() << "Failed to load translation file.";
return -1;
}
a.installTranslator(&qtBaseTranslator);
// 读取窗体的配置并初始化
sui_init_config();
ctai x;
x.init_layout();
// 仅限于windows平台
#if defined(__WIN32__)
x.title()->set_type(QD_TYPE::QD_EXIT);
#endif
x.show();
// qputenv("QT_QPA_PLATFORM", "windows:fontengine=freetype");
// // 加载语言包
// QTranslator qtBaseTranslator;
// if (!qtBaseTranslator.load(QStringLiteral(":/res/translator/qtbase_zh_CN.qm")))
// {
// // 处理加载翻译文件失败的情况
// qDebug() << "Failed to load translation file.";
// return -1;
// }
// a.installTranslator(&qtBaseTranslator);
// // 读取窗体的配置并初始化
// sui_init_config();
// ctai x;
// x.init_layout();
// // 仅限于windows平台
// #if defined(__WIN32__)
// x.title()->set_type(QD_TYPE::QD_EXIT);
// #endif
// x.show();
a.exec();
qDebug() << "EXIT";
return 0;