Skip to content

Commit

Permalink
Merge pull request #18 from dwarvesf/develop
Browse files Browse the repository at this point in the history
hot fix for save current state feature
  • Loading branch information
siliconprime-thanhduc authored Mar 1, 2019
2 parents 41022b1 + abec268 commit 06aef95
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Hidden Bar lets you hide menu bar items to give your Mac a cleaner look.
</p>

## Requirements
macOS version >= 10.13
macOS version >= 10.13

## Contribution
## License

If you
MIT &copy; [Dwarves Foundation](https://github.com/dwarvesf)
26 changes: 19 additions & 7 deletions hidden/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@
<objects>
<viewController storyboardIdentifier="prefVC" showSeguePresentationStyle="single" id="XfG-lQ-9wD" customClass="ViewController" customModule="Hidden_Bar" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="600" height="448"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="494"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<box autoresizesSubviews="NO" fixedFrame="YES" boxType="custom" borderType="none" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Jjd-1G-63n">
<rect key="frame" x="0.0" y="174" width="600" height="274"/>
<rect key="frame" x="0.0" y="220" width="600" height="274"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" id="TZd-5p-NFL">
<rect key="frame" x="0.0" y="0.0" width="600" height="274"/>
Expand All @@ -735,7 +735,7 @@
<color key="fillColor" name="quaternaryLabelColor" catalog="System" colorSpace="catalog"/>
</box>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cbR-Jv-adm">
<rect key="frame" x="73" y="126" width="292" height="30"/>
<rect key="frame" x="73" y="172" width="292" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Start Hidden Bar when I log in" bezelStyle="regularSquare" imagePosition="left" inset="2" id="W1G-55-zGo">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -746,7 +746,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gj1-Ms-4No">
<rect key="frame" x="73" y="88" width="308" height="30"/>
<rect key="frame" x="73" y="134" width="308" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Automatically hide icon after five seconds" bezelStyle="regularSquare" imagePosition="left" inset="2" id="kg8-rW-srh">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -757,7 +757,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6Dz-il-Lwp">
<rect key="frame" x="73" y="50" width="292" height="30"/>
<rect key="frame" x="73" y="96" width="292" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Keep icon in dock" bezelStyle="regularSquare" imagePosition="left" inset="2" id="cUd-D7-0WY">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -768,7 +768,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gWT-L1-Xdf">
<rect key="frame" x="73" y="12" width="292" height="30"/>
<rect key="frame" x="73" y="58" width="292" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Show preferences on launch" bezelStyle="regularSquare" imagePosition="left" inset="2" id="hCh-Ue-NgH">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -778,11 +778,23 @@
<action selector="showPreferencesChanged:" target="XfG-lQ-9wD" id="UYB-yR-xTM"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3rx-g0-xcM">
<rect key="frame" x="73" y="20" width="139" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Keep last app state" bezelStyle="regularSquare" imagePosition="left" inset="2" id="31D-vN-XSA">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="onLastKeepAppStateChange:" target="XfG-lQ-9wD" id="dE2-Vi-5ST"/>
</connections>
</button>
</subviews>
</view>
<connections>
<outlet property="checkBoxAutoHide" destination="gj1-Ms-4No" id="Ibl-5H-2vh"/>
<outlet property="checkBoxKeepInDock" destination="6Dz-il-Lwp" id="Dcg-eh-7gL"/>
<outlet property="checkBoxKeepLastState" destination="3rx-g0-xcM" id="76B-1e-ahO"/>
<outlet property="checkBoxLogin" destination="cbR-Jv-adm" id="DFO-De-0KU"/>
<outlet property="checkBoxShowPreferences" destination="gWT-L1-Xdf" id="sC8-cw-Fmh"/>
<outlet property="imageViewTop" destination="ZE5-y9-i8b" id="wNv-Wx-ILV"/>
Expand All @@ -791,7 +803,7 @@
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="743"/>
<point key="canvasLocation" x="75" y="766"/>
</scene>
</scenes>
</document>
1 change: 1 addition & 0 deletions hidden/Common/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let IS_AUTO_START = "isAutoStart"
let IS_AUTO_HIDE = "isAutoHide"
let IS_KEEP_IN_DOCK = "isKeepInDock"
let IS_SHOW_PREFERENCES = "isShowPreferences"
let IS_KEEP_LAST_STATE = "isKeepLastState"
let App_Name = "Hidden Bar"
let IS_COLLAPSE = "isCollapse"

Expand Down
15 changes: 15 additions & 0 deletions hidden/Common/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ class Util {
return getShowPreferences() ? .on : .off
}


static func getKeepLastState() -> Bool {
let savedValue = UserDefaults.standard.bool(forKey: IS_KEEP_LAST_STATE)
return savedValue
}

static func setKeepLastState(_ isKeepLastState: Bool) {
UserDefaults.standard.set(isKeepLastState, forKey: IS_KEEP_LAST_STATE)
}

static func getStateKeepLastState() -> NSControl.StateValue {
return getKeepLastState() ? .on : .off
}


static func isMenuOpened() -> Bool {
let options = CGWindowListOption(arrayLiteral: .excludeDesktopElements, .optionOnScreenOnly)
let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
Expand Down
2 changes: 1 addition & 1 deletion hidden/ViewControlllers/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class StatusBarController{
}

private func checkCollapseWhenOpen(){
if(Util.getIsCollapse())
if(Util.getIsCollapse() && Util.getKeepLastState())
{
if(isToggle && isValidPosition())
{
Expand Down
14 changes: 14 additions & 0 deletions hidden/ViewControlllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Cocoa

class ViewController: NSViewController {

@IBOutlet weak var checkBoxKeepLastState: NSButton!
@IBOutlet weak var textFieldTitle: NSTextField!
@IBOutlet weak var imageViewTop: NSImageView!

Expand All @@ -29,6 +30,7 @@ class ViewController: NSViewController {
checkBoxAutoHide.state = Util.getStateAutoHide()
checkBoxKeepInDock.state = Util.getStateKeepInDock()
checkBoxShowPreferences.state = Util.getStateShowPreferences()
checkBoxKeepLastState.state = Util.getStateKeepLastState()
}

override var representedObject: Any? {
Expand Down Expand Up @@ -79,6 +81,7 @@ class ViewController: NSViewController {
}
}


@IBAction func showPreferencesChanged(_ sender: NSButton) {
switch sender.state {
case .on:
Expand All @@ -89,5 +92,16 @@ class ViewController: NSViewController {
break
}
}

@IBAction func onLastKeepAppStateChange(_ sender: NSButton) {
switch sender.state {
case .on:
Util.setKeepLastState(true)
case .off:
Util.setKeepLastState(false)
default:
break
}
}
}

0 comments on commit 06aef95

Please sign in to comment.