plusui-native-core 0.1.4 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/Core/CMakeLists.txt +190 -7
  2. package/Core/Features/App/app.cpp +129 -0
  3. package/Core/Features/App/app.ts +126 -0
  4. package/Core/Features/Browser/browser.cpp +181 -0
  5. package/Core/Features/Browser/browser.ts +182 -0
  6. package/Core/Features/Clipboard/clipboard.cpp +234 -0
  7. package/Core/Features/Clipboard/clipboard.ts +113 -0
  8. package/Core/Features/Display/display.cpp +209 -0
  9. package/Core/Features/Display/display.ts +104 -0
  10. package/Core/Features/Event/Events.ts +166 -0
  11. package/Core/Features/Event/events.cpp +200 -0
  12. package/Core/Features/Keyboard/keyboard.cpp +186 -0
  13. package/Core/Features/Keyboard/keyboard.ts +175 -0
  14. package/Core/Features/Menu/context-menu.css +293 -0
  15. package/Core/Features/Menu/menu.cpp +481 -0
  16. package/Core/Features/Menu/menu.ts +439 -0
  17. package/Core/Features/Tray/tray.cpp +310 -0
  18. package/Core/Features/Tray/tray.ts +68 -0
  19. package/Core/Features/WebGPU/webgpu.cpp +939 -0
  20. package/Core/Features/WebGPU/webgpu.ts +1013 -0
  21. package/Core/Features/WebView/webview.cpp +1052 -0
  22. package/Core/Features/WebView/webview.ts +510 -0
  23. package/Core/Features/Window/window.cpp +664 -0
  24. package/Core/Features/Window/window.ts +142 -0
  25. package/Core/Features/WindowManager/window_manager.cpp +341 -0
  26. package/Core/include/plusui/app.hpp +73 -0
  27. package/Core/include/plusui/browser.hpp +66 -0
  28. package/Core/include/plusui/clipboard.hpp +41 -0
  29. package/Core/include/plusui/events.hpp +58 -0
  30. package/Core/include/{keyboard.hpp → plusui/keyboard.hpp} +21 -44
  31. package/Core/include/plusui/menu.hpp +153 -0
  32. package/Core/include/plusui/tray.hpp +93 -0
  33. package/Core/include/plusui/webgpu.hpp +434 -0
  34. package/Core/include/plusui/webview.hpp +142 -0
  35. package/Core/include/plusui/window.hpp +111 -0
  36. package/Core/include/plusui/window_manager.hpp +57 -0
  37. package/Core/vendor/WebView2EnvironmentOptions.h +406 -0
  38. package/Core/vendor/stb_image.h +7988 -0
  39. package/Core/vendor/webview.h +618 -510
  40. package/Core/vendor/webview2.h +52079 -0
  41. package/README.md +19 -0
  42. package/package.json +12 -15
  43. package/Core/include/app.hpp +0 -121
  44. package/Core/include/menu.hpp +0 -79
  45. package/Core/include/tray.hpp +0 -81
  46. package/Core/include/window.hpp +0 -106
  47. package/Core/src/app.cpp +0 -311
  48. package/Core/src/display.cpp +0 -424
  49. package/Core/src/tray.cpp +0 -275
  50. package/Core/src/window.cpp +0 -528
  51. package/dist/index.d.ts +0 -205
  52. package/dist/index.js +0 -198
  53. package/src/index.ts +0 -574
  54. /package/Core/include/{display.hpp → plusui/display.hpp} +0 -0
