Skip to content

Commit

Permalink
Add a preferences option to disable Crashlytics, and a link to a priv…
Browse files Browse the repository at this point in the history
…acy policy page on hammerspoon.org. Relates to #139
  • Loading branch information
cmsj committed Mar 9, 2015
1 parent 2aee23f commit 47dbd78
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 30 deletions.
12 changes: 8 additions & 4 deletions Hammerspoon/MJAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
MJConfigFile = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:tmp length:strlen(tmp)];
}

MJEnsureDirectoryExists(MJConfigDir());
[[NSFileManager defaultManager] changeCurrentDirectoryPath:MJConfigDir()];

[self registerDefaultDefaults];

// Enable Crashlytics, if we have an API key available
#ifdef CRASHLYTICS_API_KEY
if (HSUploadCrashData()) {
[Crashlytics startWithAPIKey:[NSString stringWithUTF8String:CRASHLYTICS_API_KEY]];
Crashlytics *crashlytics = [Crashlytics sharedInstance];
crashlytics.debugMode = YES; // TODO: We probably don't want to leave this enabled
}
#endif

MJEnsureDirectoryExists(MJConfigDir());
[[NSFileManager defaultManager] changeCurrentDirectoryPath:MJConfigDir()];

[self registerDefaultDefaults];
MJMenuIconSetup(self.menuBarMenu);
MJDockIconSetup();
[[MJConsoleWindowController singleton] setup];
Expand All @@ -68,6 +71,7 @@ - (void) registerDefaultDefaults {
registerDefaults: @{MJShowDockIconKey: @YES,
MJShowMenuIconKey: @YES,
HSAutoLoadExtensions: @YES,
HSUploadCrashDataKey: @YES,
}];
}

Expand Down
3 changes: 3 additions & 0 deletions Hammerspoon/MJPreferencesWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
+ (instancetype) singleton;

@end

BOOL HSUploadCrashData(void);
void HSSetUploadCrashData(BOOL uploadCrashData);
25 changes: 25 additions & 0 deletions Hammerspoon/MJPreferencesWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import "MJAccessibilityUtils.h"
#import "MJConsoleWindowController.h"
#import "variables.h"
#import "secrets.h"

#define MJSkipDockMenuIconProblemAlertKey @"MJSkipDockMenuIconProblemAlertKey"

Expand All @@ -15,6 +16,7 @@ @interface MJPreferencesWindowController ()
@property (weak) IBOutlet NSButton* showDockIconCheckbox;
@property (weak) IBOutlet NSButton* showMenuIconCheckbox;
@property (weak) IBOutlet NSButton* keepConsoleOnTopCheckbox;
@property (weak) IBOutlet NSButton* uploadCrashDataCheckbox;

@property BOOL isAccessibilityEnabled;

Expand Down Expand Up @@ -52,6 +54,12 @@ - (void)windowDidLoad {
[self.showDockIconCheckbox setState: MJDockIconVisible() ? NSOnState : NSOffState];
[self.showMenuIconCheckbox setState: MJMenuIconVisible() ? NSOnState : NSOffState];
[self.keepConsoleOnTopCheckbox setState: MJConsoleWindowAlwaysOnTop() ? NSOnState : NSOffState];
[self.uploadCrashDataCheckbox setState: HSUploadCrashData() ? NSOnState : NSOffState];
#ifndef CRASHLYTICS_API_KEY
[self.uploadCrashDataCheckbox setState:NSOffState];
[self.uploadCrashDataCheckbox setEnabled:NO];
#endif

}

- (void) accessibilityChanged:(NSNotification*)note {
Expand Down Expand Up @@ -116,6 +124,14 @@ - (IBAction) toggleKeepConsoleOnTop:(id)sender {
MJConsoleWindowSetAlwaysOnTop([sender state] == NSOnState);
}

- (IBAction) toggleUploadCrashData:(id)sender {
HSSetUploadCrashData([sender state] == NSOnState);
}

- (IBAction) privacyPolicyClicked:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.hammerspoon.org/privacy"]];
}

- (void) dockMenuProblemAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
BOOL skipNextTime = ([[alert suppressionButton] state] == NSOnState);
[[NSUserDefaults standardUserDefaults] setBool:skipNextTime forKey:MJSkipDockMenuIconProblemAlertKey];
Expand All @@ -140,3 +156,12 @@ - (void) maybeWarnAboutDockMenuProblem {
}

@end


BOOL HSUploadCrashData(void) {
return [[NSUserDefaults standardUserDefaults] boolForKey: HSUploadCrashDataKey];
}

