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) => {}); +}