Skip to content

Commit

Permalink
1.1 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
MTACS committed Dec 28, 2021
1 parent 5001601 commit c51f593
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 28 deletions.
20 changes: 20 additions & 0 deletions ReFinder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
1709F9662778AD8A00C35A97 /* ReFinder.m in Sources */ = {isa = PBXBuildFile; fileRef = 1709F9652778AD8A00C35A97 /* ReFinder.m */; };
1709F96A2778AD8A00C35A97 /* ZKSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1709F9692778AD8A00C35A97 /* ZKSwizzle.m */; };
1709F96C2778AD8A00C35A97 /* PrefixHeader.pch in Resources */ = {isa = PBXBuildFile; fileRef = 1709F96B2778AD8A00C35A97 /* PrefixHeader.pch */; };
1741270E27795BB20020949D /* ReFinderWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 1741270D27795BB20020949D /* ReFinderWindow.m */; };
17FA6E8027794186009C6D1B /* ReFinderPreferencesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 17FA6E7E27794186009C6D1B /* ReFinderPreferencesController.m */; };
17FA6E8127794186009C6D1B /* ReFinderPreferencesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17FA6E7F27794186009C6D1B /* ReFinderPreferencesController.xib */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -25,6 +28,11 @@
1709F9682778AD8A00C35A97 /* ZKSwizzle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZKSwizzle.h; sourceTree = "<group>"; };
1709F9692778AD8A00C35A97 /* ZKSwizzle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZKSwizzle.m; sourceTree = "<group>"; };
1709F96B2778AD8A00C35A97 /* PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PrefixHeader.pch; path = ../PrefixHeader.pch; sourceTree = "<group>"; };
1741270C27795BB20020949D /* ReFinderWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReFinderWindow.h; sourceTree = "<group>"; };
1741270D27795BB20020949D /* ReFinderWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReFinderWindow.m; sourceTree = "<group>"; };
17FA6E7D27794186009C6D1B /* ReFinderPreferencesController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReFinderPreferencesController.h; sourceTree = "<group>"; };
17FA6E7E27794186009C6D1B /* ReFinderPreferencesController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReFinderPreferencesController.m; sourceTree = "<group>"; };
17FA6E7F27794186009C6D1B /* ReFinderPreferencesController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ReFinderPreferencesController.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -73,6 +81,11 @@
1709F9652778AD8A00C35A97 /* ReFinder.m */,
1709F9672778AD8A00C35A97 /* ZKSwizzle */,
1709F9612778AD8A00C35A97 /* Supporting Files */,
17FA6E7D27794186009C6D1B /* ReFinderPreferencesController.h */,
17FA6E7E27794186009C6D1B /* ReFinderPreferencesController.m */,
17FA6E7F27794186009C6D1B /* ReFinderPreferencesController.xib */,
1741270C27795BB20020949D /* ReFinderWindow.h */,
1741270D27795BB20020949D /* ReFinderWindow.m */,
);
path = ReFinder;
sourceTree = "<group>";
Expand Down Expand Up @@ -152,6 +165,7 @@
buildActionMask = 2147483647;
files = (
1709F96C2778AD8A00C35A97 /* PrefixHeader.pch in Resources */,
17FA6E8127794186009C6D1B /* ReFinderPreferencesController.xib in Resources */,
1709F9632778AD8A00C35A97 /* Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -165,6 +179,8 @@
files = (
1709F9662778AD8A00C35A97 /* ReFinder.m in Sources */,
1709F96A2778AD8A00C35A97 /* ZKSwizzle.m in Sources */,
1741270E27795BB20020949D /* ReFinderWindow.m in Sources */,
17FA6E8027794186009C6D1B /* ReFinderPreferencesController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -293,6 +309,8 @@
INFOPLIST_FILE = ReFinder/Info.plist;
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.mtac.ReFinder;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = bundle;
Expand All @@ -314,6 +332,8 @@
INFOPLIST_FILE = ReFinder/Info.plist;
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.mtac.ReFinder;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = bundle;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "9E8CEACB-EE25-402E-A629-104C3D32B0DC"
type = "1"
version = "2.0">
</Bucket>
2 changes: 1 addition & 1 deletion ReFinder/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
5 changes: 4 additions & 1 deletion ReFinder/ReFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import "ZKSwizzle/ZKSwizzle.h"
#import "ReFinderPreferencesController.h"

@interface ReFinder : NSObject
@interface ReFinder : NSObject // <NSUserInterfaceValidations>
+ (instancetype)sharedInstance;
- (void)restartFinder;
- (void)openSourceCode;
@end
140 changes: 114 additions & 26 deletions ReFinder/ReFinder.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
ReFinder *plugin;
NSUserDefaults *defaults;
NSMutableDictionary *finderDictionary;
static NSUserDefaults *preferences = nil;
static NSDictionary *preferencesDict = nil;

@implementation ReFinder
+ (instancetype)sharedInstance {
Expand All @@ -23,56 +25,132 @@ + (instancetype)sharedInstance {
+ (void)load {
defaults = [NSUserDefaults standardUserDefaults];
plugin = [ReFinder sharedInstance];
[plugin loadSections];

finderDictionary = [[defaults persistentDomainForName:@"com.apple.finder"] mutableCopy];

for (NSString *key in [finderDictionary allKeys]) {
NSLog(@"[REFINDER] : Key/Value -> %@, %@", key, [finderDictionary objectForKey:key]);
}
NSUInteger osx_ver_min = [[NSProcessInfo processInfo] operatingSystemVersion].minorVersion;
NSUInteger osx_ver_maj = [[NSProcessInfo processInfo] operatingSystemVersion].majorVersion;

NSUInteger osx_ver = [[NSProcessInfo processInfo] operatingSystemVersion].minorVersion;
NSLog(@"[REFINDER] : %@ loaded into %@ on macOS 10.%ld", [plugin class], [[NSBundle mainBundle] bundleIdentifier], (long)osx_ver);
NSLog(@"[REFINDER] : %@ loaded into %@ on macOS %ld.%ld", [plugin class], [[NSBundle mainBundle] bundleIdentifier], (long)osx_ver_maj, (long)osx_ver_min);

NSMenu *mainFinderMenu = [[[[NSApp mainMenu] itemArray] firstObject] submenu];

NSMenu *reFinderSubMenu = [[NSMenu alloc] initWithTitle:@"ReFinder"];
[[reFinderSubMenu addItemWithTitle:@"Restart Finder" action:@selector(restartFinder) keyEquivalent:@""] setTarget:plugin];
[reFinderSubMenu addItem:[NSMenuItem separatorItem]];
[[reFinderSubMenu addItemWithTitle:@"Show Hidden Files" action:@selector(showHidden) keyEquivalent:@""] setTarget:plugin];
[[reFinderSubMenu addItemWithTitle:@"Hide Hidden Files" action:@selector(hideHidden) keyEquivalent:@""] setTarget:plugin];
NSMenuItem *restartItem = [[NSMenuItem alloc] init];
[restartItem setTitle:@"Restart Finder"];
[restartItem setKeyEquivalent:@""];
[restartItem setTarget:plugin];
[restartItem setAction:@selector(restartFinder)];
[reFinderSubMenu addItem:restartItem];

[reFinderSubMenu addItem:[NSMenuItem separatorItem]];
[[reFinderSubMenu addItemWithTitle:@"Show Desktop Icons" action:@selector(showDesktopIcons) keyEquivalent:@""] setTarget:plugin];
[[reFinderSubMenu addItemWithTitle:@"Hide Desktop Icons" action:@selector(hideDesktopIcons) keyEquivalent:@""] setTarget:plugin];

NSMenu *reFinderTools = [[NSMenu alloc] initWithTitle:@"Tools"];

NSMenuItem *toggleHiddenItem = [[NSMenuItem alloc] init];
[toggleHiddenItem setTarget:plugin];
[toggleHiddenItem setAction:@selector(toggleHidden:)];
[toggleHiddenItem setKeyEquivalent:@""];
if ([plugin hiddenFilesAreShown]) {
[toggleHiddenItem setTitle:@"Hide Hidden Files"];
} else {
[toggleHiddenItem setTitle:@"Show Hidden Files"];
}
[reFinderTools addItem:toggleHiddenItem];

[reFinderTools addItem:[NSMenuItem separatorItem]];

NSMenuItem *toggleDesktopItem = [[NSMenuItem alloc] init];
[toggleDesktopItem setTarget:plugin];
[toggleDesktopItem setAction:@selector(toggleDesktop:)];
[toggleDesktopItem setKeyEquivalent:@""];
if ([plugin desktopIconsAreShown]) {
[toggleDesktopItem setTitle:@"Hide Desktop Icons"];
} else {
[toggleDesktopItem setTitle:@"Show Desktop Icons"];
}
[reFinderTools addItem:toggleDesktopItem];

NSMenuItem *reFinderItem = [[NSMenuItem alloc] initWithTitle:@"ReFinder" action:nil keyEquivalent:@""];

NSMenuItem *reFinderToolsItem = [[NSMenuItem alloc] initWithTitle:@"Tools" action:nil keyEquivalent:@""];
[reFinderSubMenu addItem:reFinderToolsItem];
[mainFinderMenu setSubmenu:reFinderTools forItem:reFinderToolsItem];

[mainFinderMenu addItem:[NSMenuItem separatorItem]];
[mainFinderMenu addItem:reFinderItem];
[mainFinderMenu setSubmenu:reFinderSubMenu forItem:reFinderItem];

[reFinderSubMenu addItem:[NSMenuItem separatorItem]];

[[reFinderSubMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences) keyEquivalent:@""] setTarget:plugin];
}
- (void)showHidden {
- (void)loadSections {
finderDictionary = [[defaults persistentDomainForName:@"com.apple.finder"] mutableCopy];
[finderDictionary setValue:[NSNumber numberWithBool:1] forKey:@"AppleShowAllFiles"];
[defaults setPersistentDomain:finderDictionary forName:@"com.apple.finder"];
[plugin restartFinder];
NSMenu *mainFinderMenu = [NSApp mainMenu];
for (NSMenuItem *item in mainFinderMenu.itemArray) { // Feels like it could be done cleaner
if ([[finderDictionary objectForKey:@"hideFileItem"] boolValue] == 1 && [item.title isEqualToString:@"File"]) {
[item setHidden:YES];
}
if ([[finderDictionary objectForKey:@"hideEditItem"] boolValue] == 1 && [item.title isEqualToString:@"Edit"]) {
[item setHidden:YES];
}
if ([[finderDictionary objectForKey:@"hideViewItem"] boolValue] == 1 && [item.title isEqualToString:@"View"]) {
[item setHidden:YES];
}
if ([[finderDictionary objectForKey:@"hideGoItem"] boolValue] == 1 && [item.title isEqualToString:@"Go"]) {
[item setHidden:YES];
}
if ([[finderDictionary objectForKey:@"hideWindowItem"] boolValue] == 1 && [item.title isEqualToString:@"Window"]) {
[item setHidden:YES];
}
if ([[finderDictionary objectForKey:@"hideHelpItem"] boolValue] == 1 && [item.title isEqualToString:@"Help"]) {
[item setHidden:YES];
}
}
}
- (void)showPreferences {
ReFinderPreferencesController *prefsController = [[ReFinderPreferencesController alloc] init];
NSWindow *prefsWindow = [prefsController window];
[prefsWindow setStyleMask:prefsWindow.styleMask|NSWindowStyleMaskFullSizeContentView];
NSVisualEffectView *vibrant = [[NSClassFromString(@"NSVisualEffectView") alloc] initWithFrame:[[prefsWindow contentView] bounds]];
[vibrant setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[vibrant setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
[vibrant setIdentifier:@"rfView"];
[[prefsWindow contentView] addSubview:vibrant positioned:NSWindowBelow relativeTo:nil];
[prefsWindow makeKeyAndOrderFront:plugin];
}
- (void)hideHidden {
- (void)toggleHidden:(NSMenuItem *)sender {
finderDictionary = [[defaults persistentDomainForName:@"com.apple.finder"] mutableCopy];
[finderDictionary setValue:[NSNumber numberWithBool:0] forKey:@"AppleShowAllFiles"];
if ([plugin hiddenFilesAreShown]) {
[finderDictionary setValue:[NSNumber numberWithBool:0] forKey:@"AppleShowAllFiles"];
[sender setTitle:@"0"];
} else {
[finderDictionary setValue:[NSNumber numberWithBool:1] forKey:@"AppleShowAllFiles"];
[sender setTitle:@"1"];
}
[defaults setPersistentDomain:finderDictionary forName:@"com.apple.finder"];
[plugin restartFinder];
}
- (void)showDesktopIcons {
- (void)toggleDesktop:(id)sender {
finderDictionary = [[defaults persistentDomainForName:@"com.apple.finder"] mutableCopy];
[finderDictionary setValue:[NSNumber numberWithBool:1] forKey:@"CreateDesktop"];

if ([plugin desktopIconsAreShown]) {
[finderDictionary setValue:[NSNumber numberWithBool:0] forKey:@"CreateDesktop"];
[sender setTitle:@"0"];
} else {
[finderDictionary setValue:[NSNumber numberWithBool:1] forKey:@"CreateDesktop"];
[sender setTitle:@"1"];
}
[defaults setPersistentDomain:finderDictionary forName:@"com.apple.finder"];
[plugin restartFinder];
}
- (void)hideDesktopIcons {
- (BOOL)hiddenFilesAreShown {
finderDictionary = [[defaults persistentDomainForName:@"com.apple.finder"] mutableCopy];
[finderDictionary setValue:[NSNumber numberWithBool:0] forKey:@"CreateDesktop"];
[defaults setPersistentDomain:finderDictionary forName:@"com.apple.finder"];
[plugin restartFinder];
return [[finderDictionary objectForKey:@"AppleShowAllFiles"] boolValue];
}
- (BOOL)desktopIconsAreShown {
finderDictionary = [[defaults persistentDomainForName:@"com.apple.finder"] mutableCopy];
return [[finderDictionary objectForKey:@"CreateDesktop"] boolValue];
}

// https://github.com/w0lfschild/podcastsPlus/blob/182809f07326f5364954addc47ccd0dd8e83d6de/podcastsPlus/podcastsPlus.m#L424
Expand All @@ -89,14 +167,24 @@ - (void)restartFinder {
[task launch];
[NSApp terminate:nil];
}
- (void)openSourceCode {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://github.com/MTACS/ReFinder"]];
}
- (void)initializePrefs {
if (!preferences) {
preferences = [[NSUserDefaults alloc] initWithSuiteName:@"com.mtac.refinder"];
preferencesDict = [preferences dictionaryRepresentation];
}
[preferences synchronize];
}
@end

ZKSwizzleInterface(rf_AboutController, TAboutWindowController, NSWindowController)
@implementation rf_AboutController
- (void)windowDidLoad {
ZKOrig(void);
NSTextField *field = (NSTextField *)[self.window.contentView.subviews lastObject];
[field setStringValue:[NSString stringWithFormat:@"%@\n\nReFinder 1.0 © MTAC", field.stringValue]];
[field setStringValue:[NSString stringWithFormat:@"%@\n\nReFinder 1.1 © MTAC", field.stringValue]];
}
@end

Expand Down
11 changes: 11 additions & 0 deletions ReFinder/ReFinderPreferencesController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ReFinderPreferencesController.h
// ReFinder
//
// Created by MTAC on 12/26/21.
//

#import <Cocoa/Cocoa.h>

@interface ReFinderPreferencesController : NSWindowController
@end
21 changes: 21 additions & 0 deletions ReFinder/ReFinderPreferencesController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// ReFinderPreferencesController.m
// ReFinder
//
// Created by MTAC on 12/26/21.
//

#import "ReFinderPreferencesController.h"

@interface ReFinderPreferencesController ()
@end

@implementation ReFinderPreferencesController
- (void)windowDidLoad {
[super windowDidLoad];
}
- (id)init {
self = [super initWithWindowNibName:@"ReFinderPreferencesController"];
return self;
}
@end
Loading

0 comments on commit c51f593

Please sign in to comment.