pinokiod 8.3.23 → 8.3.28

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": "8.3.23",
3
+ "version": "8.3.28",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -30,6 +30,8 @@ const registerFileRoutes = require('./routes/files')
30
30
  const registerAppRoutes = require('./routes/apps')
31
31
  const registerConnectRoutes = require('./routes/connect')
32
32
  const registerGithubAuthRoutes = require('./routes/github_auth')
33
+ const registerGitPageRoutes = require('./routes/git_page')
34
+ const AppRunTabs = require('./lib/app_run_tabs')
33
35
  const ServerAutolaunch = require('./autolaunch')
34
36
  const Git = require("../kernel/git")
35
37
  const TerminalApi = require('../kernel/api/terminal')
@@ -1855,7 +1857,7 @@ class Server {
1855
1857
  let autoselect
1856
1858
  let run_tab
1857
1859
  if (type === "run") {
1858
- if (options && options.no_autoselect) {
1860
+ if ((options && options.no_autoselect) || AppRunTabs.chosen(req)) {
1859
1861
  run_tab = "/v/" + name
1860
1862
  autoselect = false
1861
1863
  } else {
@@ -2004,6 +2006,7 @@ class Server {
2004
2006
  editor_tab: editor_tab,
2005
2007
  dev_initial_tab,
2006
2008
  vault_initial_reveal,
2009
+ ...AppRunTabs.locals(req, type, config),
2007
2010
  config,
2008
2011
  protection_enabled: protectionPreference ? protectionPreference.protection_enabled !== false : false,
2009
2012
  autolaunch_app: autolaunchAppState,
@@ -10670,11 +10673,13 @@ class Server {
10670
10673
  const baseUrl = `${protocol}://${host}`
10671
10674
 
10672
10675
  const wantsCreatePage = Object.prototype.hasOwnProperty.call(req.query, 'create')
10673
- const initialUrl = new URL(wantsCreatePage ? '/create/page' : '/home', baseUrl)
10676
+ // `page` is one of Pinokio's own pages to show in this window instead of home
10677
+ const startPage = typeof req.query.page === 'string' && /^\/[^/\\]/.test(req.query.page) ? req.query.page : ''
10678
+ const initialUrl = new URL(startPage || (wantsCreatePage ? '/create/page' : '/home'), baseUrl)
10674
10679
  const defaultUrl = new URL('/home', baseUrl)
10675
10680
 
10676
10681
  for (const [key, value] of Object.entries(req.query)) {
10677
- if (key === 'session' || key === 'create') {
10682
+ if (key === 'session' || key === 'create' || key === 'page') {
10678
10683
  continue
10679
10684
  }
10680
10685
  if (Array.isArray(value)) {
@@ -12638,6 +12643,10 @@ class Server {
12638
12643
  agent: req.agent
12639
12644
  })
12640
12645
  })
12646
+ registerGitPageRoutes(this.app, {
12647
+ kernel: this.kernel,
12648
+ getPageContext: (req) => ({ theme: this.theme, agent: req.agent })
12649
+ })
12641
12650
  /*
12642
12651
  * GET /connect/x
12643
12652
  * GET /connect/discord
@@ -16412,10 +16421,10 @@ class Server {
16412
16421
  await this.chrome(req, res, "launch")
16413
16422
  }))
16414
16423
  this.app.get("/pinokio/browser/:name/dev", ex(async (req, res) => {
16415
- await this.chrome(req, res, "browse")
16424
+ AppRunTabs.redirectDev(req, res)
16416
16425
  }))
16417
16426
  this.app.get("/pinokio/browser/:name/browse", ex(async (req, res) => {
16418
- await this.chrome(req, res, "browse")
16427
+ AppRunTabs.redirectDev(req, res)
16419
16428
  }))
16420
16429
  this.app.get("/pinokio/browser/:name", ex(async (req, res) => {
16421
16430
  await this.chrome(req, res, "run")
@@ -16459,13 +16468,13 @@ class Server {
16459
16468
  })
16460
16469
  }))
16461
16470
  this.app.get("/p/:name/dev", ex(async (req, res) => {
16462
- await this.chrome(req, res, "browse")
16471
+ AppRunTabs.redirectDev(req, res)
16463
16472
  }))
16464
16473
  this.app.get("/p/:name/files", ex(async (req, res) => {
16465
- res.redirect(`/p/${encodeURIComponent(req.params.name)}/dev?pinokio_dev_tab=files`)
16474
+ AppRunTabs.redirectDev(req, res, "files")
16466
16475
  }))
16467
16476
  this.app.get("/p/:name/browse", ex(async (req, res) => {
16468
- await this.chrome(req, res, "browse")
16477
+ AppRunTabs.redirectDev(req, res)
16469
16478
  }))
16470
16479
  this.app.get("/p/:name/snapshot_status", ex(async (req, res) => {
16471
16480
  let d = Date.now()
@@ -0,0 +1,63 @@
1
+ // The app page has one mode, Run. What used to be its Dev mode is now two tabs in
2
+ // the Run sidebar: Files and Git. This module holds the two things the server
3
+ // needs for that:
4
+ //
5
+ // chosen(req) the tab a link asked for, if any
6
+ // ?pinokio_tab=files|git that tab
7
+ // ?git_publish=1 the Git tab, on its Publish section
8
+ // A link that asks for a tab opens the page without launching the app.
9
+ // locals(req, type, config) which tab the page should open on
10
+ // the chosen tab; or, for a plain visit (an address with nothing after
11
+ // it), Files when the folder has nothing of its own to show: no launcher
12
+ // menu and no index.html, so the only thing Pinokio would open is its
13
+ // plain listing of the folder
14
+ // redirectDev(req, res, tab) sends an old Dev mode address to the Run page,
15
+ // without launching the app (Dev mode never launched it), keeping its query
16
+ const TABS = new Set(["files", "git"])
17
+
18
+ const chosen = (req) => {
19
+ const query = (req && req.query) || {}
20
+ if (query.git_publish === "1") return "git"
21
+ return TABS.has(query.pinokio_tab) ? query.pinokio_tab : ""
22
+ }
23
+
24
+ // the folder's default menu item is the plain listing of it that Pinokio falls back to
25
+ const onlyHasListing = (req, config) => {
26
+ const menu = config && Array.isArray(config.menu) ? config.menu : []
27
+ const first = menu.find((item) => item && item.default)
28
+ return Boolean(first && req && req.params && first.href === `/files/api/${req.params.name}`)
29
+ }
30
+
31
+ const locals = (req, type, config) => {
32
+ const query = (req && req.query) || {}
33
+ let tab = ""
34
+ if (type === "run") {
35
+ // a link that carries anything else (Settings from Home, a plugin, a file to reveal) keeps its own destination
36
+ tab = chosen(req) || (Object.keys(query).length === 0 && onlyHasListing(req, config) ? "files" : "")
37
+ }
38
+ return { run_initial_tab: tab, git_initial_publish: type === "run" && query.git_publish === "1" }
39
+ }
40
+
41
+ const redirectDev = (req, res, tab) => {
42
+ const query = new URLSearchParams()
43
+ let chosen = tab || ""
44
+ for (const [key, value] of Object.entries(req.query || {})) {
45
+ if (key === "pinokio_dev_tab") {
46
+ if (value === "files") chosen = "files"
47
+ } else if (key === "pinokio.publish") {
48
+ if (value === "1") query.set("git_publish", "1")
49
+ } else {
50
+ // a value given more than once stays given more than once
51
+ for (const item of [].concat(value)) {
52
+ if (typeof item === "string") query.append(key, item)
53
+ }
54
+ }
55
+ }
56
+ if (chosen && !query.has("git_publish")) {
57
+ query.set("pinokio_tab", chosen)
58
+ }
59
+ const search = query.toString()
60
+ res.redirect(`/v/${encodeURIComponent(req.params.name)}${search ? `?${search}` : ""}`)
61
+ }
62
+
63
+ module.exports = { chosen, locals, redirectDev }
@@ -605,7 +605,9 @@
605
605
  moreRow('Open in a new tab', 'fa-solid fa-arrow-up-right-from-square', () => {
606
606
  const session = win.session;
607
607
  const url = session && (session.tabUrl || session.fullUrl || session.url);
608
- if (url) whenRunning(session, () => window.open(url, '_blank', 'noopener'));
608
+ // opened inside a top-level Pinokio window, which in the desktop app is what
609
+ // carries the bar the window is dragged by
610
+ if (url) whenRunning(session, () => window.open(`/?page=${encodeURIComponent(url)}`, '_blank', 'noopener'));
609
611
  });
610
612
  // the session page's own appearance button, pressed from here (see embed below). Its
611
613
  // "sync size" button has no row: Refresh reloads the page, which sends the size too.
@@ -1185,7 +1185,7 @@
1185
1185
  throw new Error(payload && payload.error ? payload.error : 'Failed to create app.');
1186
1186
  }
1187
1187
  if (handOver('create_app', payload, tool)) return;
1188
- setStatus('Opening dev page', 'Redirecting to the new app.');
1188
+ setStatus('Opening the app', 'Redirecting to the new app.');
1189
1189
  api.navigate(payload.url);
1190
1190
  } catch (error) {
1191
1191
  fail(error, 'Failed to continue.');
@@ -0,0 +1,20 @@
1
+ // Loaded last on the app page (server/views/app.ejs), in Run mode.
2
+ //
3
+ // - Opens the sidebar tab a link asked for (Files or Git; the server passes it
4
+ // in data-tab). This is a chosen tab, so it also applies when the page was
5
+ // opened without launching the app.
6
+ // - Starts the plugin a link asked for (?plugin=...&prompt=...), as its own tab.
7
+ // The page already knows how; it only did it in the old Dev mode.
8
+ (() => {
9
+ const script = document.currentScript
10
+ const tab = script && script.dataset ? script.dataset.tab : ''
11
+
12
+ const link = tab === 'files' || tab === 'git' ? document.querySelector(`#${tab}-tab.frame-link`) : null
13
+ if (link && typeof renderSelection === 'function') {
14
+ renderSelection({ target: link, force: true })
15
+ return
16
+ }
17
+ if (typeof maybeLaunchPluginFromQuery === 'function') {
18
+ maybeLaunchPluginFromQuery()
19
+ }
20
+ })()
@@ -0,0 +1,94 @@
1
+ // The File Explorer button on the Files page (server/views/file_browser.ejs).
2
+ //
3
+ // Opens a folder in the system's file explorer:
4
+ // a folder was clicked in the file list -> that folder
5
+ // otherwise -> the folder of the file being edited
6
+ // nothing is open -> the app's own folder
7
+ //
8
+ // The file list itself only highlights the open file; clicking a folder just
9
+ // expands it. So this highlights the clicked folder too, to show which folder
10
+ // the button will open, and the button's tooltip names it. Opening or switching
11
+ // to a file afterwards takes over again.
12
+ (() => {
13
+ const button = document.getElementById('files-app-open-explorer')
14
+ const tree = document.getElementById('files-app-tree')
15
+ if (!button || !tree) {
16
+ return
17
+ }
18
+ const root = button.dataset.root || ''
19
+ const editedFile = () => (window.FilesApp && window.FilesApp.state && window.FilesApp.state.activePath) || ''
20
+ let clicked = null // the clicked folder: { path, row, edited: the file being edited at that moment }
21
+
22
+ const forget = () => {
23
+ if (clicked && clicked.row.isConnected) {
24
+ clicked.row.dataset.selected = 'false'
25
+ }
26
+ clicked = null
27
+ }
28
+
29
+ // the folder to open, relative to the app's folder; '' is the app's folder
30
+ const target = () => {
31
+ if (clicked && !clicked.row.isConnected) {
32
+ // the list was redrawn: the folder is still the target if it is still listed
33
+ const row = Array.from(tree.querySelectorAll('.files-app__tree-row'))
34
+ .find((item) => item.dataset.type === 'directory' && item.dataset.path === clicked.row.dataset.path)
35
+ if (row) {
36
+ row.dataset.selected = 'true'
37
+ clicked.row = row
38
+ } else {
39
+ clicked = null
40
+ }
41
+ }
42
+ if (clicked && clicked.edited !== editedFile()) {
43
+ forget()
44
+ }
45
+ if (clicked) {
46
+ return clicked.path
47
+ }
48
+ return editedFile().split('/').filter(Boolean).slice(0, -1).join('/')
49
+ }
50
+
51
+ tree.addEventListener('click', (event) => {
52
+ const row = event.target.closest('.files-app__tree-row')
53
+ // the row's own buttons (open, rename, delete, more) are not a selection
54
+ if (!row || event.target.closest('.files-app__tree-actions, .files-app__tree-more')) {
55
+ return
56
+ }
57
+ forget()
58
+ if (row.dataset.type === 'directory') {
59
+ row.dataset.selected = 'true'
60
+ clicked = { path: (row.dataset.path || '').split('/').filter(Boolean).join('/'), row, edited: editedFile() }
61
+ }
62
+ })
63
+
64
+ const describe = () => {
65
+ const label = `Open ${target() || 'the app folder'} in File Explorer`
66
+ button.title = label
67
+ button.setAttribute('aria-label', label)
68
+ }
69
+ button.addEventListener('pointerenter', describe)
70
+ button.addEventListener('focus', describe)
71
+ // switching to another open file takes over from a clicked folder right away
72
+ const tabs = document.getElementById('files-app-tabs')
73
+ if (tabs) {
74
+ tabs.addEventListener('click', () => setTimeout(describe, 0))
75
+ }
76
+
77
+ button.addEventListener('click', () => {
78
+ if (!root) {
79
+ return
80
+ }
81
+ const folder = target()
82
+ const separator = root.includes('\\') ? '\\' : '/'
83
+ fetch('/openfs', {
84
+ method: 'POST',
85
+ headers: { 'Content-Type': 'application/json' },
86
+ body: JSON.stringify({
87
+ path: folder ? `${root.replace(/[\\/]+$/, '')}${separator}${folder.split('/').join(separator)}` : root,
88
+ command: 'open',
89
+ }),
90
+ }).catch(() => {})
91
+ })
92
+
93
+ describe()
94
+ })()
@@ -0,0 +1,50 @@
1
+ /* The Files page has no header. Its buttons sit in the bar that holds the
2
+ open-file tabs: at the left, the one that hides or shows the file list (on a
3
+ phone, "back to files" instead); at the right, File Explorer (opens the
4
+ folder selected in the file list) and Save. */
5
+ .files-app__tabbar {
6
+ display: flex;
7
+ align-items: center;
8
+ gap: 8px;
9
+ padding: 0 10px;
10
+ border-bottom: 1px solid var(--border-color);
11
+ }
12
+ .files-app__tabbar .files-app__tabs {
13
+ flex: 1 1 auto;
14
+ min-width: 0;
15
+ padding-left: 0;
16
+ padding-right: 0;
17
+ border-bottom: none;
18
+ }
19
+ /* with no file open the tab list hides itself; keep its room so the buttons stay at the right */
20
+ .files-app__tabbar .files-app__tabs:empty {
21
+ display: block;
22
+ min-height: 30px;
23
+ }
24
+ .files-app__tabbar .files-app__meta,
25
+ .files-app__tabbar .files-app__save,
26
+ .files-app__tabbar .files-app__mobile-back,
27
+ .files-app__tabbar .files-app__sidebar-toggle {
28
+ flex: 0 0 auto;
29
+ }
30
+ /* On a phone the file list and the editor take turns. The bar stays above the
31
+ file list too, so Save and File Explorer are there in both. */
32
+ .files-app.files-app--mobile[data-mobile-view='list'] .files-app__main {
33
+ display: block;
34
+ flex: 0 0 auto;
35
+ order: -1;
36
+ }
37
+ .files-app.files-app--mobile[data-mobile-view='list'] .files-app__editor,
38
+ .files-app.files-app--mobile[data-mobile-view='list'] .files-app__status {
39
+ display: none;
40
+ }
41
+ /* an ordinary button in the bar, not a tab floating over the edge of the file list */
42
+ .files-app__tabbar .files-app__sidebar-toggle {
43
+ position: static;
44
+ transform: none;
45
+ width: 28px;
46
+ height: 28px;
47
+ border: 1px solid var(--border-color);
48
+ border-radius: 6px;
49
+ box-shadow: none;
50
+ }