pinokiod 8.3.20 → 8.3.22

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.
@@ -1,27 +1,43 @@
1
1
  // Which console layer a shell starts on, on Windows.
2
2
  //
3
3
  // Every Windows shell runs behind a console layer (ConPTY) that sits between
4
- // the program and the terminal page. The one built into Windows 10 keeps a
5
- // full-screen program's "I own the screen" and "send me the mouse" requests to
6
- // itself, so the page never hears them: it keeps its own scrollback and
7
- // scrollbar next to the one the program draws, and the wheel and clicks never
8
- // reach the program. The pty library ships a newer copy of the layer that
9
- // passes both on.
4
+ // the program and the terminal page. There are two copies of it to choose from:
10
5
  //
11
- // The newer copy is used only when the user picks it in Settings. The choice
12
- // is read each time a shell starts, so it applies to shells started after it
13
- // is saved. Anywhere but Windows nothing here does anything.
6
+ // "system" the one built into Windows. How old it is depends on the Windows
7
+ // version: on Windows 10 it dates from around 2020 and is no
8
+ // longer updated.
9
+ // "pinokio" a newer one that comes with Pinokio (the pty library ships it).
10
+ //
11
+ // The Windows 10 copy keeps a full-screen program's "I own the screen" and
12
+ // "send me the mouse" requests to itself, so the page never hears them: it
13
+ // keeps its own scrollback and scrollbar next to the one the program draws, and
14
+ // the wheel and clicks never reach the program. Pinokio's copy passes both on.
15
+ //
16
+ // So the copy used when nothing is chosen depends on the Windows version:
17
+ // pinokio on Windows 10, system on Windows 11 and later. Settings shows which
18
+ // one is in use and lets the user try the other. The choice is read each time a
19
+ // shell starts, so it applies to shells started after it is saved. Anywhere but
20
+ // Windows nothing here does anything.
14
21
  const fs = require('fs')
22
+ const os = require('os')
15
23
  const path = require('path')
16
24
 
17
- const KEY = "windows_console"
18
- const DEFAULT = "default"
19
- const BUNDLED = "bundled"
25
+ const KEY = "terminal_engine"
26
+ const SYSTEM = "system"
27
+ const PINOKIO = "pinokio"
28
+ // the first Windows 11 build
29
+ const WINDOWS_11_BUILD = 22000
30
+
31
+ // Inside the desktop app the library resolves to a path in the app archive
32
+ // (app.asar), while its native module and these files are real files in the
33
+ // folder beside it (app.asar.unpacked). Files put there when the app is built
34
+ // are not listed in the archive, so they are only found by the real path.
35
+ const outsideArchive = (dir, sep = path.sep) => dir.split(`app.asar${sep}`).join(`app.asar.unpacked${sep}`)
20
36
 
21
- // Where the pty library's install step puts its copy: next to its native module.
37
+ // Where the copy has to be for the library to load it: next to its native module.
22
38
  const bundledFiles = () => {
23
39
  const root = path.dirname(require.resolve('@homebridge/node-pty-prebuilt-multiarch/package.json'))
24
- const dir = path.join(root, 'build', 'Release', 'conpty')
40
+ const dir = path.join(outsideArchive(root), 'build', 'Release', 'conpty')
25
41
  return ['conpty.dll', 'OpenConsole.exe'].map((file) => path.join(dir, file))
26
42
  }
27
43
 
@@ -35,34 +51,50 @@ const bundledAvailable = (files = bundledFiles()) => {
35
51
  }
36
52
  }
37
53
 
38
- const choice = (store) => (store && store.get(KEY) === BUNDLED ? BUNDLED : DEFAULT)
54
+ // What a Windows version gets when the user has not chosen. `release` is
55
+ // os.release(), "10.0.19045" on Windows 10 22H2. A version that cannot be read
56
+ // gets the system copy.
57
+ const defaultFor = (release = os.release()) => {
58
+ const match = /^\d+\.\d+\.(\d+)/.exec(release || "")
59
+ const build = match ? parseInt(match[1], 10) : 0
60
+ return build > 0 && build < WINDOWS_11_BUILD ? PINOKIO : SYSTEM
61
+ }
62
+
63
+ const choice = (store, release) => {
64
+ const saved = store && store.get(KEY)
65
+ return saved === SYSTEM || saved === PINOKIO ? saved : defaultFor(release)
66
+ }
39
67
 
40
68
  // The row for the Settings page's General list: none except on Windows.
