1 Star 0 Fork 0

zhishy/zserge-webview

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.cc 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
Serge A. Zaitsev 提交于 2020-03-01 22:38 . merge webview-x branch
//bin/echo; [ $(uname) = "Darwin" ] && FLAGS="-framework Webkit" || FLAGS="$(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0)" ; c++ "$0" $FLAGS -std=c++11 -g -o webview && ./webview ; exit
// +build ignore
#include "webview.h"
#include <iostream>
#ifdef _WIN32
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
#else
int main()
#endif
{
webview::webview w(true, nullptr);
w.set_title("Example");
w.set_size(480, 320, WEBVIEW_HINT_NONE);
w.set_size(180, 120, WEBVIEW_HINT_MIN);
w.bind("noop", [](std::string s) -> std::string {
std::cout << s << std::endl;
return s;
});
w.bind("add", [](std::string s) -> std::string {
auto a = std::stoi(webview::json_parse(s, "", 0));
auto b = std::stoi(webview::json_parse(s, "", 1));
return std::to_string(a + b);
});
w.navigate(R"(data:text/html,
<!doctype html>
<html>
<body>hello</body>
<script>
window.onload = function() {
document.body.innerText = `hello, ${navigator.userAgent}`;
noop('hello').then(function(res) {
console.log('noop res', res);
});
add(1, 2).then(function(res) {
console.log('add res', res);
});
};
</script>
</html>
)");
w.run();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhishy/zserge-webview.git
git@gitee.com:zhishy/zserge-webview.git
zhishy
zserge-webview
zserge-webview
master

搜索帮助