From 16f100cbd18bebb1a4311636ff5f9b4e88f46288 Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Tue, 27 May 2025 14:24:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=88=B7=E6=96=B0=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=E5=89=A5=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/inject-view/app.vue | 28 ++------------------------ src/scripts/inject/util.ts | 35 +++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/scripts/inject-view/app.vue b/src/scripts/inject-view/app.vue index 90c295e..2632b3b 100644 --- a/src/scripts/inject-view/app.vue +++ b/src/scripts/inject-view/app.vue @@ -31,6 +31,7 @@ import Memory from "./memory.vue"; import Shortkeys from "./shortkeys.vue"; import { appStore } from "./store"; import { sendGaEvent } from "./util"; +import { freshEditor } from "../inject/util"; declare const cc: any; const { CCDialog, CCMenu } = ccui.components; interface ListItem { @@ -363,32 +364,7 @@ export default defineComponent({ break; } case shortKeyGameFresh: { - let router = ""; - let isCreator2X = false; - if (typeof cc !== "undefined" && cc && typeof cc.ENGINE_VERSION !== "undefined") { - if (cc.ENGINE_VERSION.startsWith("3.")) { - isCreator2X = false; - router = "asset-db/refresh"; - } else { - isCreator2X = true; - router = "update-db"; - } - } - const url = new URL(window.location.href); - const port = Number(url.port) || 7456; - fetch(`http://localhost:${port}/${router}`) - .then((res) => { - res.text().then((a: string) => { - window.location.reload(); - if (isCreator2X === false && a === "success") { - // 3.x - } - if (isCreator2X === true && a === "Changes submitted") { - // 2.x - } - }); - }) - .then((data) => {}); + freshEditor(); break; } } diff --git a/src/scripts/inject/util.ts b/src/scripts/inject/util.ts index f78746b..d6bedac 100644 --- a/src/scripts/inject/util.ts +++ b/src/scripts/inject/util.ts @@ -1,23 +1,50 @@ declare const cc: any; export function isVersion3() { - if (typeof cc.ENGINE_VERSION === "string") { + if (typeof cc !== "undefined" && cc && typeof cc.ENGINE_VERSION === "string") { const version: string = cc.ENGINE_VERSION; - return version.startsWith("3.") + return version.startsWith("3."); } return false; } export function isHasProperty(base: Object, key: string): boolean { - let ret = Object.getOwnPropertyDescriptor(base, key) + let ret = Object.getOwnPropertyDescriptor(base, key); if (ret) { return true; } else { let proto = Object.getPrototypeOf(base); if (proto) { - return isHasProperty(proto, key) + return isHasProperty(proto, key); } else { return false; } } } + +export function freshEditor() { + let router = ""; + let isCreator2X = false; + if (isVersion3()) { + isCreator2X = false; + router = "asset-db/refresh"; + } else { + isCreator2X = true; + router = "update-db"; + } + const url = new URL(window.location.href); + const port = Number(url.port) || 7456; + fetch(`http://localhost:${port}/${router}`) + .then((res) => { + res.text().then((a: string) => { + window.location.reload(); + if (isCreator2X === false && a === "success") { + // 3.x + } + if (isCreator2X === true && a === "Changes submitted") { + // 2.x + } + }); + }) + .then((data) => {}); +}