41
- const settings = (kernel) => {
69
+ const settings = (kernel, release) => {
42
70
  if (!kernel || kernel.platform !== "win32") return []
43
71
  return [{
44
72
  key: KEY,
45
- val: choice(kernel.store),
46
- options: [DEFAULT, BUNDLED],
73
+ val: choice(kernel.store, release),
74
+ options: [SYSTEM, PINOKIO],
47
75
  description: [
48
- "The console layer terminals run on. \"default\" is the one built into Windows.",
49
- "Choose \"bundled\" if a full-screen terminal app shows two scrollbars or ignores the mouse wheel (seen on Windows 10). Applies to terminals started after saving.",
76
+ "What terminals run on: \"system\" is the one built into Windows, \"pinokio\" is a newer one that comes with Pinokio.",
77
+ "Windows 10 starts on pinokio, Windows 11 and later on system. If terminals misbehave, try the other one. Applies to terminals started after saving.",
50
78
  ]
51
79
  }]
52
80
  }
53
81
 
54
82
  // Called with what the Settings page posted. The row is absent off Windows, and
55
- // anything but the two choices is ignored.
56
- const save = (store, config) => {
83
+ // anything but the two choices is ignored. Only a choice that differs from the
84
+ // Windows version's own is kept: the page posts this row with every save, and
85
+ // someone who never touched it should keep following their Windows version.
86
+ const save = (store, config, release) => {
57
87
  const value = config && config[KEY]
58
- if (value === DEFAULT || value === BUNDLED) store.set(KEY, value)
88
+ if (value !== SYSTEM && value !== PINOKIO) return
89
+ if (value === defaultFor(release)) store.delete(KEY)
90
+ else store.set(KEY, value)
59
91
  }
60
92
 
61
93
  // Extra options for the pty library when a shell is started.
62
- const ptyOptions = (kernel, available = bundledAvailable) => {
94
+ const ptyOptions = (kernel, available = bundledAvailable, release) => {
63
95
  if (!kernel || kernel.platform !== "win32") return {}
64
- if (choice(kernel.store) !== BUNDLED) return {}
96
+ if (choice(kernel.store, release) !== PINOKIO) return {}
65
97
  return available() ? { useConptyDll: true } : {}
66
98
  }
67
99
 
68
- module.exports = { KEY, settings, save, ptyOptions, bundledAvailable, bundledFiles }
100
+ module.exports = { KEY, settings, save, ptyOptions, defaultFor, bundledAvailable, bundledFiles, outsideArchive }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.20",
3
+ "version": "8.3.22",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,58 +13,105 @@ const WindowsConsole = require('../kernel/windows_console')
13
13
 
14
14
  const store = (initial = {}) => {
15
15
  const data = { ...initial }
16
- return { get: (key) => (key in data ? data[key] : null), set: (key, val) => { data[key] = val }, data }
16
+ return {
17
+ get: (key) => (key in data ? data[key] : null),
18
+ set: (key, val) => { data[key] = val },
19
+ delete: (key) => { delete data[key] },
20
+ data,
21
+ }
17
22
  }
18
23
  const kernel = (platform, initial) => ({ platform, store: store(initial) })
19
24
  const present = () => true
20
25
  const missing = () => false
26
+ // os.release() on each
27
+ const WIN10 = '10.0.19045'
28
+ const WIN11 = '10.0.22000'
29
+ const WIN11_25H2 = '10.0.26200'
21
30
 
22
- test('the Settings row exists on Windows only and starts on the built-in layer', () => {
23
- assert.deepEqual(WindowsConsole.settings(kernel('darwin')), [])
24
- assert.deepEqual(WindowsConsole.settings(kernel('linux')), [])
31
+ test('Windows 10 gets Pinokio\'s layer and Windows 11 and later the system one', () => {
32
+ assert.equal(WindowsConsole.defaultFor('10.0.18363'), 'pinokio')
33
+ assert.equal(WindowsConsole.defaultFor(WIN10), 'pinokio')
34
+ assert.equal(WindowsConsole.defaultFor('10.0.21999'), 'pinokio')
35
+ assert.equal(WindowsConsole.defaultFor(WIN11), 'system')
36
+ assert.equal(WindowsConsole.defaultFor('10.0.22631'), 'system')
37
+ assert.equal(WindowsConsole.defaultFor(WIN11_25H2), 'system')
38
+ // a version that cannot be read stays on what Windows has
39
+ assert.equal(WindowsConsole.defaultFor(''), 'system')
40
+ assert.equal(WindowsConsole.defaultFor('nonsense'), 'system')
41
+ // and on the machine running this, whatever it is, it is one of the two
42
+ assert.ok(['system', 'pinokio'].includes(WindowsConsole.defaultFor()))
43
+ })
44
+
45
+ test('the Settings row exists on Windows only and shows the layer in use', () => {
46
+ assert.deepEqual(WindowsConsole.settings(kernel('darwin'), WIN10), [])
47
+ assert.deepEqual(WindowsConsole.settings(kernel('linux'), WIN10), [])
25
48
 
26
- const [row, ...rest] = WindowsConsole.settings(kernel('win32'))
49
+ const [row, ...rest] = WindowsConsole.settings(kernel('win32'), WIN10)
27
50
  assert.equal(rest.length, 0)
28
- assert.equal(row.key, 'windows_console')
29
- assert.equal(row.val, 'default')
30
- assert.deepEqual(row.options, ['default', 'bundled'])
51
+ assert.equal(row.key, 'terminal_engine')
52
+ assert.deepEqual(row.options, ['system', 'pinokio'])
53
+ // nothing chosen: what the Windows version gets
54
+ assert.equal(row.val, 'pinokio')
55
+ assert.equal(WindowsConsole.settings(kernel('win32'), WIN11)[0].val, 'system')
31
56
 
32
- assert.equal(WindowsConsole.settings(kernel('win32', { windows_console: 'bundled' }))[0].val, 'bundled')
33
- // a value nobody could have picked reads as the built-in layer
34
- assert.equal(WindowsConsole.settings(kernel('win32', { windows_console: 'nonsense' }))[0].val, 'default')
57
+ // a choice wins over the Windows version, either way
58
+ assert.equal(WindowsConsole.settings(kernel('win32', { terminal_engine: 'system' }), WIN10)[0].val, 'system')
59
+ assert.equal(WindowsConsole.settings(kernel('win32', { terminal_engine: 'pinokio' }), WIN11)[0].val, 'pinokio')
60
+ // a value that is not one of the two reads as nothing chosen
61
+ assert.equal(WindowsConsole.settings(kernel('win32', { terminal_engine: 'nonsense' }), WIN10)[0].val, 'pinokio')
62
+ assert.equal(WindowsConsole.settings(kernel('win32', { terminal_engine: 'default' }), WIN11)[0].val, 'system')
35
63
  })
36
64
 
37
- test('saving stores one of the two choices and nothing else', () => {
65
+ test('saving keeps only a choice that differs from the Windows version\'s own', () => {
38
66
  const s = store()
39
- WindowsConsole.save(s, { theme: 'dark' }) // the row is absent off Windows
67
+ WindowsConsole.save(s, { theme: 'dark' }, WIN10) // the row is absent off Windows
40
68
  assert.deepEqual(s.data, {})
41
- WindowsConsole.save(s, { windows_console: 'nonsense' })
69
+ WindowsConsole.save(s, { terminal_engine: 'nonsense' }, WIN10)
70
+ assert.deepEqual(s.data, {})
71
+
72
+ // the page posts the row with every save: an untouched row stores nothing
73
+ WindowsConsole.save(s, { terminal_engine: 'pinokio' }, WIN10)
74
+ assert.deepEqual(s.data, {})
75
+ WindowsConsole.save(s, { terminal_engine: 'system' }, WIN11)
42
76
  assert.deepEqual(s.data, {})
43
- WindowsConsole.save(s, { windows_console: 'bundled' })
44
- assert.deepEqual(s.data, { windows_console: 'bundled' })
45
- WindowsConsole.save(s, { windows_console: 'default' })
46
- assert.deepEqual(s.data, { windows_console: 'default' })
47
- })
48
77
 
49
- test('a shell gets the bundled layer only on Windows, only when chosen, only when its files are there', () => {
50
- const chosen = { windows_console: 'bundled' }
51
- assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', chosen), present), { useConptyDll: true })
78
+ // the other one is kept
79
+ WindowsConsole.save(s, { terminal_engine: 'system' }, WIN10)
80
+ assert.deepEqual(s.data, { terminal_engine: 'system' })
81
+ // and going back to the Windows version's own clears it
82
+ WindowsConsole.save(s, { terminal_engine: 'pinokio' }, WIN10)
83
+ assert.deepEqual(s.data, {})
84
+
85
+ WindowsConsole.save(s, { terminal_engine: 'pinokio' }, WIN11)
86
+ assert.deepEqual(s.data, { terminal_engine: 'pinokio' })
87
+ WindowsConsole.save(s, { terminal_engine: 'system' }, WIN11)
88
+ assert.deepEqual(s.data, {})
89
+ })
52
90
 
53
- assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32'), present), {})
54
- assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', { windows_console: 'default' }), present), {})
55
- assert.deepEqual(WindowsConsole.ptyOptions(kernel('darwin', chosen), present), {})
56
- assert.deepEqual(WindowsConsole.ptyOptions(kernel('linux', chosen), present), {})
57
- // chosen, but the install has no copy: the shell starts as it always did
58
- assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', chosen), missing), {})
91
+ test('a shell gets the bundled layer only on Windows, only when it is the one in use, only when its files are there', () => {
92
+ const on = { useConptyDll: true }
93
+ // nothing chosen
94
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32'), present, WIN10), on)
95
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32'), present, WIN11), {})
96
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32'), present, WIN11_25H2), {})
97
+ // chosen
98
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', { terminal_engine: 'system' }), present, WIN10), {})
99
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', { terminal_engine: 'pinokio' }), present, WIN11), on)
100
+ // never off Windows
101
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('darwin', { terminal_engine: 'pinokio' }), present, WIN10), {})
102
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('linux', { terminal_engine: 'pinokio' }), present, WIN10), {})
103
+ // in use, but the install has no copy: the shell starts on the system one
104
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32'), missing, WIN10), {})
105
+ assert.deepEqual(WindowsConsole.ptyOptions(kernel('win32', { terminal_engine: 'pinokio' }), missing, WIN11), {})
59
106
  })
60
107
 
61
108
  test('the choice is read each time a shell starts', () => {
62
109
  const k = kernel('win32')
63
- assert.deepEqual(WindowsConsole.ptyOptions(k, present), {})
64
- WindowsConsole.save(k.store, { windows_console: 'bundled' })
65
- assert.deepEqual(WindowsConsole.ptyOptions(k, present), { useConptyDll: true })
66
- WindowsConsole.save(k.store, { windows_console: 'default' })
67
- assert.deepEqual(WindowsConsole.ptyOptions(k, present), {})
110
+ assert.deepEqual(WindowsConsole.ptyOptions(k, present, WIN11), {})
111
+ WindowsConsole.save(k.store, { terminal_engine: 'pinokio' }, WIN11)
112
+ assert.deepEqual(WindowsConsole.ptyOptions(k, present, WIN11), { useConptyDll: true })
113
+ WindowsConsole.save(k.store, { terminal_engine: 'system' }, WIN11)
114
+ assert.deepEqual(WindowsConsole.ptyOptions(k, present, WIN11), {})
68
115
  })
69
116
 
70
117
  test('the bundled layer counts as there only when both of its files are', (t) => {
@@ -82,6 +129,19 @@ test('the bundled layer counts as there only when both of its files are', (t) =>
82
129
  assert.deepEqual(expected, ['build/Release/conpty/conpty.dll', 'build/Release/conpty/OpenConsole.exe'])
83
130
  })
84
131
 
132
+ test('inside the desktop app the files are looked for beside the app archive', () => {
133
+ const win = 'C:\\Pinokio\\resources\\app.asar\\node_modules\\@homebridge\\node-pty-prebuilt-multiarch'
134
+ assert.equal(
135
+ WindowsConsole.outsideArchive(win, '\\'),
136
+ 'C:\\Pinokio\\resources\\app.asar.unpacked\\node_modules\\@homebridge\\node-pty-prebuilt-multiarch'
137
+ )
138
+ // already the real folder, or not in the desktop app at all: unchanged
139
+ const unpacked = 'C:\\Pinokio\\resources\\app.asar.unpacked\\node_modules\\x'
140
+ assert.equal(WindowsConsole.outsideArchive(unpacked, '\\'), unpacked)
141
+ assert.equal(WindowsConsole.outsideArchive('C:\\src\\pinokiod\\node_modules\\x', '\\'), 'C:\\src\\pinokiod\\node_modules\\x')
142
+ assert.equal(WindowsConsole.outsideArchive('/opt/app.asar/node_modules/x', '/'), '/opt/app.asar.unpacked/node_modules/x')
143
+ })
144
+
85
145
  test('the pty library still takes the option this hands it', () => {
86
146
  // The option is passed straight to the library. If an upgrade renames or
87
147
  // drops it, the Settings choice would silently do nothing.
@@ -96,10 +156,10 @@ test('the Settings page draws the row as a dropdown with its explanation', async
96
156
  const start = view.indexOf('<% config.forEach((c) => { %>')
97
157
  const end = view.indexOf('<% }) %>', view.indexOf("<div class='explanation'><%=c.description%></div>")) + '<% }) %>'.length
98
158
  assert.ok(start > 0 && end > start)
99
- const html = ejs.render(view.slice(start, end), { config: WindowsConsole.settings(kernel('win32', { windows_console: 'bundled' })) })
159
+ const html = ejs.render(view.slice(start, end), { config: WindowsConsole.settings(kernel('win32'), WIN10) })
100
160
 
101
- assert.match(html, /<select name="windows_console">/)
102
- assert.match(html, /<option value="default">default<\/option>/)
103
- assert.match(html, /<option value="bundled" selected>bundled<\/option>/)
161
+ assert.match(html, /<select name="terminal_engine">/)
162
+ assert.match(html, /<option value="system">system<\/option>/)
163
+ assert.match(html, /<option value="pinokio" selected>pinokio<\/option>/)
104
164
  assert.equal((html.match(/class='explanation'/g) || []).length, 2)
105
165
  })