Skip to content

Commit

Permalink
Fixed volume filtering for 10.15+ (popup now shows all mount points +…
Browse files Browse the repository at this point in the history
… volname if available) (#11)
  • Loading branch information
sveinbjornt committed Mar 17, 2021
1 parent 451225e commit c3fb0f3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 40 deletions.
24 changes: 6 additions & 18 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@

TODO for Sloth 3.1
TODO for Sloth 3.2
* Show full command (w/args) for process (ala ps -ef) in Info Panel
* Highlight matching part of string when filtering (option in filter field popup)
* Store authentication privileges and use them to run command line tool "/usr/bin/file"
* Show Path Control w. selected path at bottom of table view when item selected
* Fix split-APFS Volumes filtering
* "Case sensitive" filtering doesn't seem to work
* Handle "unknown file type:", show question mark icon
* Add tests for lsof output parsing

TODO for Sloth 3.0
DONE * Identifier for bundle processes is now lazy-loaded for a small performance gain
DONE * Spin off Lsof task and parsing into separate class, document the parsing and data structure produced
DONE * Make main controller slimmer
DONE * Move over to object-oriented model for items, lazy-load expensive properties such as bundle identifier, etc.
DONE * Show raw IP numbers briefly in Info Panel before IP socket DNS lookup, which can be slow
DONE * Move to Trash + file context menu operations no longer available for sockets
DONE * Process name shown under "Used by" should use Mac-friendly process name if enabled and available (see third screenshot)
DONE * Smart copying (tab-indent subfile names if process + subfiles selected)
DONE * File System in Info Panel should show name of volume and mount point, in addition to device ID and inode number
DONE * Fix broken bundle identifier loading
DONE * "Path" label in Info Window for IP sockets should show more intelligent label
DONE * Show Package Contents contextual menu item for bundle processes
DONE * New Big Sur style application icon
DONE * Support arm64

TODO for Sloth 3.1
DONE * Added default regex filters option to Prefs
DONE * Added optional update/refresh interval
DONE * Fixed buggy behaviour when authentication was cancelled
DONE * Fix split-APFS Volumes filtering
2 changes: 1 addition & 1 deletion resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>276</string>
<string>278</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
16 changes: 16 additions & 0 deletions source/SlothController.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

// Set icons for items in Filter menu
NSArray<NSMenuItem *> *items = [filterMenu itemArray];
int idx = 0;
for (NSMenuItem *i in items) {
idx += 1;
if (idx < 2) { // Skip first menu item (Show All)
continue;
}
NSString *type = [i toolTip];
if (type) {
NSImage *img = [IconUtils imageNamed:type];
Expand Down Expand Up @@ -338,6 +343,16 @@ - (void)controlTextDidChange:(NSNotification *)aNotification {

// VolumesPopUpDelegate
- (void)volumeSelectionChanged:(NSString *)volumePath {
// If can't do volume filtering on 10.15+
// if (@available(macOS 10.15, *)) {
// if ([[volumesPopupButton titleOfSelectedItem] isEqualToString:@"All"]) {
// return;
// }
// [volumesPopupButton selectItemAtIndex:0];
// [Alerts alert:@"Unable to filter by volume"
// subTextFormat:@"Volume filtering is not available on this version of macOS."];
// return;
// }
[self performSelector:@selector(updateFiltering) withObject:nil afterDelay:0.05];
}

Expand Down Expand Up @@ -478,6 +493,7 @@ - (NSMutableArray *)filterContent:(NSMutableArray *)unfilteredContent numberOfMa
}

if (volumesFilter) {
// DLog(@"%@ cmp %@", file[@"device"][@"devid"], volumesFilter);
if ([file[@"device"][@"devid"] isEqualToNumber:volumesFilter] == NO) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion source/Util/FSUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ + (NSDictionary *)mountedFileSystems {
};
}

DLog(@"File system info: %@", fsdict);
//DLog(@"File system info: %@", fsdict);

return [fsdict copy]; // Return immutable copy
}
Expand Down
65 changes: 45 additions & 20 deletions source/VolumesPopUpButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,39 +106,64 @@ - (void)populateMenu {
[volumesMenu addItem:item];
[volumesMenu addItem:[NSMenuItem separatorItem]];

NSArray *props = @[NSURLVolumeNameKey];
NSArray *urls = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:props
options:NSVolumeEnumerationSkipHiddenVolumes];
// Add all volumes as items
for (NSURL *url in urls) {
// NEW METHOD: Add all filesystems
for (NSNumber *fsid in [filesystems allKeys]) {
NSDictionary *fs = filesystems[fsid];
NSString *menuItemName = fs[@"mountpoint"];

// Get volume name, if possible
NSURL *url = [NSURL fileURLWithPath:fs[@"mountpoint"]];
NSString *volumeName;
NSError *err;
[url getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&err];
if (volumeName == nil) {
NSLog(@"%@", [err localizedDescription]);
continue;
if (volumeName != nil) {
menuItemName = [NSString stringWithFormat:@"%@ (%@)", fs[@"mountpoint"], volumeName];
}

SEL action = @selector(notifyDelegateSelectionHasChanged:);
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:volumeName
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:menuItemName
action:action
keyEquivalent:@""];
[item setTarget:self];
[item setToolTip:[url path]];

// Set filesystem info dict as represented object
for (NSNumber *fsid in filesystems) {
NSDictionary *fs = filesystems[fsid];
if ([fs[@"mountpoint"] isEqualToString:[url path]]) {
[item setRepresentedObject:fs];
break;
}
}

[item setToolTip:fs[@"mountpoint"]];
[item setRepresentedObject:fs];
[volumesMenu addItem:item];

}

// OLD METHOD: Add all volumes as items
// NSArray *props = @[NSURLVolumeNameKey];
// NSArray *urls = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:props
//
// for (NSURL *url in urls) {
//
// NSString *volumeName;
// NSError *err;
// [url getResourceValue:&volumeName forKey:NSURLVolumeNameKey error:&err];
// if (volumeName == nil) {
// NSLog(@"%@", [err localizedDescription]);
// continue;
// }
//
// SEL action = @selector(notifyDelegateSelectionHasChanged:);
// NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:volumeName
// action:action
// keyEquivalent:@""];
// [item setTarget:self];
// [item setToolTip:[url path]];
//
// // Set filesystem info dict as represented object
// for (NSNumber *fsid in filesystems) {
// NSDictionary *fs = filesystems[fsid];
// if ([fs[@"mountpoint"] isEqualToString:[url path]]) {
// [item setRepresentedObject:fs];
// break;
// }
// }
//
// [volumesMenu addItem:item];
// }

// Restore selection, if possible
NSMenuItem *itemToSelect = [volumesMenu itemArray][0];
for (NSMenuItem *item in [volumesMenu itemArray]) {
Expand Down

0 comments on commit c3fb0f3

Please sign in to comment.