mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 10:41:52 +00:00
Merge pull request #41 from tobspr-games/dengr1065/electron-updates
Update the Electron wrapper
This commit is contained in:
commit
6ff5cc26d2
@ -10,27 +10,17 @@ const windowStateKeeper = require("electron-window-state");
|
|||||||
app.commandLine.appendSwitch("disable-features", "HardwareMediaKeyHandling");
|
app.commandLine.appendSwitch("disable-features", "HardwareMediaKeyHandling");
|
||||||
|
|
||||||
const isDev = app.commandLine.hasSwitch("dev");
|
const isDev = app.commandLine.hasSwitch("dev");
|
||||||
const isLocal = app.commandLine.hasSwitch("local");
|
|
||||||
const safeMode = app.commandLine.hasSwitch("safe-mode");
|
const safeMode = app.commandLine.hasSwitch("safe-mode");
|
||||||
const externalMod = app.commandLine.getSwitchValue("load-mod");
|
const externalMod = app.commandLine.getSwitchValue("load-mod");
|
||||||
|
|
||||||
const roamingFolder =
|
app.setName("shapez-ce");
|
||||||
process.env.APPDATA ||
|
const userData = app.getPath("userData");
|
||||||
(process.platform == "darwin"
|
|
||||||
? process.env.HOME + "/Library/Preferences"
|
|
||||||
: process.env.HOME + "/.local/share");
|
|
||||||
|
|
||||||
let storePath = path.join(roamingFolder, "shapez.io", "saves");
|
const storePath = path.join(userData, "saves");
|
||||||
let modsPath = path.join(roamingFolder, "shapez.io", "mods");
|
const modsPath = path.join(userData, "mods");
|
||||||
|
|
||||||
if (!fs.existsSync(storePath)) {
|
fs.mkdirSync(storePath, { recursive: true });
|
||||||
// No try-catch by design
|
fs.mkdirSync(modsPath, { recursive: true });
|
||||||
fs.mkdirSync(storePath, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync(modsPath)) {
|
|
||||||
fs.mkdirSync(modsPath, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {BrowserWindow} */
|
/** @type {BrowserWindow} */
|
||||||
let win = null;
|
let win = null;
|
||||||
@ -63,24 +53,14 @@ function createWindow() {
|
|||||||
// fullscreen: true,
|
// fullscreen: true,
|
||||||
autoHideMenuBar: !isDev,
|
autoHideMenuBar: !isDev,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: false,
|
|
||||||
nodeIntegrationInWorker: false,
|
|
||||||
nodeIntegrationInSubFrames: false,
|
|
||||||
contextIsolation: true,
|
|
||||||
enableRemoteModule: false,
|
|
||||||
disableBlinkFeatures: "Auxclick",
|
disableBlinkFeatures: "Auxclick",
|
||||||
|
|
||||||
webSecurity: true,
|
|
||||||
sandbox: true,
|
|
||||||
preload: path.join(__dirname, "preload.js"),
|
preload: path.join(__dirname, "preload.js"),
|
||||||
experimentalFeatures: false,
|
|
||||||
},
|
},
|
||||||
allowRunningInsecureContent: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindowState.manage(win);
|
mainWindowState.manage(win);
|
||||||
|
|
||||||
if (isLocal) {
|
if (!app.isPackaged) {
|
||||||
win.loadURL("http://localhost:3005");
|
win.loadURL("http://localhost:3005");
|
||||||
} else {
|
} else {
|
||||||
win.loadURL(
|
win.loadURL(
|
||||||
@ -123,30 +103,6 @@ function createWindow() {
|
|||||||
contentsEvent.preventDefault();
|
contentsEvent.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Filter loading any module via remote;
|
|
||||||
// you shouldn't be using remote at all, though
|
|
||||||
// https://electronjs.org/docs/tutorial/security#16-filter-the-remote-module
|
|
||||||
app.on("remote-require", (event, webContents, moduleName) => {
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
// built-ins are modules such as "app"
|
|
||||||
app.on("remote-get-builtin", (event, webContents, moduleName) => {
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on("remote-get-global", (event, webContents, globalName) => {
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on("remote-get-current-window", (event, webContents) => {
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on("remote-get-current-web-contents", (event, webContents) => {
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
//// END SECURITY
|
//// END SECURITY
|
||||||
|
|
||||||
win.webContents.on("will-navigate", (event, pth) => {
|
win.webContents.on("will-navigate", (event, pth) => {
|
||||||
@ -313,7 +269,7 @@ async function writeFileSafe(filename, contents) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.handle("fs-job", async (event, job) => {
|
ipcMain.handle("fs-job", async (event, job) => {
|
||||||
const filenameSafe = job.filename.replace(/[^a-z\.\-_0-9]/gi, "_");
|
const filenameSafe = job.filename.replace(/[^a-z.\-_0-9]/gi, "_");
|
||||||
const fname = path.join(storePath, filenameSafe);
|
const fname = path.join(storePath, filenameSafe);
|
||||||
switch (job.type) {
|
switch (job.type) {
|
||||||
case "read": {
|
case "read": {
|
||||||
|
|||||||
@ -5,15 +5,15 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"startDev": "electron --disable-direct-composition --in-process-gpu . --dev --local",
|
"start": "electron .",
|
||||||
"startDevGpu": "electron --enable-gpu-rasterization --enable-accelerated-2d-canvas --num-raster-threads=8 --enable-zero-copy . --dev --local",
|
"startDev": "electron . --dev"
|
||||||
"start": "electron --disable-direct-composition --in-process-gpu ."
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"electron": "^31.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
|
||||||
"optionalDependencies": {},
|
"optionalDependencies": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async-lock": "^1.4.1",
|
"async-lock": "^1.4.1",
|
||||||
"electron": "^30.0.0",
|
|
||||||
"electron-window-state": "^5.0.3"
|
"electron-window-state": "^5.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -162,10 +162,10 @@ electron-window-state@^5.0.3:
|
|||||||
jsonfile "^4.0.0"
|
jsonfile "^4.0.0"
|
||||||
mkdirp "^0.5.1"
|
mkdirp "^0.5.1"
|
||||||
|
|
||||||
electron@^30.0.0:
|
electron@^31.3.0:
|
||||||
version "30.0.1"
|
version "31.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/electron/-/electron-30.0.1.tgz#2caf0eb7ed591b9b9842b522421bcae3aa8293d6"
|
resolved "https://registry.yarnpkg.com/electron/-/electron-31.3.0.tgz#4a084a8229d5bd829c33b8b65073381d0e925093"
|
||||||
integrity sha512-iwxkI/n2wBd29NH7TH0ZY8aWGzCoKpzJz+D10u7aGSJi1TV6d4MSM3rWyKvT/UkAHkTKOEgYfUyCa2vWQm8L0g==
|
integrity sha512-3LMRMmK4UK0A+jYSLGLYdfhc20TgY2v5jD3iGmhRZlDYj0gn7xBj/waRjlNalysZ0D2rgPvoes0wHuf5e/Bguw==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@electron/get" "^2.0.0"
|
"@electron/get" "^2.0.0"
|
||||||
"@types/node" "^20.9.0"
|
"@types/node" "^20.9.0"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user