Skip to content

Commit

Permalink
feat: Add reset procedure & released version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
X1a0He committed Nov 16, 2024
1 parent bc6cfba commit 735b3d6
Show file tree
Hide file tree
Showing 22 changed files with 321 additions and 119 deletions.
8 changes: 4 additions & 4 deletions Adobe Downloader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 120;
CURRENT_PROJECT_VERSION = 130;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Adobe Downloader/Preview Content\"";
DEVELOPMENT_TEAM = TG862GVKHK;
Expand All @@ -434,7 +434,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.x1a0he.macOS.Adobe-Downloader";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -452,7 +452,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 120;
CURRENT_PROJECT_VERSION = 130;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Adobe Downloader/Preview Content\"";
DEVELOPMENT_TEAM = TG862GVKHK;
Expand All @@ -468,7 +468,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.x1a0he.macOS.Adobe-Downloader";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
12 changes: 8 additions & 4 deletions Adobe Downloader/HelperManager/PrivilegedHelperManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,24 @@ class PrivilegedHelperManager: NSObject {
}
}
}

while true {
let output = try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<String, Error>) in
helper.getInstallationOutput { result in
continuation.resume(returning: result)
}
}

if output == "Completed" {
break
} else if !output.isEmpty {
if !output.isEmpty {
progress(output)
}

if output.contains("Exit Code:") || output.range(of: "Progress: \\d+/\\d+", options: .regularExpression) != nil{
if(output.range(of: "Progress: \\d+/\\d+", options: .regularExpression) != nil) {
progress("Exit Code: 0")
}
break
}

try await Task.sleep(nanoseconds: 100_000_000)
}
}
Expand Down
3 changes: 2 additions & 1 deletion Adobe Downloader/Scripts/clean-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sudo /bin/rm /Library/LaunchDaemons/com.x1a0he.macOS.Adobe-Downloader.helper.pli
sudo /bin/rm /Library/PrivilegedHelperTools/com.x1a0he.macOS.Adobe-Downloader.helper
sudo /bin/rm -rf ~/Library/Application\ Support/Adobe\ Downloader
sudo /bin/rm ~/Library/Preferences/com.x1a0he.macOS.Adobe-Downloader.plist
sudo /usr/bin/killall -u root -9 com.x1a0he.macOS.Adobe-Downloader.helper
sudo /usr/bin/killall -u root -9 com.x1a0he.macOS.Adobe-Downloader.helper
sudo rm "$0"
1 change: 0 additions & 1 deletion Adobe Downloader/Services/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class NetworkService {
guard let url = components?.url else {
throw NetworkError.invalidURL(NetworkConstants.productsXmlURL)
}
print(url)
return url
}

Expand Down
8 changes: 1 addition & 7 deletions Adobe Downloader/Utils/DownloadUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,6 @@ class DownloadUtils {
continue
}

#if DEBUG
if let manifestString = String(data: manifestData, encoding: .utf8) {
print("Manifest内容: \(manifestString)")
}
#endif
let manifestDoc = try XMLDocument(data: manifestData)
let assetPathNodes = try manifestDoc.nodes(forXPath: "//asset_path")
let sizeNodes = try manifestDoc.nodes(forXPath: "//asset_size")
Expand Down Expand Up @@ -1139,7 +1134,7 @@ class DownloadUtils {
}
}
}

try await Task.sleep(nanoseconds: 1_000_000_000)
try await withCheckedThrowingContinuation { continuation in
ModifySetup.backupAndModifySetupFile { success, message in
if success {
Expand All @@ -1151,7 +1146,6 @@ class DownloadUtils {
}

ModifySetup.clearVersionCache()

try? FileManager.default.removeItem(at: tempDirectory)

await MainActor.run {
Expand Down
106 changes: 97 additions & 9 deletions Adobe Downloader/Views/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ struct GeneralSettingsView: View {
helperAlertSuccess: $helperAlertSuccess)
CCSettingsView(viewModel: viewModel)
UpdateSettingsView(viewModel: viewModel)
CleanConfigView()
}
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
Expand Down Expand Up @@ -433,15 +434,89 @@ struct UpdateSettingsView: View {
}
}

#Preview("About Tab") {
AboutAppView()
}

#Preview("General Settings") {
let networkManager = NetworkManager()
VStack {
GeneralSettingsView(updater: PreviewUpdater())
.environmentObject(networkManager)
struct CleanConfigView: View {
@State private var showConfirmation = false
@State private var showAlert = false
@State private var alertMessage = ""

var body: some View {
GroupBox(label: Text("重置程序").padding(.bottom, 8)) {
VStack(alignment: .leading, spacing: 12) {
HStack {
Button("重置程序") {
showConfirmation = true
}
.buttonStyle(.borderedProminent)
.tint(.red)
}
}
.padding(8)
}
.alert("确认重置程序", isPresented: $showConfirmation) {
Button("取消", role: .cancel) { }
Button("确定", role: .destructive) {
cleanConfig()
}
} message: {
Text("这将清空所有配置并结束应用程序,确定要继续吗?")
}
.alert("操作结果", isPresented: $showAlert) {
Button("确定") { }
} message: {
Text(alertMessage)
}
}

private func cleanConfig() {
do {
let downloadsURL = try FileManager.default.url(for: .downloadsDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false)
let scriptURL = downloadsURL.appendingPathComponent("clean-config.sh")

guard let scriptPath = Bundle.main.path(forResource: "clean-config", ofType: "sh"),
let scriptContent = try? String(contentsOfFile: scriptPath, encoding: .utf8) else {
throw NSError(domain: "ScriptError", code: 1, userInfo: [NSLocalizedDescriptionKey: "无法读取脚本文件"])
}

try scriptContent.write(to: scriptURL, atomically: true, encoding: .utf8)

try FileManager.default.setAttributes([.posixPermissions: 0o755],
ofItemAtPath: scriptURL.path)

if PrivilegedHelperManager.getHelperStatus {
PrivilegedHelperManager.shared.executeCommand("open -a Terminal \(scriptURL.path)") { output in
if output.isEmpty {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
exit(0)
}
} else {
alertMessage = "清空配置失败: \(output)"
showAlert = true
}
}
} else {
let terminalURL = URL(fileURLWithPath: "/System/Applications/Utilities/Terminal.app")
NSWorkspace.shared.open([scriptURL],
withApplicationAt: terminalURL,
configuration: NSWorkspace.OpenConfiguration()) { _, error in
if let error = error {
alertMessage = "打开终端失败: \(error.localizedDescription)"
showAlert = true
return
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
exit(0)
}
}
}

} catch {
alertMessage = "清空配置失败: \(error.localizedDescription)"
showAlert = true
}
}
}

Expand Down Expand Up @@ -770,3 +845,16 @@ struct AutoDownloadRow: View {
}
}


#Preview("About Tab") {
AboutAppView()
}

#Preview("General Settings") {
let networkManager = NetworkManager()
VStack {
GeneralSettingsView(updater: PreviewUpdater())
.environmentObject(networkManager)
}
.fixedSize()
}
Loading

0 comments on commit 735b3d6

Please sign in to comment.