pinokiod 8.3.21 → 8.3.23

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,22 +1,24 @@
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: the one built
5
+ // into Windows, and a newer one the pty library ships with itself.
10
6
  //
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.
7
+ // The copy built into Windows 10 dates from around 2020 and is no longer
8
+ // updated. It keeps a full-screen program's "I own the screen" and "send me the
9
+ // mouse" requests to itself, so the page never hears them: it keeps its own
10
+ // scrollback and scrollbar next to the one the program draws, and the wheel and
11
+ // clicks never reach the program. The shipped copy passes both on.
12
+ //
13
+ // So shells on Windows 10 start on the shipped copy. Windows 11 and later keep
14
+ // the one built into Windows, and anywhere but Windows nothing here does
15
+ // anything.
14
16
  const fs = require('fs')
17
+ const os = require('os')
15
18
  const path = require('path')
16
19
 
17
- const KEY = "windows_console"
18
- const DEFAULT = "default"
19
- const BUNDLED = "bundled"
20
+ // the first Windows 11 build
21
+ const WINDOWS_11_BUILD = 22000
20
22
 
21
23
  // Inside the desktop app the library resolves to a path in the app archive
22
24
  // (app.asar), while its native module and these files are real files in the
@@ -41,34 +43,19 @@ const bundledAvailable = (files = bundledFiles()) => {
41
43
  }
42
44
  }
43
45
 
