MCPcopy Create free account
hub / github.com/YtFlow/Maple / WebView_WebMessageReceived

Method WebView_WebMessageReceived

Maple.App/MonacoEditPage.cpp:151–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149 }
150
151 fire_and_forget MonacoEditPage::WebView_WebMessageReceived(
152 MUXC::WebView2 const& sender,
153 CoreWebView2WebMessageReceivedEventArgs const& args
154 )
155 {
156 try {
157 auto const lifetime{ get_strong() };
158
159 auto const source = args.Source();
160 if (source != WEBVIEW_EDITOR_URL)
161 {
162 co_return;
163 }
164
165 nlohmann::json doc;
166 bool hasError{};
167 try {
168 doc = nlohmann::json::parse(to_string(args.WebMessageAsJson()));
169 }
170 catch (...)
171 {
172 hasError = true;
173 }
174 if (hasError)
175 {
176 co_return;
177 }
178
179 std::string const& cmd = doc["cmd"];
180 if (cmd == "editorReady")
181 {
182 m_webviewState = MonacoEditPageWebViewState::EditorReady;
183 co_await WebView().ExecuteScriptAsync(hstring{ L"window.mapleHostApi.loadFile(`" } +
184 CONFIG_ROOT_VIRTUAL_HOSTW +
185 m_currentFileName +
186 L"`)");
187 SaveModifiedContent = [weak = weak_ref{ lifetime }]()->IAsyncAction
188 {
189 if (auto const lifetime{ weak.get() })
190 {
191 struct awaiter : std::suspend_always
192 {
193 void await_suspend(
194 std::coroutine_handle<> handle)
195 {
196 lifetime->m_fileSaveHandle = handle;
197 }
198
199 com_ptr<MonacoEditPage> lifetime;
200 };
201 lifetime->WebView().ExecuteScriptAsync(hstring{ L"window.mapleHostApi.requestSaveCurrent()" });
202 co_await awaiter{ .lifetime = lifetime };
203 }
204 co_return;
205 };
206 }
207 else if (cmd == "save")
208 {

Callers

nothing calls this directly

Calls 1

dataMethod · 0.80

Tested by

no test coverage detected