Skip to content

Commit 0147e07

Browse files
Create comprehensive debug updater with detailed logging
🔧 New UpdateDebugView: - Created UpdateDebugView.swift with comprehensive logging system - Shows detailed step-by-step update process with timestamps - Displays current version detection and GitHub API communication - Includes clipboard copy functionality for debugging - Handles local builds with fallback version detection - Provides clear error messages and status indicators 🐛 Debug improvements: - Added detailed logging for version detection from Info.plist - Added comprehensive GitHub API request/response logging - Added version comparison logic with detailed output - Added network error handling with specific error messages - Added clipboard copy functionality for log analysis 📱 UI improvements: - Large text-based dialog (700x500) for better readability - Monospaced font for log messages for better alignment - Color-coded status indicators (success/error/progress) - Auto-expanded log section for immediate visibility - Clear action buttons with proper state management 🔍 Local build support: - Handles missing CFBundleShortVersionString gracefully - Uses fallback version '1.0.0' for local builds - Provides clear warnings when using default values - Comprehensive logging for version detection process This replaces the previous UpdateProgressView with a more robust debugging system.
1 parent 1076418 commit 0147e07

3 files changed

Lines changed: 352 additions & 128 deletions

File tree

A6Cutter/A6CutterApp.swift

Lines changed: 12 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,13 @@ import SwiftUI
99
import SwiftData
1010
// import Sparkle // TODO: Add Sparkle package dependency in Xcode
1111

12-
// MARK: - GitHub API Models
13-
struct GitHubRelease: Codable, Sendable {
14-
let tagName: String
15-
let name: String
16-
let body: String
17-
let htmlUrl: String
18-
let publishedAt: String
19-
20-
enum CodingKeys: String, CodingKey {
21-
case tagName = "tag_name"
22-
case name
23-
case body
24-
case htmlUrl = "html_url"
25-
case publishedAt = "published_at"
26-
}
27-
}
2812

2913
@main
3014
struct A6CutterApp: App {
3115
@Environment(\.openWindow) private var openWindow
3216

33-
// Update progress state
34-
@State private var showUpdateProgress = false
35-
@State private var updateCurrentVersion = ""
36-
@State private var updateLatestVersion = ""
37-
@State private var updateReleaseNotes = ""
17+
// Update debug state
18+
@State private var showUpdateDebug = false
3819

3920
// Sparkle updater controller - TODO: Uncomment after adding Sparkle package
4021
// private let updaterController = SPUStandardUpdaterController(
@@ -49,79 +30,24 @@ struct A6CutterApp: App {
4930
}
5031

5132
private func checkForUpdates() {
52-
// Check for updates by comparing current version with latest GitHub release
53-
checkForUpdatesFromGitHub()
33+
// Show debug updater
34+
print("DEBUG: checkForUpdates called - showing debug updater")
35+
showUpdateDebug = true
5436
}
5537

56-
private func checkForUpdatesFromGitHub() {
57-
// Get current app version
58-
let currentVersion = getCurrentAppVersion()
59-
60-
// Fetch latest release from GitHub
61-
fetchLatestRelease { latestRelease in
62-
DispatchQueue.main.async {
63-
64-
if let latestRelease = latestRelease {
65-
let latestVersion = latestRelease.tagName.replacingOccurrences(of: "v", with: "")
66-
67-
if self.isNewerVersion(latestVersion, than: currentVersion) {
68-
self.showUpdateDialog(currentVersion: currentVersion, latestVersion: latestVersion, releaseNotes: latestRelease.body)
69-
} else {
70-
self.showNoUpdatesDialog()
71-
}
72-
} else {
73-
self.showUpdateErrorDialog()
74-
}
75-
}
76-
}
77-
}
7838

7939
private func getCurrentAppVersion() -> String {
8040
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
41+
print("DEBUG: CFBundleShortVersionString found: '\(version)'")
8142
// Remove 'v' prefix if present for consistent comparison
82-
return version.hasPrefix("v") ? String(version.dropFirst()) : version
43+
let cleanVersion = version.hasPrefix("v") ? String(version.dropFirst()) : version
44+
print("DEBUG: Clean version: '\(cleanVersion)'")
45+
return cleanVersion
8346
}
47+
print("DEBUG: CFBundleShortVersionString not found. Using default '1.0.0'")
8448
return "1.0.0"
8549
}
8650

