-
-
Save Lakr233/cde8bd539713afc5df78f9c64e05c7ef to your computer and use it in GitHub Desktop.
Only Apple Can Do.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// 装逼 | |
// | |
// Created by 秋星桥 on 2024/4/4. | |
// | |
import Cocoa | |
import IOKit | |
import SwiftUI | |
import ColorfulX | |
let productName = { | |
let mainEntry = IORegistryEntryFromPath(kIOMainPortDefault, "IOService:/AppleARMPE/product") | |
defer { IOObjectRelease(mainEntry) } | |
let property = IORegistryEntryCreateCFProperty(mainEntry, "product-description" as CFString, kCFAllocatorDefault, 0) | |
if let bytes = property?.takeRetainedValue() as? Data { | |
let array = [UInt8](bytes) | |
let terminatedModelString = String(cString: array) | |
return terminatedModelString | |
} | |
return "" | |
}() | |
let cpuName = productName | |
.components(separatedBy: "(") | |
.last? | |
.components(separatedBy: ")") | |
.first? | |
.trimmingCharacters(in: .whitespacesAndNewlines) | |
.components(separatedBy: ",") | |
.first ?? "" | |
let yearName = productName | |
.components(separatedBy: "(") | |
.last? | |
.components(separatedBy: ")") | |
.first? | |
.trimmingCharacters(in: .whitespacesAndNewlines) | |
.components(separatedBy: ",") | |
.last ?? "" | |
let memsize = (ProcessInfo().physicalMemory / 1024 / 1024) / 1024 | |
let bootdisk = "Macintosh HD" | |
let systemName = "Sonoma" | |
let systemVersion = "\(ProcessInfo().operatingSystemVersion.majorVersion).\(ProcessInfo().operatingSystemVersion.minorVersion).\(ProcessInfo().operatingSystemVersion.patchVersion)" | |
struct ContentView: View { | |
var body: some View { | |
content | |
.background( | |
ColorfulView( | |
color: .constant(ColorfulPreset.neon.colors), | |
speed: .constant(0.5) | |
) | |
.ignoresSafeArea() | |
) | |
} | |
var modalName: String { | |
productName | |
.components(separatedBy: "(") | |
.first? | |
.trimmingCharacters(in: .whitespacesAndNewlines) | |
?? "" | |
} | |
@ViewBuilder | |
var content: some View { | |
VStack(spacing: 16) { | |
Text("标准件厂长砍砍制作,版权没有,盗版不纠。@Lakr233") | |
.font(.footnote) | |
.opacity(0.5) | |
Divider() | |
HStack(spacing: 64) { | |
info | |
.padding(32) | |
.background(.thinMaterial) | |
.clipShape(RoundedRectangle(cornerRadius: 16)) | |
.fixedSize() | |
price | |
.frame(maxWidth: .infinity) | |
} | |
.padding(.horizontal, 64) | |
Divider() | |
toolbar.padding() | |
Spacer().frame(height: 0) | |
} | |
} | |
func keyValue(_ title: String, _ value: String, redacted: Bool = false) -> some View { | |
GridRow { | |
Text(title) | |
.opacity(0.8) | |
.frame(width: 66, alignment: .trailing) | |
if redacted { | |
Text(value) | |
.redacted(reason: .placeholder) | |
} else { | |
Text(value) | |
.opacity(0.75) | |
} | |
} | |
.offset(x: -20) | |
.font(.footnote) | |
} | |
@ViewBuilder | |
var info: some View { | |
VStack(spacing: 4) { | |
Group { | |
Image(nsImage: .init(named: NSImage.computerName) ?? .init()) | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
.frame(width: 180) | |
.fixedSize() | |
Text(modalName) | |
.font(.title) | |
.bold() | |
Text("\(cpuName), \(yearName)年") | |
.font(.footnote) | |
.foregroundStyle(.secondary) | |
.opacity(0.5) | |
} | |
Text("88").opacity(0) | |
Grid(alignment: .leading) { | |
keyValue("芯片", "Apple \(cpuName)") | |
keyValue("内存", "\(memsize) GB") | |
keyValue("启动磁盘", bootdisk) | |
keyValue("序列号", "G92M2Y8888", redacted: true) | |
keyValue("macOS", "\(systemName) \(systemVersion)") | |
} | |
Text("88").opacity(0) | |
Text("更多信息...") | |
.padding(.top, 2) | |
.padding(.bottom, 2) | |
.padding(.horizontal, 10) | |
.background( | |
RoundedRectangle(cornerRadius: 5) | |
.foregroundStyle(.gray) | |
.opacity(0.25) | |
) | |
Text("88").opacity(0) | |
VStack(spacing: 0) { | |
Text("监管认证") | |
.underline() | |
Text("™和© 1983-2024 Apple Inc.") | |
Text("保留一切权利。") | |
} | |
.font(.footnote) | |
.opacity(0.4) | |
} | |
} | |
@ViewBuilder | |
var price: some View { | |
VStack(alignment: .leading, spacing: 16) { | |
Divider().opacity(0) | |
HStack(spacing: 16) { | |
Image(systemName: "applelogo") | |
Text("官网售价") | |
} | |
.font(.system(size: 32, weight: .bold, design: .default)) | |
Text("¥ 48, 999") | |
.font(.system(size: 64, weight: .bold, design: .default)) | |
Text("您的价格击败 55% 苹果用户,66% 田牌电脑用户。") | |
.font(.system(size: 16, weight: .bold, design: .default)) | |
Text("您的雷电口数量击败 77% 苹果用户,88% 田牌电脑用户。") | |
.font(.system(size: 16, weight: .bold, design: .default)) | |
Text("您的 Apple Care+ 天数量击败 99% 苹果用户,100% 田牌电脑用户。") | |
.font(.system(size: 16, weight: .bold, design: .default)) | |
} | |
.frame(minWidth: 500, alignment: .leading) | |
} | |
@ViewBuilder | |
var toolbar: some View { | |
HStack { | |
Button("分享到社交媒体 (+100积分)") {} | |
Button("保存图片(Pro 或 200积分)") {} | |
Button("填写拼多多邀请链接(Pro 或 200 积分)") {} | |
Button("自定义售价(Pro 或 1000 积分)") {} | |
} | |
} | |
} | |
#Preview("", traits: .sizeThatFitsLayout) { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment