Skip to content

Commit

Permalink
v3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alienator88 committed Mar 23, 2024
1 parent 5350a8f commit 7906cd7
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 179 deletions.
10 changes: 5 additions & 5 deletions Pearcleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@
isa = PBXGroup;
children = (
C77B90222AF2D616009CC655 /* FilesView.swift */,
C71848432B8D2D600046CB13 /* ZombieView.swift */,
C76D08542AF89CDE00D07867 /* RegularMode.swift */,
C7D31D472AFEB23700C7ED9E /* TopBar.swift */,
C7045A292B03FAF000376976 /* TopBarMini.swift */,
C7D31D492AFEB26700C7ED9E /* AppListItems.swift */,
C7045A272B03E71D00376976 /* MiniMode.swift */,
C71848432B8D2D600046CB13 /* ZombieView.swift */,
C7FB173A2B96321300B96F9A /* AppsListView.swift */,
C7DE672C2BA6356500EB1633 /* MenuBarMiniAppView.swift */,
);
Expand Down Expand Up @@ -575,7 +575,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 26;
CURRENT_PROJECT_VERSION = 27;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BK8443AXLU;
Expand All @@ -593,7 +593,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 3.3.0;
MARKETING_VERSION = 3.3.1;
PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -610,7 +610,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 26;
CURRENT_PROJECT_VERSION = 27;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BK8443AXLU;
Expand All @@ -628,7 +628,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 3.3.0;
MARKETING_VERSION = 3.3.1;
PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
23 changes: 17 additions & 6 deletions Pearcleaner/Logic/AppCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct AppCommands: Commands {
}

}



