Skip to content

Commit

Permalink
Minor refactoring + cleanup
Browse files Browse the repository at this point in the history
sveinbjornt committed Nov 14, 2023

Unverified

This user has not yet uploaded their public signing key.
1 parent 87165b6 commit 1c9be32
Showing 6 changed files with 43 additions and 31 deletions.
File renamed without changes.
16 changes: 8 additions & 8 deletions Sloth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@
F442E0721EA7DB1000BAD80C /* InfoPanel.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InfoPanel.xib; sourceTree = "<group>"; };
F442E0771EA7DD0D00BAD80C /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = sparkle/Sparkle.framework; sourceTree = "<group>"; };
F44FC67225AD5EA200BC72F5 /* macos.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; name = macos.yml; path = .github/workflows/macos.yml; sourceTree = "<group>"; };
F45B3F6F29A15132007D506D /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
F45B3F6F29A15132007D506D /* CHANGES.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGES.md; sourceTree = "<group>"; };
F47B45351EE74F2C00D79DFF /* Credits.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
F47B453F1EF82AC200D79DFF /* TODO.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = "<group>"; };
F48BB5B924732C2C00B569F6 /* sloth_screenshot3.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = sloth_screenshot3.jpg; sourceTree = "<group>"; };
@@ -140,7 +140,7 @@
F4A8B5CD222DB5280049FA51 /* Makefile */,
F4F1D8A01C7623AF00945D3E /* README.md */,
F47B453F1EF82AC200D79DFF /* TODO.md */,
F45B3F6F29A15132007D506D /* CHANGELOG.md */,
F45B3F6F29A15132007D506D /* CHANGES.md */,
F4A9D5EE206A68BC0069B2B6 /* LICENSE.txt */,
F435320D2558EFC800AF00BD /* Source */,
F438712713402CDD00B51A5E /* Resources */,
@@ -219,20 +219,20 @@
children = (
F43532242558EFC800AF00BD /* Alerts.h */,
F43532122558EFC800AF00BD /* Alerts.m */,
F43532212558EFC800AF00BD /* MutableDictProxy.h */,
F435320F2558EFC800AF00BD /* MutableDictProxy.m */,
F435322D2558EFC800AF00BD /* IPUtils.h */,
F43532192558EFC800AF00BD /* IPUtils.m */,
F435321A2558EFC800AF00BD /* ProcessUtils.h */,
F435322C2558EFC800AF00BD /* ProcessUtils.m */,
F435322A2558EFC800AF00BD /* FSUtils.h */,
F435321C2558EFC800AF00BD /* FSUtils.m */,
F43532132558EFC800AF00BD /* IconUtils.h */,
F43532232558EFC800AF00BD /* IconUtils.m */,
F435322D2558EFC800AF00BD /* IPUtils.h */,
F43532192558EFC800AF00BD /* IPUtils.m */,
F43532212558EFC800AF00BD /* MutableDictProxy.h */,
F435320F2558EFC800AF00BD /* MutableDictProxy.m */,
F43532112558EFC800AF00BD /* NSString+RegexConvenience.h */,
F43532252558EFC800AF00BD /* NSString+RegexConvenience.m */,
F43532262558EFC800AF00BD /* NSWorkspace+Additions.h */,
F43532182558EFC800AF00BD /* NSWorkspace+Additions.m */,
F435321A2558EFC800AF00BD /* ProcessUtils.h */,
F435322C2558EFC800AF00BD /* ProcessUtils.m */,
F43532102558EFC800AF00BD /* STPrivilegedTask.h */,
F435321D2558EFC800AF00BD /* STPrivilegedTask.m */,
);
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -13,4 +13,5 @@
* Preserve expanded items between refreshes
* Update antiquated screenshots in README
* Show Path Control w. selected path at bottom of table view when item selected
* Upgrade Sparkle version
DONE * Always (re)select "General" tab when Preferences are shown
14 changes: 6 additions & 8 deletions source/Util/NSWorkspace+Additions.m
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ - (NSMenu *)openWithMenuForFile:(NSString *)path target:(id)t action:(SEL)s menu
}

id target = t ? t : self;
SEL selector = s ? s : @selector(openWith:);
SEL selector = s ? s : @selector(_openWith:);

NSMenu *submenu = menu ? menu : [[NSMenu alloc] init];
[submenu setTitle:path]; // Used by selector
@@ -128,7 +128,7 @@ - (NSMenu *)openWithMenuForFile:(NSString *)path target:(id)t action:(SEL)s menu
}

