Skip to content

Commit

Permalink
RuleItem refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyroh committed Sep 13, 2016
1 parent 4bfbac5 commit 14610ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 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>20</string>
<string>21</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down
10 changes: 5 additions & 5 deletions Fluor/RulesEditorWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ class RulesEditorWindowController: NSWindowController {

@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)
rulesArray[index] = RuleItem(fromItem: rulesArray[index], withBehavior: appBehavior.rawValue - 1)
}
} else {
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)
rulesArray.append(item)
}
}
Expand Down
4 changes: 4 additions & 0 deletions Fluor/RulesItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class RuleItem: NSObject {
self.behavior = behavior
}

convenience init(fromItem item: RuleItem, withBehavior behavior: Int) {
self.init(id: item.id, url: item.url, icon: item.icon, name: item.name, behavior: behavior)
}

fileprivate func postChangeNotification() {
let info = StatusMenuController.behaviorDidChangeUserInfoConstructor(id: id, url: url, behavior: AppBehavior(rawValue: behavior + 1)!)
let not = Notification(name: Notification.Name.BehaviorDidChangeForApp, object: self, userInfo: info)
Expand Down

0 comments on commit 14610ca

Please sign in to comment.