@vnejs/desktop 0.0.5 → 0.0.7
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/package.json +2 -1
- package/src/electron.entry.js +1 -0
- package/src/electron.js +6 -19
- package/src/electron.utils.js +23 -0
- package/src/server.js +20 -20
- package/src/web.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/desktop",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Tools to run desktop app of @vnejs",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"commander": "13.1.0",
|
|
20
20
|
"express": "4.21.2",
|
|
21
21
|
"get-port": "5.1.1",
|
|
22
|
+
"electron": "30.3.1",
|
|
22
23
|
"open": "10.1.0"
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./electron")();
|
package/src/electron.js
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const electron = require("electron");
|
|
2
|
+
const proc = require("node:child_process");
|
|
2
3
|
|
|
3
4
|
const { runServer } = require("./server");
|
|
4
|
-
|
|
5
|
+
const { runElectron } = require("./electron.utils");
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
module.exports = () => {
|
|
8
|
+
proc.spawn(electron);
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
mainWindow = new BrowserWindow({ autoHideMenuBar: isProd, fullscreen: true, frame: true });
|
|
10
|
-
|
|
11
|
-
if (options.port) mainWindow.loadURL(`http://localhost:${options.port}/`);
|
|
12
|
-
if (options.file) mainWindow.loadFile(options.file);
|
|
13
|
-
|
|
14
|
-
mainWindow.on("closed", () => (mainWindow = null));
|
|
15
|
-
isProd ? mainWindow.removeMenu() : mainWindow.webContents.openDevTools();
|
|
10
|
+
return runServer({ rootDir: process.env.PWD }).then((port) => runElectron({ port }));
|
|
16
11
|
};
|
|
17
|
-
|
|
18
|
-
const runElectron = (options) => {
|
|
19
|
-
app.whenReady().then(() => createWindow(options));
|
|
20
|
-
app.on("window-all-closed", () => process.platform !== "darwin" && app.quit());
|
|
21
|
-
app.on("activate", () => mainWindow === null && createWindow(options));
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
runServer().then((port) => runElectron({ port }));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { app, BrowserWindow } = require("electron");
|
|
2
|
+
|
|
3
|
+
let mainWindow;
|
|
4
|
+
|
|
5
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
6
|
+
|
|
7
|
+
const createWindow = (options) => {
|
|
8
|
+
mainWindow = new BrowserWindow({ autoHideMenuBar: isProd, fullscreen: true, frame: true });
|
|
9
|
+
|
|
10
|
+
if (options.port) mainWindow.loadURL(`http://localhost:${options.port}/`);
|
|
11
|
+
if (options.file) mainWindow.loadFile(options.file);
|
|
12
|
+
|
|
13
|
+
mainWindow.on("closed", () => (mainWindow = null));
|
|
14
|
+
isProd ? mainWindow.removeMenu() : mainWindow.webContents.openDevTools();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const runElectron = (options) => {
|
|
18
|
+
app.whenReady().then(() => createWindow(options));
|
|
19
|
+
app.on("window-all-closed", () => process.platform !== "darwin" && app.quit());
|
|
20
|
+
app.on("activate", () => mainWindow === null && createWindow(options));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = { runElectron };
|
package/src/server.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
const express = require("express");
|
|
3
|
-
const getPort = require("get-port")
|
|
3
|
+
const getPort = require("get-port");
|
|
4
4
|
const bodyParser = require("body-parser");
|
|
5
5
|
const { writeFile, appendFile, readdirSync, existsSync, readFile } = require("fs");
|
|
6
6
|
|
|
7
|
-
const rootDir =
|
|
8
|
-
const
|
|
9
|
-
const gamePath = path.join(rootDir, "game");
|
|
7
|
+
const runServer = async ({ rootDir, oldApp } = {}) => {
|
|
8
|
+
const port = await getPort();
|
|
10
9
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
err ? res.json({ status: "error" }) : res.json({ status: "ok" })
|
|
14
|
-
);
|
|
10
|
+
const stateJson = path.join(rootDir, "state.json");
|
|
11
|
+
const gamePath = path.join(rootDir, "game");
|
|
15
12
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
13
|
+
const onSaveState = (req, res) =>
|
|
14
|
+
writeFile(stateJson, JSON.stringify(req.body), (err) =>
|
|
15
|
+
err ? res.json({ status: "error" }) : res.json({ status: "ok" })
|
|
16
|
+
);
|
|
21
17
|
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
const onGetState = (req, res) =>
|
|
19
|
+
readFile(stateJson, (err, data) =>
|
|
20
|
+
err
|
|
21
|
+
? writeFile(stateJson, "{}", () => res.json({ status: "ok", state: {} }))
|
|
22
|
+
: res.json({ status: "ok", state: JSON.parse(data.toString()) })
|
|
23
|
+
);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const onLog = (req, res) => {
|
|
26
|
+
res.end("ok");
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
appendFile(path.join(rootDir, "log.txt"), `${req.body.log}\n`);
|
|
29
|
+
};
|
|
30
30
|
|
|
31
31
|
console.log("server will try to start on localhost: ", port);
|
|
32
32
|
|
|
@@ -59,7 +59,7 @@ const runServer = async ({ oldApp } = {}) => {
|
|
|
59
59
|
if (error.code === "EADDRINUSE") {
|
|
60
60
|
console.log("server not started on port: ", port);
|
|
61
61
|
|
|
62
|
-
await runServer({ oldApp: app });
|
|
62
|
+
await runServer({ rootDir, oldApp: app });
|
|
63
63
|
|
|
64
64
|
resolve(port);
|
|
65
65
|
}
|
package/src/web.js
CHANGED