Compare commits

...

4 Commits

Author SHA1 Message Date
Memory
195306f251
fix: deleted subscriptions reappearing
* chore: udpate download link

* fix: deleted subscriptions reappearing

---------

Co-authored-by: ezequielnick <107352853+ezequielnick@users.noreply.github.com>
2025-08-31 12:54:43 +08:00
ezequielnick
4946d73183 chore: update workflow to delete old assets 2025-08-31 12:33:41 +08:00
ezequielnick
e1c4a94e02 refactor: commit hash in dev version 2025-08-31 12:08:19 +08:00
ezequielnick
80c611aec8 Revert "feat: add commit hash in dev version"
This reverts commit c01c985c91f8446065e9eb89f600b133db60151b.
2025-08-31 10:34:09 +08:00
12 changed files with 245 additions and 147 deletions

View File

@ -27,18 +27,41 @@ jobs:
if [ ! -z "$RELEASE_ID" ] && [ "$RELEASE_ID" != "empty" ]; then
echo "✅ Found dev release with ID: $RELEASE_ID"
echo "📋 Getting list of assets with pagination..."
ALL_ASSETS="[]"
PAGE=1
PER_PAGE=100
# Get all assets
echo "📋 Getting list of assets..."
ASSETS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets")
while true; do
echo "📄 Fetching page $PAGE..."
ASSETS_PAGE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?page=$PAGE&per_page=$PER_PAGE")
PAGE_COUNT=$(echo "$ASSETS_PAGE" | jq '. | length')
echo "📦 Found $PAGE_COUNT assets on page $PAGE"
if [ "$PAGE_COUNT" -eq 0 ]; then
echo "📋 No more assets found, stopping pagination"
break
fi
ALL_ASSETS=$(echo "$ALL_ASSETS" "$ASSETS_PAGE" | jq -s '.[0] + .[1]')
if [ "$PAGE_COUNT" -lt "$PER_PAGE" ]; then
echo "📋 Last page reached (got $PAGE_COUNT < $PER_PAGE), stopping pagination"
break
fi
PAGE=$((PAGE + 1))
done
ASSET_COUNT=$(echo "$ASSETS" | jq '. | length')
echo "📦 Found $ASSET_COUNT assets to delete"
TOTAL_ASSET_COUNT=$(echo "$ALL_ASSETS" | jq '. | length')
echo "📦 Total assets found across all pages: $TOTAL_ASSET_COUNT"
if [ "$ASSET_COUNT" -gt 0 ]; then
if [ "$TOTAL_ASSET_COUNT" -gt 0 ]; then
# Delete each asset with detailed logging
echo "$ASSETS" | jq -r '.[].id' | while read asset_id; do
echo "$ALL_ASSETS" | jq -r '.[].id' | while read asset_id; do
if [ ! -z "$asset_id" ]; then
echo "🗑️ Deleting asset ID: $asset_id"
RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X DELETE \
@ -56,7 +79,7 @@ jobs:
sleep 0.5
fi
done
echo "🎉 Finished deleting assets"
echo "🎉 Finished deleting all $TOTAL_ASSET_COUNT assets"
else
echo " No assets found to delete"
fi
@ -89,7 +112,13 @@ jobs:
run: |
pnpm install
pnpm add @mihomo-party/sysproxy-win32-${{ matrix.arch }}-msvc
pnpm prepare --${{ matrix.arch }}
- name: Update Version for Dev Build
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_EVENT_NAME: workflow_dispatch
run: node scripts/update-version.mjs
- name: Prepare
run: pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
@ -159,7 +188,13 @@ jobs:
pnpm add @mihomo-party/sysproxy-win32-${{ matrix.arch }}-msvc
pnpm add -D electron@22.3.27
(Get-Content electron-builder.yml) -replace 'windows', 'win7' | Set-Content electron-builder.yml
pnpm prepare --${{ matrix.arch }}
- name: Update Version for Dev Build
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_EVENT_NAME: workflow_dispatch
run: node scripts/update-version.mjs
- name: Prepare
run: pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
@ -228,7 +263,13 @@ jobs:
pnpm install
pnpm add @mihomo-party/sysproxy-linux-${{ matrix.arch }}-gnu
sed -i "s/productName: Clash Party/productName: mihomo-party/" electron-builder.yml
pnpm prepare --${{ matrix.arch }}
- name: Update Version for Dev Build
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_EVENT_NAME: workflow_dispatch
run: node scripts/update-version.mjs
- name: Prepare
run: pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
@ -290,7 +331,13 @@ jobs:
run: |
pnpm install
pnpm add @mihomo-party/sysproxy-darwin-${{ matrix.arch }}
pnpm prepare --${{ matrix.arch }}
- name: Update Version for Dev Build
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_EVENT_NAME: workflow_dispatch
run: node scripts/update-version.mjs
- name: Prepare
run: pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
@ -376,7 +423,13 @@ jobs:
pnpm install
pnpm add @mihomo-party/sysproxy-darwin-${{ matrix.arch }}
pnpm add -D electron@32.2.2
pnpm prepare --${{ matrix.arch }}
- name: Update Version for Dev Build
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_EVENT_NAME: workflow_dispatch
run: node scripts/update-version.mjs
- name: Prepare
run: pnpm prepare --${{ matrix.arch }}
- name: Build
env:
npm_config_arch: ${{ matrix.arch }}
@ -451,6 +504,11 @@ jobs:
run: npm install -g pnpm
- name: Install Dependencies
run: pnpm install
- name: Update Version for Dev Build
if: github.event_name == 'workflow_dispatch'
env:
GITHUB_EVENT_NAME: workflow_dispatch
run: node scripts/update-version.mjs
- name: Telegram Notification
if: startsWith(github.ref, 'refs/tags/v')
env:

