Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alienator88 committed Mar 19, 2024
1 parent 404bdf0 commit 2318949
Show file tree
Hide file tree
Showing 28 changed files with 865 additions and 452 deletions.
24 changes: 14 additions & 10 deletions Pearcleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
C7D31D4A2AFEB26700C7ED9E /* AppListItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D31D492AFEB26700C7ED9E /* AppListItems.swift */; };
C7D31D512AFF00F300C7ED9E /* Locations.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D31D502AFF00F300C7ED9E /* Locations.swift */; };
C7DC1FEE2B9F7D3D009AC317 /* features.json in Resources */ = {isa = PBXBuildFile; fileRef = C7DC1FED2B9F7D3D009AC317 /* features.json */; };
C7DE67272BA61E8D00EB1633 /* MenuBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DE67262BA61E8D00EB1633 /* MenuBar.swift */; };
C7DE672B2BA6343D00EB1633 /* MenuBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DE672A2BA6343D00EB1633 /* MenuBarItem.swift */; };
C7DE672D2BA6356500EB1633 /* MenuBarMiniAppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DE672C2BA6356500EB1633 /* MenuBarMiniAppView.swift */; };
C7ED86B12BA8A35500F13DE4 /* Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7ED86B02BA8A35500F13DE4 /* Interface.swift */; };
C7ED86B32BA8ED8800F13DE4 /* Trash.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7ED86B22BA8ED8800F13DE4 /* Trash.swift */; };
C7F539382AF60865007DF1B2 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F539372AF60865007DF1B2 /* Utilities.swift */; };
C7FB173B2B96321300B96F9A /* AppsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7FB173A2B96321300B96F9A /* AppsListView.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -100,9 +101,10 @@
C7D31D492AFEB26700C7ED9E /* AppListItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppListItems.swift; sourceTree = "<group>"; };
C7D31D502AFF00F300C7ED9E /* Locations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Locations.swift; sourceTree = "<group>"; };
C7DC1FED2B9F7D3D009AC317 /* features.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = features.json; sourceTree = SOURCE_ROOT; };
C7DE67262BA61E8D00EB1633 /* MenuBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBar.swift; sourceTree = "<group>"; };
C7DE672A2BA6343D00EB1633 /* MenuBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarItem.swift; sourceTree = "<group>"; };
C7DE672C2BA6356500EB1633 /* MenuBarMiniAppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarMiniAppView.swift; sourceTree = "<group>"; };
C7ED86B02BA8A35500F13DE4 /* Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Interface.swift; sourceTree = "<group>"; };
C7ED86B22BA8ED8800F13DE4 /* Trash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trash.swift; sourceTree = "<group>"; };
C7F539372AF60865007DF1B2 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
C7FB173A2B96321300B96F9A /* AppsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppsListView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -132,6 +134,8 @@
C7045A312B068AD700376976 /* NewWin.swift */,
C7045A332B068B2900376976 /* UpdateView.swift */,
C7045A352B068DD700376976 /* PermView.swift */,
C7DE672A2BA6343D00EB1633 /* MenuBarItem.swift */,
C7CF47232B3B3F1700979C5F /* WindowSettings.swift */,
);
path = Windows;
sourceTree = "<group>";
Expand All @@ -140,16 +144,15 @@
isa = PBXGroup;
children = (
C77B90192AF1938F009CC655 /* Logic.swift */,
C7DE672A2BA6343D00EB1633 /* MenuBarItem.swift */,
C77B90172AF19382009CC655 /* AppCommands.swift */,
C77B90152AF19377009CC655 /* AppState.swift */,
C7F539372AF60865007DF1B2 /* Utilities.swift */,
C72893042AFD42E600C8C1CD /* DeepLink.swift */,
C77B901B2AF193A3009CC655 /* Styles.swift */,
C7D31D502AFF00F300C7ED9E /* Locations.swift */,
C7CF47232B3B3F1700979C5F /* WindowSettings.swift */,
C7A9CE462B89164700EB6E78 /* Authorization.swift */,
C7ACADE52B92A737000B5845 /* Features.swift */,
C7ED86B22BA8ED8800F13DE4 /* Trash.swift */,
);
path = Logic;
sourceTree = "<group>";
Expand All @@ -175,7 +178,7 @@
children = (
C77B901D2AF1A9DB009CC655 /* SettingsWindow.swift */,
C76D08492AF83C6E00D07867 /* General.swift */,
C7DE67262BA61E8D00EB1633 /* MenuBar.swift */,
C7ED86B02BA8A35500F13DE4 /* Interface.swift */,
C76D08472AF83C3F00D07867 /* Update.swift */,
C76D08502AF850F300D07867 /* About.swift */,
);
Expand Down Expand Up @@ -357,11 +360,13 @@
C77B90162AF19377009CC655 /* AppState.swift in Sources */,
C7045A322B068AD700376976 /* NewWin.swift in Sources */,
C7DE672D2BA6356500EB1633 /* MenuBarMiniAppView.swift in Sources */,
C7ED86B32BA8ED8800F13DE4 /* Trash.swift in Sources */,
C7D31D512AFF00F300C7ED9E /* Locations.swift in Sources */,
C77B901A2AF1938F009CC655 /* Logic.swift in Sources */,
C7045A2A2B03FAF000376976 /* TopBarMini.swift in Sources */,
C77B901C2AF193A3009CC655 /* Styles.swift in Sources */,
C7045A282B03E71D00376976 /* MiniMode.swift in Sources */,
C7ED86B12BA8A35500F13DE4 /* Interface.swift in Sources */,
C72893052AFD42E600C8C1CD /* DeepLink.swift in Sources */,
C71848442B8D2D600046CB13 /* ZombieView.swift in Sources */,
C7DE672B2BA6343D00EB1633 /* MenuBarItem.swift in Sources */,
Expand All @@ -378,7 +383,6 @@
C76D08552AF89CDE00D07867 /* RegularMode.swift in Sources */,
C7A9CE472B89164700EB6E78 /* Authorization.swift in Sources */,
C7CF47242B3B3F1700979C5F /* WindowSettings.swift in Sources */,
C7DE67272BA61E8D00EB1633 /* MenuBar.swift in Sources */,
C77B90232AF2D616009CC655 /* FilesView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -555,7 +559,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 23;
CURRENT_PROJECT_VERSION = 24;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BK8443AXLU;
Expand All @@ -573,7 +577,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 3.1.1;
MARKETING_VERSION = 3.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -590,7 +594,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 23;
CURRENT_PROJECT_VERSION = 24;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BK8443AXLU;
Expand All @@ -608,7 +612,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 3.1.1;
MARKETING_VERSION = 3.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.alienator88.Pearcleaner;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
8 changes: 2 additions & 6 deletions Pearcleaner/Logic/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,14 @@ struct ZombieFile: Identifiable, Equatable, Hashable {
enum CurrentTabView:Int
{
case general
case menubar
// case permissions
// case sentinel
case interface
case update
case about

var title: String {
switch self {
case .general: return "General"
case .menubar: return "MenuBar"
// case .permissions: return "Permissions"
// case .sentinel: return "Sentinel"
case .interface: return "Interface"
case .update: return "Update"
case .about: return "About"
}
Expand Down
212 changes: 106 additions & 106 deletions Pearcleaner/Logic/Authorization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,109 +5,109 @@
// Created by Alin Lupascu on 2/23/24.
//

import Foundation
import Swift

// https://github.com/x13a/authorization-swift

public struct Authorization {

public enum Error: Swift.Error {
case create(OSStatus)
case copyRights(OSStatus)
case exec(OSStatus)
}

public static func executeWithPrivileges(
_ command: String
) -> Result<FileHandle, Error> {

let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
var fn: @convention(c) (
AuthorizationRef,
UnsafePointer<CChar>, // path
AuthorizationFlags,
UnsafePointer<UnsafePointer<CChar>?>, // args
UnsafeMutablePointer<UnsafeMutablePointer<FILE>>?
) -> OSStatus
fn = unsafeBitCast(
dlsym(RTLD_DEFAULT, "AuthorizationExecuteWithPrivileges"),
to: type(of: fn)
)

var authorizationRef: AuthorizationRef? = nil
var err = AuthorizationCreate(nil, nil, [], &authorizationRef)
guard err == errAuthorizationSuccess else {
return .failure(.create(err))
}
defer { AuthorizationFree(authorizationRef!, [.destroyRights]) }

var components = command.components(separatedBy: " ")
var path = components.remove(at: 0).cString(using: .utf8)!
let name = kAuthorizationRightExecute.cString(using: .utf8)!

var items: AuthorizationItem = name.withUnsafeBufferPointer { nameBuf in
path.withUnsafeBufferPointer { pathBuf in
let pathPtr =
UnsafeMutableRawPointer(mutating: pathBuf.baseAddress!)
return AuthorizationItem(
name: nameBuf.baseAddress!,
valueLength: path.count,
value: pathPtr,
flags: 0
)
}
}

var rights: AuthorizationRights =
withUnsafeMutablePointer(to: &items) { items in
return AuthorizationRights(count: 1, items: items)
}

let flags: AuthorizationFlags = [
.interactionAllowed,
.preAuthorize,
.extendRights,
]

err = AuthorizationCopyRights(
authorizationRef!,
&rights,
nil,
flags,
nil
)
guard err == errAuthorizationSuccess else {
return .failure(.copyRights(err))
}

let rest = components.map { $0.cString(using: .utf8)! }
var args = Array<UnsafePointer<CChar>?>(
repeating: nil,
count: rest.count + 1
)
for (idx, arg) in rest.enumerated() {
args[idx] = UnsafePointer<CChar>?(arg)
}

var file = FILE()
let fh: FileHandle?

(err, fh) = withUnsafeMutablePointer(to: &file) { file in
var pipe = file
let err = fn(authorizationRef!, &path, [], &args, &pipe)
guard err == errAuthorizationSuccess else {
return (err, nil)
}
let fh = FileHandle(
fileDescriptor: fileno(pipe),
closeOnDealloc: true
)
return (err, fh)
}
guard err == errAuthorizationSuccess else {
return .failure(.exec(err))
}
return .success(fh!)
}
}
//import Foundation
//import Swift
//
//// https://github.com/x13a/authorization-swift
//
//public struct Authorization {
//
// public enum Error: Swift.Error {
// case create(OSStatus)
// case copyRights(OSStatus)
// case exec(OSStatus)
// }
//
// public static func executeWithPrivileges(
// _ command: String
// ) -> Result<FileHandle, Error> {
//
// let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
// var fn: @convention(c) (
// AuthorizationRef,
// UnsafePointer<CChar>, // path
// AuthorizationFlags,
// UnsafePointer<UnsafePointer<CChar>?>, // args
// UnsafeMutablePointer<UnsafeMutablePointer<FILE>>?
// ) -> OSStatus
// fn = unsafeBitCast(
// dlsym(RTLD_DEFAULT, "AuthorizationExecuteWithPrivileges"),
// to: type(of: fn)
// )
//
// var authorizationRef: AuthorizationRef? = nil
// var err = AuthorizationCreate(nil, nil, [], &authorizationRef)
// guard err == errAuthorizationSuccess else {
// return .failure(.create(err))
// }
// defer { AuthorizationFree(authorizationRef!, [.destroyRights]) }
//
// var components = command.components(separatedBy: " ")
// var path = components.remove(at: 0).cString(using: .utf8)!
// let name = kAuthorizationRightExecute.cString(using: .utf8)!
//
// var items: AuthorizationItem = name.withUnsafeBufferPointer { nameBuf in
// path.withUnsafeBufferPointer { pathBuf in
// let pathPtr =
// UnsafeMutableRawPointer(mutating: pathBuf.baseAddress!)
// return AuthorizationItem(
// name: nameBuf.baseAddress!,
// valueLength: path.count,
// value: pathPtr,
// flags: 0
// )
// }
// }
//
// var rights: AuthorizationRights =
// withUnsafeMutablePointer(to: &items) { items in
// return AuthorizationRights(count: 1, items: items)
// }
//
// let flags: AuthorizationFlags = [
// .interactionAllowed,
// .preAuthorize,
// .extendRights,
// ]
//
// err = AuthorizationCopyRights(
// authorizationRef!,
// &rights,
// nil,
// flags,
// nil
// )
// guard err == errAuthorizationSuccess else {
// return .failure(.copyRights(err))
// }
//
// let rest = components.map { $0.cString(using: .utf8)! }
// var args = Array<UnsafePointer<CChar>?>(
// repeating: nil,
// count: rest.count + 1
// )
// for (idx, arg) in rest.enumerated() {
// args[idx] = UnsafePointer<CChar>?(arg)
// }
//
// var file = FILE()
// let fh: FileHandle?
//
// (err, fh) = withUnsafeMutablePointer(to: &file) { file in
// var pipe = file
// let err = fn(authorizationRef!, &path, [], &args, &pipe)
// guard err == errAuthorizationSuccess else {
// return (err, nil)
// }
// let fh = FileHandle(
// fileDescriptor: fileno(pipe),
// closeOnDealloc: true
// )
// return (err, fh)
// }
// guard err == errAuthorizationSuccess else {
// return .failure(.exec(err))
// }
// return .success(fh!)
// }
//}
24 changes: 0 additions & 24 deletions Pearcleaner/Logic/Logic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -640,30 +640,6 @@ 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
// var filesFinder = fileURLs
// var filesSudo: [URL] = []
//
// for file in fileURLs {
// if isSocketFile(at: file) {
// if let index = filesFinder.firstIndex(of: file) {
// filesFinder.remove(at: index)
// filesSudo.insert(file, at: 0)
// }
// }
// }
//
// if !filesSudo.isEmpty {
// // Remove socket files with rm
// let filesSudoPaths = filesSudo.map { $0.path }
// do {
// let fileHandler = try Authorization.executeWithPrivileges("/bin/rm -f \(filesSudoPaths.joined(separator: " "))").get()
// printOS(String(bytes: fileHandler.readDataToEndOfFile(), encoding: .utf8)!)
// } catch {
// printOS("Failed to remove socket file/s with privileges: \(error)")
// }
// }



updateOnBackground {
let posixFiles = fileURLs.map { "POSIX file \"\($0.path)\", " }.joined().dropLast(3)
Expand Down
Loading

0 comments on commit 2318949

Please sign in to comment.