From 5f44651b60931edc28e79d193c104adcea894f6a Mon Sep 17 00:00:00 2001 From: Alin Date: Wed, 24 Jan 2024 15:42:49 -0700 Subject: [PATCH] v2.4 --- Pearcleaner.xcodeproj/project.pbxproj | 8 +++---- Pearcleaner/Logic/DeepLink.swift | 20 ++++++++++++++--- Pearcleaner/Logic/Logic.swift | 8 ++++++- Pearcleaner/Logic/Utilities.swift | 3 ++- Pearcleaner/PearcleanerApp.swift | 4 ++-- Pearcleaner/Settings/General.swift | 32 +++++++++++++++++++++++---- Pearcleaner/Views/FilesView.swift | 4 ++++ Pearcleaner/Views/MiniMode.swift | 9 ++++---- Pearcleaner/Views/TopBarMini.swift | 2 ++ 9 files changed, 71 insertions(+), 19 deletions(-) diff --git a/Pearcleaner.xcodeproj/project.pbxproj b/Pearcleaner.xcodeproj/project.pbxproj index 913993a..8838474 100644 --- a/Pearcleaner.xcodeproj/project.pbxproj +++ b/Pearcleaner.xcodeproj/project.pbxproj @@ -543,7 +543,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BK8443AXLU; @@ -561,7 +561,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 2.3; + MARKETING_VERSION = 2.4; PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -578,7 +578,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BK8443AXLU; @@ -596,7 +596,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 2.3; + MARKETING_VERSION = 2.4; PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/Pearcleaner/Logic/DeepLink.swift b/Pearcleaner/Logic/DeepLink.swift index 76ff08a..e39324c 100644 --- a/Pearcleaner/Logic/DeepLink.swift +++ b/Pearcleaner/Logic/DeepLink.swift @@ -9,7 +9,13 @@ import Foundation import SwiftUI class DeeplinkManager { - + @Binding var showPopover: Bool + @AppStorage("settings.general.mini") private var mini: Bool = false + + init(showPopover: Binding) { + _showPopover = showPopover + } + class DeepLinkConstants { static let scheme = "pear" static let host = "com.alienator88.Pearcleaner" @@ -29,7 +35,11 @@ class DeeplinkManager { updateOnMain { appState.appInfo = appInfo! findPathsForApp(appState: appState, appInfo: appState.appInfo) - appState.currentView = .files + if self.mini { + self.showPopover = true + } else { + appState.currentView = .files + } } } else { print("No path query parameter found in the URL") @@ -67,7 +77,11 @@ class DeeplinkManager { updateOnMain { appState.appInfo = appInfo! findPathsForApp(appState: appState, appInfo: appState.appInfo) - appState.currentView = .files + if self.mini { + self.showPopover = true + } else { + appState.currentView = .files + } } } diff --git a/Pearcleaner/Logic/Logic.swift b/Pearcleaner/Logic/Logic.swift index 84f9792..1b5da0c 100644 --- a/Pearcleaner/Logic/Logic.swift +++ b/Pearcleaner/Logic/Logic.swift @@ -382,6 +382,7 @@ func findPathsForApp(appState: AppState, appInfo: AppInfo) { func getGroupContainers(bundleURL: URL) -> [URL] { + let fileManager = FileManager.default var staticCode: SecStaticCode? @@ -406,13 +407,18 @@ func getGroupContainers(bundleURL: URL) -> [URL] { } let groupContainersPath = appGroups.map { URL(fileURLWithPath: "\(home)/Library/Group Containers/" + $0) } + let existingGroupContainers = groupContainersPath.filter { fileManager.fileExists(atPath: $0.path) } - return groupContainersPath + return existingGroupContainers } // Move files to trash using applescript/Finder so it asks for user password if needed func moveFilesToTrash(at fileURLs: [URL], completion: @escaping () -> Void = {}) { + @AppStorage("settings.sentinel.enable") var sentinel: Bool = false + if sentinel { + launchctl(load: false) + } updateOnBackground { let posixFiles = fileURLs.map { "POSIX file \"\($0.path)\", " }.joined().dropLast(3) let scriptSource = """ diff --git a/Pearcleaner/Logic/Utilities.swift b/Pearcleaner/Logic/Utilities.swift index 7c1e39b..3af9f07 100644 --- a/Pearcleaner/Logic/Utilities.swift +++ b/Pearcleaner/Logic/Utilities.swift @@ -283,7 +283,8 @@ func totalSizeOnDisk(for paths: [URL]) -> String? { } let pipe = Pipe() process.standardOutput = pipe - + process.standardError = FileHandle.nullDevice + try? process.run() process.waitUntilExit() diff --git a/Pearcleaner/PearcleanerApp.swift b/Pearcleaner/PearcleanerApp.swift index 6aa80eb..4590600 100644 --- a/Pearcleaner/PearcleanerApp.swift +++ b/Pearcleaner/PearcleanerApp.swift @@ -41,14 +41,14 @@ struct PearcleanerApp: App { .alert(isPresented: $appState.showAlert) { presentAlert(appState: appState) } .handlesExternalEvents(preferring: Set(arrayLiteral: "pear"), allowing: Set(arrayLiteral: "*")) .onOpenURL(perform: { url in - let deeplinkManager = DeeplinkManager() + let deeplinkManager = DeeplinkManager(showPopover: $showPopover) deeplinkManager.manage(url: url, appState: appState) }) .onDrop(of: ["public.file-url"], isTargeted: nil) { providers, _ in for provider in providers { provider.loadItem(forTypeIdentifier: "public.file-url") { data, error in if let data = data as? Data, let url = URL(dataRepresentation: data, relativeTo: nil) { - let deeplinkManager = DeeplinkManager() + let deeplinkManager = DeeplinkManager(showPopover: $showPopover) deeplinkManager.manage(url: url, appState: appState) } } diff --git a/Pearcleaner/Settings/General.swift b/Pearcleaner/Settings/General.swift index c3caf84..223113b 100644 --- a/Pearcleaner/Settings/General.swift +++ b/Pearcleaner/Settings/General.swift @@ -13,6 +13,7 @@ struct GeneralSettingsTab: View { @AppStorage("settings.general.glass") private var glass: Bool = true @AppStorage("settings.general.mini") private var mini: Bool = false @AppStorage("settings.general.dark") var isDark: Bool = true + @AppStorage("settings.general.popover") private var popoverStay: Bool = true @AppStorage("displayMode") var displayMode: DisplayMode = .system @State private var selectedTheme = "Auto" private let themes = ["Auto", "Dark", "Light"] @@ -23,7 +24,7 @@ struct GeneralSettingsTab: View { HStack { VStack(alignment: .leading, spacing: 5) { Text("Transparency").font(.title2) - Text("Toggles the transparent sidebar material") + Text("Toggles transparent material") .font(.footnote) .foregroundStyle(.gray) } @@ -115,14 +116,37 @@ struct GeneralSettingsTab: View { RoundedRectangle(cornerRadius: 8) .fill(Color("mode").opacity(0.05)) ) - + + + + HStack { + VStack(alignment: .leading, spacing: 5) { + Text("Mini - Files View").font(.title2) + Text("Keeps file search view on top in mini mode") + .font(.footnote) + .foregroundStyle(.gray) + } + Spacer() + Toggle(isOn: $popoverStay, label: { + }) + .toggleStyle(.switch) + } + .padding() + .background( + RoundedRectangle(cornerRadius: 8) + .fill(Color("mode").opacity(0.05)) + ) + + + + Spacer() } } .padding(20) - .frame(width: 400, height: 250) - + .frame(width: 400, height: 350) + } } diff --git a/Pearcleaner/Views/FilesView.swift b/Pearcleaner/Views/FilesView.swift index 57f7d9d..a3512bd 100644 --- a/Pearcleaner/Views/FilesView.swift +++ b/Pearcleaner/Views/FilesView.swift @@ -15,6 +15,7 @@ struct FilesView: View { @State private var showPop: Bool = false @State private var itemDetails: [(size: String, icon: Image?)] = [] @AppStorage("settings.general.mini") private var mini: Bool = false + @AppStorage("settings.sentinel.enable") private var sentinel: Bool = false @Environment(\.colorScheme) var colorScheme @Binding var showPopover: Bool @Binding var search: String @@ -196,6 +197,9 @@ struct FilesView: View { withAnimation { updateOnMain { appState.isReminderVisible.toggle() + if sentinel { + launchctl(load: true) + } } } refreshAppList(appState.appInfo) diff --git a/Pearcleaner/Views/MiniMode.swift b/Pearcleaner/Views/MiniMode.swift index 51511b7..b5485d3 100644 --- a/Pearcleaner/Views/MiniMode.swift +++ b/Pearcleaner/Views/MiniMode.swift @@ -15,6 +15,7 @@ struct MiniMode: View { @State private var showSys: Bool = true @State private var showUsr: Bool = true @AppStorage("settings.general.glass") private var glass: Bool = false + @AppStorage("settings.general.popover") private var popoverStay: Bool = true @Binding var showPopover: Bool @@ -25,14 +26,14 @@ struct MiniMode: View { // Main Mini View VStack(spacing: 0) { if appState.currentView == .empty { - TopBarMini(search: $search) + TopBarMini(search: $search, showPopover: $showPopover) MiniEmptyView(showPopover: $showPopover) } else if appState.currentView == .files { - TopBarMini(search: $search) + TopBarMini(search: $search, showPopover: $showPopover) FilesView(showPopover: $showPopover, search: $search) .id(appState.appInfo.id) } else if appState.currentView == .apps { - TopBarMini(search: $search) + TopBarMini(search: $search, showPopover: $showPopover) MiniAppView(search: $search, showPopover: $showPopover) } } @@ -43,7 +44,7 @@ struct MiniMode: View { FilesView(showPopover: $showPopover, search: $search) .id(appState.appInfo.id) } - .interactiveDismissDisabled() + .interactiveDismissDisabled(popoverStay) .background( Rectangle() .fill(Color("pop")) diff --git a/Pearcleaner/Views/TopBarMini.swift b/Pearcleaner/Views/TopBarMini.swift index 05755ab..71c3a00 100644 --- a/Pearcleaner/Views/TopBarMini.swift +++ b/Pearcleaner/Views/TopBarMini.swift @@ -13,6 +13,7 @@ struct TopBarMini: View { @AppStorage("settings.sentinel.enable") private var sentinel: Bool = false @AppStorage("settings.general.mini") private var mini: Bool = false @Binding var search: String + @Binding var showPopover: Bool @EnvironmentObject var appState: AppState var body: some View { @@ -56,6 +57,7 @@ struct TopBarMini: View { // updateOnMain { appState.currentView = .empty appState.appInfo = AppInfo.empty + showPopover = false // } } }