View File

@ -1,6 +1,6 @@
{
"name": "mihomo-party",
"version": "1.8.6-dev",
"version": "1.8.6",
"description": "Clash Party",
"main": "./out/main/index.js",
"author": "mihomo-party-org",
@ -12,6 +12,7 @@
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
"typecheck": "npm run typecheck:node && npm run typecheck:web",
"prepare": "node scripts/prepare.mjs",
"prepare:dev": "node scripts/update-version.mjs && node scripts/prepare.mjs",
"updater": "node scripts/updater.mjs",
"checksum": "node scripts/checksum.mjs",
"telegram": "node scripts/telegram.mjs release",
@ -19,15 +20,12 @@
"artifact": "node scripts/artifact.mjs",
"dev": "electron-vite dev",
"postinstall": "electron-builder install-app-deps",
"prebuild:win": "node scripts/version.js",
"prebuild:mac": "node scripts/version.js",
"prebuild:linux": "node scripts/version.js",
"postbuild:win": "node scripts/restore-version.js",
"postbuild:mac": "node scripts/restore-version.js",
"postbuild:linux": "node scripts/restore-version.js",
"build:win": "electron-vite build && electron-builder --publish never --win",
"build:win:dev": "npm run prepare:dev && electron-vite build && electron-builder --publish never --win",
"build:mac": "electron-vite build && electron-builder --publish never --mac",
"build:linux": "electron-vite build && electron-builder --publish never --linux"
"build:mac:dev": "npm run prepare:dev && electron-vite build && electron-builder --publish never --mac",
"build:linux": "electron-vite build && electron-builder --publish never --linux",
"build:linux:dev": "npm run prepare:dev && electron-vite build && electron-builder --publish never --linux"
},
"dependencies": {
"@electron-toolkit/preload": "^3.0.2",
@ -104,4 +102,4 @@
"vite-plugin-monaco-editor": "^1.1.0"
},
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
}
}

View File

