Permalink
Browse files

Code refactoring

  • Loading branch information...
1 parent 24b0d55 commit 9cbc8a32e55e9d4d7b4b7072d50b0dc1bb0b9b43 @Pyroh committed Jan 8, 2017
@@ -11,7 +11,6 @@
3F2FA4011D79D66D003E2AD8 /* StateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F2FA4001D79D66D003E2AD8 /* StateView.swift */; };
3F2FA4031D7A059F003E2AD8 /* CurrentAppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F2FA4021D7A059F003E2AD8 /* CurrentAppView.swift */; };
3F2FA4051D7A1F87003E2AD8 /* BehaviorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F2FA4041D7A1F87003E2AD8 /* BehaviorManager.swift */; };
- 3F6FA1A71D7E027F00DB9289 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6FA1A51D7E027F00DB9289 /* PreferencesWindowController.swift */; };
3F6FA1A81D7E027F00DB9289 /* PreferencesWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3F6FA1A61D7E027F00DB9289 /* PreferencesWindowController.xib */; };
3FC44EFA1D7F169A0065D433 /* Enums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FC44EF91D7F169A0065D433 /* Enums.swift */; };
3FC44EFC1D7F16CB0065D433 /* RulesItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FC44EFB1D7F16CB0065D433 /* RulesItem.swift */; };
@@ -35,7 +34,6 @@
3F2FA4001D79D66D003E2AD8 /* StateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StateView.swift; sourceTree = "<group>"; };
3F2FA4021D7A059F003E2AD8 /* CurrentAppView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrentAppView.swift; sourceTree = "<group>"; };
3F2FA4041D7A1F87003E2AD8 /* BehaviorManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BehaviorManager.swift; sourceTree = "<group>"; };
- 3F6FA1A51D7E027F00DB9289 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
3F6FA1A61D7E027F00DB9289 /* PreferencesWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = PreferencesWindowController.xib; path = Base.lproj/PreferencesWindowController.xib; sourceTree = "<group>"; };
3FC44EF91D7F169A0065D433 /* Enums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enums.swift; sourceTree = "<group>"; };
3FC44EFB1D7F16CB0065D433 /* RulesItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RulesItem.swift; sourceTree = "<group>"; };
@@ -118,7 +116,6 @@
3FE7E0DE1D7CA14600DC754D /* LaunchAtLoginController.h */,
3FE7E0DF1D7CA14600DC754D /* LaunchAtLoginController.m */,
3F2FA3FE1D79D094003E2AD8 /* StatusMenuController.swift */,
- 3F6FA1A51D7E027F00DB9289 /* PreferencesWindowController.swift */,
3FE7E0E11D7CBE1700DC754D /* AboutWindowController.swift */,
3FE7E0E81D7CC01B00DC754D /* RulesEditorWindowController.swift */,
3FC44EFD1D7F464C0065D433 /* RunningAppsWindowController.swift */,
@@ -248,7 +245,6 @@
3F2FA4031D7A059F003E2AD8 /* CurrentAppView.swift in Sources */,
3FC44EFC1D7F16CB0065D433 /* RulesItem.swift in Sources */,
3F2FA3FF1D79D094003E2AD8 /* StatusMenuController.swift in Sources */,
- 3F6FA1A71D7E027F00DB9289 /* PreferencesWindowController.swift in Sources */,
3FCD16A51D79793600C57B22 /* AppDelegate.swift in Sources */,
3F2FA4011D79D66D003E2AD8 /* StateView.swift in Sources */,
3FCD16B41D79797600C57B22 /* utils.m in Sources */,
@@ -17,11 +17,15 @@ class AboutWindowController: NSWindowController {
window?.styleMask.formUnion(.fullSizeContentView)
window?.titleVisibility = .hidden
window?.titlebarAppearsTransparent = true
- window?.setFrameAutosaveName("Fluor_AboutWindowAutosaveName")
+ let bundleVersion = getBundleVersion()
+ versionLabel.stringValue = "Version \(bundleVersion.version) build \(bundleVersion.build)"
+ }
+
+ private func getBundleVersion() -> (version: String, build: String) {
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
let build = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as! String
- versionLabel.stringValue = "Version \(version) build \(build)"
+
+ return (version, build)
}
-
}
@@ -10,12 +10,6 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
- func applicationDidFinishLaunching(_ aNotification: Notification) {
-
- }
-
- func applicationWillTerminate(_ aNotification: Notification) {
-
- }
+ // We have no business here...
}
@@ -16,7 +16,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
- <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
+ <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" frameAutosaveName="Fluor_AboutWindowAutosaveName" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<rect key="contentRect" x="196" y="240" width="513" height="236"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="878"/>
@@ -6,14 +6,14 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
- <customObject id="-2" userLabel="File's Owner" customClass="PreferencesWindowController" customModule="Fluor" customModuleProvider="target">
+ <customObject id="-2" userLabel="File's Owner" customClass="NSWindowController">
<connections>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
- <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
+ <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" frameAutosaveName="Fluor_PreferencesWindowAutosaveName" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<rect key="contentRect" x="196" y="240" width="261" height="135"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="878"/>
@@ -118,7 +118,7 @@
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
- <point key="canvasLocation" x="29.5" y="94.5"/>
+ <point key="canvasLocation" x="131" y="141"/>
</window>
<customObject id="LKl-gm-Txd" customClass="LaunchAtLoginController"/>
<userDefaultsController representsSharedInstance="YES" id="wfg-0V-Kft"/>
@@ -17,7 +17,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
- <window title="Rules" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
+ <window title="Rules" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" frameAutosaveName="Fluor_EditRulesWindowAutosaveName" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" resizable="YES" texturedBackground="YES"/>
<rect key="contentRect" x="196" y="240" width="300" height="417"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="878"/>
@@ -135,7 +135,7 @@
</clipView>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="BaA-mh-PXc"/>
- <constraint firstAttribute="width" relation="lessThanOrEqual" constant="450" id="tit-Za-anh"/>
+ <constraint firstAttribute="width" relation="lessThanOrEqual" constant="600" id="tit-Za-anh"/>
</constraints>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="o5l-46-DPF">
<rect key="frame" x="1" y="119" width="223" height="15"/>
@@ -16,7 +16,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
- <window title="Running Applications" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
+ <window title="Running Applications" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" frameAutosaveName="Fluor_RunningAppsWindowAutosaveName" animationBehavior="default" id="F0z-JX-Cv5" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" resizable="YES" texturedBackground="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="1003" y="371" width="350" height="417"/>
@@ -137,7 +137,7 @@
</clipView>
<constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="600" id="8Kq-U3-wXm"/>
- <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="350" id="Ukl-zI-Ve2"/>
+ <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="Ukl-zI-Ve2"/>
</constraints>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="3R3-KB-bdb">
<rect key="frame" x="0.0" y="362" width="319" height="16"/>
View
@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
<key>CFBundleVersion</key>
- <string>53</string>
+ <string>59</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
@@ -1,16 +0,0 @@
-//
-// PreferencesWindowController.swift
-// Fluor
-//
-// Created by Pierre TACCHI on 05/09/16.
-// Copyright © 2016 Pyrolyse. All rights reserved.
-//
-
-import Cocoa
-
-class PreferencesWindowController: NSWindowController {
- override func windowDidLoad() {
- super.windowDidLoad()
- window?.setFrameAutosaveName("Fluor_PreferencesWindowAutosaveName")
- }
-}
@@ -18,7 +18,6 @@ class RulesEditorWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
window?.styleMask.formUnion(.nonactivatingPanel)
- window?.setFrameAutosaveName("Fluor_EditRulesWindowAutosaveName")
NotificationCenter.default.addObserver(self, selector: #selector(ruleDidChangeForApp(notification:)), name: Notification.Name.RuleDidChangeForApp, object: nil)
@@ -32,7 +31,6 @@ class RulesEditorWindowController: NSWindowController {
NotificationCenter.default.removeObserver(self)
}
-
/// Called when a rule change for an application.
///
/// - parameter notification: The notification.
@@ -53,7 +51,6 @@ class RulesEditorWindowController: NSWindowController {
}
}
-
/// Add a rule for a given application.
///
/// - parameter sender: The object that sent the action.
@@ -76,7 +73,6 @@ class RulesEditorWindowController: NSWindowController {
}
}
-
/// Remove a rule for a given application.
///
/// - parameter sender: The object that sent the action.
@@ -18,7 +18,6 @@ class RunningAppsWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
window?.styleMask.formUnion(.nonactivatingPanel)
- window?.setFrameAutosaveName("Fluor_RunningAppsWindowAutosaveName")
let sortDescriptor = NSSortDescriptor(key: "name", ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:)))
runningAppsArrayController.sortDescriptors = [sortDescriptor]
loadData()
@@ -29,7 +28,6 @@ class RunningAppsWindowController: NSWindowController {
NSWorkspace.shared().notificationCenter.removeObserver(self)
}
-
/// Update the behavior of a given application. It changes the segmented control's selected item of the right table view's row.
///
/// - parameter id: The application bundle id.
@@ -56,7 +54,6 @@ class RunningAppsWindowController: NSWindowController {
runningAppsArray.append(item)
}
-
/// Called whenever an application is terminated by the system or the user.
///
/// - parameter notification: The notification.
@@ -67,14 +64,12 @@ class RunningAppsWindowController: NSWindowController {
runningAppsArray.remove(at: index)
}
-
/// Set `self` as an observer for *launch* and *terminate* notfications.
private func applyAsObserver() {
NSWorkspace.shared().notificationCenter.addObserver(self, selector: #selector(appDidLaunch(notification:)), name: NSNotification.Name.NSWorkspaceDidLaunchApplication, object: nil)
NSWorkspace.shared().notificationCenter.addObserver(self, selector: #selector(appDidTerminate(notification:)), name: NSNotification.Name.NSWorkspaceDidTerminateApplication, object: nil)
}
-
/// Load all running applications and populate the table view with corresponding datas.
private func loadData() {
runningAppsArray = NSWorkspace.shared().runningApplications.flatMap { (app) -> RunningAppItem? in
@@ -15,7 +15,7 @@ class StatusMenuController: NSObject {
private var rulesController: RulesEditorWindowController?
private var aboutController: AboutWindowController?
- private var preferencesController: PreferencesWindowController?
+ private var preferencesController: NSWindowController?
private var runningAppsController: RunningAppsWindowController?
private var currentState: KeyboardState = .error
@@ -38,7 +38,6 @@ class StatusMenuController: NSObject {
// MARK: Operations callbacks
-
/// React to active application change.
///
/// - parameter notification: The notification.
@@ -50,7 +49,6 @@ class StatusMenuController: NSObject {
adaptBehaviorForApp(id: id)
}
-
/// React to the change of default function keys behavior in the dedicated view.
///
/// - parameter notification: The notification.
@@ -60,7 +58,6 @@ class StatusMenuController: NSObject {
adaptBehaviorForApp(id: currentID)
}
-
/// React to the change of the function keys behavior for one app.
///
/// - parameter notification: The notification.
@@ -91,7 +88,6 @@ class StatusMenuController: NSObject {
}
}
-
/// When a window was closed this methods takes care of releasing its controller.
///
/// - parameter notification: The notification.
@@ -125,22 +121,19 @@ class StatusMenuController: NSObject {
}
}
-
/// Register self as an observer for some notifications.
private func applyAsObserver() {
NotificationCenter.default.addObserver(self, selector: #selector(stateViewDidChangeState(notification:)), name: Notification.Name.StateViewDidChangeState, object: stateView)
NotificationCenter.default.addObserver(self, selector: #selector(behaviorDidChangeForApp(notification:)), name: Notification.Name.BehaviorDidChangeForApp, object: nil)
NSWorkspace.shared().notificationCenter.addObserver(self, selector: #selector(activeAppDidChange(notification:)), name: NSNotification.Name.NSWorkspaceDidActivateApplication, object: nil)
}
-
/// Unregister self as an observer for some notifications.
private func resignAsObserver() {
NotificationCenter.default.removeObserver(self)
NSWorkspace.shared().notificationCenter.removeObserver(self)
}
-
/// Set function key behavior in the current running app view.
///
/// - parameter app: The running app.
@@ -150,7 +143,6 @@ class StatusMenuController: NSObject {
currentAppView.setCurrent(app: app, behavior: BehaviorManager.default.behaviorForApp(id: id))
}
-
/// Set the behavior for an application.
///
/// - parameter id: The application's bundle id.
@@ -160,7 +152,6 @@ class StatusMenuController: NSObject {
BehaviorManager.default.setBehaviorForApp(id: id, behavior: behavior, url: url)
}
-
/// Set the function keys' behavior for the given app.
///
/// - parameter id: The app's bundle id.
@@ -195,7 +186,6 @@ class StatusMenuController: NSObject {
return ["id": id, "url": url, "behavior": behavior]
}
-
/// Try to unpack Notification's userInfo with app's information.
///
/// - parameter dict: The userInfo dictionnary provided by a Notification object.
@@ -223,7 +213,6 @@ class StatusMenuController: NSObject {
rulesController?.window?.orderFrontRegardless()
}
-
/// Show the *About* window.
///
/// - parameter sender: The object that sent the action.
@@ -245,7 +234,7 @@ class StatusMenuController: NSObject {
preferencesController?.window?.orderFrontRegardless()
return
}
- preferencesController = PreferencesWindowController(windowNibName: "PreferencesWindowController")
+ preferencesController = NSWindowController(windowNibName: "PreferencesWindowController")
NotificationCenter.default.addObserver(self, selector: #selector(someWindowWillClose(notification:)), name: Notification.Name.NSWindowWillClose, object: preferencesController?.window)
preferencesController?.window?.orderFrontRegardless()
}

0 comments on commit 9cbc8a3

Please sign in to comment.