Skip to content

Commit

Permalink
Merge pull request #22 from DamienB325/patch-1
Browse files Browse the repository at this point in the history
System Preferences -> System Settings (for Ventura and newer)
  • Loading branch information
Lakr233 committed Jun 22, 2023
2 parents 3fc3201 + 204f987 commit c8c3553
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 66 deletions.
1 change: 1 addition & 0 deletions Activate/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "macOS aktivieren";
DESCRIPTION = "Wechseln Sie zu den Systemeinstellungen, um macOS zu aktivieren.";
DESCRIPTION_VENTURA = "Wechseln Sie zu den Systemeinstellungen, um macOS zu aktivieren.";
1 change: 1 addition & 0 deletions Activate/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "Activate macOS";
DESCRIPTION = "Go to System Preferences to activate macOS.";
DESCRIPTION_VENTURA = "Go to System Settings to activate macOS.";
1 change: 1 addition & 0 deletions Activate/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "macOS のライセンス認証";
DESCRIPTION = "システム環境設定を開き、macOSのライセンス認証を行ってください";
DESCRIPTION_VENTURA = "システム環境設定を開き、macOSのライセンス認証を行ってください";
147 changes: 81 additions & 66 deletions Activate/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#import <AppKit/AppKit.h>


@interface AppDelegate : NSObject <NSApplicationDelegate>
@end

Expand All @@ -24,7 +23,6 @@ @interface AppController : NSViewController
@interface AppView : NSView
@end


@implementation AppDelegate {
NSMutableArray *_windowControllers;
}
Expand All @@ -37,16 +35,18 @@ - (instancetype)init {

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self bootstrap];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(bootstrap)
name:NSApplicationDidChangeScreenParametersNotification
object:nil];

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(bootstrap)
name:NSApplicationDidChangeScreenParametersNotification
object:nil];

// To show dock icon, comment this line.
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:
(NSApplication *)sender {
return YES;
}

Expand All @@ -55,14 +55,16 @@ - (void)bootstrap {
[windowCtrl close];
}
[_windowControllers removeAllObjects];

for (NSScreen *screen in [NSScreen screens]) {
[_windowControllers addObject:[self createWindowControllerForScreen:screen]];
[_windowControllers
addObject:[self createWindowControllerForScreen:screen]];
}
}

