From b2ab5d9510918435c104087b8a38c6658b922e61 Mon Sep 17 00:00:00 2001 From: shawn Date: Tue, 7 Jul 2026 22:38:57 +0800 Subject: [PATCH] feat: add manual update check --- Sources/LocalShare/Lang.swift | 10 ++++++++-- Sources/LocalShare/SettingsScreen.swift | 11 +++++++++++ build.sh | 14 +++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Sources/LocalShare/Lang.swift b/Sources/LocalShare/Lang.swift index f1cba3e..b6de215 100644 --- a/Sources/LocalShare/Lang.swift +++ b/Sources/LocalShare/Lang.swift @@ -122,6 +122,7 @@ enum L: CaseIterable { // 设置 —— 更新 case autoUpdate, autoUpdateDescOn, autoUpdateDescOff + case manualUpdate, manualUpdateDescOn, manualUpdateDescOff // 设置 —— 命令行工具 case cliHintAvailable, cliHintUnavailable @@ -289,9 +290,14 @@ enum L: CaseIterable { case .resetWindowDesc: return ("把窗口还原成默认大小", "Restore the window to its default size") case .autoUpdate: return ("自动更新", "Automatic Updates") - case .autoUpdateDescOn: return ("关闭后不自动更新、不弹提示;仍可在菜单「检查更新…」手动检查", - "When off, no auto-updates or prompts; you can still check manually via the menu") + case .autoUpdateDescOn: return ("关闭后不自动检查、不弹提示;仍可手动检查", + "When off, no automatic checks or prompts; manual checks still work") case .autoUpdateDescOff: return ("开发构建未启用更新,正式版生效", "Updates are disabled in dev builds; active in release") + case .manualUpdate: return ("手动检查更新", "Manual Update Check") + case .manualUpdateDescOn: return ("立刻检查是否有新版,有更新时按提示安装", + "Check for a new version now and install when prompted") + case .manualUpdateDescOff: return ("开发构建未启用更新,正式版可手动检查", + "Updates are disabled in dev builds; active in release") case .cliHintAvailable: return ("在终端用 localshare 分享文件", "Use localshare in the terminal to share files") case .cliHintUnavailable: return ("以 app 包运行时可安装", "Installable when run as an app bundle") diff --git a/Sources/LocalShare/SettingsScreen.swift b/Sources/LocalShare/SettingsScreen.swift index fb61b69..13b2180 100644 --- a/Sources/LocalShare/SettingsScreen.swift +++ b/Sources/LocalShare/SettingsScreen.swift @@ -201,6 +201,17 @@ struct SettingsScreen: View { updater.setAutomaticChecks(!updater.automaticChecks) } } + settingRow(top: true, + title: L.manualUpdate(lang), + desc: updater.isActive + ? L.manualUpdateDescOn(lang) + : L.manualUpdateDescOff(lang)) { + GhostButton(t: t, title: L.checkForUpdates(lang), systemImage: "arrow.clockwise") { + updater.checkForUpdates() + } + .disabled(!updater.canCheckForUpdates) + .opacity(updater.canCheckForUpdates ? 1 : 0.5) + } } // MARK: 命令行工具 diff --git a/build.sh b/build.sh index 71c969c..bd7e4cf 100755 --- a/build.sh +++ b/build.sh @@ -34,9 +34,21 @@ cp "$EXT_BIN_PATH" "$EXT/Contents/MacOS/$EXT_BINARY" cp "$ROOT/bundle/ShareExtensionInfo.plist" "$EXT/Contents/Info.plist" cp "$ROOT/bundle/AppIcon.icns" "$EXT/Contents/Resources/AppIcon.icns" -# 扩展版本号与宿主 app 保持一致;release workflow 会在 build.sh 前改写 bundle/Info.plist。 +# 本地构建时 bundle/Info.plist 仍是占位版本;CI release 会在 build.sh 前按 tag 改写, +# 因此这里只在占位值仍存在时,用最近的 vX.Y.Z tag 生成一个可用的本地版本号。 APP_SHORT_VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")" APP_BUILD_VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP/Contents/Info.plist")" +if [ "$APP_SHORT_VERSION" = "0.2.0" ] && git -C "$ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1; then + GIT_VERSION="$(git -C "$ROOT" describe --tags --match 'v[0-9]*' --abbrev=0 2>/dev/null || true)" + if [ -n "$GIT_VERSION" ]; then + APP_SHORT_VERSION="${GIT_VERSION#v}" + APP_BUILD_VERSION="$(git -C "$ROOT" rev-list --count HEAD)" + /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $APP_SHORT_VERSION" "$APP/Contents/Info.plist" + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $APP_BUILD_VERSION" "$APP/Contents/Info.plist" + echo "==> 本地版本号: $APP_SHORT_VERSION ($APP_BUILD_VERSION)" + fi +fi +# 扩展版本号与宿主 app 保持一致。 /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $APP_SHORT_VERSION" "$EXT/Contents/Info.plist" /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $APP_BUILD_VERSION" "$EXT/Contents/Info.plist"