mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2026-07-29 06:24:31 +08:00
subcommand: add versions
This commit is contained in:
@@ -8,6 +8,15 @@ import Foundation
|
||||
import Dispatch
|
||||
import ArgumentParser
|
||||
|
||||
struct Versions: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(abstract: "List all supported WeChat versions")
|
||||
|
||||
mutating func run() async throws {
|
||||
try await Config.load(from: Tweak.config).forEach({ print($0.version) })
|
||||
Darwin.exit(EXIT_SUCCESS)
|
||||
}
|
||||
}
|
||||
|
||||
struct Patch: AsyncParsableCommand {
|
||||
enum Error: LocalizedError {
|
||||
case invalidApp
|
||||
@@ -57,42 +66,35 @@ struct Patch: AsyncParsableCommand {
|
||||
}
|
||||
}
|
||||
)
|
||||
var config: URL = URL(string: "https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/feature/2.0/config.json")!
|
||||
var config: URL = Tweak.config
|
||||
|
||||
mutating func run() async throws {
|
||||
do {
|
||||
print("------ Version ------")
|
||||
guard let version = try await Command.version(app: self.app) else {
|
||||
throw Error.invalidVersion
|
||||
}
|
||||
print("\(version)")
|
||||
|
||||
print("------ Config ------")
|
||||
guard let config = (try await Config.load(from: self.config)).first(where: { $0.version == version }) else {
|
||||
throw Error.unsupportedVersion
|
||||
}
|
||||
print("\(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!")
|
||||
|
||||
print("------🎉 Done!------")
|
||||
Darwin.exit(EXIT_SUCCESS)
|
||||
} catch {
|
||||
print("------🚨 Error------")
|
||||
print("\(error.localizedDescription)")
|
||||
Darwin.exit(EXIT_FAILURE)
|
||||
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(from: self.config)).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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,10 +103,13 @@ struct Tweak: AsyncParsableCommand {
|
||||
commandName: "wechattweak",
|
||||
abstract: "A command-line tool for tweaking WeChat.",
|
||||
subcommands: [
|
||||
Versions.self,
|
||||
Patch.self
|
||||
],
|
||||
defaultSubcommand: Self.self
|
||||
)
|
||||
|
||||
static let config = URL(string:"https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/feature/2.0/config.json")!
|
||||
}
|
||||
|
||||
Task {
|
||||
|
||||
Reference in New Issue
Block a user