Skip to content

Commit 39d962a

Browse files
committed
Made sheet config more useful and changed GitHub sign in to use it.
1 parent 6290613 commit 39d962a

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

CCMenu/Source/Pipeline Window/EditPipelineSheet.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ struct EditPipelineSheet: View {
3737
}
3838
.keyboardShortcut(.cancelAction)
3939
Button("Apply") {
40-
config.pipeline?.name = name
40+
if var p = config.pipeline {
41+
p.name = name
42+
config.setPipeline(p)
43+
}
4144
presentation.dismiss()
4245
}
4346
.keyboardShortcut(.defaultAction)

CCMenu/Source/Pipeline Window/PipelineListMenu.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct PipelineListMenu: View {
3333
Divider()
3434
Button("Edit...") {
3535
let p = model.pipelines.first(where: { viewState.selection.contains($0.id) })
36-
viewState.editPipelineSheetConfig.pipeline = p
36+
viewState.editPipelineSheetConfig.setPipeline(p)
3737
viewState.editPipelineSheetConfig.isPresented = true
3838
}
3939
.disabled(contextSelection.count != 1)
@@ -55,7 +55,7 @@ struct PipelineListMenu: View {
5555
Button("Sign In at GitHub...") {
5656
Task {
5757
if await ghAuthenticator.signInAtGitHub() {
58-
viewState.isShowingSignInAtGitHubSheet = true
58+
viewState.signInAtGitHubSheetSheetConfig.isPresented = true
5959
await ghAuthenticator.waitForToken()
6060
}
6161
}

CCMenu/Source/Pipeline Window/PipelineListToolbar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct PipelineListToolbar: ToolbarContent {
5757

5858
Button() {
5959
let p = model.pipelines.first(where: { viewState.selection.contains($0.id) })
60-
viewState.editPipelineSheetConfig.pipeline = p
60+
viewState.editPipelineSheetConfig.setPipeline(p)
6161
viewState.editPipelineSheetConfig.isPresented = true
6262
} label: {
6363
Label("Edit", systemImage: "gearshape")

CCMenu/Source/Pipeline Window/PipelineListView.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class ListViewState: ObservableObject {
1212
@Published var addCCTrayPipelineSheetConfig = PipelineSheetConfig()
1313
@Published var addGitHubPipelineSheetConfig = PipelineSheetConfig()
1414
@Published var editPipelineSheetConfig = PipelineSheetConfig()
15-
@Published var isShowingSignInAtGitHubSheet: Bool = false
15+
@Published var signInAtGitHubSheetSheetConfig = PipelineSheetConfig()
1616
@Published var isShowingImporter: Bool = false
1717
@Published var isShowingExporter: Bool = false
1818
@Published var errorMessage: String? = nil
@@ -21,7 +21,6 @@ final class ListViewState: ObservableObject {
2121

2222
struct PipelineListView: View {
2323
@ObservedObject var model: PipelineModel
24-
@AppStorage(.showAppIcon) var showAppIcon: AppIconVisibility = .sometimes
2524
@AppStorage(.pollInterval) var pollInterval = 10
2625
@StateObject var viewState = ListViewState()
2726
@StateObject private var ghAuthenticator = GitHubAuthenticator()
@@ -75,15 +74,10 @@ struct PipelineListView: View {
7574
} content: {
7675
EditPipelineSheet(config: $viewState.editPipelineSheetConfig)
7776
}
78-
.sheet(isPresented: $viewState.isShowingSignInAtGitHubSheet) {
77+
.sheet(isPresented: $viewState.signInAtGitHubSheetSheetConfig.isPresented) {
7978
} content: {
8079
SignInAtGitHubSheet()
8180
}
82-
// .onChange(of: viewState.showSheet) { _ in
83-
// guard showAppIcon == .sometimes else { return }
84-
// NSApp.hideApplicationIcon(viewState.showSheet == .noSheet)
85-
// NSApp.activateThisApp()
86-
// }
8781
.fileImporter(isPresented: $viewState.isShowingImporter, allowedContentTypes: [.json]) { result in
8882
switch result {
8983
case .success(let fileurl):
@@ -106,12 +100,6 @@ struct PipelineListView: View {
106100
}
107101
.environmentObject(ghAuthenticator)
108102
}
109-
110-
private func showOrHideAppIcon(_ flag: Bool) {
111-
guard showAppIcon == .sometimes else { return }
112-
NSApp.hideApplicationIcon(!flag)
113-
NSApp.activateThisApp()
114-
}
115103

116104
}
117105

CCMenu/Source/Pipeline Window/PipelineSheetConfig.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@
44
* not use these files except in compliance with the License.
55
*/
66

7-
import Foundation
7+
import SwiftUI
88

99
struct PipelineSheetConfig {
10-
var isPresented: Bool = false
11-
var pipeline: Pipeline?
12-
10+
@AppStorage(.showAppIcon) var showAppIcon: AppIconVisibility = .sometimes
11+
var isPresented: Bool = false { didSet { setAppIconVisibility() } }
12+
var pipelines: [Pipeline] = []
13+
14+
15+
var pipeline: Pipeline? {
16+
return (pipelines.count == 1) ? pipelines[0] : nil
17+
}
18+
1319
mutating func setPipeline(_ pipeline: Pipeline?) {
14-
self.pipeline = pipeline
20+
self.pipelines.removeAll()
21+
if let pipeline {
22+
self.pipelines.append(pipeline)
23+
}
24+
}
25+
26+
func setAppIconVisibility() {
27+
guard showAppIcon == .sometimes else { return }
28+
NSApp.hideApplicationIcon(!isPresented)
29+
NSApp.activateThisApp()
1530
}
1631
}

0 commit comments

Comments
 (0)