pinokiod 0.1.24 → 0.1.26

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/index.js CHANGED
@@ -135,17 +135,19 @@ class Kernel {
135
135
  async init() {
136
136
  let home = this.store.get("home")
137
137
  if (home) {
138
+ this.homedir = home
138
139
 
139
- // check if the path exists
140
- let exists = fs.existsSync(home)
141
- if (exists) {
142
- this.homedir = home
143
- } else {
144
- // if it doesn't exists, means there was some error, so just delete this entry from the store, and set the default home as the home
145
- this.store.delete("home")
146
- this.homedir = path.resolve(os.homedir(), "pinokio")
147
- }
140
+ // // check if the path exists
141
+ // let exists = fs.existsSync(home)
142
+ // if (exists) {
143
+ // this.homedir = home
144
+ // } else {
145
+ // // if it doesn't exist, means there was some error, so just delete this entry from the store, and set the default home as the home
146
+ // this.store.delete("home")
147
+ // this.homedir = path.resolve(os.homedir(), "pinokio")
148
+ // }
148
149
  } else {
150
+ // this.homedir = null
149
151
  this.homedir = path.resolve(os.homedir(), "pinokio")
150
152
  }
151
153
  console.log("homedir", this.homedir)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/script/index.js CHANGED
@@ -26,7 +26,9 @@ class Store {
26
26
  try {
27
27
  let str = fs.readFileSync(path.resolve(__dirname, "pinokio.json"), "utf8")
28
28
  let o = JSON.parse(str)
29
+ console.log("before delete", o)
29
30
  delete o[key]
31
+ console.log("after delete", o)
30
32
  fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
31
33
  } catch (e) {
32
34
  }
package/server/index.js CHANGED
@@ -1246,6 +1246,40 @@ class Server {
1246
1246
  })
1247
1247
  return response
1248
1248
  }
1249
+ async mv(existing_home, new_home) {
1250
+ //// Next, empty the bin folder => need to reinitialize because of symlinks, etc. with the package managers
1251
+ console.log("RUNNING RM BIN")
1252
+ const path_to_delete = path.resolve(existing_home, "bin")
1253
+ let del_cmd
1254
+ if (this.kernel.platform === "win32") {
1255
+ del_cmd = `rd /s /q ${path_to_delete}`
1256
+ } else {
1257
+ del_cmd = `rm -rf ${path_to_delete}`
1258
+ }
1259
+ console.log("del_cmd", del_cmd)
1260
+
1261
+ await this.sudo_exec(del_cmd, new_home)
1262
+ console.log("FINISHED RM BIN")
1263
+
1264
+ console.log("RUNNING MV")
1265
+ let mv_cmd
1266
+ if (this.kernel.platform === "win32") {
1267
+ // robocoyp returns 1 when successful
1268
+ //mv_cmd = `start /wait (robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL) ^& IF %ERRORLEVEL% LEQ 1 exit 0`
1269
+ //mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL`
1270
+ mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL`
1271
+ //mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL`
1272
+ } else {
1273
+ mv_cmd = `mv ${existing_home} ${new_home}`
1274
+ }
1275
+ try {
1276
+ await this.sudo_exec(mv_cmd, existing_home)
1277
+ } catch (e) {
1278
+ console.log("ROBOCOPY RESULT", e)
1279
+ }
1280
+ console.log("FINISHED MV")
1281
+ }
1282
+
1249
1283
  async syncConfig() {
1250
1284
  // 1. THEME
1251
1285
  this.theme = this.kernel.store.get("theme") || "light"
@@ -1263,61 +1297,91 @@ class Server {
1263
1297
  //this.logo = (this.theme === 'dark' ? "<img class='icon' src='/pinokio-white.png'>" : "<img class='icon' src='/pinokio-black.png'>")
1264
1298
  this.logo = '<i class="fa-solid fa-house"></i>'
1265
1299
 
1300
+ // 4. existing home is set + new home is set + existing home does NOT exist => delete the "home" field and DO NOT go through with the move command
1301
+ // 5. existing home is NOT set + new home is set => go through with the "home" setting procedure
1302
+ // 6. existing home is NOT set + new home is NOT set => don't touch anything => the homedir will be the default home
1303
+
1266
1304
  // 2. HOME
1267
1305
  // 2.1. Check if the config includes NEW_HOME => if so,
1268
1306
  // - move the HOME folder to NEW_HOME
1269
1307
  // - set HOME=NEW_HOME
1270
1308
  // - remove NEW_HOME
1309
+ let existing_home = this.kernel.store.get("home")
1271
1310
  let new_home = this.kernel.store.get("new_home")
1272
- console.log("new_home", new_home)
1273
- if (new_home) {
1274
- // move the home folder to new_home
1275
-
1276
- let existing_home = this.kernel.store.get("home")
1277
-
1278
- console.log({ existing_home, new_home })
1311
+ console.log("syncConfig", { existing_home, new_home })
1279
1312
 
1280
- if (existing_home) {
1281
- // if the home is already set, move
1282
-
1283
- //// Next, empty the bin folder => need to reinitialize because of symlinks, etc. with the package managers
1284
- console.log("RUNNING RM BIN")
1285
- const path_to_delete = path.resolve(existing_home, "bin")
1286
- let del_cmd
1287
- if (this.kernel.platform === "win32") {
1288
- del_cmd = `rd /s /q ${path_to_delete}`
1313
+ if (existing_home) {
1314
+ let exists = await fse.pathExists(existing_home)
1315
+ console.log("#A", { exists })
1316
+ if (exists) {
1317
+ console.log("#B", { new_home })
1318
+ if (new_home) {
1319
+ let new_home_exists = await fse.pathExists(new_home)
1320
+ console.log("#C", { new_home_exists })
1321
+ if (new_home_exists) {
1322
+ console.log("#D")
1323
+ // - existing home is set
1324
+ // - existing home exists
1325
+ // - new home is set
1326
+ // - new home exists already
1327
+ // => delete store.new_home ==> will load at store.home
1328
+ this.kernel.store.delete("new_home")
1329
+ } else {
1330
+ console.log("#E")
1331
+ // - existing home is set
1332
+ // - existing home exists
1333
+ // - new home is set
1334
+ // - new home does not exist
1335
+ // => run mv()
1336
+ // => update store.home
1337
+ // => delete store.new_home
1338
+ await this.mv(existing_home, new_home)
1339
+ this.kernel.store.set("home", new_home)
1340
+ this.kernel.store.delete("new_home")
1341
+ }
1289
1342
  } else {
1290
- del_cmd = `rm -rf ${path_to_delete}`
1343
+ console.log("#F")
1344
+ // - existing home is set
1345
+ // - existing home exists
1346
+ // - new home is not set
1347
+ // => This is most typical scenario => don't touch anything => the homedir will be the existing home
1291
1348
  }
1292
- console.log("del_cmd", del_cmd)
1293
-
1294
- await this.sudo_exec(del_cmd, new_home)
1295
- console.log("FINISHED RM BIN")
1296
-
1297
- console.log("RUNNING MV")
1298
- let mv_cmd
1299
- if (this.kernel.platform === "win32") {
1300
- // robocoyp returns 1 when successful
1301
- //mv_cmd = `start /wait (robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL) ^& IF %ERRORLEVEL% LEQ 1 exit 0`
1302
- //mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL /NDL`
1303
- mv_cmd = `start /wait robocopy ${existing_home} ${new_home} /E /MOVE /NFL`
1349
+ } else {
1350
+ console.log("#G", { new_home })
1351
+ if (new_home) {
1352
+ console.log("#H")
1353
+ // - existing home is set
1354
+ // - but the existing home path DOES NOT exist
1355
+ // - new home is set
1356
+ // => This is an invalid scenario => Just to avoid disaster, just delete store.home and delete store.new_home
1357
+ // => the app will load at ~/pinokio
1358
+ this.kernel.store.delete("home")
1359
+ this.kernel.store.delete("new_home")
1304
1360
  } else {
1305
- mv_cmd = `mv ${existing_home} ${new_home}`
1361
+ console.log("#I")
1362
+ // - existing home is set
1363
+ // - but the existing home path DOES NOT exist
1364
+ // - new home is NOT set
1365
+ // => This is an invalid scenario => just delete store.home
1366
+ // => the app will load at ~/pinokio
1367
+ this.kernel.store.delete("home")
1306
1368
  }
1307
- try {
1308
- await this.sudo_exec(mv_cmd, existing_home)
1309
- } catch (e) {
1310
- console.log("E", e)
1311
- }
1312
- console.log("FINISHED MV")
1313
-
1314
- // set home=new_home
1369
+ }
1370
+ } else {
1371
+ console.log("#J", { new_home })
1372
+ if (new_home) {
1373
+ console.log("#K")
1374
+ // - existing home is NOT set
1375
+ // - new home is set
1376
+ // => update store.home
1377
+ // => delete store.new_home
1315
1378
  this.kernel.store.set("home", new_home)
1316
- // delete new_home
1317
- console.log("STORE", this.kernel.store)
1318
1379
  this.kernel.store.delete("new_home")
1319
1380
  } else {
1320
- // if the home is not already set, don't need to do anything
1381
+ console.log("#L")
1382
+ // - existing home is NOT set
1383
+ // - new home is NOT set
1384
+ // => don't touch anything => will load at ~/pinokio
1321
1385
  }
1322
1386
  }
1323
1387
  }
@@ -1335,26 +1399,33 @@ class Server {
1335
1399
  // 2. Handle HOME
1336
1400
  if (config.home) {
1337
1401
  // set "new_home"
1338
- const basename = path.basename(config.home)
1339
1402
 
1340
- // check for invalid path
1341
- let isValidPath = (basename !== '' && basename !== config.home)
1342
- if (isValidPath) {
1403
+ // if the home is different from the existing home, go forward
1404
+ if (config.home !== home) {
1405
+ const basename = path.basename(config.home)
1406
+ // check for invalid path
1407
+ let isValidPath = (basename !== '' && basename !== config.home)
1408
+ if (!isValidPath) {
1409
+ throw new Error("Invalid path: " + config.home)
1410
+ }
1411
+
1412
+ // check if the destination already exists => throw error
1413
+ let exists = await fse.pathExists(config.home)
1414
+ if (exists) {
1415
+ throw new Error(`The path ${config.home} already exists. Please remove the folder and retry`)
1416
+ }
1417
+
1418
+ console.log("set new home", config.home)
1419
+
1343
1420
  this.kernel.store.set("new_home", config.home)
1344
- } else {
1345
- throw new Error("Invalid path: " + config.home)
1346
1421
  }
1347
1422
 
1348
- // check if the destination already exists => throw error
1349
- let exists = await fse.pathExists(config.home)
1350
- if (exists) {
1351
- throw new Error(`The path ${config.home} already exists. Please remove the folder and retry`)
1352
- }
1353
1423
  }
1354
1424
 
1355
1425
  home = this.kernel.store.get("home")
1356
1426
  theme = this.kernel.store.get("theme")
1357
- console.log("after setting config", { home, theme })
1427
+ let new_home = this.kernel.store.get("new_home")
1428
+ console.log("after setting config", { home, theme, new_home })
1358
1429
  }
1359
1430
  async start(debug) {
1360
1431
 
@@ -1431,7 +1502,8 @@ class Server {
1431
1502
  this.app.use(cookieParser());
1432
1503
  this.app.use(session({secret: "secret" }))
1433
1504
 
1434
- let home = this.kernel.homedir
1505
+ //let home = this.kernel.homedir
1506
+ let home = this.kernel.store.get("home")
1435
1507
  this.app.get("/", async (req, res) => {
1436
1508
  console.log("### req.headers", req.headers)
1437
1509
 
@@ -19,7 +19,7 @@ aside {
19
19
  -webkit-app-region: no-drag !important;
20
20
  cursor: auto;
21
21
  }
22
- header {
22
+ header.grabbable {
23
23
  padding: 32px 10px 0 !important;
24
24
  }
25
25
  /*