From 3232c81e804141e0fe3fd1842e0f7767aa412d3b Mon Sep 17 00:00:00 2001 From: Alin Date: Tue, 18 Jun 2024 22:20:22 -0600 Subject: [PATCH] v3.7.4 --- Pearcleaner.xcodeproj/project.pbxproj | 8 +++--- Pearcleaner/Logic/AppCommands.swift | 28 ++++++++++++++++++++- Pearcleaner/Logic/AppState.swift | 1 + Pearcleaner/Logic/Utilities.swift | 35 ++++++++++++++++++++++++++- Pearcleaner/PearcleanerApp.swift | 3 +-- Pearcleaner/Views/FilesView.swift | 20 +++++++-------- 6 files changed, 77 insertions(+), 18 deletions(-) diff --git a/Pearcleaner.xcodeproj/project.pbxproj b/Pearcleaner.xcodeproj/project.pbxproj index 18d507c..f49a3ae 100644 --- a/Pearcleaner.xcodeproj/project.pbxproj +++ b/Pearcleaner.xcodeproj/project.pbxproj @@ -572,8 +572,8 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - APP_BUILD = 48; - APP_VERSION = 3.7.3; + APP_BUILD = 49; + APP_VERSION = 3.7.4; ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -642,8 +642,8 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - APP_BUILD = 48; - APP_VERSION = 3.7.3; + APP_BUILD = 49; + APP_VERSION = 3.7.4; ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; diff --git a/Pearcleaner/Logic/AppCommands.swift b/Pearcleaner/Logic/AppCommands.swift index 5021b48..b02450a 100644 --- a/Pearcleaner/Logic/AppCommands.swift +++ b/Pearcleaner/Logic/AppCommands.swift @@ -80,7 +80,33 @@ struct AppCommands: Commands { } - + + // Tools Menu + CommandMenu(Text("Tools", comment: "Tools Menu")) { + + Button + { + if !appState.appInfo.bundleIdentifier.isEmpty { + appState.showConditionBuilder = true + } + } label: { + Label("Condition Builder", systemImage: "hammer") + } + .keyboardShortcut("b", modifiers: .command) + + Button + { + if !appState.appInfo.bundleIdentifier.isEmpty { + saveURLsToFile(urls: appState.selectedItems, appState: appState) + } + } label: { + Label("Export Files", systemImage: "square.and.arrow.up") + } + .keyboardShortcut("e", modifiers: .command) + + + } + // GitHub Menu CommandMenu(Text("GitHub", comment: "Github Repo")) { diff --git a/Pearcleaner/Logic/AppState.swift b/Pearcleaner/Logic/AppState.swift index 2fab8d2..04fd5ea 100644 --- a/Pearcleaner/Logic/AppState.swift +++ b/Pearcleaner/Logic/AppState.swift @@ -33,6 +33,7 @@ class AppState: ObservableObject { @Published var permissionResults: PermissionsCheckResults? @Published var showUninstallAlert: Bool = false @Published var oneShotMode: Bool = false + @Published var showConditionBuilder: Bool = false diff --git a/Pearcleaner/Logic/Utilities.swift b/Pearcleaner/Logic/Utilities.swift index ecb4016..41f4ede 100644 --- a/Pearcleaner/Logic/Utilities.swift +++ b/Pearcleaner/Logic/Utilities.swift @@ -185,7 +185,40 @@ func caskCleanup(app: String) { process.waitUntilExit() // Ensure the process completes let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = (String(data: data, encoding: .utf8) ?? "") as String - print(output) + printOS(output) + } +} + + +// Print list of files locally +func saveURLsToFile(urls: Set, appState: AppState) { + let panel = NSOpenPanel() + panel.canChooseFiles = false + panel.canChooseDirectories = true + panel.allowsMultipleSelection = false + panel.prompt = "Select Folder" + + if panel.runModal() == .OK, let selectedFolder = panel.url { + let filePath = selectedFolder.appendingPathComponent("Export-\(appState.appInfo.appName)(v\(appState.appInfo.appVersion)).txt") + var fileContent = "" + var count = 1 + let sortedUrls = urls.sorted { $0.path < $1.path } + + for url in sortedUrls { + fileContent += "[\(count)] - \(url.path)\n" + count += 1 + } + + do { + try fileContent.write(to: filePath, atomically: true, encoding: .utf8) + printOS("File saved successfully at \(filePath.path)") + // Open Finder and select the file + NSWorkspace.shared.selectFile(filePath.path, inFileViewerRootedAtPath: filePath.deletingLastPathComponent().path) + } catch { + printOS("Error saving file: \(error)") + } + } else { + printOS("Folder selection was canceled.") } } diff --git a/Pearcleaner/PearcleanerApp.swift b/Pearcleaner/PearcleanerApp.swift index af831f1..0e67060 100644 --- a/Pearcleaner/PearcleanerApp.swift +++ b/Pearcleaner/PearcleanerApp.swift @@ -126,8 +126,7 @@ struct PearcleanerApp: App { } // Get new features getFeatures(appState: appState, features: $features) - // Load extra conditions from GitHub -// loadConditionsFromGitHub() // REPLACE THIS WITH NEW CONDITION MANAGER + } } diff --git a/Pearcleaner/Views/FilesView.swift b/Pearcleaner/Views/FilesView.swift index cd8040c..49204f3 100644 --- a/Pearcleaner/Views/FilesView.swift +++ b/Pearcleaner/Views/FilesView.swift @@ -20,7 +20,7 @@ struct FilesView: View { @AppStorage("settings.general.sizeType") var sizeType: String = "Real" @AppStorage("settings.general.filesWarning") private var warning: Bool = false @State private var showAlert = false - @State private var showConditionBuilder = false +// @State private var showConditionBuilder = false @Environment(\.colorScheme) var colorScheme @Binding var showPopover: Bool @Binding var search: String @@ -278,12 +278,12 @@ struct FilesView: View { .padding(.top) - Button("Builder") { - showConditionBuilder = true - } - .buttonStyle(SimpleButtonStyle(icon: "hammer.fill", help: "Condition Builder", size: 14)) - .padding(.top) - .padding(.trailing, 5) +// Button("Builder") { +// appState.showConditionBuilder = true +// } +// .buttonStyle(SimpleButtonStyle(icon: "hammer.fill", help: "Condition Builder", size: 14)) +// .padding(.top) +// .padding(.trailing, 5) Button("\(sizeType == "Logical" ? totalSelectedSize.logical : sizeType == "Finder" ? totalSelectedSize.finder : totalSelectedSize.real)") { @@ -395,11 +395,11 @@ struct FilesView: View { Spacer() } .padding(15) - .frame(width: 400, height: 200) + .frame(width: 400, height: 220) .background(GlassEffect(material: .hudWindow, blendingMode: .behindWindow)) }) - .sheet(isPresented: $showConditionBuilder, content: { - ConditionBuilderView(showAlert: $showConditionBuilder, bundle: appState.appInfo.bundleIdentifier) + .sheet(isPresented: $appState.showConditionBuilder, content: { + ConditionBuilderView(showAlert: $appState.showConditionBuilder, bundle: appState.appInfo.bundleIdentifier) }) .onAppear { if !warning {