Skip to content

Commit

Permalink
Fix CocoaPods warnings + commit Sparkle directly because CocoaPods is…
Browse files Browse the repository at this point in the history
… just terrible
  • Loading branch information
cstigler committed Jan 21, 2021
1 parent 8837a99 commit f334c61
Show file tree
Hide file tree
Showing 209 changed files with 6,517 additions and 119 deletions.
90 changes: 38 additions & 52 deletions AppController.m
Expand Up @@ -84,12 +84,12 @@ - (IBAction)updateTimeSliderDisplay:(id)sender {
- (NSString *)timeSliderDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes {
static NSCalendar* gregorian = nil;
if (gregorian == nil) {
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
}

NSRange secondsRangePerMinute = [gregorian
rangeOfUnit:NSSecondCalendarUnit
inUnit:NSMinuteCalendarUnit
rangeOfUnit:NSCalendarUnitSecond
inUnit:NSCalendarUnitMinute
forDate:[NSDate date]];
NSUInteger numberOfSecondsPerMinute = NSMaxRange(secondsRangePerMinute);

Expand Down Expand Up @@ -255,7 +255,7 @@ - (void)handleConfigurationChangedNotification {

- (void)showTimerWindow {
if(timerWindowController_ == nil) {
[NSBundle loadNibNamed: @"TimerWindow" owner: self];
[[NSBundle mainBundle] loadNibNamed: @"TimerWindow" owner: self topLevelObjects: nil];
} else {
[[timerWindowController_ window] makeKeyAndOrderFront: self];
[[timerWindowController_ window] center];
Expand Down Expand Up @@ -433,7 +433,7 @@ - (IBAction)showDomainList:(id)sender {
}

if(domainListWindowController_ == nil) {
[NSBundle loadNibNamed: @"DomainList" owner: self];
[[NSBundle mainBundle] loadNibNamed: @"DomainList" owner: self topLevelObjects: nil];
}
[domainListWindowController_ showWindow: self];
}
Expand Down Expand Up @@ -738,18 +738,18 @@ - (IBAction)save:(id)sender {
runResult = [sp runModal];

/* if successful, save file under designated name */
if (runResult == NSOKButton) {
NSString* errDescription;
if (runResult == NSModalResponseOK) {
NSError* err;
[SCBlockFileReaderWriter writeBlocklistToFileURL: sp.URL
blockInfo: @{
@"Blocklist": [defaults_ arrayForKey: @"Blocklist"],
@"BlockAsWhitelist": [defaults_ objectForKey: @"BlockAsWhitelist"]

}
errorDescription: &errDescription];
error: &err];

if(errDescription) {
NSError* displayErr = [SCErr errorWithCode: 105 subDescription: errDescription];
if (err != nil) {
NSError* displayErr = [SCErr errorWithCode: 105 subDescription: err.localizedDescription];
[SCSentry captureError: displayErr];
NSBeep();
[NSApp presentError: displayErr];
Expand All @@ -760,60 +760,46 @@ - (IBAction)save:(id)sender {
}
}

- (BOOL)openSavedBlockFileAtURL:(NSURL*)fileURL {
NSDictionary* settingsFromFile = [SCBlockFileReaderWriter readBlocklistFromFile: fileURL];

if (settingsFromFile != nil) {
[defaults_ setObject: settingsFromFile[@"Blocklist"] forKey: @"Blocklist"];
[defaults_ setObject: settingsFromFile[@"BlockAsWhitelist"] forKey: @"BlockAsWhitelist"];
[SCSentry addBreadcrumb: @"Opened blocklist from file" category:@"app"];
} else {
NSLog(@"WARNING: Could not read a valid blocklist from file - ignoring.");
return NO;
}

// close the domain list (and reopen again if need be to refresh)
BOOL domainListIsOpen = [[domainListWindowController_ window] isVisible];
NSRect frame = [[domainListWindowController_ window] frame];
[self closeDomainList];
if(domainListIsOpen) {
[self showDomainList: self];
[[domainListWindowController_ window] setFrame: frame display: YES];
}

[self refreshUserInterface];
return YES;
}

- (IBAction)open:(id)sender {
NSLog(@"CALLED OPEN OPENING FILE!");
NSOpenPanel* oPanel = [NSOpenPanel openPanel];
oPanel.allowedFileTypes = @[@"selfcontrol"];
oPanel.allowsMultipleSelection = NO;

long result = [oPanel runModal];
if (result == NSOKButton) {
if (result == NSModalResponseOK) {
if([oPanel.URLs count] > 0) {
NSDictionary* settingsFromFile = [SCBlockFileReaderWriter readBlocklistFromFile: oPanel.URLs[0]];

if (settingsFromFile != nil) {
[defaults_ setObject: settingsFromFile[@"Blocklist"] forKey: @"Blocklist"];
[defaults_ setObject: settingsFromFile[@"BlockAsWhitelist"] forKey: @"BlockAsWhitelist"];
[SCSentry addBreadcrumb: @"Opened blocklist from file" category:@"app"];
} else {
NSLog(@"WARNING: Could not read a valid blocklist from file - ignoring.");
}

// close the domain list (and reopen again if need be to refresh)
BOOL domainListIsOpen = [[domainListWindowController_ window] isVisible];
NSRect frame = [[domainListWindowController_ window] frame];
[self closeDomainList];
if(domainListIsOpen) {
[self showDomainList: self];
[[domainListWindowController_ window] setFrame: frame display: YES];
}

[self refreshUserInterface];
[self openSavedBlockFileAtURL: oPanel.URLs[0]];
}
}
}

- (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)filename {
NSLog(@"CALLED APPLICATION OPEN FILE!");
NSDictionary* openedDict = [NSDictionary dictionaryWithContentsOfFile: filename];
if(openedDict == nil) return NO;

NSArray* newBlocklist = openedDict[@"HostBlacklist"];
NSNumber* newAllowlistChoice = openedDict[@"BlockAsWhitelist"];
if(newBlocklist == nil || newAllowlistChoice == nil) return NO;

[defaults_ setValue: newBlocklist forKey:@"Blocklist"];
[defaults_ setObject: newAllowlistChoice forKey: @"BlockAsWhitelist"];

BOOL domainListIsOpen = [[domainListWindowController_ window] isVisible];
NSRect frame = [[domainListWindowController_ window] frame];
[self closeDomainList];
if(domainListIsOpen) {
[self showDomainList: self];
[[domainListWindowController_ window] setFrame: frame display: YES];
}

return YES;
return [self openSavedBlockFileAtURL: [NSURL fileURLWithPath: filename]];
}

- (IBAction)openFAQ:(id)sender {
Expand Down
23 changes: 23 additions & 0 deletions Common/DeprecationSilencers.h
@@ -0,0 +1,23 @@
//
// DeprecationSilencers.h
// SelfControl
//
// Created by Charlie Stigler on 1/19/21.
//

#ifndef DeprecationSilencers_h
#define DeprecationSilencers_h

// great idea taken from this guy: https://stackoverflow.com/a/26564750

#define SILENCE_DEPRECATION(expr) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
expr; \
_Pragma("clang diagnostic pop") \
} while(0)

#define SILENCE_OSX10_10_DEPRECATION(expr) SILENCE_DEPRECATION(expr)

#endif /* DeprecationSilencers_h */
2 changes: 1 addition & 1 deletion Common/SCBlockFileReaderWriter.h
Expand Up @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
// Writes out a saved .selfcontrol blocklist file to the file system
// containing the block info (blocklist + whitelist setting) defined
// in blockInfo.
+ (BOOL)writeBlocklistToFileURL:(NSURL*)targetFileURL blockInfo:(NSDictionary*)blockInfo errorDescription:(NSString**)errDescriptionRef;
+ (BOOL)writeBlocklistToFileURL:(NSURL*)targetFileURL blockInfo:(NSDictionary*)blockInfo error:(NSError*_Nullable*_Nullable)errRef;

// reads in a saved .selfcontrol blocklist file and returns
// an NSDictionary with the block settings contained
Expand Down
11 changes: 5 additions & 6 deletions Common/SCBlockFileReaderWriter.m
Expand Up @@ -9,25 +9,24 @@

@implementation SCBlockFileReaderWriter

+ (BOOL)writeBlocklistToFileURL:(NSURL*)targetFileURL blockInfo:(NSDictionary*)blockInfo errorDescription:(NSString**)errDescriptionRef {
+ (BOOL)writeBlocklistToFileURL:(NSURL*)targetFileURL blockInfo:(NSDictionary*)blockInfo error:(NSError**)errRef {
NSDictionary* saveDict = @{@"HostBlacklist": [blockInfo objectForKey: @"Blocklist"],
@"BlockAsWhitelist": [blockInfo objectForKey: @"BlockAsWhitelist"]};

NSString* saveDataErr;
NSData* saveData = [NSPropertyListSerialization dataFromPropertyList: saveDict format: NSPropertyListBinaryFormat_v1_0 errorDescription: &saveDataErr];
if (saveDataErr != nil) {
*errDescriptionRef = saveDataErr;
NSData* saveData = [NSPropertyListSerialization dataWithPropertyList: saveDict format: NSPropertyListBinaryFormat_v1_0 options: 0 error: errRef];
if (*errRef != nil) {
return NO;
}

if (![saveData writeToURL: targetFileURL atomically: YES]) {
NSLog(@"ERROR: Failed to write blocklist to URL %@", targetFileURL);
*errRef = [SCErr errorWithCode: 106];
return NO;
}

// for prettiness sake, attempt to hide the file extension
NSDictionary* attribs = @{NSFileExtensionHidden: @YES};
[[NSFileManager defaultManager] setAttributes: attribs ofItemAtPath: [targetFileURL path] error: NULL];
[[NSFileManager defaultManager] setAttributes: attribs ofItemAtPath: [targetFileURL path] error: errRef];

return YES;
}
Expand Down
2 changes: 2 additions & 0 deletions Common/Utility/SCHelperToolUtilities.m
Expand Up @@ -47,7 +47,9 @@ + (void)unloadDaemonJob {
// uh-oh, looks like it's 5 seconds later and the sync hasn't completed yet. Bad news.
CFErrorRef cfError;
// this should block until the process is dead, so we should never get to the other side if it's successful
SILENCE_OSX10_10_DEPRECATION(
SMJobRemove(kSMDomainSystemLaunchd, CFSTR("org.eyebeam.selfcontrold"), NULL, YES, &cfError);
);
if (cfError) {
NSLog(@"Failed to remove selfcontrold daemon with error %@", cfError);
}
Expand Down
17 changes: 10 additions & 7 deletions DomainListWindowController.m
Expand Up @@ -247,13 +247,16 @@ - (IBAction)allowlistOptionChanged:(NSMatrix*)sender {
}

- (void)showAllowlistWarning {
if(![defaults_ boolForKey: @"WhitelistAlertSuppress"]) {
NSAlert* a = [NSAlert alertWithMessageText: NSLocalizedString(@"Are you sure you want an allowlist block?", @"Allowlist block confirmation prompt") defaultButton: NSLocalizedString(@"OK", @"OK button") alternateButton: @"" otherButton: @"" informativeTextWithFormat: NSLocalizedString(@"An allowlist block means that everything on the internet BESIDES your specified list will be blocked. This includes the web, email, SSH, and anything else your computer accesses via the internet. If a web site requires resources such as images or scripts from a site that is not on your allowlist, the site may not work properly.", @"allowlist block explanation")];
if([a respondsToSelector: @selector(setShowsSuppressionButton:)]) {
[a setShowsSuppressionButton: YES];
}
[a runModal];
if([a respondsToSelector: @selector(suppressionButton)] && [[a suppressionButton] state] == NSOnState) {
if(![defaults_ boolForKey: @"WhitelistAlertSuppress"]) {
NSAlert* alert = [NSAlert new];
alert.messageText = NSLocalizedString(@"Are you sure you want an allowlist block?", @"Allowlist block confirmation prompt");
alert.buttons[0].title = NSLocalizedString(@"OK", @"OK button");
alert.informativeText = NSLocalizedString(@"An allowlist block means that everything on the internet BESIDES your specified list will be blocked. This includes the web, email, SSH, and anything else your computer accesses via the internet. If a web site requires resources such as images or scripts from a site that is not on your allowlist, the site may not work properly.", @"allowlist block explanation");
alert.showsSuppressionButton = YES;

[alert runModal];

if (alert.suppressionButton.state == NSOnState) {
[defaults_ setBool: YES forKey: @"WhitelistAlertSuppress"];
}
}
Expand Down
27 changes: 20 additions & 7 deletions Podfile
@@ -1,5 +1,8 @@
source 'https://github.com/CocoaPods/Specs.git'
platform :osx, '10.10'

minVersion = '10.10'

platform :osx, minVersion

# cocoapods-prune-localizations doesn't appear to auto-detect pods properly, so using a manual list
supported_locales = ['Base', 'da', 'de', 'en', 'es', 'fr', 'it', 'ja', 'ko', 'nl', 'pt-BR', 'sv', 'tr', 'zh-Hans']
Expand All @@ -9,24 +12,34 @@ target "SelfControl" do
use_frameworks! :linkage => :static
pod 'MASPreferences', '~> 1.1.4'
pod 'FormatterKit/TimeIntervalFormatter', '~> 1.8.0'
pod 'Sparkle', '~> 1.22'
pod 'LetsMove', '~> 1.24'
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.2'
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.3'
end

target "SelfControl Killer" do
use_frameworks! :linkage => :static
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.2'
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.3'
end

# we can't use_frameworks on these because they're command-line tools
# Sentry says we need use_frameworks, but they seem to work OK anyway?
target "SCKillerHelper" do
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.2'
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.3'
end
target "selfcontrol-cli" do
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.2'
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.3'
end
target "org.eyebeam.selfcontrold" do
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.2'
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '6.1.3'
end

post_install do |pi|
pi.pods_project.targets.each do |t|
t.build_configurations.each do |bc|
if Gem::Version.new(bc.build_settings['MACOSX_DEPLOYMENT_TARGET']) < Gem::Version.new(minVersion)
# if bc.build_settings['MACOSX_DEPLOYMENT_TARGET'] == '8.0'
bc.build_settings['MACOSX_DEPLOYMENT_TARGET'] = minVersion
end
end
end
end
1 change: 1 addition & 0 deletions SCError.strings
Expand Up @@ -16,6 +16,7 @@
"103" = "You can't extend block duration, because no block is currently running.";
"104" = "You can't start a block, because another block is currently running.";
"105" = "The block wasn't removed at the scheduled time, for unknown reasons.";
"106" = "Data couldn't be written to that location.";

// 200 - 299 = errors generated in the CLI

Expand Down
2 changes: 2 additions & 0 deletions SCKillerHelper/main.m
Expand Up @@ -137,7 +137,9 @@ int main(int argc, char* argv[]) {
[log appendFormat: @"Unloading the legacy (1.0 - 3.0.3) launchd daemon returned: %d\n\n", status];

CFErrorRef cfError;
SILENCE_OSX10_10_DEPRECATION(
SMJobRemove(kSMDomainSystemLaunchd, CFSTR("org.eyebeam.selfcontrold"), NULL, YES, &cfError);
);
if (cfError) {
[log appendFormat: @"Failed to remove selfcontrold daemon (4.x) with error %@\n\n", cfError];
} else {
Expand Down

0 comments on commit f334c61

Please sign in to comment.