mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-10-07 20:13:04 +00:00
Support for building wegame specific version
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/* eslint-disable quotes,no-undef */
|
||||
|
||||
const { app, BrowserWindow, Menu, MenuItem, ipcMain, shell } = require("electron");
|
||||
|
||||
app.commandLine.appendSwitch("in-process-gpu");
|
||||
|
||||
const path = require("path");
|
||||
const url = require("url");
|
||||
const fs = require("fs");
|
||||
@@ -49,7 +52,7 @@ function createWindow() {
|
||||
nodeIntegration: true,
|
||||
webSecurity: false,
|
||||
},
|
||||
allowRunningInsecureContent: false,
|
||||
// allowRunningInsecureContent: false,
|
||||
});
|
||||
|
||||
if (isLocal) {
|
||||
@@ -63,7 +66,7 @@ function createWindow() {
|
||||
})
|
||||
);
|
||||
}
|
||||
win.webContents.session.clearCache();
|
||||
win.webContents.session.clearCache(() => null);
|
||||
win.webContents.session.clearStorageData();
|
||||
|
||||
win.webContents.on("new-window", (event, pth) => {
|
||||
@@ -81,7 +84,7 @@ function createWindow() {
|
||||
|
||||
const mainItem = new MenuItem({
|
||||
label: "Toggle Dev Tools",
|
||||
click: () => win.toggleDevTools(),
|
||||
click: () => win.webContents.toggleDevTools(),
|
||||
accelerator: "F12",
|
||||
});
|
||||
menu.append(mainItem);
|
||||
@@ -161,20 +164,20 @@ async function writeFileSafe(filename, contents) {
|
||||
console.warn(prefix, "Concurrent write process on", filename);
|
||||
}
|
||||
|
||||
fileLock.acquire(filename, async () => {
|
||||
await fileLock.acquire(filename, async () => {
|
||||
console.log(prefix, "Starting write on", niceFileName(filename), "in transaction", transactionId);
|
||||
|
||||
if (!fs.existsSync(filename)) {
|
||||
// this one is easy
|
||||
console.log(prefix, "Writing file instantly because it does not exist:", niceFileName(filename));
|
||||
await fs.promises.writeFile(filename, contents, { encoding: "utf8" });
|
||||
fs.writeFileSync(filename, contents, { encoding: "utf8" });
|
||||
return;
|
||||
}
|
||||
|
||||
// first, write a temporary file (.tmp-XXX)
|
||||
const tempName = filename + ".tmp-" + transactionId;
|
||||
console.log(prefix, "Writing temporary file", niceFileName(tempName));
|
||||
await fs.promises.writeFile(tempName, contents, { encoding: "utf8" });
|
||||
fs.writeFileSync(tempName, contents, { encoding: "utf8" });
|
||||
|
||||
// now, rename the original file to (.backup-XXX)
|
||||
const oldTemporaryName = filename + ".backup-" + transactionId;
|
||||
@@ -185,7 +188,7 @@ async function writeFileSafe(filename, contents) {
|
||||
"to",
|
||||
niceFileName(oldTemporaryName)
|
||||
);
|
||||
await fs.promises.rename(filename, oldTemporaryName);
|
||||
fs.renameSync(filename, oldTemporaryName);
|
||||
|
||||
// now, rename the temporary file (.tmp-XXX) to the target
|
||||
console.log(
|
||||
@@ -195,7 +198,7 @@ async function writeFileSafe(filename, contents) {
|
||||
"to the original",
|
||||
niceFileName(filename)
|
||||
);
|
||||
await fs.promises.rename(tempName, filename);
|
||||
fs.renameSync(tempName, filename);
|
||||
|
||||
// we are done now, try to create a backup, but don't fail if the backup fails
|
||||
try {
|
||||
@@ -204,12 +207,12 @@ async function writeFileSafe(filename, contents) {
|
||||
if (fs.existsSync(backupFileName)) {
|
||||
console.log(prefix, "Deleting old backup file", niceFileName(backupFileName));
|
||||
// delete the old backup
|
||||
await fs.promises.unlink(backupFileName);
|
||||
fs.unlinkSync(backupFileName);
|
||||
}
|
||||
|
||||
// rename the old file to the new backup file
|
||||
console.log(prefix, "Moving", niceFileName(oldTemporaryName), "to the backup file location");
|
||||
await fs.promises.rename(oldTemporaryName, backupFileName);
|
||||
fs.renameSync(oldTemporaryName, backupFileName);
|
||||
} catch (ex) {
|
||||
console.error(prefix, "Failed to switch backup files:", ex);
|
||||
}
|
||||
@@ -229,12 +232,13 @@ async function performFsJob(job) {
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await fs.promises.readFile(fname, { encoding: "utf8" });
|
||||
const data = fs.readFileSync(fname, { encoding: "utf8" });
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
};
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
return {
|
||||
error: ex,
|
||||
};
|
||||
@@ -242,12 +246,13 @@ async function performFsJob(job) {
|
||||
}
|
||||
case "write": {
|
||||
try {
|
||||
await writeFileSafe(fname, job.contents);
|
||||
writeFileSafe(fname, job.contents);
|
||||
return {
|
||||
success: true,
|
||||
data: job.contents,
|
||||
};
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
return {
|
||||
error: ex,
|
||||
};
|
||||
@@ -256,8 +261,9 @@ async function performFsJob(job) {
|
||||
|
||||
case "delete": {
|
||||
try {
|
||||
await fs.promises.unlink(fname);
|
||||
fs.unlinkSync(fname);
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
return {
|
||||
error: ex,
|
||||
};
|
||||
@@ -274,7 +280,9 @@ async function performFsJob(job) {
|
||||
}
|
||||
}
|
||||
|
||||
ipcMain.handle("fs-job", (event, arg) => performFsJob(arg));
|
||||
|
||||
ipcMain.on("fs-job", async (event, arg) => {
|
||||
const result = await performFsJob(arg);
|
||||
event.sender.send("fs-response", { id: arg.id, result });
|
||||
});
|
||||
wegame.init(isDev);
|
||||
wegame.listen();
|
||||
|
||||
Reference in New Issue
Block a user