Skip to content

Commit

Permalink
Support Apple Silicon (M1) (#112)
Browse files Browse the repository at this point in the history
* add WeBuild badge to README

* always hidden section, hide separators (#95)

Co-authored-by: s-valent <[email protected]>

* Update README.md (#105)

Calling brew cask install is disabled

* Bump version to 1.7 (#111)

Co-authored-by: Han Ngo <[email protected]>
Co-authored-by: Valentin Shinkarev <[email protected]>
Co-authored-by: s-valent <[email protected]>
Co-authored-by: カワリミ人形 <[email protected]>
  • Loading branch information
5 people authored Feb 23, 2021
1 parent 23cee22 commit 16b4191
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 55 deletions.
8 changes: 4 additions & 4 deletions Hidden Bar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_TEAM = W777S7V8TN;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = hidden/Info.plist;
Expand All @@ -567,7 +567,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
PRODUCT_BUNDLE_IDENTIFIER = com.dwarvesv.minimalbar;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -583,7 +583,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_TEAM = W777S7V8TN;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = hidden/Info.plist;
Expand All @@ -592,7 +592,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
PRODUCT_BUNDLE_IDENTIFIER = com.dwarvesv.minimalbar;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
<img width="200" height="200" margin-right="100%" src="https://github.com/dwarvesf/hidden/blob/master/hidden/Assets.xcassets/AppIcon.appiconset/1024x1024.png?raw=true">
</p>
<p align="center">
<a href="https://github.com/dwarvesf/hidden/releases/latest">
<a href="https://webuild.community">
<img src="https://raw.githubusercontent.com/webuild-community/badge/master/svg/love.svg" />
</a>
<a href="https://github.com/dwarvesf/hidden/releases/latest">
<img src="https://img.shields.io/badge/download-latest-brightgreen.svg" alt="download">
</a>
<a href="https://img.shields.io/badge/platform-macOS-lightgrey.svg">
<img src="https://img.shields.io/badge/platform-macOS-lightgrey.svg" alt="platform">
</a>
Expand All @@ -20,12 +24,11 @@ Hidden Bar lets you hide menu bar items to give your Mac a cleaner look.
<img width="400" src="img/screen2.png">
</p>


## 🚀 Install

###  App Store

[![AppStore](/img/appstore.svg)](https://itunes.apple.com/app/hidden-bar/id1452453066)
[![AppStore](img/appstore.svg)](https://itunes.apple.com/app/hidden-bar/id1452453066)

### Others

Expand All @@ -34,7 +37,7 @@ The Hidden Bar is notarized before distributed out side App Store. It's safe to
#### Using Homebrew

```
brew cask install hiddenbar
brew install --cask hiddenbar
```

#### Manual download
Expand Down
6 changes: 4 additions & 2 deletions hidden/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AppDelegate: NSObject, NSApplicationDelegate{
guard let hotKey = hotKey else { return }

hotKey.keyDownHandler = { [weak self] in
self?.statusBarController.expandCollapseIfNeeded(nil)
self?.statusBarController.expandCollapseIfNeeded()
}
}
}
Expand All @@ -47,7 +47,9 @@ class AppDelegate: NSObject, NSApplicationDelegate{
UserDefaults.Key.isAutoStart: false,
UserDefaults.Key.isShowPreference: true,
UserDefaults.Key.isAutoHide: true,
UserDefaults.Key.numberOfSecondForAutoHide: 10.0
UserDefaults.Key.numberOfSecondForAutoHide: 10.0,
UserDefaults.Key.areSeparatorsHidden: false,
UserDefaults.Key.alwaysHiddenSectionEnabled: false
])
}

Expand Down
85 changes: 49 additions & 36 deletions hidden/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions hidden/Common/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,24 @@ enum Preferences {
NotificationCenter.default.post(Notification(name: .prefsChanged))
}
}

static var areSeparatorsHidden: Bool {
get {
UserDefaults.standard.bool(forKey: UserDefaults.Key.areSeparatorsHidden)
}

set {
UserDefaults.standard.set(newValue, forKey: UserDefaults.Key.areSeparatorsHidden)
}
}

static var alwaysHiddenSectionEnabled: Bool {
get {
UserDefaults.standard.bool(forKey: UserDefaults.Key.alwaysHiddenSectionEnabled)
}

set {
UserDefaults.standard.set(newValue, forKey: UserDefaults.Key.alwaysHiddenSectionEnabled)
}
}
}
2 changes: 2 additions & 0 deletions hidden/Extensions/UserDefault+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ extension UserDefaults {
static let isAutoStart = "isAutoStart"
static let isAutoHide = "isAutoHide"
static let isShowPreference = "isShowPreferences"
static let areSeparatorsHidden = "areSeparatorsHidden"
static let alwaysHiddenSectionEnabled = "alwaysHiddenSectionEnabled"
}

open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
Expand Down
8 changes: 8 additions & 0 deletions hidden/Features/Preferences/PreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PreferencesViewController: NSViewController {
@IBOutlet weak var checkBoxKeepInDock: NSButton!
@IBOutlet weak var checkBoxLogin: NSButton!
@IBOutlet weak var checkBoxShowPreferences: NSButton!
@IBOutlet weak var checkBoxShowAlwaysHiddenSection: NSButton!

@IBOutlet weak var timePopup: NSPopUpButton!

Expand Down Expand Up @@ -64,6 +65,12 @@ class PreferencesViewController: NSViewController {
Preferences.isShowPreference = sender.state == .on
}


@IBAction func showAlwaysHiddenSectionChanged(_ sender: NSButton) {
Preferences.alwaysHiddenSectionEnabled = sender.state == .on
}


@IBAction func timePopupDidSelected(_ sender: NSPopUpButton) {
let selectedIndex = sender.indexOfSelectedItem
if let selectedInSecond = SelectedSecond(rawValue: selectedIndex)?.toSeconds() {
Expand Down Expand Up @@ -135,6 +142,7 @@ class PreferencesViewController: NSViewController {
checkBoxLogin.state = Preferences.isAutoStart ? .on : .off
checkBoxAutoHide.state = Preferences.isAutoHide ? .on : .off
checkBoxShowPreferences.state = Preferences.isShowPreference ? .on : .off
checkBoxShowAlwaysHiddenSection.state = Preferences.alwaysHiddenSectionEnabled ? .on : .off
timePopup.selectItem(at: SelectedSecond.secondToPossition(seconds: Preferences.numberOfSecondForAutoHide))
}

Expand Down
85 changes: 76 additions & 9 deletions hidden/Features/StatusBar/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ class StatusBarController {
//MARK: - BarItems
private let expandCollapseStatusBar = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
private let separateStatusBar = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
private let terminateStatusBar = NSStatusBar.system.statusItem(withLength: Preferences.alwaysHiddenSectionEnabled ? 20 : 0)

private let normalStatusBarIconLength: CGFloat = 20
private let collapseStatusBarIconLength: CGFloat = 10000
private var normalSeparateStatusBarIconLength: CGFloat { return Preferences.areSeparatorsHidden ? 0 : 20 }
private let collapseSeparateStatusBarIconLength: CGFloat = 10000

private let normalTerminateStatusBarIconLength: CGFloat = Preferences.alwaysHiddenSectionEnabled ? 20 : 0
private let collapseTerminateStatusBarIconLength: CGFloat = Preferences.alwaysHiddenSectionEnabled ? 10000 : 0

private let imgIconLine = NSImage(named:NSImage.Name("ic_line"))
private let imgIconCollapse = NSImage(named:NSImage.Name("ic_collapse"))
private let imgIconExpand = NSImage(named:NSImage.Name("ic_expand"))

private var isCollapsed: Bool {
return self.separateStatusBar.length == self.collapseStatusBarIconLength
return self.separateStatusBar.length == self.collapseSeparateStatusBarIconLength
}

private var isValidPosition: Bool {
Expand All @@ -34,7 +38,18 @@ class StatusBarController {
let separateBarButtonX = self.separateStatusBar.button?.getOrigin?.x
else {return false}

return expandBarButtonX > separateBarButtonX
return expandBarButtonX >= separateBarButtonX
}

private var isValidTogglablePosition: Bool {
if !Preferences.alwaysHiddenSectionEnabled { return true }

guard
let separateBarButtonX = self.separateStatusBar.button?.getOrigin?.x,
let terminateBarButtonX = self.terminateStatusBar.button?.getOrigin?.x
else {return false}

return separateBarButtonX >= terminateBarButtonX
}

//MARK: - Methods
Expand All @@ -46,6 +61,7 @@ class StatusBarController {
self.collapseMenuBar()
})

if Preferences.areSeparatorsHidden {hideSeparators()}
autoCollapseIfNeeded()
}

Expand All @@ -54,20 +70,71 @@ class StatusBarController {
button.image = self.imgIconLine
}

separateStatusBar.menu = self.getContextMenu()
if let button = terminateStatusBar.button {
button.image = self.imgIconLine
button.appearsDisabled = true
}

let menu = self.getContextMenu()
separateStatusBar.menu = menu
terminateStatusBar.menu = menu
updateMenuTitles()

if let button = expandCollapseStatusBar.button {
button.image = self.imgIconCollapse
button.target = self
button.action = #selector(expandCollapseIfNeeded(_:))

button.action = #selector(self.statusBarButtonClicked(sender:))
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
}

expandCollapseStatusBar.autosaveName = "hiddenbar_expandcollapse";
separateStatusBar.autosaveName = "hiddenbar_separate";
terminateStatusBar.autosaveName = "hiddenbar_terminate";
}

@objc func statusBarButtonClicked(sender: NSStatusBarButton) {
if let event = NSApp.currentEvent {

let isOptionKeyPressed = event.modifierFlags.contains(NSEvent.ModifierFlags.option)

if event.type == NSEvent.EventType.leftMouseUp && !isOptionKeyPressed{
self.expandCollapseIfNeeded()
} else {
self.toggleSeparators()
}
}
}

func toggleSeparators() {
Preferences.areSeparatorsHidden ? self.showSeparators() : self.hideSeparators()

if self.isCollapsed {self.expandMenubar()}
}

private func showSeparators() {
Preferences.areSeparatorsHidden = false

if !self.isCollapsed {
self.separateStatusBar.length = self.normalSeparateStatusBarIconLength
}

self.terminateStatusBar.length = self.normalTerminateStatusBarIconLength
}

private func hideSeparators() {
guard self.isValidTogglablePosition else {return}

Preferences.areSeparatorsHidden = true

if !self.isCollapsed {
self.separateStatusBar.length = self.normalSeparateStatusBarIconLength
}

self.terminateStatusBar.length = self.collapseTerminateStatusBarIconLength
}

@objc func expandCollapseIfNeeded(_ sender: NSStatusBarButton?) {
func expandCollapseIfNeeded() {
self.isCollapsed ? self.expandMenubar() : self.collapseMenuBar()
}

Expand All @@ -77,7 +144,7 @@ class StatusBarController {
return
}

separateStatusBar.length = self.collapseStatusBarIconLength
separateStatusBar.length = self.collapseSeparateStatusBarIconLength
if let button = expandCollapseStatusBar.button {
button.image = self.imgIconExpand
}
Expand All @@ -86,7 +153,7 @@ class StatusBarController {

private func expandMenubar() {
guard self.isCollapsed else {return}
separateStatusBar.length = normalStatusBarIconLength
separateStatusBar.length = normalSeparateStatusBarIconLength
if let button = expandCollapseStatusBar.button {
button.image = self.imgIconCollapse
}
Expand Down

0 comments on commit 16b4191

Please sign in to comment.