Skip to content

Commit

Permalink
Made sheet config more useful and changed GitHub sign in to use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdoe committed May 4, 2024
1 parent 6290613 commit 39d962a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CCMenu/Source/Pipeline Window/EditPipelineSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ struct EditPipelineSheet: View {
}
.keyboardShortcut(.cancelAction)
Button("Apply") {
config.pipeline?.name = name
if var p = config.pipeline {
p.name = name
config.setPipeline(p)
}
presentation.dismiss()
}
.keyboardShortcut(.defaultAction)
Expand Down
4 changes: 2 additions & 2 deletions CCMenu/Source/Pipeline Window/PipelineListMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct PipelineListMenu: View {
Divider()
Button("Edit...") {
let p = model.pipelines.first(where: { viewState.selection.contains($0.id) })
viewState.editPipelineSheetConfig.pipeline = p
viewState.editPipelineSheetConfig.setPipeline(p)
viewState.editPipelineSheetConfig.isPresented = true
}
.disabled(contextSelection.count != 1)
Expand All @@ -55,7 +55,7 @@ struct PipelineListMenu: View {
Button("Sign In at GitHub...") {
Task {
if await ghAuthenticator.signInAtGitHub() {
viewState.isShowingSignInAtGitHubSheet = true
viewState.signInAtGitHubSheetSheetConfig.isPresented = true
await ghAuthenticator.waitForToken()
}
}
Expand Down
2 changes: 1 addition & 1 deletion CCMenu/Source/Pipeline Window/PipelineListToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct PipelineListToolbar: ToolbarContent {

Button() {
let p = model.pipelines.first(where: { viewState.selection.contains($0.id) })
viewState.editPipelineSheetConfig.pipeline = p
viewState.editPipelineSheetConfig.setPipeline(p)
viewState.editPipelineSheetConfig.isPresented = true
} label: {
Label("Edit", systemImage: "gearshape")
Expand Down
16 changes: 2 additions & 14 deletions CCMenu/Source/Pipeline Window/PipelineListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class ListViewState: ObservableObject {
@Published var addCCTrayPipelineSheetConfig = PipelineSheetConfig()
@Published var addGitHubPipelineSheetConfig = PipelineSheetConfig()
@Published var editPipelineSheetConfig = PipelineSheetConfig()
@Published var isShowingSignInAtGitHubSheet: Bool = false
@Published var signInAtGitHubSheetSheetConfig = PipelineSheetConfig()
@Published var isShowingImporter: Bool = false
@Published var isShowingExporter: Bool = false
@Published var errorMessage: String? = nil
Expand All @@ -21,7 +21,6 @@ final class ListViewState: ObservableObject {

struct PipelineListView: View {
@ObservedObject var model: PipelineModel
@AppStorage(.showAppIcon) var showAppIcon: AppIconVisibility = .sometimes
@AppStorage(.pollInterval) var pollInterval = 10
@StateObject var viewState = ListViewState()
@StateObject private var ghAuthenticator = GitHubAuthenticator()
Expand Down Expand Up @@ -75,15 +74,10 @@ struct PipelineListView: View {
} content: {
EditPipelineSheet(config: $viewState.editPipelineSheetConfig)
}
.sheet(isPresented: $viewState.isShowingSignInAtGitHubSheet) {
.sheet(isPresented: $viewState.signInAtGitHubSheetSheetConfig.isPresented) {
} content: {
SignInAtGitHubSheet()
}
// .onChange(of: viewState.showSheet) { _ in
// guard showAppIcon == .sometimes else { return }
// NSApp.hideApplicationIcon(viewState.showSheet == .noSheet)
// NSApp.activateThisApp()
// }
.fileImporter(isPresented: $viewState.isShowingImporter, allowedContentTypes: [.json]) { result in
switch result {
case .success(let fileurl):
Expand All @@ -106,12 +100,6 @@ struct PipelineListView: View {
}
.environmentObject(ghAuthenticator)
}

private func showOrHideAppIcon(_ flag: Bool) {
guard showAppIcon == .sometimes else { return }
NSApp.hideApplicationIcon(!flag)
NSApp.activateThisApp()
}

}

Expand Down
25 changes: 20 additions & 5 deletions CCMenu/Source/Pipeline Window/PipelineSheetConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@
* not use these files except in compliance with the License.
*/

import Foundation
import SwiftUI

struct PipelineSheetConfig {
var isPresented: Bool = false
var pipeline: Pipeline?

@AppStorage(.showAppIcon) var showAppIcon: AppIconVisibility = .sometimes
var isPresented: Bool = false { didSet { setAppIconVisibility() } }
var pipelines: [Pipeline] = []


var pipeline: Pipeline? {
return (pipelines.count == 1) ? pipelines[0] : nil
}

mutating func setPipeline(_ pipeline: Pipeline?) {
self.pipeline = pipeline
self.pipelines.removeAll()
if let pipeline {
self.pipelines.append(pipeline)
}
}

func setAppIconVisibility() {
guard showAppIcon == .sometimes else { return }
NSApp.hideApplicationIcon(!isPresented)
NSApp.activateThisApp()
}
}

0 comments on commit 39d962a

Please sign in to comment.