2021-05-25 19:29:44 +00:00
|
|
|
const railsdk = require("./wegame_sdk/railsdk.js");
|
2021-08-04 11:46:05 +00:00
|
|
|
const { dialog, app, remote, ipcMain } = require("electron");
|
2021-05-25 19:29:44 +00:00
|
|
|
|
2021-05-25 11:09:33 +00:00
|
|
|
function init(isDev) {
|
2021-05-25 19:29:44 +00:00
|
|
|
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
|
|
|
|
) {
|
2021-08-04 11:45:40 +00:00
|
|
|
app.exit();
|
2021-05-25 19:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-05-25 11:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function listen() {
|
|
|
|
console.log("wegame: listen");
|
2021-08-04 11:44:02 +00:00
|
|
|
ipcMain.handle("profanity-check", async (event, data) => {
|
2021-08-04 12:15:33 +00:00
|
|
|
if (data.length === 0) {
|
|
|
|
return "";
|
|
|
|
}
|
2021-08-04 11:44:02 +00:00
|
|
|
const result = railsdk.RailUtils.DirtyWordsFilter(data, true);
|
|
|
|
if (result.check_result.dirty_type !== 0 /** kRailDirtyWordsTypeNormalAllowWords */) {
|
2021-08-04 12:15:33 +00:00
|
|
|
return result.check_result.replace_string;
|
2021-08-04 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
2021-05-25 11:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { init, listen };
|