pinokiod 1.2.1 → 1.2.2

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/shell.js CHANGED
@@ -545,18 +545,41 @@ class Shell {
545
545
  let env_exists = await this.exists(env_path)
546
546
  if (env_exists) {
547
547
  params.message = [
548
+
549
+ (this.platform === 'win32' ? 'conda_hook' : `eval "$(conda shell.bash hook)"`),
550
+ `conda deactivate`,
551
+ `conda deactivate`,
552
+ `conda deactivate`,
553
+ `conda activate base`,
554
+
548
555
  (this.platform === "win32" ? `${activate_path} ${env_path}` : `source ${activate_path} ${env_path}`),
549
556
  //'pip install --upgrade pip',
550
557
  // 'pip install --upgrade wheel pip setuptools',
551
558
  ].concat(params.message)
552
559
  } else {
553
560
  params.message = [
561
+
562
+ (this.platform === 'win32' ? 'conda_hook' : `eval "$(conda shell.bash hook)"`),
563
+ `conda deactivate`,
564
+ `conda deactivate`,
565
+ `conda deactivate`,
566
+ `conda activate base`,
567
+
568
+
554
569
  `python -m venv ${env_path}`,
555
570
  (this.platform === "win32" ? `${activate_path} ${env_path}` : `source ${activate_path} ${env_path}`),
556
571
  //'pip install --upgrade pip',
557
572
  // 'pip install --upgrade wheel pip setuptools',
558
573
  ].concat(params.message)
559
574
  }
575
+ } else {
576
+ params.message = [
577
+ (this.platform === 'win32' ? 'conda_hook' : `eval "$(conda shell.bash hook)"`),
578
+ `conda deactivate`,
579
+ `conda deactivate`,
580
+ `conda deactivate`,
581
+ `conda activate base`,
582
+ ].concat(params.message)
560
583
  }
561
584
 
562
585
  return params
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -86,11 +86,11 @@ class Server {
86
86
  throw new Error(`Pinokio supports Windows release 18309 and up (current system: ${buildNumber}`)
87
87
  }
88
88
 
89
- if (buildNumber > 25000) {
90
- console.log("Windows buildNumber", buildNumber)
91
- throw new Error(`Pinokio does not currently support Windows Canary (versions 25000 and up). The current system is ${buildNumber}`)
92
-
93
- }
89
+ // if (buildNumber > 25000) {
90
+ // console.log("Windows buildNumber", buildNumber)
91
+ // throw new Error(`Pinokio does not currently support Windows Canary (versions 25000 and up). The current system is ${buildNumber}`)
92
+ //
93
+ // }
94
94
  }
95
95
  }
