Skip to content

Commit

Permalink
add an option to hide status bar icon
Browse files Browse the repository at this point in the history
  • Loading branch information
L1cardo committed Mar 30, 2020
1 parent 0fff998 commit cd9cdc1
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 34 deletions.
12 changes: 6 additions & 6 deletions ClockBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
091F12975425693F99521C97 /* Pods_ClockBar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ClockBar.framework; sourceTree = BUILT_PRODUCTS_DIR; };
376ECC70A35AC58E99F85ACB /* Pods-ClockBar.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ClockBar.release.xcconfig"; path = "Target Support Files/Pods-ClockBar/Pods-ClockBar.release.xcconfig"; sourceTree = "<group>"; };
964408C723F3CD3200CDF07C /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.strings"; sourceTree = "<group>"; };
964408CB23F3CEF400CDF07C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/MainMenu.strings; sourceTree = "<group>"; };
9646ECC5237583FE0019A927 /* ClockBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ClockBar.app; sourceTree = BUILT_PRODUCTS_DIR; };
9646ECC8237583FE0019A927 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9646ECCA237583FF0019A927 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -44,6 +43,7 @@
9646ECD62375843B0019A927 /* ClockBar-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ClockBar-Bridging-Header.h"; sourceTree = "<group>"; };
9646ECD72375843B0019A927 /* TouchBar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBar.h; sourceTree = "<group>"; };
9646ECDA237584CE0019A927 /* DFRFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DFRFoundation.framework; path = ../../../../System/Library/PrivateFrameworks/DFRFoundation.framework; sourceTree = "<group>"; };
96BD288C24322EE8008C42AD /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/MainMenu.strings; sourceTree = "<group>"; };
9B956657E1A6217BD8CE988F /* Pods-ClockBar.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ClockBar.debug.xcconfig"; path = "Target Support Files/Pods-ClockBar/Pods-ClockBar.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -256,7 +256,7 @@
children = (
9646ECCD237583FF0019A927 /* Base */,
964408C723F3CD3200CDF07C /* zh-Hans */,
964408CB23F3CEF400CDF07C /* en */,
96BD288C24322EE8008C42AD /* en */,
);
name = MainMenu.xib;
sourceTree = "<group>";
Expand Down Expand Up @@ -392,15 +392,15 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20200308;
CURRENT_PROJECT_VERSION = 20200330;
DEVELOPMENT_TEAM = 2U23P5CPX2;
ENABLE_HARDENED_RUNTIME = NO;
INFOPLIST_FILE = "ClockBar/Supporting Files/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.2;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = cn.licardo.ClockBar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ClockBar/TouchBar/ClockBar-Bridging-Header.h";
Expand All @@ -424,15 +424,15 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20200308;
CURRENT_PROJECT_VERSION = 20200330;
DEVELOPMENT_TEAM = 2U23P5CPX2;
ENABLE_HARDENED_RUNTIME = NO;
INFOPLIST_FILE = "ClockBar/Supporting Files/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.2;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = cn.licardo.ClockBar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ClockBar/TouchBar/ClockBar-Bridging-Header.h";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "25FE4E51-B191-403A-B172-1F36867BE17D"
type = "0"
version = "2.0">
</Bucket>
28 changes: 22 additions & 6 deletions ClockBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
@IBOutlet weak var preferencesWindowVersionNum: NSTextField!
@IBOutlet weak var aboutWindowVersionNum: NSTextField!
@IBOutlet weak var launchAtLoginCheckbox: NSButton!
@IBOutlet weak var hideStatusBarIconCheckBox: NSButton!
@IBOutlet weak var time1Text: NSTextField!
@IBOutlet weak var time2Text: NSTextField!
@IBOutlet weak var preferencesWindow: NSWindow!
Expand All @@ -38,6 +39,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
displayStatusBarMenu()

launchAtLoginCheckbox.state = LoginServiceKit.isExistLoginItems() ? .on : .off
hideStatusBarIconCheckBox.state = Defaults[.shouldShowStatusBarIcon] ? .off : .on

time1Text.delegate = self
time2Text.delegate = self
Expand All @@ -50,6 +52,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
NSApp.activate(ignoringOtherApps: true)
aboutWindow.close()
preferencesWindow.makeKeyAndOrderFront(sender)
return true
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
Expand Down Expand Up @@ -105,6 +114,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
func displayStatusBarMenu() {
guard let button = statusBarItem.button else { return }
statusBarItem.button?.image = NSImage(named: "StatusBarIcon")
statusBarItem.isVisible = Defaults[.shouldShowStatusBarIcon] ? true : false
button.action = #selector(statusBarMenuClicked)
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
}
Expand Down Expand Up @@ -139,22 +149,28 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {

// launch at login checkbox
@IBAction func launchAtLoginChecked(_ sender: NSButton) {
let isChecked = launchAtLoginCheckbox.state == .on
if isChecked == true {
if sender.state == .on {
LoginServiceKit.addLoginItems()
} else {
LoginServiceKit.removeLoginItems()
}
}
@IBAction func HideStatusBarIconChecked(_ sender: NSButton) {
if sender.state == .on {
statusBarItem.isVisible = false
Defaults[.shouldShowStatusBarIcon] = false
} else {
statusBarItem.isVisible = true
Defaults[.shouldShowStatusBarIcon] = true
}
}

@IBAction func timeFormat(_ sender: NSButton) {
switch sender.tag {
case 0:
UserDefaults.standard.set("h:mm", forKey: "timeFormat")

case 1:
UserDefaults.standard.set("HH:mm", forKey: "timeFormat")

default:
return
}
Expand Down Expand Up @@ -206,7 +222,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
}
NSWorkspace.shared.open(URL(string: url)!)
}

}

class LinkButton: NSButton {
Expand All @@ -223,5 +238,6 @@ extension Defaults.Keys {
static let time1 = Key<String>("time1", default: "h:mm")
static let time2 = Key<String>("time2", default: "HH:mm")
static let showTime = Key<String>("showTime", default: "h:mm")
static let shouldShowTime1 = Key<Bool>("showTime1", default: true)
static let shouldShowTime1 = Key<Bool>("shouldShowTime1", default: true)
static let shouldShowStatusBarIcon = Key<Bool>("shouldShowStatusBarIcon", default: true)
}
Loading

0 comments on commit cd9cdc1

Please sign in to comment.