From b4c842c2438c049581376dbe0cce5aebecf2fab7 Mon Sep 17 00:00:00 2001 From: AlvinZhu Date: Sun, 15 May 2016 00:14:00 +0800 Subject: [PATCH] refactor --- Podfile | 1 + Podfile.lock | 3 + Thor.xcodeproj/project.pbxproj | 38 ++++++----- Thor/AppDelegate.swift | 44 ++++++------- Thor/AppsManager.swift | 2 +- Thor/Base.lproj/Main.storyboard | 42 ++++++++----- Thor/Constant.swift | 2 +- Thor/DefaultsKeys+Extension.swift | 2 +- ...swift => EditShortcutViewController.swift} | 11 ++-- ...ift => EditShortcutWindowController.swift} | 7 +-- Thor/Info.plist | 8 ++- Thor/MainWindowController.swift | 4 +- Thor/NSApplication+Extension.swift | 24 +++++++ Thor/NSView+Extension.swift | 63 ------------------- ...swift => ShortcutListViewController.swift} | 34 +++++----- ...sRegister.swift => ShortcutRegister.swift} | 20 +++--- Thor/StatusItemController.swift | 16 +++-- Thor/TOLWindowController.swift | 2 +- 18 files changed, 150 insertions(+), 173 deletions(-) rename Thor/{EditHotKeyViewController.swift => EditShortcutViewController.swift} (95%) rename Thor/{EditHotKeyWindowController.swift => EditShortcutWindowController.swift} (67%) delete mode 100644 Thor/NSView+Extension.swift rename Thor/{HotKeyListViewController.swift => ShortcutListViewController.swift} (66%) rename Thor/{HotKeysRegister.swift => ShortcutRegister.swift} (87%) diff --git a/Podfile b/Podfile index 6e8ea2c..1d9946c 100644 --- a/Podfile +++ b/Podfile @@ -4,5 +4,6 @@ use_frameworks! target 'Thor' do pod 'MASShortcut' pod 'SwiftyUserDefaults' + pod 'Sparkle' end diff --git a/Podfile.lock b/Podfile.lock index 9ab6914..56590b5 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,13 +1,16 @@ PODS: - MASShortcut (2.3.3) + - Sparkle (1.14.0) - SwiftyUserDefaults (2.1.3) DEPENDENCIES: - MASShortcut + - Sparkle - SwiftyUserDefaults SPEC CHECKSUMS: MASShortcut: 38a76c9ea927de770c0a97ae28b15d18d6268b24 + Sparkle: ccd95233b12a3e3d4eeb55ff01dd4c8bb8188b07 SwiftyUserDefaults: bd394a09247e3f00e17e402aa535c047c5d12b07 COCOAPODS: 0.39.0 diff --git a/Thor.xcodeproj/project.pbxproj b/Thor.xcodeproj/project.pbxproj index b54ef5a..f077c08 100644 --- a/Thor.xcodeproj/project.pbxproj +++ b/Thor.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ B2B04B781CC74DC7005C9BEF /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B04B771CC74DC7005C9BEF /* MainWindowController.swift */; }; B2D65A071CDAF2D500E39A65 /* NSApplication+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2D65A061CDAF2D500E39A65 /* NSApplication+Extension.swift */; }; - B2D65A091CDB1BA100E39A65 /* HotKeysRegister.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2D65A081CDB1BA100E39A65 /* HotKeysRegister.swift */; }; B2E1B0441CC48CD900FB687F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E1B0431CC48CD900FB687F /* AppDelegate.swift */; }; B2E1B0481CC48CD900FB687F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B2E1B0471CC48CD900FB687F /* Assets.xcassets */; }; B2E1B04B1CC48CD900FB687F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B2E1B0491CC48CD900FB687F /* Main.storyboard */; }; @@ -17,15 +16,15 @@ B2E1B0571CC4A85700FB687F /* AppsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E1B0561CC4A85700FB687F /* AppsManager.swift */; }; B2E1B05B1CC4AE2600FB687F /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E1B05A1CC4AE2600FB687F /* Constant.swift */; }; B2E1B05D1CC4AE4500FB687F /* DefaultsKeys+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E1B05C1CC4AE4500FB687F /* DefaultsKeys+Extension.swift */; }; - B2E1B0611CC4B16200FB687F /* NSView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E1B0601CC4B16200FB687F /* NSView+Extension.swift */; }; B2E1B0691CC4CDD100FB687F /* TOLWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E1B0681CC4CDD100FB687F /* TOLWindowController.swift */; }; B2E1B06B1CC4D49800FB687F /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E1B06A1CC4D49800FB687F /* SettingsViewController.swift */; }; B2F635FC1CD35BDD00E1232D /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F635FB1CD35BDD00E1232D /* String+Extension.swift */; }; C70F7238CC27794CB6C37880 /* Pods_Thor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE6D8111B4E9725A60F041E4 /* Pods_Thor.framework */; }; E166F32B1CE4B7E300F7C7B8 /* StatusItemController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F32A1CE4B7E300F7C7B8 /* StatusItemController.swift */; }; - E166F32F1CE4BBA000F7C7B8 /* HotKeyListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F32E1CE4BBA000F7C7B8 /* HotKeyListViewController.swift */; }; - E166F3311CE4BC5B00F7C7B8 /* EditHotKeyWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F3301CE4BC5B00F7C7B8 /* EditHotKeyWindowController.swift */; }; - E166F3331CE4BC7F00F7C7B8 /* EditHotKeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F3321CE4BC7F00F7C7B8 /* EditHotKeyViewController.swift */; }; + E166F3391CE7801A00F7C7B8 /* ShortcutListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F3371CE7801A00F7C7B8 /* ShortcutListViewController.swift */; }; + E166F33C1CE780A600F7C7B8 /* EditShortcutWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F33B1CE780A600F7C7B8 /* EditShortcutWindowController.swift */; }; + E166F33E1CE780CA00F7C7B8 /* EditShortcutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F33D1CE780CA00F7C7B8 /* EditShortcutViewController.swift */; }; + E166F3401CE781EC00F7C7B8 /* ShortcutRegister.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166F33F1CE781EC00F7C7B8 /* ShortcutRegister.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -33,7 +32,6 @@ 3A89078B5AFF17A0F2DB5DAA /* Pods-Thor.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Thor.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Thor/Pods-Thor.debug.xcconfig"; sourceTree = ""; }; B2B04B771CC74DC7005C9BEF /* MainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = ""; }; B2D65A061CDAF2D500E39A65 /* NSApplication+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSApplication+Extension.swift"; sourceTree = ""; }; - B2D65A081CDB1BA100E39A65 /* HotKeysRegister.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HotKeysRegister.swift; sourceTree = ""; }; B2E1B0401CC48CD900FB687F /* Thor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Thor.app; sourceTree = BUILT_PRODUCTS_DIR; }; B2E1B0431CC48CD900FB687F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; B2E1B0471CC48CD900FB687F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -43,14 +41,14 @@ B2E1B0561CC4A85700FB687F /* AppsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppsManager.swift; sourceTree = ""; }; B2E1B05A1CC4AE2600FB687F /* Constant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; B2E1B05C1CC4AE4500FB687F /* DefaultsKeys+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DefaultsKeys+Extension.swift"; sourceTree = ""; }; - B2E1B0601CC4B16200FB687F /* NSView+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSView+Extension.swift"; sourceTree = ""; }; B2E1B0681CC4CDD100FB687F /* TOLWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TOLWindowController.swift; sourceTree = ""; }; B2E1B06A1CC4D49800FB687F /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; B2F635FB1CD35BDD00E1232D /* String+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = ""; }; E166F32A1CE4B7E300F7C7B8 /* StatusItemController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusItemController.swift; sourceTree = ""; }; - E166F32E1CE4BBA000F7C7B8 /* HotKeyListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HotKeyListViewController.swift; sourceTree = ""; }; - E166F3301CE4BC5B00F7C7B8 /* EditHotKeyWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHotKeyWindowController.swift; sourceTree = ""; }; - E166F3321CE4BC7F00F7C7B8 /* EditHotKeyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHotKeyViewController.swift; sourceTree = ""; }; + E166F3371CE7801A00F7C7B8 /* ShortcutListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShortcutListViewController.swift; sourceTree = ""; }; + E166F33B1CE780A600F7C7B8 /* EditShortcutWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditShortcutWindowController.swift; sourceTree = ""; }; + E166F33D1CE780CA00F7C7B8 /* EditShortcutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditShortcutViewController.swift; sourceTree = ""; }; + E166F33F1CE781EC00F7C7B8 /* ShortcutRegister.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShortcutRegister.swift; sourceTree = ""; }; EE6D8111B4E9725A60F041E4 /* Pods_Thor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Thor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -80,10 +78,10 @@ E166F32A1CE4B7E300F7C7B8 /* StatusItemController.swift */, B2E1B0681CC4CDD100FB687F /* TOLWindowController.swift */, B2B04B771CC74DC7005C9BEF /* MainWindowController.swift */, - E166F32E1CE4BBA000F7C7B8 /* HotKeyListViewController.swift */, + E166F3371CE7801A00F7C7B8 /* ShortcutListViewController.swift */, B2E1B06A1CC4D49800FB687F /* SettingsViewController.swift */, - E166F3301CE4BC5B00F7C7B8 /* EditHotKeyWindowController.swift */, - E166F3321CE4BC7F00F7C7B8 /* EditHotKeyViewController.swift */, + E166F33B1CE780A600F7C7B8 /* EditShortcutWindowController.swift */, + E166F33D1CE780CA00F7C7B8 /* EditShortcutViewController.swift */, ); name = Controller; sourceTree = ""; @@ -134,7 +132,7 @@ isa = PBXGroup; children = ( B2E1B0561CC4A85700FB687F /* AppsManager.swift */, - B2D65A081CDB1BA100E39A65 /* HotKeysRegister.swift */, + E166F33F1CE781EC00F7C7B8 /* ShortcutRegister.swift */, ); name = Helper; sourceTree = ""; @@ -143,7 +141,6 @@ isa = PBXGroup; children = ( B2E1B05C1CC4AE4500FB687F /* DefaultsKeys+Extension.swift */, - B2E1B0601CC4B16200FB687F /* NSView+Extension.swift */, B2F635FB1CD35BDD00E1232D /* String+Extension.swift */, B2D65A061CDAF2D500E39A65 /* NSApplication+Extension.swift */, ); @@ -283,18 +280,17 @@ B2E1B06B1CC4D49800FB687F /* SettingsViewController.swift in Sources */, B2F635FC1CD35BDD00E1232D /* String+Extension.swift in Sources */, B2E1B0531CC4A81D00FB687F /* AppModel.swift in Sources */, + E166F3391CE7801A00F7C7B8 /* ShortcutListViewController.swift in Sources */, B2E1B0691CC4CDD100FB687F /* TOLWindowController.swift in Sources */, + E166F33C1CE780A600F7C7B8 /* EditShortcutWindowController.swift in Sources */, B2E1B05B1CC4AE2600FB687F /* Constant.swift in Sources */, - E166F32F1CE4BBA000F7C7B8 /* HotKeyListViewController.swift in Sources */, B2E1B05D1CC4AE4500FB687F /* DefaultsKeys+Extension.swift in Sources */, B2B04B781CC74DC7005C9BEF /* MainWindowController.swift in Sources */, B2E1B0441CC48CD900FB687F /* AppDelegate.swift in Sources */, - B2E1B0611CC4B16200FB687F /* NSView+Extension.swift in Sources */, - E166F3331CE4BC7F00F7C7B8 /* EditHotKeyViewController.swift in Sources */, + E166F33E1CE780CA00F7C7B8 /* EditShortcutViewController.swift in Sources */, B2E1B0571CC4A85700FB687F /* AppsManager.swift in Sources */, E166F32B1CE4B7E300F7C7B8 /* StatusItemController.swift in Sources */, - E166F3311CE4BC5B00F7C7B8 /* EditHotKeyWindowController.swift in Sources */, - B2D65A091CDB1BA100E39A65 /* HotKeysRegister.swift in Sources */, + E166F3401CE781EC00F7C7B8 /* ShortcutRegister.swift in Sources */, B2D65A071CDAF2D500E39A65 /* NSApplication+Extension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -401,6 +397,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Developer ID Application"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Thor/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; @@ -417,6 +414,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Developer ID Application"; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = Thor/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; diff --git a/Thor/AppDelegate.swift b/Thor/AppDelegate.swift index 5d702c8..c548877 100644 --- a/Thor/AppDelegate.swift +++ b/Thor/AppDelegate.swift @@ -19,11 +19,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { var isTapping = false var hasTapped = false - var isGoingToDisableHotKey = false + var isGoingToDisableShortcut = false var mainWindowController: MainWindowController? - var anewHotKeyTimer: NSTimer? + var anewShortcutTimer: NSTimer? var delayTimer: NSTimer? var statusItem: NSStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(NSVariableStatusItemLength) @@ -39,48 +39,48 @@ class AppDelegate: NSObject, NSApplicationDelegate { NSApp.setActivationPolicy(.Accessory) - hotKeyEnableMonitor() + shortcutEnableMonitor() displayInStatusBar() - HotKeysRegister.registerHotKeys() + ShortcutRegister.register() NSDistributedNotificationCenter.defaultCenter().addObserver(self, selector: #selector(displayInStatusBar), name: "AppleInterfaceThemeChangedNotification", object: nil) } // MARK: Listen events - private func hotKeyEnableMonitor() { + private func shortcutEnableMonitor() { let delayInterval: NSTimeInterval = 0.3 let anewShortcutInterval: NSTimeInterval = Defaults[.DelayInterval] - let hotKeyActivateHandler = { (event: NSEvent) in - let deactivateKey: NSEventModifierFlags = [.CommandKeyMask, .AlternateKeyMask, .ControlKeyMask, .ShiftKeyMask][Defaults[.DeactivateKey]] + let shortcutActivateHandler = { (event: NSEvent) in + let deactivateKey: NSEventModifierFlags = [.AlternateKeyMask, .CommandKeyMask, .ControlKeyMask, .ShiftKeyMask][Defaults[.DeactivateKey]] let modifier = event.modifierFlags.intersect(deactivateKey) if modifier == deactivateKey { - if self.isGoingToDisableHotKey { - self.isGoingToDisableHotKey = false + if self.isGoingToDisableShortcut { + self.isGoingToDisableShortcut = false - HotKeysRegister.unregisterHotKeys() + ShortcutRegister.unregister() - self.anewHotKeyTimer = NSTimer(timeInterval: anewShortcutInterval, target: self, selector: #selector(self.anewHotKeyEnable), userInfo: nil, repeats: false) - NSRunLoop.currentRunLoop().addTimer(self.anewHotKeyTimer!, forMode: NSRunLoopCommonModes) + self.anewShortcutTimer = NSTimer(timeInterval: anewShortcutInterval, target: self, selector: #selector(self.anewShortcutEnable), userInfo: nil, repeats: false) + NSRunLoop.currentRunLoop().addTimer(self.anewShortcutTimer!, forMode: NSRunLoopCommonModes) } else { - self.isGoingToDisableHotKey = true + self.isGoingToDisableShortcut = true - self.delayTimer = NSTimer(timeInterval: delayInterval, target: self, selector: #selector(self.checkHotKeyEnable(_:)), userInfo: nil, repeats: false) + self.delayTimer = NSTimer(timeInterval: delayInterval, target: self, selector: #selector(self.checkShortcutEnable(_:)), userInfo: nil, repeats: false) NSRunLoop.currentRunLoop().addTimer(self.delayTimer!, forMode: NSRunLoopCommonModes) } } } NSEvent.addGlobalMonitorForEventsMatchingMask([.FlagsChangedMask], handler: { (event) in - hotKeyActivateHandler(event) + shortcutActivateHandler(event) }) NSEvent.addLocalMonitorForEventsMatchingMask([.FlagsChangedMask], handler: { (event) -> NSEvent? in - hotKeyActivateHandler(event) + shortcutActivateHandler(event) return event }) } @@ -95,18 +95,18 @@ class AppDelegate: NSObject, NSApplicationDelegate { statusItem.image = image } - @objc private func checkHotKeyEnable(timer: NSTimer) { + @objc private func checkShortcutEnable(timer: NSTimer) { delayTimer?.invalidate() delayTimer = nil - isGoingToDisableHotKey = false + isGoingToDisableShortcut = false } - @objc private func anewHotKeyEnable(timer: NSTimer) { - anewHotKeyTimer?.invalidate() - anewHotKeyTimer = nil + @objc private func anewShortcutEnable(timer: NSTimer) { + anewShortcutTimer?.invalidate() + anewShortcutTimer = nil - HotKeysRegister.registerHotKeys() + ShortcutRegister.register() } } diff --git a/Thor/AppsManager.swift b/Thor/AppsManager.swift index e5e2506..700c1cf 100644 --- a/Thor/AppsManager.swift +++ b/Thor/AppsManager.swift @@ -68,7 +68,7 @@ class AppsManager: NSObject { let apps = selectedApps.map { $0.encode() } if NSKeyedArchiver.archiveRootObject(apps, toFile: selectedAppsFile) { - HotKeysRegister.registerHotKeys() + ShortcutRegister.register() } } diff --git a/Thor/Base.lproj/Main.storyboard b/Thor/Base.lproj/Main.storyboard index ddf0fa9..be5a14b 100644 --- a/Thor/Base.lproj/Main.storyboard +++ b/Thor/Base.lproj/Main.storyboard @@ -76,7 +76,11 @@ - + + + + + @@ -85,20 +89,26 @@ - + - + + + + - + - + + + + @@ -137,7 +147,7 @@ - + @@ -151,10 +161,10 @@ - + - + @@ -207,11 +217,11 @@ - + - + @@ -251,7 +261,7 @@ - + @@ -305,7 +315,7 @@ - + @@ -449,15 +459,15 @@ - + - + @@ -472,8 +482,8 @@ - - + + diff --git a/Thor/Constant.swift b/Thor/Constant.swift index 74c3922..604393c 100644 --- a/Thor/Constant.swift +++ b/Thor/Constant.swift @@ -20,4 +20,4 @@ let titleViewIdentifier = "titleViewIdentifier" let appsTitleItemIdentifier = "appsTitleItemIdentifier" let settingsTitleItemIdentifier = "settingsTitleItemIdentifier" let appTableCellViewIdentifier = "AppTableCellView" -let hotKeyTableCellViewIdentifier = "HotKeyTableCellView" +let shortcutTableCellViewIdentifier = "ShortcutTableCellView" diff --git a/Thor/DefaultsKeys+Extension.swift b/Thor/DefaultsKeys+Extension.swift index 892cc36..f734620 100644 --- a/Thor/DefaultsKeys+Extension.swift +++ b/Thor/DefaultsKeys+Extension.swift @@ -14,7 +14,7 @@ extension DefaultsKeys { static let ModifyKey = DefaultsKey("ModifyKey") static let EnableShortcut = DefaultsKey("EnableShortcut") static let DelayInterval = DefaultsKey("DelayInterval") - static let HotKeys = DefaultsKey<[NSData]?>("HotKeys") + static let Shortcuts = DefaultsKey<[NSData]?>("Shortcuts") static let DeactivateKey = DefaultsKey("DeactivateKey") } diff --git a/Thor/EditHotKeyViewController.swift b/Thor/EditShortcutViewController.swift similarity index 95% rename from Thor/EditHotKeyViewController.swift rename to Thor/EditShortcutViewController.swift index 9d5aedc..756791e 100644 --- a/Thor/EditHotKeyViewController.swift +++ b/Thor/EditShortcutViewController.swift @@ -1,15 +1,15 @@ // -// EditHotKeyViewController.swift +// EditShortcutViewController.swift // Thor // -// Created by Alvin on 5/12/16. +// Created by Alvin on 5/14/16. // Copyright © 2016 AlvinZhu. All rights reserved. // import Cocoa import MASShortcut -class EditHotKeyViewController: NSViewController { +class EditShortcutViewController: NSViewController { @IBOutlet weak var btnApps: NSPopUpButton! @IBOutlet weak var shortcutView: MASShortcutView! @@ -77,11 +77,10 @@ class EditHotKeyViewController: NSViewController { openPanel.beginSheetModalForWindow(view.window!, completionHandler: { (result) in if result == NSModalResponseOK, let metaDataItem = NSMetadataItem(URL: openPanel.URLs.first!) { - self.editedApp = AppModel(item: metaDataItem) - - self.resetSelections(self.apps) } + + self.resetSelections(self.apps) }) } else { let idx = popUpButton.indexOfSelectedItem - (editedApp == nil ? 0 : 2) diff --git a/Thor/EditHotKeyWindowController.swift b/Thor/EditShortcutWindowController.swift similarity index 67% rename from Thor/EditHotKeyWindowController.swift rename to Thor/EditShortcutWindowController.swift index a62b619..e24709a 100644 --- a/Thor/EditHotKeyWindowController.swift +++ b/Thor/EditShortcutWindowController.swift @@ -1,14 +1,14 @@ // -// EditHotKeyWindowController.swift +// EditShortcutWindowController.swift // Thor // -// Created by Alvin on 5/12/16. +// Created by Alvin on 5/14/16. // Copyright © 2016 AlvinZhu. All rights reserved. // import Cocoa -class EditHotKeyWindowController: NSWindowController { +class EditShortcutWindowController: NSWindowController { override func windowDidLoad() { super.windowDidLoad() @@ -16,7 +16,6 @@ class EditHotKeyWindowController: NSWindowController { window?.titlebarAppearsTransparent = true window?.titleVisibility = .Hidden window?.backgroundColor = NSColor.whiteColor() - window?.center() } } diff --git a/Thor/Info.plist b/Thor/Info.plist index 65c79b7..3db6742 100644 --- a/Thor/Info.plist +++ b/Thor/Info.plist @@ -17,20 +17,24 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.0.0 CFBundleSignature ???? CFBundleVersion 1 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) + LSUIElement + NSHumanReadableCopyright Copyright © 2016 AlvinZhu. All rights reserved. NSMainStoryboardFile Main NSPrincipalClass NSApplication - LSUIElement + SUEnableAutomaticChecks + SUFeedURL + https://github.com/insidegui/PodcastMenu/raw/master/Releases/appcast.xml diff --git a/Thor/MainWindowController.swift b/Thor/MainWindowController.swift index 9a6bbab..6a6f4c0 100644 --- a/Thor/MainWindowController.swift +++ b/Thor/MainWindowController.swift @@ -23,8 +23,8 @@ class MainWindowController: TOLWindowController { settingsItem.activeImage = NSImage(named: "Settings-active") settingsItem.inactiveImage = NSImage(named: "Settings") - let hotKeyListViewController = storyboard!.instantiateControllerWithIdentifier(String(HotKeyListViewController)) as! HotKeyListViewController - insert(appItem, viewController: hotKeyListViewController) + let shortcutListViewController = storyboard!.instantiateControllerWithIdentifier(String(ShortcutListViewController)) as! ShortcutListViewController + insert(appItem, viewController: shortcutListViewController) let settingsViewController = storyboard!.instantiateControllerWithIdentifier(String(SettingsViewController)) as! SettingsViewController insert(settingsItem, viewController: settingsViewController) diff --git a/Thor/NSApplication+Extension.swift b/Thor/NSApplication+Extension.swift index af49776..d6d7dc2 100644 --- a/Thor/NSApplication+Extension.swift +++ b/Thor/NSApplication+Extension.swift @@ -8,6 +8,30 @@ import Cocoa +extension NSApplication { + + class func shortVersionString() -> String { + guard let infoDict = NSBundle.mainBundle().infoDictionary else { + return "Unknown" + } + + return infoDict["CFBundleShortVersionString"] as! String + } + + class func buildVersionString() -> String { + guard let infoDict = NSBundle.mainBundle().infoDictionary else { + return "?" + } + + return infoDict["CFBundleVersion"] as! String + } + + class func formattedVersion() -> String { + return "Version \(shortVersionString()) (\(buildVersionString()))" + } + +} + extension NSApplication { // MARK: Variables diff --git a/Thor/NSView+Extension.swift b/Thor/NSView+Extension.swift deleted file mode 100644 index f8382aa..0000000 --- a/Thor/NSView+Extension.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// NSView+Extension.swift -// Thor -// -// Created by AlvinZhu on 4/18/16. -// Copyright © 2016 AlvinZhu. All rights reserved. -// - -import Cocoa - -extension NSView { - - var left: CGFloat { - get { return frame.origin.x } - set { frame.origin.x = newValue } - } - - var top: CGFloat { - get { return frame.origin.y } - set { frame.origin.y = newValue } - } - - var right: CGFloat { - get { return frame.origin.x + frame.size.width } - set { frame.origin.x = newValue - frame.size.width } - } - - var bottom: CGFloat { - get { return frame.origin.y + frame.size.height } - set { frame.origin.y = newValue - frame.size.height } - } - - var width: CGFloat { - get { return frame.size.width } - set { frame.size.width = newValue } - } - - var height: CGFloat { - get { return frame.size.height } - set { frame.size.height = newValue } - } - - var origin: CGPoint { - get { return frame.origin } - set { frame.origin = newValue } - } - - var size: CGSize { - get { return frame.size } - set { frame.size = newValue } - } - - var centerX: CGFloat { - get { return NSMidX(self.frame) } - set { frame.origin.x = newValue - (self.frame.size.width * 0.5) } - } - - var centerY: CGFloat { - get { return NSMidY(self.frame) } - set { frame.origin.y = newValue - (self.frame.size.height * 0.5) } - } - -} diff --git a/Thor/HotKeyListViewController.swift b/Thor/ShortcutListViewController.swift similarity index 66% rename from Thor/HotKeyListViewController.swift rename to Thor/ShortcutListViewController.swift index b3e66bc..1689b28 100644 --- a/Thor/HotKeyListViewController.swift +++ b/Thor/ShortcutListViewController.swift @@ -1,20 +1,20 @@ // -// HotKeyListViewController.swift +// ShortcutListViewController.swift // Thor // -// Created by Alvin on 5/12/16. +// Created by Alvin on 5/14/16. // Copyright © 2016 AlvinZhu. All rights reserved. // import Cocoa -class HotKeyListViewController: NSViewController { - +class ShortcutListViewController: NSViewController { + @IBOutlet weak var tableView: NSTableView! @IBOutlet weak var btnAdd: NSButton! @IBOutlet weak var btnRemove: NSButton! - lazy var editHotKeyWindowController: EditHotKeyWindowController = SharedAppDelegate?.mainWindowController?.storyboard?.instantiateControllerWithIdentifier(String(EditHotKeyWindowController)) as! EditHotKeyWindowController + lazy var editShortcutWindowController = SharedAppDelegate?.mainWindowController?.storyboard?.instantiateControllerWithIdentifier(String(EditShortcutWindowController)) as! EditShortcutWindowController var apps: [AppModel] { get { return AppsManager.manager.selectedApps } } @@ -23,7 +23,7 @@ class HotKeyListViewController: NSViewController { view.layer?.backgroundColor = NSColor.whiteColor().CGColor - tableView.doubleAction = #selector(editHotKey) + tableView.doubleAction = #selector(editShortcut) } override func viewWillAppear() { @@ -39,14 +39,14 @@ class HotKeyListViewController: NSViewController { } @IBAction func add(sender: AnyObject) { - NSApplication.sharedApplication().runModalForWindow(editHotKeyWindowController.window!) + NSApplication.sharedApplication().runModalForWindow(editShortcutWindowController.window!) } @IBAction func remove(sender: AnyObject) { let alert = NSAlert() alert.addButtonWithTitle("Sure".localized()) alert.addButtonWithTitle("Cancel".localized()) - alert.messageText = "Delete this hotkey?".localized() + alert.messageText = "Delete this shortcut?".localized() alert.alertStyle = .WarningAlertStyle if alert.runModal() == NSAlertFirstButtonReturn { @@ -56,23 +56,17 @@ class HotKeyListViewController: NSViewController { } } - @objc private func editHotKey() { - let editHotKeyViewController = editHotKeyWindowController.contentViewController as! EditHotKeyViewController + @objc private func editShortcut() { + let editShortcutViewController = editShortcutWindowController.contentViewController as! EditShortcutViewController let app = AppsManager.manager.selectedApps[tableView.selectedRow] - editHotKeyViewController.editedApp = app - -// NSApp.runModalForWindow(editHotKeyWindowController.window!) + editShortcutViewController.editedApp = app - view.window!.beginSheet(editHotKeyWindowController.window!) { (response) in - - } - -// NSApp.beginSheet(editHotKeyWindowController.window!, modalForWindow: view.window!, modalDelegate: nil, didEndSelector: nil, contextInfo: nil) + NSApp.runModalForWindow(editShortcutWindowController.window!) } } -extension HotKeyListViewController: NSTableViewDataSource, NSTableViewDelegate { +extension ShortcutListViewController: NSTableViewDataSource, NSTableViewDelegate { func numberOfRowsInTableView(tableView: NSTableView) -> Int { return apps.count @@ -91,7 +85,7 @@ extension HotKeyListViewController: NSTableViewDataSource, NSTableViewDelegate { return cell } else { - let cell = tableView.makeViewWithIdentifier(hotKeyTableCellViewIdentifier, owner: self) as! NSTableCellView + let cell = tableView.makeViewWithIdentifier(shortcutTableCellViewIdentifier, owner: self) as! NSTableCellView cell.textField?.stringValue = "\(app.shortcut!)" return cell diff --git a/Thor/HotKeysRegister.swift b/Thor/ShortcutRegister.swift similarity index 87% rename from Thor/HotKeysRegister.swift rename to Thor/ShortcutRegister.swift index 57af788..009fff0 100644 --- a/Thor/HotKeysRegister.swift +++ b/Thor/ShortcutRegister.swift @@ -1,8 +1,8 @@ // -// HotKeysRegister.swift +// ShortcutRegister.swift // Thor // -// Created by AlvinZhu on 5/5/16. +// Created by Alvin on 5/14/16. // Copyright © 2016 AlvinZhu. All rights reserved. // @@ -10,10 +10,10 @@ import Foundation import Carbon import SwiftyUserDefaults -struct HotKeysRegister { +struct ShortcutRegister { - static func registerHotKeys() { - unregisterHotKeys() + static func register() { + unregister() var hotKeyRefs = [NSData]() let apps = AppsManager.manager.selectedApps @@ -21,7 +21,7 @@ struct HotKeysRegister { let signature = OSType((app.appName as NSString).UTF8String.memory) let id = UInt32(i) let hotKeyID = EventHotKeyID(signature: signature, id: id) - + var hotKeyRef: EventHotKeyRef = nil RegisterEventHotKey(app.shortcut!.carbonKeyCode, app.shortcut!.carbonFlags, hotKeyID, GetApplicationEventTarget(), 0, &hotKeyRef) if hotKeyRef != nil { @@ -30,13 +30,13 @@ struct HotKeysRegister { } } - Defaults[.HotKeys] = hotKeyRefs + Defaults[.Shortcuts] = hotKeyRefs var eventType = EventTypeSpec(eventClass: OSType(kEventClassKeyboard), eventKind: UInt32(kEventHotKeyPressed)) InstallEventHandler(GetApplicationEventTarget(), { (nextHandler, event, userData) -> OSStatus in guard Defaults[.EnableShortcut] else { return noErr } - + let apps = AppsManager.manager.selectedApps guard apps.count > 0 else { return noErr } @@ -49,8 +49,8 @@ struct HotKeysRegister { }, 1, &eventType, nil, nil) } - static func unregisterHotKeys() { - if let hotKeyRefs = Defaults[.HotKeys] { + static func unregister() { + if let hotKeyRefs = Defaults[.Shortcuts] { hotKeyRefs.forEach { var hotKeyRef: EventHotKeyRef = nil $0.getBytes(&hotKeyRef, length: sizeof(EventHotKeyRef)) diff --git a/Thor/StatusItemController.swift b/Thor/StatusItemController.swift index 27922f5..e108661 100644 --- a/Thor/StatusItemController.swift +++ b/Thor/StatusItemController.swift @@ -7,9 +7,12 @@ // import Cocoa +import Sparkle -class StatusItemController: NSObject { +class StatusItemController: NSObject, NSMenuDelegate { + @IBOutlet weak var versionMenuItem: NSMenuItem! + @IBAction func showApps(sender: AnyObject) { if let rootViewController = SharedAppDelegate?.mainWindowController { rootViewController.showWindow(nil) @@ -20,11 +23,16 @@ class StatusItemController: NSObject { } } - @IBAction func about(sender: AnyObject) { + @IBAction func quit(sender: AnyObject) { + NSApp.terminate(self) } - @IBAction func exit(sender: AnyObject) { - NSApp.terminate(self) + @IBAction func checkForUpdates(sender: AnyObject) { + SUUpdater.sharedUpdater().checkForUpdates(sender) + } + + func menuWillOpen(menu: NSMenu) { + versionMenuItem.title = NSApplication.formattedVersion() } } diff --git a/Thor/TOLWindowController.swift b/Thor/TOLWindowController.swift index 1f2a082..fffce39 100644 --- a/Thor/TOLWindowController.swift +++ b/Thor/TOLWindowController.swift @@ -114,7 +114,7 @@ class TitleView: NSView { items.forEach { $0.removeFromSuperview() } for (index, item) in items.enumerate() { - item.frame = NSRect(x: CGFloat(index) * titleItemWidth, y: 0, width: titleItemWidth, height: self.height) + item.frame = NSRect(x: CGFloat(index) * titleItemWidth, y: 0, width: titleItemWidth, height: self.frame.size.height) item.target = self item.action = #selector(TitleView.toggle(_:))