@vnejs/desktop 0.2.4 → 0.2.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/desktop",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Tools to run desktop app of @vnejs",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/electron.js CHANGED
@@ -6,6 +6,15 @@ let mainWindow;
6
6
 
7
7
  protocol.registerSchemesAsPrivileged([{ scheme: "vnejs", privileges: { standard: true, secure: true, supportFetchAPI: true, corsEnabled: true } }]);
8
8
 
9
+ const withSteamDeckQuery = (url) => {
10
+ if (process.env.STEAM_DECK !== "1") return url;
11
+
12
+ const parsed = new URL(url);
13
+ parsed.searchParams.set("steamDeck", "1");
14
+
15
+ return parsed.toString();
16
+ };
17
+
9
18
  const createWindow = (options) => {
10
19
  mainWindow = new BrowserWindow({
11
20
  autoHideMenuBar: options.isProd,
@@ -14,8 +23,8 @@ const createWindow = (options) => {
14
23
  webPreferences: { contextIsolation: true, nodeIntegration: false },
15
24
  });
16
25
 
17
- if (options.port) mainWindow.loadURL(`http://localhost:${options.port}/`);
18
- if (options.file) mainWindow.loadURL(`vnejs://${options.file}`);
26
+ if (options.port) mainWindow.loadURL(withSteamDeckQuery(`http://localhost:${options.port}/`));
27
+ if (options.file) mainWindow.loadURL(withSteamDeckQuery(`vnejs://${options.file}`));
19
28
 
20
29
  mainWindow.on("closed", () => (mainWindow = null));
21
30
  options.isProd ? mainWindow.removeMenu() : mainWindow.webContents.openDevTools();
@@ -26,10 +35,29 @@ const createWindow = (options) => {
26
35
  });
27
36
  };
28
37
 
38
+ const QUIT_EXIT_FALLBACK_MS = 2000;
39
+
29
40
  const runElectron = (options) => {
30
41
  // Allow unmuted <video> autoplay in packaged builds (Steam / Electron).
31
42
  app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");
32
43
 
44
+ let isShuttingDown = false;
45
+
46
+ const shutdown = async () => {
47
+ if (isShuttingDown) return;
48
+
49
+ isShuttingDown = true;
50
+ setTimeout(() => app.exit(0), QUIT_EXIT_FALLBACK_MS);
51
+
52
+ try {
53
+ await options.onBeforeQuit?.();
54
+ } catch (error) {
55
+ console.log("Desktop shutdown failed", error);
56
+ }
57
+
58
+ app.quit();
59
+ };
60
+
33
61
  app.whenReady().then(() => {
34
62
  protocol.handle("vnejs", (request) => {
35
63
  const url = new URL(request.url);
@@ -44,8 +72,13 @@ const runElectron = (options) => {
44
72
  });
45
73
  createWindow(options);
46
74
  });
47
- app.on("window-all-closed", () => process.platform !== "darwin" && app.quit());
48
- app.on("activate", () => mainWindow === null && createWindow(options));
75
+ app.on("window-all-closed", shutdown);
76
+ app.on("before-quit", (event) => {
77
+ if (isShuttingDown) return;
78
+
79
+ event.preventDefault();
80
+ shutdown();
81
+ });
49
82
  };
50
83
 
51
84
  module.exports = { runElectron };
package/src/server.js CHANGED
@@ -320,7 +320,7 @@ const runServer = async ({
320
320
 
321
321
  logServerAddresses(port);
322
322
 
323
- return port;
323
+ return { port, close: () => app.close() };
324
324
  } catch (error) {
325
325
  if (error.code === "EADDRINUSE") {
326
326
  console.log("server not started on port: ", port);
package/src/web.js CHANGED
@@ -4,7 +4,7 @@ const { runServer } = require("./server");
4
4
  const getRootDir = () => process.env.PWD || process.env.INIT_CWD;
5
5
 
6
6
  const runWeb = async ({ rootDir = getRootDir() } = {}) => {
7
- const port = await runServer({ rootDir });
7
+ const { port } = await runServer({ rootDir });
8
8
 
9
9
  return open(`http://localhost:${port}/?port=${port}`);
10
10
  };