mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2025-12-16 09:05:40 +08:00
reorder code blocks
This commit is contained in:
parent
3cc0f2c5c6
commit
0682644327
|
|
@ -9,6 +9,8 @@ import Foundation
|
||||||
import MachO
|
import MachO
|
||||||
|
|
||||||
struct Config: Decodable {
|
struct Config: Decodable {
|
||||||
|
static let `default` = URL(string:"https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/master/config.json")!
|
||||||
|
|
||||||
enum Arch: String, Decodable {
|
enum Arch: String, Decodable {
|
||||||
case arm64
|
case arm64
|
||||||
case x86_64
|
case x86_64
|
||||||
|
|
@ -81,7 +83,7 @@ struct Config: Decodable {
|
||||||
let version: String
|
let version: String
|
||||||
let targets: [Target]
|
let targets: [Target]
|
||||||
|
|
||||||
static func load(from url: URL) async throws -> [Config] {
|
static func load(url: URL = Self.default) async throws -> [Config] {
|
||||||
if url.isFileURL {
|
if url.isFileURL {
|
||||||
return try JSONDecoder().decode(
|
return try JSONDecoder().decode(
|
||||||
[Config].self,
|
[Config].self,
|
||||||
|
|
|
||||||
|
|
@ -8,96 +8,104 @@ import Foundation
|
||||||
import Dispatch
|
import Dispatch
|
||||||
import ArgumentParser
|
import ArgumentParser
|
||||||
|
|
||||||
struct Versions: AsyncParsableCommand {
|
// MARK: Versions
|
||||||
static let configuration = CommandConfiguration(abstract: "List all supported WeChat versions")
|
extension Tweak {
|
||||||
|
struct Versions: AsyncParsableCommand {
|
||||||
|
static let configuration = CommandConfiguration(abstract: "List all supported WeChat versions")
|
||||||
|
|
||||||
mutating func run() async throws {
|
mutating func run() async throws {
|
||||||
try await Config.load(from: Tweak.config).forEach({ print($0.version) })
|
try await Config.load().forEach({ print($0.version) })
|
||||||
Darwin.exit(EXIT_SUCCESS)
|
Darwin.exit(EXIT_SUCCESS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Patch: AsyncParsableCommand {
|
// MARK: Patch
|
||||||
enum Error: LocalizedError {
|
extension Tweak {
|
||||||
case invalidApp
|
struct Patch: AsyncParsableCommand {
|
||||||
case invalidConfig
|
enum Error: LocalizedError {
|
||||||
case invalidVersion
|
case invalidApp
|
||||||
case unsupportedVersion
|
case invalidConfig
|
||||||
|
case invalidVersion
|
||||||
|
case unsupportedVersion
|
||||||
|
|
||||||
var errorDescription: String? {
|
var errorDescription: String? {
|
||||||
switch self {
|
switch self {
|
||||||
case .invalidApp:
|
case .invalidApp:
|
||||||
return "Invalid app path"
|
return "Invalid app path"
|
||||||
case .invalidConfig:
|
case .invalidConfig:
|
||||||
return "Invalid patch config"
|
return "Invalid patch config"
|
||||||
case .invalidVersion:
|
case .invalidVersion:
|
||||||
return "Invalid app version"
|
return "Invalid app version"
|
||||||
case .unsupportedVersion:
|
case .unsupportedVersion:
|
||||||
return "Unsupported WeChat version"
|
return "Unsupported WeChat version"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static let configuration = CommandConfiguration(abstract: "Patch WeChat.app")
|
|
||||||
|
|
||||||
@Option(
|
|
||||||
name: .shortAndLong,
|
|
||||||
help: "Path of WeChat.app",
|
|
||||||
transform: {
|
|
||||||
guard FileManager.default.fileExists(atPath: $0) else {
|
|
||||||
throw Error.invalidApp
|
|
||||||
}
|
|
||||||
return URL(fileURLWithPath: $0)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
var app: URL = URL(fileURLWithPath: "/Applications/WeChat.app", isDirectory: true)
|
|
||||||
|
|
||||||
@Option(
|
|
||||||
name: .shortAndLong,
|
|
||||||
help: "Local path or Remote URL of config.json",
|
|
||||||
transform: {
|
|
||||||
if FileManager.default.fileExists(atPath: $0) {
|
|
||||||
return URL(fileURLWithPath: $0)
|
|
||||||
} else {
|
|
||||||
guard let url = URL(string: $0) else {
|
|
||||||
throw Error.invalidConfig
|
|
||||||
}
|
}
|
||||||
return url
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
var config: URL = Tweak.config
|
|
||||||
|
|
||||||
mutating func run() async throws {
|
static let configuration = CommandConfiguration(abstract: "Patch WeChat.app")
|
||||||
print("------ Version ------")
|
|
||||||
guard let version = try await Command.version(app: self.app) else {
|
|
||||||
throw Error.invalidVersion
|
|
||||||
}
|
|
||||||
print("WeChat version: \(version)")
|
|
||||||
|
|
||||||
print("------ Config ------")
|
@Option(
|
||||||
guard let config = (try await Config.load(from: self.config)).first(where: { $0.version == version }) else {
|
name: .shortAndLong,
|
||||||
throw Error.unsupportedVersion
|
help: "Path of WeChat.app",
|
||||||
}
|
transform: {
|
||||||
print("Matched config: \(config)")
|
guard FileManager.default.fileExists(atPath: $0) else {
|
||||||
|
throw Error.invalidApp
|
||||||
print("------ Patch ------")
|
}
|
||||||
try await Command.patch(
|
return URL(fileURLWithPath: $0)
|
||||||
app: self.app,
|
}
|
||||||
config: config
|
|
||||||
)
|
)
|
||||||
print("Done!")
|
var app: URL = URL(fileURLWithPath: "/Applications/WeChat.app", isDirectory: true)
|
||||||
|
|
||||||
print("------ Resign ------")
|
@Option(
|
||||||
try await Command.resign(
|
name: .shortAndLong,
|
||||||
app: self.app
|
help: "Local path or Remote URL of config.json",
|
||||||
|
transform: {
|
||||||
|
if FileManager.default.fileExists(atPath: $0) {
|
||||||
|
return URL(fileURLWithPath: $0)
|
||||||
|
} else {
|
||||||
|
guard let url = URL(string: $0) else {
|
||||||
|
throw Error.invalidConfig
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
print("Done!")
|
var config: URL = Config.default
|
||||||
|
|
||||||
Darwin.exit(EXIT_SUCCESS)
|
mutating func run() async throws {
|
||||||
|
print("------ Version ------")
|
||||||
|
guard let version = try await Command.version(app: self.app) else {
|
||||||
|
throw Error.invalidVersion
|
||||||
|
}
|
||||||
|
print("WeChat version: \(version)")
|
||||||
|
|
||||||
|
print("------ Config ------")
|
||||||
|
guard let config = (try await Config.load()).first(where: { $0.version == version }) else {
|
||||||
|
throw Error.unsupportedVersion
|
||||||
|
}
|
||||||
|
print("Matched config: \(config)")
|
||||||
|
|
||||||
|
print("------ Patch ------")
|
||||||
|
try await Command.patch(
|
||||||
|
app: self.app,
|
||||||
|
config: config
|
||||||
|
)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
print("------ Resign ------")
|
||||||
|
try await Command.resign(
|
||||||
|
app: self.app
|
||||||
|
)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
Darwin.exit(EXIT_SUCCESS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Tweak
|
||||||
struct Tweak: AsyncParsableCommand {
|
struct Tweak: AsyncParsableCommand {
|
||||||
static let configuration = CommandConfiguration(
|
static let configuration = CommandConfiguration(
|
||||||
commandName: "wechattweak",
|
commandName: "wechattweak",
|
||||||
|
|
@ -108,8 +116,6 @@ struct Tweak: AsyncParsableCommand {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
static let config = URL(string:"https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/master/config.json")!
|
|
||||||
|
|
||||||
mutating func run() async throws {
|
mutating func run() async throws {
|
||||||
print(Tweak.helpMessage())
|
print(Tweak.helpMessage())
|
||||||
Darwin.exit(EXIT_SUCCESS)
|
Darwin.exit(EXIT_SUCCESS)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user