mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 19:27:30 +03:00
Improve manaer initializers
This commit is contained in:
parent
37743ffb54
commit
ce85564792
@ -55,7 +55,7 @@ final class CommandLineToolManager: Sendable {
|
||||
|
||||
// MARK: Public Methods
|
||||
|
||||
init(bundle: Bundle) {
|
||||
private init(bundle: Bundle) {
|
||||
|
||||
self.bundledCommandURL = bundle.cotURL!
|
||||
self.preferredLinkURL = URL(filePath: "/usr/local/bin/cot")
|
||||
|
@ -49,7 +49,7 @@ import FileEncoding
|
||||
|
||||
// MARK: Lifecycle
|
||||
|
||||
init(defaults: UserDefaults) {
|
||||
private init(defaults: UserDefaults) {
|
||||
|
||||
self.defaults = defaults
|
||||
|
||||
|
@ -44,7 +44,7 @@ import Syntax
|
||||
|
||||
// MARK: Lifecycle
|
||||
|
||||
init(defaults: UserDefaults) {
|
||||
private init(defaults: UserDefaults) {
|
||||
|
||||
self.defaults = defaults
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ import Shortcut
|
||||
|
||||
// MARK: Public Properties
|
||||
|
||||
static let shared = SnippetManager()
|
||||
static let shared = SnippetManager(defaults: .standard)
|
||||
|
||||
private(set) var snippets: [Snippet]
|
||||
weak var menu: NSMenu? { didSet { self.updateMenu() } }
|
||||
@ -47,16 +47,18 @@ import Shortcut
|
||||
|
||||
// MARK: Private Properties
|
||||
|
||||
private let defaults: UserDefaults
|
||||
|
||||
private var scope: String? { didSet { self.updateMenu() } }
|
||||
|
||||
|
||||
|
||||
// MARK: Lifecycle
|
||||
|
||||
private init() {
|
||||
private init(defaults: UserDefaults) {
|
||||
|
||||
self.snippets = UserDefaults.standard[.snippets]
|
||||
.compactMap(Snippet.init(dictionary:))
|
||||
self.defaults = defaults
|
||||
self.snippets = defaults[.snippets].compactMap(Snippet.init(dictionary:))
|
||||
|
||||
Task.detached {
|
||||
self.migrateIfNeeded()
|
||||
@ -105,7 +107,7 @@ import Shortcut
|
||||
func save(_ snippets: [Snippet]) {
|
||||
|
||||
self.snippets = snippets
|
||||
UserDefaults.standard[.snippets] = snippets.map(\.dictionary)
|
||||
self.defaults[.snippets] = snippets.map(\.dictionary)
|
||||
|
||||
self.updateMenu()
|
||||
}
|
||||
@ -174,7 +176,7 @@ private extension SnippetManager {
|
||||
|
||||
let defaultKey = "insertCustomTextArray"
|
||||
|
||||
guard let texts = UserDefaults.standard.stringArray(forKey: defaultKey) else { return }
|
||||
guard let texts = self.defaults.stringArray(forKey: defaultKey) else { return }
|
||||
|
||||
let shortcuts: [Int: Shortcut]
|
||||
let fileURL = URL.applicationSupportDirectory(component: "KeyBindings")
|
||||
@ -209,7 +211,7 @@ private extension SnippetManager {
|
||||
}
|
||||
|
||||
// remove old settings
|
||||
UserDefaults.standard.removeObject(forKey: defaultKey)
|
||||
self.defaults.removeObject(forKey: defaultKey)
|
||||
if fileURL.isReachable {
|
||||
try? FileManager.default.removeItem(at: fileURL)
|
||||
let parent = fileURL.deletingLastPathComponent()
|
||||
|
Loading…
Reference in New Issue
Block a user