Skip to content

Commit

Permalink
Change path debounce
Browse files Browse the repository at this point in the history
Use the DebouncedOnChange package instead of a Combine based approach
  • Loading branch information
milanvarady committed Jan 1, 2025
1 parent 34ab366 commit a5d1c29
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
21 changes: 17 additions & 4 deletions Applite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 */; };
Expand Down Expand Up @@ -144,7 +144,6 @@
4140750428DF5FA60073EB22 /* AppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppView.swift; sourceTree = "<group>"; };
41483CCC29101C9900BB10C2 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = "<group>"; };
41524B98295E352200D0046A /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
41524B9D295FA36E00D0046A /* DebounceObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebounceObject.swift; sourceTree = "<group>"; };
415563A12A98BB2500AE2F2E /* ErrorWindowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorWindowView.swift; sourceTree = "<group>"; };
415563A32A98C54300AE2F2E /* AppdirSelectorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppdirSelectorView.swift; sourceTree = "<group>"; };
4166EE6F28F5D4C900CE305A /* Commands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Commands.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -452,7 +452,6 @@
isa = PBXGroup;
children = (
41062C942A3794EA00FD48EA /* BrewPaths.swift */,
41524B9D295FA36E00D0046A /* DebounceObject.swift */,
41DF006329EAA094004EB7AE /* SendNotification.swift */,
41062C962A3A20F900FD48EA /* UninstallSelf.swift */,
);
Expand Down Expand Up @@ -675,6 +674,7 @@
4129FFD82A7A613E00CFE392 /* Fuse */,
418E9EF32AACD9C000046A58 /* CircularProgress */,
413E60BF2BBF0E5C00978F6A /* Kingfisher */,
419256B12D26033400D9EF10 /* DebouncedOnChange */,
);
productName = Applite;
productReference = 414074F128DF53E80073EB22 /* Applite.app */;
Expand Down Expand Up @@ -714,6 +714,7 @@
4129FFD72A7A613E00CFE392 /* XCRemoteSwiftPackageReference "fuse-swift" */,
418E9EF22AACD9C000046A58 /* XCRemoteSwiftPackageReference "CircularProgressSwiftUI" */,
413E60BE2BBF0E5C00978F6A /* XCRemoteSwiftPackageReference "Kingfisher" */,
419256B02D26033400D9EF10 /* XCRemoteSwiftPackageReference "DebouncedOnChange" */,
);
productRefGroup = 414074F228DF53E80073EB22 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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" */;
Expand Down
1 change: 0 additions & 1 deletion Applite/Utilities/Network Proxy/NetworkProxyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ struct NetworkProxyManager {
let preferredProxyType: NetworkProxyType? = NetworkProxyType(rawValue: preferredProxyTypeString)

if !proxyEnabled {
Self.logger.info("Proxy disabled by user")
throw NetworkProxyError.proxyNotEnabled
}

Expand Down
28 changes: 0 additions & 28 deletions Applite/Utilities/Other/DebounceObject.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down

0 comments on commit a5d1c29

Please sign in to comment.