@ -1,32 +0,0 @@
const fs = require('fs')
const path = require('path')
function restoreVersion() {
const backupPath = path.join(__dirname, '..', 'package.json.bak')
const packagePath = path.join(__dirname, '..', 'package.json')
if (fs.existsSync(backupPath)) {
try {
const backup = JSON.parse(fs.readFileSync(backupPath, 'utf8'))
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
// 恢复版本号
packageJson.version = backup.version
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2))
// 删除备份文件
fs.unlinkSync(backupPath)
console.log(`版本号已恢复: ${backup.version}`)
} catch (error) {
console.error('恢复版本号时出错:', error)
}
}
}
// 如果是直接运行此脚本,则执行版本恢复
if (require.main === module) {
restoreVersion()
}
module.exports = { restoreVersion }

View File

@ -1,13 +1,16 @@
import axios from 'axios'
import { readFileSync } from 'fs'
import { getProcessedVersion, isDevBuild, getDownloadUrl, generateDownloadLinksMarkdown, getGitCommitHash } from './version-utils.mjs'
const chat_id = '@MihomoPartyChannel'
const pkg = readFileSync('package.json', 'utf-8')
const changelog = readFileSync('changelog.md', 'utf-8')
const { version } = JSON.parse(pkg)
const { version: packageVersion } = JSON.parse(pkg)
// 获取处理后的版本号
const version = getProcessedVersion()
const releaseType = process.env.RELEASE_TYPE || process.argv[2] || 'release'
const isDevRelease = releaseType === 'dev'
const isDevRelease = releaseType === 'dev' || isDevBuild()
function convertMarkdownToTelegramHTML(content) {
return content
@ -42,50 +45,34 @@ function convertMarkdownToTelegramHTML(content) {
let content = '';
if (isDevRelease) {
const commitSha = process.env.GITHUB_SHA || 'unknown'
const shortCommitSha = commitSha.substring(0, 7)
// 版本号中提取commit hash
const shortCommitSha = getGitCommitHash(true)
const commitSha = getGitCommitHash(false)
content = `<b>🚧 <a href="https://github.com/mihomo-party-org/mihomo-party/releases/tag/dev">Clash Party Dev Build</a> 开发版本发布</b>\n\n`
content = `<b>🚧 <a href="https://github.com/mihomo-party-org/clash-party/releases/tag/dev">Clash Party Dev Build</a> 开发版本发布</b>\n\n`
content += `<b>基于版本:</b> ${version}\n`
content += `<b>提交哈希:</b> <a href="https://github.com/mihomo-party-org/mihomo-party/commit/${commitSha}">${shortCommitSha}</a>\n\n`
content += `<b>提交哈希:</b> <a href="https://github.com/mihomo-party-org/clash-party/commit/${commitSha}">${shortCommitSha}</a>\n\n`
content += `<b>更新日志:</b>\n`
content += convertMarkdownToTelegramHTML(changelog)
content += '\n\n<b>⚠️ 注意:这是开发版本,可能存在不稳定性,仅供测试使用</b>\n'
} else {
// 正式版本通知
content = `<b>🌟 <a href="https://github.com/mihomo-party-org/mihomo-party/releases/tag/v${version}">Clash Party v${version}</a> 正式发布</b>\n\n`
content = `<b>🌟 <a href="https://github.com/mihomo-party-org/clash-party/releases/tag/v${version}">Clash Party v${version}</a> 正式发布</b>\n\n`
content += convertMarkdownToTelegramHTML(changelog)
}
// 构建下载链接
const downloadUrl = isDevRelease
? `https://github.com/mihomo-party-org/mihomo-party/releases/download/dev`
: `https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}`
const downloadUrl = getDownloadUrl(isDevRelease, version)
content += '\n<b>下载地址:</b>\n<b>Windows10/11</b>\n'
content += `安装版:<a href="${downloadUrl}/mihomo-party-windows-${version}-x64-setup.exe">64位</a> | <a href="${downloadUrl}/mihomo-party-windows-${version}-ia32-setup.exe">32位</a> | <a href="${downloadUrl}/mihomo-party-windows-${version}-arm64-setup.exe">ARM64</a>\n`
content += `便携版:<a href="${downloadUrl}/mihomo-party-windows-${version}-x64-portable.7z">64位</a> | <a href="${downloadUrl}/mihomo-party-windows-${version}-ia32-portable.7z">32位</a> | <a href="${downloadUrl}/mihomo-party-windows-${version}-arm64-portable.7z">ARM64</a>\n`
content += '\n<b>Windows7/8</b>\n'
content += `安装版:<a href="${downloadUrl}/mihomo-party-win7-${version}-x64-setup.exe">64位</a> | <a href="${downloadUrl}/mihomo-party-win7-${version}-ia32-setup.exe">32位</a>\n`
content += `便携版:<a href="${downloadUrl}/mihomo-party-win7-${version}-x64-portable.7z">64位</a> | <a href="${downloadUrl}/mihomo-party-win7-${version}-ia32-portable.7z">32位</a>\n`
content += '\n<b>macOS 11+</b>\n'
content += `PKG<a href="${downloadUrl}/mihomo-party-macos-${version}-x64.pkg
">Intel</a> | <a href="${downloadUrl}/mihomo-party-macos-${version}-arm64.pkg">Apple Silicon</a>\n`
content += '\n<b>macOS 10.15+</b>\n'
content += `PKG<a href="${downloadUrl}/mihomo-party-catalina-${version}-x64.pkg
">Intel</a> | <a href="${downloadUrl}/mihomo-party-catalina-${version}-arm64.pkg">Apple Silicon</a>\n`
content += '\n<b>Linux</b>\n'
content += `DEB<a href="${downloadUrl}/mihomo-party-linux-${version}-amd64.deb
">64位</a> | <a href="${downloadUrl}/mihomo-party-linux-${version}-arm64.deb">ARM64</a>\n`
content += `RPM<a href="${downloadUrl}/mihomo-party-linux-${version}-x86_64.rpm">64位</a> | <a href="${downloadUrl}/mihomo-party-linux-${version}-aarch64.rpm">ARM64</a>`
const downloadLinksMarkdown = generateDownloadLinksMarkdown(downloadUrl, version)
content += convertMarkdownToTelegramHTML(downloadLinksMarkdown)
await axios.post(`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, {
chat_id,
text: content,
link_preview_options: {
is_disabled: false,
url: 'https://github.com/mihomo-party-org/mihomo-party',
url: 'https://github.com/mihomo-party-org/clash-party',
prefer_large_media: true
},
parse_mode: 'HTML'

View File

@ -0,0 +1,34 @@
import { readFileSync, writeFileSync } from 'fs'
import { getProcessedVersion, isDevBuild } from './version-utils.mjs'
// 更新package.json中的版本号
function updatePackageVersion() {
try {
const packagePath = 'package.json'
const packageContent = readFileSync(packagePath, 'utf-8')
const packageData = JSON.parse(packageContent)
// 获取处理后的版本号
const newVersion = getProcessedVersion()
console.log(`当前版本: ${packageData.version}`)
console.log(`${isDevBuild() ? 'Dev构建' : '正式构建'} - 新版本: ${newVersion}`)
packageData.version = newVersion
// 写回package.json
writeFileSync(packagePath, JSON.stringify(packageData, null, 2) + '\n')
console.log(`✅ package.json版本号已更新为: ${newVersion}`)
} catch (error) {
console.error('❌ 更新package.json版本号失败:', error.message)
process.exit(1)
}
}
if (import.meta.url === `file://${process.argv[1]}`) {
updatePackageVersion()
}
export { updatePackageVersion }

View File

@ -1,28 +1,23 @@
import yaml from 'yaml'
import { readFileSync, writeFileSync } from 'fs'
import { getProcessedVersion, isDevBuild, getDownloadUrl, generateDownloadLinksMarkdown } from './version-utils.mjs'
const pkg = readFileSync('package.json', 'utf-8')
let changelog = readFileSync('changelog.md', 'utf-8')
const { version } = JSON.parse(pkg)
const downloadUrl = `https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}`
const { version: packageVersion } = JSON.parse(pkg)
// 获取处理后的版本号
const version = getProcessedVersion()
const isDev = isDevBuild()
const downloadUrl = getDownloadUrl(isDev, version)
const latest = {
version,
changelog
}
changelog += '\n### 下载地址:\n\n#### Windows10/11\n\n'
changelog += `- 安装版:[64位](${downloadUrl}/mihomo-party-windows-${version}-x64-setup.exe) | [32位](${downloadUrl}/mihomo-party-windows-${version}-ia32-setup.exe) | [ARM64](${downloadUrl}/mihomo-party-windows-${version}-arm64-setup.exe)\n\n`
changelog += `- 便携版:[64位](${downloadUrl}/mihomo-party-windows-${version}-x64-portable.7z) | [32位](${downloadUrl}/mihomo-party-windows-${version}-ia32-portable.7z) | [ARM64](${downloadUrl}/mihomo-party-windows-${version}-arm64-portable.7z)\n\n`
changelog += '\n#### Windows7/8\n\n'
changelog += `- 安装版:[64位](${downloadUrl}/mihomo-party-win7-${version}-x64-setup.exe) | [32位](${downloadUrl}/mihomo-party-win7-${version}-ia32-setup.exe)\n\n`
changelog += `- 便携版:[64位](${downloadUrl}/mihomo-party-win7-${version}-x64-portable.7z) | [32位](${downloadUrl}/mihomo-party-win7-${version}-ia32-portable.7z)\n\n`
changelog += '\n#### macOS 11+\n\n'
changelog += `- PKG[Intel](${downloadUrl}/mihomo-party-macos-${version}-x64.pkg) | [Apple Silicon](${downloadUrl}/mihomo-party-macos-${version}-arm64.pkg)\n\n`
changelog += '\n#### macOS 10.15+\n\n'
changelog += `- PKG[Intel](${downloadUrl}/mihomo-party-catalina-${version}-x64.pkg) | [Apple Silicon](${downloadUrl}/mihomo-party-catalina-${version}-arm64.pkg)\n\n`
changelog += '\n#### Linux\n\n'
changelog += `- DEB[64位](${downloadUrl}/mihomo-party-linux-${version}-amd64.deb) | [ARM64](${downloadUrl}/mihomo-party-linux-${version}-arm64.deb)\n\n`
changelog += `- RPM[64位](${downloadUrl}/mihomo-party-linux-${version}-x86_64.rpm) | [ARM64](${downloadUrl}/mihomo-party-linux-${version}-aarch64.rpm)`
// 使用统一的下载链接生成函数
changelog += generateDownloadLinksMarkdown(downloadUrl, version)
changelog += '\n\n### 机场推荐:\n- 高性能海外机场,稳定首选:[https://狗狗加速.com](https://party.dginv.click/#/register?code=ARdo0mXx)'

86
scripts/version-utils.mjs Normal file
View File

@ -0,0 +1,86 @@
import { execSync } from 'child_process'
import { readFileSync } from 'fs'
// 获取Git commit hash
export function getGitCommitHash(short = true) {
try {
const command = short ? 'git rev-parse --short HEAD' : 'git rev-parse HEAD'
return execSync(command, { encoding: 'utf-8' }).trim()
} catch (error) {
console.warn('Failed to get git commit hash:', error.message)
return 'unknown'
}
}
// 获取当前月份日期
export function getCurrentMonthDate() {
const now = new Date()
const month = String(now.getMonth() + 1).padStart(2, '0')
const day = String(now.getDate()).padStart(2, '0')
return `${month}${day}`
}
// 从package.json读取基础版本号
export function getBaseVersion() {
try {
const pkg = readFileSync('package.json', 'utf-8')
const { version } = JSON.parse(pkg)
// 移除dev版本格式后缀
return version.replace('-dev', '').replace(/-\d{4}-[a-f0-9]{7}$/, '')
} catch (error) {
console.error('Failed to read package.json:', error.message)
return '1.0.0'
}
}
// 生成dev版本号
export function getDevVersion() {
const baseVersion = getBaseVersion()
const monthDate = getCurrentMonthDate()
const commitHash = getGitCommitHash(true)
return `${baseVersion}-${monthDate}-${commitHash}`
}
// 检查当前环境是否为dev构建
export function isDevBuild() {
return process.env.NODE_ENV === 'development' ||
process.argv.includes('--dev') ||
process.env.GITHUB_EVENT_NAME === 'workflow_dispatch'
}
// 获取处理后的版本号
export function getProcessedVersion() {
if (isDevBuild()) {
return getDevVersion()
} else {
return getBaseVersion()
}
}
// 生成下载URL
export function getDownloadUrl(isDev, version) {
if (isDev) {
return 'https://github.com/mihomo-party-org/clash-party/releases/download/dev'
} else {
return `https://github.com/mihomo-party-org/clash-party/releases/download/v${version}`
}
}
export function generateDownloadLinksMarkdown(downloadUrl, version) {
let links = '\n### 下载地址:\n\n#### Windows10/11\n\n'
links += `- 安装版:[64位](${downloadUrl}/clash-party-windows-${version}-x64-setup.exe) | [32位](${downloadUrl}/clash-party-windows-${version}-ia32-setup.exe) | [ARM64](${downloadUrl}/clash-party-windows-${version}-arm64-setup.exe)\n\n`
links += `- 便携版:[64位](${downloadUrl}/clash-party-windows-${version}-x64-portable.7z) | [32位](${downloadUrl}/clash-party-windows-${version}-ia32-portable.7z) | [ARM64](${downloadUrl}/clash-party-windows-${version}-arm64-portable.7z)\n\n`
links += '\n#### Windows7/8\n\n'
links += `- 安装版:[64位](${downloadUrl}/clash-party-win7-${version}-x64-setup.exe) | [32位](${downloadUrl}/clash-party-win7-${version}-ia32-setup.exe)\n\n`
links += `- 便携版:[64位](${downloadUrl}/clash-party-win7-${version}-x64-portable.7z) | [32位](${downloadUrl}/clash-party-win7-${version}-ia32-portable.7z)\n\n`
links += '\n#### macOS 11+\n\n'
links += `- PKG[Intel](${downloadUrl}/clash-party-macos-${version}-x64.pkg) | [Apple Silicon](${downloadUrl}/clash-party-macos-${version}-arm64.pkg)\n\n`
links += '\n#### macOS 10.15+\n\n'
links += `- PKG[Intel](${downloadUrl}/clash-party-catalina-${version}-x64.pkg) | [Apple Silicon](${downloadUrl}/clash-party-catalina-${version}-arm64.pkg)\n\n`
links += '\n#### Linux\n\n'
links += `- DEB[64位](${downloadUrl}/clash-party-linux-${version}-amd64.deb) | [ARM64](${downloadUrl}/clash-party-linux-${version}-arm64.deb)\n\n`
links += `- RPM[64位](${downloadUrl}/clash-party-linux-${version}-x86_64.rpm) | [ARM64](${downloadUrl}/clash-party-linux-${version}-aarch64.rpm)`
return links
}

View File

@ -1,47 +0,0 @@
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
function getGitCommitHash() {
try {
return execSync('git rev-parse --short=7 HEAD').toString().trim()
} catch (error) {
console.warn('无法获取 Git commit hash使用默认值')
return 'unknown'
}
}
function processVersion() {
const packagePath = path.join(__dirname, '..', 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
// 备份原始版本号
const originalVersion = packageJson.version
fs.writeFileSync(
path.join(__dirname, '..', 'package.json.bak'),
JSON.stringify({ version: originalVersion }, null, 2)
)
// 检查版本号是否以 -dev 结尾
if (originalVersion.endsWith('-dev')) {
const commitHash = getGitCommitHash()
const newVersion = originalVersion.replace('-dev', `-${commitHash}-dev`)
// 更新 package.json
packageJson.version = newVersion
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2))
console.log(`版本号已更新: ${originalVersion} -> ${newVersion}`)
return newVersion
}
console.log(`版本号未修改: ${originalVersion}`)
return originalVersion
}
// 如果是直接运行此脚本,则执行版本处理
if (require.main === module) {
processVersion()
}
module.exports = { processVersion, getGitCommitHash }

View File

@ -1,6 +1,6 @@
import { getControledMihomoConfig } from './controledMihomo'
import { mihomoProfileWorkDir, mihomoWorkDir, profileConfigPath, profilePath } from '../utils/dirs'
import { addProfileUpdater } from '../core/profileUpdater'
import { addProfileUpdater, removeProfileUpdater } from '../core/profileUpdater'
import { readFile, rm, writeFile } from 'fs/promises'
import { restartCore } from '../core/manager'
import { getAppConfig } from './app'
@ -82,6 +82,9 @@ export async function addProfileItem(item: Partial<IProfileItem>): Promise<void>
}
export async function removeProfileItem(id: string): Promise<void> {
// 先清理自动更新定时器,防止已删除的订阅重新出现
await removeProfileUpdater(id)
const config = await getProfileConfig()
config.items = config.items?.filter((item) => item.id !== id)
let shouldRestart = false

View File

@ -112,4 +112,15 @@ export async function addProfileUpdater(item: IProfileItem): Promise<void> {
})
}
}
}
export async function removeProfileUpdater(id: string): Promise<void> {
if (intervalPool[id]) {
if (intervalPool[id] instanceof Cron) {
(intervalPool[id] as Cron).stop()
} else {
clearInterval(intervalPool[id] as NodeJS.Timeout)
}
delete intervalPool[id]
}
}

