Skip to content

Commit

Permalink
Some things were done.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyroh committed Sep 2, 2016
1 parent 6d8bc12 commit 5aec48b
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 736 deletions.
16 changes: 16 additions & 0 deletions Fluor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@
objects = {

/* Begin PBXBuildFile section */
3F2FA3FF1D79D094003E2AD8 /* StatusMenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F2FA3FE1D79D094003E2AD8 /* StatusMenuController.swift */; };
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 */; };
3FCD16A51D79793600C57B22 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FCD16A41D79793600C57B22 /* AppDelegate.swift */; };
3FCD16A71D79793600C57B22 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3FCD16A61D79793600C57B22 /* Assets.xcassets */; };
3FCD16AA1D79793600C57B22 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3FCD16A81D79793600C57B22 /* MainMenu.xib */; };
3FCD16B41D79797600C57B22 /* utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FCD16B31D79797600C57B22 /* utils.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3F2FA3FE1D79D094003E2AD8 /* StatusMenuController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusMenuController.swift; sourceTree = "<group>"; };
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>"; };
3FCD16A11D79793600C57B22 /* Fluor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Fluor.app; sourceTree = BUILT_PRODUCTS_DIR; };
3FCD16A41D79793600C57B22 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3FCD16A61D79793600C57B22 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -57,6 +65,10 @@
3FCD16A41D79793600C57B22 /* AppDelegate.swift */,
3FCD16A61D79793600C57B22 /* Assets.xcassets */,
3FCD16A81D79793600C57B22 /* MainMenu.xib */,
3F2FA4021D7A059F003E2AD8 /* CurrentAppView.swift */,
3F2FA4001D79D66D003E2AD8 /* StateView.swift */,
3F2FA3FE1D79D094003E2AD8 /* StatusMenuController.swift */,
3F2FA4041D7A1F87003E2AD8 /* BehaviorManager.swift */,
3FCD16AB1D79793600C57B22 /* Info.plist */,
3FCD16B21D79797600C57B22 /* utils.h */,
3FCD16B31D79797600C57B22 /* utils.m */,
Expand Down Expand Up @@ -143,8 +155,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3F2FA4031D7A059F003E2AD8 /* CurrentAppView.swift in Sources */,
3F2FA3FF1D79D094003E2AD8 /* StatusMenuController.swift in Sources */,
3FCD16A51D79793600C57B22 /* AppDelegate.swift in Sources */,
3F2FA4011D79D66D003E2AD8 /* StateView.swift in Sources */,
3FCD16B41D79797600C57B22 /* utils.m in Sources */,
3F2FA4051D7A1F87003E2AD8 /* BehaviorManager.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
53 changes: 1 addition & 52 deletions Fluor/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,12 @@ import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
dynamic var state: Bool = false {
didSet {
switchState()
changeTitleAccordingToState()
}
}
dynamic var appID: String?

@IBOutlet weak var window: NSWindow!
@IBOutlet weak var button: NSButton!

func applicationDidFinishLaunching(_ aNotification: Notification) {
// window.styleMask = NSFullSizeContentViewWindowMask.union(NSTexturedBackgroundWindowMask).union(NSResizableWindowMask)
window.level = Int(CGWindowLevelForKey(.maximumWindow))

state = getStateAccordingToPreferences()
button.state = state ? NSOnState : NSOffState
changeTitleAccordingToState()
NSWorkspace.shared().notificationCenter.addObserver(self, selector: #selector(activeAppDidChange(notification:)), name: NSNotification.Name.NSWorkspaceDidActivateApplication, object: nil)
}

func applicationWillTerminate(_ aNotification: Notification) {
NSWorkspace.shared().notificationCenter.removeObserver(self)
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

@objc private func activeAppDidChange(notification: NSNotification) {
guard let app = notification.userInfo?[NSWorkspaceApplicationKey] as? NSRunningApplication,
let id = app.bundleIdentifier else { return }
appID = id
}

private func switchState() {
if state {
setFnKeysToOtherMode()
} else {
setFnKeysToAppleMode()
}
}

private func getStateAccordingToPreferences() -> Bool {
switch getCurrentFnKeyState() {
case AppleMode:
return false
case OtherMode:
return true
default:
assertionFailure()
return false
}
}

private func changeTitleAccordingToState() {
button.title = state ? "Switch to Apple mode" : "Switch to Other mode"

}
}

Loading

0 comments on commit 5aec48b

Please sign in to comment.