diff --git a/MeoAsstMac/Core/Maa.swift b/MeoAsstMac/Core/Maa.swift index 94f0780c5..10357e743 100644 --- a/MeoAsstMac/Core/Maa.swift +++ b/MeoAsstMac/Core/Maa.swift @@ -10,8 +10,20 @@ import Foundation import MaaCore import SwiftyJSON +@_silgen_name("AsstGetVersion") +private func MaaCoreAsstGetVersion() -> UnsafePointer? + actor MAAProvider { static let shared = MAAProvider() + + static let coreVersion: String = { + guard let versionPointer = MaaCoreAsstGetVersion() else { + return "Unknown" + } + + return String(cString: versionPointer) + }() + private init() {} func loadResource(path: String) throws { diff --git a/MeoAsstMac/Model/MAAViewModel.swift b/MeoAsstMac/Model/MAAViewModel.swift index a47c21cfa..cfc51f8b5 100644 --- a/MeoAsstMac/Model/MAAViewModel.swift +++ b/MeoAsstMac/Model/MAAViewModel.swift @@ -342,12 +342,14 @@ extension MAAViewModel { """ 外部资源版本:\(currentResourceVersion.title) 更新时间:\(currentResourceVersion.last_updated) + \(MaaVersionInfo.coreVersionLogLine()) """) } else { logTrace( """ 内置资源版本:\(currentResourceVersion.title) 更新时间:\(currentResourceVersion.last_updated) + \(MaaVersionInfo.coreVersionLogLine()) """) let url = documentsDirectory.appendingPathComponent("resource", isDirectory: true) try? FileManager.default.removeItem(at: url) diff --git a/MeoAsstMac/Settings/UpdaterSettingsView.swift b/MeoAsstMac/Settings/UpdaterSettingsView.swift index b34e8bd34..4879b9a58 100644 --- a/MeoAsstMac/Settings/UpdaterSettingsView.swift +++ b/MeoAsstMac/Settings/UpdaterSettingsView.swift @@ -7,6 +7,7 @@ import Sparkle import SwiftUI +import AppKit struct UpdaterSettingsView: View { private let updater: SPUUpdater @@ -38,6 +39,10 @@ struct UpdaterSettingsView: View { .onChange(of: automaticallyDownloadsUpdates) { newValue in updater.automaticallyDownloadsUpdates = newValue } + + Button("复制版本信息") { + copyVersionInfo() + } Divider() @@ -62,6 +67,15 @@ struct UpdaterSettingsView: View { .animation(.default, value: resourceChannel) .padding() } + +//复制更详细的版本信息 + private func copyVersionInfo() { + guard let (_, resourceVersion) = try? resourceChannel.version() else { return } + + let pasteboard = NSPasteboard.general + pasteboard.clearContents() + pasteboard.setString(MaaVersionInfo.text(resourceVersion: resourceVersion), forType: .string) + } } private let mirrorChyanCDK = Binding { diff --git a/MeoAsstMac/Utils/ResourceUpdater.swift b/MeoAsstMac/Utils/ResourceUpdater.swift index 2504fa825..881d87569 100644 --- a/MeoAsstMac/Utils/ResourceUpdater.swift +++ b/MeoAsstMac/Utils/ResourceUpdater.swift @@ -107,3 +107,27 @@ extension MAAResourceChannel { return try decoder.decode(MAAResourceVersion.self, from: data) } } + +enum MaaVersionInfo { + static var uiVersion: String { + let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown" + return version.hasPrefix("v") ? version : "v\(version)" + } + + static var coreVersion: String { + MAAProvider.coreVersion + } + + static func text(resourceVersion: MAAResourceVersion) -> String { + """ + UI Version: \(uiVersion) + Core Version: \(coreVersion) + Resource Version: \(resourceVersion.title) + Resource Time: \(resourceVersion.last_updated) + """ + } + + static func coreVersionLogLine() -> String { + String(localized: "Core Version: \(coreVersion)") + } +} diff --git a/Resources/Localizable.xcstrings b/Resources/Localizable.xcstrings index aee47be4d..2938573c0 100644 --- a/Resources/Localizable.xcstrings +++ b/Resources/Localizable.xcstrings @@ -1225,6 +1225,15 @@ }, "PV-烟花筹委会" : { + }, + "RA-1" : { + + }, + "RA-4" : { + + }, + "RA-15" : { + }, "Read item_index.json failed: %@" : { "localizations" : { @@ -2238,7 +2247,18 @@ } } }, + "内置资源版本:%@\nMaaCore 版本:%@\n更新时间:%@" : { + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "new", + "value" : "内置资源版本:%1$@\nMaaCore 版本:%2$@\n更新时间:%3$@" + } + } + } + }, "内置资源版本:%@\n更新时间:%@" : { + "extractionState" : "stale", "localizations" : { "ko" : { "stringUnit" : { @@ -2759,6 +2779,9 @@ } } } + }, + "复制版本信息" : { + }, "复制结果JSON至剪贴板:" : { "localizations" : {