From ed5543d594bc3f19c5a77ed7209bf4e3b505068e Mon Sep 17 00:00:00 2001 From: Nookery Date: Fri, 27 Sep 2024 13:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Chore:=20=20Minor=20adjustments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Views/Content/CommitList.swift | 78 +++++++++++-------- .../xcshareddata/swiftpm/Package.resolved | 2 +- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/App/Views/Content/CommitList.swift b/App/Views/Content/CommitList.swift index e8a1d7e..a2b0566 100644 --- a/App/Views/Content/CommitList.swift +++ b/App/Views/Content/CommitList.swift @@ -1,8 +1,8 @@ +import MagicKit import OSLog import SwiftUI -import MagicKit -struct CommitList: View, SuperThread, SuperLog{ +struct CommitList: View, SuperThread, SuperLog { @EnvironmentObject var app: AppProvider @EnvironmentObject var g: GitProvider @@ -37,42 +37,19 @@ struct CommitList: View, SuperThread, SuperLog{ } } } - .onAppear { - refresh("OnAppear") - self.showCommitForm = project.hasUnCommittedChanges() - } - .onChange(of: selection, { - g.setCommit(selection) - }) - .onChange(of: g.project, { - self.refresh("\(self.t)Project Changed") - }) - .onReceive(NotificationCenter.default.publisher(for: .gitCommitSuccess)) { _ in - guard let project = g.project else { - return - } - - let commits = [project.headCommit] + project.getCommits("") - - self.main.async { - self.commits = commits - } - } - .onReceive(NotificationCenter.default.publisher(for: .gitPullSuccess)) { _ in - self.refresh("\(self.t)GitPullSuccess") - } - .onReceive(NotificationCenter.default.publisher(for: .gitPushSuccess)) { _ in - self.refresh("\(self.t)GitPushSuccess") - } -// .onReceive(NotificationCenter.default.publisher(for: .appWillBecomeActive)) { _ in -// self.refresh("\(self.label)AppWillBecomeActive") -// } + .onAppear(perform: onAppear) + .onChange(of: selection, onChangeOfSelection) + .onChange(of: g.project, onProjectChange) + .onReceive(NotificationCenter.default.publisher(for: .gitCommitSuccess), perform: onCommitSuccess) + .onReceive(NotificationCenter.default.publisher(for: .gitPullSuccess), perform: onPullSuccess) + .onReceive(NotificationCenter.default.publisher(for: .gitPushSuccess), perform: onPushSuccess) +// .onReceive(NotificationCenter.default.publisher(for: .appWillBecomeActive), perform: onAppWillBecomeActive) } } func refresh(_ reason: String = "") { let verbose = false - + guard let project = g.project, !isRefreshing else { return } @@ -85,18 +62,51 @@ struct CommitList: View, SuperThread, SuperLog{ if verbose { os_log("\(t)Refresh(\(reason))") } - + let commits = [project.headCommit] + project.getCommits(reason) self.main.async { self.commits = commits self.loading = false self.isRefreshing = false + self.showCommitForm = project.hasUnCommittedChanges() } } } } +// MARK: Event Handlers + +extension CommitList { + func onProjectChange() { + self.refresh("\(self.t)Project Changed") + } + + func onCommitSuccess(_ notification: Notification) { + self.refresh("\(self.t)GitCommitSuccess") + } + + func onAppear() { + refresh("OnAppear") + } + + func onChangeOfSelection() { + g.setCommit(selection) + } + + func onPullSuccess(_ notification: Notification) { + self.refresh("\(self.t)GitPullSuccess") + } + + func onPushSuccess(_ notification: Notification) { + self.refresh("\(self.t)GitPushSuccess") + } + + func onAppWillBecomeActive(_ notification: Notification) { + self.refresh("\(self.t)AppWillBecomeActive") + } +} + #Preview { AppPreview() .frame(width: 800) diff --git a/GitOK.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/GitOK.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index c1d8695..1cd8456 100644 --- a/GitOK.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/GitOK.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/CofficLab/MagicKit", "state" : { "branch" : "main", - "revision" : "158fd5ff30cf47546f5d433600b86d6d6815b0c4" + "revision" : "409913a41dfffdb4d5f23f31efaf3c669685147f" } }, {