-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathgui.cpp
74 lines (53 loc) · 2.2 KB
/
gui.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
////////////////////////////////////////////////////////////////////////////////////////////////////
// This file is part of CosmoScout VR //
////////////////////////////////////////////////////////////////////////////////////////////////////
// SPDX-FileCopyrightText: German Aerospace Center (DLR) <[email protected]>
// SPDX-License-Identifier: MIT
#include "gui.hpp"
#include "internal/WebApp.hpp"
#include "logger.hpp"
#include <iostream>
namespace cs::gui {
namespace {
CefRefPtr<detail::WebApp> app;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
void executeWebProcess(int argc, char* argv[]) {
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
app = new detail::WebApp(argc, argv, false);
int result = CefExecuteProcess(app->GetArgs(), app, nullptr);
if (result >= 0) {
// Child proccess has endend, so exit.
exit(result);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void init() {
if (!app) {
logger().error("Failed to initialize gui: Please call executeWebProcess() before init()!");
return;
}
// For some reason CefInitialize changes the global locale. We therefore store
// it here and reset it at the end of this method.
std::locale current_locale;
CefSettings settings;
settings.command_line_args_disabled = true;
settings.no_sandbox = true;
settings.remote_debugging_port = 8999;
settings.windowless_rendering_enabled = true;
if (!CefInitialize(app->GetArgs(), settings, app, nullptr)) {
logger().error("Failed to initialize CEF. Gui will not work at all.");
}
std::locale::global(current_locale);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void cleanUp() {
CefShutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void update() {
CefDoMessageLoopWork();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
} // namespace cs::gui