- (NSWindowController *)createWindowControllerForScreen:(NSScreen *)screen {
NSWindowController *ctrl = [[AppWindowController alloc] initWithScreen:screen];
NSWindowController *ctrl =
[[AppWindowController alloc] initWithScreen:screen];
[[ctrl window] setFrameOrigin:screen.frame.origin];
[[ctrl window] setContentSize:screen.frame.size];
[[ctrl window] makeKeyAndOrderFront:nil];
Expand All @@ -71,24 +73,26 @@ - (NSWindowController *)createWindowControllerForScreen:(NSScreen *)screen {

@end


@implementation AppWindow

- (instancetype)initWithScreen:(NSScreen *)screen {
self = [super initWithContentRect:[screen frame]
styleMask:(NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView)
styleMask:(NSWindowStyleMaskBorderless |
NSWindowStyleMaskFullSizeContentView)
backing:NSBackingStoreBuffered
defer:NO
screen:screen];

[self setOpaque:NO];
[self setAlphaValue:1];
[self setTitleVisibility:NSWindowTitleHidden];
[self setTitlebarAppearsTransparent:YES];
[self setBackgroundColor:[NSColor clearColor]];
[self setIgnoresMouseEvents:YES];
[self setMovable:NO];
[self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorStationary | NSWindowCollectionBehaviorCanJoinAllSpaces];
[self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary |
NSWindowCollectionBehaviorStationary |
NSWindowCollectionBehaviorCanJoinAllSpaces];
[self setLevel:kCGStatusWindowLevel];
[self setHasShadow:NO];
return self;
Expand All @@ -103,12 +107,13 @@ - (BOOL)canBecomeMainWindow {
}

- (NSWindowCollectionBehavior)collectionBehavior {
return NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorStationary | NSWindowCollectionBehaviorCanJoinAllSpaces;
return NSWindowCollectionBehaviorFullScreenAuxiliary |
NSWindowCollectionBehaviorStationary |
NSWindowCollectionBehaviorCanJoinAllSpaces;
}

@end


@implementation AppWindowController

- (instancetype)initWithScreen:(NSScreen *)screen {
Expand All @@ -119,7 +124,6 @@ - (instancetype)initWithScreen:(NSScreen *)screen {

@end


@implementation AppController

- (instancetype)init {
Expand All @@ -132,7 +136,6 @@ - (void)loadView {

@end


@implementation AppView

- (instancetype)init {
Expand All @@ -142,62 +145,74 @@ - (instancetype)init {
- (void)drawRect:(NSRect)dirtyRect {
NSString *title = NSLocalizedString(@"TITLE", @"");
NSString *description = NSLocalizedString(@"DESCRIPTION", @"");


// check if running macOS ventura and newer, and if so use the ventura
// description string
NSOperatingSystemVersion venturaVersion = {.majorVersion = 13, .minorVersion = 0, .patchVersion = 0};
BOOL useSystemSettings = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:venturaVersion];
if (useSystemSettings) { description = NSLocalizedString(@"DESCRIPTION_VENTURA", @""); }

// check if screen height is larger than 1500px
if (self.bounds.size.height > 1500) {
// print height
NSLog(@"%f", self.bounds.size.height);
NSAttributedString *firstLine = [[NSAttributedString alloc] initWithString:title
attributes:@{ NSFontAttributeName: [NSFont systemFontOfSize:36.0],
NSForegroundColorAttributeName: [NSColor colorWithWhite:0.57 alpha:0.5],
}];

NSAttributedString *secondLine = [[NSAttributedString alloc] initWithString:description
attributes:@{ NSFontAttributeName: [NSFont systemFontOfSize:20.0],
NSForegroundColorAttributeName: [NSColor colorWithWhite:0.57 alpha:0.5],
}];

CGRect firstLineRect = [firstLine boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
CGRect secondLineRect = [secondLine boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];

CGFloat decisionWidth = MAX(firstLineRect.size.width, secondLineRect.size.width);

CGFloat xPosition = self.bounds.size.width - 125 - decisionWidth; // padding to right 125
[firstLine drawAtPoint:CGPointMake(xPosition, 150)];
[secondLine drawAtPoint:CGPointMake(xPosition, 125)];
// NSLog(@"%f", self.bounds.size.height);
NSAttributedString *firstLine = [[NSAttributedString alloc] initWithString:title attributes:@{
NSFontAttributeName : [NSFont systemFontOfSize:36.0],
NSForegroundColorAttributeName : [NSColor colorWithWhite:0.57 alpha:0.5],
}];
NSAttributedString *secondLine = [[NSAttributedString alloc] initWithString:description attributes:@{
NSFontAttributeName : [NSFont systemFontOfSize:20.0],
NSForegroundColorAttributeName : [NSColor colorWithWhite:0.57 alpha:0.5],
}];

CGRect firstLineRect = [firstLine
boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading];
CGRect secondLineRect = [secondLine
boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading];

CGFloat decisionWidth =
MAX(firstLineRect.size.width, secondLineRect.size.width);

CGFloat xPosition = self.bounds.size.width - 125 -
decisionWidth; // padding to right 125
[firstLine drawAtPoint:CGPointMake(xPosition, 150)];
[secondLine drawAtPoint:CGPointMake(xPosition, 125)];
} else {
//print height
// print height
NSLog(@"%f", self.bounds.size.height);
NSAttributedString *firstLine = [[NSAttributedString alloc] initWithString:title
attributes:@{ NSFontAttributeName: [NSFont systemFontOfSize:24.0],
NSForegroundColorAttributeName: [NSColor colorWithWhite:0.57 alpha:0.5],
}];

NSAttributedString *secondLine = [[NSAttributedString alloc] initWithString:description
attributes:@{ NSFontAttributeName: [NSFont systemFontOfSize:13.0],
NSForegroundColorAttributeName: [NSColor colorWithWhite:0.57 alpha:0.5],
}];

CGRect firstLineRect = [firstLine boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
CGRect secondLineRect = [secondLine boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];

CGFloat decisionWidth = MAX(firstLineRect.size.width, secondLineRect.size.width);

CGFloat xPosition = self.bounds.size.width - 125 - decisionWidth; // padding to right 125
[firstLine drawAtPoint:CGPointMake(xPosition, 134)];
[secondLine drawAtPoint:CGPointMake(xPosition, 116)];
NSAttributedString *firstLine = [[NSAttributedString alloc] initWithString:title attributes:@{
NSFontAttributeName : [NSFont systemFontOfSize:24.0],
NSForegroundColorAttributeName : [NSColor colorWithWhite:0.57 alpha:0.5],
}];

NSAttributedString *secondLine = [[NSAttributedString alloc] initWithString:description attributes:@{
NSFontAttributeName : [NSFont systemFontOfSize:13.0],
NSForegroundColorAttributeName : [NSColor colorWithWhite:0.57 alpha:0.5],
}];

CGRect firstLineRect = [firstLine
boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading];
CGRect secondLineRect = [secondLine
boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading];

CGFloat decisionWidth =
MAX(firstLineRect.size.width, secondLineRect.size.width);

CGFloat xPosition = self.bounds.size.width - 125 - decisionWidth; // padding to right 125
[firstLine drawAtPoint:CGPointMake(xPosition, 134)];
[secondLine drawAtPoint:CGPointMake(xPosition, 116)];
}


}

@end


int main(int argc, const char *argv[]) {
static AppDelegate *appDelegate = nil;
appDelegate = [AppDelegate new];
Expand Down
1 change: 1 addition & 0 deletions Activate/pl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "Aktywuj system macOS";
DESCRIPTION = "Przejdź do ustawień, aby aktywować system macOS.";
DESCRIPTION_VENTURA = "Przejdź do ustawień, aby aktywować system macOS.";
1 change: 1 addition & 0 deletions Activate/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "Активация macOS";
DESCRIPTION = "Чтобы активировать macOS, перейдите в раздел \"Параметры\".";
DESCRIPTION_VENTURA = "Чтобы активировать macOS, перейдите в раздел \"Параметры\".";
1 change: 1 addition & 0 deletions Activate/tr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "macOS'i Etkinleştir";
DESCRIPTION = "macOS'i etkinleştirmek için Ayarlar'a gidin.";
DESCRIPTION_VENTURA = "macOS'i etkinleştirmek için Ayarlar'a gidin.";
1 change: 1 addition & 0 deletions Activate/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "激活 macOS";
DESCRIPTION = "您当前所使用的可能是盗版 macOS 副本,请前往偏好设置激活。";
DESCRIPTION_VENTURA = "您当前所使用的可能是盗版 macOS 副本,请前往设置激活。";
1 change: 1 addition & 0 deletions Activate/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TITLE = "啟用 macOS";
DESCRIPTION = "您目前使用的可能是盜版 macOS 副本。請前往「系統偏好設定」啟用。";
DESCRIPTION_VENTURA = "您當前所使用的可能是盜版 macOS 副本,請前往設置激活。";

0 comments on commit c8c3553

Please sign in to comment.