Skip to content

Commit

Permalink
Merge pull request #9 from pixel-point/hide-menu-bar-set-custom-shortcut
Browse files Browse the repository at this point in the history
Hide menu bar set custom shortcut
  • Loading branch information
lnikell authored Aug 9, 2017
2 parents f672512 + 1841147 commit 3b2164e
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 43 deletions.
3 changes: 3 additions & 0 deletions Mute Me Now/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

- (IBAction)menuMenuItemAction:(id)sender;

- (void) hideMenuBar:(BOOL)enableState;

- (void) shortCutKeyPressed;

@end

51 changes: 39 additions & 12 deletions Mute Me Now/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import <MASShortcut/Shortcut.h>

static const NSTouchBarItemIdentifier muteIdentifier = @"pp.mute";
static NSString *const MASCustomShortcutKey = @"customShortcut";

@interface AppDelegate () <TouchDelegate>

Expand All @@ -27,6 +28,24 @@ @implementation AppDelegate

- (void) awakeFromNib {

BOOL hideStatusBar = NO;

if ([[NSUserDefaults standardUserDefaults] objectForKey:@"hide_status_bar"] != nil) {
hideStatusBar = [[NSUserDefaults standardUserDefaults] boolForKey:@"hide_status_bar"];
}

if (!hideStatusBar) {
[self setupStatusBarItem];
}

[[NSUserDefaults standardUserDefaults] setBool:hideStatusBar forKey:@"hide_status_bar"];

// masshortcut
[self setShortcutKey];
}

- (void) setupStatusBarItem {

self.statusBar = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];

NSImage* statusImage = [self getStatusBarImage];
Expand All @@ -41,25 +60,37 @@ - (void) awakeFromNib {
self.statusBar.highlightMode = YES;
self.statusBar.enabled = YES;
self.statusBar.menu = self.statusMenu;

// masshortcut

}

- (void) setShortcutKey {

// default shortcut is "Shift Command 0"
MASShortcut *firstLaunchShortcut = [MASShortcut shortcutWithKeyCode:kVK_ANSI_0 modifierFlags:NSEventModifierFlagCommand | NSEventModifierFlagShift];
NSData *firstLaunchShortcutData = [NSKeyedArchiver archivedDataWithRootObject:firstLaunchShortcut];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:@{
MASCustomShortcutKey : firstLaunchShortcutData
}];

[[MASShortcutMonitor sharedMonitor] registerShortcut:firstLaunchShortcut withAction:^{
[self shortCutKeyPressed];
}];
[defaults synchronize];

