Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10.14 plus #69

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Install as a [cask](https://caskroom.github.io) via `brew cask install michaelvi

Inspired by the **great** [Minutes widget](http://minutes.en.softonic.com/mac) from Nitram-nunca I've been using for years. But it wasn't maintained anymore (non-retina) + it was the only widget in my dashboard :)

Timer requires macOS 10.11 or later.
Timer requires macOS 10.13 or later.

### Build

Expand Down
6 changes: 3 additions & 3 deletions Timer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -284,7 +284,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand All @@ -300,7 +300,7 @@
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = Timer/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.michaelvillar.Timer;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
30 changes: 15 additions & 15 deletions Timer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {

private var controllers: [MVTimerController] = []
private var currentlyInDock : MVTimerController?

private var staysOnTop = false {
didSet {
for window in NSApplication.shared.windows {
window.level = self.windowLevel()
}
}
}

override init() {
super.init()
self.registerDefaults()
Expand All @@ -23,17 +23,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
let controller = MVTimerController()
controllers.append(controller)
self.addBadgeToDock(controller: controller)

NSUserNotificationCenter.default.delegate = self

let nc = NotificationCenter.default
nc.addObserver(self, selector: #selector(handleClose), name: NSWindow.willCloseNotification, object: nil)
nc.addObserver(self, selector: #selector(handleUserDefaultsChange), name: UserDefaults.didChangeNotification, object: nil)
nc.addObserver(self, selector: #selector(handleOcclusionChange), name: NSWindow.didChangeOcclusionStateNotification, object: nil)

staysOnTop = UserDefaults.standard.bool(forKey: MVUserDefaultsKeys.staysOnTop)
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
for window in NSApplication.shared.windows {
window.makeKeyAndOrderFront(self)
Expand All @@ -44,27 +44,27 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
return true
}

func addBadgeToDock(controller: MVTimerController){
if currentlyInDock != controller {
self.removeBadgeFromDock()
}
currentlyInDock = controller
controller.showInDock(true)
}

func removeBadgeFromDock() {
if currentlyInDock != nil {
currentlyInDock!.showInDock(false)
}
}

@objc func newDocument(_ sender: AnyObject?) {
let controller = MVTimerController(closeToWindow: NSApplication.shared.keyWindow)
controller.window?.level = self.windowLevel()
controllers.append(controller)
}

@objc func handleClose(_ notification: Notification) {
if let window = notification.object as? NSWindow,
let controller = window.windowController as? MVTimerController,
Expand All @@ -73,23 +73,23 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
controllers.remove(at: index)
}
}

@objc func handleOcclusionChange(_ notification: Notification) {
if let window = notification.object as? NSWindow,
let controller = window.windowController as? MVTimerController
{
controller.windowVisibilityChanged(window.isVisible)
}
}

@objc func handleUserDefaultsChange(_ notification: Notification) {
staysOnTop = UserDefaults.standard.bool(forKey: MVUserDefaultsKeys.staysOnTop)
}

func windowLevel() -> NSWindow.Level {
return staysOnTop ? .floating : .normal
}

private func registerDefaults() {
UserDefaults.standard.register(defaults: [MVUserDefaultsKeys.staysOnTop: false])
}
Expand Down
10 changes: 5 additions & 5 deletions Timer/Keycodes.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct Keycode {

// Layout-independent Keys
// eg.These key codes are always the same key on all layouts.
static let returnKey : UInt16 = 0x24
Expand Down Expand Up @@ -50,7 +50,7 @@ struct Keycode {
static let f18 : UInt16 = 0x4F
static let f19 : UInt16 = 0x50
static let f20 : UInt16 = 0x5A

// US-ANSI Keyboard Positions
// eg. These key codes are for the physical key (in any keyboard layout)
// at the location of the named key in the US-ANSI layout.
Expand Down Expand Up @@ -80,7 +80,7 @@ struct Keycode {
static let x : UInt16 = 0x07
static let y : UInt16 = 0x10
static let z : UInt16 = 0x06

static let zero : UInt16 = 0x1D
static let one : UInt16 = 0x12
static let two : UInt16 = 0x13
Expand All @@ -91,7 +91,7 @@ struct Keycode {
static let seven : UInt16 = 0x1A
static let eight : UInt16 = 0x1C
static let nine : UInt16 = 0x19

static let equals : UInt16 = 0x18
static let minus : UInt16 = 0x1B
static let semicolon : UInt16 = 0x29
Expand All @@ -103,7 +103,7 @@ struct Keycode {
static let grave : UInt16 = 0x32
static let leftBracket : UInt16 = 0x21
static let rightBracket : UInt16 = 0x1E

static let keypadDecimal : UInt16 = 0x41
static let keypadMultiply : UInt16 = 0x43
static let keypadPlus : UInt16 = 0x45
Expand Down
Loading