janela 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/bin/janela.mjs +271 -0
- package/package.json +43 -0
- package/runtime/janela.ts +193 -0
- package/shim/wvshim.cc +201 -0
- package/templates/index.html +48 -0
- package/templates/janela.conf.json +10 -0
- package/templates/main.ts +37 -0
- package/vendor-webview/LICENSE +22 -0
- package/vendor-webview/core/include/webview/api.h +251 -0
- package/vendor-webview/core/include/webview/backends.hh +40 -0
- package/vendor-webview/core/include/webview/c_api_impl.hh +258 -0
- package/vendor-webview/core/include/webview/detail/backends/cocoa_webkit.hh +626 -0
- package/vendor-webview/core/include/webview/detail/backends/gtk_webkitgtk.hh +355 -0
- package/vendor-webview/core/include/webview/detail/backends/win32_edge.hh +909 -0
- package/vendor-webview/core/include/webview/detail/basic_result.hh +119 -0
- package/vendor-webview/core/include/webview/detail/engine_base.hh +382 -0
- package/vendor-webview/core/include/webview/detail/exceptions.hh +42 -0
- package/vendor-webview/core/include/webview/detail/json.hh +337 -0
- package/vendor-webview/core/include/webview/detail/native_library.hh +170 -0
- package/vendor-webview/core/include/webview/detail/optional.hh +118 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSApplication.hh +107 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSBundle.hh +56 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSEvent.hh +71 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSInvocation.hh +66 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSMethodSignature.hh +52 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSNotification.hh +51 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSNumber.hh +53 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSObject.hh +51 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSOpenPanel.hh +71 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSPoint.hh +53 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSRect.hh +53 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSSavePanel.hh +52 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSSize.hh +53 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSString.hh +87 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSURL.hh +63 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSURLRequest.hh +52 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSValue.hh +56 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSView.hh +91 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSWindow.hh +137 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/cocoa.hh +59 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/types.hh +49 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/objc/Class.hh +55 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/objc/autoreleasepool.hh +70 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/objc/invoke.hh +75 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/objc/memory.hh +57 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/objc/objc.hh +47 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKOpenPanelParameters.hh +57 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKScriptMessage.hh +51 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKUserContentController.hh +61 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKUserScript.hh +71 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKWebView.hh +108 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKWebViewConfiguration.hh +60 -0
- package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/webkit.hh +46 -0
- package/vendor-webview/core/include/webview/detail/platform/linux/gtk/compat.hh +137 -0
- package/vendor-webview/core/include/webview/detail/platform/linux/webkitgtk/compat.hh +142 -0
- package/vendor-webview/core/include/webview/detail/platform/linux/webkitgtk/dmabuf.hh +167 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/com_init_wrapper.hh +126 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/dpi.hh +161 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/dwmapi.hh +67 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/iid.hh +78 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/ntdll.hh +58 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/reg_key.hh +135 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/shcore.hh +59 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/theme.hh +76 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/user32.hh +90 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/version.hh +151 -0
- package/vendor-webview/core/include/webview/detail/platform/windows/webview2/loader.hh +391 -0
- package/vendor-webview/core/include/webview/detail/user_script.hh +76 -0
- package/vendor-webview/core/include/webview/detail/utility/string.hh +99 -0
- package/vendor-webview/core/include/webview/errors.h +67 -0
- package/vendor-webview/core/include/webview/errors.hh +85 -0
- package/vendor-webview/core/include/webview/json_deprecated.hh +61 -0
- package/vendor-webview/core/include/webview/macros.h +123 -0
- package/vendor-webview/core/include/webview/types.h +81 -0
- package/vendor-webview/core/include/webview/types.hh +48 -0
- package/vendor-webview/core/include/webview/version.h +67 -0
- package/vendor-webview/core/include/webview/webview.h +32 -0
- package/vendor-webview/core/include/webview.h +15 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017 Serge Zaitsev
|
|
5
|
+
* Copyright (c) 2022 Steffen André Langnes
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef WEBVIEW_PLATFORM_WINDOWS_THEME_HH
|
|
27
|
+
#define WEBVIEW_PLATFORM_WINDOWS_THEME_HH
|
|
28
|
+
|
|
29
|
+
#if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
|
|
30
|
+
|
|
31
|
+
#include "../../../macros.h"
|
|
32
|
+
|
|
33
|
+
#if defined(WEBVIEW_PLATFORM_WINDOWS)
|
|
34
|
+
|
|
35
|
+
#include "../../native_library.hh"
|
|
36
|
+
#include "dwmapi.hh"
|
|
37
|
+
#include "reg_key.hh"
|
|
38
|
+
|
|
39
|
+
namespace webview {
|
|
40
|
+
namespace detail {
|
|
41
|
+
|
|
42
|
+
inline bool is_dark_theme_enabled() {
|
|
43
|
+
constexpr auto *sub_key =
|
|
44
|
+
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
|
|
45
|
+
reg_key key(HKEY_CURRENT_USER, sub_key, 0, KEY_READ);
|
|
46
|
+
if (!key.is_open()) {
|
|
47
|
+
// Default is light theme
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return key.query_uint(L"AppsUseLightTheme", 1) == 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
inline void apply_window_theme(HWND window) {
|
|
54
|
+
auto dark_theme_enabled = is_dark_theme_enabled();
|
|
55
|
+
|
|
56
|
+
// Use "immersive dark mode" on systems that support it.
|
|
57
|
+
// Changes the color of the window's title bar (light or dark).
|
|
58
|
+
BOOL use_dark_mode{dark_theme_enabled ? TRUE : FALSE};
|
|
59
|
+
static native_library dwmapi{L"dwmapi.dll"};
|
|
60
|
+
if (auto fn = dwmapi.get(dwmapi_symbols::DwmSetWindowAttribute)) {
|
|
61
|
+
// Try the modern, documented attribute before the older, undocumented one.
|
|
62
|
+
if (fn(window, dwmapi_symbols::DWMWA_USE_IMMERSIVE_DARK_MODE,
|
|
63
|
+
&use_dark_mode, sizeof(use_dark_mode)) != S_OK) {
|
|
64
|
+
fn(window,
|
|
65
|
+
dwmapi_symbols::DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_V10_0_19041,
|
|
66
|
+
&use_dark_mode, sizeof(use_dark_mode));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} // namespace detail
|
|
72
|
+
} // namespace webview
|
|
73
|
+
|
|
74
|
+
#endif // defined(WEBVIEW_PLATFORM_WINDOWS)
|
|
75
|
+
#endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
|
|
76
|
+
#endif // WEBVIEW_PLATFORM_WINDOWS_THEME_HH
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017 Serge Zaitsev
|
|
5
|
+
* Copyright (c) 2022 Steffen André Langnes
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef WEBVIEW_PLATFORM_WINDOWS_USER32_HH
|
|
27
|
+
#define WEBVIEW_PLATFORM_WINDOWS_USER32_HH
|
|
28
|
+
|
|
29
|
+
#if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
|
|
30
|
+
|
|
31
|
+
#include "../../../macros.h"
|
|
32
|
+
|
|
33
|
+
#if defined(WEBVIEW_PLATFORM_WINDOWS)
|
|
34
|
+
|
|
35
|
+
#include "../../native_library.hh"
|
|
36
|
+
|
|
37
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
38
|
+
#define WIN32_LEAN_AND_MEAN
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#include <windows.h>
|
|
42
|
+
|
|
43
|
+
namespace webview {
|
|
44
|
+
namespace detail {
|
|
45
|
+
namespace user32_symbols {
|
|
46
|
+
|
|
47
|
+
using DPI_AWARENESS_CONTEXT = HANDLE;
|
|
48
|
+
using SetProcessDpiAwarenessContext_t = BOOL(WINAPI *)(DPI_AWARENESS_CONTEXT);
|
|
49
|
+
using SetProcessDPIAware_t = BOOL(WINAPI *)();
|
|
50
|
+
using GetDpiForWindow_t = UINT(WINAPI *)(HWND);
|
|
51
|
+
using EnableNonClientDpiScaling_t = BOOL(WINAPI *)(HWND);
|
|
52
|
+
using AdjustWindowRectExForDpi_t = BOOL(WINAPI *)(LPRECT, DWORD, BOOL, DWORD,
|
|
53
|
+
UINT);
|
|
54
|
+
using GetWindowDpiAwarenessContext_t = DPI_AWARENESS_CONTEXT(WINAPI *)(HWND);
|
|
55
|
+
using AreDpiAwarenessContextsEqual_t = BOOL(WINAPI *)(DPI_AWARENESS_CONTEXT,
|
|
56
|
+
DPI_AWARENESS_CONTEXT);
|
|
57
|
+
|
|
58
|
+
// Use intptr_t as the underlying type because we need to
|
|
59
|
+
// reinterpret_cast<DPI_AWARENESS_CONTEXT> which is a pointer.
|
|
60
|
+
// Available since Windows 10, version 1607
|
|
61
|
+
enum class dpi_awareness : intptr_t {
|
|
62
|
+
per_monitor_v2_aware = -4, // Available since Windows 10, version 1703
|
|
63
|
+
per_monitor_aware = -3
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
constexpr auto SetProcessDpiAwarenessContext =
|
|
67
|
+
library_symbol<SetProcessDpiAwarenessContext_t>(
|
|
68
|
+
"SetProcessDpiAwarenessContext");
|
|
69
|
+
constexpr auto SetProcessDPIAware =
|
|
70
|
+
library_symbol<SetProcessDPIAware_t>("SetProcessDPIAware");
|
|
71
|
+
constexpr auto GetDpiForWindow =
|
|
72
|
+
library_symbol<GetDpiForWindow_t>("GetDpiForWindow");
|
|
73
|
+
constexpr auto EnableNonClientDpiScaling =
|
|
74
|
+
library_symbol<EnableNonClientDpiScaling_t>("EnableNonClientDpiScaling");
|
|
75
|
+
constexpr auto AdjustWindowRectExForDpi =
|
|
76
|
+
library_symbol<AdjustWindowRectExForDpi_t>("AdjustWindowRectExForDpi");
|
|
77
|
+
constexpr auto GetWindowDpiAwarenessContext =
|
|
78
|
+
library_symbol<GetWindowDpiAwarenessContext_t>(
|
|
79
|
+
"GetWindowDpiAwarenessContext");
|
|
80
|
+
constexpr auto AreDpiAwarenessContextsEqual =
|
|
81
|
+
library_symbol<AreDpiAwarenessContextsEqual_t>(
|
|
82
|
+
"AreDpiAwarenessContextsEqual");
|
|
83
|
+
|
|
84
|
+
} // namespace user32_symbols
|
|
85
|
+
} // namespace detail
|
|
86
|
+
} // namespace webview
|
|
87
|
+
|
|
88
|
+
#endif // defined(WEBVIEW_PLATFORM_WINDOWS)
|
|
89
|
+
#endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
|
|
90
|
+
#endif // WEBVIEW_PLATFORM_WINDOWS_USER32_HH
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017 Serge Zaitsev
|
|
5
|
+
* Copyright (c) 2022 Steffen André Langnes
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef WEBVIEW_PLATFORM_WINDOWS_VERSION_HH
|
|
27
|
+
#define WEBVIEW_PLATFORM_WINDOWS_VERSION_HH
|
|
28
|
+
|
|
29
|
+
#if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
|
|
30
|
+
|
|
31
|
+
#include "../../../macros.h"
|
|
32
|
+
|
|
33
|
+
#if defined(WEBVIEW_PLATFORM_WINDOWS)
|
|
34
|
+
|
|
35
|
+
#include "ntdll.hh"
|
|
36
|
+
|
|
37
|
+
#include <array>
|
|
38
|
+
#include <string>
|
|
39
|
+
#include <vector>
|
|
40
|
+
|
|
41
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
42
|
+
#define WIN32_LEAN_AND_MEAN
|
|
43
|
+
#endif
|
|
44
|
+
|
|
45
|
+
#include <windows.h>
|
|
46
|
+
|
|
47
|
+
#ifdef _MSC_VER
|
|
48
|
+
#pragma comment(lib, "version.lib")
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
namespace webview {
|
|
52
|
+
namespace detail {
|
|
53
|
+
|
|
54
|
+
// Parses a version string with 1-4 integral components, e.g. "1.2.3.4".
|
|
55
|
+
// Missing or invalid components default to 0, and excess components are ignored.
|
|
56
|
+
template <typename T>
|
|
57
|
+
std::array<unsigned int, 4>
|
|
58
|
+
parse_version(const std::basic_string<T> &version) noexcept {
|
|
59
|
+
using iterator = typename std::basic_string<T>::const_iterator;
|
|
60
|
+
auto parse_component = [](iterator sb, iterator se) -> unsigned int {
|
|
61
|
+
try {
|
|
62
|
+
auto n = std::stol(std::basic_string<T>(sb, se));
|
|
63
|
+
return n < 0 ? 0 : n;
|
|
64
|
+
} catch (std::exception &) {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
auto end = version.end();
|
|
69
|
+
auto sb = version.begin(); // subrange begin
|
|
70
|
+
auto se = sb; // subrange end
|
|
71
|
+
unsigned int ci = 0; // component index
|
|
72
|
+
std::array<unsigned int, 4> components{};
|
|
73
|
+
while (sb != end && se != end && ci < components.size()) {
|
|
74
|
+
if (*se == static_cast<T>('.')) {
|
|
75
|
+
components[ci++] = parse_component(sb, se);
|
|
76
|
+
sb = ++se;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
++se;
|
|
80
|
+
}
|
|
81
|
+
if (sb < se && ci < components.size()) {
|
|
82
|
+
components[ci] = parse_component(sb, se);
|
|
83
|
+
}
|
|
84
|
+
return components;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
template <typename T, std::size_t Length>
|
|
88
|
+
std::array<unsigned int, 4> parse_version(const T (&version)[Length]) noexcept {
|
|
89
|
+
return parse_version(std::basic_string<T>(version, Length));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
inline std::wstring
|
|
93
|
+
get_file_version_string(const std::wstring &file_path) noexcept {
|
|
94
|
+
DWORD dummy_handle; // Unused
|
|
95
|
+
DWORD info_buffer_length =
|
|
96
|
+
GetFileVersionInfoSizeW(file_path.c_str(), &dummy_handle);
|
|
97
|
+
if (info_buffer_length == 0) {
|
|
98
|
+
return std::wstring();
|
|
99
|
+
}
|
|
100
|
+
std::vector<char> info_buffer;
|
|
101
|
+
info_buffer.reserve(info_buffer_length);
|
|
102
|
+
if (!GetFileVersionInfoW(file_path.c_str(), 0, info_buffer_length,
|
|
103
|
+
info_buffer.data())) {
|
|
104
|
+
return std::wstring();
|
|
105
|
+
}
|
|
106
|
+
auto sub_block = L"\\StringFileInfo\\040904B0\\ProductVersion";
|
|
107
|
+
LPWSTR version = nullptr;
|
|
108
|
+
unsigned int version_length = 0;
|
|
109
|
+
if (!VerQueryValueW(info_buffer.data(), sub_block,
|
|
110
|
+
reinterpret_cast<LPVOID *>(&version), &version_length)) {
|
|
111
|
+
return std::wstring();
|
|
112
|
+
}
|
|
113
|
+
if (!version || version_length == 0) {
|
|
114
|
+
return std::wstring();
|
|
115
|
+
}
|
|
116
|
+
return std::wstring(version, version_length);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Compare the specified version against the OS version.
|
|
120
|
+
// Returns less than 0 if the OS version is less.
|
|
121
|
+
// Returns 0 if the versions are equal.
|
|
122
|
+
// Returns greater than 0 if the specified version is greater.
|
|
123
|
+
inline int compare_os_version(unsigned int major, unsigned int minor,
|
|
124
|
+
unsigned int build) {
|
|
125
|
+
// Use RtlGetVersion both to bypass potential issues related to
|
|
126
|
+
// VerifyVersionInfo and manifests, and because both GetVersion and
|
|
127
|
+
// GetVersionEx are deprecated.
|
|
128
|
+
auto ntdll = native_library(L"ntdll.dll");
|
|
129
|
+
if (auto fn = ntdll.get(ntdll_symbols::RtlGetVersion)) {
|
|
130
|
+
RTL_OSVERSIONINFOW vi{};
|
|
131
|
+
vi.dwOSVersionInfoSize = sizeof(vi);
|
|
132
|
+
if (fn(&vi) != 0) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (vi.dwMajorVersion == major) {
|
|
136
|
+
if (vi.dwMinorVersion == minor) {
|
|
137
|
+
return static_cast<int>(vi.dwBuildNumber) - static_cast<int>(build);
|
|
138
|
+
}
|
|
139
|
+
return static_cast<int>(vi.dwMinorVersion) - static_cast<int>(minor);
|
|
140
|
+
}
|
|
141
|
+
return static_cast<int>(vi.dwMajorVersion) - static_cast<int>(major);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
} // namespace detail
|
|
147
|
+
} // namespace webview
|
|
148
|
+
|
|
149
|
+
#endif // defined(WEBVIEW_PLATFORM_WINDOWS)
|
|
150
|
+
#endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
|
|
151
|
+
#endif // WEBVIEW_PLATFORM_WINDOWS_VERSION_HH
|