@aptre/bldr-saucer 0.4.2 → 0.4.4
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/package.json +6 -6
- package/src/fetch_proto.cpp +24 -0
- package/src/fetch_proto.h +4 -0
- package/src/main.cpp +43 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptre/bldr-saucer",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Native webview bridge for Bldr using Saucer",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"release:publish": "git push && git push --tags"
|
|
39
39
|
},
|
|
40
40
|
"optionalDependencies": {
|
|
41
|
-
"@aptre/bldr-saucer-darwin-arm64": "0.4.
|
|
42
|
-
"@aptre/bldr-saucer-darwin-x64": "0.4.
|
|
43
|
-
"@aptre/bldr-saucer-linux-x64": "0.4.
|
|
44
|
-
"@aptre/bldr-saucer-linux-arm64": "0.4.
|
|
45
|
-
"@aptre/bldr-saucer-win32-x64": "0.4.
|
|
41
|
+
"@aptre/bldr-saucer-darwin-arm64": "0.4.4",
|
|
42
|
+
"@aptre/bldr-saucer-darwin-x64": "0.4.4",
|
|
43
|
+
"@aptre/bldr-saucer-linux-x64": "0.4.4",
|
|
44
|
+
"@aptre/bldr-saucer-linux-arm64": "0.4.4",
|
|
45
|
+
"@aptre/bldr-saucer-win32-x64": "0.4.4"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
48
|
"index.js",
|
package/src/fetch_proto.cpp
CHANGED
|
@@ -394,6 +394,30 @@ bool DecodeSaucerInit(const uint8_t* buf, size_t len, SaucerInit& out) {
|
|
|
394
394
|
out.external_links = static_cast<uint32_t>(v);
|
|
395
395
|
break;
|
|
396
396
|
}
|
|
397
|
+
case 3: { // app_name
|
|
398
|
+
if (wire != kLengthDelimited) return false;
|
|
399
|
+
if (!decodeString(buf, len, offset, out.app_name)) return false;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
case 4: { // window_title
|
|
403
|
+
if (wire != kLengthDelimited) return false;
|
|
404
|
+
if (!decodeString(buf, len, offset, out.window_title)) return false;
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
case 5: { // window_width
|
|
408
|
+
if (wire != kVarint) return false;
|
|
409
|
+
uint64_t v;
|
|
410
|
+
if (!decodeVarint(buf, len, offset, v)) return false;
|
|
411
|
+
out.window_width = static_cast<uint32_t>(v);
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
case 6: { // window_height
|
|
415
|
+
if (wire != kVarint) return false;
|
|
416
|
+
uint64_t v;
|
|
417
|
+
if (!decodeVarint(buf, len, offset, v)) return false;
|
|
418
|
+
out.window_height = static_cast<uint32_t>(v);
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
397
421
|
default:
|
|
398
422
|
if (!skipField(buf, len, offset, wire)) return false;
|
|
399
423
|
break;
|
package/src/fetch_proto.h
CHANGED
|
@@ -13,6 +13,10 @@ namespace proto {
|
|
|
13
13
|
struct SaucerInit {
|
|
14
14
|
bool dev_tools = false; // field 1
|
|
15
15
|
uint32_t external_links = 0; // field 2 (enum ExternalLinks)
|
|
16
|
+
std::string app_name; // field 3
|
|
17
|
+
std::string window_title; // field 4
|
|
18
|
+
uint32_t window_width = 0; // field 5
|
|
19
|
+
uint32_t window_height = 0; // field 6
|
|
16
20
|
};
|
|
17
21
|
|
|
18
22
|
// DecodeSaucerInit decodes a SaucerInit protobuf message.
|
package/src/main.cpp
CHANGED
|
@@ -123,8 +123,21 @@ coco::stray start(saucer::application* app) {
|
|
|
123
123
|
.storage_path = storage,
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
// Apply branding from SaucerInit, with defaults.
|
|
127
|
+
std::string title = saucer_init.window_title;
|
|
128
|
+
if (title.empty()) {
|
|
129
|
+
title = saucer_init.app_name;
|
|
130
|
+
}
|
|
131
|
+
if (title.empty()) {
|
|
132
|
+
title = "Bldr";
|
|
133
|
+
}
|
|
134
|
+
window->set_title(title);
|
|
135
|
+
|
|
136
|
+
uint32_t win_w = saucer_init.window_width;
|
|
137
|
+
uint32_t win_h = saucer_init.window_height;
|
|
138
|
+
if (win_w == 0) win_w = 1024;
|
|
139
|
+
if (win_h == 0) win_h = 768;
|
|
140
|
+
window->set_size({static_cast<int>(win_w), static_cast<int>(win_h)});
|
|
128
141
|
|
|
129
142
|
// Handle bldr:// scheme: forward all requests to Go over yamux.
|
|
130
143
|
webview->handle_scheme("bldr", [forwarder](saucer::scheme::request req, saucer::scheme::executor executor) {
|
|
@@ -133,6 +146,20 @@ coco::stray start(saucer::application* app) {
|
|
|
133
146
|
}).detach();
|
|
134
147
|
});
|
|
135
148
|
|
|
149
|
+
// SPA guard: the app only works at /index.html with hash routing.
|
|
150
|
+
// If something tries to navigate to e.g. bldr:///feed.xml, block it.
|
|
151
|
+
webview->on<saucer::webview::event::navigate>([](const saucer::navigation& nav) -> saucer::policy {
|
|
152
|
+
auto target = nav.url();
|
|
153
|
+
if (target.scheme() != "bldr") {
|
|
154
|
+
return saucer::policy::block;
|
|
155
|
+
}
|
|
156
|
+
auto p = target.path().string();
|
|
157
|
+
if (p != "/index.html" && p != "/" && !p.empty()) {
|
|
158
|
+
return saucer::policy::block;
|
|
159
|
+
}
|
|
160
|
+
return saucer::policy::allow;
|
|
161
|
+
});
|
|
162
|
+
|
|
136
163
|
// Navigate via HTML redirect (works around WebKit's loadFileURL issue with custom schemes).
|
|
137
164
|
std::string nav_url = "bldr:///index.html";
|
|
138
165
|
const char* doc_id_env = std::getenv("BLDR_WEB_DOCUMENT_ID");
|
|
@@ -302,7 +329,20 @@ coco::stray start(saucer::application* app) {
|
|
|
302
329
|
}
|
|
303
330
|
|
|
304
331
|
int main() {
|
|
305
|
-
|
|
332
|
+
// Parse SaucerInit early to get the app name for the application ID.
|
|
333
|
+
std::string app_id = "bldr";
|
|
334
|
+
const char* init_b64 = std::getenv("BLDR_SAUCER_INIT");
|
|
335
|
+
if (init_b64) {
|
|
336
|
+
auto data = bldr::proto::Base64Decode(init_b64);
|
|
337
|
+
if (!data.empty()) {
|
|
338
|
+
bldr::proto::SaucerInit init;
|
|
339
|
+
if (bldr::proto::DecodeSaucerInit(data.data(), data.size(), init) && !init.app_name.empty()) {
|
|
340
|
+
app_id = init.app_name;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
auto app_result = saucer::application::create({.id = app_id});
|
|
306
346
|
if (!app_result) {
|
|
307
347
|
std::cerr << "[bldr-saucer] failed to create application" << std::endl;
|
|
308
348
|
return 1;
|