CLI: fix --version by reading app Info.plist
This commit is contained in:
@@ -159,13 +159,38 @@ struct ClawdisCLI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static func printVersion() {
|
private static func printVersion() {
|
||||||
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "unknown"
|
let info = loadInfo()
|
||||||
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? ""
|
let version = info["CFBundleShortVersionString"] as? String ?? "unknown"
|
||||||
let git = Bundle.main.object(forInfoDictionaryKey: "ClawdisGitCommit") as? String ?? "unknown"
|
let build = info["CFBundleVersion"] as? String ?? ""
|
||||||
let ts = Bundle.main.object(forInfoDictionaryKey: "ClawdisBuildTimestamp") as? String ?? "unknown"
|
let git = info["ClawdisGitCommit"] as? String ?? "unknown"
|
||||||
|
let ts = info["ClawdisBuildTimestamp"] as? String ?? "unknown"
|
||||||
print("clawdis-mac \(version) (\(build)) git:\(git) built:\(ts)")
|
print("clawdis-mac \(version) (\(build)) git:\(git) built:\(ts)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func loadInfo() -> [String: Any] {
|
||||||
|
if let dict = Bundle.main.infoDictionary, !dict.isEmpty { return dict }
|
||||||
|
guard let exePath = executablePath() else { return [:] }
|
||||||
|
let infoURL = exePath
|
||||||
|
.deletingLastPathComponent() // MacOS
|
||||||
|
.deletingLastPathComponent() // Contents
|
||||||
|
.appendingPathComponent("Info.plist")
|
||||||
|
if let data = try? Data(contentsOf: infoURL),
|
||||||
|
let dict = (try? PropertyListSerialization.propertyList(
|
||||||
|
from: data,
|
||||||
|
options: [],
|
||||||
|
format: nil)) as? [String: Any] {
|
||||||
|
return dict
|
||||||
|
}
|
||||||
|
return [:]
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func executablePath() -> URL? {
|
||||||
|
if let cstr = _dyld_get_image_name(0) {
|
||||||
|
return URL(fileURLWithPath: String(cString: cstr)).resolvingSymlinksInPath()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
private static func send(request: Request) async throws -> Response {
|
private static func send(request: Request) async throws -> Response {
|
||||||
let conn = NSXPCConnection(machServiceName: serviceName)
|
let conn = NSXPCConnection(machServiceName: serviceName)
|
||||||
let interface = NSXPCInterface(with: ClawdisXPCProtocol.self)
|
let interface = NSXPCInterface(with: ClawdisXPCProtocol.self)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ PRODUCT="Clawdis"
|
|||||||
BUNDLE_ID="${BUNDLE_ID:-com.steipete.clawdis.debug}"
|
BUNDLE_ID="${BUNDLE_ID:-com.steipete.clawdis.debug}"
|
||||||
BUILD_TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
BUILD_TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||||
GIT_COMMIT=$(cd "$ROOT_DIR" && git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
GIT_COMMIT=$(cd "$ROOT_DIR" && git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
||||||
|
APP_VERSION="${APP_VERSION:-0.0.0}"
|
||||||
|
APP_BUILD="${APP_BUILD:-$GIT_COMMIT}"
|
||||||
|
|
||||||
cd "$ROOT_DIR/apps/macos"
|
cd "$ROOT_DIR/apps/macos"
|
||||||
|
|
||||||
@@ -32,6 +34,10 @@ cat > "$APP_ROOT/Contents/Info.plist" <<PLIST
|
|||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>${BUNDLE_ID}</string>
|
<string>${BUNDLE_ID}</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>${APP_VERSION}</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>${APP_BUILD}</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string>Clawdis</string>
|
<string>Clawdis</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user