// Handler for when user selects item in Open With menu
- (void)openWith:(id)sender {
- (void)_openWith:(id)sender {
NSString *appPath = [sender toolTip];
NSString *filePath = [[sender menu] title];

@@ -145,7 +145,7 @@ - (void)openWith:(id)sender {
[oPanel setDirectoryURL:applicationFolderPaths[0]];
}

// Run
// Enter modal mode
if ([oPanel runModal] == NSModalResponseOK) {
appPath = [[oPanel URLs][0] path];
} else {
@@ -157,7 +157,7 @@ - (void)openWith:(id)sender {
}


#pragma mark -
#pragma mark - Info about file

- (NSString *)kindStringForFile:(NSString *)filePath {
NSURL *url = [NSURL fileURLWithPath:filePath];
@@ -199,8 +199,6 @@ - (BOOL)canRevealFileAtPath:(NSString *)path {
return ![badTypes containsObject:type];
}

#pragma mark - File/folder size

- (NSString *)fileSizeAsHumanReadableString:(UInt64)size {
if (size < 1024ULL) {
return [NSString stringWithFormat:@"%u bytes", (unsigned int)size];
@@ -212,7 +210,7 @@ - (NSString *)fileSizeAsHumanReadableString:(UInt64)size {
return [NSString stringWithFormat:@"%.1f GB", size / 1073741824.0];
}

#pragma mark - Finder
#pragma mark - Finder actions

- (BOOL)showFinderGetInfoForFile:(NSString *)path {
if (!path || [self canRevealFileAtPath:path] == NO) {
@@ -258,7 +256,7 @@ - (BOOL)showPackageContents:(NSString *)path {
return [self selectFile:contentsPath inFileViewerRootedAtPath:[contentsPath stringByDeletingLastPathComponent]];
}

#pragma mark -
#pragma mark - Util

- (BOOL)runAppleScript:(NSString *)scriptSource {
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:scriptSource];
20 changes: 14 additions & 6 deletions source/Util/STPrivilegedTask.h
Original file line number Diff line number Diff line change
@@ -53,17 +53,25 @@ extern const OSStatus errAuthorizationFnNoLongerExists;
+ (BOOL)authorizationFunctionAvailable;

- (instancetype)initWithLaunchPath:(NSString *)path;
- (instancetype)initWithLaunchPath:(NSString *)path arguments:(NSArray *)args;
- (instancetype)initWithLaunchPath:(NSString *)path arguments:(NSArray *)args currentDirectory:(NSString *)cwd;
- (instancetype)initWithLaunchPath:(NSString *)path
arguments:(NSArray *)args;
- (instancetype)initWithLaunchPath:(NSString *)path
arguments:(NSArray *)args
currentDirectory:(NSString *)cwd;

+ (STPrivilegedTask *)launchedPrivilegedTaskWithLaunchPath:(NSString *)path;
+ (STPrivilegedTask *)launchedPrivilegedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)args;
+ (STPrivilegedTask *)launchedPrivilegedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)args currentDirectory:(NSString *)cwd;
+ (STPrivilegedTask *)launchedPrivilegedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)args currentDirectory:(NSString *)cwd authorization:(AuthorizationRef)authorization;
+ (STPrivilegedTask *)launchedPrivilegedTaskWithLaunchPath:(NSString *)path
arguments:(NSArray *)args;
+ (STPrivilegedTask *)launchedPrivilegedTaskWithLaunchPath:(NSString *)path
arguments:(NSArray *)args
currentDirectory:(NSString *)cwd;
+ (STPrivilegedTask *)launchedPrivilegedTaskWithLaunchPath:(NSString *)path
arguments:(NSArray *)args
currentDirectory:(NSString *)cwd authorization:(AuthorizationRef)authorization;

- (OSStatus)launch;
- (OSStatus)launchWithAuthorization:(AuthorizationRef)authorization;
- (void)terminate; // doesn't work
// - (void)terminate; // doesn't work
- (void)waitUntilExit;

@end
23 changes: 14 additions & 9 deletions source/Util/STPrivilegedTask.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/*
STPrivilegedTask - NSTask-like wrapper around AuthorizationExecuteWithPrivileges
Copyright (C) 2008-2023 Sveinbjorn Thordarson <[email protected]>
BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor that of any other
contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor that of any other
contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -246,14 +251,14 @@ - (OSStatus)launchWithAuthorization:(AuthorizationRef)authorization {
return err;
}

- (void)terminate {
//- (void)terminate {
// This doesn't work without a PID, and we can't get one. Stupid Security API.
// int ret = kill(pid, SIGKILL);
//
// if (ret != 0) {
// NSLog(@"Error %d", errno);
// }
}
//}

// Hang until task is done
- (void)waitUntilExit {

0 comments on commit 1c9be32

Please sign in to comment.