-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break up huge view files into smaller files
- Loading branch information
1 parent
1161418
commit 19e4dd1
Showing
49 changed files
with
1,986 additions
and
1,530 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Applite/Utilities/Alert Manager/AlertManagerViewModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// AlertManagerViewModifier.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2024.12.27. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct AlertModifier: ViewModifier { | ||
@ObservedObject var manager: AlertManager | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.alert(manager.title, isPresented: $manager.isPresented) { | ||
Button(manager.primaryButtonTitle) { | ||
manager.primaryAction?() | ||
manager.dismiss() | ||
} | ||
|
||
// Add cancel button if we have a primary action | ||
if manager.primaryAction != nil { | ||
Button("Cancel", role: .cancel) { | ||
manager.dismiss() | ||
} | ||
} | ||
} message: { | ||
Text(manager.message) | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func alertManager(_ manager: AlertManager) -> some View { | ||
modifier(AlertModifier(manager: manager)) | ||
} | ||
} |
File renamed without changes.
39 changes: 39 additions & 0 deletions
39
Applite/Views/Components/Brew Path Selector/BrewPathSelectorView+CustomPathOption.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// BrewPathSelectorView+CustomPathOption.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2024.12.26. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension BrewPathSelectorView { | ||
func customPathOption(option: BrewPaths.PathOption) -> some View { | ||
VStack(alignment: .leading, spacing: 5) { | ||
pathOption(option, showPath: false) | ||
|
||
HStack { | ||
TextField("Custom brew path", text: $customBrewPathDebounced.text, prompt: Text("/path/to/brew")) | ||
.textFieldStyle(.roundedBorder) | ||
.frame(maxWidth: 300) | ||
.autocorrectionDisabled() | ||
|
||
Button("Browse") { | ||
choosingCustomFolder = true | ||
} | ||
.fileImporter( | ||
isPresented: $choosingCustomFolder, | ||
allowedContentTypes: [.unixExecutable] | ||
) { result in | ||
switch result { | ||
case .success(let file): | ||
customBrewPathDebounced.text = file.path | ||
case .failure(let error): | ||
print(error.localizedDescription) | ||
} | ||
} | ||
} | ||
.disabled(brewPathOption != BrewPaths.PathOption.custom.rawValue) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Applite/Views/Components/Brew Path Selector/BrewPathSelectorView+GetPathDescription.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// BrewPathSelectorView+GetPathDescription.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2024.12.26. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension BrewPathSelectorView { | ||
func getPathDescription(for option: BrewPaths.PathOption) -> String { | ||
switch option { | ||
case .appPath: | ||
return "\(Bundle.main.appName)'s installation" | ||
|
||
case .defaultAppleSilicon: | ||
return "Apple Silicon Mac" | ||
|
||
case .defaultIntel: | ||
return "Intel Mac" | ||
|
||
case .custom: | ||
return "Custom" | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Applite/Views/Components/Brew Path Selector/BrewPathSelectorView+PathOption.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// BrewPathSelectorView+PathOption.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2024.12.26. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension BrewPathSelectorView { | ||
func pathOption(_ option: BrewPaths.PathOption, showPath: Bool = true) -> some View { | ||
HStack { | ||
Text("\(getPathDescription(for: option))") | ||
|
||
if showPath { | ||
Text("(\(BrewPaths.getBrewExectuablePath(for: option, shellFriendly: false)))") | ||
.truncationMode(.middle) | ||
.lineLimit(1) | ||
.foregroundColor(.gray) | ||
} | ||
|
||
if option.rawValue == brewPathOption { | ||
if isSelectedPathValid { | ||
Image(systemName: "checkmark.circle") | ||
.font(.system(size: 16)) | ||
.foregroundColor(.green) | ||
} else { | ||
Image(systemName: "xmark.circle") | ||
.font(.system(size: 16)) | ||
.foregroundColor(.red) | ||
} | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Applite/Views/Components/Brew Path Selector/BrewPathSelectorView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// BrewPathSelectorView.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2023. 01. 03.. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Provides a picker so the user can select the brew executable path they want to use | ||
struct BrewPathSelectorView: View { | ||
@Binding var isSelectedPathValid: Bool | ||
|
||
@StateObject var customBrewPathDebounced = DebounceObject() | ||
|
||
@AppStorage(Preferences.customUserBrewPath.rawValue) var customUserBrewPath: String = BrewPaths.getBrewExectuablePath(for: .defaultAppleSilicon, shellFriendly: false) | ||
@AppStorage(Preferences.brewPathOption.rawValue) var brewPathOption = BrewPaths.PathOption.defaultAppleSilicon.rawValue | ||
|
||
@State var choosingCustomFolder = false | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
Picker("", selection: $brewPathOption) { | ||
ForEach(BrewPaths.PathOption.allCases) { option in | ||
if option != .custom { | ||
pathOption(option) | ||
.tag(option.rawValue) | ||
} else { | ||
customPathOption(option: option) | ||
.tag(option.rawValue) | ||
} | ||
} | ||
} | ||
.pickerStyle(.radioGroup) | ||
} | ||
.onAppear { | ||
customBrewPathDebounced.text = customUserBrewPath | ||
isSelectedPathValid = BrewPaths.isSelectedBrewPathValid() | ||
} | ||
.onChange(of: brewPathOption) { _ in | ||
isSelectedPathValid = BrewPaths.isSelectedBrewPathValid() | ||
} | ||
.onChange(of: customBrewPathDebounced.debouncedText) { newPath in | ||
customUserBrewPath = newPath | ||
|
||
if brewPathOption == BrewPaths.PathOption.custom.rawValue { | ||
isSelectedPathValid = isBrewPathValid(path: newPath) | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct BrewPathSelectorView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
BrewPathSelectorView(isSelectedPathValid: .constant(false)) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.