pinokiod 3.160.0 → 3.162.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 +1 -1
- package/server/public/common.js +6 -1
- package/server/views/app.ejs +117 -67
- package/server/views/d.ejs +22 -2
package/package.json
CHANGED
package/server/public/common.js
CHANGED
|
@@ -28,7 +28,7 @@ function collectPostMessageTargets(contextWindow) {
|
|
|
28
28
|
return targets;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function pinokioBroadcastMessage(payload, targetOrigin = '*', contextWindow = null) {
|
|
31
|
+
function pinokioBroadcastMessage(payload, targetOrigin = '*', contextWindow = null, includeCurrent = false) {
|
|
32
32
|
const ctx = (contextWindow && typeof contextWindow === 'object') ? contextWindow : window;
|
|
33
33
|
let dispatched = false;
|
|
34
34
|
let targets;
|
|
@@ -37,6 +37,11 @@ function pinokioBroadcastMessage(payload, targetOrigin = '*', contextWindow = nu
|
|
|
37
37
|
} catch (_) {
|
|
38
38
|
targets = new Set();
|
|
39
39
|
}
|
|
40
|
+
if (includeCurrent) {
|
|
41
|
+
try {
|
|
42
|
+
targets.add(ctx);
|
|
43
|
+
} catch (_) {}
|
|
44
|
+
}
|
|
40
45
|
if (targets.size === 0) {
|
|
41
46
|
return dispatched;
|
|
42
47
|
}
|
package/server/views/app.ejs
CHANGED
|
@@ -4979,6 +4979,28 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
|
|
|
4979
4979
|
}
|
|
4980
4980
|
return null
|
|
4981
4981
|
}
|
|
4982
|
+
const forwardEventToParent = (payload) => {
|
|
4983
|
+
if (!payload || typeof payload !== 'object' || payload === null) {
|
|
4984
|
+
return
|
|
4985
|
+
}
|
|
4986
|
+
if (window.parent === window) {
|
|
4987
|
+
return
|
|
4988
|
+
}
|
|
4989
|
+
const forwardingPayload = Object.assign({}, payload, { __pinokioForwarded: true })
|
|
4990
|
+
let forwarded = false
|
|
4991
|
+
if (typeof window.PinokioBroadcastMessage === 'function') {
|
|
4992
|
+
try {
|
|
4993
|
+
forwarded = window.PinokioBroadcastMessage(forwardingPayload, '*', window)
|
|
4994
|
+
} catch (_) {
|
|
4995
|
+
forwarded = false
|
|
4996
|
+
}
|
|
4997
|
+
}
|
|
4998
|
+
if (!forwarded) {
|
|
4999
|
+
try {
|
|
5000
|
+
window.parent.postMessage(forwardingPayload, '*')
|
|
5001
|
+
} catch (_) {}
|
|
5002
|
+
}
|
|
5003
|
+
}
|
|
4982
5004
|
const getTarget = (href) => {
|
|
4983
5005
|
let u
|
|
4984
5006
|
if (href.startsWith("http")) {
|
|
@@ -6388,77 +6410,105 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
|
|
|
6388
6410
|
window.addEventListener('message', (event) => {
|
|
6389
6411
|
console.log("EVENT", event)
|
|
6390
6412
|
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
} else if (event.data.launch) {
|
|
6414
|
-
const rawName = event.data.launch.name
|
|
6415
|
-
const escapedSelector = escapeTargetSelector(rawName)
|
|
6416
|
-
if (escapedSelector) {
|
|
6417
|
-
global_selector = `.frame-link[target="${escapedSelector}"]`
|
|
6418
|
-
} else {
|
|
6419
|
-
global_selector = null
|
|
6420
|
-
}
|
|
6421
|
-
const frameExists = Array.from(document.querySelectorAll("main.browserview iframe")).some((frame) => {
|
|
6422
|
-
return frame.name === rawName
|
|
6423
|
-
})
|
|
6424
|
-
if (!frameExists) {
|
|
6425
|
-
create_iframe(rawName, event.data.launch.href)
|
|
6426
|
-
}
|
|
6427
|
-
refresh()
|
|
6428
|
-
} else if (event.data.type === "shell-session-id") {
|
|
6429
|
-
const frameName = resolveFrameName(event.data.frame, event.source)
|
|
6430
|
-
if (frameName && event.data.shellId) {
|
|
6431
|
-
const link = getTabLink(frameName)
|
|
6432
|
-
if (link) {
|
|
6433
|
-
link.setAttribute("data-shell", event.data.shellId)
|
|
6434
|
-
link.dataset.shell = event.data.shellId
|
|
6435
|
-
}
|
|
6436
|
-
}
|
|
6437
|
-
return
|
|
6438
|
-
} else if (event.data.type === "terminal-input") {
|
|
6439
|
-
const frameName = resolveFrameName(event.data.frame, event.source)
|
|
6440
|
-
const hasContent = typeof event.data.hasContent === "boolean" ? event.data.hasContent : Boolean(event.data.line && event.data.line.length > 0)
|
|
6441
|
-
updateTabPreview(frameName, event.data.line || "", hasContent, Date.now())
|
|
6442
|
-
return
|
|
6443
|
-
} else if (event.data.type) {
|
|
6444
|
-
if (event.data.type === 'stream') {
|
|
6445
|
-
const frameName = resolveFrameName(null, event.source)
|
|
6446
|
-
updateTabTimestamp(frameName, Date.now())
|
|
6447
|
-
} else if (event.data.type === 'result') {
|
|
6448
|
-
refresh()
|
|
6449
|
-
refresh_du()
|
|
6450
|
-
refresh_du("logs")
|
|
6451
|
-
} else {
|
|
6452
|
-
refresh()
|
|
6453
|
-
}
|
|
6454
|
-
}
|
|
6455
|
-
} else {
|
|
6456
|
-
refresh()
|
|
6413
|
+
const data = event.data
|
|
6414
|
+
const dataIsObject = data && typeof data === 'object' && data !== null
|
|
6415
|
+
const frameHint = dataIsObject && typeof data.frame === 'string' ? data.frame : null
|
|
6416
|
+
|
|
6417
|
+
let matchedFrameName = null
|
|
6418
|
+
if (frameHint) {
|
|
6419
|
+
matchedFrameName = resolveFrameName(frameHint, event.source)
|
|
6420
|
+
}
|
|
6421
|
+
if (!matchedFrameName) {
|
|
6422
|
+
matchedFrameName = resolveFrameName(null, event.source)
|
|
6423
|
+
}
|
|
6424
|
+
|
|
6425
|
+
let allowEvent = false
|
|
6426
|
+
const origin = event.origin
|
|
6427
|
+
if (!origin) {
|
|
6428
|
+
allowEvent = true
|
|
6429
|
+
} else {
|
|
6430
|
+
try {
|
|
6431
|
+
const originUrl = new URL(origin)
|
|
6432
|
+
const originPort = originUrl.port || (originUrl.protocol === 'https:' ? '443' : '80')
|
|
6433
|
+
if (String(originPort) === String(location.port)) {
|
|
6434
|
+
allowEvent = true
|
|
6457
6435
|
}
|
|
6436
|
+
} catch (_) {}
|
|
6437
|
+
if (!allowEvent && /https:\/\/.*pinokio\..*(localhost|co)/.test(origin)) {
|
|
6438
|
+
allowEvent = true
|
|
6458
6439
|
}
|
|
6459
6440
|
}
|
|
6441
|
+
if (!allowEvent && matchedFrameName) {
|
|
6442
|
+
allowEvent = true
|
|
6443
|
+
}
|
|
6444
|
+
if (!allowEvent) {
|
|
6445
|
+
return
|
|
6446
|
+
}
|
|
6447
|
+
if (!dataIsObject) {
|
|
6448
|
+
return
|
|
6449
|
+
}
|
|
6450
|
+
if (!data.__pinokioForwarded) {
|
|
6451
|
+
forwardEventToParent(data)
|
|
6452
|
+
}
|
|
6460
6453
|
|
|
6461
|
-
|
|
6454
|
+
if (data.action) {
|
|
6455
|
+
if (data.action.type === "newtab") {
|
|
6456
|
+
addTab(data.action.url)
|
|
6457
|
+
} else if (data.action.type === "title") {
|
|
6458
|
+
} else if (data.action.type === "location") {
|
|
6459
|
+
let url = data.action.url
|
|
6460
|
+
let pathname = new URL(url).pathname
|
|
6461
|
+
if (pathname.startsWith("/run")) {
|
|
6462
|
+
document.querySelector("#location").value = pathname.slice(4)
|
|
6463
|
+
} else {
|
|
6464
|
+
document.querySelector("#location").value = pathname
|
|
6465
|
+
}
|
|
6466
|
+
}
|
|
6467
|
+
} else if (data.launch) {
|
|
6468
|
+
const rawName = data.launch.name
|
|
6469
|
+
const escapedSelector = escapeTargetSelector(rawName)
|
|
6470
|
+
if (escapedSelector) {
|
|
6471
|
+
global_selector = `.frame-link[target="${escapedSelector}"]`
|
|
6472
|
+
} else {
|
|
6473
|
+
global_selector = null
|
|
6474
|
+
}
|
|
6475
|
+
const frameExists = Array.from(document.querySelectorAll("main.browserview iframe")).some((frame) => {
|
|
6476
|
+
return frame.name === rawName
|
|
6477
|
+
})
|
|
6478
|
+
if (!frameExists) {
|
|
6479
|
+
create_iframe(rawName, data.launch.href)
|
|
6480
|
+
}
|
|
6481
|
+
refresh()
|
|
6482
|
+
} else if (data.type === "shell-session-id") {
|
|
6483
|
+
const frameName = matchedFrameName || (typeof data.frame === 'string' ? data.frame : null)
|
|
6484
|
+
if (frameName && data.shellId) {
|
|
6485
|
+
const link = getTabLink(frameName)
|
|
6486
|
+
if (link) {
|
|
6487
|
+
link.setAttribute("data-shell", data.shellId)
|
|
6488
|
+
link.dataset.shell = data.shellId
|
|
6489
|
+
}
|
|
6490
|
+
}
|
|
6491
|
+
return
|
|
6492
|
+
} else if (data.type === "terminal-input") {
|
|
6493
|
+
const frameName = matchedFrameName || (typeof data.frame === 'string' ? data.frame : null)
|
|
6494
|
+
const hasContent = typeof data.hasContent === "boolean" ? data.hasContent : Boolean(data.line && data.line.length > 0)
|
|
6495
|
+
updateTabPreview(frameName, data.line || "", hasContent, Date.now())
|
|
6496
|
+
return
|
|
6497
|
+
} else if (data.type) {
|
|
6498
|
+
if (data.type === 'stream') {
|
|
6499
|
+
if (matchedFrameName) {
|
|
6500
|
+
updateTabTimestamp(matchedFrameName, Date.now())
|
|
6501
|
+
}
|
|
6502
|
+
} else if (data.type === 'result') {
|
|
6503
|
+
refresh()
|
|
6504
|
+
refresh_du()
|
|
6505
|
+
refresh_du("logs")
|
|
6506
|
+
} else {
|
|
6507
|
+
refresh()
|
|
6508
|
+
}
|
|
6509
|
+
} else {
|
|
6510
|
+
refresh()
|
|
6511
|
+
}
|
|
6462
6512
|
});
|
|
6463
6513
|
refresh_du()
|
|
6464
6514
|
refresh_du("logs")
|
package/server/views/d.ejs
CHANGED
|
@@ -593,12 +593,32 @@ const launchTab = (tab) => {
|
|
|
593
593
|
const href = appendSessionParam(baseHref, session)
|
|
594
594
|
const target = appendSessionParam(baseTarget, session)
|
|
595
595
|
|
|
596
|
-
|
|
596
|
+
const payload = {
|
|
597
597
|
launch: {
|
|
598
598
|
name: target,
|
|
599
599
|
href
|
|
600
600
|
}
|
|
601
|
-
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
let posted = false
|
|
604
|
+
if (typeof window !== 'undefined' && typeof window.PinokioBroadcastMessage === 'function') {
|
|
605
|
+
try {
|
|
606
|
+
posted = window.PinokioBroadcastMessage(payload, '*', window, true)
|
|
607
|
+
} catch (_) {
|
|
608
|
+
posted = false
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (!posted) {
|
|
613
|
+
try {
|
|
614
|
+
window.parent.postMessage(payload, '*')
|
|
615
|
+
} catch (_) {}
|
|
616
|
+
if (window.parent && window.parent !== window && typeof window.postMessage === 'function') {
|
|
617
|
+
try {
|
|
618
|
+
window.postMessage(payload, '*')
|
|
619
|
+
} catch (_) {}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
602
622
|
|
|
603
623
|
return true
|
|
604
624
|
}
|