Skip to content

Commit

Permalink
remove @nihalsharma from contributors list
Browse files Browse the repository at this point in the history
Nothing to say, interesting!
  • Loading branch information
L1cardo committed Nov 13, 2019
1 parent d6ea4b4 commit 3854e76
Show file tree
Hide file tree
Showing 39 changed files with 2,790 additions and 2 deletions.
465 changes: 465 additions & 0 deletions ClockBar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
78 changes: 78 additions & 0 deletions ClockBar.xcodeproj/xcshareddata/xcschemes/ClockBar.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1120"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9646ECC4237583FE0019A927"
BuildableName = "ClockBar.app"
BlueprintName = "ClockBar"
ReferencedContainer = "container:ClockBar.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9646ECC4237583FE0019A927"
BuildableName = "ClockBar.app"
BlueprintName = "ClockBar"
ReferencedContainer = "container:ClockBar.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9646ECC4237583FE0019A927"
BuildableName = "ClockBar.app"
BlueprintName = "ClockBar"
ReferencedContainer = "container:ClockBar.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
10 changes: 10 additions & 0 deletions ClockBar.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ClockBar.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
199 changes: 199 additions & 0 deletions ClockBar/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
//
// AppDelegate.swift
// ClockBar
//
// Created by Licardo on 2019/11/8.
// Copyright © 2019 Licardo. All rights reserved.
//

import Cocoa
import LoginServiceKit
import Defaults

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var statusBarMenu: NSMenu!
@IBOutlet weak var preferencesWindowVersionNum: NSTextField!
@IBOutlet weak var aboutWindowVersionNum: NSTextField!
@IBOutlet weak var launchAtLoginCheckbox: NSButton!
@IBOutlet weak var timeFormat12h: NSButton!
@IBOutlet weak var timeFormat24h: NSButton!
@IBOutlet weak var preferencesWindow: NSWindow!
@IBOutlet weak var aboutWindow: NSWindow!
@IBOutlet weak var alertWindow: NSWindow!

var touchBarButton: NSButton?
var timeFormatter: DateFormatter?
let statusBarMenuItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

func applicationDidFinishLaunching(_ aNotification: Notification) {

// get current version
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
preferencesWindowVersionNum.stringValue = version
aboutWindowVersionNum.stringValue = version

// status bar
statusBarMenuItem.button?.image = NSImage(named: "StatusBarIcon")
statusBarMenuItem.button?.action = #selector(self.displayStatusBarMenu)

launchAtLoginCheckbox.state = LoginServiceKit.isExistLoginItems() ? .on : .off

switch Defaults[.timeFormat] {
case "h:mm":
timeFormat12h.state = .on
timeFormat24h.state = .off
case "HH:mm":
timeFormat12h.state = .off
timeFormat24h.state = .on
default:
return
}

clockBar()

// update time
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}


// add clockbar to touch bar
func clockBar() {
DFRSystemModalShowsCloseBoxWhenFrontMost(true)

timeFormatter = DateFormatter()
timeFormatter?.dateFormat = Defaults[.timeFormat]
let nowTime = timeFormatter?.string(from: Date())

let clockBarIdentifier = NSTouchBarItem.Identifier(rawValue: "ClockBar")
let clockBar = NSCustomTouchBarItem.init(identifier: clockBarIdentifier)
touchBarButton = NSButton(title: nowTime!, target: nil, action: nil)
clockBar.view = touchBarButton!
NSTouchBarItem.addSystemTrayItem(clockBar)
DFRElementSetControlStripPresenceForIdentifier(clockBarIdentifier, true)
}

// update time
@objc func updateTime() {
timeFormatter?.dateFormat = Defaults[.timeFormat]
touchBarButton?.title = (timeFormatter?.string(from: Date()))!
}

// display status menu
@objc func displayStatusBarMenu() {
guard let button = statusBarMenuItem.button else { return }
let x = button.frame.origin.x
let y = button.frame.origin.y - 5
let w = button.window
let location = button.superview!.convert(NSMakePoint(x, y), to: nil)
let event = NSEvent.mouseEvent(with: .leftMouseUp,
location: location,
modifierFlags: NSEvent.ModifierFlags(rawValue: 0),
timestamp: 0,
windowNumber: w!.windowNumber,
context: NSGraphicsContext.init(),
eventNumber: 0,
clickCount: 1,
pressure: 0)!
NSMenu.popUpContextMenu(statusBarMenu, with: event, for: button)
}


// click status bar menu item
@IBAction func didClickStatusBarMenuItem(_ sender: NSMenuItem) {
switch sender.tag {
case 1:
NSApp.activate(ignoringOtherApps: true)
aboutWindow.close()
preferencesWindow.makeKeyAndOrderFront(sender)
case 3:
NSApp.activate(ignoringOtherApps: true)
preferencesWindow.close()
aboutWindow.makeKeyAndOrderFront(sender)
case 4:
NSApp.activate(ignoringOtherApps: true)
alertWindow.makeKeyAndOrderFront(sender)
default:
return
}
}

// launch at login checkbox
@IBAction func launchAtLoginChecked(_ sender: NSButton) {
let isChecked = launchAtLoginCheckbox.state == .on
if isChecked == true {
LoginServiceKit.addLoginItems()
} else {
LoginServiceKit.removeLoginItems()
}
}

@IBAction func timeFormat(_ sender: NSButton) {
switch sender.tag {
case 0:
Defaults[.timeFormat] = "h:mm"
timeFormat24h.state = .off
case 1:
Defaults[.timeFormat] = "HH:mm"
timeFormat12h.state = .off
default:
return
}
}

// preferences window close button
@IBAction func preferencesWindowClosetButton(_ sender: Any) {
preferencesWindow.close()
}

// preferences window quit button
@IBAction func preferencesWindowQuitButton(_ sender: NSButton) {
NSApp.activate(ignoringOtherApps: true)
alertWindow.makeKeyAndOrderFront(sender)
}

// alert window yes button
@IBAction func alertWindowYesButton(_ sender: NSButton) {
NSApp.terminate(self)
}

// alert window cancel button
@IBAction func alertWindowCancelButton(_ sender: NSButton) {
alertWindow.close()
}

// about window urls
@IBAction func didClickURL(_ sender: NSButton) {
let url: String
switch sender.tag {
case 1:
url = "https://github.com/L1cardo"
case 2:
url = "https://licardo.cn"
case 3:
url = "https://twitter.com/AlbertAbdilim"
case 41:
url = "https://paypal.me/mrlicardo"
case 42:
url = "https://raw.githubusercontent.com/L1cardo/Image-Hosting/master/donate/alipay.jpg"
case 43:
url = "https://raw.githubusercontent.com/L1cardo/Image-Hosting/master/donate/wechat.jpg"
case 5:
url = "mailto:[email protected]"
default:
return
}
NSWorkspace.shared.open(URL(string: url)!)
}


}

extension Defaults.Keys {
static let timeFormat = Key<String>("timeFormat", default: "h:mm")
}
Loading

0 comments on commit 3854e76

Please sign in to comment.