44
- const choice = (store) => (store && store.get(KEY) === BUNDLED ? BUNDLED : DEFAULT)
45
-
46
- // The row for the Settings page's General list: none except on Windows.
47
- const settings = (kernel) => {
48
- if (!kernel || kernel.platform !== "win32") return []
49
- return [{
50
- key: KEY,
51
- val: choice(kernel.store),
52
- options: [DEFAULT, BUNDLED],
53
- description: [
54
- "The console layer terminals run on. \"default\" is the one built into Windows.",
55
- "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.",
56
- ]
57
- }]
58
- }
59
-
60
- // Called with what the Settings page posted. The row is absent off Windows, and
61
- // anything but the two choices is ignored.
62
- const save = (store, config) => {
63
- const value = config && config[KEY]
64
- if (value === DEFAULT || value === BUNDLED) store.set(KEY, value)
46
+ // `release` is os.release(), "10.0.19045" on Windows 10 22H2. A version that
47
+ // cannot be read counts as not Windows 10.
48
+ const isWindows10 = (release = os.release()) => {
49
+ const match = /^\d+\.\d+\.(\d+)/.exec(release || "")
50
+ const build = match ? parseInt(match[1], 10) : 0
51
+ return build > 0 && build < WINDOWS_11_BUILD
65
52
  }
66
53
 
67
54
  // Extra options for the pty library when a shell is started.
68
- const ptyOptions = (kernel, available = bundledAvailable) => {
55
+ const ptyOptions = (kernel, available = bundledAvailable, release) => {
69
56
  if (!kernel || kernel.platform !== "win32") return {}
70
- if (choice(kernel.store) !== BUNDLED) return {}
57
+ if (!isWindows10(release)) return {}
71
58
  return available() ? { useConptyDll: true } : {}
72
59
  }
73
60
 
74
- module.exports = { KEY, settings, save, ptyOptions, bundledAvailable, bundledFiles, outsideArchive }
61
+ module.exports = { ptyOptions, isWindows10, bundledAvailable, bundledFiles, outsideArchive }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.21",
3
+ "version": "8.3.23",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -76,7 +76,6 @@ const Socket = require('./socket')
76
76
  const Kernel = require("../kernel")
77
77
  const packagejson = require("../package.json")
78
78
  const Environment = require("../kernel/environment")
79
- const WindowsConsole = require("../kernel/windows_console")
80
79
  const Cloudflare = require("../kernel/api/cloudflare")
81
80
  const Util = require("../kernel/util")
82
81
  const Info = require("../kernel/info")
@@ -3310,7 +3309,7 @@ class Server {
3310
3309
  key: "mode",
3311
3310
  val: this.mode,
3312
3311
  options: ["desktop", "background"]
3313
- }, ...WindowsConsole.settings(this.kernel), {
3312
+ }, {
3314
3313
  key: "HTTP_PROXY",
3315
3314
  val: (system_env.HTTP_PROXY || ""),
3316
3315
  show_on_click: "#proxy",
@@ -5572,7 +5571,6 @@ class Server {
5572
5571
  }
5573
5572
  this.kernel.store.set("mode", config.mode)
5574
5573
  }
5575
- WindowsConsole.save(this.kernel.store, config)
5576
5574
  // // 3. Handle Drive
5577
5575
  // if (config.drive) {
5578
5576
  // // if the home is different from the existing home, go forward
@@ -10602,7 +10600,7 @@ class Server {
10602
10600
  key: "mode",
10603
10601
  val: this.mode,
10604
10602
  options: ["desktop", "background"]
10605
- }, ...WindowsConsole.settings(this.kernel), {
10603
+ }, {
10606
10604
  key: "HTTP_PROXY",
10607
10605
  val: (system_env.HTTP_PROXY || ""),
10608
10606
  show_on_click: "#proxy",
@@ -1,73 +1,49 @@
1
- // The Windows console choice (kernel/windows_console.js): the row it adds to
2
- // the Settings page, what saving it stores, and the option it hands the pty
3
- // library when a shell starts. No shell is started here, and none of it runs
4
- // the bundled console layer itself: that exists only on Windows.
1
+ // Which Windows console layer a shell starts on (kernel/windows_console.js):
2
+ // the option it hands the pty library. No shell is started here, and none of
3
+ // it runs the shipped console layer itself: that exists only on Windows.
5
4
  const assert = require('node:assert/strict')
6
5
  const fs = require('node:fs')
7
6
  const os = require('node:os')
8
7
  const path = require('node:path')
9
8
  const test = require('node:test')
10
- const ejs = require('ejs')
11
9
 
12
10
  const WindowsConsole = require('../kernel/windows_console')
13
11
 
14
- const store = (initial = {}) => {
15
- const data = { ...initial }
16
- return { get: (key) => (key in data ? data[key] : null), set: (key, val) => { data[key] = val }, data }
17
- }
18
- const kernel = (platform, initial) => ({ platform, store: store(initial) })
19
12
  const present = () => true
20
13
  const missing = () => false
14
+ // os.release() on each
15
+ const WIN10 = '10.0.19045'
16
+ const WIN11 = '10.0.22000'
17
+ const WIN11_25H2 = '10.0.26200'
21
18
 
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')), [])
25
-
26
- const [row, ...rest] = WindowsConsole.settings(kernel('win32'))
27
- 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'])
31
-
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')
35
- })
36
-
37
- test('saving stores one of the two choices and nothing else', () => {
38
- const s = store()
39
- WindowsConsole.save(s, { theme: 'dark' }) // the row is absent off Windows
40
- assert.deepEqual(s.data, {})
41
- WindowsConsole.save(s, { windows_console: 'nonsense' })
42
- 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
-
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 })
52
-
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), {})
19
+ test('Windows 10 is every build before the first Windows 11 one', () => {
20
+ assert.equal(WindowsConsole.isWindows10('10.0.18363'), true)
21
+ assert.equal(WindowsConsole.isWindows10(WIN10), true)
22
+ assert.equal(WindowsConsole.isWindows10('10.0.21999'), true)
23
+ assert.equal(WindowsConsole.isWindows10(WIN11), false)
24
+ assert.equal(WindowsConsole.isWindows10('10.0.22631'), false)
25
+ assert.equal(WindowsConsole.isWindows10(WIN11_25H2), false)
26
+ // a version that cannot be read stays on what Windows has
27
+ assert.equal(WindowsConsole.isWindows10(''), false)
28
+ assert.equal(WindowsConsole.isWindows10('nonsense'), false)
29
+ // and on the machine running this, whatever it is, it has an answer
30
+ assert.equal(typeof WindowsConsole.isWindows10(), 'boolean')
59
31
  })
