diff --git a/Applite.xcodeproj/project.pbxproj b/Applite.xcodeproj/project.pbxproj index b5a3b87..afc0cad 100644 --- a/Applite.xcodeproj/project.pbxproj +++ b/Applite.xcodeproj/project.pbxproj @@ -30,7 +30,6 @@ 4140750528DF5FA60073EB22 /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4140750428DF5FA60073EB22 /* AppView.swift */; }; 41483CCD29101C9900BB10C2 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41483CCC29101C9900BB10C2 /* Category.swift */; }; 41524B99295E352200D0046A /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41524B98295E352200D0046A /* SettingsView.swift */; }; - 41524B9E295FA36E00D0046A /* DebounceObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41524B9D295FA36E00D0046A /* DebounceObject.swift */; }; 415563A22A98BB2500AE2F2E /* ErrorWindowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 415563A12A98BB2500AE2F2E /* ErrorWindowView.swift */; }; 415563A42A98C54300AE2F2E /* AppdirSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 415563A32A98C54300AE2F2E /* AppdirSelectorView.swift */; }; 4166EE7028F5D4C900CE305A /* Commands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4166EE6F28F5D4C900CE305A /* Commands.swift */; }; @@ -108,6 +107,7 @@ 419256AB2D25E19B00D9EF10 /* BrewManagementView+ActionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419256AA2D25E19B00D9EF10 /* BrewManagementView+ActionsView.swift */; }; 419256AD2D25E1F100D9EF10 /* BrewManagementView+InfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419256AC2D25E1F100D9EF10 /* BrewManagementView+InfoView.swift */; }; 419256AF2D25F68700D9EF10 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419256AE2D25F68700D9EF10 /* AppDelegate.swift */; }; + 419256B22D26033400D9EF10 /* DebouncedOnChange in Frameworks */ = {isa = PBXBuildFile; productRef = 419256B12D26033400D9EF10 /* DebouncedOnChange */; }; 419506A42964A27F00FE5802 /* SetupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419506A32964A27F00FE5802 /* SetupView.swift */; }; 419506A62964A5EF00FE5802 /* BrewPathSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 419506A52964A5EF00FE5802 /* BrewPathSelectorView.swift */; }; 4196C8F528F9CB2600EADDDA /* DiscoverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4196C8F428F9CB2600EADDDA /* DiscoverView.swift */; }; @@ -144,7 +144,6 @@ 4140750428DF5FA60073EB22 /* AppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppView.swift; sourceTree = ""; }; 41483CCC29101C9900BB10C2 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = ""; }; 41524B98295E352200D0046A /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; - 41524B9D295FA36E00D0046A /* DebounceObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebounceObject.swift; sourceTree = ""; }; 415563A12A98BB2500AE2F2E /* ErrorWindowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorWindowView.swift; sourceTree = ""; }; 415563A32A98C54300AE2F2E /* AppdirSelectorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppdirSelectorView.swift; sourceTree = ""; }; 4166EE6F28F5D4C900CE305A /* Commands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Commands.swift; sourceTree = ""; }; @@ -239,6 +238,7 @@ buildActionMask = 2147483647; files = ( 41C8FA292A7A598B000BB9A2 /* Sparkle in Frameworks */, + 419256B22D26033400D9EF10 /* DebouncedOnChange in Frameworks */, 4189CE392937CD41009C836D /* Shimmer in Frameworks */, 418E9EF42AACD9C000046A58 /* CircularProgress in Frameworks */, 4129FFD92A7A613E00CFE392 /* Fuse in Frameworks */, @@ -452,7 +452,6 @@ isa = PBXGroup; children = ( 41062C942A3794EA00FD48EA /* BrewPaths.swift */, - 41524B9D295FA36E00D0046A /* DebounceObject.swift */, 41DF006329EAA094004EB7AE /* SendNotification.swift */, 41062C962A3A20F900FD48EA /* UninstallSelf.swift */, ); @@ -675,6 +674,7 @@ 4129FFD82A7A613E00CFE392 /* Fuse */, 418E9EF32AACD9C000046A58 /* CircularProgress */, 413E60BF2BBF0E5C00978F6A /* Kingfisher */, + 419256B12D26033400D9EF10 /* DebouncedOnChange */, ); productName = Applite; productReference = 414074F128DF53E80073EB22 /* Applite.app */; @@ -714,6 +714,7 @@ 4129FFD72A7A613E00CFE392 /* XCRemoteSwiftPackageReference "fuse-swift" */, 418E9EF22AACD9C000046A58 /* XCRemoteSwiftPackageReference "CircularProgressSwiftUI" */, 413E60BE2BBF0E5C00978F6A /* XCRemoteSwiftPackageReference "Kingfisher" */, + 419256B02D26033400D9EF10 /* XCRemoteSwiftPackageReference "DebouncedOnChange" */, ); productRefGroup = 414074F228DF53E80073EB22 /* Products */; projectDirPath = ""; @@ -788,7 +789,6 @@ 4192561E2D1DEBE700D9EF10 /* AppView+UninstallButton.swift in Sources */, 4192569B2D24335900D9EF10 /* CaskTaskError.swift in Sources */, 41524B99295E352200D0046A /* SettingsView.swift in Sources */, - 41524B9E295FA36E00D0046A /* DebounceObject.swift in Sources */, 419256292D1DF1CF00D9EF10 /* SetupView+BrewPathSelection.swift in Sources */, 415563A22A98BB2500AE2F2E /* ErrorWindowView.swift in Sources */, 4196C8FE28F9E13600EADDDA /* UpdateView.swift in Sources */, @@ -1098,6 +1098,14 @@ minimumVersion = 1.2.1; }; }; + 419256B02D26033400D9EF10 /* XCRemoteSwiftPackageReference "DebouncedOnChange" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Tunous/DebouncedOnChange"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.0.0; + }; + }; 41C8FA272A7A598B000BB9A2 /* XCRemoteSwiftPackageReference "Sparkle" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/sparkle-project/Sparkle"; @@ -1129,6 +1137,11 @@ package = 418E9EF22AACD9C000046A58 /* XCRemoteSwiftPackageReference "CircularProgressSwiftUI" */; productName = CircularProgress; }; + 419256B12D26033400D9EF10 /* DebouncedOnChange */ = { + isa = XCSwiftPackageProductDependency; + package = 419256B02D26033400D9EF10 /* XCRemoteSwiftPackageReference "DebouncedOnChange" */; + productName = DebouncedOnChange; + }; 41C8FA282A7A598B000BB9A2 /* Sparkle */ = { isa = XCSwiftPackageProductDependency; package = 41C8FA272A7A598B000BB9A2 /* XCRemoteSwiftPackageReference "Sparkle" */; diff --git a/Applite/Utilities/Network Proxy/NetworkProxyManager.swift b/Applite/Utilities/Network Proxy/NetworkProxyManager.swift index c7e7534..cef654c 100644 --- a/Applite/Utilities/Network Proxy/NetworkProxyManager.swift +++ b/Applite/Utilities/Network Proxy/NetworkProxyManager.swift @@ -23,7 +23,6 @@ struct NetworkProxyManager { let preferredProxyType: NetworkProxyType? = NetworkProxyType(rawValue: preferredProxyTypeString) if !proxyEnabled { - Self.logger.info("Proxy disabled by user") throw NetworkProxyError.proxyNotEnabled } diff --git a/Applite/Utilities/Other/DebounceObject.swift b/Applite/Utilities/Other/DebounceObject.swift deleted file mode 100755 index ef11499..0000000 --- a/Applite/Utilities/Other/DebounceObject.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// DebounceObject.swift -// Applite -// -// Created by Milán Várady on 2022. 12. 30.. -// - -import Foundation -import Combine - -/// Debounces a changing `String` and only publishes it when it stops changing for a predetermined time. Used in text fields. -/// -/// Got this from https://onmyway133.com/posts/how-to-debounce-textfield-search-in-swiftui/ -final public class DebounceObject: ObservableObject { - @Published var text: String = "" - @Published var debouncedText: String = "" - private var bag = Set() - - public init(dueTime: TimeInterval = 0.5) { - $text - .removeDuplicates() - .debounce(for: .seconds(dueTime), scheduler: DispatchQueue.main) - .sink(receiveValue: { [weak self] value in - self?.debouncedText = value - }) - .store(in: &bag) - } -} diff --git a/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView+CustomPathOption.swift b/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView+CustomPathOption.swift index 53a360a..261ecb7 100644 --- a/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView+CustomPathOption.swift +++ b/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView+CustomPathOption.swift @@ -13,7 +13,7 @@ extension BrewPathSelectorView { pathOption(option, showPath: false) HStack { - TextField("Custom brew path", text: $customBrewPathDebounced.text, prompt: Text("/path/to/brew")) + TextField("Custom brew path", text: $customUserBrewPath, prompt: Text("/path/to/brew")) .textFieldStyle(.roundedBorder) .frame(maxWidth: 300) .autocorrectionDisabled() @@ -27,7 +27,7 @@ extension BrewPathSelectorView { ) { result in switch result { case .success(let file): - customBrewPathDebounced.text = file.path + customUserBrewPath = file.path(percentEncoded: false) case .failure(let error): print(error.localizedDescription) } diff --git a/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView.swift b/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView.swift index f44768d..9724164 100755 --- a/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView.swift +++ b/Applite/Views/Components/Brew Path Selector/BrewPathSelectorView.swift @@ -6,13 +6,12 @@ // import SwiftUI +import DebouncedOnChange /// 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 @@ -36,15 +35,12 @@ struct BrewPathSelectorView: View { .task { isSelectedPathValid = await BrewPaths.isSelectedBrewPathValid() } - .onAppear { - customBrewPathDebounced.text = customUserBrewPath - } .onChange(of: brewPathOption) { _ in Task { @MainActor in isSelectedPathValid = await BrewPaths.isSelectedBrewPathValid() } } - .onChange(of: customBrewPathDebounced.debouncedText) { newPath in + .onChange(of: customUserBrewPath, debounceTime: .seconds(0.5)) { newPath in customUserBrewPath = newPath if brewPathOption == BrewPaths.PathOption.custom.rawValue {