plusui-native-core 0.1.85 → 0.1.88
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/API/index.ts
CHANGED
|
@@ -18,6 +18,53 @@
|
|
|
18
18
|
* and generates typed channel objects for both frontend and backend.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
// ============================================================
|
|
22
|
+
// INTERNAL: Initialize Native Bridge Polyfill
|
|
23
|
+
// ============================================================
|
|
24
|
+
if (typeof window !== 'undefined') {
|
|
25
|
+
const win = window as any;
|
|
26
|
+
if (!win.__invoke__) {
|
|
27
|
+
const pendingPromises = new Map<string, { resolve: (val: any) => void; reject: (err: any) => void }>();
|
|
28
|
+
let callId = 0;
|
|
29
|
+
|
|
30
|
+
win.__response__ = function (id: string, result: any, error?: any) {
|
|
31
|
+
if (pendingPromises.has(id)) {
|
|
32
|
+
const { resolve, reject } = pendingPromises.get(id)!;
|
|
33
|
+
pendingPromises.delete(id);
|
|
34
|
+
if (error) {
|
|
35
|
+
reject(new Error(error));
|
|
36
|
+
} else {
|
|
37
|
+
resolve(result);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
win.__invoke__ = function (method: string, params: any[] = []): Promise<any> {
|
|
43
|
+
if (!win.__native_invoke__) {
|
|
44
|
+
console.warn(`[PlusUI] API not initialized: __native_invoke__ missing. Running in mock mode for '${method}'.`);
|
|
45
|
+
return Promise.resolve(null);
|
|
46
|
+
}
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const id = String(++callId);
|
|
49
|
+
pendingPromises.set(id, { resolve, reject });
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const payload = JSON.stringify({
|
|
53
|
+
jsonrpc: '2.0',
|
|
54
|
+
id,
|
|
55
|
+
method,
|
|
56
|
+
params
|
|
57
|
+
});
|
|
58
|
+
win.__native_invoke__(payload);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
pendingPromises.delete(id);
|
|
61
|
+
reject(err);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
21
68
|
// ============================================================
|
|
22
69
|
// BUILT-IN FEATURES - Direct methods only (NO .on/.emit)
|
|
23
70
|
// ============================================================
|
package/Core/CMakeLists.txt
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#include <plusui/router.hpp>
|
|
2
|
+
|
|
3
|
+
namespace plusui {
|
|
4
|
+
|
|
5
|
+
struct Router::Impl {
|
|
6
|
+
std::map<std::string, std::string> routes;
|
|
7
|
+
std::string initialRoute = "/";
|
|
8
|
+
std::map<std::string, std::string> currentRoutes;
|
|
9
|
+
std::vector<RouteChangeCallback> callbacks;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
Router::Router() : pImpl(std::make_unique<Impl>()) {}
|
|
13
|
+
Router::~Router() = default;
|
|
14
|
+
|
|
15
|
+
Router& Router::instance() {
|
|
16
|
+
static Router router;
|
|
17
|
+
return router;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void Router::setRoutes(const std::map<std::string, std::string>& routes) {
|
|
21
|
+
pImpl->routes = routes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
std::map<std::string, std::string> Router::getRoutes() const {
|
|
25
|
+
return pImpl->routes;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void Router::push(const std::string& route, const std::string& windowId) {
|
|
29
|
+
std::string wid = windowId.empty() ? "__main__" : windowId;
|
|
30
|
+
pImpl->currentRoutes[wid] = route;
|
|
31
|
+
for (auto& cb : pImpl->callbacks) {
|
|
32
|
+
cb(route, wid);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void Router::replace(const std::string& route, const std::string& windowId) {
|
|
37
|
+
std::string wid = windowId.empty() ? "__main__" : windowId;
|
|
38
|
+
pImpl->currentRoutes[wid] = route;
|
|
39
|
+
for (auto& cb : pImpl->callbacks) {
|
|
40
|
+
cb(route, wid);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
std::string Router::getCurrentRoute(const std::string& windowId) const {
|
|
45
|
+
std::string wid = windowId.empty() ? "__main__" : windowId;
|
|
46
|
+
auto it = pImpl->currentRoutes.find(wid);
|
|
47
|
+
if (it != pImpl->currentRoutes.end()) {
|
|
48
|
+
return it->second;
|
|
49
|
+
}
|
|
50
|
+
return pImpl->initialRoute;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void Router::setInitialRoute(const std::string& route) {
|
|
54
|
+
pImpl->initialRoute = route;
|
|
55
|
+
pImpl->currentRoutes["__main__"] = route;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void Router::onRouteChange(RouteChangeCallback callback) {
|
|
59
|
+
pImpl->callbacks.push_back(std::move(callback));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
} // namespace plusui
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#ifndef PLUSUI_ROUTER_H
|
|
2
|
+
#define PLUSUI_ROUTER_H
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <map>
|
|
6
|
+
#include <functional>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace plusui {
|
|
11
|
+
|
|
12
|
+
class Router {
|
|
13
|
+
public:
|
|
14
|
+
Router();
|
|
15
|
+
~Router();
|
|
16
|
+
|
|
17
|
+
static Router& instance();
|
|
18
|
+
|
|
19
|
+
void setRoutes(const std::map<std::string, std::string>& routes);
|
|
20
|
+
std::map<std::string, std::string> getRoutes() const;
|
|
21
|
+
|
|
22
|
+
void push(const std::string& route, const std::string& windowId = "");
|
|
23
|
+
void replace(const std::string& route, const std::string& windowId = "");
|
|
24
|
+
|
|
25
|
+
std::string getCurrentRoute(const std::string& windowId = "") const;
|
|
26
|
+
void setInitialRoute(const std::string& route);
|
|
27
|
+
|
|
28
|
+
using RouteChangeCallback = std::function<void(const std::string& route, const std::string& windowId)>;
|
|
29
|
+
void onRouteChange(RouteChangeCallback callback);
|
|
30
|
+
|
|
31
|
+
private:
|
|
32
|
+
struct Impl;
|
|
33
|
+
std::unique_ptr<Impl> pImpl;
|
|
34
|
+
|
|
35
|
+
// Prevent copying
|
|
36
|
+
Router(const Router&) = delete;
|
|
37
|
+
Router& operator=(const Router&) = delete;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
} // namespace plusui
|
|
41
|
+
|
|
42
|
+
#endif // PLUSUI_ROUTER_H
|