mirror of
https://github.com/tauri-apps/zserge-webview.git
synced 2026-02-04 02:11:18 +01:00
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
//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;
|
|
}
|