Skip to content

Commit

Permalink
BundleSetting.url -> BundleSetting.path
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jan 14, 2025
1 parent 6a74265 commit 1f7f53a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/TrueWidget/swift/UserSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct TimeZoneTimeSetting: Identifiable, Codable {
struct BundleSetting: Identifiable, Codable {
var id = UUID().uuidString
var show = false
var url: URL?
var path = ""
}

final class UserSettings: ObservableObject {
Expand Down Expand Up @@ -136,7 +136,7 @@ final class UserSettings: ObservableObject {
if bundleSettings.isEmpty {
bundleSettings.append(
BundleSetting(
url: URL(filePath: "/Applications/TrueWidget.app")
path: "/Applications/TrueWidget.app"
))
} else {
bundleSettings.append(BundleSetting())
Expand Down
16 changes: 10 additions & 6 deletions src/TrueWidget/swift/Views/BundlePickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import SwiftUI
import UniformTypeIdentifiers

struct BundlePickerView: View {
@Binding private(set) var selectedFileURL: URL?
@Binding private(set) var path: String

@State private var isPickingFile = false
@State private var errorMessage: String?

init(path: Binding<String>) {
self._path = path
}

var body: some View {
HStack {
VStack(alignment: .leading) {
Text("\(selectedFileURL?.path ?? "---")")
Text("\(path.isEmpty ? "---" : path)")
.fixedSize(horizontal: false, vertical: true)

if let error = errorMessage {
Expand All @@ -33,24 +37,24 @@ struct BundlePickerView: View {
if let url = try? result.get().first {
HelperClient.shared.proxy?.bundleVersions(paths: [url.path]) { versions in
if versions[url.path] != nil {
selectedFileURL = url
path = url.path
errorMessage = nil
} else {
selectedFileURL = nil
path = ""
errorMessage = "Could not get the version of the selected file"
}
}
return
}

selectedFileURL = nil
path = ""
errorMessage = "File selection failed"
}

Button(
role: .destructive,
action: {
selectedFileURL = nil
path = ""
errorMessage = nil
},
label: {
Expand Down
2 changes: 1 addition & 1 deletion src/TrueWidget/swift/Views/Main/MainBundleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct MainBundleView: View {
VStack(alignment: .trailing, spacing: 0) {
ForEach(userSettings.bundleSettings) { setting in
if setting.show {
if let version = bundle.bundleVersions[setting.url?.path ?? ""] {
if let version = bundle.bundleVersions[setting.path] {
Text("\(version["name"] ?? "---"): \(version["version"] ?? "---")")
.fixedSize(horizontal: false, vertical: true)
.multilineTextAlignment(.trailing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct SettingsBundleView: View {
}
.switchToggleStyle()

BundlePickerView(selectedFileURL: setting.url)
BundlePickerView(path: setting.path)
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/TrueWidget/swift/WidgetSource/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ extension WidgetSource {
@MainActor
private func update() {
HelperClient.shared.proxy?.bundleVersions(
paths: userSettings.bundleSettings.filter({ $0.show && $0.url != nil }).map({
$0.url?.path ?? ""
})
paths: userSettings.bundleSettings.filter({ $0.show && !$0.path.isEmpty }).map({ $0.path })
) { versions in
Task { @MainActor in
self.bundleVersions = versions
Expand Down

0 comments on commit 1f7f53a

Please sign in to comment.