buckyos 0.7.200 → 0.7.204
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/README.md +2 -0
- package/cli/dist/cli.mjs +42 -1
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/pikg.ts +7 -0
- package/cli/modules/pikg_protocol.ts +37 -0
- package/cli/version.ts +1 -1
- package/dist/{aiws_write-2f0baa6f.mjs → aiws_write-0606e098.mjs} +707 -291
- package/dist/aiws_write-0606e098.mjs.map +1 -0
- package/dist/aiws_write-7a9d71d1.js +13 -0
- package/dist/aiws_write-7a9d71d1.js.map +1 -0
- package/dist/app-frame.cjs +1 -1
- package/dist/app-frame.cjs.map +1 -1
- package/dist/app-frame.d.ts +131 -24
- package/dist/app-frame.d.ts.map +1 -1
- package/dist/app-frame.mjs +235 -70
- package/dist/app-frame.mjs.map +1 -1
- package/dist/audio.d.ts +84 -0
- package/dist/audio.d.ts.map +1 -0
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +5 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +249 -219
- package/dist/browser.mjs.map +1 -1
- package/dist/content.cjs +1 -1
- package/dist/content.cjs.map +1 -1
- package/dist/content.mjs +357 -34
- package/dist/content.mjs.map +1 -1
- package/dist/{content_objid-0e63f1ff.js → content_objid-c69251aa.js} +2 -2
- package/dist/{content_objid-0e63f1ff.js.map → content_objid-c69251aa.js.map} +1 -1
- package/dist/{content_objid-8ebeead4.mjs → content_objid-e3fc56dd.mjs} +2 -2
- package/dist/{content_objid-8ebeead4.mjs.map → content_objid-e3fc56dd.mjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +249 -219
- package/dist/index.mjs.map +1 -1
- package/dist/msg_center_client.d.ts +37 -0
- package/dist/msg_center_client.d.ts.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +5 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.mjs +246 -215
- package/dist/node.mjs.map +1 -1
- package/dist/open-app.cjs +2 -0
- package/dist/open-app.cjs.map +1 -0
- package/dist/open-app.mjs +160 -0
- package/dist/open-app.mjs.map +1 -0
- package/dist/open_app.d.ts +95 -0
- package/dist/open_app.d.ts.map +1 -0
- package/dist/provision.cjs +1 -1
- package/dist/provision.cjs.map +1 -1
- package/dist/provision.mjs +1 -3
- package/dist/provision.mjs.map +1 -1
- package/dist/provision_activate.d.ts.map +1 -1
- package/dist/runtime_env-39e4df98.mjs +44 -0
- package/dist/runtime_env-39e4df98.mjs.map +1 -0
- package/dist/runtime_env-6396e1eb.js +2 -0
- package/dist/runtime_env-6396e1eb.js.map +1 -0
- package/dist/runtime_env.d.ts +53 -0
- package/dist/runtime_env.d.ts.map +1 -0
- package/dist/sdk_core.d.ts +4 -2
- package/dist/sdk_core.d.ts.map +1 -1
- package/dist/zone_clients.d.ts +35 -0
- package/dist/zone_clients.d.ts.map +1 -0
- package/package.json +6 -1
- package/dist/aiws_write-2f0baa6f.mjs.map +0 -1
- package/dist/aiws_write-ad97b561.js +0 -13
- package/dist/aiws_write-ad97b561.js.map +0 -1
- package/dist/content_mime-dc80d960.js +0 -2
- package/dist/content_mime-dc80d960.js.map +0 -1
- package/dist/content_mime-e42d5f8d.mjs +0 -335
- package/dist/content_mime-e42d5f8d.mjs.map +0 -1
package/dist/app-frame.mjs
CHANGED
|
@@ -1,8 +1,66 @@
|
|
|
1
1
|
import { SystemDialogError, isOpenRequest, readContentHints, readSelectDialogResult, systemOpenUrl, SELECT_DIALOG_PATH, isTransferableRef, isTransferableSession, SYSTEM_DIALOG_ERROR_CODES } from "./content.mjs";
|
|
2
|
-
import "./
|
|
2
|
+
import { readAppOpenRequest, systemOpenAppUrl } from "./open-app.mjs";
|
|
3
|
+
import { g as getBuckyApi } from "./runtime_env-39e4df98.mjs";
|
|
3
4
|
import "./object_url-20e94b67.mjs";
|
|
4
5
|
import "./ndn_types-0fac2499.mjs";
|
|
5
6
|
const dialogErrorCode = (value) => SYSTEM_DIALOG_ERROR_CODES.includes(value) ? value : "protocol";
|
|
7
|
+
const text = (value, max) => typeof value === "string" ? value.slice(0, max) : void 0;
|
|
8
|
+
function readHeaderList(value, read) {
|
|
9
|
+
if (!Array.isArray(value))
|
|
10
|
+
return [];
|
|
11
|
+
return value.slice(0, 32).flatMap((entry) => {
|
|
12
|
+
const v = entry;
|
|
13
|
+
if (!v || typeof v !== "object" || typeof v.id !== "string" || !v.id || v.id.length > 128 || typeof v.label !== "string")
|
|
14
|
+
return [];
|
|
15
|
+
return [read(v, { id: v.id, label: v.label.slice(0, 128) })];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function readHeader(p) {
|
|
19
|
+
const header = {};
|
|
20
|
+
const title = text(p.title, 256);
|
|
21
|
+
if (title !== void 0)
|
|
22
|
+
header.title = title;
|
|
23
|
+
if (Array.isArray(p.second_row))
|
|
24
|
+
header.second_row = readHeaderList(p.second_row, (v, base) => ({ ...base, ...v.active === true ? { active: true } : {} }));
|
|
25
|
+
if (Array.isArray(p.menu))
|
|
26
|
+
header.menu = readHeaderList(p.menu, (v, base) => ({ ...base, ...typeof v.icon === "string" ? { icon: v.icon.slice(0, 2048) } : {}, ...v.danger === true ? { danger: true } : {} }));
|
|
27
|
+
if (p.search === null)
|
|
28
|
+
header.search = null;
|
|
29
|
+
else if (p.search && typeof p.search === "object") {
|
|
30
|
+
const search = p.search;
|
|
31
|
+
const placeholder = text(search.placeholder, 128), value = text(search.value, 1024);
|
|
32
|
+
header.search = { ...placeholder !== void 0 ? { placeholder } : {}, ...value !== void 0 ? { value } : {} };
|
|
33
|
+
}
|
|
34
|
+
if (typeof p.back === "boolean")
|
|
35
|
+
header.back = p.back;
|
|
36
|
+
return header;
|
|
37
|
+
}
|
|
38
|
+
function windowTransport(peer, origin) {
|
|
39
|
+
return {
|
|
40
|
+
post: (message) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = peer()) == null ? void 0 : _a.postMessage(message, origin);
|
|
43
|
+
},
|
|
44
|
+
onMessage: (cb) => {
|
|
45
|
+
const own = window;
|
|
46
|
+
const listener = (event) => {
|
|
47
|
+
if (event.source === peer() && event.origin === origin)
|
|
48
|
+
cb(event.data);
|
|
49
|
+
};
|
|
50
|
+
own.addEventListener("message", listener);
|
|
51
|
+
return () => own.removeEventListener("message", listener);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function bridgeTransport(api) {
|
|
56
|
+
return {
|
|
57
|
+
post: (message) => {
|
|
58
|
+
void Promise.resolve(api.call("frame.post", message)).catch(() => {
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
onMessage: (cb) => api.on("frame.message", cb)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
6
64
|
const envelope = (type, payload, extra = {}) => ({ protocol: "buckyos.app-frame", version: 1, type, payload, ...extra });
|
|
7
65
|
const isMessage = (value) => {
|
|
8
66
|
if (!value || typeof value !== "object")
|
|
@@ -10,51 +68,95 @@ const isMessage = (value) => {
|
|
|
10
68
|
const v = value;
|
|
11
69
|
return v.protocol === "buckyos.app-frame" && v.version === 1 && typeof v.type === "string" && !!v.payload && typeof v.payload === "object";
|
|
12
70
|
};
|
|
71
|
+
const FRAME_NAME_PREFIX = "buckyos.app-frame:";
|
|
72
|
+
function appFrameName(nonce) {
|
|
73
|
+
return FRAME_NAME_PREFIX + nonce;
|
|
74
|
+
}
|
|
75
|
+
const OPEN_LIMIT = 5;
|
|
13
76
|
class AppFrameHost {
|
|
14
77
|
constructor(options) {
|
|
15
|
-
this.options = options;
|
|
16
78
|
this.ready = false;
|
|
17
79
|
this.capabilities = [];
|
|
80
|
+
this.header = {};
|
|
18
81
|
this.pending = /* @__PURE__ */ new Map();
|
|
19
|
-
this.
|
|
20
|
-
this.opens = [];
|
|
82
|
+
this.opens = /* @__PURE__ */ new Map();
|
|
21
83
|
this.dialogOpen = false;
|
|
22
|
-
|
|
84
|
+
this.callbacks = options;
|
|
85
|
+
this.framed = !options.transport;
|
|
86
|
+
this.init = options.transport ? { ...options.init, nonce: "" } : options.init;
|
|
87
|
+
this.channel = options.transport ?? windowTransport(options.target, options.origin);
|
|
88
|
+
this.detach = this.channel.onMessage((message) => this.receive(message));
|
|
89
|
+
}
|
|
90
|
+
limited(type) {
|
|
91
|
+
const recent = (this.opens.get(type) ?? []).filter((t) => t > Date.now() - 1e4);
|
|
92
|
+
this.opens.set(type, recent);
|
|
93
|
+
if (recent.length >= OPEN_LIMIT)
|
|
94
|
+
return true;
|
|
95
|
+
recent.push(Date.now());
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
async appOpen(id, payload) {
|
|
99
|
+
const reply = (result) => {
|
|
100
|
+
if (this.ready)
|
|
101
|
+
this.channel.post(envelope("app.openResult", result, { replyTo: id }));
|
|
102
|
+
};
|
|
103
|
+
if (!this.callbacks.onAppOpen)
|
|
104
|
+
return reply({ ok: false, code: "unsupported" });
|
|
105
|
+
const request = readAppOpenRequest(payload);
|
|
106
|
+
if (!request || this.limited("app.open"))
|
|
107
|
+
return reply({ ok: false, code: "denied" });
|
|
108
|
+
try {
|
|
109
|
+
reply(await this.callbacks.onAppOpen(request));
|
|
110
|
+
} catch {
|
|
111
|
+
reply({ ok: false, code: "denied" });
|
|
112
|
+
}
|
|
23
113
|
}
|
|
24
114
|
async systemDialog(id, path, params) {
|
|
25
115
|
const reply = (payload) => {
|
|
26
|
-
var _a;
|
|
27
116
|
if (this.ready)
|
|
28
|
-
|
|
117
|
+
this.channel.post(envelope("sysdlg.openResult", payload, { replyTo: id }));
|
|
29
118
|
};
|
|
30
|
-
if (!this.
|
|
119
|
+
if (!this.callbacks.onSystemDialog || typeof path !== "string")
|
|
31
120
|
return reply({ ok: false, code: "unsupported" });
|
|
32
121
|
if (this.dialogOpen)
|
|
33
122
|
return reply({ ok: false, code: "busy" });
|
|
34
123
|
this.dialogOpen = true;
|
|
35
124
|
try {
|
|
36
|
-
reply(await this.
|
|
125
|
+
reply(await this.callbacks.onSystemDialog(path, params));
|
|
37
126
|
} catch (error) {
|
|
38
127
|
reply({ ok: false, code: error instanceof SystemDialogError ? error.code : "closed" });
|
|
39
128
|
} finally {
|
|
40
129
|
this.dialogOpen = false;
|
|
41
130
|
}
|
|
42
131
|
}
|
|
43
|
-
receive(
|
|
44
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
45
|
-
if (
|
|
132
|
+
receive(m) {
|
|
133
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
134
|
+
if (!isMessage(m))
|
|
46
135
|
return;
|
|
47
|
-
const m = event.data;
|
|
48
136
|
const p = m.payload;
|
|
49
137
|
if (m.type === "frame.hello") {
|
|
50
|
-
if (
|
|
138
|
+
if (!Array.isArray(p.appCapabilities))
|
|
51
139
|
return;
|
|
140
|
+
if (this.framed) {
|
|
141
|
+
if (p.nonce !== this.init.nonce)
|
|
142
|
+
return;
|
|
143
|
+
} else {
|
|
144
|
+
if (typeof p.nonce !== "string" || !p.nonce || p.nonce.length > 128)
|
|
145
|
+
return;
|
|
146
|
+
if (p.nonce !== this.init.nonce)
|
|
147
|
+
this.failPending("App frame reloaded");
|
|
148
|
+
this.init = { ...this.init, nonce: p.nonce };
|
|
149
|
+
}
|
|
52
150
|
this.ready = true;
|
|
53
151
|
this.capabilities = p.appCapabilities.filter((c) => typeof c === "string");
|
|
54
|
-
this.send("frame.init", this.
|
|
152
|
+
this.send("frame.init", this.init);
|
|
55
153
|
if (this.focused !== void 0)
|
|
56
154
|
this.send("frame.focusChanged", { focused: this.focused });
|
|
57
|
-
|
|
155
|
+
if (Object.keys(this.header).length) {
|
|
156
|
+
this.header = {};
|
|
157
|
+
(_b = (_a = this.callbacks).onHeader) == null ? void 0 : _b.call(_a, {});
|
|
158
|
+
}
|
|
159
|
+
(_d = (_c = this.callbacks).onReady) == null ? void 0 : _d.call(_c);
|
|
58
160
|
return;
|
|
59
161
|
}
|
|
60
162
|
if (!this.ready)
|
|
@@ -69,24 +171,26 @@ class AppFrameHost {
|
|
|
69
171
|
return;
|
|
70
172
|
}
|
|
71
173
|
if (m.type === "window.setTitle" && typeof p.title === "string")
|
|
72
|
-
(
|
|
174
|
+
(_f = (_e = this.callbacks).onTitle) == null ? void 0 : _f.call(_e, p.title.slice(0, 256), p.dirty === true);
|
|
73
175
|
if (m.type === "window.requestClose")
|
|
74
|
-
(
|
|
176
|
+
(_h = (_g = this.callbacks).onRequestClose) == null ? void 0 : _h.call(_g);
|
|
177
|
+
if (m.type === "header.set") {
|
|
178
|
+
this.header = { ...this.header, ...readHeader(p) };
|
|
179
|
+
(_j = (_i = this.callbacks).onHeader) == null ? void 0 : _j.call(_i, this.header);
|
|
180
|
+
}
|
|
181
|
+
if (m.type === "app.open" && typeof m.id === "string")
|
|
182
|
+
void this.appOpen(m.id, p);
|
|
75
183
|
if (m.type === "sysdlg.open" && typeof m.id === "string")
|
|
76
184
|
void this.systemDialog(m.id, p.path, p.params);
|
|
77
185
|
if (m.type === "content.open" && (p.target === "default" || p.target === "preview" || p.target === "chooser")) {
|
|
78
186
|
const request = { ...p.request, requestId: crypto.randomUUID() };
|
|
79
|
-
if (!isOpenRequest(request))
|
|
187
|
+
if (!isOpenRequest(request) || this.limited("content.open"))
|
|
80
188
|
return;
|
|
81
|
-
|
|
82
|
-
if (this.opens.length >= 5)
|
|
83
|
-
return;
|
|
84
|
-
this.opens.push(Date.now());
|
|
85
|
-
(_h = (_g = this.options).onContentOpen) == null ? void 0 : _h.call(_g, request, p.target, { newWindow: p.newWindow === true, hints: readContentHints(p.hints) });
|
|
189
|
+
(_l = (_k = this.callbacks).onContentOpen) == null ? void 0 : _l.call(_k, request, p.target, { newWindow: p.newWindow === true, hints: readContentHints(p.hints) });
|
|
86
190
|
}
|
|
87
191
|
}
|
|
88
192
|
update(init) {
|
|
89
|
-
this.
|
|
193
|
+
this.init = { ...this.init, ...init };
|
|
90
194
|
}
|
|
91
195
|
/** Reports whether the App's window is the focused one; only a change is sent. */
|
|
92
196
|
setFocused(focused) {
|
|
@@ -95,23 +199,25 @@ class AppFrameHost {
|
|
|
95
199
|
this.focused = focused;
|
|
96
200
|
this.send("frame.focusChanged", { focused });
|
|
97
201
|
}
|
|
202
|
+
/** Tells the App what happened in the header the host draws for it. */
|
|
203
|
+
headerEvent(event) {
|
|
204
|
+
this.send("header.event", event);
|
|
205
|
+
}
|
|
98
206
|
send(type, payload) {
|
|
99
|
-
var _a;
|
|
100
207
|
if (this.ready)
|
|
101
|
-
|
|
208
|
+
this.channel.post(envelope(type, payload));
|
|
102
209
|
}
|
|
103
210
|
request(type, payload, timeout = 3e3) {
|
|
104
211
|
if (!this.ready)
|
|
105
212
|
return Promise.reject(new Error("App frame is not ready"));
|
|
106
213
|
const id = crypto.randomUUID();
|
|
107
214
|
return new Promise((resolve, reject) => {
|
|
108
|
-
var _a;
|
|
109
215
|
const timer = setTimeout(() => {
|
|
110
216
|
this.pending.delete(id);
|
|
111
217
|
reject(new Error("App frame timed out"));
|
|
112
218
|
}, timeout);
|
|
113
219
|
this.pending.set(id, { resolve, reject, timer, type });
|
|
114
|
-
|
|
220
|
+
this.channel.post(envelope(type, payload, { id }));
|
|
115
221
|
});
|
|
116
222
|
}
|
|
117
223
|
async open(request) {
|
|
@@ -130,20 +236,23 @@ class AppFrameHost {
|
|
|
130
236
|
return false;
|
|
131
237
|
return (await this.request("frame.back", {})).handled === true;
|
|
132
238
|
}
|
|
133
|
-
|
|
134
|
-
window.removeEventListener("message", this.listener);
|
|
239
|
+
failPending(reason) {
|
|
135
240
|
this.pending.forEach((p) => {
|
|
136
241
|
clearTimeout(p.timer);
|
|
137
|
-
p.reject(new Error(
|
|
242
|
+
p.reject(new Error(reason));
|
|
138
243
|
});
|
|
139
244
|
this.pending.clear();
|
|
245
|
+
}
|
|
246
|
+
dispose() {
|
|
247
|
+
this.detach();
|
|
248
|
+
this.failPending("App frame disposed");
|
|
140
249
|
this.ready = false;
|
|
141
250
|
}
|
|
142
251
|
}
|
|
143
252
|
function embedderOrigin(accept) {
|
|
144
253
|
var _a;
|
|
145
254
|
if (window.parent === window)
|
|
146
|
-
return null;
|
|
255
|
+
return getBuckyApi() && accept(window.location.origin) ? window.location.origin : null;
|
|
147
256
|
const candidates = [(_a = window.location.ancestorOrigins) == null ? void 0 : _a[0], document.referrer];
|
|
148
257
|
for (const candidate of candidates) {
|
|
149
258
|
if (!candidate)
|
|
@@ -168,29 +277,33 @@ const originInZone = (origin, zoneHost) => {
|
|
|
168
277
|
class AppFrameClient {
|
|
169
278
|
constructor(options) {
|
|
170
279
|
this.options = options;
|
|
171
|
-
this.
|
|
172
|
-
void this.receive(event);
|
|
173
|
-
};
|
|
280
|
+
this.header = {};
|
|
174
281
|
this.dialogs = /* @__PURE__ */ new Map();
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
window.
|
|
178
|
-
|
|
179
|
-
|
|
282
|
+
this.appOpens = /* @__PURE__ */ new Map();
|
|
283
|
+
const origin = new URL(options.shellOrigin).origin;
|
|
284
|
+
const bridge = window.parent === window ? getBuckyApi() : void 0;
|
|
285
|
+
this.native = !!bridge;
|
|
286
|
+
const name = window.parent !== window ? window.name : "";
|
|
287
|
+
this.nonce = (name == null ? void 0 : name.startsWith(FRAME_NAME_PREFIX)) ? name.slice(FRAME_NAME_PREFIX.length) : new URLSearchParams(window.location.hash.slice(1)).get("bfp") ?? (bridge ? crypto.randomUUID() : null);
|
|
288
|
+
this.channel = bridge ? bridgeTransport(bridge) : windowTransport(() => window.parent, origin);
|
|
289
|
+
this.detach = this.channel.onMessage((message) => {
|
|
290
|
+
void this.receive(message);
|
|
291
|
+
});
|
|
292
|
+
if ((bridge || window.parent !== window) && this.nonce) {
|
|
293
|
+
const hello = () => this.channel.post(envelope("frame.hello", { nonce: this.nonce, appCapabilities: [
|
|
180
294
|
...options.onOpen ? ["open"] : [],
|
|
181
295
|
...options.onBeforeClose ? ["beforeClose"] : [],
|
|
182
296
|
...options.onBack ? ["back"] : []
|
|
183
|
-
] })
|
|
297
|
+
] }));
|
|
184
298
|
hello();
|
|
185
299
|
this.helloTimer = setInterval(hello, 250);
|
|
186
|
-
this.helloDeadline = setTimeout(() => clearInterval(this.helloTimer), 1500);
|
|
300
|
+
this.helloDeadline = setTimeout(() => clearInterval(this.helloTimer), bridge ? 1e4 : 1500);
|
|
187
301
|
}
|
|
188
302
|
}
|
|
189
|
-
async receive(
|
|
190
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
191
|
-
if (
|
|
303
|
+
async receive(m) {
|
|
304
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
305
|
+
if (!isMessage(m))
|
|
192
306
|
return;
|
|
193
|
-
const m = event.data;
|
|
194
307
|
const p = m.payload;
|
|
195
308
|
if (m.type === "frame.init") {
|
|
196
309
|
if (!this.nonce || p.nonce !== this.nonce || typeof p.locale !== "string" || !p.theme || typeof p.windowId !== "string" || p.launch && !isOpenRequest(p.launch))
|
|
@@ -200,6 +313,8 @@ class AppFrameClient {
|
|
|
200
313
|
this.init = p;
|
|
201
314
|
this.title = void 0;
|
|
202
315
|
this.focused = void 0;
|
|
316
|
+
if (Object.keys(this.header).length)
|
|
317
|
+
this.send("header.set", this.header);
|
|
203
318
|
(_b = (_a = this.options).onInit) == null ? void 0 : _b.call(_a, this.init);
|
|
204
319
|
return;
|
|
205
320
|
}
|
|
@@ -219,21 +334,33 @@ class AppFrameClient {
|
|
|
219
334
|
pending.reject(new SystemDialogError("protocol"));
|
|
220
335
|
return;
|
|
221
336
|
}
|
|
222
|
-
|
|
337
|
+
if (m.type === "app.openResult") {
|
|
338
|
+
const code = p.code === "not_found" || p.code === "denied" ? p.code : "unsupported";
|
|
339
|
+
if (m.replyTo)
|
|
340
|
+
(_c = this.appOpens.get(m.replyTo)) == null ? void 0 : _c(p.ok === true ? { ok: true } : { ok: false, code });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (m.type === "header.event") {
|
|
344
|
+
if (p.kind !== "search" && p.kind !== "item" && p.kind !== "menu")
|
|
345
|
+
return;
|
|
346
|
+
(_e = (_d = this.options).onHeaderEvent) == null ? void 0 : _e.call(_d, { kind: p.kind, ...typeof p.id === "string" ? { id: p.id } : {}, ...typeof p.value === "string" ? { value: p.value } : {} });
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const reply = (payload) => this.channel.post(envelope(m.type + "Result", payload, { replyTo: m.id }));
|
|
223
350
|
try {
|
|
224
351
|
if (m.type === "frame.open" && isOpenRequest(p.request))
|
|
225
|
-
reply(await ((
|
|
352
|
+
reply(await ((_g = (_f = this.options).onOpen) == null ? void 0 : _g.call(_f, p.request)) ?? { accepted: false });
|
|
226
353
|
if (m.type === "frame.beforeClose")
|
|
227
|
-
reply({ decision: await ((
|
|
354
|
+
reply({ decision: await ((_i = (_h = this.options).onBeforeClose) == null ? void 0 : _i.call(_h, p.reason)) ?? "allow" });
|
|
228
355
|
if (m.type === "frame.back")
|
|
229
|
-
reply({ handled: await ((
|
|
356
|
+
reply({ handled: await ((_k = (_j = this.options).onBack) == null ? void 0 : _k.call(_j)) ?? false });
|
|
230
357
|
if (m.type === "frame.themeChanged" && (p.mode === "dark" || p.mode === "light"))
|
|
231
|
-
(
|
|
358
|
+
(_m = (_l = this.options).onTheme) == null ? void 0 : _m.call(_l, p);
|
|
232
359
|
if (m.type === "frame.localeChanged" && typeof p.locale === "string")
|
|
233
|
-
(
|
|
360
|
+
(_o = (_n = this.options).onLocale) == null ? void 0 : _o.call(_n, p.locale);
|
|
234
361
|
if (m.type === "frame.focusChanged" && this.focused !== (p.focused === true)) {
|
|
235
362
|
this.focused = p.focused === true;
|
|
236
|
-
(
|
|
363
|
+
(_q = (_p = this.options).onFocus) == null ? void 0 : _q.call(_p, this.focused);
|
|
237
364
|
}
|
|
238
365
|
} catch {
|
|
239
366
|
if (m.type === "frame.open")
|
|
@@ -244,7 +371,7 @@ class AppFrameClient {
|
|
|
244
371
|
}
|
|
245
372
|
send(type, payload) {
|
|
246
373
|
if (this.init)
|
|
247
|
-
|
|
374
|
+
this.channel.post(envelope(type, payload));
|
|
248
375
|
}
|
|
249
376
|
setTitle(title, dirty = false) {
|
|
250
377
|
const key = JSON.stringify([title, dirty]);
|
|
@@ -256,10 +383,44 @@ class AppFrameClient {
|
|
|
256
383
|
requestClose() {
|
|
257
384
|
this.send("window.requestClose", {});
|
|
258
385
|
}
|
|
386
|
+
/** Sets what the host shows in the header above this App. It may be called before the handshake. */
|
|
387
|
+
setHeader(header) {
|
|
388
|
+
this.header = { ...this.header, ...header };
|
|
389
|
+
this.send("header.set", header);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Opens another App, or a page of one, in this App's Zone (or in `zone`). The host decides between a new window and
|
|
393
|
+
* an open one. In a standalone tab it opens the Zone's system entry (`systemOrigin`) in a new tab, which only reaches
|
|
394
|
+
* this App's own Zone. Never rejects.
|
|
395
|
+
*/
|
|
396
|
+
openApp(request) {
|
|
397
|
+
const clean = readAppOpenRequest(request);
|
|
398
|
+
if (!clean)
|
|
399
|
+
return Promise.resolve({ ok: false, code: "denied" });
|
|
400
|
+
if (this.init) {
|
|
401
|
+
if (!this.init.shellCapabilities.includes("app.open"))
|
|
402
|
+
return Promise.resolve({ ok: false, code: "unsupported" });
|
|
403
|
+
const id = crypto.randomUUID();
|
|
404
|
+
return new Promise((resolve) => {
|
|
405
|
+
const settle = (reply) => {
|
|
406
|
+
clearTimeout(timer);
|
|
407
|
+
this.appOpens.delete(id);
|
|
408
|
+
resolve(reply);
|
|
409
|
+
};
|
|
410
|
+
const timer = setTimeout(() => settle({ ok: false, code: "unsupported" }), 3e4);
|
|
411
|
+
this.appOpens.set(id, settle);
|
|
412
|
+
this.channel.post(envelope("app.open", clean, { id }));
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (!this.options.systemOrigin || clean.zone)
|
|
416
|
+
return Promise.resolve({ ok: false, code: "unsupported" });
|
|
417
|
+
window.open(systemOpenAppUrl(this.options.systemOrigin, clean), "_blank", "noopener");
|
|
418
|
+
return Promise.resolve({ ok: true });
|
|
419
|
+
}
|
|
259
420
|
/**
|
|
260
421
|
* Asks the system to open content: with its default app, in Preview, or by letting the user choose (`chooser`).
|
|
261
|
-
*
|
|
262
|
-
* (`systemOrigin`) in a new tab. Returns false when neither is available.
|
|
422
|
+
* Inside the shell or the BuckyOS client the request goes to the host; in a standalone tab it opens the Zone's system
|
|
423
|
+
* entry (`systemOrigin`) in a new tab. Returns false when neither is available.
|
|
263
424
|
*/
|
|
264
425
|
openContent(request, target = "default", options = {}) {
|
|
265
426
|
const hints = options.hints ?? {};
|
|
@@ -275,27 +436,29 @@ class AppFrameClient {
|
|
|
275
436
|
/**
|
|
276
437
|
* Shows the system file picker (`sysdlg/select`) and resolves with what the user chose; cancelling resolves with
|
|
277
438
|
* `{ action: 'cancelled' }`. Embedded in the shell the shell draws the dialog over this App's window; in a
|
|
278
|
-
* standalone tab the picker page of the Zone's system entry
|
|
279
|
-
* with a `SystemDialogError` when no picker is available or the
|
|
439
|
+
* standalone tab, and in the BuckyOS client unless it lists the dialog, the picker page of the Zone's system entry
|
|
440
|
+
* (`systemOrigin`) is framed over this page. Rejects with a `SystemDialogError` when no picker is available or the
|
|
441
|
+
* request did not complete.
|
|
280
442
|
*/
|
|
281
443
|
selectContent(params = {}, options = {}) {
|
|
282
|
-
var _a, _b;
|
|
283
|
-
|
|
284
|
-
|
|
444
|
+
var _a, _b, _c;
|
|
445
|
+
const offered = (_a = this.init) == null ? void 0 : _a.shellCapabilities.includes(SELECT_DIALOG_PATH);
|
|
446
|
+
if (this.init && (offered || !this.native)) {
|
|
447
|
+
if (!offered)
|
|
285
448
|
return Promise.reject(new SystemDialogError("unsupported"));
|
|
286
449
|
if (this.dialogs.size)
|
|
287
450
|
return Promise.reject(new SystemDialogError("busy"));
|
|
288
451
|
const id = crypto.randomUUID();
|
|
289
452
|
return new Promise((resolve, reject) => {
|
|
290
453
|
this.dialogs.set(id, { resolve, reject, allowLocal: params.allowLocal === true });
|
|
291
|
-
|
|
454
|
+
this.channel.post(envelope("sysdlg.open", { path: SELECT_DIALOG_PATH, params }, { id }));
|
|
292
455
|
});
|
|
293
456
|
}
|
|
294
457
|
if (!this.options.systemOrigin)
|
|
295
458
|
return Promise.reject(new SystemDialogError("unsupported"));
|
|
296
459
|
const abort = this.embedAbort = new AbortController();
|
|
297
|
-
(
|
|
298
|
-
if ((
|
|
460
|
+
(_b = options.signal) == null ? void 0 : _b.addEventListener("abort", () => abort.abort(), { once: true });
|
|
461
|
+
if ((_c = options.signal) == null ? void 0 : _c.aborted)
|
|
299
462
|
abort.abort();
|
|
300
463
|
return openSelectEmbed(this.options.systemOrigin, params, { ...options, signal: abort.signal });
|
|
301
464
|
}
|
|
@@ -303,7 +466,8 @@ class AppFrameClient {
|
|
|
303
466
|
var _a;
|
|
304
467
|
clearInterval(this.helloTimer);
|
|
305
468
|
clearTimeout(this.helloDeadline);
|
|
306
|
-
|
|
469
|
+
this.detach();
|
|
470
|
+
this.appOpens.forEach((settle) => settle({ ok: false, code: "unsupported" }));
|
|
307
471
|
this.dialogs.forEach((pending) => pending.reject(new SystemDialogError("closed")));
|
|
308
472
|
this.dialogs.clear();
|
|
309
473
|
(_a = this.embedAbort) == null ? void 0 : _a.abort();
|
|
@@ -519,9 +683,9 @@ function openSelectEmbed(systemOrigin, params, options = {}) {
|
|
|
519
683
|
const panel = document.createElement("div");
|
|
520
684
|
panel.setAttribute("role", "alert");
|
|
521
685
|
panel.style.cssText = `max-width:22rem;margin:1rem;padding:1.25rem;border-radius:16px;font:14px/1.6 system-ui,sans-serif;background:${theme === "dark" ? "#1f2329" : "#fff"};color:${theme === "dark" ? "#f2f3f5" : "#1f2329"};box-shadow:0 24px 64px rgba(0,0,0,.24)`;
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
686
|
+
const text2 = document.createElement("p");
|
|
687
|
+
text2.style.margin = "0 0 1rem";
|
|
688
|
+
text2.textContent = zh ? "无法加载文件选择器" : "Unable to load the file picker";
|
|
525
689
|
const actions = document.createElement("div");
|
|
526
690
|
actions.style.cssText = "display:flex;gap:.5rem;justify-content:flex-end";
|
|
527
691
|
const button = (label, action) => {
|
|
@@ -538,7 +702,7 @@ function openSelectEmbed(systemOrigin, params, options = {}) {
|
|
|
538
702
|
panel.remove();
|
|
539
703
|
load();
|
|
540
704
|
});
|
|
541
|
-
panel.append(
|
|
705
|
+
panel.append(text2, actions);
|
|
542
706
|
root.append(panel);
|
|
543
707
|
retry.focus();
|
|
544
708
|
};
|
|
@@ -810,6 +974,7 @@ export {
|
|
|
810
974
|
PreviewEmbedHost,
|
|
811
975
|
SELECT_EMBED_PATH,
|
|
812
976
|
SelectEmbedHost,
|
|
977
|
+
appFrameName,
|
|
813
978
|
embedderOrigin,
|
|
814
979
|
openSelectEmbed,
|
|
815
980
|
originInZone
|