void HSSetUploadCrashData(BOOL uploadCrashData) {
[[NSUserDefaults standardUserDefaults] setBool:uploadCrashData forKey:HSUploadCrashDataKey];
}
75 changes: 49 additions & 26 deletions Hammerspoon/PreferencesWindow.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6245" systemVersion="14A388a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="14D87p" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6245"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6751"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MJPreferencesWindowController">
Expand All @@ -11,6 +11,7 @@
<outlet property="openAtLoginCheckbox" destination="e5P-fQ-lSS" id="ug0-D4-eSm"/>
<outlet property="showDockIconCheckbox" destination="LCE-lg-IdY" id="8xH-gB-Wng"/>
<outlet property="showMenuIconCheckbox" destination="onk-bV-cOj" id="OuW-dV-96B"/>
<outlet property="uploadCrashDataCheckbox" destination="gOt-KN-83u" id="MPR-aF-ZbI"/>
<outlet property="window" destination="1ae-mv-r5b" id="d2x-lo-e3M"/>
</connections>
</customObject>
Expand All @@ -19,14 +20,14 @@
<window title="Hammerspoon Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" frameAutosaveName="prefs" animationBehavior="default" id="1ae-mv-r5b" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="957" y="580" width="406" height="242"/>
<rect key="contentRect" x="957" y="580" width="406" height="296"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1418"/>
<view key="contentView" id="Akb-Ed-9u3">
<rect key="frame" x="0.0" y="-1" width="406" height="242"/>
<rect key="frame" x="0.0" y="-1" width="406" height="296"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button id="LCE-lg-IdY">
<rect key="frame" x="127" y="144" width="121" height="18"/>
<rect key="frame" x="127" y="198" width="121" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Show dock icon" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="1Ay-Q1-93j">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -37,7 +38,7 @@
</connections>
</button>
<button id="onk-bV-cOj">
<rect key="frame" x="127" y="124" width="126" height="18"/>
<rect key="frame" x="127" y="178" width="126" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Show menu icon" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="uNE-4I-dRd">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -48,7 +49,7 @@
</connections>
</button>
<button id="e5P-fQ-lSS">
<rect key="frame" x="127" y="184" width="241" height="18"/>
<rect key="frame" x="127" y="238" width="241" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Launch Hammerspoon at login" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="WYx-7x-qXj">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -59,7 +60,7 @@
</connections>
</button>
<button id="8hE-jn-yvO">
<rect key="frame" x="127" y="164" width="137" height="18"/>
<rect key="frame" x="127" y="218" width="137" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Check for updates" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="eue-1N-zi1">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -70,16 +71,49 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="VQb-h7-4Va">
<rect key="frame" x="50" y="185" width="73" height="17"/>
<rect key="frame" x="50" y="239" width="73" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Behavior:" id="dha-iU-GWx">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button id="pYS-Wj-7iw">
<rect key="frame" x="127" y="158" width="205" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Keep Console window on top" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="OSm-zw-Lk8">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleKeepConsoleOnTop:" target="-2" id="bCp-5r-duV"/>
</connections>
</button>
<button id="gOt-KN-83u">
<rect key="frame" x="127" y="138" width="227" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Send crash data (requires restart)" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="YwH-Pc-MwX">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleUploadCrashData:" target="-2" id="8a1-bO-6qu"/>
</connections>
</button>
<button verticalHuggingPriority="750" id="Brc-yV-QuI">
<rect key="frame" x="106" y="106" width="195" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Crash Data Privacy Policy" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="hjR-yP-MS1">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="privacyPolicyClicked:" target="-2" id="wJg-Ny-X8G"/>
</connections>
</button>
<button verticalHuggingPriority="750" id="4ho-hR-nJI">
<rect key="frame" x="123" y="33" width="162" height="32"/>
<rect key="frame" x="123" y="40" width="162" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Enable Accessibility" bezelStyle="rounded" imagePosition="left" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="cuD-Tg-hc1">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -95,7 +129,7 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="fRb-9A-PSe">
<rect key="frame" x="127" y="69" width="241" height="17"/>
<rect key="frame" x="127" y="76" width="241" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Accessibility is enabled. You're all set!" id="PqP-7R-CO6">
<font key="font" metaFont="system"/>
Expand All @@ -107,7 +141,7 @@
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="Ljs-s0-qtL">
<rect key="frame" x="38" y="69" width="85" height="17"/>
<rect key="frame" x="38" y="76" width="85" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Accessibility:" id="xX6-GD-rGt">
<font key="font" metaFont="system"/>
Expand All @@ -116,27 +150,16 @@
</textFieldCell>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="fzK-vc-sjF">
<rect key="frame" x="287" y="42" width="16" height="16"/>
<rect key="frame" x="287" y="49" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="NSStatusAvailable" id="6r9-hh-evU"/>
<connections>
<binding destination="-2" name="value" keyPath="self.isAccessibilityEnabledImage" id="sOX-IP-ZMv"/>
</connections>
</imageView>
<button id="pYS-Wj-7iw">
<rect key="frame" x="127" y="104" width="205" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Keep Console window on top" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="OSm-zw-Lk8">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleKeepConsoleOnTop:" target="-2" id="bCp-5r-duV"/>
</connections>
</button>
</subviews>
</view>
<point key="canvasLocation" x="333" y="345"/>
<point key="canvasLocation" x="333" y="372"/>
</window>
<customObject id="aFN-bk-0DY" customClass="SUUpdater"/>
<userDefaultsController representsSharedInstance="YES" id="dqg-7Y-qrg"/>
Expand Down
1 change: 1 addition & 0 deletions Hammerspoon/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define MJKeepConsoleOnTopKey @"MJKeepConsoleOnTopKey"
#define MJHasRunAlreadyKey @"MJHasRunAlreadyKey"
#define HSAutoLoadExtensions @"HSAutoLoadExtensions"
#define HSUploadCrashDataKey @"HSUploadCrashData"

extern NSString* MJConfigFile;

Expand Down

0 comments on commit 47dbd78

Please sign in to comment.