pinokiod 8.3.16 → 8.3.18
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/index.js +6 -3
- package/server/lib/create_page_url.js +21 -0
- package/server/public/agent-bar-compose.css +23 -2
- package/server/public/explore-create-handoff.js +49 -0
- package/server/public/sidebar-create.css +23 -0
- package/server/views/explore.ejs +2 -1
- package/server/views/partials/main_sidebar.ejs +2 -0
- package/test/create-page.test.js +207 -0
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -86,6 +86,7 @@ const { createTerminalSessionHelpers } = require("./lib/terminal_session_helpers
|
|
|
86
86
|
const { createLauncherInstructionBootstrap } = require("./lib/launcher_instruction_bootstrap")
|
|
87
87
|
const { createBrain } = require("./lib/brain")
|
|
88
88
|
const { registerSessionFiles } = require("./lib/session_files")
|
|
89
|
+
const { createPageUrl } = require("./lib/create_page_url")
|
|
89
90
|
const { createJobs, registerJobRoutes } = require("./lib/agent_jobs")
|
|
90
91
|
const RequestFile = require("../kernel/request_file")
|
|
91
92
|
const { createTerminalGitResetHandler } = require("./lib/terminal_git_reset")
|
|
@@ -3208,15 +3209,17 @@ class Server {
|
|
|
3208
3209
|
throw error
|
|
3209
3210
|
}
|
|
3210
3211
|
}
|
|
3211
|
-
if (pathComponents.length === 0 && req.query.mode === "explore") {
|
|
3212
|
+
if (pathComponents.length === 0 && (req.query.mode === "explore" || req.query.mode === "create")) {
|
|
3213
|
+
const createPage = req.query.mode === "create"
|
|
3212
3214
|
const peerAccess = await this.composePeerAccessPayload()
|
|
3213
3215
|
let list = this.getPeers()
|
|
3214
3216
|
res.render("explore", {
|
|
3215
3217
|
current_host: this.kernel.peer.host,
|
|
3216
3218
|
...peerAccess,
|
|
3217
3219
|
list,
|
|
3218
|
-
discover_dark: this.discover_dark,
|
|
3219
|
-
discover_light: this.discover_light,
|
|
3220
|
+
discover_dark: createPage ? createPageUrl(this.discover_dark) : this.discover_dark,
|
|
3221
|
+
discover_light: createPage ? createPageUrl(this.discover_light) : this.discover_light,
|
|
3222
|
+
sidebar_selected: createPage ? "create" : "explore",
|
|
3220
3223
|
portal: this.portal,
|
|
3221
3224
|
version: this.version,
|
|
3222
3225
|
schema: this.kernel.schema,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The sidebar's Create page shows the registry's /create page in the same pane
|
|
2
|
+
// Explore uses. Its address is the Explore address with the path set to
|
|
3
|
+
// /create, so the host, the embed flag and the theme stay whatever the app was
|
|
4
|
+
// started with and no separate setting is needed.
|
|
5
|
+
const CREATE_PATH = "/create"
|
|
6
|
+
|
|
7
|
+
function createPageUrl(discoverUrl) {
|
|
8
|
+
if (typeof discoverUrl !== "string" || !discoverUrl.trim()) return ""
|
|
9
|
+
let url
|
|
10
|
+
try {
|
|
11
|
+
url = new URL(discoverUrl.trim())
|
|
12
|
+
} catch (_) {
|
|
13
|
+
return ""
|
|
14
|
+
}
|
|
15
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return ""
|
|
16
|
+
url.pathname = CREATE_PATH
|
|
17
|
+
url.hash = ""
|
|
18
|
+
return url.toString()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { createPageUrl }
|
|
@@ -436,11 +436,32 @@ html .agent-bar.agent-compose[data-compose="centre"] .agent-compose__bg {
|
|
|
436
436
|
.agent-bar[data-compose="centre"] .agent-compose__greet {
|
|
437
437
|
display: block;
|
|
438
438
|
}
|
|
439
|
+
/* A link's text is often long (a template's address and answers), so it is set
|
|
440
|
+
a step smaller than typed text, and the greeting with it. */
|
|
439
441
|
html .agent-bar.agent-compose[data-compose="centre"] .agent-bar__input {
|
|
440
442
|
min-height: 82px;
|
|
441
443
|
padding: 2px 4px;
|
|
442
|
-
font-size:
|
|
443
|
-
line-height:
|
|
444
|
+
font-size: 15px;
|
|
445
|
+
line-height: 22px;
|
|
446
|
+
}
|
|
447
|
+
.agent-bar[data-compose="centre"] .agent-compose__greet {
|
|
448
|
+
font-size: 15px;
|
|
449
|
+
line-height: 22px;
|
|
450
|
+
}
|
|
451
|
+
/* Dark theme: the open view's face is filled off-white with dark features, so
|
|
452
|
+
it is the same light-faced character as on the light theme and as the mark
|
|
453
|
+
at rest, not white lines around a dark face. While working it is the
|
|
454
|
+
outlined face again: the line that runs around the head needs the outline to
|
|
455
|
+
run on. */
|
|
456
|
+
body.dark .agent-bar[data-compose] .agent-compose__face:not([data-face="working"]) {
|
|
457
|
+
color: #1b1c1d;
|
|
458
|
+
}
|
|
459
|
+
body.dark .agent-bar[data-compose] .agent-compose__face:not([data-face="working"]) .agent-compose__head {
|
|
460
|
+
fill: #d9d9da;
|
|
461
|
+
stroke: #d9d9da;
|
|
462
|
+
}
|
|
463
|
+
body.dark .agent-bar[data-compose] .agent-compose__face:not([data-face="working"]) .agent-compose__nose {
|
|
464
|
+
fill: #d9d9da;
|
|
444
465
|
}
|
|
445
466
|
html .agent-bar.agent-compose[data-compose="centre"] .agent-bar__footer {
|
|
446
467
|
margin: 0 -16px;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The registry page shown in the Explore pane (the Explore and Create pages)
|
|
2
|
+
// can ask this Pinokio to open its own bar with a request filled in, instead of
|
|
3
|
+
// sending the visitor to "a Pinokio somewhere" in a new window:
|
|
4
|
+
//
|
|
5
|
+
// registry -> here { e: 'pinokio:create', requestId, type, prompt, name? }
|
|
6
|
+
// here -> registry { e: 'pinokio:create:result', requestId, handled: true }
|
|
7
|
+
//
|
|
8
|
+
// The registry waits briefly for the result and falls back to its own
|
|
9
|
+
// "Open in Pinokio" panel when none comes, so a Pinokio without this file keeps
|
|
10
|
+
// working. On a request this page goes to the home page's pre-filled link
|
|
11
|
+
// (?universal&type&prompt&name), which fills the bar in and sends nothing.
|
|
12
|
+
(function () {
|
|
13
|
+
if (window.__pinokioExploreCreateHandoffInstalled) return;
|
|
14
|
+
window.__pinokioExploreCreateHandoffInstalled = true;
|
|
15
|
+
|
|
16
|
+
var TYPES = ['create_app', 'create_plugin', 'ask'];
|
|
17
|
+
// A longer link is refused by the server; the registry then shows its panel.
|
|
18
|
+
var MAX_LINK = 8000;
|
|
19
|
+
|
|
20
|
+
window.addEventListener('message', function (event) {
|
|
21
|
+
var data = event && event.data;
|
|
22
|
+
if (!data || typeof data !== 'object' || data.e !== 'pinokio:create') return;
|
|
23
|
+
|
|
24
|
+
// Only the registry iframe of this page, at the origin it was given, is heard.
|
|
25
|
+
var frame = document.querySelector('iframe[name="pinokio-explore"]');
|
|
26
|
+
if (!frame || event.source !== frame.contentWindow) return;
|
|
27
|
+
try {
|
|
28
|
+
if (event.origin !== new URL(frame.getAttribute('src') || '', window.location.href).origin) return;
|
|
29
|
+
} catch (_) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (TYPES.indexOf(data.type) === -1) return;
|
|
34
|
+
var target = new URL('/home', window.location.origin);
|
|
35
|
+
target.searchParams.set('universal', '');
|
|
36
|
+
target.searchParams.set('type', data.type);
|
|
37
|
+
if (typeof data.prompt === 'string' && data.prompt.trim()) target.searchParams.set('prompt', data.prompt.trim());
|
|
38
|
+
if (typeof data.name === 'string' && data.name.trim()) target.searchParams.set('name', data.name.trim());
|
|
39
|
+
if (target.toString().length > MAX_LINK) return;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
event.source.postMessage(
|
|
43
|
+
{ e: 'pinokio:create:result', requestId: data.requestId, handled: true },
|
|
44
|
+
event.origin
|
|
45
|
+
);
|
|
46
|
+
} catch (_) {}
|
|
47
|
+
window.location.assign(target.toString());
|
|
48
|
+
});
|
|
49
|
+
})();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* The sidebar's Create entry: the first row, drawn as a button. It has a
|
|
2
|
+
hairline border and no fill, its plus and label are centred, and it sits 4px
|
|
3
|
+
above My Apps (3px here plus the section's 1px row gap). Its icon and text
|
|
4
|
+
are the sidebar's own at full strength; no colour is added. Selected, it
|
|
5
|
+
gets the fill and bold text every selected row gets. */
|
|
6
|
+
body.main-sidebar-page aside.main-sidebar .tab.main-sidebar-create,
|
|
7
|
+
aside.main-sidebar .tab.main-sidebar-create {
|
|
8
|
+
display: flex !important;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
margin-bottom: 3px;
|
|
11
|
+
border: 1px solid rgba(15, 23, 42, 0.11) !important;
|
|
12
|
+
padding-left: 4px !important;
|
|
13
|
+
padding-right: 4px !important;
|
|
14
|
+
color: var(--pinokio-sidebar-tab-active-color) !important;
|
|
15
|
+
}
|
|
16
|
+
body.dark.main-sidebar-page aside.main-sidebar .tab.main-sidebar-create,
|
|
17
|
+
body.dark aside.main-sidebar .tab.main-sidebar-create {
|
|
18
|
+
border-color: rgba(255, 255, 255, 0.13) !important;
|
|
19
|
+
}
|
|
20
|
+
body.main-sidebar-page aside.main-sidebar .tab.main-sidebar-create i,
|
|
21
|
+
aside.main-sidebar .tab.main-sidebar-create i {
|
|
22
|
+
color: var(--pinokio-sidebar-icon-active) !important;
|
|
23
|
+
}
|
package/server/views/explore.ejs
CHANGED
|
@@ -181,7 +181,7 @@ body.dark .explore-url {
|
|
|
181
181
|
<% } else { %>
|
|
182
182
|
<iframe name="pinokio-explore" src="<%=discover_light%>" <%=agent === "electron" ? "no-referrer" : ""%> allow="fullscreen *;" allowfullscreen></iframe>
|
|
183
183
|
<% } %>
|
|
184
|
-
<%- include('partials/main_sidebar', { selected: 'explore' }) %>
|
|
184
|
+
<%- include('partials/main_sidebar', { selected: typeof sidebar_selected === 'string' ? sidebar_selected : 'explore' }) %>
|
|
185
185
|
</main>
|
|
186
186
|
<link href="/xterm.min.css" rel="stylesheet" />
|
|
187
187
|
<link href="/css/fontawesome.min.css" rel="stylesheet">
|
|
@@ -192,6 +192,7 @@ body.dark .explore-url {
|
|
|
192
192
|
<link href="/electron.css" rel="stylesheet"/>
|
|
193
193
|
<% } %>
|
|
194
194
|
<script src="/common.js"></script>
|
|
195
|
+
<script src="/explore-create-handoff.js"></script>
|
|
195
196
|
<script>
|
|
196
197
|
/*
|
|
197
198
|
document.querySelector("form").addEventListener("submit", (e) => {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const sidebarSelected = (typeof selected !== "undefined" && selected) ? String(selected) : "";
|
|
3
3
|
%>
|
|
4
4
|
<link rel="stylesheet" href="/agent-bar.css">
|
|
5
|
+
<link rel="stylesheet" href="/sidebar-create.css">
|
|
5
6
|
<script src="/storage-sweep.js"></script>
|
|
6
7
|
<script src="/agent-bar.js" data-agent-bar="true"></script>
|
|
7
8
|
<link rel="stylesheet" href="/agent-bar-files.css">
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
<aside class="main-sidebar" id="main-sidebar" aria-label="Primary navigation">
|
|
21
22
|
<nav class="main-sidebar-nav" aria-label="Pinokio navigation">
|
|
22
23
|
<div class='main-sidebar-section main-sidebar-section-actions' aria-label="Actions">
|
|
24
|
+
<a class='tab main-sidebar-create <%= sidebarSelected === 'create' ? 'selected' : '' %>' id='create' href="/home?mode=create"<% if (sidebarSelected === 'create') { %> aria-current="page"<% } %>><i class="fa-solid fa-plus main-sidebar-action-icon"></i><div class='caption'>Create</div></a>
|
|
23
25
|
<a class='tab main-sidebar-action <%= sidebarSelected === 'home' ? 'selected' : '' %>' id='home' href="/home"<% if (sidebarSelected === 'home') { %> aria-current="page"<% } %>><i class="fa-solid fa-layer-group main-sidebar-action-icon"></i><div class='caption'>My Apps</div></a>
|
|
24
26
|
<a class='tab main-sidebar-action <%= sidebarSelected === 'explore' ? 'selected' : '' %>' id='explore' href="/home?mode=explore"<% if (sidebarSelected === 'explore') { %> aria-current="page"<% } %>><i class="fa-solid fa-globe main-sidebar-action-icon"></i><div class='caption'>Explore</div></a>
|
|
25
27
|
<details class="universal-create-menu">
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
const assert = require('node:assert/strict')
|
|
2
|
+
const fs = require('node:fs/promises')
|
|
3
|
+
const path = require('node:path')
|
|
4
|
+
const test = require('node:test')
|
|
5
|
+
const ejs = require('ejs')
|
|
6
|
+
|
|
7
|
+
const { createPageUrl } = require('../server/lib/create_page_url')
|
|
8
|
+
|
|
9
|
+
const root = path.resolve(__dirname, '..')
|
|
10
|
+
const sidebarFile = path.join(root, 'server', 'views', 'partials', 'main_sidebar.ejs')
|
|
11
|
+
const exploreFile = path.join(root, 'server', 'views', 'explore.ejs')
|
|
12
|
+
const serverFile = path.join(root, 'server', 'index.js')
|
|
13
|
+
|
|
14
|
+
const renderSidebar = (selected) => ejs.renderFile(sidebarFile, { selected })
|
|
15
|
+
const createTag = (html) => html.match(/<a class='tab main-sidebar-create[^>]*>/)?.[0] || ''
|
|
16
|
+
const exploreTag = (html) => html.match(/<a class='tab main-sidebar-action[^>]*id='explore'[^>]*>/)?.[0] || ''
|
|
17
|
+
|
|
18
|
+
test('the Create address is the Explore address with the /create path', () => {
|
|
19
|
+
assert.equal(
|
|
20
|
+
createPageUrl('https://pinokio.co?embed=1&theme=dark'),
|
|
21
|
+
'https://pinokio.co/create?embed=1&theme=dark',
|
|
22
|
+
)
|
|
23
|
+
assert.equal(
|
|
24
|
+
createPageUrl('https://pinokio.co?embed=1&theme=light'),
|
|
25
|
+
'https://pinokio.co/create?embed=1&theme=light',
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('the Create address keeps a custom registry host, port and query', () => {
|
|
30
|
+
assert.equal(
|
|
31
|
+
createPageUrl('https://beta.pinokio.co/?embed=1&theme=dark'),
|
|
32
|
+
'https://beta.pinokio.co/create?embed=1&theme=dark',
|
|
33
|
+
)
|
|
34
|
+
assert.equal(
|
|
35
|
+
createPageUrl('http://localhost:3000/some/path?embed=1&theme=light#top'),
|
|
36
|
+
'http://localhost:3000/create?embed=1&theme=light',
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('the Create address is empty when there is no usable Explore address', () => {
|
|
41
|
+
assert.equal(createPageUrl(undefined), '')
|
|
42
|
+
assert.equal(createPageUrl(''), '')
|
|
43
|
+
assert.equal(createPageUrl('not a url'), '')
|
|
44
|
+
assert.equal(createPageUrl('javascript:alert(1)'), '')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('the sidebar starts with Create, a link to the Create page', async () => {
|
|
48
|
+
const source = await fs.readFile(sidebarFile, 'utf8')
|
|
49
|
+
const createIndex = source.indexOf("<div class='caption'>Create</div>")
|
|
50
|
+
const myAppsIndex = source.indexOf("<div class='caption'>My Apps</div>")
|
|
51
|
+
|
|
52
|
+
assert.notEqual(createIndex, -1)
|
|
53
|
+
assert.ok(createIndex < myAppsIndex)
|
|
54
|
+
|
|
55
|
+
const html = await renderSidebar('home')
|
|
56
|
+
assert.match(createTag(html), /href="\/home\?mode=create"/)
|
|
57
|
+
assert.doesNotMatch(createTag(html), /selected|aria-current/)
|
|
58
|
+
assert.match(html, /href="\/sidebar-create\.css"/)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('the sidebar marks Create, and only Create, on the Create page', async () => {
|
|
62
|
+
const html = await renderSidebar('create')
|
|
63
|
+
|
|
64
|
+
assert.match(createTag(html), /class='tab main-sidebar-create selected'/)
|
|
65
|
+
assert.match(createTag(html), /aria-current="page"/)
|
|
66
|
+
assert.doesNotMatch(exploreTag(html), /selected|aria-current/)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('the sidebar still marks Explore on the Explore page', async () => {
|
|
70
|
+
const html = await renderSidebar('explore')
|
|
71
|
+
|
|
72
|
+
assert.match(exploreTag(html), /selected/)
|
|
73
|
+
assert.doesNotMatch(createTag(html), /selected|aria-current/)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('the Create page is the Explore page with its own address and sidebar entry', async () => {
|
|
77
|
+
const [server, explore] = await Promise.all([
|
|
78
|
+
fs.readFile(serverFile, 'utf8'),
|
|
79
|
+
fs.readFile(exploreFile, 'utf8'),
|
|
80
|
+
])
|
|
81
|
+
|
|
82
|
+
assert.match(server, /req\.query\.mode === "explore" \|\| req\.query\.mode === "create"/)
|
|
83
|
+
assert.match(server, /discover_dark: createPage \? createPageUrl\(this\.discover_dark\) : this\.discover_dark/)
|
|
84
|
+
assert.match(server, /discover_light: createPage \? createPageUrl\(this\.discover_light\) : this\.discover_light/)
|
|
85
|
+
assert.match(server, /sidebar_selected: createPage \? "create" : "explore"/)
|
|
86
|
+
assert.match(explore, /selected: typeof sidebar_selected === 'string' \? sidebar_selected : 'explore'/)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// The registry page in the pane asks this Pinokio to open its bar.
|
|
90
|
+
const { JSDOM, VirtualConsole } = require('jsdom')
|
|
91
|
+
const handoffFile = path.join(root, 'server', 'public', 'explore-create-handoff.js')
|
|
92
|
+
|
|
93
|
+
async function handoffHarness(frameUrl = 'https://pinokio.co/create?embed=1&theme=dark') {
|
|
94
|
+
const source = await fs.readFile(handoffFile, 'utf8')
|
|
95
|
+
const navigations = []
|
|
96
|
+
const virtualConsole = new VirtualConsole()
|
|
97
|
+
virtualConsole.on('jsdomError', (error) => {
|
|
98
|
+
if (error && /Not implemented: navigation/.test(error.message || '')) {
|
|
99
|
+
navigations.push(error)
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
throw error
|
|
103
|
+
})
|
|
104
|
+
const built = []
|
|
105
|
+
const dom = new JSDOM('<!doctype html><body><main><iframe name="pinokio-explore"></iframe><iframe name="other"></iframe></main></body>', {
|
|
106
|
+
runScripts: 'dangerously',
|
|
107
|
+
url: 'http://192.168.1.50:42000/home?mode=create',
|
|
108
|
+
virtualConsole,
|
|
109
|
+
beforeParse(window) {
|
|
110
|
+
// The page cannot be watched leaving, so the addresses it builds are kept.
|
|
111
|
+
const NativeURL = window.URL
|
|
112
|
+
window.URL = class extends NativeURL {
|
|
113
|
+
constructor(value, base) {
|
|
114
|
+
super(value, base)
|
|
115
|
+
built.push(this)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
const [frame, other] = dom.window.document.querySelectorAll('iframe')
|
|
121
|
+
frame.setAttribute('src', frameUrl)
|
|
122
|
+
const replies = []
|
|
123
|
+
frame.contentWindow.postMessage = (message, origin) => replies.push({ message, origin })
|
|
124
|
+
const script = dom.window.document.createElement('script')
|
|
125
|
+
script.textContent = source
|
|
126
|
+
dom.window.document.body.appendChild(script)
|
|
127
|
+
const send = (data, options = {}) => dom.window.dispatchEvent(new dom.window.MessageEvent('message', {
|
|
128
|
+
data,
|
|
129
|
+
origin: options.origin || 'https://pinokio.co',
|
|
130
|
+
source: options.source || frame.contentWindow,
|
|
131
|
+
}))
|
|
132
|
+
// where the page was sent: the last address built on this Pinokio's own /home
|
|
133
|
+
const target = () => built.map(url => url.href).filter(href => href.startsWith('http://192.168.1.50:42000/home?universal')).pop()
|
|
134
|
+
return { dom, frame, other, replies, navigations, send, target }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
test('the registry frame\'s create request is answered and this page goes to its own pre-filled bar', async (t) => {
|
|
138
|
+
const { dom, replies, navigations, send, target } = await handoffHarness()
|
|
139
|
+
t.after(() => dom.window.close())
|
|
140
|
+
|
|
141
|
+
send({ e: 'pinokio:create', requestId: 'r1', type: 'create_app', prompt: ' A launcher for $& 雪 ', name: ' my-app ' })
|
|
142
|
+
|
|
143
|
+
assert.deepEqual(JSON.parse(JSON.stringify(replies)), [{
|
|
144
|
+
message: { e: 'pinokio:create:result', requestId: 'r1', handled: true },
|
|
145
|
+
origin: 'https://pinokio.co',
|
|
146
|
+
}])
|
|
147
|
+
assert.equal(navigations.length, 1)
|
|
148
|
+
// this Pinokio's own address, whatever one the visitor reached it at
|
|
149
|
+
const url = new URL(target())
|
|
150
|
+
assert.equal(url.origin, 'http://192.168.1.50:42000')
|
|
151
|
+
assert.equal(url.pathname, '/home')
|
|
152
|
+
assert.ok(url.searchParams.has('universal'))
|
|
153
|
+
assert.equal(url.searchParams.get('type'), 'create_app')
|
|
154
|
+
assert.equal(url.searchParams.get('prompt'), 'A launcher for $& 雪')
|
|
155
|
+
assert.equal(url.searchParams.get('name'), 'my-app')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('every mode is accepted, with or without a prompt', async (t) => {
|
|
159
|
+
for (const type of ['create_app', 'create_plugin', 'ask']) {
|
|
160
|
+
const { dom, navigations, send, target } = await handoffHarness()
|
|
161
|
+
t.after(() => dom.window.close())
|
|
162
|
+
send({ e: 'pinokio:create', requestId: type, type })
|
|
163
|
+
assert.equal(navigations.length, 1)
|
|
164
|
+
assert.equal(target(), `http://192.168.1.50:42000/home?universal=&type=${type}`)
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('a prompt too long for a link is left unanswered, so the registry shows its panel', async (t) => {
|
|
169
|
+
const { dom, replies, navigations, send } = await handoffHarness()
|
|
170
|
+
t.after(() => dom.window.close())
|
|
171
|
+
|
|
172
|
+
send({ e: 'pinokio:create', requestId: 'long', type: 'create_app', prompt: '雪'.repeat(2000) })
|
|
173
|
+
|
|
174
|
+
assert.deepEqual(replies, [])
|
|
175
|
+
assert.equal(navigations.length, 0)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('a create request from another frame, origin or type is ignored', async (t) => {
|
|
179
|
+
const { dom, other, replies, navigations, send } = await handoffHarness()
|
|
180
|
+
t.after(() => dom.window.close())
|
|
181
|
+
|
|
182
|
+
send({ e: 'pinokio:create', requestId: 'a', type: 'create_app', prompt: 'x' }, { source: other.contentWindow })
|
|
183
|
+
send({ e: 'pinokio:create', requestId: 'b', type: 'create_app', prompt: 'x' }, { origin: 'https://evil.example' })
|
|
184
|
+
send({ e: 'pinokio:create', requestId: 'c', type: 'download', prompt: 'x' })
|
|
185
|
+
send({ e: 'pinokio:create', requestId: 'd', prompt: 'x' })
|
|
186
|
+
send({ e: 'pinokio:navigate', url: '/home?universal&type=create_app' })
|
|
187
|
+
|
|
188
|
+
assert.deepEqual(replies, [])
|
|
189
|
+
assert.equal(navigations.length, 0)
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
test('a custom registry origin is the one trusted', async (t) => {
|
|
193
|
+
const { dom, replies, navigations, send } = await handoffHarness('https://beta.pinokio.co/create?embed=1&theme=dark')
|
|
194
|
+
t.after(() => dom.window.close())
|
|
195
|
+
|
|
196
|
+
send({ e: 'pinokio:create', requestId: 'a', type: 'ask', prompt: 'hi' })
|
|
197
|
+
assert.equal(navigations.length, 0)
|
|
198
|
+
|
|
199
|
+
send({ e: 'pinokio:create', requestId: 'b', type: 'ask', prompt: 'hi' }, { origin: 'https://beta.pinokio.co' })
|
|
200
|
+
assert.equal(replies.length, 1)
|
|
201
|
+
assert.equal(navigations.length, 1)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test('the Explore page loads the create handoff', async () => {
|
|
205
|
+
const explore = await fs.readFile(exploreFile, 'utf8')
|
|
206
|
+
assert.match(explore, /<script src="\/explore-create-handoff\.js"><\/script>/)
|
|
207
|
+
})
|