Initial commit.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface AboutViewController : NSViewController
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,163 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "AboutViewController.h"
|
||||
|
||||
@implementation AboutViewController {
|
||||
NSFont *_fontSubheadline;
|
||||
NSFont *_fontTitle1Bold;
|
||||
|
||||
NSImage *_appImage;
|
||||
NSImageView *_iconImageView;
|
||||
|
||||
NSTextField *_appNameLabel;
|
||||
NSTextField *_versionLabel;
|
||||
NSTextField *_copyrightLabel;
|
||||
|
||||
NSLayoutGuide *_buttonsLayoutGuide;
|
||||
/* NSButton *_button; */
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
/* Setup fonts. */
|
||||
CGFloat size = [[NSFontDescriptor preferredFontDescriptorForTextStyle:
|
||||
NSFontTextStyleSubheadline options:@{}] pointSize];
|
||||
_fontSubheadline = [[NSFont systemFontOfSize:size] retain];
|
||||
|
||||
size = [[NSFontDescriptor preferredFontDescriptorForTextStyle:
|
||||
NSFontTextStyleTitle1 options:@{}] pointSize];
|
||||
_fontTitle1Bold = [[NSFont systemFontOfSize:size
|
||||
weight:NSFontWeightBold] retain];
|
||||
|
||||
/* Program info. */
|
||||
NSString *programName = [[NSBundle mainBundle]
|
||||
objectForInfoDictionaryKey:@"CFBundleName"];
|
||||
NSString *programVersion = [[NSBundle mainBundle]
|
||||
objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
||||
|
||||
/* TODO: "String literals" do not belong in here. */
|
||||
NSMutableString *appVersionMutStr = [[NSMutableString alloc] init];
|
||||
[appVersionMutStr appendString:@"Version: "];
|
||||
[appVersionMutStr appendString:
|
||||
(programVersion ? programVersion : @"-.--")];
|
||||
|
||||
/* Labels. */
|
||||
_appNameLabel = [[NSTextField labelWithString:
|
||||
(programName ? programName : @"NO")] retain];
|
||||
[_appNameLabel setFont:_fontTitle1Bold];
|
||||
[_appNameLabel setAlignment:NSTextAlignmentCenter];
|
||||
[_appNameLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
|
||||
_versionLabel = [[NSTextField labelWithString:appVersionMutStr] retain];
|
||||
[_versionLabel setFont:_fontSubheadline];
|
||||
[_versionLabel setTextColor:[NSColor systemGrayColor]];
|
||||
[_versionLabel setAlignment:NSTextAlignmentCenter];
|
||||
[_versionLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
|
||||
_copyrightLabel = [[NSTextField labelWithString:
|
||||
@"Copyright © 2025\nGarikMI. All rights reserved."] retain];
|
||||
[_copyrightLabel setFont:_fontSubheadline];
|
||||
[_copyrightLabel setTextColor:[NSColor systemGrayColor]];
|
||||
[_copyrightLabel setAlignment:NSTextAlignmentCenter];
|
||||
[_copyrightLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
|
||||
/* Program icon. */
|
||||
_iconImageView = [[NSImageView alloc] init];
|
||||
[_iconImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
|
||||
_appImage = [[[NSWorkspace sharedWorkspace] iconForFile:
|
||||
[[NSBundle mainBundle] bundlePath]] retain];
|
||||
[_iconImageView setImage:_appImage];
|
||||
[_iconImageView setImageScaling:NSImageScaleAxesIndependently];
|
||||
|
||||
/* Link buttons. */
|
||||
/* _buttonsLayoutGuide = [[NSLayoutGuide alloc] init]; */
|
||||
|
||||
/* _button = [[NSButton alloc] init]; */
|
||||
/* [_button setTitle:@"Test"]; */
|
||||
/* [_button sizeToFit]; */
|
||||
/* [_button setTranslatesAutoresizingMaskIntoConstraints:NO]; */
|
||||
|
||||
/* Constraints. */
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[[[self view] widthAnchor] constraintEqualToConstant:300.0],
|
||||
[[[self view] heightAnchor] constraintLessThanOrEqualToConstant:
|
||||
500.0]
|
||||
]];
|
||||
|
||||
[[self view] addSubview:_iconImageView];
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[[_iconImageView widthAnchor] constraintEqualToConstant:100.0],
|
||||
[[_iconImageView heightAnchor] constraintEqualToAnchor:
|
||||
[_iconImageView widthAnchor]],
|
||||
[[_iconImageView topAnchor] constraintEqualToAnchor:
|
||||
[[self view] topAnchor] constant:20.0],
|
||||
[[_iconImageView centerXAnchor] constraintEqualToAnchor:
|
||||
[[self view] centerXAnchor]]
|
||||
]];
|
||||
|
||||
[[self view] addSubview:_appNameLabel];
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[[_appNameLabel centerXAnchor] constraintEqualToAnchor:
|
||||
[[self view] centerXAnchor]],
|
||||
[[_appNameLabel topAnchor] constraintEqualToAnchor:
|
||||
[_iconImageView bottomAnchor] constant:20.0]
|
||||
]];
|
||||
|
||||
[[self view] addSubview:_versionLabel];
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[[_versionLabel centerXAnchor] constraintEqualToAnchor:
|
||||
[[self view] centerXAnchor]],
|
||||
[[_versionLabel topAnchor] constraintEqualToAnchor:
|
||||
[_appNameLabel bottomAnchor] constant:2.0],
|
||||
]];
|
||||
|
||||
[[self view] addSubview:_copyrightLabel];
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[[_copyrightLabel centerXAnchor] constraintEqualToAnchor:
|
||||
[[self view] centerXAnchor]],
|
||||
[[_copyrightLabel topAnchor] constraintEqualToAnchor:
|
||||
[_versionLabel bottomAnchor] constant:20.0],
|
||||
[[_copyrightLabel bottomAnchor] constraintEqualToAnchor:
|
||||
[[self view] bottomAnchor] constant:-20.0]
|
||||
]];
|
||||
|
||||
/* [[self view] addLayoutGuide:_buttonsLayoutGuide]; */
|
||||
/* [[self view] addSubview:_button]; */
|
||||
/* [NSLayoutConstraint activateConstraints:@[ */
|
||||
/* [[_buttonsLayoutGuide centerXAnchor] constraintEqualToAnchor:[[self view] centerXAnchor]], */
|
||||
/* [[_buttonsLayoutGuide topAnchor] constraintEqualToAnchor:[_copyrightLabel bottomAnchor] constant:20.0], */
|
||||
/* [[_buttonsLayoutGuide bottomAnchor] constraintEqualToAnchor:[[self view] bottomAnchor] constant:-20.0], */
|
||||
|
||||
/* [[_button topAnchor] constraintEqualToAnchor:[_buttonsLayoutGuide topAnchor]], */
|
||||
/* [[_button bottomAnchor] constraintEqualToAnchor:[_buttonsLayoutGuide bottomAnchor]], */
|
||||
/* [[_button leadingAnchor] constraintEqualToAnchor:[_buttonsLayoutGuide leadingAnchor]], */
|
||||
/* [[_button trailingAnchor] constraintEqualToAnchor:[_buttonsLayoutGuide trailingAnchor]] */
|
||||
/* ]]; */
|
||||
}
|
||||
|
||||
- (void)setRepresentedObject:(id)representedObject {
|
||||
[super setRepresentedObject:representedObject];
|
||||
|
||||
// Update the view, if already loaded.
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_fontSubheadline release];
|
||||
[_fontTitle1Bold release];
|
||||
|
||||
[_appImage release];
|
||||
[_iconImageView release];
|
||||
|
||||
[_appNameLabel release];
|
||||
[_versionLabel release];
|
||||
[_copyrightLabel release];
|
||||
|
||||
[_buttonsLayoutGuide release];
|
||||
/* [_button release]; */
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,6 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,208 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <IOKit/pwr_mgt/IOPMLib.h>
|
||||
#import <ServiceManagement/ServiceManagement.h>
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
#import "MenulessWindow.h"
|
||||
#import "AboutViewController.h"
|
||||
|
||||
@interface AppDelegate ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppDelegate {
|
||||
NSImage *_imageON;
|
||||
NSImage *_imageOFF;
|
||||
|
||||
NSStatusItem *_statusItem;
|
||||
|
||||
NSMenu *_menu;
|
||||
NSMenuItem *_loginMenuItem;
|
||||
|
||||
NSEvent *_eventMonitor;
|
||||
|
||||
BOOL awake;
|
||||
IOPMAssertionID _assertionID;
|
||||
|
||||
AboutViewController *_aboutViewController;
|
||||
MenulessWindow *_aboutWindow;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
[self setupIcons];
|
||||
[self setupMenu];
|
||||
[self setupWindows];
|
||||
|
||||
[self updateButtonState];
|
||||
[self updateLaunchAtLoginStatus];
|
||||
|
||||
_eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:
|
||||
NSEventMaskLeftMouseDown|NSEventMaskRightMouseDown
|
||||
handler:^NSEvent * _Nullable(NSEvent *event)
|
||||
{
|
||||
if([event window] == [[_statusItem button] window] &&
|
||||
!containsFlags([event modifierFlags], NSEventModifierFlagCommand))
|
||||
{
|
||||
if([event type] == NSEventTypeLeftMouseDown) {
|
||||
if(awake)
|
||||
[self disableWake];
|
||||
else
|
||||
[self enableWake];
|
||||
[self updateButtonState];
|
||||
} else if([event type] == NSEventTypeRightMouseDown) {
|
||||
[self displayMenu];
|
||||
}
|
||||
}
|
||||
return event;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Setup.
|
||||
- (void)setupIcons {
|
||||
_imageON = [[NSImage imageWithSystemSymbolName:@"cup.and.saucer.fill"
|
||||
accessibilityDescription:nil] retain];
|
||||
_imageOFF = [[NSImage imageWithSystemSymbolName:@"cup.and.saucer"
|
||||
accessibilityDescription:nil] retain];
|
||||
}
|
||||
|
||||
- (void)setupMenu {
|
||||
_statusItem = [[[NSStatusBar systemStatusBar]
|
||||
statusItemWithLength:NSVariableStatusItemLength] retain];
|
||||
|
||||
_menu = [[NSMenu alloc] init];
|
||||
_loginMenuItem = [[NSMenuItem alloc] initWithTitle:@"Launch At Login"
|
||||
action:@selector(toggleLaunchAtLogin)
|
||||
keyEquivalent:@""];
|
||||
|
||||
[_menu addItemWithTitle:@"About"
|
||||
action:@selector(displayAboutWindow)
|
||||
keyEquivalent:@"i"];
|
||||
[_menu addItem:[NSMenuItem separatorItem]];
|
||||
[_menu addItem:_loginMenuItem];
|
||||
[_menu addItem:[NSMenuItem separatorItem]];
|
||||
[_menu addItemWithTitle:@"Quit"
|
||||
action:@selector(terminateApplication)
|
||||
keyEquivalent:@"q"];
|
||||
}
|
||||
|
||||
- (void)setupWindows {
|
||||
_aboutViewController = [[AboutViewController alloc] init];
|
||||
_aboutWindow = [[MenulessWindow alloc]
|
||||
initWithContentViewController:_aboutViewController];
|
||||
[_aboutWindow setLevel:NSStatusWindowLevel];
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Actions.
|
||||
- (void)displayAboutWindow {
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
[_aboutWindow makeKeyAndOrderFront:nil];
|
||||
[_aboutWindow center];
|
||||
}
|
||||
|
||||
- (void)updateLaunchAtLoginStatus {
|
||||
if([self willLaunchAtLogin])
|
||||
[_loginMenuItem setTitle:@"Disable Launch At Login"];
|
||||
else
|
||||
[_loginMenuItem setTitle:@"Enable Launch At Login"];
|
||||
}
|
||||
|
||||
- (void)terminateApplication {
|
||||
[[NSApplication sharedApplication] terminate:nil];
|
||||
}
|
||||
|
||||
- (void)displayMenu {
|
||||
NSScreen *scrn = [NSScreen mainScreen];
|
||||
CGPoint itemOrigin = [[[_statusItem button] window] frame].origin;
|
||||
|
||||
// NOTE: -5 because NSMenu pops up higher than wanted; don't know how
|
||||
// it will behave on different displays and resolutions.
|
||||
CGFloat y =
|
||||
NSHeight([scrn visibleFrame]) + [scrn visibleFrame].origin.y - 5;
|
||||
|
||||
[self setButtonHighlighted:YES];
|
||||
|
||||
[_menu popUpMenuPositioningItem:nil
|
||||
atLocation:NSMakePoint(itemOrigin.x, y)
|
||||
inView:nil];
|
||||
}
|
||||
|
||||
- (void)updateButtonState {
|
||||
[[_statusItem button] setImage:(awake ? _imageON : _imageOFF)];
|
||||
}
|
||||
|
||||
- (BOOL)willLaunchAtLogin {
|
||||
BOOL state = NO;
|
||||
SMAppService *service = [[SMAppService mainAppService] retain];
|
||||
|
||||
state = ([service status] == SMAppServiceStatusEnabled);
|
||||
|
||||
[service release];
|
||||
return state;
|
||||
}
|
||||
|
||||
- (void)launchAtLogin:(BOOL)state {
|
||||
SMAppService *service = [[SMAppService mainAppService] retain];
|
||||
|
||||
if(state && [service status] != SMAppServiceStatusEnabled)
|
||||
[service registerAndReturnError:nil];
|
||||
else if([service status] == SMAppServiceStatusEnabled)
|
||||
[service unregisterAndReturnError:nil];
|
||||
|
||||
[service release];
|
||||
}
|
||||
|
||||
- (void)toggleLaunchAtLogin {
|
||||
[self launchAtLogin:![self willLaunchAtLogin]];
|
||||
[self updateLaunchAtLoginStatus];
|
||||
}
|
||||
|
||||
- (void)setButtonHighlighted:(BOOL)state {
|
||||
[[_statusItem button] highlight:state];
|
||||
}
|
||||
|
||||
- (void)enableWake {
|
||||
if(!awake) {
|
||||
IOReturn err = IOPMAssertionCreateWithName(
|
||||
kIOPMAssertionTypeNoDisplaySleep,
|
||||
kIOPMAssertionLevelOn,
|
||||
CFSTR("Caffeine Preventing Sleep"),
|
||||
&_assertionID);
|
||||
awake = (err == kIOReturnSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)disableWake {
|
||||
if(awake) {
|
||||
IOPMAssertionRelease(_assertionID);
|
||||
awake = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
/* NOTE: This is all useless because this program should not exist without AppDelegate.
|
||||
* If this point is reached, no clean up is needed, program is terminated. */
|
||||
/*[_imageON release];
|
||||
[_imageOFF release];
|
||||
[_statusItem release];
|
||||
[_menu release];
|
||||
[_aboutViewController release];
|
||||
[_aboutWindow release];
|
||||
[self disableWake];*/
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/*- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app {
|
||||
return YES;
|
||||
}*/
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<false/>
|
||||
<key>com.apple.security.get-task-allow</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef HELPERS_H_SENTRY
|
||||
#define HELPERS_H_SENTRY
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#define OS_MODS (NSUInteger)(NSEventModifierFlagControl |\
|
||||
NSEventModifierFlagCommand |\
|
||||
NSEventModifierFlagOption |\
|
||||
NSEventModifierFlagShift)
|
||||
|
||||
BOOL modsContains(NSUInteger keys, NSUInteger modifiers);
|
||||
BOOL modsContainsNone(NSUInteger modifiers);
|
||||
BOOL containsFlags(NSUInteger flags, NSUInteger key);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "Helpers.h"
|
||||
|
||||
BOOL modsContains(NSUInteger keys, NSUInteger modifiers)
|
||||
{
|
||||
return (modifiers & keys) == keys && ((modifiers ^ keys) & OS_MODS) == 0;
|
||||
}
|
||||
|
||||
BOOL modsContainsNone(NSUInteger modifiers)
|
||||
{
|
||||
return (modifiers & OS_MODS) == 0;
|
||||
}
|
||||
|
||||
BOOL containsFlags(NSUInteger flags, NSUInteger key) {
|
||||
return (flags & key) == key;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>Caffeine</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>AppIcon</string>
|
||||
<key>CFBundleIconName</key>
|
||||
<string>AppIcon</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.garikme.Caffeine</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Caffeine</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.2</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>0.2</string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>macosx</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>15.0</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx15.0</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>13.0</string>
|
||||
<key>LSUIElement</key>
|
||||
<true/>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,28 @@
|
||||
CC = clang
|
||||
# FLAGS = -fno-objc-arc -Wall -Wextra -Wunguarded-availability \
|
||||
# -Werror=unguarded-availability -glldb -fno-caret-diagnostics \
|
||||
# -fno-show-column
|
||||
FLAGS = -O3
|
||||
FRAMEWORKS = -framework Cocoa -framework IOKit -framework ServiceManagement
|
||||
MACOS_VERSION = 13.0
|
||||
EXEC = Caffeine
|
||||
|
||||
default: $(EXEC) $(EXEC).app
|
||||
|
||||
# TODO: Add x86 support.
|
||||
# -mmacosx-version-min=$(MACOS_VERSION)
|
||||
$(EXEC): main.m AppDelegate.m AboutViewController.m MenulessWindow.m \
|
||||
Helpers.m
|
||||
$(CC) $(FLAGS) -target arm64-apple-macos$(MACOS_VERSION) \
|
||||
-sectcreate __TEXT __info_plist Info.plist $^ $(FRAMEWORKS) -o $@
|
||||
|
||||
$(EXEC).app: $(EXEC)
|
||||
@rm -rf $@
|
||||
@mkdir -p $@/Contents/MacOS/ && \
|
||||
mkdir -p $@/Contents/Resources/ && \
|
||||
cp Info.plist $@/Contents/ && \
|
||||
cp resources/AppIcon.icns $@/Contents/Resources/ && \
|
||||
cp $(EXEC) $@/Contents/MacOS/
|
||||
|
||||
clean:
|
||||
rm -rf $(EXEC) $(EXEC).dSYM $(EXEC).app
|
||||
@@ -0,0 +1,94 @@
|
||||
# main.m AppDelegate.m -framework Cocoa -o main
|
||||
|
||||
CC=clang
|
||||
FLAGS = -Wall -Wextra -glldb -fno-caret-diagnostics -fno-show-column
|
||||
MACOS_VERSION = 13.0
|
||||
SDK = $(shell xcrun --show-sdk-path)
|
||||
XCODE_PATH = $(shell xcode-select --print-path)
|
||||
|
||||
EXEC = Caffeine
|
||||
|
||||
SRCMODULES = AppDelegate.swift AboutViewController.swift \
|
||||
MenulessWindow.swift Helpers.swift HotKeyManager.swift \
|
||||
EventMonitor.swift main.swift
|
||||
ARMOBJMODULES = $(addprefix ./arm64/,$(SRCMODULES:.swift=.o))
|
||||
X86OBJMODULES = $(addprefix ./x86_64/,$(SRCMODULES:.swift=.o))
|
||||
|
||||
LIBS =
|
||||
|
||||
FRAMEWORKS = -framework AppKit -framework ServiceManagement
|
||||
|
||||
default: $(EXEC).app
|
||||
|
||||
# HACK: Target is getting touched because timestamps of the generated
|
||||
# object file don't change unless there's an actual change in the
|
||||
# outputted object code. This results in this target running every
|
||||
# single time. I'm not sure whether that's the exact reason, but
|
||||
# I can't imagine why timestamps wouldn't change. When clang
|
||||
# generates same exact executable, timestamps do change.
|
||||
./arm64/%.o: %.swift
|
||||
swift -frontend -c -target arm64-apple-macos$(MACOS_VERSION) $(FLAGS) \
|
||||
-primary-file $< $(filter-out $<, $(SRCMODULES)) $(LIBS) \
|
||||
$(FRAMEWORKS) -sdk $(SDK) -module-name $(EXEC) -o $@ \
|
||||
-emit-module && \
|
||||
touch $@
|
||||
|
||||
ifdef UNIVERSAL
|
||||
./x86_64/%.o: %.swift
|
||||
@swift -frontend -c -target x86_64-apple-macos$(MACOS_VERSION) \
|
||||
$(FLAGS) -primary-file $< $(filter-out $<, $(SRCMODULES)) \
|
||||
$(LIBS) $(FRAMEWORKS) -sdk $(SDK) -module-name $(EXEC) -o $@ \
|
||||
-emit-module && \
|
||||
touch $@
|
||||
endif
|
||||
|
||||
./arm64/$(EXEC): $(ARMOBJMODULES)
|
||||
@ld -syslibroot $(SDK) -lSystem $(FRAMEWORKS) -arch arm64 \
|
||||
-macos_version_min $(MACOS_VERSION).0 \
|
||||
/Library/Developer/CommandLineTools/usr/lib/swift/macosx/libswiftCompatibilityPacks.a \
|
||||
-sectcreate __TEXT __info_plist Info.plist \
|
||||
-L /Library/Developer/CommandLineTools/usr/lib/swift/macosx -L \
|
||||
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/swift \
|
||||
-no_objc_category_merging -L $(XCODE_PATH) -rpath \
|
||||
Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx \
|
||||
./arm64/main.o $(filter-out ./arm64/main.o, $(ARMOBJMODULES)) -o $@
|
||||
|
||||
ifdef UNIVERSAL
|
||||
./x86_64/$(EXEC): $(X86OBJMODULES)
|
||||
@ld -syslibroot $(SDK) -lSystem $(FRAMEWORKS) -arch x86_64 \
|
||||
-macos_version_min $(MACOS_VERSION).0 \
|
||||
/Library/Developer/CommandLineTools/usr/lib/swift/macosx/libswiftCompatibilityPacks.a \
|
||||
-sectcreate __TEXT __info_plist Info.plist \
|
||||
-L /Library/Developer/CommandLineTools/usr/lib/swift/macosx -L \
|
||||
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/swift \
|
||||
-no_objc_category_merging -L $(XCODE_PATH) -rpath \
|
||||
Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx \
|
||||
./x86_64/main.o $(filter-out ./x86_64/main.o, $(X86OBJMODULES)) \
|
||||
-o $@
|
||||
endif
|
||||
|
||||
ifdef UNIVERSAL
|
||||
$(EXEC): ./arm64/$(EXEC) ./x86_64/$(EXEC)
|
||||
@lipo -create -output $(EXEC) $^
|
||||
else
|
||||
$(EXEC): ./arm64/$(EXEC)
|
||||
@lipo -create -output $(EXEC) $^
|
||||
endif
|
||||
|
||||
$(EXEC).app: $(EXEC)
|
||||
|
||||
#$(EXEC).app: $(EXEC)
|
||||
# @rm -rf $@
|
||||
# @mkdir -p $@/Contents/MacOS/ && \
|
||||
# mkdir -p $@/Contents/Resources/ && \
|
||||
# cp Info.plist $@/Contents/ && \
|
||||
# cp resources/AppIcon.icns $@/Contents/Resources/ && \
|
||||
# cp $(EXEC) $@/Contents/MacOS/ && \
|
||||
# $(if $(DEBUG), codesign --entitlements Caffeine.entitlements \
|
||||
# -s ${APPLE_DEVELOPMENT} -f --timestamp -o runtime $(EXEC).app, \
|
||||
# codesign -s ${APPLE_DEVELOPER_ID_APPLICATION} -f --timestamp \
|
||||
# -o runtime $(EXEC).app)
|
||||
|
||||
clean:
|
||||
rm -rf $(EXEC) $(EXEC).app arm64 x86_64
|
||||
mkdir arm64 x86_64
|
||||
@@ -0,0 +1,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface MenulessWindow : NSWindow
|
||||
|
||||
- (instancetype)initWithContentViewController:(NSViewController *)contentViewController;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,50 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
#import "MenulessWindow.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
/* TODO: Either change name or move some of the configuration out of the
|
||||
* init, decide whether this is a generic menuless window or not. */
|
||||
@implementation MenulessWindow
|
||||
|
||||
- (instancetype)initWithContentViewController:(NSViewController *)contentViewController {
|
||||
self = [super initWithContentRect:NSMakeRect(0, 0, 100, 100)
|
||||
styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskClosable
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:false];
|
||||
if(self) {
|
||||
[super setContentViewController:contentViewController];
|
||||
[self setTitle:@""];
|
||||
[self setTitlebarAppearsTransparent:YES];
|
||||
[self setCollectionBehavior:NSWindowCollectionBehaviorManaged];
|
||||
[self setReleasedWhenClosed:NO];
|
||||
[self setHidesOnDeactivate:NO];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)performKeyEquivalent:(NSEvent *)event {
|
||||
NSEventModifierFlags modifiers = [event modifierFlags];
|
||||
unsigned short key = [event keyCode];
|
||||
|
||||
if([event type] == NSEventTypeKeyDown) {
|
||||
if(modsContains(NSEventModifierFlagCommand, modifiers) &&
|
||||
key == kVK_ANSI_W)
|
||||
{
|
||||
[self performClose:nil];
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
/* - (instancetype)init { */
|
||||
/* self = [super init]; */
|
||||
/* if(self) { */
|
||||
/* } */
|
||||
/* return self; */
|
||||
/* } */
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,14 @@
|
||||
Jonathan Blow on Swift's Compile Times
|
||||
https://youtu.be/dHfHCZb5bS4?si=kCtAHv1VolGPwfPv
|
||||
|
||||
No Virginia, Swift is not 10x faster than Objective-C
|
||||
https://blog.metaobject.com/2014/09/no-virginia-swift-is-not-10x-faster.html
|
||||
|
||||
On my Misalignment with Apple's Love Affair with Swift
|
||||
https://rant.monkeydom.de/posts/2018/06/10/on-my-misalignment-with-apple_s-love-affair-with-swift
|
||||
|
||||
Apple is Killing Swift
|
||||
https://blog.jacobstechtavern.com/p/apple-is-killing-swift
|
||||
|
||||
Not to mention SwiftUI which a joke of a UI framework. If you ever wonder
|
||||
why iOS has become so buggy and dysfunction, you now know why.
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "AppDelegate.h"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
AppDelegate *delegate = [[AppDelegate alloc] init];
|
||||
[app setDelegate:delegate];
|
||||
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
||||
|
||||
return NSApplicationMain(argc, argv);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user