87-
private func fetchLatestRelease(completion: @escaping (GitHubRelease?) -> Void) {
88-
let urlString = "https://api.github.com/repos/devopsmariocom/A6Cutter/releases/latest"
89-
print("DEBUG: Fetching from URL: \(urlString)")
90-
91-
guard let url = URL(string: urlString) else {
92-
print("DEBUG: Failed to create URL from string: \(urlString)")
93-
completion(nil)
94-
return
95-
}
96-
97-
var request = URLRequest(url: url)
98-
request.setValue("application/vnd.github.v3+json", forHTTPHeaderField: "Accept")
99-
request.setValue("A6Cutter/\(getCurrentAppVersion())", forHTTPHeaderField: "User-Agent")
100-
101-
print("DEBUG: Making request with headers: \(request.allHTTPHeaderFields ?? [:])")
102-
103-
URLSession.shared.dataTask(with: request) { data, response, error in
104-
guard let data = data, error == nil else {
105-
print("DEBUG: GitHub API error: \(error?.localizedDescription ?? "Unknown error")")
106-
completion(nil)
107-
return
108-
}
109-
110-
// Debug: Print raw response
111-
if let responseString = String(data: data, encoding: .utf8) {
112-
print("DEBUG: GitHub API response: \(responseString)")
113-
}
114-
115-
do {
116-
let release = try JSONDecoder().decode(GitHubRelease.self, from: data)
117-
print("DEBUG: Parsed release - tagName: '\(release.tagName)', name: '\(release.name)'")
118-
completion(release)
119-
} catch {
120-
print("DEBUG: JSON decode error: \(error)")
121-
completion(nil)
122-
}
123-
}.resume()
124-
}
12551

12652
private func isNewerVersion(_ latest: String, than current: String) -> Bool {
12753
let latestComponents = latest.split(separator: ".").compactMap { Int($0) }
@@ -143,41 +69,6 @@ struct A6CutterApp: App {
14369
return false
14470
}
14571

146-
private func showUpdateDialog(currentVersion: String, latestVersion: String, releaseNotes: String) {
147-
updateCurrentVersion = currentVersion
148-
updateLatestVersion = latestVersion
149-
updateReleaseNotes = releaseNotes
150-
showUpdateProgress = true
151-
}
152-
153-
// Update functionality moved to UpdateProgressView
154-
155-
private func showDownloadError(_ message: String) {
156-
let alert = NSAlert()
157-
alert.messageText = "Update Failed"
158-
alert.informativeText = message
159-
alert.alertStyle = .warning
160-
alert.addButton(withTitle: "OK")
161-
alert.runModal()
162-
}
163-
164-
private func showNoUpdatesDialog() {
165-
let alert = NSAlert()
166-
alert.messageText = "No Updates Available"
167-
alert.informativeText = "You are running the latest version of A6Cutter."
168-
alert.alertStyle = .informational
169-
alert.addButton(withTitle: "OK")
170-
alert.runModal()
171-
}
172-
173-
private func showUpdateErrorDialog() {
174-
let alert = NSAlert()
175-
alert.messageText = "Update Check Failed"
176-
alert.informativeText = "Unable to check for updates. Please check your internet connection and try again."
177-
alert.alertStyle = .warning
178-
alert.addButton(withTitle: "OK")
179-
alert.runModal()
180-
}
18172

18273
var sharedModelContainer: ModelContainer = {
18374
let schema = Schema([
@@ -195,13 +86,8 @@ struct A6CutterApp: App {
19586
var body: some Scene {
19687
WindowGroup {
19788
ContentView()
198-
.sheet(isPresented: $showUpdateProgress) {
199-
UpdateProgressView(
200-
isPresented: $showUpdateProgress,
201-
currentVersion: updateCurrentVersion,
202-
latestVersion: updateLatestVersion,
203-
releaseNotes: updateReleaseNotes
204-
)
89+
.sheet(isPresented: $showUpdateDebug) {
90+
UpdateDebugView(isPresented: $showUpdateDebug)
20591
}
20692
}
20793
.modelContainer(sharedModelContainer)

A6Cutter/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundleSignature</key>
1818
<string>????</string>
1919
<key>CFBundleVersion</key>
20-
<string>7fe41aa</string>
20+
<string>1076418</string>
2121
<key>GitHash</key>
22-
<string>7fe41aa202cf5f453abc3c328006fd93fa0a29d4</string>
22+
<string>10764189f5c722bddd9e55334df239195d358c66</string>
2323
<key>LSMinimumSystemVersion</key>
2424
<string>14.0</string>
2525
<key>NSHumanReadableCopyright</key>

0 commit comments

Comments
 (0)