| #include <iostream> |
| #include <stdio.h> |
| #include "webview/webview.h" |
| #include "nlohmann/json.hpp" |
| #include "bundle-webview-js.h" |
| |
| using json = nlohmann::json; |
| |
| extern "C" { |
| extern void do_a_conversion(char *, char *); |
| } |
| |
| extern char log_buffer[4096]; |
| extern char *log_buffer_ptr; |
| |
| |
| std::string convert(std::string arg) { |
| std::cout << "Params: " << arg << std::endl; |
| json j = json::parse(arg); |
| |
| auto from = j[0].template get<std::string>(), |
| to = j[1].template get<std::string>(); |
| |
| std::cout << from << ' ' << to << std::endl; |
| |
| do_a_conversion((char *)from.data(), to.size() > 0 ? (char *)to.data() : nullptr); |
| std::string res = json(std::string(log_buffer, log_buffer_ptr - log_buffer)).dump(); |
| log_buffer_ptr = log_buffer; |
| std::cout << res << std::endl; |
| return res; |
| } |
| |
| std::string get_html() { |
| return std::string("<div id=app></div><script>") + std::string((const char *)bundle_webview_js, bundle_webview_js_len) + std::string("</script>"); |
| } |
| |
| #ifdef WIN32 |
| int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine, |
| int nCmdShow) { |
| #else |
| int main() { |
| #endif |
| // cookie_io_functions_t iofns = {NULL}; |
| // iofns.cookie_write_function_t = writer; |
| // |
| // stdout = fopencookie(NULL, "r", iofns); |
| |
| try { |
| webview::webview w(false, nullptr); |
| w.set_title("Units"); |
| w.set_size(480, 320, WEBVIEW_HINT_NONE); |
| w.bind("convert", convert); |
| w.set_html(get_html()); |
| // w.navigate("http://localhost:8000/index-webview.html"); |
| w.run(); |
| } catch (const webview::exception &e) { |
| std::cerr << e.what() << std::endl; |
| return 1; |
| } |
| |
| |
| return 0; |
| } |