pinokiod 3.6.30 → 3.6.32

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/server/socket.js CHANGED
@@ -1,10 +1,8 @@
1
1
  const WebSocket = require('ws');
2
- const Util = require("../kernel/util")
3
2
  class Socket {
4
3
  constructor(parent) {
5
4
  this.buffer = {}
6
5
  this.connected = {}
7
- this.active_shell = {}
8
6
  this.parent = parent
9
7
  this.server = parent.server
10
8
  // this.kernel = parent.kernel
@@ -27,65 +25,42 @@ class Socket {
27
25
  // look for repos that match
28
26
 
29
27
  if (req.uri) {
30
- if (req.mode === "open") {
31
- // get the default script and respond
32
- let id = this.parent.kernel.api.filePath(req.uri)
33
- try {
34
- let default_url = await this.parent.kernel.api.get_default(id)
35
- console.log({ id, default_url })
36
- ws.send(JSON.stringify({
37
- data: {
38
- uri: default_url
39
- }
40
- }))
41
- } catch (e) {
42
- console.log(e)
43
- }
28
+ /******************************************************************
29
+ *
30
+ * req.uri is ALWAYS either of the two:
31
+ * 1. ~/...
32
+ * 2. https://github.com/...
33
+ *
34
+ * Need to turn it into absolute file path before subscribing
35
+ *
36
+ ******************************************************************/
37
+
38
+ // req.uri is always http or absolute path
39
+ let id = this.parent.kernel.api.filePath(req.uri)
40
+
41
+ if (req.status) {
42
+ ws.send(JSON.stringify({
43
+ data: this.parent.kernel.api.running[id] ? true : false
44
+ }))
45
+ } else if (req.stop) {
46
+ this.parent.kernel.api.stop({ params: req })
44
47
  } else {
45
- console.log("REQ.URI", req.uri)
46
- if (req.uri.startsWith("http")) {
47
- // open
48
- Util.openfs(req.uri, { mode: "open" })
49
- } else {
50
- /******************************************************************
51
- *
52
- * req.uri is ALWAYS either of the two:
53
- * 1. ~/...
54
- * 2. https://github.com/...
55
- *
56
- * Need to turn it into absolute file path before subscribing
57
- *
58
- ******************************************************************/
59
-
60
- // req.uri is always http or absolute path
61
- let id = this.parent.kernel.api.filePath(req.uri)
62
-
63
- if (req.status) {
64
- ws.send(JSON.stringify({
65
- data: this.parent.kernel.api.running[id] ? true : false
66
- }))
67
- } else if (req.stop) {
68
- this.parent.kernel.api.stop({ params: req })
69
- } else {
70
- let buf = this.buffer[id]
71
- let sh = this.active_shell[id]
72
- this.subscribe(ws, id, buf, sh)
73
- if (req.mode !== "listen") {
74
- // Run only if currently not running
75
- if (!this.parent.kernel.api.running[id]) {
76
-
77
- // clear the log first
78
-
79
- await this.parent.kernel.clearLog(id)
80
-
81
-
82
- this.parent.kernel.api.process(req)
83
- }
84
- }
48
+ this.subscribe(ws, id)
49
+
50
+ if (req.mode !== "listen") {
51
+ // Run only if currently not running
52
+ if (!this.parent.kernel.api.running[id]) {
53
+
54
+ // clear the log first
55
+
56
+ await this.parent.kernel.clearLog(id)
57
+
58
+
59
+ this.parent.kernel.api.process(req)
85
60
  }
86
61
  }
87
-
88
62
  }
63
+
89
64
  } else if (req.method) {
90
65
  this.subscribe(ws, req.method)
91
66
  if (req.mode !== "listen") {
@@ -93,11 +68,6 @@ class Socket {
93
68
  }
94
69
  } else if (req.emit) {
95
70
  this.parent.kernel.shell.emit(req)
96
- } else if (req.key && req.id) {
97
- this.parent.kernel.shell.emit({
98
- id: req.id,
99
- emit: req.key
100
- })
101
71
  }
102
72
  }
103
73
 
@@ -108,16 +78,11 @@ class Socket {
108
78
  headers.push('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
109
79
  });
110
80
  }
111
- subscribe(ws, id, buf, sh) {
81
+ subscribe(ws, id) {
112
82
 
113
83
  if (this.parent.kernel.api.running[id]) {
114
84
  ws.send(JSON.stringify({
115
- type: "connect",
116
- data: {
117
- id,
118
- state: buf,
119
- shell: sh
120
- }
85
+ type: "connect"
121
86
  }))
122
87
  }
123
88
 
@@ -155,15 +120,6 @@ class Socket {
155
120
  });
156
121
  }
157
122
 
158
- if (!this.buffer[id]) {
159
- this.buffer[id] = ""
160
- }
161
- if (e.data && e.data.raw) this.buffer[id] += e.data.raw
162
-
163
- if (e.data && e.data.shell_id) {
164
- this.active_shell[id] = e.data.shell_id
165
- }
166
-
167
123
  // send to caller session
168
124
  if (e.caller) {
169
125
  let caller
@@ -192,15 +148,6 @@ class Socket {
192
148
  }
193
149
  });
194
150
  }
195
-
196
- if (!this.buffer[caller]) {
197
- this.buffer[caller] = ""
198
- }
199
- if (e.data.raw) this.buffer[caller] += e.data.raw
200
-
201
- if (e.data && e.data.shell_id) {
202
- this.active_shell[caller] = e.data.shell_id
203
- }
204
151
  }
205
152
  }
206
153
  }