60
32
 
61
- test('the choice is read each time a shell starts', () => {
62
- 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), {})
33
+ test('a shell gets the shipped layer only on Windows 10, and only when its files are there', () => {
34
+ const on = { useConptyDll: true }
35
+ assert.deepEqual(WindowsConsole.ptyOptions({ platform: 'win32' }, present, WIN10), on)
36
+ assert.deepEqual(WindowsConsole.ptyOptions({ platform: 'win32' }, present, WIN11), {})
37
+ assert.deepEqual(WindowsConsole.ptyOptions({ platform: 'win32' }, present, WIN11_25H2), {})
38
+ // never off Windows, whatever the version string looks like
39
+ assert.deepEqual(WindowsConsole.ptyOptions({ platform: 'darwin' }, present, WIN10), {})
40
+ assert.deepEqual(WindowsConsole.ptyOptions({ platform: 'linux' }, present, WIN10), {})
41
+ assert.deepEqual(WindowsConsole.ptyOptions(null, present, WIN10), {})
42
+ // the install has no copy: the shell starts on the one built into Windows
43
+ assert.deepEqual(WindowsConsole.ptyOptions({ platform: 'win32' }, missing, WIN10), {})
68
44
  })
69
45
 
70
- test('the bundled layer counts as there only when both of its files are', (t) => {
46
+ test('the shipped layer counts as there only when both of its files are', (t) => {
71
47
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pinokio-conpty-'))
72
48
  t.after(() => fs.rmSync(dir, { recursive: true, force: true }))
73
49
  const files = ['conpty.dll', 'OpenConsole.exe'].map((name) => path.join(dir, name))
@@ -77,7 +53,7 @@ test('the bundled layer counts as there only when both of its files are', (t) =>
77
53
  fs.writeFileSync(files[1], '')
78
54
  assert.equal(WindowsConsole.bundledAvailable(files), true)
79
55
 
80
- // looked for where the pty library's install step puts them
56
+ // looked for where the pty library loads them from
81
57
  const expected = WindowsConsole.bundledFiles().map((file) => file.split(path.sep).slice(-4).join('/'))
82
58
  assert.deepEqual(expected, ['build/Release/conpty/conpty.dll', 'build/Release/conpty/OpenConsole.exe'])
83
59
  })
@@ -97,22 +73,8 @@ test('inside the desktop app the files are looked for beside the app archive', (
97
73
 
98
74
  test('the pty library still takes the option this hands it', () => {
99
75
  // The option is passed straight to the library. If an upgrade renames or
100
- // drops it, the Settings choice would silently do nothing.
76
+ // drops it, Windows 10 would silently stay on the copy built into Windows.
101
77
  const root = path.dirname(require.resolve('@homebridge/node-pty-prebuilt-multiarch/package.json'))
102
78
  const source = fs.readFileSync(path.join(root, 'lib', 'windowsTerminal.js'), 'utf8')
103
79
  assert.match(source, /opt\.useConptyDll/)
104
80
  })
105
-
106
- test('the Settings page draws the row as a dropdown with its explanation', async () => {
107
- const view = fs.readFileSync(path.resolve(__dirname, '../server/views/settings.ejs'), 'utf8')
108
- // the General form's loop over the rows, as the page has it
109
- const start = view.indexOf('<% config.forEach((c) => { %>')
110
- const end = view.indexOf('<% }) %>', view.indexOf("<div class='explanation'><%=c.description%></div>")) + '<% }) %>'.length
111
- assert.ok(start > 0 && end > start)
112
- const html = ejs.render(view.slice(start, end), { config: WindowsConsole.settings(kernel('win32', { windows_console: 'bundled' })) })
113
-
114
- assert.match(html, /<select name="windows_console">/)
115
- assert.match(html, /<option value="default">default<\/option>/)
116
- assert.match(html, /<option value="bundled" selected>bundled<\/option>/)
117
- assert.equal((html.match(/class='explanation'/g) || []).length, 2)
118
- })