From 1aeac29f3829231830e39dda8036828f0ad5c71f Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:35:50 +1000 Subject: [PATCH] feat: add CI/CD information display in PreferencePanel and support for environment variables --- .gitea/workflows/workflow.yaml | 6 +++++ .gitignore | 3 +++ public/background.js | 29 ++++++++++++++++-------- src/components/PreferencePanel.vue | 36 ++++++++++++++++++++++++++++-- src/utils/cicdInfo.ts | 4 ++++ src/utils/index.ts | 3 ++- 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 src/utils/cicdInfo.ts diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index 7fb3e0b..555fa33 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -8,6 +8,9 @@ jobs: build-for-chrome: name: 构建 Chrome 扩展程序 runs-on: ubuntu-latest + env: + VITE_RUN_ID: ${{ gitea.run_id }} + VITE_HASH_ID: ${{ gitea.sha | slice(0, 7) }} steps: - uses: actions/checkout@v3 @@ -33,6 +36,9 @@ jobs: build-for-firefox: name: 构建 Firefox 附加组件 runs-on: ubuntu-latest + env: + VITE_RUN_ID: ${{ gitea.run_id }} + VITE_HASH_ID: ${{ gitea.sha | slice(0, 7) }} steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index a547bf3..ce0d618 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ dist-ssr *.njsproj *.sln *.sw? + +.env +.env.local \ No newline at end of file diff --git a/public/background.js b/public/background.js index c1e4463..4b009eb 100644 --- a/public/background.js +++ b/public/background.js @@ -1,6 +1,9 @@ console.log("aaaa") -browser.webRequest.onBeforeRequest.addListener( +// 兼容 Chrome 和 Firefox +const browserAPI = typeof browser !== 'undefined' ? browser : chrome; + +browserAPI.webRequest.onBeforeRequest.addListener( async (details) => { console.log( 'onBeforeRequest MAIN_FRAME:', @@ -11,27 +14,35 @@ browser.webRequest.onBeforeRequest.addListener( ) console.log('recived request for fontset api, redirecting to index.html') - const pref = await browser.storage.sync.get('preferences') + const pref = await browserAPI.storage.sync.get('preferences') if (pref === undefined || pref.preferences === undefined || pref.preferences.autoRedirect === undefined || pref.preferences.autoRedirect === true) { - const isChrome = typeof browser.runtime.getBrowserInfo === 'undefined'; + const isChrome = typeof browserAPI.runtime.getBrowserInfo === 'undefined'; if (isChrome) { - browser.tabs.create({ url: browser.runtime.getURL('index.html') }) - browser.tabs.remove(details.tabId) + if ( + details.url === 'https://monster-siren.hypergryph.com/manifest.json' && + details.type === 'other' && + details.frameId === 0 + ) { + const pref = await chrome.storage.sync.get('preferences') + + chrome.tabs.create({ url: chrome.runtime.getURL('index.html') }) + chrome.tabs.remove(details.tabId) + } } else { // Firefox: 直接在当前标签页导航 - browser.tabs.update(details.tabId, { url: browser.runtime.getURL('index.html') }) + browserAPI.tabs.update(details.tabId, { url: browserAPI.runtime.getURL('index.html') }) } } }, - { urls: ['https://monster-siren.hypergryph.com/api/fontset'] }, + { urls: ['https://monster-siren.hypergryph.com/api/fontset', 'https://monster-siren.hypergryph.com/manifest.json'] }, ) // 兼容新旧版本的 API -const actionAPI = browser.action || browser.browserAction; +const actionAPI = browserAPI.action || browserAPI.browserAction; if (actionAPI) { actionAPI.onClicked.addListener(() => { - browser.tabs.create({ url: browser.runtime.getURL('index.html') }) + browserAPI.tabs.create({ url: browserAPI.runtime.getURL('index.html') }) }) } \ No newline at end of file diff --git a/src/components/PreferencePanel.vue b/src/components/PreferencePanel.vue index 73238d2..ef58750 100644 --- a/src/components/PreferencePanel.vue +++ b/src/components/PreferencePanel.vue @@ -3,10 +3,10 @@ import XIcon from '../assets/icons/x.vue' import { usePreferences } from '../stores/usePreferences' import { computed } from 'vue' +import { cicdInfo } from '../utils' const preferences = usePreferences() - defineProps<{ present: boolean }>() @@ -103,7 +103,7 @@ const version = computed(() => { -
即使此项目关闭,随时都可以通过点按 MSR Mod 扩展图标启动 MSR Mod。
+
即使此项目关闭,随时都可以通过点按 MSR Mod 扩展图标启动 MSR Mod。
@@ -133,6 +133,38 @@ const version = computed(() => { + +
+
+
构建信息
+ +
MSR Mod 使用 Gitea Actions 完成打包与自动商店提交工作。此信息用于确认 MSR Mod 的 + CI/CD 构建版本信息,以及当前构建代码是否被篡改。
+
+
diff --git a/src/utils/cicdInfo.ts b/src/utils/cicdInfo.ts new file mode 100644 index 0000000..2d47548 --- /dev/null +++ b/src/utils/cicdInfo.ts @@ -0,0 +1,4 @@ +export default { + runId: import.meta.env.VITE_RUN_ID ?? '未知', + hashId: import.meta.env.VITE_HASH_ID ?? '未知', +} \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index 6b0c702..08ff66e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,5 @@ import artistsOrganize from "./artistsOrganize" import { audioVisualizer } from "./audioVisualizer" +import cicdInfo from "./cicdInfo" -export { artistsOrganize, audioVisualizer } +export { artistsOrganize, audioVisualizer, cicdInfo }