View File

@ -104,7 +104,7 @@ import { getImageDataURL } from './image'
import { startMonitor } from '../resolve/trafficMonitor'
import { closeFloatingWindow, showContextMenu, showFloatingWindow } from '../resolve/floatingWindow'
import i18next from 'i18next'
import { addProfileUpdater } from '../core/profileUpdater'
import { addProfileUpdater, removeProfileUpdater } from '../core/profileUpdater'
function ipcErrorWrapper<T>( // eslint-disable-next-line @typescript-eslint/no-explicit-any
fn: (...args: any[]) => Promise<T> // eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -187,6 +187,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('addProfileItem', (_e, item) => ipcErrorWrapper(addProfileItem)(item))
ipcMain.handle('removeProfileItem', (_e, id) => ipcErrorWrapper(removeProfileItem)(id))
ipcMain.handle('addProfileUpdater', (_e, item) => ipcErrorWrapper(addProfileUpdater)(item))
ipcMain.handle('removeProfileUpdater', (_e, id) => ipcErrorWrapper(removeProfileUpdater)(id))
ipcMain.handle('getOverrideConfig', (_e, force) => ipcErrorWrapper(getOverrideConfig)(force))
ipcMain.handle('setOverrideConfig', (_e, config) => ipcErrorWrapper(setOverrideConfig)(config))
ipcMain.handle('getOverrideItem', (_e, id) => ipcErrorWrapper(getOverrideItem)(id))

View File

@ -167,6 +167,10 @@ export async function addProfileUpdater(item: IProfileItem): Promise<void> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('addProfileUpdater', item))
}
export async function removeProfileUpdater(id: string): Promise<void> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('removeProfileUpdater', id))
}
export async function getProfileStr(id: string): Promise<string> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('getProfileStr', id))
}