Skip to content

Commit

Permalink
Don't init UI until needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jslegendre committed May 22, 2020
1 parent f4f4b4c commit 0d9cb5c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
8 changes: 4 additions & 4 deletions AfloatX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.3.5;
CURRENT_PROJECT_VERSION = 1.3.6;
DEPLOYMENT_LOCATION = YES;
DEVELOPMENT_TEAM = 6LAE5ASX7M;
DSTROOT = /;
Expand All @@ -318,7 +318,7 @@
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.3.5;
MARKETING_VERSION = 1.3.6;
PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.AfloatX;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = bundle;
Expand All @@ -331,7 +331,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.3.5;
CURRENT_PROJECT_VERSION = 1.3.6;
DEPLOYMENT_LOCATION = YES;
DEVELOPMENT_TEAM = 6LAE5ASX7M;
DSTROOT = /;
Expand All @@ -342,7 +342,7 @@
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.3.5;
MARKETING_VERSION = 1.3.6;
PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.AfloatX;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = bundle;
Expand Down
41 changes: 23 additions & 18 deletions AfloatX/AfloatX.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import <objc/runtime.h>
#import <objc/message.h>

WindowTransparencyController *transparencyController;
NSMenu *AfloatXMenu;
NSMenuItem *AfloatXItem;
NSMenu *AfloatXSubmenu;
Expand Down Expand Up @@ -147,25 +146,30 @@ - (void)toggleDropMainWindow {
}

- (void)showTransparencySheet {
[transparencyController runSheetForWindow:[AXWindowUtils windowToModify]];
[[WindowTransparencyController sharedInstance] runSheetForWindow:[AXWindowUtils windowToModify]];
if([self isMainWindowFloating]) {
[AXWindowUtils setMainWindowLevel:kCGFloatingWindowLevel];
}
}

+ (void)load {
AfloatX *plugin = [AfloatX sharedInstance];
NSArray *blackList = [[NSArray alloc] initWithObjects:@"com.apple.dock", @"com.vmware.vmware-vmx", @"com.apple.loginwindow", nil];
if([NSBundle mainBundle] == NULL)
return;

if(NSBundle.mainBundle.bundleIdentifier == NULL)
return;

NSArray *blackList = [[NSArray alloc] initWithObjects:@"com.apple.dock", @"com.vmware.vmware-vmx", @"com.apple.loginwindow", @"com.apple.Spotlight", @"com.apple.SystemUIServer", @"com.apple.screencaptureui", nil];
if ([blackList containsObject:NSBundle.mainBundle.bundleIdentifier])
return;

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


AfloatX *plugin = [AfloatX sharedInstance];

colorInvertFilter = [CIFilter filterWithName:@"CIColorInvert"];
[colorInvertFilter setDefaults];

transparencyController = [WindowTransparencyController sharedInstance];

AfloatXMenu = [NSMenu new];
AfloatXItem = [NSMenuItem new];
Expand Down Expand Up @@ -195,19 +199,20 @@ + (void)load {

clickPassthroughItem = [[NSMenuItem alloc] initWithTitle:@"Click-Through Window" action:@selector(toggleEventPassthrough) keyEquivalent:@""];
[clickPassthroughItem setTarget:plugin];

transparencyItem = [[NSMenuItem alloc] initWithTitle:@"Transparency..." action:@selector(showTransparencySheet) keyEquivalent:@""];
[transparencyItem setTarget:plugin];

afloatXItems = [[NSArray alloc] initWithObjects:floatItem,
dropItem,
invertColorItem,
stickyItem,
transientItem,
clickPassthroughItem,
windowOutlineItem,
transparencyItem,
nil];
dropItem,
invertColorItem,
stickyItem,
transientItem,
clickPassthroughItem,
windowOutlineItem,
transparencyItem,
nil];

[AfloatXSubmenu setItemArray:afloatXItems];

[AfloatXMenu addItem:[NSMenuItem separatorItem]];
Expand All @@ -223,7 +228,7 @@ - (CFArrayRef)_createDockMenu:(BOOL)enabled {
if(!window) {
return ZKOrig(CFArrayRef, enabled);
}

// Make any necessary changes to our menu before it is 'flattened'
if([[AfloatX sharedInstance] isWindowTransient:window]) {
[transientItem setState:NSControlStateValueOn];
Expand Down

0 comments on commit 0d9cb5c

Please sign in to comment.