mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Support for building wegame specific version
This commit is contained in:
parent
56214defaf
commit
291614cb3c
@ -274,7 +274,10 @@ 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.reply("fs-response", { id: arg.id, result });
|
||||
});
|
||||
|
||||
steam.init(isDev);
|
||||
steam.listen();
|
||||
|
1
electron_wegame/.gitignore
vendored
Normal file
1
electron_wegame/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
wegame_sdk
|
@ -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();
|
||||
|
@ -1,5 +1,48 @@
|
||||
const railsdk = require("./wegame_sdk/railsdk.js");
|
||||
const { dialog } = require("electron");
|
||||
|
||||
function init(isDev) {
|
||||
console.log("wegame: init");
|
||||
console.log("Step 1: wegame: init");
|
||||
|
||||
try {
|
||||
console.log("Step 2: Calling need restart app");
|
||||
const need_restart = railsdk.RailNeedRestartAppForCheckingEnvironment(
|
||||
2001639,
|
||||
[`--rail_render_pid=${process.pid}`] //,"--rail_debug_mode",
|
||||
);
|
||||
console.log("Step 3: Needs restart =", need_restart);
|
||||
if (need_restart) {
|
||||
console.error("Step 4: Need restart");
|
||||
dialog.showErrorBox("加载RailSDK失败", "请先运行WeGame开发者版本");
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Rail SDK error:", err);
|
||||
dialog.showErrorBox("加载RailSDK失败", err);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Step 5: starting rail sdk");
|
||||
if (railsdk.RailInitialize() === false) {
|
||||
console.error("RailInitialize() = false");
|
||||
dialog.showErrorBox("RailInitialize调用失败", "请先运行WeGame开发者版本");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Initialize RailSDK success!");
|
||||
|
||||
railsdk.RailRegisterEvent(railsdk.RailEventID.kRailEventSystemStateChanged, event => {
|
||||
console.log(event);
|
||||
if (event.result === railsdk.RailResult.kSuccess) {
|
||||
if (
|
||||
event.state === railsdk.RailSystemState.kSystemStatePlatformOffline ||
|
||||
event.state === railsdk.RailSystemState.kSystemStatePlatformExit ||
|
||||
event.state === railsdk.RailSystemState.kSystemStateGameExitByAntiAddiction
|
||||
) {
|
||||
remote.app.exit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function listen() {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -247,7 +247,7 @@ function gulptasksJS($, gulp, buildFolder, browserSync) {
|
||||
requireUncached("./webpack.production.config.js")({
|
||||
enableAssert: false,
|
||||
environment: "prod",
|
||||
es6: true,
|
||||
es6: false,
|
||||
standalone: true,
|
||||
wegameVersion: true,
|
||||
})
|
||||
|
@ -44,6 +44,8 @@ function gulptasksStandalone($, gulp) {
|
||||
const requiredFiles = [
|
||||
path.join(electronBaseDir, "node_modules", "**", "*.*"),
|
||||
path.join(electronBaseDir, "node_modules", "**", ".*"),
|
||||
path.join(electronBaseDir, "wegame_sdk", "**", "*.*"),
|
||||
path.join(electronBaseDir, "wegame_sdk", "**", ".*"),
|
||||
path.join(electronBaseDir, "favicon*"),
|
||||
|
||||
// fails on platforms which support symlinks
|
||||
@ -133,11 +135,10 @@ function gulptasksStandalone($, gulp) {
|
||||
const tomlFile = fs.readFileSync(path.join(__dirname, ".itch.toml"));
|
||||
const privateArtifactsPath = "node_modules/shapez.io-private-artifacts";
|
||||
|
||||
let asar;
|
||||
let asar = steam;
|
||||
if (steam && fs.existsSync(path.join(tempDestBuildDir, privateArtifactsPath))) {
|
||||
// @ts-expect-error
|
||||
asar = { unpackDir: privateArtifactsPath };
|
||||
} else {
|
||||
asar = true;
|
||||
}
|
||||
|
||||
packager({
|
||||
|
@ -2,16 +2,16 @@
|
||||
{
|
||||
"appid" "1318690"
|
||||
"desc" "$DESC$"
|
||||
"buildoutput" "C:\work\shapez.io\gulp\steampipe\steamtemp"
|
||||
"buildoutput" "C:\work\shapez\shapez.io\gulp\steampipe\steamtemp"
|
||||
"contentroot" ""
|
||||
"setlive" ""
|
||||
"preview" "0"
|
||||
"local" ""
|
||||
"depots"
|
||||
{
|
||||
"1318691" "C:\work\shapez.io\gulp\steampipe\scripts\windows.vdf"
|
||||
"1318694" "C:\work\shapez.io\gulp\steampipe\scripts\china-windows.vdf"
|
||||
"1318692" "C:\work\shapez.io\gulp\steampipe\scripts\linux.vdf"
|
||||
"1318695" "C:\work\shapez.io\gulp\steampipe\scripts\china-linux.vdf"
|
||||
"1318691" "C:\work\shapez\shapez.io\gulp\steampipe\scripts\windows.vdf"
|
||||
"1318694" "C:\work\shapez\shapez.io\gulp\steampipe\scripts\china-windows.vdf"
|
||||
"1318692" "C:\work\shapez\shapez.io\gulp\steampipe\scripts\linux.vdf"
|
||||
"1318695" "C:\work\shapez\shapez.io\gulp\steampipe\scripts\china-linux.vdf"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
"DepotBuildConfig"
|
||||
{
|
||||
"DepotID" "1318695"
|
||||
"contentroot" "C:\work\shapez.io\tmp_standalone_files_china\shapez.io-standalonechina-linux-x64"
|
||||
"contentroot" "C:\work\shapez\shapez.io\tmp_standalone_files_china\shapez.io-standalonechina-linux-x64"
|
||||
"FileMapping"
|
||||
{
|
||||
"LocalPath" "*"
|
||||
|
@ -1,7 +1,7 @@
|
||||
"DepotBuildConfig"
|
||||
{
|
||||
"DepotID" "1318694"
|
||||
"contentroot" "C:\work\shapez.io\tmp_standalone_files_china\shapez.io-standalonechina-win32-x64"
|
||||
"contentroot" "C:\work\shapez\shapez.io\tmp_standalone_files_china\shapez.io-standalonechina-win32-x64"
|
||||
"FileMapping"
|
||||
{
|
||||
"LocalPath" "*"
|
||||
|
@ -1,7 +1,7 @@
|
||||
"DepotBuildConfig"
|
||||
{
|
||||
"DepotID" "1318692"
|
||||
"contentroot" "C:\work\shapez.io\tmp_standalone_files\shapez.io-standalone-linux-x64"
|
||||
"contentroot" "C:\work\shapez\shapez.io\tmp_standalone_files\shapez.io-standalone-linux-x64"
|
||||
"FileMapping"
|
||||
{
|
||||
"LocalPath" "*"
|
||||
|
@ -1,7 +1,7 @@
|
||||
"DepotBuildConfig"
|
||||
{
|
||||
"DepotID" "1318691"
|
||||
"contentroot" "C:\work\shapez.io\tmp_standalone_files\shapez.io-standalone-win32-x64"
|
||||
"contentroot" "C:\work\shapez\shapez.io\tmp_standalone_files\shapez.io-standalone-win32-x64"
|
||||
"FileMapping"
|
||||
{
|
||||
"LocalPath" "*"
|
||||
|
@ -105,6 +105,10 @@ export class SteamAchievementProvider extends AchievementProviderInterface {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (G_WEGAME_VERSION) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this.ipc = getIPCRenderer();
|
||||
|
||||
return this.ipc.invoke("steam:is-initialized").then(initialized => {
|
||||
@ -125,6 +129,10 @@ export class SteamAchievementProvider extends AchievementProviderInterface {
|
||||
activate(key) {
|
||||
let promise;
|
||||
|
||||
if (G_WEGAME_VERSION) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (!this.initialized) {
|
||||
promise = Promise.resolve();
|
||||
} else {
|
||||
|
@ -7,6 +7,24 @@ const logger = createLogger("electron-storage");
|
||||
export class StorageImplElectron extends StorageInterface {
|
||||
constructor(app) {
|
||||
super(app);
|
||||
|
||||
/** @type {Object.<number, {resolve:Function, reject: Function}>} */
|
||||
this.jobs = {};
|
||||
this.jobId = 0;
|
||||
|
||||
getIPCRenderer().on("fs-response", (event, arg) => {
|
||||
const id = arg.id;
|
||||
if (!this.jobs[id]) {
|
||||
logger.warn("Got unhandled FS response, job not known:", id);
|
||||
return;
|
||||
}
|
||||
const { resolve, reject } = this.jobs[id];
|
||||
if (arg.result.success) {
|
||||
resolve(arg.result.data);
|
||||
} else {
|
||||
reject(arg.result.error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initialize() {
|
||||
@ -15,53 +33,43 @@ export class StorageImplElectron extends StorageInterface {
|
||||
|
||||
writeFileAsync(filename, contents) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getIPCRenderer()
|
||||
.invoke("fs-job", {
|
||||
type: "write",
|
||||
filename,
|
||||
contents,
|
||||
})
|
||||
.then(result => {
|
||||
if (result.success) {
|
||||
resolve(result.data);
|
||||
} else {
|
||||
reject(result.error);
|
||||
}
|
||||
});
|
||||
// ipcMain
|
||||
const jobId = ++this.jobId;
|
||||
this.jobs[jobId] = { resolve, reject };
|
||||
|
||||
getIPCRenderer().send("fs-job", {
|
||||
type: "write",
|
||||
filename,
|
||||
contents,
|
||||
id: jobId,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
readFileAsync(filename) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getIPCRenderer()
|
||||
.invoke("fs-job", {
|
||||
type: "read",
|
||||
filename,
|
||||
})
|
||||
.then(result => {
|
||||
if (result.success) {
|
||||
resolve(result.data);
|
||||
} else {
|
||||
reject(result.error);
|
||||
}
|
||||
});
|
||||
// ipcMain
|
||||
const jobId = ++this.jobId;
|
||||
this.jobs[jobId] = { resolve, reject };
|
||||
|
||||
getIPCRenderer().send("fs-job", {
|
||||
type: "read",
|
||||
filename,
|
||||
id: jobId,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
deleteFileAsync(filename) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getIPCRenderer()
|
||||
.invoke("fs-job", {
|
||||
type: "delete",
|
||||
filename,
|
||||
})
|
||||
.then(result => {
|
||||
if (result.success) {
|
||||
resolve(result.data);
|
||||
} else {
|
||||
reject(result.error);
|
||||
}
|
||||
});
|
||||
// ipcMain
|
||||
const jobId = ++this.jobId;
|
||||
this.jobs[jobId] = { resolve, reject };
|
||||
getIPCRenderer().send("fs-job", {
|
||||
type: "delete",
|
||||
filename,
|
||||
id: jobId,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,10 @@ export class PlatformWrapperImplElectron extends PlatformWrapperImplBrowser {
|
||||
initializeDlcStatus() {
|
||||
const renderer = getIPCRenderer();
|
||||
|
||||
if (G_WEGAME_VERSION) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
logger.log("Checking DLC ownership ...");
|
||||
// @todo: Don't hardcode the app id
|
||||
return renderer.invoke("steam:check-app-ownership", 1625400).then(
|
||||
|
@ -87,7 +87,7 @@ export class MainMenuState extends GameState {
|
||||
|
||||
<div class="mainContainer">
|
||||
${
|
||||
isSupportedBrowser()
|
||||
G_IS_STANDALONE || isSupportedBrowser()
|
||||
? ""
|
||||
: `<div class="browserWarning">${T.mainMenu.browserWarning}</div>`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user