Skip to content

Commit

Permalink
Release candidate 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyroh committed Sep 12, 2016
1 parent 8ca98f6 commit 4bfbac5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Fluor/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0 beta</string>
<key>CFBundleVersion</key>
<string>16</string>
<string>20</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down
1 change: 0 additions & 1 deletion Fluor/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Cocoa

class PreferencesWindowController: NSWindowController {

override func windowDidLoad() {
super.windowDidLoad()
window?.setFrameAutosaveName("PreferencesWindowAutosaveName")
Expand Down
27 changes: 24 additions & 3 deletions Fluor/RulesEditorWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,39 @@ class RulesEditorWindowController: NSWindowController {
@IBOutlet var rulesArrayController: NSArrayController!

dynamic var rulesArray = [RuleItem]()

override func windowDidLoad() {
super.windowDidLoad()
window?.styleMask.formUnion(.nonactivatingPanel)
window?.setFrameAutosaveName("EditRulesWindowAutosaveName")

NotificationCenter.default.addObserver(self, selector: #selector(ruleDidChangeForApp(notification:)), name: Notification.Name.RuleDidChangeForApp, object: nil)

let sortDescriptor = NSSortDescriptor(key: "name", ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:)))
rulesArrayController.sortDescriptors = [sortDescriptor]

rulesArray = BehaviorManager.default.retrieveRules()
}

func loadRules() {
rulesArray = BehaviorManager.default.retrieveRules()
deinit {
NotificationCenter.default.removeObserver(self)
}

@objc private func ruleDidChangeForApp(notification: Notification) {
guard let userInfo = notification.userInfo as? [String: Any], let appId = userInfo["id"] as? String, let appBehavior = userInfo["behavior"] as? AppBehavior, let appURL = userInfo["url"] as? URL else { return }
let appPath = appURL.path
let appIcon = NSWorkspace.shared().icon(forFile: appPath)
let appName = Bundle(path: appPath)?.localizedInfoDictionary?["CFBundleName"] as? String ?? appURL.deletingPathExtension().lastPathComponent
let item = RuleItem(id: appId, url: appURL, icon: appIcon, name: appName, behavior: appBehavior.rawValue - 1)
if let index = rulesArray.index(where: { $0.id == appId }) {
if case .infered = appBehavior {
rulesArray.remove(at: index)
} else {
rulesArray[index] = RuleItem(id: appId, url: appURL, icon: appIcon, name: appName, behavior: appBehavior.rawValue - 1)
}
} else {
rulesArray.append(item)
}
}

@IBAction func addRule(_ sender: AnyObject) {
Expand Down
8 changes: 5 additions & 3 deletions Fluor/StatusMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cocoa
extension Notification.Name {
public static let StateViewDidChangeState = Notification.Name("kStateViewDidChangeState")
public static let BehaviorDidChangeForApp = Notification.Name("kBehaviorDidChangeForApp")
public static let RuleDidChangeForApp = Notification.Name("RuleDidChangeForApp")
}

class StatusMenuController: NSObject {
Expand Down Expand Up @@ -82,11 +83,13 @@ class StatusMenuController: NSObject {
setBehaviorForApp(id: info.id, behavior: info.behavior, url: info.url)
switch notification.object! {
case is CurrentAppView:
rulesController?.loadRules()
let notification = Notification(name: Notification.Name.RuleDidChangeForApp, object: nil, userInfo: userInfo)
NotificationCenter.default.post(notification)
runningAppsController?.updateBehaviorForApp(id: info.id, behavior: info.behavior)
adaptBehaviorForApp(id: info.id)
case is RunningAppItem:
rulesController?.loadRules()
let notification = Notification(name: Notification.Name.RuleDidChangeForApp, object: nil, userInfo: userInfo)
NotificationCenter.default.post(notification)
updateIfCurrent(id: info.id, behavior: info.behavior)
default:
runningAppsController?.updateBehaviorForApp(id: info.id, behavior: info.behavior)
Expand Down Expand Up @@ -209,7 +212,6 @@ class StatusMenuController: NSObject {
return
}
rulesController = RulesEditorWindowController(windowNibName: "RulesEditorWindowController")
rulesController?.loadRules()
NotificationCenter.default.addObserver(self, selector: #selector(someWindowWillClose(notification:)), name: Notification.Name.NSWindowWillClose, object: rulesController?.window)
rulesController?.window?.orderFrontRegardless()
}
Expand Down

0 comments on commit 4bfbac5

Please sign in to comment.