-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
1 parent
588031d
commit ebd7b9b
Showing
14 changed files
with
72 additions
and
154 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// StatusItemDefaults.swift | ||
// Ice | ||
// | ||
|
||
import Cocoa | ||
|
||
// MARK: - StatusItemDefaults | ||
|
||
/// Proxy getters and setters for a status item's user defaults values. | ||
enum StatusItemDefaults { | ||
/// Accesses the value associated with the specified key and autosave name. | ||
static subscript<Value>(key: Key<Value>, autosaveName: String) -> Value? { | ||
get { | ||
let stringKey = key.stringKey(for: autosaveName) | ||
return UserDefaults.standard.object(forKey: stringKey) as? Value | ||
} | ||
set { | ||
let stringKey = key.stringKey(for: autosaveName) | ||
return UserDefaults.standard.set(newValue, forKey: stringKey) | ||
} | ||
} | ||
|
||
/// Migrates the given status item defaults key from an old autosave name | ||
/// to a new autosave name. | ||
static func migrate<Value>(key: Key<Value>, from oldAutosaveName: String, to newAutosaveName: String) { | ||
guard newAutosaveName != oldAutosaveName else { | ||
return | ||
} | ||
Self[key, newAutosaveName] = Self[key, oldAutosaveName] | ||
Self[key, oldAutosaveName] = nil | ||
} | ||
} | ||
|
||
// MARK: - StatusItemDefaults.Key | ||
|
||
extension StatusItemDefaults { | ||
/// Keys used to look up user defaults values for status items. | ||
struct Key<Value> { | ||
/// The raw value of the key. | ||
let rawValue: String | ||
|
||
/// Returns the full string key for the given autosave name. | ||
func stringKey(for autosaveName: String) -> String { | ||
return "NSStatusItem \(rawValue) \(autosaveName)" | ||
} | ||
} | ||
} | ||
|
||
extension StatusItemDefaults.Key<CGFloat> { | ||
/// String key: "NSStatusItem Preferred Position autosaveName" | ||
static let preferredPosition = Self(rawValue: "Preferred Position") | ||
} | ||
|
||
extension StatusItemDefaults.Key<Bool> { | ||
/// String key: "NSStatusItem Visible autosaveName" | ||
static let visible = Self(rawValue: "Visible") | ||
} |
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
Ice/Utilities/StatusItemDefaults/StatusItemDefaultsKey.swift
This file was deleted.
Oops, something went wrong.