Skip to content

Commit

Permalink
v3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alienator88 committed Mar 19, 2024
1 parent 2318949 commit a55396c
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 151 deletions.
8 changes: 4 additions & 4 deletions Pearcleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 25;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BK8443AXLU;
Expand All @@ -577,7 +577,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 3.2.0;
MARKETING_VERSION = 3.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -594,7 +594,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 25;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BK8443AXLU;
Expand All @@ -612,7 +612,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 3.2.0;
MARKETING_VERSION = 3.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
4 changes: 2 additions & 2 deletions Pearcleaner/Logic/DeepLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DeeplinkManager {
if let path = queryItems.first(where: { $0.name == DeepLinkConstants.query })?.value {
let pathURL = URL(fileURLWithPath: path)
let appInfo = getAppInfo(atPath: pathURL)
showAppInFiles(appInfo: appInfo!, mini: mini, appState: appState, locations: locations, showPopover: $showPopover)
showAppInFiles(appInfo: appInfo!, appState: appState, locations: locations, showPopover: $showPopover)
} else {
printOS("No path query parameter found in the URL")
}
Expand All @@ -46,7 +46,7 @@ class DeeplinkManager {

func handleAppBundle(url: URL, appState: AppState, locations: Locations) {
let appInfo = getAppInfo(atPath: url)
showAppInFiles(appInfo: appInfo!, mini: mini, appState: appState, locations: locations, showPopover: $showPopover)
showAppInFiles(appInfo: appInfo!, appState: appState, locations: locations, showPopover: $showPopover)
}

}
23 changes: 9 additions & 14 deletions Pearcleaner/Logic/Logic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func loadAllPaths(allApps: [AppInfo], appState: AppState, locations: Locations,


// Load item in Files view
func showAppInFiles(appInfo: AppInfo, mini: Bool, appState: AppState, locations: Locations, showPopover: Binding<Bool>) {
func showAppInFiles(appInfo: AppInfo, appState: AppState, locations: Locations, showPopover: Binding<Bool>) {
showPopover.wrappedValue = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
updateOnMain {
Expand All @@ -481,23 +481,15 @@ func showAppInFiles(appInfo: AppInfo, mini: Bool, appState: AppState, locations:
appState.appInfo = storedAppInfo
appState.selectedItems = Set(storedAppInfo.files)
withAnimation(Animation.easeIn(duration: 0.4)) {
if mini {
appState.currentView = .files
showPopover.wrappedValue.toggle()
} else {
appState.currentView = .files
}
appState.currentView = .files
showPopover.wrappedValue.toggle()
}
} else {
// Handle the case where the appInfo is not found in the store
withAnimation(Animation.easeIn(duration: 0.4)) {
appState.showProgress = true
if mini {
appState.currentView = .files
showPopover.wrappedValue.toggle()
} else {
appState.currentView = .files
}
appState.currentView = .files
showPopover.wrappedValue.toggle()
}
appState.appInfo = appInfo
findPathsForApp(appInfo: appInfo, appState: appState, locations: locations) {
Expand Down Expand Up @@ -640,7 +632,9 @@ func reversePathsSearch(appState: AppState, locations: Locations, completion: @e
// 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 = """
Expand All @@ -660,6 +654,7 @@ func moveFilesToTrash(at fileURLs: [URL], completion: @escaping () -> Void = {})
completion()
}
}

}


Expand Down
13 changes: 8 additions & 5 deletions Pearcleaner/Logic/Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import SwiftUI
struct SimpleButtonStyle: ButtonStyle {
@State private var hovered = false
let icon: String
let label: String?
let help: String
let color: Color
let shield: Bool?

init(icon: String, help: String, color: Color, shield: Bool? = nil) {

init(icon: String, label: String? = "", help: String, color: Color) {
self.icon = icon
self.label = label
self.help = help
self.color = color
self.shield = shield
}

func makeBody(configuration: Self.Configuration) -> some View {
Expand All @@ -28,8 +28,11 @@ struct SimpleButtonStyle: ButtonStyle {
.resizable()
.scaledToFit()
.frame(width: 20)
.foregroundColor(hovered ? color : color.opacity(0.5))
if label != "" {
Text(label!)
}
}
.foregroundColor(hovered ? color : color.opacity(0.5))
.padding(5)
.onHover { hovering in
withAnimation() {
Expand Down
19 changes: 10 additions & 9 deletions Pearcleaner/Logic/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func updateOnBackground(_ updates: @escaping () -> Void) {


// Resize window
func resizeWindow(width: CGFloat, height: CGFloat) {
if let window = NSApplication.shared.windows.first {
let newSize = NSSize(width: width, height: height)
window.setContentSize(newSize)
}
}
//func resizeWindow(width: CGFloat, height: CGFloat) {
// if let window = NSApplication.shared.windows.first {
// let newSize = NSSize(width: width, height: height)
// window.setContentSize(newSize)
// }
//}

func resizeWindowAuto(windowSettings: WindowSettings) {
if let window = NSApplication.shared.windows.first {
func resizeWindowAuto(windowSettings: WindowSettings, title: String) {
if let window = NSApplication.shared.windows.first(where: { $0.title == title }) {
let newSize = NSSize(width: windowSettings.loadWindowSettings().width, height: windowSettings.loadWindowSettings().height)
window.setContentSize(newSize)
}
Expand Down Expand Up @@ -168,7 +168,8 @@ func hasWindowOpen() -> Bool {
func findAndHideWindows(named titles: [String]) {
for title in titles {
if let window = NSApp.windows.first(where: { $0.title == title }) {
window.orderOut(nil)
// window.orderOut(nil)
window.close()
}
}
}
Expand Down
43 changes: 11 additions & 32 deletions Pearcleaner/PearcleanerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct PearcleanerApp: App {
MenuBarMiniAppView(search: $search, showPopover: $showPopover)
.environmentObject(locations)
.environmentObject(appState)
.preferredColorScheme(displayMode.colorScheme)
}, icon: selectedMenubarIcon)
}

Expand Down Expand Up @@ -181,49 +182,27 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
}


#if !DEBUG
func windowShouldClose(_ sender: NSWindow) -> Bool {
let menubarEnabled = UserDefaults.standard.bool(forKey: "settings.menubar.enabled")
// let alert = NSAlert.init()
// alert.addButton(withTitle: "Return")
// alert.addButton(withTitle: "Quit")
// alert.informativeText = "Quit or return to application?"
// let response = alert.runModal()
// if response == NSApplication.ModalResponse.alertFirstButtonReturn {
//#if !DEBUG
// func windowShouldClose(_ sender: NSWindow) -> Bool {
// let menubarEnabled = UserDefaults.standard.bool(forKey: "settings.menubar.enabled")
// if menubarEnabled {
// findAndHideWindows(named: ["Pearcleaner"])
// return false
// } else {
// NSApplication.shared.terminate(self)
// return true
// }
if menubarEnabled {
findAndHideWindows(named: ["Pearcleaner"])
return false
} else {
return true
}
}
#endif
// }
//#endif

func applicationDidFinishLaunching(_ notification: Notification) {
let menubarEnabled = UserDefaults.standard.bool(forKey: "settings.menubar.enabled")
// let dockEnabled = UserDefaults.standard.bool(forKey: "settings.dock.enabled")

if menubarEnabled {
#if !DEBUG
findAndHideWindows(named: ["Pearcleaner"])
// NSApp.windows.first?.close()
NSApplication.shared.setActivationPolicy(.accessory)
#endif
// if dockEnabled {
// NSApplication.shared.setActivationPolicy(.regular)
// } else {
// NSApplication.shared.setActivationPolicy(.accessory)
// }
}

// Link window to delegate
let mainWindow = NSApp.windows[0]
mainWindow.delegate = self
// Link window to delegate
// let mainWindow = NSApp.windows[0]
// mainWindow.delegate = self

}

Expand Down
55 changes: 41 additions & 14 deletions Pearcleaner/Settings/Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct InterfaceSettingsTab: View {
@EnvironmentObject var locations: Locations
@State private var windowSettings = WindowSettings()
@AppStorage("settings.menubar.enabled") private var menubarEnabled: Bool = false
// @AppStorage("settings.dock.enabled") private var dockEnabled: Bool = false
@AppStorage("settings.general.mini") private var mini: Bool = false
@AppStorage("displayMode") var displayMode: DisplayMode = .system
@AppStorage("settings.general.glass") private var glass: Bool = true
Expand Down Expand Up @@ -57,6 +56,9 @@ struct InterfaceSettingsTab: View {
Toggle(isOn: $glass, label: {
})
.toggleStyle(.switch)
.onChange(of: glass) { newVal in
MenuBarExtraManager.shared.restartMenuBarExtra()
}
}
.padding(5)
.padding(.leading)
Expand Down Expand Up @@ -89,13 +91,17 @@ struct InterfaceSettingsTab: View {
displayMode.colorScheme = nil
if isDarkModeEnabled() {
displayMode.colorScheme = .dark
MenuBarExtraManager.shared.restartMenuBarExtra()
} else {
displayMode.colorScheme = .light
MenuBarExtraManager.shared.restartMenuBarExtra()
}
case "Dark":
displayMode.colorScheme = .dark
MenuBarExtraManager.shared.restartMenuBarExtra()
case "Light":
displayMode.colorScheme = .light
MenuBarExtraManager.shared.restartMenuBarExtra()
default:
break
}
Expand Down Expand Up @@ -135,19 +141,35 @@ struct InterfaceSettingsTab: View {
Toggle(isOn: $mini, label: {
})
.toggleStyle(.switch)
.disabled(menubarEnabled)
.help(menubarEnabled ? "Disabled when menubar icon is enabled" : "")
.onChange(of: mini) { newVal in
if mini {
appState.currentView = miniView ? .apps : .empty
showPopover = false
resizeWindowAuto(windowSettings: windowSettings)
} else {
resizeWindowAuto(windowSettings: windowSettings)
if appState.appInfo.appName.isEmpty {
appState.currentView = .empty
if mini {
appState.currentView = miniView ? .apps : .empty
showPopover = false
windowSettings.newWindow {
MiniMode(search: $search, showPopover: $showPopover)
.environmentObject(locations)
.environmentObject(appState)
.preferredColorScheme(displayMode.colorScheme)
}
resizeWindowAuto(windowSettings: windowSettings, title: "Pearcleaner")
} else {
appState.currentView = .files
if appState.appInfo.appName.isEmpty {
appState.currentView = .empty
} else {
appState.currentView = .files
}
windowSettings.newWindow {
RegularMode(search: $search, showPopover: $showPopover)
.environmentObject(locations)
.environmentObject(appState)
.preferredColorScheme(displayMode.colorScheme)
}
resizeWindowAuto(windowSettings: windowSettings, title: "Pearcleaner")
}
}


}
}
.padding(5)
Expand Down Expand Up @@ -229,7 +251,7 @@ struct InterfaceSettingsTab: View {
.font(.callout)
.foregroundStyle(.gray)
}
InfoButton(text: "When menubar icon is enabled, the main app window and dock icon will be hidden. You can still pop-out the main app window from the menubar icon temporarily if you'd like.", color: nil, label: "")
InfoButton(text: "When menubar icon is enabled, the main app window and dock icon will be disabled since the app will be put in accessory mode.", color: nil, label: "")
Spacer()
Toggle(isOn: $menubarEnabled, label: {
})
Expand All @@ -240,26 +262,31 @@ struct InterfaceSettingsTab: View {
MenuBarMiniAppView(search: $search, showPopover: $showPopover)
.environmentObject(locations)
.environmentObject(appState)
.preferredColorScheme(displayMode.colorScheme)
}, icon: selectedMenubarIcon)
NSApplication.shared.setActivationPolicy(.accessory)
findAndShowWindows(named: ["Pearcleaner", "Interface"])
findAndHideWindows(named: ["Pearcleaner"])
// findAndShowWindows(named: ["Pearcleaner", "Interface"])
} else {
MenuBarExtraManager.shared.removeMenuBarExtra()
// dockEnabled = true
NSApplication.shared.setActivationPolicy(.regular)
if !hasWindowOpen() {
if mini {
windowSettings.newWindow {
MiniMode(search: $search, showPopover: $showPopover)
.environmentObject(locations)
.environmentObject(appState)
.preferredColorScheme(displayMode.colorScheme)
}
resizeWindowAuto(windowSettings: windowSettings, title: "Pearcleaner")
} else {
windowSettings.newWindow {
RegularMode(search: $search, showPopover: $showPopover)
.environmentObject(locations)
.environmentObject(appState)
.preferredColorScheme(displayMode.colorScheme)
}
resizeWindowAuto(windowSettings: windowSettings, title: "Pearcleaner")
}
}

Expand Down
6 changes: 3 additions & 3 deletions Pearcleaner/Views/AppListItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ struct AppListItems: View {
@State private var isHovered = false
@State private var windowSettings = WindowSettings()
@Environment(\.colorScheme) var colorScheme
@AppStorage("settings.general.mini") private var mini: Bool = false
@AppStorage("settings.general.popover") private var popoverStay: Bool = true
// @AppStorage("settings.general.mini") private var mini: Bool = false
// @AppStorage("settings.general.popover") private var popoverStay: Bool = true
@AppStorage("displayMode") var displayMode: DisplayMode = .system
@Binding var showPopover: Bool
@EnvironmentObject var locations: Locations
Expand Down Expand Up @@ -110,7 +110,7 @@ struct AppListItems: View {
}
.onTapGesture {
withAnimation(Animation.easeInOut(duration: 0.4)) {
showAppInFiles(appInfo: appInfo, mini: mini, appState: appState, locations: locations, showPopover: $showPopover)
showAppInFiles(appInfo: appInfo, appState: appState, locations: locations, showPopover: $showPopover)
}
}

Expand Down
Loading

0 comments on commit a55396c

Please sign in to comment.