-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
47 lines (43 loc) · 1.39 KB
/
main.cpp
File metadata and controls
47 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "pch.h"
#include "wv2_mgmt.h"
#define WM_JSONRPC_MESSAGE (WM_USER + 114514)
std::unique_ptr<AppContext> g_app;
int main() {
// Initialize COM for the main thread
(void)CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
g_app = std::make_unique<AppContext>([main_thread_id = GetCurrentThreadId()]() {
PostThreadMessage(main_thread_id, WM_JSONRPC_MESSAGE, 0, 0);
});
g_app->dummy_hwnd = CreateWindowEx(
0, L"Static", L"emacs-webview2-nursery", 0,
0, 0, 0, 0, NULL,
NULL, NULL, NULL
);
if (g_app->dummy_hwnd) {
ShowWindow(g_app->dummy_hwnd, SW_HIDE);
} else {
}
webview_init();
// Start the JSON-RPC server
g_app->server.start();
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) {
if (msg.message == WM_JSONRPC_MESSAGE) {
g_app->server.process_queue();
if (!g_app->server.is_running()) {
break;
}
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
if (hIn != INVALID_HANDLE_VALUE) {
CancelIoEx(hIn, nullptr); // Forcefully abort pending I/O on the reader thread
}
// Free resources before COM uninitialize.
g_app.reset();
CoUninitialize();
return 0;
}