From 30c6f301bdc7267a9720427a17d8c83f73eec8fa Mon Sep 17 00:00:00 2001 From: ohaiibuzzle <23693150+ohaiibuzzle@users.noreply.github.com> Date: Thu, 15 Jun 2023 21:56:34 +0700 Subject: [PATCH] feat: make bottle paths look pretty --- Harbor/Extensions/URLExtensions.swift | 27 +++++++++++++++++++++++++ Harbor/Views/BottleManagementView.swift | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Harbor/Extensions/URLExtensions.swift diff --git a/Harbor/Extensions/URLExtensions.swift b/Harbor/Extensions/URLExtensions.swift new file mode 100644 index 0000000..1f447ea --- /dev/null +++ b/Harbor/Extensions/URLExtensions.swift @@ -0,0 +1,27 @@ +// +// URLExtensions.swift +// Harbor +// +// Created by Venti on 15/06/2023. +// + +import Foundation + +extension URL { + var prettyFileUrl: String { + if !self.isFileURL { + return self.absoluteString + } + guard var prettyPath = self.path.removingPercentEncoding else { + return self.path + } + + if path.hasPrefix("/Users") { + // Remove /Users/ and replace with ~ + prettyPath = prettyPath.replacingOccurrences(of: #"/Users/[^/]+/"#, + with: "~/", options: .regularExpression) + } + + return prettyPath + } +} diff --git a/Harbor/Views/BottleManagementView.swift b/Harbor/Views/BottleManagementView.swift index 9ab70fa..9548d25 100644 --- a/Harbor/Views/BottleManagementView.swift +++ b/Harbor/Views/BottleManagementView.swift @@ -30,7 +30,7 @@ struct BottleManagementView: View { Table(bottles, selection: $selectedBottle, sortOrder: $sortOrder) { TableColumn("home.table.name", value: \.name) - TableColumn("home.table.path", value: \.path.relativeString) + TableColumn("home.table.path", value: \.path.prettyFileUrl) TableColumn("home.table.primaryApp", value: \.primaryApplicationPath) } .padding() @@ -100,7 +100,7 @@ struct BottleManagementView: View { alert.alertStyle = .critical let checkbox = NSButton(checkboxWithTitle: String(format: String(localized: "home.alert.deletePath %@"), - thisBottle.path.absoluteString), target: nil, action: nil) + thisBottle.path.prettyFileUrl), target: nil, action: nil) checkbox.state = .on alert.accessoryView = checkbox alert.addButton(withTitle: String(localized: "btn.delete"))