forked from jordanbaird/Ice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
92 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// StatusItemDefaults.swift | ||
// Ice | ||
// | ||
|
||
import Foundation | ||
|
||
/// Proxy getters and setters for a status item's user default values. | ||
enum StatusItemDefaults { | ||
private static func stringKey<Value>(forKey key: StatusItemDefaultsKey<Value>, autosaveName: String) -> String { | ||
return "NSStatusItem \(key.rawValue) \(autosaveName)" | ||
} | ||
|
||
/// Accesses the value associated with the specified key and autosave name. | ||
static subscript<Value>(key: StatusItemDefaultsKey<Value>, autosaveName: String) -> Value? { | ||
get { | ||
let key = stringKey(forKey: key, autosaveName: autosaveName) | ||
return UserDefaults.standard.object(forKey: key) as? Value | ||
} | ||
set { | ||
let key = stringKey(forKey: key, autosaveName: autosaveName) | ||
UserDefaults.standard.set(newValue, forKey: key) | ||
} | ||
} | ||
|
||
/// Migrates the given status item defaults key from an old autosave name to a new autosave name. | ||
static func migrate<Value>(key: StatusItemDefaultsKey<Value>, from oldAutosaveName: String, to newAutosaveName: String) { | ||
guard newAutosaveName != oldAutosaveName else { | ||
return | ||
} | ||
Self[key, newAutosaveName] = Self[key, oldAutosaveName] | ||
Self[key, oldAutosaveName] = nil | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Ice/Utilities/StatusItemDefaults/StatusItemDefaultsKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// StatusItemDefaultsKey.swift | ||
// Ice | ||
// | ||
|
||
import CoreGraphics | ||
|
||
/// Keys used to look up user defaults for status items. | ||
struct StatusItemDefaultsKey<Value> { | ||
let rawValue: String | ||
} | ||
|
||
extension StatusItemDefaultsKey<CGFloat> { | ||
static let preferredPosition = StatusItemDefaultsKey(rawValue: "Preferred Position") | ||
} | ||
|
||
extension StatusItemDefaultsKey<Bool> { | ||
static let isVisible = StatusItemDefaultsKey(rawValue: "Visible") | ||
} |