pinokiod 3.159.0 → 3.160.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.159.0",
3
+ "version": "3.160.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -91,11 +91,22 @@ class Socket {
91
91
  });
92
92
  this.ws.addEventListener('close', () => {
93
93
  console.log('Disconnected from WebSocket endpoint', { error: this.error, result: this.result });
94
- if (typeof window !== 'undefined' && window.parent && window.parent !== window) {
95
- try {
96
- window.parent.postMessage({ type: 'pinokio:socket-closed' }, '*')
97
- } catch (err) {
98
- console.debug('postMessage error', err)
94
+ if (typeof window !== 'undefined') {
95
+ const payload = { type: 'pinokio:socket-closed' }
96
+ let dispatched = false
97
+ if (typeof window.PinokioBroadcastMessage === 'function') {
98
+ try {
99
+ dispatched = window.PinokioBroadcastMessage(payload, '*', window)
100
+ } catch (err) {
101
+ console.debug('postMessage error', err)
102
+ }
103
+ }
104
+ if (!dispatched && window.parent && window.parent !== window) {
105
+ try {
106
+ window.parent.postMessage(payload, '*')
107
+ } catch (err) {
108
+ console.debug('postMessage error', err)
109
+ }
99
110
  }
100
111
  }
101
112
  resolve()
@@ -1,5 +1,58 @@
1
1
  const CAPTURE_MIN_SIZE = 32;
2
2
 
3
+ function collectPostMessageTargets(contextWindow) {
4
+ const ctx = contextWindow || window;
5
+ const targets = new Set();
6
+ const addTarget = (candidate) => {
7
+ if (!candidate || candidate === ctx) {
8
+ return;
9
+ }
10
+ try {
11
+ if (typeof candidate.postMessage !== 'function') {
12
+ return;
13
+ }
14
+ } catch (_) {
15
+ return;
16
+ }
17
+ targets.add(candidate);
18
+ };
19
+ try {
20
+ addTarget(ctx.parent);
21
+ } catch (_) {}
22
+ try {
23
+ addTarget(ctx.top);
24
+ } catch (_) {}
25
+ try {
26
+ addTarget(ctx.opener);
27
+ } catch (_) {}
28
+ return targets;
29
+ }
30
+
31
+ function pinokioBroadcastMessage(payload, targetOrigin = '*', contextWindow = null) {
32
+ const ctx = (contextWindow && typeof contextWindow === 'object') ? contextWindow : window;
33
+ let dispatched = false;
34
+ let targets;
35
+ try {
36
+ targets = collectPostMessageTargets(ctx);
37
+ } catch (_) {
38
+ targets = new Set();
39
+ }
40
+ if (targets.size === 0) {
41
+ return dispatched;
42
+ }
43
+ targets.forEach((target) => {
44
+ try {
45
+ target.postMessage(payload, targetOrigin);
46
+ dispatched = true;
47
+ } catch (_) {}
48
+ });
49
+ return dispatched;
50
+ }
51
+
52
+ if (typeof window !== 'undefined' && typeof window.PinokioBroadcastMessage !== 'function') {
53
+ window.PinokioBroadcastMessage = pinokioBroadcastMessage;
54
+ }
55
+
3
56
  async function uploadCapture(blob, filename) {
4
57
  const fd = new FormData();
5
58
  fd.append('file', blob, filename);
@@ -1716,9 +1769,22 @@ if (typeof hotkeys === 'function') {
1716
1769
  attemptLeadership();
1717
1770
  })();
1718
1771
  const refreshParent = (e) => {
1719
- // if (window.parent === window.top) {
1720
- window.parent.postMessage(e, "*")
1721
- // }
1772
+ let dispatched = false;
1773
+ if (typeof window !== 'undefined' && typeof window.PinokioBroadcastMessage === 'function') {
1774
+ try {
1775
+ dispatched = window.PinokioBroadcastMessage(e, '*', window);
1776
+ } catch (_) {
1777
+ dispatched = false;
1778
+ }
1779
+ }
1780
+ if (dispatched) {
1781
+ return;
1782
+ }
1783
+ try {
1784
+ if (window.parent && window.parent !== window && typeof window.parent.postMessage === 'function') {
1785
+ window.parent.postMessage(e, '*');
1786
+ }
1787
+ } catch (_) {}
1722
1788
  }
1723
1789
  let tippyInstances = [];
1724
1790
  const COMPACT_LAYOUT_QUERY = '(max-width: 768px)';
@@ -44,7 +44,7 @@
44
44
 
45
45
  submit(line, meta = {}) {
46
46
  const win = this.getWindow()
47
- if (!win || !win.parent || typeof win.parent.postMessage !== "function") {
47
+ if (!win) {
48
48
  return
49
49
  }
50
50
  const safeLine = (line || "").replace(/[\x00-\x1F\x7F]/g, "")
@@ -52,12 +52,29 @@
52
52
  const truncated = preview.length > this.limit ? `${preview.slice(0, this.limit)}...` : preview
53
53
  const hadLineBreak = Boolean(meta && meta.hadLineBreak)
54
54
  const meaningful = truncated.length > 0 || hadLineBreak
55
- win.parent.postMessage({
55
+ const payload = {
56
56
  type: "terminal-input",
57
57
  frame: this.getFrameName(),
58
58
  line: truncated,
59
59
  hasContent: meaningful
60
- }, "*")
60
+ }
61
+
62
+ let dispatched = false
63
+ if (typeof global.PinokioBroadcastMessage === "function") {
64
+ try {
65
+ dispatched = global.PinokioBroadcastMessage(payload, "*", win)
66
+ } catch (_) {
67
+ dispatched = false
68
+ }
69
+ }
70
+ if (dispatched) {
71
+ return
72
+ }
73
+ try {
74
+ if (win.parent && win.parent !== win && typeof win.parent.postMessage === "function") {
75
+ win.parent.postMessage(payload, "*")
76
+ }
77
+ } catch (_) {}
61
78
  }
62
79
  }
63
80
 
@@ -6386,6 +6386,7 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6386
6386
  init.click()
6387
6387
  }
6388
6388
  window.addEventListener('message', (event) => {
6389
+ console.log("EVENT", event)
6389
6390
 
6390
6391
  // only process the event it's coming from pinokio
6391
6392
  let origin = event.origin
@@ -206,18 +206,47 @@ body.dark #status-window b {
206
206
  <script>
207
207
  let shell_id
208
208
  let lastNotifiedShellId = null
209
+ const postMessageToAncestors = (payload) => {
210
+ if (!payload || typeof payload !== "object") {
211
+ return false
212
+ }
213
+ if (typeof window !== "undefined" && typeof window.PinokioBroadcastMessage === "function") {
214
+ try {
215
+ if (window.PinokioBroadcastMessage(payload, "*", window)) {
216
+ return true
217
+ }
218
+ } catch (_) {}
219
+ }
220
+ const targets = new Set()
221
+ try {
222
+ if (window.parent && window.parent !== window && typeof window.parent.postMessage === "function") {
223
+ targets.add(window.parent)
224
+ }
225
+ } catch (_) {}
226
+ try {
227
+ if (window.top && window.top !== window && typeof window.top.postMessage === "function") {
228
+ targets.add(window.top)
229
+ }
230
+ } catch (_) {}
231
+ let dispatched = false
232
+ targets.forEach((target) => {
233
+ try {
234
+ target.postMessage(payload, "*")
235
+ dispatched = true
236
+ } catch (_) {}
237
+ })
238
+ return dispatched
239
+ }
209
240
  const notifyShellSession = (id) => {
210
241
  if (!id || id === lastNotifiedShellId) {
211
242
  return
212
243
  }
213
244
  lastNotifiedShellId = id
214
- if (window && window.parent && typeof window.parent.postMessage === "function") {
215
- window.parent.postMessage({
216
- type: "shell-session-id",
217
- frame: window.name || null,
218
- shellId: id
219
- }, "*")
220
- }
245
+ postMessageToAncestors({
246
+ type: "shell-session-id",
247
+ frame: window.name || null,
248
+ shellId: id
249
+ })
221
250
  }
222
251
  function buildBinaryRpcPayload(rpc, fileEntries) {
223
252
  const metadata = {
@@ -299,19 +328,16 @@ document.addEventListener("DOMContentLoaded", async () => {
299
328
  this.inputTracker.submit(line)
300
329
  return
301
330
  }
302
- if (!window || !window.parent || typeof window.parent.postMessage !== "function") {
303
- return
304
- }
305
331
  const safeLine = (line || "").replace(/[\x00-\x1F\x7F]/g, "")
306
332
  const preview = safeLine.trim()
307
333
  const limit = 200
308
334
  const truncated = preview.length > limit ? preview.slice(0, limit) + "..." : preview
309
- window.parent.postMessage({
335
+ postMessageToAncestors({
310
336
  type: "terminal-input",
311
337
  frame: window.name || null,
312
338
  line: truncated,
313
339
  hasContent: truncated.length > 0
314
- }, "*")
340
+ })
315
341
  }
316
342
  write(text) {
317
343
  if (text !== "\u0007") {
@@ -182,6 +182,38 @@ body.frozen {
182
182
  <script>
183
183
  let shell_id
184
184
  Dropzone.autoDiscover = false;
185
+ function postMessageToAncestors(payload) {
186
+ if (!payload || typeof payload !== "object") {
187
+ return false
188
+ }
189
+ if (typeof window !== "undefined" && typeof window.PinokioBroadcastMessage === "function") {
190
+ try {
191
+ if (window.PinokioBroadcastMessage(payload, "*", window)) {
192
+ return true
193
+ }
194
+ } catch (_) {}
195
+ }
196
+ const targets = new Set()
197
+ try {
198
+ if (window.parent && window.parent !== window && typeof window.parent.postMessage === "function") {
199
+ targets.add(window.parent)
200
+ }
201
+ } catch (_) {}
202
+ try {
203
+ if (window.top && window.top !== window && typeof window.top.postMessage === "function") {
204
+ targets.add(window.top)
205
+ }
206
+ } catch (_) {}
207
+ let dispatched = false
208
+ targets.forEach((target) => {
209
+ try {
210
+ target.postMessage(payload, "*")
211
+ dispatched = true
212
+ } catch (_) {}
213
+ })
214
+ return dispatched
215
+ }
216
+
185
217
  function buildBinaryRpcPayload(rpc, fileEntries) {
186
218
  const metadata = {
187
219
  rpc,
@@ -288,21 +320,18 @@ document.addEventListener("DOMContentLoaded", async () => {
288
320
  this.inputTracker.submit(line, meta)
289
321
  return
290
322
  }
291
- if (!window || !window.parent || typeof window.parent.postMessage !== "function") {
292
- return
293
- }
294
323
  const safeLine = (line || "").replace(/[\x00-\x1F\x7F]/g, "")
295
324
  const preview = safeLine.trim()
296
325
  const limit = 200
297
326
  const truncated = preview.length > limit ? preview.slice(0, limit) + "..." : preview
298
327
  const hadLineBreak = Boolean(meta && meta.hadLineBreak)
299
328
  const meaningful = truncated.length > 0 || hadLineBreak
300
- window.parent.postMessage({
329
+ postMessageToAncestors({
301
330
  type: "terminal-input",
302
331
  frame: window.name || null,
303
332
  line: truncated,
304
333
  hasContent: meaningful
305
- }, "*")
334
+ })
306
335
  }
307
336
  write(text) {
308
337
  if (text !== "\u0007") {