@@ -0,0 +1,57 @@
1
+ #ifndef PLUSUI_WINDOW_MANAGER_H
2
+ #define PLUSUI_WINDOW_MANAGER_H
3
+
4
+ #include <string>
5
+ #include <memory>
6
+
7
+ namespace plusui {
8
+
9
+ struct WindowSize {
10
+ int width = 0;
11
+ int height = 0;
12
+ };
13
+
14
+ struct WindowPosition {
15
+ int x = 0;
16
+ int y = 0;
17
+ };
18
+
19
+ class WindowManager {
20
+ public:
21
+ WindowManager();
22
+ explicit WindowManager(void* nativeWindow);
23
+ ~WindowManager();
24
+
25
+ // Window operations
26
+ void setTitle(const std::string& title);
27
+ void setSize(int width, int height);
28
+ WindowSize getSize() const;
29
+ void setPosition(int x, int y);
30
+ WindowPosition getPosition() const;
31
+ void setCenter();
32
+ void setFullscreen(bool enabled);
33
+ void setAlwaysOnTop(bool enabled);
34
+ void setResizable(bool enabled);
35
+ void setDecorations(bool enabled);
36
+ void setSkipTaskbar(bool enabled);
37
+ void setTransparency(double alpha);
38
+
39
+ void minimize();
40
+ void maximize();
41
+ void restore();
42
+ void show();
43
+ void hide();
44
+ void close();
45
+
46
+ bool isMaximized() const;
47
+ bool isMinimized() const;
48
+ bool isVisible() const;
49
+
50
+ private:
51
+ struct Impl;
52
+ std::unique_ptr<Impl> pImpl;
53
+ };
54
+
55
+ } // namespace plusui
56
+
57
+ #endif
@@ -0,0 +1,406 @@
1
+ // Copyright (C) Microsoft Corporation. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef __core_webview2_environment_options_h__
6
+ #define __core_webview2_environment_options_h__
7
+
8
+ #include <objbase.h>
9
+ #include <wrl/implements.h>
10
+
11
+ #include "webview2.h"
12
+ #define CORE_WEBVIEW_TARGET_PRODUCT_VERSION L"126.0.2592.51"
13
+
14
+ #define COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(p) \
15
+ public: \
16
+ HRESULT STDMETHODCALLTYPE get_##p(LPWSTR* value) override { \
17
+ if (!value) \
18
+ return E_POINTER; \
19
+ *value = m_##p.Copy(); \
20
+ if ((*value == nullptr) && (m_##p.Get() != nullptr)) \
21
+ return HRESULT_FROM_WIN32(GetLastError()); \
22
+ return S_OK; \
23
+ } \
24
+ HRESULT STDMETHODCALLTYPE put_##p(LPCWSTR value) override { \
25
+ LPCWSTR result = m_##p.Set(value); \
26
+ if ((result == nullptr) && (value != nullptr)) \
27
+ return HRESULT_FROM_WIN32(GetLastError()); \
28
+ return S_OK; \
29
+ } \
30
+ \
31
+ protected: \
32
+ AutoCoMemString m_##p;
33
+
34
+ #define COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(p, defPVal) \
35
+ public: \
36
+ HRESULT STDMETHODCALLTYPE get_##p(BOOL* value) override { \
37
+ if (!value) \
38
+ return E_POINTER; \
39
+ *value = m_##p; \
40
+ return S_OK; \
41
+ } \
42
+ HRESULT STDMETHODCALLTYPE put_##p(BOOL value) override { \
43
+ m_##p = value; \
44
+ return S_OK; \
45
+ } \
46
+ \
47
+ protected: \
48
+ BOOL m_##p = defPVal ? TRUE : FALSE;
49
+
50
+ #define DEFINE_AUTO_COMEM_STRING() \
51
+ protected: \
52
+ class AutoCoMemString { \
53
+ public: \
54
+ AutoCoMemString() {} \
55
+ ~AutoCoMemString() { Release(); } \
56
+ void Release() { \
57
+ if (m_string) { \
58
+ deallocate_fn(m_string); \
59
+ m_string = nullptr; \
60
+ } \
61
+ } \
62
+ \
63
+ LPCWSTR Set(LPCWSTR str) { \
64
+ Release(); \
65
+ if (str) { \
66
+ m_string = MakeCoMemString(str); \
67
+ } \
68
+ return m_string; \
69
+ } \
70
+ LPCWSTR Get() { return m_string; } \
71
+ LPWSTR Copy() { \
72
+ if (m_string) \
73
+ return MakeCoMemString(m_string); \
74
+ return nullptr; \
75
+ } \
76
+ \
77
+ protected: \
78
+ LPWSTR MakeCoMemString(LPCWSTR source) { \
79
+ const size_t length = wcslen(source); \
80
+ const size_t bytes = (length + 1) * sizeof(*source); \
81
+ \
82
+ if (bytes <= length) { \
83
+ return nullptr; \
84
+ } \
85
+ \
86
+ wchar_t* result = reinterpret_cast<wchar_t*>(allocate_fn(bytes)); \
87
+ \
88
+ if (result) \
89
+ memcpy(result, source, bytes); \
90
+ return result; \
91
+ } \
92
+ LPWSTR m_string = nullptr; \
93
+ };
94
+
95
+ template <typename allocate_fn_t,
96
+ allocate_fn_t allocate_fn,
97
+ typename deallocate_fn_t,
98
+ deallocate_fn_t deallocate_fn>
99
+ class CoreWebView2CustomSchemeRegistrationBase
100
+ : public Microsoft::WRL::RuntimeClass<
101
+ Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
102
+ ICoreWebView2CustomSchemeRegistration> {
103
+ public:
104
+ CoreWebView2CustomSchemeRegistrationBase(LPCWSTR schemeName) {
105
+ m_schemeName.Set(schemeName);
106
+ }
107
+
108
+ CoreWebView2CustomSchemeRegistrationBase(
109
+ CoreWebView2CustomSchemeRegistrationBase&&) = default;
110
+ ~CoreWebView2CustomSchemeRegistrationBase() { ReleaseAllowedOrigins(); }
111
+
112
+ HRESULT STDMETHODCALLTYPE get_SchemeName(LPWSTR* schemeName) override {
113
+ if (!schemeName)
114
+ return E_POINTER;
115
+ *schemeName = m_schemeName.Copy();
116
+ if ((*schemeName == nullptr) && (m_schemeName.Get() != nullptr))
117
+ return HRESULT_FROM_WIN32(GetLastError());
118
+ return S_OK;
119
+ }
120
+
121
+ HRESULT STDMETHODCALLTYPE
122
+ GetAllowedOrigins(UINT32* allowedOriginsCount,
123
+ LPWSTR** allowedOrigins) override {
124
+ if (!allowedOrigins || !allowedOriginsCount) {
125
+ return E_POINTER;
126
+ }
127
+ *allowedOriginsCount = 0;
128
+ if (m_allowedOriginsCount == 0) {
129
+ *allowedOrigins = nullptr;
130
+ return S_OK;
131
+ } else {
132
+ *allowedOrigins = reinterpret_cast<LPWSTR*>(
133
+ allocate_fn(m_allowedOriginsCount * sizeof(LPWSTR)));
134
+ if (!(*allowedOrigins)) {
135
+ return HRESULT_FROM_WIN32(GetLastError());
136
+ }
137
+ ZeroMemory(*allowedOrigins, m_allowedOriginsCount * sizeof(LPWSTR));
138
+ for (UINT32 i = 0; i < m_allowedOriginsCount; i++) {
139
+ (*allowedOrigins)[i] = m_allowedOrigins[i].Copy();
140
+ if (!(*allowedOrigins)[i]) {
141
+ HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
142
+ for (UINT32 j = 0; j < i; j++) {
143
+ deallocate_fn((*allowedOrigins)[j]);
144
+ }
145
+ deallocate_fn(*allowedOrigins);
146
+ return hr;
147
+ }
148
+ }
149
+ *allowedOriginsCount = m_allowedOriginsCount;
150
+ return S_OK;
151
+ }
152
+ }
153
+
154
+ HRESULT STDMETHODCALLTYPE
155
+ SetAllowedOrigins(UINT32 allowedOriginsCount,
156
+ LPCWSTR* allowedOrigins) override {
157
+ ReleaseAllowedOrigins();
158
+ if (allowedOriginsCount == 0) {
159
+ return S_OK;
160
+ } else {
161
+ m_allowedOrigins = new AutoCoMemString[allowedOriginsCount];
162
+ if (!m_allowedOrigins) {
163
+ return HRESULT_FROM_WIN32(GetLastError());
164
+ }
165
+ for (UINT32 i = 0; i < allowedOriginsCount; i++) {
166
+ m_allowedOrigins[i].Set(allowedOrigins[i]);
167
+ if (!m_allowedOrigins[i].Get()) {
168
+ HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
169
+ for (UINT32 j = 0; j < i; j++) {
170
+ m_allowedOrigins[j].Release();
171
+ }
172
+ m_allowedOriginsCount = 0;
173
+ delete[] (m_allowedOrigins);
174
+ return hr;
175
+ }
176
+ }
177
+ m_allowedOriginsCount = allowedOriginsCount;
178
+ return S_OK;
179
+ }
180
+ }
181
+
182
+ protected:
183
+ DEFINE_AUTO_COMEM_STRING();
184
+
185
+ void ReleaseAllowedOrigins() {
186
+ if (m_allowedOrigins) {
187
+ delete[] (m_allowedOrigins);
188
+ m_allowedOrigins = nullptr;
189
+ }
190
+ }
191
+
192
+ AutoCoMemString m_schemeName;
193
+ COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(TreatAsSecure, false);
194
+ COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(HasAuthorityComponent, false);
195
+ AutoCoMemString* m_allowedOrigins = nullptr;
196
+ unsigned int m_allowedOriginsCount = 0;
197
+ };
198
+
199
+ // This is a base COM class that implements ICoreWebView2EnvironmentOptions.
200
+ template <typename allocate_fn_t,
201
+ allocate_fn_t allocate_fn,
202
+ typename deallocate_fn_t,
203
+ deallocate_fn_t deallocate_fn>
204
+ class CoreWebView2EnvironmentOptionsBase
205
+ : public Microsoft::WRL::Implements<
206
+ Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
207
+ ICoreWebView2EnvironmentOptions,
208
+ ICoreWebView2EnvironmentOptions2,
209
+ ICoreWebView2EnvironmentOptions3,
210
+ ICoreWebView2EnvironmentOptions4,
211
+ ICoreWebView2EnvironmentOptions5,
212
+ ICoreWebView2EnvironmentOptions6,
213
+ ICoreWebView2EnvironmentOptions7,
214
+ ICoreWebView2EnvironmentOptions8> {
215
+ public:
216
+ static const COREWEBVIEW2_RELEASE_CHANNELS kInternalChannel =
217
+ static_cast<COREWEBVIEW2_RELEASE_CHANNELS>(1 << 4);
218
+ static const COREWEBVIEW2_RELEASE_CHANNELS kAllChannels =
219
+ COREWEBVIEW2_RELEASE_CHANNELS_STABLE |
220
+ COREWEBVIEW2_RELEASE_CHANNELS_BETA | COREWEBVIEW2_RELEASE_CHANNELS_DEV |
221
+ COREWEBVIEW2_RELEASE_CHANNELS_CANARY | kInternalChannel;
222
+
223
+ CoreWebView2EnvironmentOptionsBase() {
224
+ // Initialize the target compatible browser version value to the version
225
+ // of the browser binaries corresponding to this version of the SDK.
226
+ m_TargetCompatibleBrowserVersion.Set(CORE_WEBVIEW_TARGET_PRODUCT_VERSION);
227
+ }
228
+
229
+ // ICoreWebView2EnvironmentOptions7
230
+ HRESULT STDMETHODCALLTYPE
231
+ get_ReleaseChannels(COREWEBVIEW2_RELEASE_CHANNELS* channels) override {
232
+ if (!channels) {
233
+ return E_POINTER;
234
+ }
235
+ *channels = m_releaseChannels;
236
+ return S_OK;
237
+ }
238
+
239
+ HRESULT STDMETHODCALLTYPE
240
+ put_ReleaseChannels(COREWEBVIEW2_RELEASE_CHANNELS channels) override {
241
+ m_releaseChannels = channels;
242
+ return S_OK;
243
+ }
244
+
245
+ HRESULT STDMETHODCALLTYPE
246
+ get_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND* value) override {
247
+ if (!value) {
248
+ return E_POINTER;
249
+ }
250
+ *value = m_channelSearchKind;
251
+ return S_OK;
252
+ }
253
+
254
+ HRESULT STDMETHODCALLTYPE
255
+ put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND value) override {
256
+ m_channelSearchKind = value;
257
+ return S_OK;
258
+ }
259
+
260
+ // ICoreWebView2EnvironmentOptions8
261
+ HRESULT STDMETHODCALLTYPE
262
+ get_ScrollBarStyle(COREWEBVIEW2_SCROLLBAR_STYLE* style) override {
263
+ if (!style) {
264
+ return E_POINTER;
265
+ }
266
+ *style = m_scrollbarStyle;
267
+ return S_OK;
268
+ }
269
+
270
+ HRESULT STDMETHODCALLTYPE
271
+ put_ScrollBarStyle(COREWEBVIEW2_SCROLLBAR_STYLE style) override {
272
+ m_scrollbarStyle = style;
273
+ return S_OK;
274
+ }
275
+
276
+ protected:
277
+ ~CoreWebView2EnvironmentOptionsBase() { ReleaseCustomSchemeRegistrations(); };
278
+
279
+ void ReleaseCustomSchemeRegistrations() {
280
+ if (m_customSchemeRegistrations) {
281
+ for (UINT32 i = 0; i < m_customSchemeRegistrationsCount; i++) {
282
+ m_customSchemeRegistrations[i]->Release();
283
+ }
284
+ deallocate_fn(m_customSchemeRegistrations);
285
+ m_customSchemeRegistrations = nullptr;
286
+ m_customSchemeRegistrationsCount = 0;
287
+ }
288
+ }
289
+
290
+ private:
291
+ ICoreWebView2CustomSchemeRegistration** m_customSchemeRegistrations = nullptr;
292
+ unsigned int m_customSchemeRegistrationsCount = 0;
293
+
294
+ COREWEBVIEW2_RELEASE_CHANNELS m_releaseChannels = kAllChannels;
295
+ COREWEBVIEW2_CHANNEL_SEARCH_KIND m_channelSearchKind =
296
+ COREWEBVIEW2_CHANNEL_SEARCH_KIND_MOST_STABLE;
297
+
298
+ // ICoreWebView2EnvironmentOptions8
299
+ COREWEBVIEW2_SCROLLBAR_STYLE m_scrollbarStyle =
300
+ COREWEBVIEW2_SCROLLBAR_STYLE_DEFAULT;
301
+
302
+ DEFINE_AUTO_COMEM_STRING();
303
+
304
+ public:
305
+ // ICoreWebView2EnvironmentOptions
306
+ COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(AdditionalBrowserArguments)
307
+ COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(Language)
308
+ COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(TargetCompatibleBrowserVersion)
309
+ COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(
310
+ AllowSingleSignOnUsingOSPrimaryAccount,
311
+ false)
312
+
313
+ // ICoreWebView2EnvironmentOptions2
314
+ COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(ExclusiveUserDataFolderAccess,
315
+ false)
316
+
317
+ // ICoreWebView2EnvironmentOptions3
318
+ COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(IsCustomCrashReportingEnabled,
319
+ false)
320
+
321
+ // ICoreWebView2EnvironmentOptions4
322
+ public:
323
+ HRESULT STDMETHODCALLTYPE GetCustomSchemeRegistrations(
324
+ UINT32* count,
325
+ ICoreWebView2CustomSchemeRegistration*** schemeRegistrations) override {
326
+ if (!count || !schemeRegistrations) {
327
+ return E_POINTER;
328
+ }
329
+ *count = 0;
330
+ if (m_customSchemeRegistrationsCount == 0) {
331
+ *schemeRegistrations = nullptr;
332
+ return S_OK;
333
+ } else {
334
+ *schemeRegistrations =
335
+ reinterpret_cast<ICoreWebView2CustomSchemeRegistration**>(
336
+ allocate_fn(sizeof(ICoreWebView2CustomSchemeRegistration*) *
337
+ m_customSchemeRegistrationsCount));
338
+ if (!*schemeRegistrations) {
339
+ return HRESULT_FROM_WIN32(GetLastError());
340
+ }
341
+ for (UINT32 i = 0; i < m_customSchemeRegistrationsCount; i++) {
342
+ (*schemeRegistrations)[i] = m_customSchemeRegistrations[i];
343
+ (*schemeRegistrations)[i]->AddRef();
344
+ }
345
+ *count = m_customSchemeRegistrationsCount;
346
+ return S_OK;
347
+ }
348
+ }
349
+
350
+ HRESULT STDMETHODCALLTYPE SetCustomSchemeRegistrations(
351
+ UINT32 count,
352
+ ICoreWebView2CustomSchemeRegistration** schemeRegistrations) override {
353
+ ReleaseCustomSchemeRegistrations();
354
+ m_customSchemeRegistrations =
355
+ reinterpret_cast<ICoreWebView2CustomSchemeRegistration**>(allocate_fn(
356
+ sizeof(ICoreWebView2CustomSchemeRegistration*) * count));
357
+ if (!m_customSchemeRegistrations) {
358
+ return GetLastError();
359
+ }
360
+ for (UINT32 i = 0; i < count; i++) {
361
+ m_customSchemeRegistrations[i] = schemeRegistrations[i];
362
+ m_customSchemeRegistrations[i]->AddRef();
363
+ }
364
+ m_customSchemeRegistrationsCount = count;
365
+ return S_OK;
366
+ }
367
+
368
+ // ICoreWebView2EnvironmentOptions5
369
+ COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(EnableTrackingPrevention, true)
370
+
371
+ // ICoreWebView2EnvironmentOptions6
372
+ COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(AreBrowserExtensionsEnabled,
373
+ false)
374
+ };
375
+
376
+ template <typename allocate_fn_t,
377
+ allocate_fn_t allocate_fn,
378
+ typename deallocate_fn_t,
379
+ deallocate_fn_t deallocate_fn>
380
+ class CoreWebView2EnvironmentOptionsBaseClass
381
+ : public Microsoft::WRL::RuntimeClass<
382
+ Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
383
+ CoreWebView2EnvironmentOptionsBase<allocate_fn_t,
384
+ allocate_fn,
385
+ deallocate_fn_t,
386
+ deallocate_fn>> {
387
+ public:
388
+ CoreWebView2EnvironmentOptionsBaseClass() {}
389
+
390
+ protected:
391
+ ~CoreWebView2EnvironmentOptionsBaseClass() override {}
392
+ };
393
+
394
+ typedef CoreWebView2CustomSchemeRegistrationBase<decltype(&::CoTaskMemAlloc),
395
+ ::CoTaskMemAlloc,
396
+ decltype(&::CoTaskMemFree),
397
+ ::CoTaskMemFree>
398
+ CoreWebView2CustomSchemeRegistration;
399
+
400
+ typedef CoreWebView2EnvironmentOptionsBaseClass<decltype(&::CoTaskMemAlloc),
401
+ ::CoTaskMemAlloc,
402
+ decltype(&::CoTaskMemFree),
403
+ ::CoTaskMemFree>
404
+ CoreWebView2EnvironmentOptions;
405
+
406
+ #endif // __core_webview2_environment_options_h__