@@ -29,9 +29,7 @@
29
29
  */
30
30
  }
31
31
  #menu.margin {
32
- /*
33
32
  padding: 5px;
34
- */
35
33
  }
36
34
  #menu.margin i {
37
35
  display: none;
@@ -582,7 +580,7 @@ body.dark .loader-container {
582
580
  <div class='header-top header-item'>
583
581
  <div class='app-info'>
584
582
  <% if (config.icon) { %>
585
- <img src="<%=config.icon%>"/>
583
+ <img src="<%=rawpath%>/<%=config.icon%>?raw=true"/>
586
584
  <% } else { %>
587
585
  <i class="fa-regular fa-circle-dot"></i>
588
586
  <% } %>
@@ -597,15 +595,6 @@ body.dark .loader-container {
597
595
  <a target="<%=src%>" href="<%=src%>" class='btn header-item frame-link' data-index="0">
598
596
  <div class='tab'><i class="fa-regular fa-folder-open"></i> Files <div class='disk-usage'></div></div>
599
597
  </a>
600
- <div class='shells'>
601
- <% shells.forEach((shell, index) => { %>
602
- <a target="SHELL<%=index%>" data-mode="" href="<%=shell%>" class='btn header-item frame-link'>
603
- <div class='tab'>
604
- <i class='fa-solid fa-terminal'></i> <%=shell%></i>
605
- </div>
606
- </a>
607
- <% }) %>
608
- </div>
609
598
  <a target="/share/<%=name%>" href="/share/<%=name%>", class="btn header-item frame-link" data-index="1" data-mode="refresh">
610
599
  <div class='tab'><i class="fa-solid fa-wifi"></i> Share</div>
611
600
  </a>
@@ -664,7 +653,7 @@ body.dark .loader-container {
664
653
  <div class='bar'>
665
654
  <button class='btn2' id='menu-mobile'><i class="fa-solid fa-bars"></i></button>
666
655
  <button class='btn2' id='menu'>
667
- <img src="<%=config.icon%>"/>
656
+ <img src="<%=rawpath%>/<%=config.icon%>?raw=true"/>
668
657
  <i class="fa-solid fa-arrow-right-to-bracket fa-rotate-180"></i>
669
658
  </button>
670
659
  <% if (agent === "electron") { %>
@@ -1521,7 +1510,6 @@ body.dark .loader-container {
1521
1510
  console.log("asideHidden", asideHidden)
1522
1511
  if (!asideHidden) {
1523
1512
  // refresh only if aside
1524
- console.log("type", event.data.type)
1525
1513
  if (event.data.type === 'disconnect') {
1526
1514
  console.log("Refresh 1")
1527
1515
  refresh()
@@ -113,7 +113,6 @@ body.frozen {
113
113
  }
114
114
  </style>
115
115
  <script>
116
- let shell_id
117
116
  document.addEventListener("DOMContentLoaded", async () => {
118
117
  <% if (error) { %>
119
118
  document.querySelector(".requirements .content").innerHTML = '<div class="loading"><i class="fa-solid fa-circle-exclamation"></i> <%=error%></div>'
@@ -332,17 +331,8 @@ document.addEventListener("DOMContentLoaded", async () => {
332
331
 
333
332
  } else if (packet.type === 'connect') {
334
333
  // document.querySelector(".terminal-container").classList.remove("hidden")
335
- if (packet.data.id) {
336
- shell_id = packet.data.id
337
- }
338
- if (packet.data) {
339
- if (packet.data.shell) {
340
- shell_id = packet.data.shell
341
- }
342
- if (packet.data.state) {
343
- this.write(packet.data.state)
344
- }
345
- }
334
+ const message = "..........Connected!\r\n"
335
+ this.term.write(message)
346
336
  /*
347
337
  for(let i=0; i<message.length; i++) {
348
338
  await new Promise((r, reject) => {
@@ -246,6 +246,32 @@ body.dark .browser-options-row {
246
246
  <div>Serve Pinokio, installed apps, and even external apps (example: Ollama) to any device on the same network.</div>
247
247
  </div>
248
248
  </div>
249
+ <!--
250
+ <div class='browser-options-row'>
251
+ <a href="/proxy" class='flexible'>
252
+ <h3><i class="fa-solid fa-wifi"></i> Local Share</h3>
253
+ <div>Access Pinokio, Ollama, and other 3rd party apps from any device on the same network. By default it's off.</div>
254
+ </a>
255
+ <% if (false) { %>
256
+ <% if (proxy) { %>
257
+ <a id='wifi-stop' data-proxy="<%=proxy.proxy%>" class='btn'><div><i class="fa-solid fa-stop"></i> Stop</div></a>
258
+ <div class='flexible'>
259
+ <h3><i class="fa-solid fa-wifi"></i> Local Share</h3>
260
+ <div>Access Pinokio from any device on the same network. By default it's off.</div>
261
+ <span class='badge'><i class="fa-solid fa-circle-notch fa-spin"></i> Running at <a href="<%=proxy.proxy%>" target="_blank" features="browser"><%=proxy.proxy%></a></span>
262
+ <a id='wifi-qr' class='badge'><i class="fa-solid fa-qrcode"></i> Scan QR Code</a>
263
+ </div>
264
+ <% } else { %>
265
+ <a id='wifi' class='btn'><div><i class="fa-solid fa-play"></i> Start</div></a>
266
+ <a id='wifi-starting' class='btn disabled hidden'><div><i class="fa-solid fa-circle-notch fa-spin"></i> Starting</div></a>
267
+ <div class='flexible'>
268
+ <h3><i class="fa-solid fa-wifi"></i> Local Share</h3>
269
+ <div>Access Pinokio from any device on the same network. By default it's off.</div>
270
+ </div>
271
+ <% } %>
272
+ <% } %>
273
+ </div>
274
+ -->
249
275
  <div class='browser-options-row hidden'>
250
276
  <% if (cloudflare_pub) { %>
251
277
  <a id='cloudflare-stop' class='btn'><div><i class="fa-solid fa-stop"></i> Stop</div></a>
@@ -266,10 +292,17 @@ body.dark .browser-options-row {
266
292
  </div>
267
293
  </div>
268
294
  <% } %>
269
- <div id='fsmenu'>
270
- <div class='flexible'></div>
271
- <button id='newfolder' class='btn'><i class="fa-solid fa-folder-plus"></i> New Folder</button>
295
+ <!--
296
+ <div class='type-tabs'>
297
+ <% if (mode === "task") { %>
298
+ <a class='type-tab' href="/"><img src='/pinokio-<%=theme=='dark' ? 'white' : 'black'%>.png'> Apps</a>
299
+ <a class='type-tab selected' href="/?mode=task"> <img src='/<%=theme=='dark' ? 'term-dark.png' : 'term-white.png'%>'> Tasks</a>
300
+ <% } else { %>
301
+ <a class='type-tab selected' href="/"><img src='/pinokio-<%=theme=='dark' ? 'white' : 'black'%>.png'> Apps</a>
302
+ <a class='type-tab' href="/?mode=task"> <img src='/<%=theme=='dark' ? 'term-dark.png' : 'term-white.png'%>'> Tasks</a>
303
+ <% } %>
272
304
  </div>
305
+ -->
273
306
  <% if (running.length > 0) { %>
274
307
  <div class='running-apps'>
275
308
  <div class='header-label'>Running</div>
@@ -1061,30 +1094,6 @@ if (document.querySelector("#genlog")) {
1061
1094
  })
1062
1095
  })
1063
1096
  }
1064
- document.querySelector("#newfolder").addEventListener("click", async (e) => {
1065
- let folder = prompt("Enter a folder name for the new folder")
1066
- if (folder.includes(' ')) {
1067
- alert("Please use a folder name without a space")
1068
- return
1069
- }
1070
- let res = await fetch("/mkdir", {
1071
- method: "post",
1072
- headers: {
1073
- "Content-Type": "application/json"
1074
- },
1075
- body: JSON.stringify({
1076
- folder
1077
- })
1078
- }).then((res) => {
1079
- return res.json()
1080
- })
1081
- if (res.error) {
1082
- alert(res.error)
1083
- } else {
1084
- console.log(res)
1085
- location.href = res.success
1086
- }
1087
- })
1088
1097
 
1089
1098
  </script>
1090
1099
  </body>
@@ -111,7 +111,6 @@ body.frozen {
111
111
  </style>
112
112
  <link href="/terminal.css" rel="stylesheet"/>
113
113
  <script>
114
- let shell_id
115
114
  document.addEventListener("DOMContentLoaded", async () => {
116
115
  <% if (error) { %>
117
116
  document.querySelector(".requirements .content").innerHTML = '<div class="loading"><i class="fa-solid fa-circle-exclamation"></i> <%=error%></div>'
@@ -138,22 +137,9 @@ document.addEventListener("DOMContentLoaded", async () => {
138
137
  class RPC {
139
138
  constructor() {
140
139
  this.socket = new Socket()
141
- this.buffer = []
142
140
  }
143
141
  write(text) {
144
- // console.log(text)
145
- // this.buffer += text;
146
- // if (!this.timeout) {
147
- // this.timeout = setTimeout(() => {
148
- // console.log("write", this.buffer)
149
- // this.term.write(this.buffer);
150
- // this.buffer = "";
151
- // this.timeout = null;
152
- // }, 50);
153
- // }
154
- if (text !== "\u0007") {
155
- this.term.write(text)
156
- }
142
+ this.term.write(text)
157
143
  this.dirty = true
158
144
  }
159
145
  finished() {
@@ -248,12 +234,7 @@ document.addEventListener("DOMContentLoaded", async () => {
248
234
  // </div>`
249
235
  }
250
236
  } else if (packet.type === "stream") {
251
- // set the current shell id
252
- if (packet.data.id) {
253
- shell_id = packet.data.id
254
- }
255
237
  if (packet.data.raw) {
256
- // console.log({ packet })
257
238
  this.write(packet.data.raw)
258
239
  } else if (packet.data.json) {
259
240
  this.write(JSON.stringify(packet.data.json).replace(/\n/g, "\r\n"))
@@ -274,14 +255,8 @@ document.addEventListener("DOMContentLoaded", async () => {
274
255
  document.querySelector(".run .play").classList.remove("hidden")
275
256
  document.querySelector(".run .stop").classList.add("hidden")
276
257
  } else if (packet.type === 'connect') {
277
- if (packet.data) {
278
- if (packet.data.shell) {
279
- shell_id = packet.data.shell
280
- }
281
- if (packet.data.state) {
282
- this.write(packet.data.state)
283
- }
284
- }
258
+ const message = "..........Connected!\r\n"
259
+ this.write(message)
285
260
  /*
286
261
  for(let i=0; i<message.length; i++) {
287
262
  await new Promise((r, reject) => {
@@ -490,6 +465,7 @@ document.addEventListener("DOMContentLoaded", async () => {
490
465
  document.querySelector("#error-screen").classList.add("hidden")
491
466
  })
492
467
  */
468
+ console.log("instance", instance)
493
469
  instance.mark(packet.event)
494
470
  let element = document.querySelector("mark")
495
471
  element.scrollIntoView({ behavior: "smooth", block: "center" });
@@ -596,19 +572,13 @@ document.addEventListener("DOMContentLoaded", async () => {
596
572
  }
597
573
  const term = new Terminal(config)
598
574
  term.open(document.querySelector("#terminal"))
575
+
599
576
  term.attachCustomKeyEventHandler(event => {
600
- if ((event.ctrlKey || event.metaKey) && event.key === 'c') {
601
- const selection = term.getSelection();
602
- if (selection) {
603
- navigator.clipboard.writeText(selection);
604
- return false;
605
- }
577
+ if (event.ctrlKey && event.key === 'c' && term.hasSelection()) {
578
+ return false;
606
579
  }
607
- if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
608
- navigator.clipboard.readText().then((text) => {
609
- term.write(text);
610
- })
611
- return false
580
+ if (event.ctrlKey && event.key === 'v' && this._options.pasteWithCtrlV) {
581
+ return false;
612
582
  }
613
583
  return true;
614
584
  });
@@ -619,17 +589,6 @@ document.addEventListener("DOMContentLoaded", async () => {
619
589
  ////term.resize(cols, rows-5);
620
590
  //term.resize(cols, rows);
621
591
 
622
- term.onKey(({ key }) => {
623
- if (this.socket) {
624
- if (shell_id) {
625
- this.socket.run({
626
- key,
627
- id: shell_id
628
- })
629
- }
630
- }
631
- });
632
-
633
592
  const fitAddon = new FitAddon.FitAddon();
634
593
  // const searchAddon = new SearchAddon.SearchAddon();
635
594
  // const searchAddonBar = new SearchBarAddon.SearchBarAddon({searchAddon});
@@ -647,7 +606,6 @@ document.addEventListener("DOMContentLoaded", async () => {
647
606
  fitAddon.fit();
648
607
  this.term = term
649
608
  this.fit = fitAddon
650
-
651
609
  }
652
610
  this.term.focus()
653
611
  }
@@ -824,16 +782,14 @@ const reloadMemory = async () => {
824
782
  <span class='starting hidden'><i class="fa-solid fa-circle-notch fa-spin"></i> Starting...</span>
825
783
  <span class='stop hidden'><i class="fa-solid fa-stop"></i> Stop</span>
826
784
  </div>
827
- <% if (locals.filepath) { %>
828
- <button class='btn' id='open-fs' data-filepath="<%=filepath%>"><i class="fa-solid fa-eye"></i> View File</button>
829
- <% } %>
785
+ <button class='btn' id='open-fs' data-filepath="<%=filepath%>"><i class="fa-solid fa-eye"></i> View File</button>
830
786
  <!--
831
787
  <button class='btn' id='open-log' data-logpath="<%=logpath%>"><i class="fa-solid fa-align-left"></i> View Logs</button>
832
788
  -->
833
789
  </div>
834
790
  <% } %>
835
791
  </header>
836
- <% if (locals.requirements_pending) { %>
792
+ <% if (requirements_pending) { %>
837
793
  <div class='requirements'>
838
794
  <div class='content'>
839
795
  <div class='loading'>
@@ -842,7 +798,7 @@ const reloadMemory = async () => {
842
798
  </div>
843
799
  </div>
844
800
  <% } else { %>
845
- <% if (locals.install_required) { %>
801
+ <% if (install_required) { %>
846
802
  <div class='requirements'>
847
803
  <div class='content'>
848
804
  <div class='title'><i class="fa-solid fa-circle-exclamation"></i> Installation required</div>
package/kernel/store.js DELETED
@@ -1,58 +0,0 @@
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
Binary file