// Register default values to be used for the first app start
[defaults registerDefaults:@{
@"customShortcut" : firstLaunchShortcutData

[[MASShortcutMonitor sharedMonitor] registerShortcut:firstLaunchShortcut withAction:^{
[self shortCutKeyPressed];
}];

}

- (void) hideMenuBar: (BOOL) enableState {

if (!enableState) {
[self setupStatusBarItem];
} else {
self.statusBar = nil;
}
}

- (void) shortCutKeyPressed {

Expand Down Expand Up @@ -102,10 +133,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

// fires if we enter / exit dark mode
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(darkModeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];




}

-(void)darkModeChanged:(NSNotification *)notif
Expand Down
55 changes: 42 additions & 13 deletions Mute Me Now/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -712,35 +712,35 @@
<objects>
<viewController title="Mute Me" id="XfG-lQ-9wD" customClass="ViewController" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="400" height="223"/>
<rect key="frame" x="0.0" y="0.0" width="400" height="320"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="jgV-z1-Y2K">
<rect key="frame" x="20" y="116" width="96" height="67"/>
<rect key="frame" x="20" y="213" width="96" height="67"/>
<constraints>
<constraint firstAttribute="width" constant="96" id="z1r-30-2kr"/>
<constraint firstAttribute="height" constant="67" id="zXu-Qt-8b4"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="logo" id="2Je-uk-WdO"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hHJ-tz-Zfo">
<rect key="frame" x="154" y="147" width="248" height="31"/>
<rect key="frame" x="154" y="244" width="248" height="31"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Mute Me" id="2Zy-2M-TGH">
<font key="font" metaFont="system" size="26"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" ambiguous="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fwG-yv-1ky">
<rect key="frame" x="241" y="120" width="74" height="17"/>
<rect key="frame" x="241" y="217" width="74" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Version: 1.0" id="aLh-Ga-uOd">
<font key="font" metaFont="system"/>
<color key="textColor" red="0.50980392156862742" green="0.50980392156862742" blue="0.50980392156862742" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hvj-7s-TwY">
<rect key="frame" x="20" y="82" width="103" height="18"/>
<rect key="frame" x="20" y="179" width="103" height="18"/>
<buttonCell key="cell" type="check" title="Open at login" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="uvS-Gd-Ucm">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -750,23 +750,23 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="paW-7T-Udu">
<rect key="frame" x="18" y="23" width="31" height="17"/>
<rect key="frame" x="18" y="17" width="31" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Visit" id="bpq-Lk-wN5">
<font key="font" metaFont="system"/>
<color key="textColor" red="0.50980392156862742" green="0.50980392156862742" blue="0.50980392156862742" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IZW-rf-f4A">
<rect key="frame" x="114" y="23" width="31" height="17"/>
<rect key="frame" x="114" y="17" width="31" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Visit" id="ksb-oB-QsG">
<font key="font" metaFont="system"/>
<color key="textColor" red="0.50980392159999999" green="0.50980392159999999" blue="0.50980392159999999" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4TQ-VZ-TmS">
<rect key="frame" x="320" y="14" width="66" height="32"/>
<rect key="frame" x="320" y="8" width="66" height="32"/>
<buttonCell key="cell" type="push" title="Quit" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="fZe-Yb-1MB">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -776,7 +776,7 @@
</connections>
</button>
<button verticalHuggingPriority="749" verticalCompressionResistancePriority="751" translatesAutoresizingMaskIntoConstraints="NO" id="KAa-G4-Uci">
<rect key="frame" x="49" y="15" width="45" height="32"/>
<rect key="frame" x="49" y="9" width="45" height="32"/>
<buttonCell key="cell" type="bevel" title="Github" bezelStyle="rounded" alignment="center" state="on" allowsMixedState="YES" inset="2" id="fnI-lS-sU8">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -786,7 +786,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PYQ-lw-EpL">
<rect key="frame" x="146" y="15" width="53" height="32"/>
<rect key="frame" x="146" y="9" width="53" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="53" id="abk-Fd-YcD"/>
</constraints>
Expand All @@ -799,7 +799,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UhA-eV-vsx">
<rect key="frame" x="216" y="63" width="123" height="32"/>
<rect key="frame" x="216" y="160" width="123" height="32"/>
<buttonCell key="cell" type="bevel" title="Made by Pixel Point" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="WIm-yh-r21">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -808,40 +808,69 @@
<action selector="onMainWebsitePressed:" target="XfG-lQ-9wD" id="92d-qe-WWK"/>
</connections>
</button>
<button misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="03l-eq-BdN">
<rect key="frame" x="20" y="143" width="132" height="18"/>
<buttonCell key="cell" type="check" title="Hide icon at menu" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="n61-0U-soc">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="showMenuBarChanged:" target="XfG-lQ-9wD" id="80Y-jW-1qx"/>
</connections>
</button>
<customView misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jvA-Vd-gMo" customClass="MASShortcutView">
<rect key="frame" x="20" y="89" width="358" height="40"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="r4b-wL-2Sc"/>
<constraint firstAttribute="width" constant="358" id="yLv-u2-v3I"/>
</constraints>
</customView>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Dc9-Xu-cYw">
<rect key="frame" x="22" y="50" width="358" height="5"/>
</box>
</subviews>
<constraints>
<constraint firstItem="KAa-G4-Uci" firstAttribute="leading" secondItem="paW-7T-Udu" secondAttribute="trailing" constant="2" id="6Ie-tw-gbe"/>
<constraint firstAttribute="trailing" secondItem="4TQ-VZ-TmS" secondAttribute="trailing" constant="20" id="9uT-yX-Hcx"/>
<constraint firstItem="Dc9-Xu-cYw" firstAttribute="trailing" secondItem="4TQ-VZ-TmS" secondAttribute="trailing" id="DLb-UO-9N5"/>
<constraint firstItem="Dc9-Xu-cYw" firstAttribute="bottom" secondItem="jvA-Vd-gMo" secondAttribute="bottom" constant="20" id="DVr-Qr-Gw5"/>
<constraint firstItem="4TQ-VZ-TmS" firstAttribute="centerY" secondItem="IZW-rf-f4A" secondAttribute="centerY" id="HoT-4q-8c8"/>
<constraint firstItem="IZW-rf-f4A" firstAttribute="centerY" secondItem="paW-7T-Udu" secondAttribute="centerY" id="K1x-0t-XYq"/>
<constraint firstItem="hHJ-tz-Zfo" firstAttribute="leading" secondItem="jgV-z1-Y2K" secondAttribute="trailing" constant="40" id="Pfa-gL-Cmv"/>
<constraint firstItem="UhA-eV-vsx" firstAttribute="centerY" secondItem="hvj-7s-TwY" secondAttribute="centerY" id="QKF-iV-bEb"/>
<constraint firstItem="hHJ-tz-Zfo" firstAttribute="top" secondItem="jgV-z1-Y2K" secondAttribute="top" constant="5" id="QMH-TQ-WYW"/>
<constraint firstItem="KAa-G4-Uci" firstAttribute="centerY" secondItem="paW-7T-Udu" secondAttribute="centerY" id="Saz-gm-fsK"/>
<constraint firstItem="UhA-eV-vsx" firstAttribute="centerX" secondItem="hHJ-tz-Zfo" secondAttribute="centerX" id="TJH-hi-wcM"/>
<constraint firstItem="jvA-Vd-gMo" firstAttribute="bottom" secondItem="m2S-Jp-Qdl" secondAttribute="bottom" constant="-72" id="TXR-iF-TYp"/>
<constraint firstItem="PYQ-lw-EpL" firstAttribute="leading" secondItem="IZW-rf-f4A" secondAttribute="trailing" constant="3" id="U4C-MJ-9xq"/>
<constraint firstItem="03l-eq-BdN" firstAttribute="leading" secondItem="hvj-7s-TwY" secondAttribute="leading" id="XSI-A5-1wn"/>
<constraint firstAttribute="trailing" secondItem="hHJ-tz-Zfo" secondAttribute="trailing" id="Y4G-Ak-L4o"/>
<constraint firstItem="fwG-yv-1ky" firstAttribute="top" secondItem="hHJ-tz-Zfo" secondAttribute="bottom" constant="10" id="YDL-hS-N28"/>
<constraint firstItem="03l-eq-BdN" firstAttribute="top" secondItem="hvj-7s-TwY" secondAttribute="top" constant="35" id="aIM-aG-d6f"/>
<constraint firstItem="paW-7T-Udu" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" constant="20" id="aUq-vo-NeN"/>
<constraint firstItem="hvj-7s-TwY" firstAttribute="top" secondItem="jgV-z1-Y2K" secondAttribute="bottom" constant="30" id="d3g-2o-f5n"/>
<constraint firstItem="jgV-z1-Y2K" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" constant="40" id="dOU-bE-MfV"/>
<constraint firstItem="hvj-7s-TwY" firstAttribute="leading" secondItem="jgV-z1-Y2K" secondAttribute="leading" id="dOX-nP-MJz"/>
<constraint firstItem="jvA-Vd-gMo" firstAttribute="trailing" secondItem="4TQ-VZ-TmS" secondAttribute="trailing" id="kac-rS-txm"/>
<constraint firstItem="KAa-G4-Uci" firstAttribute="centerY" secondItem="paW-7T-Udu" secondAttribute="centerY" id="mwC-vV-fhw"/>
<constraint firstItem="Dc9-Xu-cYw" firstAttribute="width" secondItem="jvA-Vd-gMo" secondAttribute="width" id="oj0-On-MpP"/>
<constraint firstItem="IZW-rf-f4A" firstAttribute="leading" secondItem="KAa-G4-Uci" secondAttribute="trailing" constant="22" id="rr6-Qb-AEk"/>
<constraint firstItem="jgV-z1-Y2K" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" constant="20" id="rz8-or-NlC"/>
<constraint firstItem="PYQ-lw-EpL" firstAttribute="centerY" secondItem="KAa-G4-Uci" secondAttribute="centerY" id="tyJ-Oo-zzb"/>
<constraint firstItem="paW-7T-Udu" firstAttribute="top" secondItem="hvj-7s-TwY" secondAttribute="bottom" constant="32" id="znA-PO-LrO"/>
<constraint firstItem="paW-7T-Udu" firstAttribute="top" secondItem="hvj-7s-TwY" secondAttribute="bottom" constant="135" id="znA-PO-LrO"/>
</constraints>
</view>
<connections>
<outlet property="autoLoginState" destination="hvj-7s-TwY" id="adQ-vO-ZXg"/>
<outlet property="githubButton" destination="KAa-G4-Uci" id="HzP-kT-H5e"/>
<outlet property="masShortCutView" destination="jvA-Vd-gMo" id="u8T-CH-ucC"/>
<outlet property="showInMenuBarState" destination="03l-eq-BdN" id="dNu-RU-PeR"/>
<outlet property="websiteButton" destination="PYQ-lw-EpL" id="IdY-Vo-epQ"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="647"/>
<point key="canvasLocation" x="75" y="646"/>
</scene>
</scenes>
<resources>
Expand Down
2 changes: 2 additions & 0 deletions Mute Me Now/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@property (weak) IBOutlet NSButton *autoLoginState;
@property (weak) IBOutlet NSButton *showInMenuBarState;

@property (strong) IBOutlet MASShortcutView *masShortCutView;

- (IBAction)showMenuBarChanged:(id)sender;

@end
Expand Down
Loading

0 comments on commit 3b2164e

Please sign in to comment.