fix: 移除编辑器/浏览器预览
This commit is contained in:
@@ -72,7 +72,7 @@ export default class GameManager extends cc.Component {
|
||||
// });
|
||||
this.startTimeCutDown();
|
||||
cc.fx.GameConfig.init(true);
|
||||
ClientUpdate.initialize(cc.fx.GameConfig.CLIENT_UPDATE_PREVIEW);
|
||||
ClientUpdate.initialize();
|
||||
cc.fx.GameConfig.GM_INFO.sceneValue = "loadScene";
|
||||
cc.fx.GameConfig.GM_INFO.gameState = false;
|
||||
//@ts-ignore
|
||||
|
||||
@@ -8,12 +8,11 @@ export default class ClientUpdate {
|
||||
private static rejection: any = null;
|
||||
private static dialogOpen = false;
|
||||
private static waitTimer: any = null;
|
||||
private static previewPanel: HTMLElement = null;
|
||||
|
||||
static get blocked(): boolean { return this.rejection !== null; }
|
||||
static get blockedResponse(): any { return this.rejection; }
|
||||
|
||||
static initialize(simulateInPreview = false): void {
|
||||
static initialize(): void {
|
||||
if (this.initialized) return;
|
||||
this.initialized = true;
|
||||
if (typeof wx !== "undefined" && typeof wx.getUpdateManager === "function") {
|
||||
@@ -36,10 +35,6 @@ export default class ClientUpdate {
|
||||
} else {
|
||||
this.state = "unavailable";
|
||||
}
|
||||
// Local UI simulation only. Never changes the reported version or bypasses the server gate.
|
||||
if (typeof CC_PREVIEW !== "undefined" && CC_PREVIEW && simulateInPreview) {
|
||||
this.handleResponse({ code: 0, errorCode: "CLIENT_UPDATE_REQUIRED", msg: "强更流程预览", data: null });
|
||||
}
|
||||
}
|
||||
|
||||
/** Also converts late successful responses to the same error after another request blocks us. */
|
||||
@@ -76,7 +71,6 @@ export default class ClientUpdate {
|
||||
|
||||
private static showPrompt(): void {
|
||||
if (typeof wx === "undefined" || typeof wx.showModal !== "function") {
|
||||
this.showPreviewPanel();
|
||||
return;
|
||||
}
|
||||
if (this.state === "checking" || this.state === "downloading") {
|
||||
@@ -101,7 +95,7 @@ export default class ClientUpdate {
|
||||
this.dialogOpen = true;
|
||||
wx.showModal({
|
||||
title: "游戏需要更新",
|
||||
content: ready ? "新版本已准备好,请重启更新。更新后将自动登录。"
|
||||
content: ready ? "新版本已准备好,请重启更新。"
|
||||
: "当前版本已无法继续游戏,暂未取得可用的新版本。请退出后重新进入;仍有问题请稍后再试。",
|
||||
showCancel: false,
|
||||
confirmText: ready ? "重启更新" : "退出游戏",
|
||||
@@ -111,9 +105,11 @@ export default class ClientUpdate {
|
||||
try { this.manager.applyUpdate(); }
|
||||
catch (_) { this.state = "unavailable"; }
|
||||
} else if (typeof wx.exitMiniProgram === "function") {
|
||||
wx.exitMiniProgram({ fail: () => {
|
||||
wx.showToast({ title: "请手动退出后重新进入", icon: "none", duration: 3000 });
|
||||
} });
|
||||
wx.exitMiniProgram({
|
||||
fail: () => {
|
||||
wx.showToast({ title: "请手动退出后重新进入", icon: "none", duration: 3000 });
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
complete: () => {
|
||||
@@ -128,22 +124,4 @@ export default class ClientUpdate {
|
||||
});
|
||||
}
|
||||
|
||||
private static showPreviewPanel(): void {
|
||||
if (this.previewPanel || typeof document === "undefined" || !document.body) return;
|
||||
const panel = document.createElement("div");
|
||||
panel.style.cssText = "position:fixed;inset:0;z-index:2147483647;background:#182036;color:#fff;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:24px;font:18px sans-serif";
|
||||
const title = document.createElement("h2");
|
||||
title.textContent = "游戏需要更新";
|
||||
const message = document.createElement("p");
|
||||
message.textContent = "请加载兼容的新版本后刷新页面。更新后将自动登录。";
|
||||
const button = document.createElement("button");
|
||||
button.textContent = "刷新页面";
|
||||
button.style.cssText = "padding:12px 28px;margin-top:20px;font:18px sans-serif;cursor:pointer";
|
||||
button.onclick = () => window.location.reload();
|
||||
panel.appendChild(title);
|
||||
panel.appendChild(message);
|
||||
panel.appendChild(button);
|
||||
document.body.appendChild(panel);
|
||||
this.previewPanel = panel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,6 @@ interface GameplayEntryPreparation {
|
||||
const { ccclass, property } = cc._decorator;
|
||||
@ccclass('GameConfig')
|
||||
export class GameConfig {
|
||||
// Cocos browser preview only: show the update gate without changing server policy/version reporting.
|
||||
static CLIENT_UPDATE_PREVIEW = false;
|
||||
//所有控制信息都通过GameAppStart内控制
|
||||
private static _instance: GameConfig = null;
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ const transpile = source => ts.transpileModule(source, { compilerOptions: {
|
||||
} }).outputText;
|
||||
const required = () => ({ code: 0, errorCode: 'CLIENT_UPDATE_REQUIRED', msg: '需要更新', data: { version: '1.0.84', minVersion: '1.0.83' } });
|
||||
|
||||
function fixture({ native = true, managerAvailable = true, preview = false } = {}) {
|
||||
const events = {}, requests = [], dialogs = [], timers = new Map(), elements = [];
|
||||
const state = { initialized: 0, applied: 0, exits: 0, paused: 0, resumed: 0, inputPaused: 0, audioPaused: 0, loading: [], reloaded: 0 };
|
||||
function fixture({ managerAvailable = true } = {}) {
|
||||
const events = {}, requests = [], dialogs = [], timers = new Map();
|
||||
const state = { initialized: 0, applied: 0, exits: 0, paused: 0, resumed: 0, inputPaused: 0, audioPaused: 0, loading: [] };
|
||||
let id = 0;
|
||||
const manager = {
|
||||
onCheckForUpdate: cb => { events.check = cb; },
|
||||
@@ -44,19 +44,14 @@ function fixture({ native = true, managerAvailable = true, preview = false } = {
|
||||
}) },
|
||||
};
|
||||
const context = vm.createContext({
|
||||
cc, CC_PREVIEW: preview, console: { log() {}, error() {} }, exports: {},
|
||||
cc, wx, console: { log() {}, error() {} }, exports: {},
|
||||
setTimeout: (fn, ms) => { const key = ++id; timers.set(key, { fn, ms }); return key; },
|
||||
clearTimeout: key => timers.delete(key),
|
||||
window: { location: { reload: () => { state.reloaded++; } } },
|
||||
document: { body: { appendChild: element => elements.push(element) }, createElement: tag => ({
|
||||
tag, style: {}, children: [], appendChild(child) { this.children.push(child); },
|
||||
}) },
|
||||
});
|
||||
if (native) context.wx = wx;
|
||||
vm.runInContext(transpile(read('assets/Script/module/Config/ClientUpdate.ts')), context);
|
||||
const ClientUpdate = context.exports.default;
|
||||
context.exports = {};
|
||||
const sdk = { isWechat: () => native, isBytedance: () => false, API: { showToast() {} } };
|
||||
const sdk = { isWechat: () => true, isBytedance: () => false, API: { showToast() {} } };
|
||||
context.require = name => name.endsWith('/ClientUpdate') ? { default: ClientUpdate }
|
||||
: name.includes('MiniGameSdk') ? { MiniGameSdk: sdk } : {};
|
||||
// Existing Utils contains an unrelated U+200C method name beyond the request helpers.
|
||||
@@ -69,7 +64,7 @@ function fixture({ native = true, managerAvailable = true, preview = false } = {
|
||||
}
|
||||
};
|
||||
const answer = (dialog, confirm = true) => { dialog.success({ confirm }); dialog.complete(); };
|
||||
return { ClientUpdate, Utils, cc, wx, manager, events, requests, dialogs, state, timers, elements, context, runTimers, answer };
|
||||
return { ClientUpdate, Utils, cc, wx, manager, events, requests, dialogs, state, timers, context, runTimers, answer };
|
||||
}
|
||||
|
||||
test('all form/JSON/authenticated/public/external business requests report the configured version', () => {
|
||||
@@ -201,17 +196,6 @@ test('a failed applyUpdate remains blocked and offers exit instead of repeatedly
|
||||
assert.equal(f.state.resumed, 0);
|
||||
});
|
||||
|
||||
test('browser preview has a persistent refresh screen; the simulation switch cannot affect release builds', () => {
|
||||
const f = fixture({ native: false, preview: true });
|
||||
f.ClientUpdate.initialize(true);
|
||||
assert.equal(f.ClientUpdate.blocked, true); assert.equal(f.elements.length, 1);
|
||||
f.ClientUpdate.onShow(); assert.equal(f.elements.length, 1);
|
||||
const button = f.elements[0].children.find(child => child.tag === 'button');
|
||||
button.onclick(); assert.equal(f.state.reloaded, 1);
|
||||
const release = fixture(); release.ClientUpdate.initialize(true);
|
||||
assert.equal(release.ClientUpdate.blocked, false);
|
||||
});
|
||||
|
||||
test('login polling stops after upgrade, and a fresh process can log in normally', () => {
|
||||
const f = fixture(); let result;
|
||||
f.Utils.getUserInfo(value => { result = value; });
|
||||
|
||||
Reference in New Issue
Block a user