pinokiod 3.6.23 → 3.6.25
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/api/index.js +2 -0
- package/kernel/api/process/index.js +42 -0
- package/kernel/index.js +24 -1
- package/kernel/shell.js +25 -15
- package/kernel/shells.js +1 -0
- package/kernel/store.js +58 -0
- package/kernel/util.js +6 -6
- package/package.json +1 -1
- package/script/index.js +12 -0
- package/server/index.js +100 -79
- package/server/socket.js +6 -0
- package/server/views/terminal.ejs +19 -0
package/kernel/api/index.js
CHANGED
|
@@ -795,6 +795,7 @@ class Api {
|
|
|
795
795
|
} else {
|
|
796
796
|
// 11. actually make the rpc call
|
|
797
797
|
result = await this.run(resolved.method, rpc, (stream, type) => {
|
|
798
|
+
console.log("RUN RESULT", { stream ,type })
|
|
798
799
|
let m = {
|
|
799
800
|
id: request.path,
|
|
800
801
|
caller: request.caller,
|
|
@@ -818,6 +819,7 @@ class Api {
|
|
|
818
819
|
// }
|
|
819
820
|
this.ondata(m)
|
|
820
821
|
})
|
|
822
|
+
console.log("EXEC RESULT", { result })
|
|
821
823
|
}
|
|
822
824
|
|
|
823
825
|
|
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
const waitOn = require('wait-on');
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
async function checkUrlStatus(url, message, interval, ondata) {
|
|
4
|
+
try {
|
|
5
|
+
console.log({ check: url, interval })
|
|
6
|
+
if (message) {
|
|
7
|
+
ondata({
|
|
8
|
+
raw: `\r\n${message}\r\n`
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
await axios.get(url, { timeout: interval });
|
|
12
|
+
return true;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.log({ error })
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function waitForUrl(url, message, interval, ondata) {
|
|
19
|
+
let isUp = await checkUrlStatus(url, message, interval, ondata)
|
|
20
|
+
console.log({ isUp })
|
|
21
|
+
if (isUp) {
|
|
22
|
+
return
|
|
23
|
+
} else {
|
|
24
|
+
await new Promise((resolve, reject) => {
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
resolve()
|
|
27
|
+
}, interval)
|
|
28
|
+
})
|
|
29
|
+
await waitForUrl(url, message, interval, ondata)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
2
32
|
class Process {
|
|
3
33
|
// async start(req, ondata, kernel) {
|
|
4
34
|
// /*
|
|
@@ -143,6 +173,15 @@ class Process {
|
|
|
143
173
|
|
|
144
174
|
or
|
|
145
175
|
|
|
176
|
+
params := {
|
|
177
|
+
url: <URL>,
|
|
178
|
+
interval: (optional) how often to retry checking (in seconds)
|
|
179
|
+
message: (optional) the message to display while retrying (default: no message)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
or
|
|
183
|
+
|
|
184
|
+
|
|
146
185
|
params := {
|
|
147
186
|
on: <wait-on condition https://github.com/jeffbski/wait-on>,
|
|
148
187
|
message: (optional) Description to display while waiting,
|
|
@@ -176,6 +215,9 @@ class Process {
|
|
|
176
215
|
this.resolve()
|
|
177
216
|
}, ms)
|
|
178
217
|
})
|
|
218
|
+
} else if (req.params.url) {
|
|
219
|
+
let interval = req.params.interval ? req.params.interval * 1000 : 1000
|
|
220
|
+
await waitForUrl(req.params.url, req.params.message, interval, ondata)
|
|
179
221
|
} else if (req.params.on) {
|
|
180
222
|
// Wait
|
|
181
223
|
if (req.params.message) {
|
package/kernel/index.js
CHANGED
|
@@ -26,6 +26,7 @@ const Config = require("./pinokio.json")
|
|
|
26
26
|
const Info = require('./info')
|
|
27
27
|
const Pipe = require("../pipe")
|
|
28
28
|
const Cloudflare = require('./api/cloudflare')
|
|
29
|
+
const Store = require('./store')
|
|
29
30
|
const VARS = {
|
|
30
31
|
pip: {
|
|
31
32
|
install: {
|
|
@@ -42,7 +43,29 @@ class Kernel {
|
|
|
42
43
|
schema = "<=3.6.0"
|
|
43
44
|
constructor(store) {
|
|
44
45
|
this.fetch = fetch
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
// STORE
|
|
48
|
+
// Previously custom STORE could be passed in. This was to support both electron and server based initialization
|
|
49
|
+
// But this creates complexity because the store location is not fixed
|
|
50
|
+
// Migrating it to ~/.pinokio/config.json
|
|
51
|
+
//
|
|
52
|
+
// 1. does ~/.pinokio exist?
|
|
53
|
+
// - load from that file
|
|
54
|
+
// 2. does ~/.pinokio NOT exist?
|
|
55
|
+
// - save the passed in options to the `~/.pinokio`
|
|
56
|
+
// - load the config
|
|
57
|
+
|
|
58
|
+
this.store = new Store()
|
|
59
|
+
let exists = this.store.exists()
|
|
60
|
+
console.log("Store exists?", exists)
|
|
61
|
+
if (!exists) {
|
|
62
|
+
console.log("doesn't exist")
|
|
63
|
+
// clone the store to the new store
|
|
64
|
+
this.store.clone(store.store)
|
|
65
|
+
// load from the store (this will be the last time this is used, since the next time it loads, it will load from the new store)
|
|
66
|
+
}
|
|
67
|
+
console.log("this.store", this.store.store())
|
|
68
|
+
|
|
46
69
|
this.arch = os.arch()
|
|
47
70
|
this.os = os
|
|
48
71
|
this.platform = os.platform()
|
package/kernel/shell.js
CHANGED
|
@@ -274,11 +274,12 @@ class Shell {
|
|
|
274
274
|
return response
|
|
275
275
|
} else {
|
|
276
276
|
let response = await this.request(params, async (stream) => {
|
|
277
|
-
if (stream
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
277
|
+
if (ondata) ondata(stream)
|
|
278
|
+
// if (stream.prompt) {
|
|
279
|
+
// this.resolve()
|
|
280
|
+
// } else {
|
|
281
|
+
// if (ondata) ondata(stream)
|
|
282
|
+
// }
|
|
282
283
|
})
|
|
283
284
|
return response
|
|
284
285
|
}
|
|
@@ -287,7 +288,10 @@ class Shell {
|
|
|
287
288
|
}
|
|
288
289
|
emit(message) {
|
|
289
290
|
if (this.ptyProcess) {
|
|
290
|
-
|
|
291
|
+
console.log("write", { message, input: this.input })
|
|
292
|
+
if (this.input) {
|
|
293
|
+
this.ptyProcess.write(message)
|
|
294
|
+
}
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
297
|
send(message, newline, cb) {
|
|
@@ -369,6 +373,9 @@ class Shell {
|
|
|
369
373
|
|
|
370
374
|
// not connected => make a new connection => which means get a new prompt
|
|
371
375
|
// if already connected => no need for a new prompt
|
|
376
|
+
if (params.input) {
|
|
377
|
+
this.input = params.input
|
|
378
|
+
}
|
|
372
379
|
if (params.persistent) {
|
|
373
380
|
this.persistent = params.persistent
|
|
374
381
|
}
|
|
@@ -900,6 +907,7 @@ class Shell {
|
|
|
900
907
|
}
|
|
901
908
|
}
|
|
902
909
|
kill(message, force) {
|
|
910
|
+
console.log("KILL")
|
|
903
911
|
|
|
904
912
|
this.done = true
|
|
905
913
|
this.ready = false
|
|
@@ -1007,6 +1015,7 @@ ${cleaned}
|
|
|
1007
1015
|
|
|
1008
1016
|
}
|
|
1009
1017
|
stream(msg, callback) {
|
|
1018
|
+
console.log("vt write", msg)
|
|
1010
1019
|
this.vt.write(msg, () => {
|
|
1011
1020
|
let buf = this.vts.serialize()
|
|
1012
1021
|
let cleaned = this.stripAnsi(buf)
|
|
@@ -1016,6 +1025,7 @@ ${cleaned}
|
|
|
1016
1025
|
cleaned,
|
|
1017
1026
|
state: cleaned
|
|
1018
1027
|
}
|
|
1028
|
+
console.log({ response })
|
|
1019
1029
|
if (this.cb) this.cb(response)
|
|
1020
1030
|
|
|
1021
1031
|
// Decide whether to kill or continue
|
|
@@ -1030,15 +1040,15 @@ ${cleaned}
|
|
|
1030
1040
|
// todo: may need to handle cases when the command returns immediately with no output (example: 'which brew' returns immediately with no text if brew doesn't exist)
|
|
1031
1041
|
setTimeout(() => {
|
|
1032
1042
|
if (cache === cleaned) {
|
|
1033
|
-
if (this.persistent) {
|
|
1034
|
-
if (this.cb) this.cb({
|
|
1035
|
-
//raw: cached_msg,
|
|
1036
|
-
//raw: msg,
|
|
1037
|
-
//raw: "",
|
|
1038
|
-
cleaned,
|
|
1039
|
-
state: cleaned,
|
|
1040
|
-
prompt: true
|
|
1041
|
-
})
|
|
1043
|
+
if (this.input || this.persistent) {
|
|
1044
|
+
// if (this.cb) this.cb({
|
|
1045
|
+
// //raw: cached_msg,
|
|
1046
|
+
// //raw: msg,
|
|
1047
|
+
// //raw: "",
|
|
1048
|
+
// cleaned,
|
|
1049
|
+
// state: cleaned,
|
|
1050
|
+
// prompt: true
|
|
1051
|
+
// })
|
|
1042
1052
|
callback()
|
|
1043
1053
|
} else {
|
|
1044
1054
|
callback()
|
package/kernel/shells.js
CHANGED
package/kernel/store.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const os = require('os')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
class Store {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.root = path.resolve(os.homedir(), ".pinokio")
|
|
7
|
+
if (!fs.existsSync(path.resolve(this.root))) {
|
|
8
|
+
fs.mkdirSync(path.resolve(this.root))
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exists() {
|
|
12
|
+
let p = path.resolve(this.root, "config.json")
|
|
13
|
+
return fs.existsSync(p)
|
|
14
|
+
}
|
|
15
|
+
clone(old) {
|
|
16
|
+
console.log("clone", old)
|
|
17
|
+
let p = path.resolve(this.root, "config.json")
|
|
18
|
+
fs.writeFileSync(p, JSON.stringify(old, null, 2))
|
|
19
|
+
}
|
|
20
|
+
set(key, val) {
|
|
21
|
+
let o
|
|
22
|
+
try {
|
|
23
|
+
let str = fs.readFileSync(path.resolve(this.root, "config.json"), "utf8")
|
|
24
|
+
o = JSON.parse(str)
|
|
25
|
+
} catch(e) {
|
|
26
|
+
o = {}
|
|
27
|
+
}
|
|
28
|
+
o[key] = val
|
|
29
|
+
fs.writeFileSync(path.resolve(this.root, "config.json"), JSON.stringify(o, null, 2))
|
|
30
|
+
}
|
|
31
|
+
get(key) {
|
|
32
|
+
try {
|
|
33
|
+
let str = fs.readFileSync(path.resolve(this.root, "config.json"), "utf8")
|
|
34
|
+
let o = JSON.parse(str)
|
|
35
|
+
return o[key]
|
|
36
|
+
} catch (e) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
delete(key) {
|
|
41
|
+
try {
|
|
42
|
+
let str = fs.readFileSync(path.resolve(this.root, "config.json"), "utf8")
|
|
43
|
+
let o = JSON.parse(str)
|
|
44
|
+
delete o[key]
|
|
45
|
+
fs.writeFileSync(path.resolve(this.root, "config.json"), JSON.stringify(o, null, 2))
|
|
46
|
+
} catch (e) {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
store() {
|
|
50
|
+
try {
|
|
51
|
+
let str = fs.readFileSync(path.resolve(this.root, "config.json"), "utf8")
|
|
52
|
+
let o = JSON.parse(str)
|
|
53
|
+
return o
|
|
54
|
+
} catch (e) {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
module.exports = Store
|
package/kernel/util.js
CHANGED
|
@@ -36,26 +36,26 @@ const du = async (folderpath) => {
|
|
|
36
36
|
const is_port_available = async (port) => {
|
|
37
37
|
return new Promise((resolve) => {
|
|
38
38
|
const server = http.createServer();
|
|
39
|
-
console.log("> Checking port availability", port)
|
|
39
|
+
// console.log("> Checking port availability", port)
|
|
40
40
|
try {
|
|
41
41
|
server.listen(port, (err) => {
|
|
42
42
|
if (err) {
|
|
43
|
-
console.log("> [1 port not available]", err)
|
|
43
|
+
// console.log("> [1 port not available]", err)
|
|
44
44
|
resolve(false); // Port is occupied
|
|
45
45
|
} else {
|
|
46
|
-
console.log("> [2 port available] test server started. closing test server now.")
|
|
46
|
+
// console.log("> [2 port available] test server started. closing test server now.")
|
|
47
47
|
server.close(() => {
|
|
48
|
-
console.log("> Test server closed.")
|
|
48
|
+
// console.log("> Test server closed.")
|
|
49
49
|
resolve(true); // Port is free
|
|
50
50
|
}); // Close the server immediately after testing
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
server.on('error', (err) => {
|
|
54
|
-
console.log("> [3 port not available]", err);
|
|
54
|
+
// console.log("> [3 port not available]", err);
|
|
55
55
|
resolve(false); // Port is occupied
|
|
56
56
|
});
|
|
57
57
|
} catch (e) {
|
|
58
|
-
console.log("> [4 port not available]", err)
|
|
58
|
+
// console.log("> [4 port not available]", err)
|
|
59
59
|
resolve(false) // port not available
|
|
60
60
|
}
|
|
61
61
|
});
|
package/package.json
CHANGED
package/script/index.js
CHANGED
|
@@ -4,6 +4,16 @@ const os = require('os')
|
|
|
4
4
|
const platform = os.platform()
|
|
5
5
|
const Server = require('../server')
|
|
6
6
|
class Store {
|
|
7
|
+
constructor() {
|
|
8
|
+
let o
|
|
9
|
+
try {
|
|
10
|
+
let str = fs.readFileSync(path.resolve(__dirname, "pinokio.json"), "utf8")
|
|
11
|
+
o = JSON.parse(str)
|
|
12
|
+
} catch(e) {
|
|
13
|
+
o = {}
|
|
14
|
+
}
|
|
15
|
+
this.store = o
|
|
16
|
+
}
|
|
7
17
|
set(key, val) {
|
|
8
18
|
let o
|
|
9
19
|
try {
|
|
@@ -13,6 +23,7 @@ class Store {
|
|
|
13
23
|
o = {}
|
|
14
24
|
}
|
|
15
25
|
o[key] = val
|
|
26
|
+
this.store = o
|
|
16
27
|
fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
|
|
17
28
|
}
|
|
18
29
|
get(key) {
|
|
@@ -31,6 +42,7 @@ class Store {
|
|
|
31
42
|
console.log("before delete", o)
|
|
32
43
|
delete o[key]
|
|
33
44
|
console.log("after delete", o)
|
|
45
|
+
this.store = o
|
|
34
46
|
fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
|
|
35
47
|
} catch (e) {
|
|
36
48
|
}
|
package/server/index.js
CHANGED
|
@@ -28,6 +28,8 @@ const multer = require('multer');
|
|
|
28
28
|
|
|
29
29
|
const ejs = require('ejs');
|
|
30
30
|
|
|
31
|
+
const DEFAULT_PORT = 42000
|
|
32
|
+
|
|
31
33
|
const ex = fn => (req, res, next) => {
|
|
32
34
|
Promise.resolve(fn(req, res, next)).catch(next);
|
|
33
35
|
};
|
|
@@ -45,7 +47,8 @@ class Server {
|
|
|
45
47
|
constructor(config) {
|
|
46
48
|
this.tabs = {}
|
|
47
49
|
this.agent = config.agent
|
|
48
|
-
this.port =
|
|
50
|
+
this.port = DEFAULT_PORT
|
|
51
|
+
// this.port = config.port
|
|
49
52
|
this.kernel = new Kernel(config.store)
|
|
50
53
|
// this.tunnels = {}
|
|
51
54
|
this.version = {
|
|
@@ -1886,76 +1889,76 @@ class Server {
|
|
|
1886
1889
|
// 5. existing home is NOT set + new home is set => go through with the "home" setting procedure
|
|
1887
1890
|
// 6. existing home is NOT set + new home is NOT set => don't touch anything => the homedir will be the default home
|
|
1888
1891
|
|
|
1889
|
-
// 2. HOME
|
|
1890
|
-
// 2.1. Check if the config includes NEW_HOME => if so,
|
|
1891
|
-
// - move the HOME folder to NEW_HOME
|
|
1892
|
-
// - set HOME=NEW_HOME
|
|
1893
|
-
// - remove NEW_HOME
|
|
1894
|
-
let existing_home = this.kernel.store.get("home")
|
|
1895
|
-
let new_home = this.kernel.store.get("new_home")
|
|
1896
|
-
|
|
1897
|
-
if (existing_home) {
|
|
1898
|
-
let exists = await fse.pathExists(existing_home)
|
|
1899
|
-
if (exists) {
|
|
1900
|
-
if (new_home) {
|
|
1901
|
-
let new_home_exists = await fse.pathExists(new_home)
|
|
1902
|
-
if (new_home_exists) {
|
|
1903
|
-
// - existing home is set
|
|
1904
|
-
// - existing home exists
|
|
1905
|
-
// - new home is set
|
|
1906
|
-
// - new home exists already
|
|
1907
|
-
// => delete store.new_home ==> will load at store.home
|
|
1908
|
-
this.kernel.store.delete("new_home")
|
|
1909
|
-
} else {
|
|
1910
|
-
// - existing home is set
|
|
1911
|
-
// - existing home exists
|
|
1912
|
-
// - new home is set
|
|
1913
|
-
// - new home does not exist
|
|
1914
|
-
// => run mv()
|
|
1915
|
-
// => update store.home
|
|
1916
|
-
// => delete store.new_home
|
|
1917
|
-
await this.mv(existing_home, new_home)
|
|
1918
|
-
this.kernel.store.set("home", new_home)
|
|
1919
|
-
this.kernel.store.delete("new_home")
|
|
1920
|
-
}
|
|
1921
|
-
} else {
|
|
1922
|
-
// - existing home is set
|
|
1923
|
-
// - existing home exists
|
|
1924
|
-
// - new home is not set
|
|
1925
|
-
// => This is most typical scenario => don't touch anything => the homedir will be the existing home
|
|
1926
|
-
}
|
|
1927
|
-
} else {
|
|
1928
|
-
if (new_home) {
|
|
1929
|
-
// - existing home is set
|
|
1930
|
-
// - but the existing home path DOES NOT exist
|
|
1931
|
-
// - new home is set
|
|
1932
|
-
// => This is an invalid scenario => Just to avoid disaster, just delete store.home and delete store.new_home
|
|
1933
|
-
// => the app will load at ~/pinokio
|
|
1934
|
-
this.kernel.store.delete("home")
|
|
1935
|
-
this.kernel.store.delete("new_home")
|
|
1936
|
-
} else {
|
|
1937
|
-
// - existing home is set
|
|
1938
|
-
// - but the existing home path DOES NOT exist
|
|
1939
|
-
// - new home is NOT set
|
|
1940
|
-
// => This is an invalid scenario => just delete store.home
|
|
1941
|
-
// => the app will load at ~/pinokio
|
|
1942
|
-
this.kernel.store.delete("home")
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
} else {
|
|
1946
|
-
if (new_home) {
|
|
1947
|
-
// - existing home is NOT set
|
|
1948
|
-
// - new home is set
|
|
1949
|
-
// => update store.home
|
|
1950
|
-
// => delete store.new_home
|
|
1951
|
-
this.kernel.store.set("home", new_home)
|
|
1952
|
-
this.kernel.store.delete("new_home")
|
|
1953
|
-
} else {
|
|
1954
|
-
// - existing home is NOT set
|
|
1955
|
-
// - new home is NOT set
|
|
1956
|
-
// => don't touch anything => will load at ~/pinokio
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1892
|
+
// // 2. HOME
|
|
1893
|
+
// // 2.1. Check if the config includes NEW_HOME => if so,
|
|
1894
|
+
// // - move the HOME folder to NEW_HOME
|
|
1895
|
+
// // - set HOME=NEW_HOME
|
|
1896
|
+
// // - remove NEW_HOME
|
|
1897
|
+
// let existing_home = this.kernel.store.get("home")
|
|
1898
|
+
// let new_home = this.kernel.store.get("new_home")
|
|
1899
|
+
//
|
|
1900
|
+
// if (existing_home) {
|
|
1901
|
+
// let exists = await fse.pathExists(existing_home)
|
|
1902
|
+
// if (exists) {
|
|
1903
|
+
// if (new_home) {
|
|
1904
|
+
// let new_home_exists = await fse.pathExists(new_home)
|
|
1905
|
+
// if (new_home_exists) {
|
|
1906
|
+
// // - existing home is set
|
|
1907
|
+
// // - existing home exists
|
|
1908
|
+
// // - new home is set
|
|
1909
|
+
// // - new home exists already
|
|
1910
|
+
// // => delete store.new_home ==> will load at store.home
|
|
1911
|
+
// this.kernel.store.delete("new_home")
|
|
1912
|
+
// } else {
|
|
1913
|
+
// // - existing home is set
|
|
1914
|
+
// // - existing home exists
|
|
1915
|
+
// // - new home is set
|
|
1916
|
+
// // - new home does not exist
|
|
1917
|
+
// // => run mv()
|
|
1918
|
+
// // => update store.home
|
|
1919
|
+
// // => delete store.new_home
|
|
1920
|
+
// await this.mv(existing_home, new_home)
|
|
1921
|
+
// this.kernel.store.set("home", new_home)
|
|
1922
|
+
// this.kernel.store.delete("new_home")
|
|
1923
|
+
// }
|
|
1924
|
+
// } else {
|
|
1925
|
+
// // - existing home is set
|
|
1926
|
+
// // - existing home exists
|
|
1927
|
+
// // - new home is not set
|
|
1928
|
+
// // => This is most typical scenario => don't touch anything => the homedir will be the existing home
|
|
1929
|
+
// }
|
|
1930
|
+
// } else {
|
|
1931
|
+
// if (new_home) {
|
|
1932
|
+
// // - existing home is set
|
|
1933
|
+
// // - but the existing home path DOES NOT exist
|
|
1934
|
+
// // - new home is set
|
|
1935
|
+
// // => This is an invalid scenario => Just to avoid disaster, just delete store.home and delete store.new_home
|
|
1936
|
+
// // => the app will load at ~/pinokio
|
|
1937
|
+
// this.kernel.store.delete("home")
|
|
1938
|
+
// this.kernel.store.delete("new_home")
|
|
1939
|
+
// } else {
|
|
1940
|
+
// // - existing home is set
|
|
1941
|
+
// // - but the existing home path DOES NOT exist
|
|
1942
|
+
// // - new home is NOT set
|
|
1943
|
+
// // => This is an invalid scenario => just delete store.home
|
|
1944
|
+
// // => the app will load at ~/pinokio
|
|
1945
|
+
// this.kernel.store.delete("home")
|
|
1946
|
+
// }
|
|
1947
|
+
// }
|
|
1948
|
+
// } else {
|
|
1949
|
+
// if (new_home) {
|
|
1950
|
+
// // - existing home is NOT set
|
|
1951
|
+
// // - new home is set
|
|
1952
|
+
// // => update store.home
|
|
1953
|
+
// // => delete store.new_home
|
|
1954
|
+
// this.kernel.store.set("home", new_home)
|
|
1955
|
+
// this.kernel.store.delete("new_home")
|
|
1956
|
+
// } else {
|
|
1957
|
+
// // - existing home is NOT set
|
|
1958
|
+
// // - new home is NOT set
|
|
1959
|
+
// // => don't touch anything => will load at ~/pinokio
|
|
1960
|
+
// }
|
|
1961
|
+
// }
|
|
1959
1962
|
}
|
|
1960
1963
|
async setConfig(config) {
|
|
1961
1964
|
let home = this.kernel.store.get("home")
|
|
@@ -1980,13 +1983,14 @@ class Server {
|
|
|
1980
1983
|
throw new Error("Invalid path: " + config.home)
|
|
1981
1984
|
}
|
|
1982
1985
|
|
|
1983
|
-
// check if the destination already exists => throw error
|
|
1984
|
-
let exists = await fse.pathExists(config.home)
|
|
1985
|
-
if (exists) {
|
|
1986
|
-
throw new Error(`The path ${config.home} already exists. Please remove the folder and retry`)
|
|
1987
|
-
}
|
|
1986
|
+
// // check if the destination already exists => throw error
|
|
1987
|
+
// let exists = await fse.pathExists(config.home)
|
|
1988
|
+
// if (exists) {
|
|
1989
|
+
// throw new Error(`The path ${config.home} already exists. Please remove the folder and retry`)
|
|
1990
|
+
// }
|
|
1988
1991
|
|
|
1989
|
-
this.kernel.store.set("new_home", config.home)
|
|
1992
|
+
//this.kernel.store.set("new_home", config.home)
|
|
1993
|
+
this.kernel.store.set("home", config.home)
|
|
1990
1994
|
}
|
|
1991
1995
|
|
|
1992
1996
|
}
|
|
@@ -2015,7 +2019,6 @@ class Server {
|
|
|
2015
2019
|
|
|
2016
2020
|
home = this.kernel.store.get("home")
|
|
2017
2021
|
theme = this.kernel.store.get("theme")
|
|
2018
|
-
let new_home = this.kernel.store.get("new_home")
|
|
2019
2022
|
}
|
|
2020
2023
|
async startLogging(homedir) {
|
|
2021
2024
|
console.log(">>>>>>> startLogging", homedir)
|
|
@@ -2052,7 +2055,25 @@ class Server {
|
|
|
2052
2055
|
}
|
|
2053
2056
|
}
|
|
2054
2057
|
}
|
|
2058
|
+
async running(port) {
|
|
2059
|
+
let p = port || DEFAULT_PORT
|
|
2060
|
+
const available = await Util.is_port_available(p)
|
|
2061
|
+
if (available) {
|
|
2062
|
+
return false
|
|
2063
|
+
} else {
|
|
2064
|
+
return true
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2055
2067
|
async start(options) {
|
|
2068
|
+
|
|
2069
|
+
// // ONLY start if not already running
|
|
2070
|
+
// let is_running = await this.running(this.port || DEFAULT_PORT)
|
|
2071
|
+
// if (is_running) {
|
|
2072
|
+
// console.log("pinokiod already running, skip..")
|
|
2073
|
+
// return
|
|
2074
|
+
// }
|
|
2075
|
+
//
|
|
2076
|
+
|
|
2056
2077
|
this.debug = false
|
|
2057
2078
|
if (options) {
|
|
2058
2079
|
this.debug = options.debug
|
|
@@ -2101,7 +2122,7 @@ class Server {
|
|
|
2101
2122
|
// determine port if port is not passed in
|
|
2102
2123
|
|
|
2103
2124
|
if (!this.port) {
|
|
2104
|
-
this.port =
|
|
2125
|
+
this.port = DEFAULT_PORT
|
|
2105
2126
|
// let platform = os.platform()
|
|
2106
2127
|
// if (platform === 'linux') {
|
|
2107
2128
|
// // on linux you are not allowed to listen on ports below 1024
|
package/server/socket.js
CHANGED
|
@@ -111,6 +111,7 @@ body.frozen {
|
|
|
111
111
|
</style>
|
|
112
112
|
<link href="/terminal.css" rel="stylesheet"/>
|
|
113
113
|
<script>
|
|
114
|
+
let shell_id
|
|
114
115
|
document.addEventListener("DOMContentLoaded", async () => {
|
|
115
116
|
<% if (error) { %>
|
|
116
117
|
document.querySelector(".requirements .content").innerHTML = '<div class="loading"><i class="fa-solid fa-circle-exclamation"></i> <%=error%></div>'
|
|
@@ -203,6 +204,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
203
204
|
rows: this.term.rows,
|
|
204
205
|
}
|
|
205
206
|
}, async (packet) => {
|
|
207
|
+
console.log({ packet })
|
|
206
208
|
if (packet.type === 'start') {
|
|
207
209
|
refreshParent(packet)
|
|
208
210
|
reloadMemory()
|
|
@@ -234,6 +236,10 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
234
236
|
// </div>`
|
|
235
237
|
}
|
|
236
238
|
} else if (packet.type === "stream") {
|
|
239
|
+
// set the current shell id
|
|
240
|
+
if (packet.data.id) {
|
|
241
|
+
shell_id = packet.data.id
|
|
242
|
+
}
|
|
237
243
|
if (packet.data.raw) {
|
|
238
244
|
this.write(packet.data.raw)
|
|
239
245
|
} else if (packet.data.json) {
|
|
@@ -589,6 +595,18 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
589
595
|
////term.resize(cols, rows-5);
|
|
590
596
|
//term.resize(cols, rows);
|
|
591
597
|
|
|
598
|
+
term.onKey(({ key }) => {
|
|
599
|
+
console.log({ key })
|
|
600
|
+
if (this.socket) {
|
|
601
|
+
if (shell_id) {
|
|
602
|
+
this.socket.run({
|
|
603
|
+
key,
|
|
604
|
+
id: shell_id
|
|
605
|
+
})
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
592
610
|
const fitAddon = new FitAddon.FitAddon();
|
|
593
611
|
// const searchAddon = new SearchAddon.SearchAddon();
|
|
594
612
|
// const searchAddonBar = new SearchBarAddon.SearchBarAddon({searchAddon});
|
|
@@ -606,6 +624,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
606
624
|
fitAddon.fit();
|
|
607
625
|
this.term = term
|
|
608
626
|
this.fit = fitAddon
|
|
627
|
+
|
|
609
628
|
}
|
|
610
629
|
this.term.focus()
|
|
611
630
|
}
|