96
96
  getMemory(filepath) {
@@ -153,6 +153,7 @@ class Server {
153
153
  return {
154
154
  icon,
155
155
  menu: x.menu,
156
+ shortcuts: x.shortcuts,
156
157
  index: x.index,
157
158
  //icon: (x.isDirectory() ? "fa-solid fa-folder" : "fa-regular fa-file"),
158
159
  name,
@@ -972,14 +973,30 @@ class Server {
972
973
 
973
974
  items[i].menu = config.menu
974
975
  }
976
+
977
+ if (config.shortcuts) {
978
+ if (typeof config.shortcuts === "function") {
979
+ if (config.shortcuts.constructor.name === "AsyncFunction") {
980
+ config.shortcuts = await config.shortcuts(this.kernel)
981
+ } else {
982
+ config.shortcuts = config.shortcuts(this.kernel)
983
+ }
984
+ }
985
+ await this.renderShortcuts(uri, item.name, config, pathComponents)
986
+ items[i].shortcuts = config.shortcuts
987
+ }
975
988
  }
976
989
 
977
990
 
978
991
  // check if there is a running process with this folder name
979
992
  let runningApps = new Set()
980
993
  for(let key in this.kernel.api.running) {
981
- let re = new RegExp(item.name)
982
- if (re.test(key)) {
994
+ let p = this.kernel.path("api", items[i].name) + "/"
995
+ //let re = new RegExp(items[i].name)
996
+ //if (re.test(key)) {
997
+ console.log({ p , key })
998
+ //if (p === key) {
999
+ if (key.includes(p)) {
983
1000
  items[i].running = true
984
1001
  items[i].index = index
985
1002
  index++;
@@ -1020,6 +1037,9 @@ class Server {
1020
1037
  }
1021
1038
 
1022
1039
 
1040
+ console.log("#display", display)
1041
+
1042
+
1023
1043
  res.render("index", {
1024
1044
  proxy: pinokio_proxy[0],
1025
1045
  qr,
@@ -1066,9 +1086,11 @@ class Server {
1066
1086
  name = x.name
1067
1087
  description = ""
1068
1088
  }
1089
+ console.log("X", x)
1069
1090
  return {
1070
1091
  icon,
1071
1092
  menu: x.menu,
1093
+ shortcuts: x.shortcuts,
1072
1094
  //icon: (x.isDirectory() ? "fa-solid fa-folder" : "fa-regular fa-file"),
1073
1095
  name,
1074
1096
  uri,
@@ -1083,6 +1105,41 @@ class Server {
1083
1105
  })
1084
1106
  }
1085
1107
  }
1108
+ async renderShortcuts(uri, name, config, pathComponents) {
1109
+ console.log("config.shortcuts", config.shortcuts)
1110
+ if (config.shortcuts) {
1111
+ for(let i=0; i<config.shortcuts.length; i++) {
1112
+ let shortcut = config.shortcuts[i]
1113
+ if (shortcut.action) {
1114
+ if (shortcut.action.method === "stop") {
1115
+ if (shortcut.action.uri) {
1116
+ let absolute = path.resolve(__dirname, ...pathComponents, shortcut.action.uri)
1117
+ let seed = path.resolve(__dirname)
1118
+ let p = absolute.replace(seed, "")
1119
+ let link = p.split(/[\/\\]/).filter((x) => { return x }).join("/")
1120
+ let uri = "~/api/" + name + "/" + link
1121
+
1122
+ console.log("*uri", uri)
1123
+ config.shortcuts[i].action.uri = uri
1124
+
1125
+
1126
+ if (shortcut.hasOwnProperty("text")) {
1127
+ if (shortcut.hasOwnProperty("icon")) {
1128
+ config.shortcuts[i].html = `<i class="${shortcut.icon}"></i> ${shortcut.text}`
1129
+ } else {
1130
+ config.shortcuts[i].html = `${shortcut.text}`
1131
+ }
1132
+ config.shortcuts[i].btn = shortcut.html
1133
+ }
1134
+
1135
+ }
1136
+ }
1137
+ }
1138
+ }
1139
+ }
1140
+ }
1141
+
1142
+
1086
1143
  async renderMenu(uri, name, config, pathComponents) {
1087
1144
  if (config.menu) {
1088
1145
  for(let i=0; i<config.menu.length; i++) {
@@ -1093,6 +1150,7 @@ class Server {
1093
1150
  menuitem.menu = m.menu
1094
1151
  }
1095
1152
 
1153
+ console.log("MENUITEM", menuitem)
1096
1154
 
1097
1155
  if (menuitem.href && !menuitem.href.startsWith("http")) {
1098
1156
 
@@ -1125,12 +1183,31 @@ class Server {
1125
1183
 
1126
1184
  // check running
1127
1185
  let fullpath = this.kernel.path(menuitem.src.slice(1))
1186
+ console.log("fullpath", fullpath, menuitem.src, this.kernel.api.running)
1128
1187
  if (this.kernel.api.running[fullpath]) {
1129
1188
  menuitem.running = true
1130
1189
  }
1131
1190
 
1132
1191
  }
1133
1192
 
1193
+ if (menuitem.action) {
1194
+ if (menuitem.action.method === "stop") {
1195
+ if (menuitem.action.uri) {
1196
+ let absolute = path.resolve(__dirname, ...pathComponents, menuitem.action.uri)
1197
+ let seed = path.resolve(__dirname)
1198
+ let p = absolute.replace(seed, "")
1199
+ let link = p.split(/[\/\\]/).filter((x) => { return x }).join("/")
1200
+ let uri = "~/api/" + name + "/" + link
1201
+
1202
+ console.log("*uri", uri)
1203
+ config.menu[i].action.uri = uri
1204
+ }
1205
+ }
1206
+ }
1207
+
1208
+
1209
+
1210
+
1134
1211
 
1135
1212
 
1136
1213
  // if (menuitem.href && menuitem.params) {
@@ -1194,6 +1271,8 @@ class Server {
1194
1271
  if (menuitem.href) {
1195
1272
  // button
1196
1273
  config.menu[i].btn = menuitem.html
1274
+ } else if (menuitem.action) {
1275
+ config.menu[i].btn = menuitem.html
1197
1276
  } else if (menuitem.menu) {
1198
1277
  config.menu[i].btn = menuitem.html
1199
1278
  } else {
@@ -1841,7 +1920,7 @@ class Server {
1841
1920
  let uri = this.kernel.path("api")
1842
1921
  await this.renderMenu(uri, name, config, [])
1843
1922
 
1844
- console.log({ config })
1923
+ console.log("#CONFIG", JSON.stringify(config, null, 2))
1845
1924
  }
1846
1925
 
1847
1926
 
@@ -104,7 +104,8 @@ const install = async (name, url, term, socket, options) => {
104
104
  })
105
105
  } else {
106
106
  // ask the backend to create install.json and start.json if gradio
107
- location.href = `/?selected=${name}`
107
+ //location.href = `/?selected=${name}`
108
+ location.href = `/pinokio/browser/${name}`
108
109
 
109
110
  }
110
111
  }
@@ -15,6 +15,7 @@
15
15
  <script src="/opener.js"></script>
16
16
  <script src="/report.js"></script>
17
17
  <script src="/normalize.js"></script>
18
+ <script src="/Socket.js"></script>
18
19
  <% if (agent === "electron") { %>
19
20
  <link href="/electron.css" rel="stylesheet"/>
20
21
  <% } %>
@@ -409,6 +410,9 @@ body.dark .loader-container {
409
410
  background: rgba(255,255,255,0.3);
410
411
  }
411
412
  #menu {
413
+ display: flex;
414
+ }
415
+ #menu-mobile {
412
416
  display: none;
413
417
  }
414
418
  @media only screen and (max-width: 480px) {
@@ -445,6 +449,9 @@ body.dark .loader-container {
445
449
  display: none;
446
450
  }
447
451
  #menu {
452
+ display: none;
453
+ }
454
+ #menu-mobile {
448
455
  display: flex;
449
456
  }
450
457
  }
@@ -500,6 +507,7 @@ body.dark .loader-container {
500
507
  <div class='container'>
501
508
  <nav>
502
509
  <div class='hidden bar'>
510
+ <button class='btn2' id='menu-mobile'><i class="fa-solid fa-bars"></i></button>
503
511
  <button class='btn2' id='menu'><i class="fa-solid fa-bars"></i></button>
504
512
  <% if (agent === "electron") { %>
505
513
  <button class='btn2' id='back'><i class="fa-solid fa-arrow-left"></i></button>
@@ -1047,11 +1055,15 @@ const addTab = async (url) => {
1047
1055
 
1048
1056
 
1049
1057
 
1050
- if (document.querySelector("#menu")) {
1051
- document.querySelector("#menu").addEventListener("click", async (e) => {
1058
+ if (document.querySelector("#menu-mobile")) {
1059
+ document.querySelector("#menu-mobile").addEventListener("click", async (e) => {
1052
1060
  location.hash = ""
1053
1061
  refresh()
1054
- // renderSelection()
1062
+ })
1063
+ }
1064
+ if (document.querySelector("#menu")) {
1065
+ document.querySelector("#menu").addEventListener("click", async (e) => {
1066
+ document.querySelector("aside").classList.toggle("hidden")
1055
1067
  })
1056
1068
  }
1057
1069
  document.querySelector(".app-info").addEventListener("click", async (e) => {
@@ -1152,7 +1164,26 @@ document.querySelector("aside").addEventListener("click", async (e) => {
1152
1164
  }
1153
1165
  }
1154
1166
 
1155
- if (target.target === "_blank") {
1167
+ if (target.getAttribute("data-action")) {
1168
+ let actionStr = target.getAttribute("data-action")
1169
+ let action = JSON.parse(actionStr)
1170
+ console.log("action", action)
1171
+ if (action.method === "stop" && action.uri) {
1172
+ let socket = new Socket()
1173
+ socket.run({
1174
+ method: "kernel.api.stop",
1175
+ params: {
1176
+ uri: action.uri//"~" + location.pathname
1177
+ }
1178
+ }, (packet) => {
1179
+ console.log("packet", packet)
1180
+ if (packet.type === "result") {
1181
+ socket.close()
1182
+ // location.href = location.href
1183
+ }
1184
+ })
1185
+ }
1186
+ } else if (target.target === "_blank") {
1156
1187
  // nothing
1157
1188
  } else {
1158
1189
  if (target.classList.contains("reveal")) {
@@ -141,30 +141,6 @@ header .runner {
141
141
  <button class='btn' id='open-fs' data-filepath="<%=filepath%>"><i class="fa-solid fa-eye"></i> View Folder</button>
142
142
  </div>
143
143
  <% } %>
144
- <!--
145
- <div class='runner'>
146
- <% if (display.includes("menu")) { %>
147
- <% config.menu.forEach((item) => { %>
148
- <% if (item.btn) { %>
149
- <% if (item.target) { %>
150
- <% if (item.features) { %>
151
- <a target="<%=item.target%>" href="<%=item.href%>" features="<%=item.features%>" class='btn'><%-item.btn%></a>
152
- <% } else { %>
153
- <a target="<%=item.target%>" href="<%=item.href%>" class='btn'><%-item.btn%></a>
154
- <% } %>
155
- <% } else { %>
156
- <a href="<%=item.href%>" class='btn'><%-item.btn%></a>
157
- <% } %>
158
- <% } else if (item.label) { %>
159
- <label class='btn label'><%-item.label%></label>
160
- <% } %>
161
- <% }) %>
162
- <% } %>
163
- <% if (display.includes("install")) { %>
164
- <button id='install' class='btn' data-url="<%=config.install%>"><i class="fa-solid fa-plug"></i> Install</button>
165
- <% } %>
166
- </div>
167
- -->
168
144
  <% if (display.includes("dependencies")) { %>
169
145
  <div class='dependencies'>
170
146
  <h2>Prerequisites</h2>
@@ -201,31 +177,16 @@ header .runner {
201
177
  <div class='col'>
202
178
  <div class='uri'><i class="fa-regular fa-folder"></i><%=item.url%></div>
203
179
  <div class='title'><%=item.name%></div>
204
- <!--<div class='title'><a href="<%=item.browser_url%>"><%=item.name%> <i class="fa-solid fa-angles-right"></i></a></div>-->
205
180
  <div class='description'><%=item.description%></div>
206
- <!--
207
- <% if (item.menu && item.menu.length > 0) { %>
181
+ <% if (item.shortcuts && item.shortcuts.length > 0) { %>
208
182
  <div class='btns'>
209
- <% if (item.menu) { %>
210
- <% item.menu.forEach((btn) => { %>
211
- <% if (btn.btn) { %>
212
- <% if (btn.target) { %>
213
- <% if (btn.features) { %>
214
- <a target="<%=btn.target%>" href="<%=item.browser_url%>#<%=btn.href%>" features="<%=btn.features%>" class='btn'><%-btn.btn%></a>
215
- <% } else { %>
216
- <a target="<%=btn.target%>" href="<%=item.browser_url%>#<%=btn.href%>" class='btn'><%-btn.btn%></a>
217
- <% } %>
218
- <% } else { %>
219
- <a href="<%=item.browser_url%>#<%=btn.href%>" class='btn'><%-btn.btn%></a>
220
- <% } %>
221
- <% } else if (btn.label) { %>
222
- <label class='btn label'><%-btn.label%></label>
223
- <% } %>
224
- <% }) %>
225
- <% } %>
183
+ <% item.shortcuts.forEach((btn) => { %>
184
+ <% if (btn.btn) { %>
185
+ <button data-action="<%=btn.action ? JSON.stringify(btn.action) : ''%>" class='btn menu-btn'><%-btn.btn%></button>
186
+ <% } %>
187
+ <% }) %>
226
188
  </div>
227
189
  <% } %>
228
- -->
229
190
  </div>
230
191
  <div class='spinner'>
231
192
  <i class="fa-solid fa-circle-notch fa-spin"></i>
@@ -252,6 +213,15 @@ header .runner {
252
213
  <div class='uri'><i class="fa-regular fa-folder"></i><%=item.url%></div>
253
214
  <div class='title'><%=item.name%></div>
254
215
  <div class='description'><%=item.description%></div>
216
+ <% if (item.shortcuts && item.shortcuts.length > 0) { %>
217
+ <div class='btns'>
218
+ <% item.shortcuts.forEach((btn) => { %>
219
+ <% if (btn.btn) { %>
220
+ <button data-action="<%=btn.action ? JSON.stringify(btn.action) : ''%>" class='btn menu-btn'><%-btn.btn%></button>
221
+ <% } %>
222
+ <% }) %>
223
+ </div>
224
+ <% } %>
255
225
  </div>
256
226
  </h3>
257
227
  </a>
@@ -494,7 +464,62 @@ document.querySelector("form input[type=search]").addEventListener("input", (e)
494
464
  document.querySelector("form input[type=search]").focus()
495
465
  <% } %>
496
466
 
497
- <% if (display.includes("menu")) { %>
467
+ if (document.querySelector(".container")) {
468
+ document.querySelector(".container").addEventListener("click", async (e) => {
469
+ let el = e.target.closest(".menu-btn")
470
+ if (!el) {
471
+ if (el.classList.contains("menu-btn")) {
472
+ el = e.target
473
+ }
474
+ }
475
+
476
+ console.log("EL", el)
477
+ debugger
478
+
479
+ if (el) {
480
+ e.preventDefault()
481
+ e.stopPropagation()
482
+ let actionStr = el.getAttribute("data-action")
483
+ if (actionStr) {
484
+ let action = JSON.parse(actionStr)
485
+ console.log("action", action)
486
+ if (action.method === "stop" && action.uri) {
487
+ socket.run({
488
+ method: "kernel.api.stop",
489
+ params: {
490
+ uri: action.uri//"~" + location.pathname
491
+ }
492
+ }, (packet) => {
493
+ console.log("packet", packet)
494
+ if (packet.type === "result") {
495
+ socket.close()
496
+ location.href = location.href
497
+ }
498
+ })
499
+ }
500
+ }
501
+
502
+ }
503
+ })
504
+ }
505
+
506
+
507
+ // if (el) {
508
+ // let url = el.getAttribute("data-url")
509
+ // if (url) {
510
+ // let target = el.getAttribute("data-target")
511
+ // if (target && target.length > 0) {
512
+ // let agent = el.getAttribute("data-agent")
513
+ // if (agent && agent.length > 0) {
514
+ // window.open(url, target, agent)
515
+ // } else {
516
+ // window.open(url, target)
517
+ // }
518
+ // } else {
519
+ // location.href = url
520
+ // }
521
+ // }
522
+ // }
498
523
  //document.querySelector(".runner").addEventListener("click", async (e) => {
499
524
  // let el = e.target.closest(".btn")
500
525
  // if (!el) {
@@ -520,7 +545,6 @@ document.querySelector("form input[type=search]").focus()
520
545
  // }
521
546
  // }
522
547
  //})
523
- <% } %>
524
548
  <% if (display.includes("install")) { %>
525
549
  document.querySelector("#install").addEventListener("click", async (e) => {
526
550
  location.href = e.target.getAttribute("data-url")
@@ -10,7 +10,11 @@
10
10
  </div>
11
11
  <% } else { %>
12
12
  <% if (item.btn) { %>
13
- <% if (item.target === "_blank") { %>
13
+ <% if (item.action) { %>
14
+ <div data-action="<%=JSON.stringify(item.action)%>" class='btn header-item frame-link'>
15
+ <div class='tab'><%-item.btn%></div>
16
+ </div>
17
+ <% } else if (item.target === "_blank") { %>
14
18
  <a data-confirm="<%=item.confirm%>" data-index="<%=index%>" target="<%=item.target%>" data-mode="<%=item.mode%>" href="<%=item.href%>" class='btn header-item frame-link'>
15
19
  <div class='tab'><%-item.btn%></div>
16
20
  <div class='loader'>