blob: ac2fc9061cce967bcd9721fa94e026515a45c4c2 [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" {
swissChili4f0a0a82024-03-08 18:58:38 -050010 extern void do_a_conversion(char *, char *, char *);
swissChiliab615d82024-03-08 17:15:13 -050011}
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>(),
swissChili4f0a0a82024-03-08 18:58:38 -050022 to = j[1].template get<std::string>(),
23 system = j[2].template get<std::string>();
swissChiliab615d82024-03-08 17:15:13 -050024
25 std::cout << from << ' ' << to << std::endl;
26
swissChili4f0a0a82024-03-08 18:58:38 -050027 do_a_conversion((char *)from.data(), to.size() > 0 ? (char *)to.data() : nullptr, (char *)system.data());
swissChiliab615d82024-03-08 17:15:13 -050028 std::string res = json(std::string(log_buffer, log_buffer_ptr - log_buffer)).dump();
29 log_buffer_ptr = log_buffer;
30 std::cout << res << std::endl;
31 return res;
32}
33
34std::string get_html() {
35 return std::string("<div id=app></div><script>") + std::string((const char *)bundle_webview_js, bundle_webview_js_len) + std::string("</script>");
36}
37
38#ifdef WIN32
39int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine,
40 int nCmdShow) {
41#else
42int main() {
43#endif
44 // cookie_io_functions_t iofns = {NULL};
45 // iofns.cookie_write_function_t = writer;
46 //
47 // stdout = fopencookie(NULL, "r", iofns);
48
49 try {
50 webview::webview w(false, nullptr);
51 w.set_title("Units");
52 w.set_size(480, 320, WEBVIEW_HINT_NONE);
53 w.bind("convert", convert);
54 w.set_html(get_html());
55 // w.navigate("http://localhost:8000/index-webview.html");
56 w.run();
57 } catch (const webview::exception &e) {
58 std::cerr << e.what() << std::endl;
59 return 1;
60 }
61
62
63 return 0;
64}