plusui-native-core 0.1.25 → 0.1.27
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/Core/CMakeLists.txt +2 -2
- package/Core/Features/Browser/browser.cpp +32 -33
- package/Core/Features/Menu/menu.cpp +16 -16
- package/Core/include/plusui/browser.hpp +2 -2
- package/Core/include/plusui/menu.hpp +3 -3
- package/package.json +1 -1
- /package/Core/Features/{WindowManager → Window}/window_manager.cpp +0 -0
package/Core/CMakeLists.txt
CHANGED
|
@@ -24,8 +24,8 @@ add_library(plusui STATIC
|
|
|
24
24
|
Features/Bindings/CustomBindings/custom_bindings.cpp
|
|
25
25
|
Features/App/app.cpp
|
|
26
26
|
Features/Window/window.cpp
|
|
27
|
-
Features/
|
|
28
|
-
Features/
|
|
27
|
+
Features/Window/window_manager.cpp
|
|
28
|
+
Features/Window/webview.cpp
|
|
29
29
|
Features/Browser/browser.cpp
|
|
30
30
|
Features/Display/display.cpp
|
|
31
31
|
Features/Tray/tray.cpp
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
#include <iostream>
|
|
3
3
|
#include <plusui/browser.hpp>
|
|
4
4
|
#include <plusui/window.hpp>
|
|
5
|
-
#include <plusui/window.hpp>
|
|
6
5
|
#include <vector>
|
|
7
6
|
|
|
8
7
|
|
|
@@ -17,10 +16,10 @@ namespace plusui {
|
|
|
17
16
|
|
|
18
17
|
// Keep secondary windows alive
|
|
19
18
|
static std::vector<std::shared_ptr<Window>> g_windows;
|
|
20
|
-
static std::vector<std::shared_ptr<
|
|
19
|
+
static std::vector<std::shared_ptr<Window>> g_webviews;
|
|
21
20
|
|
|
22
21
|
struct Browser::Impl {
|
|
23
|
-
|
|
22
|
+
Window *window = nullptr;
|
|
24
23
|
std::map<std::string, std::string> routes;
|
|
25
24
|
std::string currentRoute;
|
|
26
25
|
BrowserState state;
|
|
@@ -32,12 +31,12 @@ struct Browser::Impl {
|
|
|
32
31
|
std::vector<std::function<void(const std::string &)>> loadErrorCallbacks;
|
|
33
32
|
|
|
34
33
|
void updateState() {
|
|
35
|
-
if (
|
|
36
|
-
state.url =
|
|
37
|
-
state.title =
|
|
38
|
-
state.canGoBack =
|
|
39
|
-
state.canGoForward =
|
|
40
|
-
state.isLoading =
|
|
34
|
+
if (window) {
|
|
35
|
+
state.url = window->getURL();
|
|
36
|
+
state.title = window->getTitle();
|
|
37
|
+
state.canGoBack = window->canGoBack();
|
|
38
|
+
state.canGoForward = window->canGoForward();
|
|
39
|
+
state.isLoading = window->isLoading();
|
|
41
40
|
|
|
42
41
|
for (auto &cb : stateCallbacks) {
|
|
43
42
|
cb(state);
|
|
@@ -58,24 +57,24 @@ Browser::Browser() : pImpl(std::make_shared<Impl>()) {}
|
|
|
58
57
|
|
|
59
58
|
Browser::~Browser() = default;
|
|
60
59
|
|
|
61
|
-
Browser Browser::create(
|
|
60
|
+
Browser Browser::create(Window *window) {
|
|
62
61
|
Browser browser;
|
|
63
|
-
browser.pImpl->
|
|
62
|
+
browser.pImpl->window = window;
|
|
64
63
|
|
|
65
|
-
if (
|
|
66
|
-
|
|
64
|
+
if (window) {
|
|
65
|
+
window->onNavigationStart([impl = browser.pImpl](const std::string &url) {
|
|
67
66
|
impl->notifyNavigate(url);
|
|
68
67
|
return true;
|
|
69
68
|
});
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
window->onLoadStart([impl = browser.pImpl]() {
|
|
72
71
|
impl->state.isLoading = true;
|
|
73
72
|
for (auto &cb : impl->loadStartCallbacks) {
|
|
74
73
|
cb();
|
|
75
74
|
}
|
|
76
75
|
});
|
|
77
76
|
|
|
78
|
-
|
|
77
|
+
window->onLoadEnd([impl = browser.pImpl]() {
|
|
79
78
|
impl->state.isLoading = false;
|
|
80
79
|
impl->updateState();
|
|
81
80
|
for (auto &cb : impl->loadEndCallbacks) {
|
|
@@ -83,7 +82,7 @@ Browser Browser::create(WebView *webview) {
|
|
|
83
82
|
}
|
|
84
83
|
});
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
window->onLoadError(
|
|
87
86
|
[impl = browser.pImpl](const std::string &error, int code) {
|
|
88
87
|
(void)code; // Suppress unused warning
|
|
89
88
|
impl->state.isLoading = false;
|
|
@@ -97,35 +96,35 @@ Browser Browser::create(WebView *webview) {
|
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
void Browser::navigate(const std::string &url) {
|
|
100
|
-
if (pImpl->
|
|
101
|
-
pImpl->
|
|
99
|
+
if (pImpl->window) {
|
|
100
|
+
pImpl->window->navigate(url);
|
|
102
101
|
pImpl->notifyNavigate(url);
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
void Browser::goBack() {
|
|
107
|
-
if (pImpl->
|
|
108
|
-
pImpl->
|
|
106
|
+
if (pImpl->window && pImpl->window->canGoBack()) {
|
|
107
|
+
pImpl->window->goBack();
|
|
109
108
|
pImpl->updateState();
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
void Browser::goForward() {
|
|
114
|
-
if (pImpl->
|
|
115
|
-
pImpl->
|
|
113
|
+
if (pImpl->window && pImpl->window->canGoForward()) {
|
|
114
|
+
pImpl->window->goForward();
|
|
116
115
|
pImpl->updateState();
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
void Browser::reload() {
|
|
121
|
-
if (pImpl->
|
|
122
|
-
pImpl->
|
|
120
|
+
if (pImpl->Window) {
|
|
121
|
+
pImpl->Window->reload();
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
void Browser::stop() {
|
|
127
|
-
if (pImpl->
|
|
128
|
-
pImpl->
|
|
126
|
+
if (pImpl->Window) {
|
|
127
|
+
pImpl->Window->stop();
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
|
|
@@ -149,9 +148,9 @@ void Browser::openNewWindow(const std::string &url) {
|
|
|
149
148
|
win->show();
|
|
150
149
|
g_windows.push_back(win);
|
|
151
150
|
|
|
152
|
-
|
|
153
|
-
auto wv = std::make_shared<
|
|
154
|
-
|
|
151
|
+
WindowConfig webConfig;
|
|
152
|
+
auto wv = std::make_shared<Window>(
|
|
153
|
+
Window::create(win->nativeHandle(), webConfig));
|
|
155
154
|
wv->setWindow(win);
|
|
156
155
|
wv->navigate(url);
|
|
157
156
|
g_webviews.push_back(wv);
|
|
@@ -168,21 +167,21 @@ void Browser::openNewWindow(const std::string &url) {
|
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
std::string Browser::getURL() const {
|
|
171
|
-
return pImpl->
|
|
170
|
+
return pImpl->window ? pImpl->window->getURL() : "";
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
std::string Browser::getTitle() const {
|
|
175
|
-
return pImpl->
|
|
174
|
+
return pImpl->window ? pImpl->window->getTitle() : "";
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
BrowserState Browser::getState() const { return pImpl->state; }
|
|
179
178
|
|
|
180
179
|
bool Browser::canGoBack() const {
|
|
181
|
-
return pImpl->
|
|
180
|
+
return pImpl->window ? pImpl->window->canGoBack() : false;
|
|
182
181
|
}
|
|
183
182
|
|
|
184
183
|
bool Browser::canGoForward() const {
|
|
185
|
-
return pImpl->
|
|
184
|
+
return pImpl->window ? pImpl->window->canGoForward() : false;
|
|
186
185
|
}
|
|
187
186
|
|
|
188
187
|
bool Browser::isLoading() const { return pImpl->state.isLoading; }
|
|
@@ -63,9 +63,9 @@ static bool extractJsonBool(const std::string &json, const std::string &key,
|
|
|
63
63
|
return defaultVal;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
void MenuBindings::registerBindings(
|
|
66
|
+
void MenuBindings::registerBindings(Window &window) {
|
|
67
67
|
// Binding: menu.create
|
|
68
|
-
|
|
68
|
+
window.bind("plusui_menu_create",
|
|
69
69
|
[this](const std::string &args) -> std::string {
|
|
70
70
|
auto items = parseMenuItems(args);
|
|
71
71
|
std::string menuId = MenuManager::instance().createMenu(items);
|
|
@@ -73,7 +73,7 @@ void MenuBindings::registerBindings(WebView &webview) {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
// Binding: menu.popup
|
|
76
|
-
|
|
76
|
+
window.bind("plusui_menu_popup", [](const std::string &args) -> std::string {
|
|
77
77
|
// Parse: [menuId, x, y]
|
|
78
78
|
std::string menuId = extractJsonString(args, "menuId");
|
|
79
79
|
|
|
@@ -103,7 +103,7 @@ void MenuBindings::registerBindings(WebView &webview) {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
// Binding: menu.setApplicationMenu
|
|
106
|
-
|
|
106
|
+
window.bind("plusui_menu_setAppMenu",
|
|
107
107
|
[this](const std::string &args) -> std::string {
|
|
108
108
|
auto items = parseMenuItems(args);
|
|
109
109
|
MenuBarData data;
|
|
@@ -113,7 +113,7 @@ void MenuBindings::registerBindings(WebView &webview) {
|
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
// Binding: menu.destroy
|
|
116
|
-
|
|
116
|
+
window.bind("plusui_menu_destroy",
|
|
117
117
|
[](const std::string &args) -> std::string {
|
|
118
118
|
std::string menuId = extractJsonString(args, "menuId");
|
|
119
119
|
MenuManager::instance().destroyMenu(menuId);
|
|
@@ -121,7 +121,7 @@ void MenuBindings::registerBindings(WebView &webview) {
|
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
// Binding: menu.close
|
|
124
|
-
|
|
124
|
+
window.bind("plusui_menu_close", [](const std::string &args) -> std::string {
|
|
125
125
|
std::string menuId = extractJsonString(args, "menuId");
|
|
126
126
|
Menu *menu = MenuManager::instance().getMenu(menuId);
|
|
127
127
|
if (menu) {
|
|
@@ -131,7 +131,7 @@ void MenuBindings::registerBindings(WebView &webview) {
|
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
// Inject JavaScript bridge for context menu handling
|
|
134
|
-
|
|
134
|
+
window.eval(R"(
|
|
135
135
|
// PlusUI Context Menu Bridge
|
|
136
136
|
window.__plusui_contextMenu = {
|
|
137
137
|
enabled: false,
|
|
@@ -184,7 +184,7 @@ void MenuBindings::registerBindings(WebView &webview) {
|
|
|
184
184
|
)");
|
|
185
185
|
|
|
186
186
|
// Binding: Show context menu
|
|
187
|
-
|
|
187
|
+
window.bind("plusui_menu_showContext",
|
|
188
188
|
[this](const std::string &args) -> std::string {
|
|
189
189
|
if (!contextMenuEnabled_ || contextMenuItems_.empty()) {
|
|
190
190
|
return "null";
|
|
@@ -223,20 +223,20 @@ void MenuBindings::registerBindings(WebView &webview) {
|
|
|
223
223
|
});
|
|
224
224
|
|
|
225
225
|
// Binding: Enable custom context menu
|
|
226
|
-
|
|
227
|
-
[this, &
|
|
226
|
+
window.bind("plusui_menu_enableContext",
|
|
227
|
+
[this, &window](const std::string &args) -> std::string {
|
|
228
228
|
(void)args; // Suppress unused warning
|
|
229
229
|
contextMenuEnabled_ = true;
|
|
230
|
-
|
|
230
|
+
window.eval("window.__plusui_contextMenu.enabled = true;");
|
|
231
231
|
return "null";
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
// Binding: Disable custom context menu
|
|
235
|
-
|
|
236
|
-
[this, &
|
|
235
|
+
window.bind("plusui_menu_disableContext",
|
|
236
|
+
[this, &window](const std::string &args) -> std::string {
|
|
237
237
|
(void)args; // Suppress unused warning
|
|
238
238
|
contextMenuEnabled_ = false;
|
|
239
|
-
|
|
239
|
+
window.eval("window.__plusui_contextMenu.enabled = false;");
|
|
240
240
|
return "null";
|
|
241
241
|
});
|
|
242
242
|
}
|
|
@@ -419,9 +419,9 @@ void ContextMenuManager::setMenuForSelector(
|
|
|
419
419
|
selectorMenus_[selector] = items;
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
void ContextMenuManager::attachToWebView(
|
|
422
|
+
void ContextMenuManager::attachToWebView(Window &window) {
|
|
423
423
|
// Inject context menu override script
|
|
424
|
-
|
|
424
|
+
window.eval(R"(
|
|
425
425
|
(function() {
|
|
426
426
|
document.addEventListener('contextmenu', function(e) {
|
|
427
427
|
// Check if we should use custom context menu
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
namespace plusui {
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class Window;
|
|
11
11
|
|
|
12
12
|
struct BrowserState {
|
|
13
13
|
std::string url;
|
|
@@ -31,7 +31,7 @@ public:
|
|
|
31
31
|
Browser();
|
|
32
32
|
~Browser();
|
|
33
33
|
|
|
34
|
-
static Browser create(
|
|
34
|
+
static Browser create(Window *window);
|
|
35
35
|
|
|
36
36
|
void navigate(const std::string &url);
|
|
37
37
|
void goBack();
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
#include <vector>
|
|
9
9
|
|
|
10
10
|
namespace plusui {
|
|
11
|
-
class
|
|
11
|
+
class Window;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
namespace plusui {
|
|
@@ -105,7 +105,7 @@ public:
|
|
|
105
105
|
MenuBindings() = default;
|
|
106
106
|
~MenuBindings() = default;
|
|
107
107
|
|
|
108
|
-
void registerBindings(
|
|
108
|
+
void registerBindings(Window &window);
|
|
109
109
|
void setItemClickCallback(
|
|
110
110
|
std::function<void(const std::string &menuId, const std::string &itemId)>
|
|
111
111
|
callback);
|
|
@@ -131,7 +131,7 @@ public:
|
|
|
131
131
|
void setDefaultMenu(const std::vector<MenuItem> &items);
|
|
132
132
|
void setMenuForSelector(const std::string &selector,
|
|
133
133
|
const std::vector<MenuItem> &items);
|
|
134
|
-
void attachToWebView(
|
|
134
|
+
void attachToWebView(Window &window);
|
|
135
135
|
void handleRightClick(int x, int y, const std::string &targetSelector);
|
|
136
136
|
void onItemClick(std::function<void(const std::string &itemId,
|
|
137
137
|
const std::string &targetSelector)>
|
package/package.json
CHANGED
|
File without changes
|