// Edit Menu
Expand All @@ -74,12 +74,12 @@ struct AppCommands: Commands {
{
undoTrash(appState: appState) {
let sortedApps = getSortedApps(paths: fsm.folderPaths, appState: appState)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
appState.sortedApps = sortedApps
// if instantSearch {
// loadAllPaths(allApps: sortedApps.userApps + sortedApps.systemApps, appState: appState, locations: locations)
// }

for app in appState.trashedFiles {
let pathFinder = AppPathFinder(appInfo: app, appState: appState, locations: locations)
pathFinder.findPaths()
}
}
}
} label: {
Expand All @@ -88,6 +88,17 @@ struct AppCommands: Commands {
.keyboardShortcut("z", modifiers: .command)


// Button
// {
// updateOnMain {
// appState.currentView = .zombie
// }
// } label: {
// Label("Zombie", systemImage: "clear")
// }
// .keyboardShortcut("f", modifiers: .command)


}


Expand Down
3 changes: 2 additions & 1 deletion Pearcleaner/Logic/AppPathsFetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ class AppPathFinder {
self.appState.appInfo = self.appInfo
self.appState.selectedItems = Set(updatedCollection)
}
self.appState.appInfoStore.append(self.appInfo)

// Only append object to store if instant search. Same for calculating progress.
if self.instantSearch {
self.appState.appInfoStore.append(self.appInfo)
self.appState.instantProgress += 1
}

Expand Down
1 change: 1 addition & 0 deletions Pearcleaner/Logic/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AppState: ObservableObject
{
@Published var appInfo: AppInfo
@Published var appInfoStore: [AppInfo] = []
@Published var trashedFiles: [AppInfo] = []
@Published var zombieFile: ZombieFile
@Published var sortedApps: [AppInfo] = []
@Published var selectedItems = Set<URL>()
Expand Down
4 changes: 3 additions & 1 deletion Pearcleaner/Logic/ReversePathsFetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ class ReversePathsSearcher {
private func processItem(_ itemName: String, itemURL: URL, allPaths: [String], allNames: [String]) {
let formattedItemName = itemName.pearFormat()
let itemPath = itemURL.path.pearFormat()
let itemLastPathComponent = itemURL.lastPathComponent.pearFormat()

guard !skipped.contains(where: { formattedItemName.contains($0) }),
!allPaths.contains(itemPath),
// !allPaths.contains(itemPath),
!allPaths.contains(where: { $0 == itemPath || $0.hasSuffix("/\(itemLastPathComponent)") }),
!allNames.contains(formattedItemName),
isSupportedFileType(at: itemURL.path) else {
return
Expand Down
4 changes: 2 additions & 2 deletions Pearcleaner/Logic/Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct SimpleButtonStyle: ButtonStyle {
.resizable()
.scaledToFit()
.frame(width: 20)
if label != "" {
Text(label!)
if let label = label, !label.isEmpty {
Text(label)
}
}
.foregroundColor(hovered ? color : color.opacity(0.5))
Expand Down
44 changes: 39 additions & 5 deletions Pearcleaner/Logic/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,47 @@ func checkAndRequestAccessibilityAccess(appState: AppState) -> Bool {
}
}

// Check app directory based on user permission
func checkAppDirectoryAndUserRole(completion: @escaping ((isInCorrectDirectory: Bool, isAdmin: Bool)) -> Void) {
isCurrentUserAdmin { isAdmin in
let bundlePath = Bundle.main.bundlePath as NSString
let applicationsDir = "/Applications"
let userApplicationsDir = "\(home)/Applications"

var isInCorrectDirectory = false

if isAdmin {
// Admins can have the app in either /Applications or ~/Applications
isInCorrectDirectory = bundlePath.deletingLastPathComponent == applicationsDir ||
bundlePath.deletingLastPathComponent == userApplicationsDir
} else {
// Standard users should only have the app in ~/Applications
isInCorrectDirectory = bundlePath.deletingLastPathComponent == userApplicationsDir
}

// Check if app is installed in /Applications directory
func isAppInApplicationsDir() -> Bool {
if let bundlePath = Bundle.main.bundlePath as NSString? {
return bundlePath.deletingLastPathComponent == "/Applications"
// Return both conditions: if the app is in the correct directory and if the user is an admin
completion((isInCorrectDirectory, isAdmin))
}
}


// Check if user is admin or standard user
func isCurrentUserAdmin(completion: @escaping (Bool) -> Void) {
let process = Process()
process.executableURL = URL(fileURLWithPath: "/bin/zsh") // Using zsh, macOS default shell
process.arguments = ["-c", "groups $(whoami) | grep -q ' admin '"]

process.terminationHandler = { process in
// On macOS, a process's exit status of 0 indicates success (admin group found in this context)
completion(process.terminationStatus == 0)
}

do {
try process.run()
} catch {
print("Failed to execute command: \(error)")
completion(false)
}
return false
}

// Check if appearance is dark mode
Expand Down
39 changes: 22 additions & 17 deletions Pearcleaner/PearcleanerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ struct PearcleanerApp: App {
}, icon: selectedMenubarIcon)
}


#if !DEBUG
Task {

Expand Down Expand Up @@ -157,7 +158,7 @@ struct PearcleanerApp: App {
.windowResizability(.contentMinSize)
.commands {
AppCommands(appState: appState, locations: locations, fsm: fsm)
CommandGroup(replacing: .newItem, addition: { })
// CommandGroup(replacing: .newItem, addition: { })

}

Expand Down Expand Up @@ -185,29 +186,33 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
return !menubarEnabled
}


//#if !DEBUG
// func windowShouldClose(_ sender: NSWindow) -> Bool {
// let menubarEnabled = UserDefaults.standard.bool(forKey: "settings.menubar.enabled")
// if menubarEnabled {
// findAndHideWindows(named: ["Pearcleaner"])
// return false
// } else {
// return true
// }
// }
//#endif

func applicationDidFinishLaunching(_ notification: Notification) {
let menubarEnabled = UserDefaults.standard.bool(forKey: "settings.menubar.enabled")
if menubarEnabled {
findAndHideWindows(named: ["Pearcleaner"])
NSApplication.shared.setActivationPolicy(.accessory)
}
// Link window to delegate
// let mainWindow = NSApp.windows[0]
// mainWindow.delegate = self
}


func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
let windowSettings = WindowSettings()

if !flag {
// No visible windows, so let's open a new one
for window in sender.windows {
window.title = "Pearcleaner"
window.makeKeyAndOrderFront(self)
print(windowSettings.loadWindowSettings())
updateOnMain(after: 0.1, {
resizeWindowAuto(windowSettings: windowSettings, title: "Pearcleaner")
print(window.title)
})
}
return true // Indicates you've handled the re-open
}
// Return true if you want the application to proceed with its default behavior
return false
}

}
Expand Down
Loading

0 comments on commit 7906cd7

Please sign in to comment.