blob: e3a2ed665953ab271f00a48b5250fcbdf37588fd [file] [log] [blame]
swissChiliab615d82024-03-08 17:15:13 -05001#include <iostream>
2#include <stdio.h>
3#include "webview/webview.h"
4#include "nlohmann/json.hpp"
5#include "bundle-webview-js.h"
6
7using json = nlohmann::json;
8
9extern "C" {
10 extern void do_a_conversion(char *, char *);
11}
12
13extern char log_buffer[4096];
14extern char *log_buffer_ptr;
15
16
17std::string convert(std::string arg) {
18 std::cout << "Params: " << arg << std::endl;
19 json j = json::parse(arg);
20
21 auto from = j[0].template get<std::string>(),
22 to = j[1].template get<std::string>();
23
24 std::cout << from << ' ' << to << std::endl;
25
swissChili16de3222024-03-08 17:55:11 -050026 do_a_conversion((char *)from.data(), to.size() > 0 ? (char *)to.data() : nullptr);
swissChiliab615d82024-03-08 17:15:13 -050027 std::string res = json(std::string(log_buffer, log_buffer_ptr - log_buffer)).dump();
28 log_buffer_ptr = log_buffer;
29 std::cout << res << std::endl;
30 return res;
31}
32
33std::string get_html() {
34 return std::string("<div id=app></div><script>") + std::string((const char *)bundle_webview_js, bundle_webview_js_len) + std::string("</script>");
35}
36
37#ifdef WIN32
38int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine,
39 int nCmdShow) {
40#else
41int main() {
42#endif
43 // cookie_io_functions_t iofns = {NULL};
44 // iofns.cookie_write_function_t = writer;
45 //
46 // stdout = fopencookie(NULL, "r", iofns);
47
48 try {
49 webview::webview w(false, nullptr);
50 w.set_title("Units");
51 w.set_size(480, 320, WEBVIEW_HINT_NONE);
52 w.bind("convert", convert);
53 w.set_html(get_html());
54 // w.navigate("http://localhost:8000/index-webview.html");
55 w.run();
56 } catch (const webview::exception &e) {
57 std::cerr << e.what() << std::endl;
58 return 1;
59 }
60
61
62 return 0;
63}