pinokiod 8.3.23 → 8.3.26

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.26",
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')
@@ -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,
@@ -12638,6 +12641,10 @@ class Server {
12638
12641
  agent: req.agent
12639
12642
  })
12640
12643
  })
12644
+ registerGitPageRoutes(this.app, {
12645
+ kernel: this.kernel,
12646
+ getPageContext: (req) => ({ theme: this.theme, agent: req.agent })
12647
+ })
12641
12648
  /*
12642
12649
  * GET /connect/x
12643
12650
  * GET /connect/discord
@@ -16412,10 +16419,10 @@ class Server {
16412
16419
  await this.chrome(req, res, "launch")
16413
16420
  }))
16414
16421
  this.app.get("/pinokio/browser/:name/dev", ex(async (req, res) => {
16415
- await this.chrome(req, res, "browse")
16422
+ AppRunTabs.redirectDev(req, res)
16416
16423
  }))
16417
16424
  this.app.get("/pinokio/browser/:name/browse", ex(async (req, res) => {
16418
- await this.chrome(req, res, "browse")
16425
+ AppRunTabs.redirectDev(req, res)
16419
16426
  }))
16420
16427
  this.app.get("/pinokio/browser/:name", ex(async (req, res) => {
16421
16428
  await this.chrome(req, res, "run")
@@ -16459,13 +16466,13 @@ class Server {
16459
16466
  })
16460
16467
  }))
16461
16468
  this.app.get("/p/:name/dev", ex(async (req, res) => {
16462
- await this.chrome(req, res, "browse")
16469
+ AppRunTabs.redirectDev(req, res)
16463
16470
  }))
16464
16471
  this.app.get("/p/:name/files", ex(async (req, res) => {
16465
- res.redirect(`/p/${encodeURIComponent(req.params.name)}/dev?pinokio_dev_tab=files`)
16472
+ AppRunTabs.redirectDev(req, res, "files")
16466
16473
  }))
16467
16474
  this.app.get("/p/:name/browse", ex(async (req, res) => {
16468
- await this.chrome(req, res, "browse")
16475
+ AppRunTabs.redirectDev(req, res)
16469
16476
  }))
16470
16477
  this.app.get("/p/:name/snapshot_status", ex(async (req, res) => {
16471
16478
  let d = Date.now()
@@ -0,0 +1,51 @@
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
+ // locals(req, type, config) which tab the page should open on
6
+ // ?pinokio_tab=files|git a link asked for it
7
+ // ?git_publish=1 the Git tab, on its Publish section
8
+ // no launcher in the folder Files, since there is nothing to run yet
9
+ // redirectDev(req, res, tab) sends an old Dev mode address to the Run page,
10
+ // without launching the app (Dev mode never launched it), keeping its query
11
+ const TABS = new Set(["files", "git"])
12
+
13
+ const locals = (req, type, config) => {
14
+ const query = (req && req.query) || {}
15
+ const publish = type === "run" && query.git_publish === "1"
16
+ let tab = ""
17
+ if (type === "run") {
18
+ if (publish) {
19
+ tab = "git"
20
+ } else if (TABS.has(query.pinokio_tab)) {
21
+ tab = query.pinokio_tab
22
+ } else if (config && config.init_required && !query.plugin) {
23
+ tab = "files"
24
+ }
25
+ }
26
+ return { run_initial_tab: tab, git_initial_publish: publish }
27
+ }
28
+
29
+ const redirectDev = (req, res, tab) => {
30
+ const query = new URLSearchParams()
31
+ let chosen = tab || ""
32
+ for (const [key, value] of Object.entries(req.query || {})) {
33
+ if (typeof value !== "string") {
34
+ continue
35
+ }
36
+ if (key === "pinokio_dev_tab") {
37
+ if (value === "files") chosen = "files"
38
+ } else if (key === "pinokio.publish") {
39
+ if (value === "1") query.set("git_publish", "1")
40
+ } else {
41
+ query.set(key, value)
42
+ }
43
+ }
44
+ if (chosen && !query.has("git_publish")) {
45
+ query.set("pinokio_tab", chosen)
46
+ }
47
+ const search = query.toString()
48
+ res.redirect(`/v/${encodeURIComponent(req.params.name)}${search ? `?${search}` : ""}`)
49
+ }
50
+
51
+ module.exports = { locals, redirectDev }
@@ -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,30 @@
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
+ try {
13
+ const url = new URL(window.location.href)
14
+ const had = url.searchParams.has('pinokio_tab') || url.searchParams.has('git_publish')
15
+ url.searchParams.delete('pinokio_tab')
16
+ url.searchParams.delete('git_publish')
17
+ if (had) {
18
+ window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`)
19
+ }
20
+ } catch (_) {}
21
+
22
+ const link = tab === 'files' || tab === 'git' ? document.querySelector(`#${tab}-tab.frame-link`) : null
23
+ if (link && typeof renderSelection === 'function') {
24
+ renderSelection({ target: link, force: true })
25
+ return
26
+ }
27
+ if (typeof maybeLaunchPluginFromQuery === 'function') {
28
+ maybeLaunchPluginFromQuery()
29
+ }
30
+ })()
@@ -0,0 +1,77 @@
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, following the row last clicked
4
+ // in the file list:
5
+ // a folder -> that folder
6
+ // a file -> the folder that holds it
7
+ // nothing -> the app's own folder
8
+ //
9
+ // The file list itself only highlights the open file; clicking a folder just
10
+ // expands it. So this also highlights the clicked folder, the same way a file is
11
+ // highlighted, to show which folder the button will open. The button's tooltip
12
+ // names it too.
13
+ (() => {
14
+ const button = document.getElementById('files-app-open-explorer')
15
+ const tree = document.getElementById('files-app-tree')
16
+ if (!button || !tree) {
17
+ return
18
+ }
19
+ const root = button.dataset.root || ''
20
+ let target = '' // folder to open, relative to the app's folder; '' is the app's folder
21
+ let markedRow = null // the folder row this script highlighted
22
+
23
+ const describe = () => {
24
+ const label = `Open ${target || 'the app folder'} in File Explorer`
25
+ button.title = label
26
+ button.setAttribute('aria-label', label)
27
+ }
28
+
29
+ tree.addEventListener('click', (event) => {
30
+ const row = event.target.closest('.files-app__tree-row')
31
+ if (!row || !tree.contains(row)) {
32
+ return
33
+ }
34
+ // the row's own buttons (open, rename, delete, more) are not a selection
35
+ if (event.target.closest('.files-app__tree-actions, .files-app__tree-more')) {
36
+ return
37
+ }
38
+ const path = row.dataset.path || ''
39
+ const isFolder = row.dataset.type === 'directory'
40
+ if (markedRow && markedRow !== row) {
41
+ markedRow.dataset.selected = 'false'
42
+ }
43
+ markedRow = null
44
+ const parts = path.split('/').filter(Boolean)
45
+ if (isFolder) {
46
+ row.dataset.selected = 'true'
47
+ markedRow = row
48
+ } else {
49
+ parts.pop()
50
+ }
51
+ target = parts.join('/')
52
+ describe()
53
+ })
54
+
55
+ button.addEventListener('click', () => {
56
+ if (!root) {
57
+ return
58
+ }
59
+ // a folder that was renamed or deleted since it was clicked falls back to the app's folder
60
+ if (markedRow && !markedRow.isConnected) {
61
+ markedRow = null
62
+ target = ''
63
+ describe()
64
+ }
65
+ const separator = root.includes('\\') ? '\\' : '/'
66
+ const folder = target
67
+ ? `${root.replace(/[\\/]+$/, '')}${separator}${target.split('/').join(separator)}`
68
+ : root
69
+ fetch('/openfs', {
70
+ method: 'POST',
71
+ headers: { 'Content-Type': 'application/json' },
72
+ body: JSON.stringify({ path: folder, command: 'open' }),
73
+ }).catch(() => {})
74
+ })
75
+
76
+ describe()
77
+ })()
@@ -0,0 +1,28 @@
1
+ /* The Files page has no header. Its two buttons sit in the bar that holds the
2
+ open-file tabs, at the right: File Explorer (opens the folder selected in the
3
+ file list) and Save. On a phone the "back to files" button is at the left of
4
+ the same bar. They stay reachable while the file list is hidden. */
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
+ flex: 0 0 auto;
28
+ }