pinokiod 8.3.22 → 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.
- package/kernel/windows_console.js +16 -55
- package/package.json +1 -1
- package/server/index.js +2 -4
- package/test/windows-console.test.js +27 -112
|
@@ -1,30 +1,22 @@
|
|
|
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. There are two copies of it
|
|
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.
|
|
5
6
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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.
|
|
10
12
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
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.
|
|
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.
|
|
21
16
|
const fs = require('fs')
|
|
22
17
|
const os = require('os')
|
|
23
18
|
const path = require('path')
|
|
24
19
|
|
|
25
|
-
const KEY = "terminal_engine"
|
|
26
|
-
const SYSTEM = "system"
|
|
27
|
-
const PINOKIO = "pinokio"
|
|
28
20
|
// the first Windows 11 build
|
|
29
21
|
const WINDOWS_11_BUILD = 22000
|
|
30
22
|
|
|
@@ -51,50 +43,19 @@ const bundledAvailable = (files = bundledFiles()) => {
|
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
45
|
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
const defaultFor = (release = os.release()) => {
|
|
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()) => {
|
|
58
49
|
const match = /^\d+\.\d+\.(\d+)/.exec(release || "")
|
|
59
50
|
const build = match ? parseInt(match[1], 10) : 0
|
|
60
|
-
return build > 0 && build < WINDOWS_11_BUILD
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const choice = (store, release) => {
|
|
64
|
-
const saved = store && store.get(KEY)
|
|
65
|
-
return saved === SYSTEM || saved === PINOKIO ? saved : defaultFor(release)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// The row for the Settings page's General list: none except on Windows.
|
|
69
|
-
const settings = (kernel, release) => {
|
|
70
|
-
if (!kernel || kernel.platform !== "win32") return []
|
|
71
|
-
return [{
|
|
72
|
-
key: KEY,
|
|
73
|
-
val: choice(kernel.store, release),
|
|
74
|
-
options: [SYSTEM, PINOKIO],
|
|
75
|
-
description: [
|
|
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.",
|
|
78
|
-
]
|
|
79
|
-
}]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Called with what the Settings page posted. The row is absent off Windows, and
|
|
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) => {
|
|
87
|
-
const value = config && config[KEY]
|
|
88
|
-
if (value !== SYSTEM && value !== PINOKIO) return
|
|
89
|
-
if (value === defaultFor(release)) store.delete(KEY)
|
|
90
|
-
else store.set(KEY, value)
|
|
51
|
+
return build > 0 && build < WINDOWS_11_BUILD
|
|
91
52
|
}
|
|
92
53
|
|
|
93
54
|
// Extra options for the pty library when a shell is started.
|
|
94
55
|
const ptyOptions = (kernel, available = bundledAvailable, release) => {
|
|
95
56
|
if (!kernel || kernel.platform !== "win32") return {}
|
|
96
|
-
if (
|
|
57
|
+
if (!isWindows10(release)) return {}
|
|
97
58
|
return available() ? { useConptyDll: true } : {}
|
|
98
59
|
}
|
|
99
60
|
|
|
100
|
-
module.exports = {
|
|
61
|
+
module.exports = { ptyOptions, isWindows10, bundledAvailable, bundledFiles, outsideArchive }
|
package/package.json
CHANGED
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
|
-
},
|
|
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
|
-
},
|
|
10603
|
+
}, {
|
|
10606
10604
|
key: "HTTP_PROXY",
|
|
10607
10605
|
val: (system_env.HTTP_PROXY || ""),
|
|
10608
10606
|
show_on_click: "#proxy",
|
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
//
|
|
2
|
-
// the
|
|
3
|
-
//
|
|
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 {
|
|
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
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const kernel = (platform, initial) => ({ platform, store: store(initial) })
|
|
24
12
|
const present = () => true
|
|
25
13
|
const missing = () => false
|
|
26
14
|
// os.release() on each
|
|
@@ -28,93 +16,34 @@ const WIN10 = '10.0.19045'
|
|
|
28
16
|
const WIN11 = '10.0.22000'
|
|
29
17
|
const WIN11_25H2 = '10.0.26200'
|
|
30
18
|
|
|
31
|
-
test('Windows 10
|
|
32
|
-
assert.equal(WindowsConsole.
|
|
33
|
-
assert.equal(WindowsConsole.
|
|
34
|
-
assert.equal(WindowsConsole.
|
|
35
|
-
assert.equal(WindowsConsole.
|
|
36
|
-
assert.equal(WindowsConsole.
|
|
37
|
-
assert.equal(WindowsConsole.
|
|
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)
|
|
38
26
|
// a version that cannot be read stays on what Windows has
|
|
39
|
-
assert.equal(WindowsConsole.
|
|
40
|
-
assert.equal(WindowsConsole.
|
|
41
|
-
// and on the machine running this, whatever it is, it
|
|
42
|
-
assert.
|
|
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')
|
|
43
31
|
})
|
|
44
32
|
|
|
45
|
-
test('the
|
|
46
|
-
assert.deepEqual(WindowsConsole.settings(kernel('darwin'), WIN10), [])
|
|
47
|
-
assert.deepEqual(WindowsConsole.settings(kernel('linux'), WIN10), [])
|
|
48
|
-
|
|
49
|
-
const [row, ...rest] = WindowsConsole.settings(kernel('win32'), WIN10)
|
|
50
|
-
assert.equal(rest.length, 0)
|
|
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')
|
|
56
|
-
|
|
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')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('saving keeps only a choice that differs from the Windows version\'s own', () => {
|
|
66
|
-
const s = store()
|
|
67
|
-
WindowsConsole.save(s, { theme: 'dark' }, WIN10) // the row is absent off Windows
|
|
68
|
-
assert.deepEqual(s.data, {})
|
|
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)
|
|
76
|
-
assert.deepEqual(s.data, {})
|
|
77
|
-
|
|
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
|
-
})
|
|
90
|
-
|
|
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', () => {
|
|
33
|
+
test('a shell gets the shipped layer only on Windows 10, and only when its files are there', () => {
|
|
92
34
|
const on = { useConptyDll: true }
|
|
93
|
-
|
|
94
|
-
assert.deepEqual(WindowsConsole.ptyOptions(
|
|
95
|
-
assert.deepEqual(WindowsConsole.ptyOptions(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
assert.deepEqual(WindowsConsole.ptyOptions(
|
|
99
|
-
assert.deepEqual(WindowsConsole.ptyOptions(
|
|
100
|
-
//
|
|
101
|
-
assert.deepEqual(WindowsConsole.ptyOptions(
|
|
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), {})
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
test('the choice is read each time a shell starts', () => {
|
|
109
|
-
const k = kernel('win32')
|
|
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), {})
|
|
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), {})
|
|
115
44
|
})
|
|
116
45
|
|
|
117
|
-
test('the
|
|
46
|
+
test('the shipped layer counts as there only when both of its files are', (t) => {
|
|
118
47
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pinokio-conpty-'))
|
|
119
48
|
t.after(() => fs.rmSync(dir, { recursive: true, force: true }))
|
|
120
49
|
const files = ['conpty.dll', 'OpenConsole.exe'].map((name) => path.join(dir, name))
|
|
@@ -124,7 +53,7 @@ test('the bundled layer counts as there only when both of its files are', (t) =>
|
|
|
124
53
|
fs.writeFileSync(files[1], '')
|
|
125
54
|
assert.equal(WindowsConsole.bundledAvailable(files), true)
|
|
126
55
|
|
|
127
|
-
// looked for where the pty library
|
|
56
|
+
// looked for where the pty library loads them from
|
|
128
57
|
const expected = WindowsConsole.bundledFiles().map((file) => file.split(path.sep).slice(-4).join('/'))
|
|
129
58
|
assert.deepEqual(expected, ['build/Release/conpty/conpty.dll', 'build/Release/conpty/OpenConsole.exe'])
|
|
130
59
|
})
|
|
@@ -144,22 +73,8 @@ test('inside the desktop app the files are looked for beside the app archive', (
|
|
|
144
73
|
|
|
145
74
|
test('the pty library still takes the option this hands it', () => {
|
|
146
75
|
// The option is passed straight to the library. If an upgrade renames or
|
|
147
|
-
// drops it,
|
|
76
|
+
// drops it, Windows 10 would silently stay on the copy built into Windows.
|
|
148
77
|
const root = path.dirname(require.resolve('@homebridge/node-pty-prebuilt-multiarch/package.json'))
|
|
149
78
|
const source = fs.readFileSync(path.join(root, 'lib', 'windowsTerminal.js'), 'utf8')
|
|
150
79
|
assert.match(source, /opt\.useConptyDll/)
|
|
151
80
|
})
|
|
152
|
-
|
|
153
|
-
test('the Settings page draws the row as a dropdown with its explanation', async () => {
|
|
154
|
-
const view = fs.readFileSync(path.resolve(__dirname, '../server/views/settings.ejs'), 'utf8')
|
|
155
|
-
// the General form's loop over the rows, as the page has it
|
|
156
|
-
const start = view.indexOf('<% config.forEach((c) => { %>')
|
|
157
|
-
const end = view.indexOf('<% }) %>', view.indexOf("<div class='explanation'><%=c.description%></div>")) + '<% }) %>'.length
|
|
158
|
-
assert.ok(start > 0 && end > start)
|
|
159
|
-
const html = ejs.render(view.slice(start, end), { config: WindowsConsole.settings(kernel('win32'), WIN10) })
|
|
160
|
-
|
|
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>/)
|
|
164
|
-
assert.equal((html.match(/class='explanation'/g) || []).length, 2)
|
|
165
|
-
})
|