Skip to content

Commit 3e4570a

Browse files
authored
Merge pull request #33 from mgxv/refactor/dedup-app-support-url
Extract shared Application Support URL resolution
2 parents 5f663cc + 86e4108 commit 3e4570a

4 files changed

Lines changed: 20 additions & 29 deletions

File tree

Sources/AppOverrides.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,7 @@ extension AppOverrides: Codable {
2626

2727
enum AppOverridesState {
2828
private static func url() -> URL? {
29-
guard let appSupport = try? FileManager.default.url(
30-
for: .applicationSupportDirectory,
31-
in: .userDomainMask,
32-
appropriateFor: nil,
33-
create: false,
34-
) else { return nil }
35-
return appSupport
36-
.appendingPathComponent(Log.subsystem, isDirectory: true)
37-
.appendingPathComponent("apps.json")
29+
subsystemSupportURL("apps.json")
3830
}
3931

4032
static func read() -> AppOverrides {

Sources/HotkeyWatcher.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,7 @@ final class HotkeyWatcher {
127127
/// shutdown so a stale value doesn't outlive the daemon.
128128
enum HotkeyState {
129129
private static func url() -> URL? {
130-
guard let appSupport = try? FileManager.default.url(
131-
for: .applicationSupportDirectory,
132-
in: .userDomainMask,
133-
appropriateFor: nil,
134-
create: false,
135-
) else { return nil }
136-
return appSupport
137-
.appendingPathComponent(Log.subsystem, isDirectory: true)
138-
.appendingPathComponent("hotkey.state")
130+
subsystemSupportURL("hotkey.state")
139131
}
140132

141133
static func write(_ state: String) {

Sources/Mode.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ enum Mode: String {
1212
/// Default is `.smart` when the file is missing or malformed.
1313
enum ModeState {
1414
private static func url() -> URL? {
15-
guard let appSupport = try? FileManager.default.url(
16-
for: .applicationSupportDirectory,
17-
in: .userDomainMask,
18-
appropriateFor: nil,
19-
create: false,
20-
) else { return nil }
21-
return appSupport
22-
.appendingPathComponent(Log.subsystem, isDirectory: true)
23-
.appendingPathComponent("mode")
15+
subsystemSupportURL("mode")
2416
}
2517

2618
static func read() -> Mode {

Sources/Paths.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
// Filesystem paths used at runtime to locate the vendored
2-
// mediaremote-adapter script and MediaRemoteAdapter.framework.
1+
// Filesystem path resolution used at runtime: the vendored
2+
// mediaremote-adapter artifacts, and the Application Support directory
3+
// backing the on-disk `*State` stores.
34

45
import Foundation
56

7+
/// `~/Library/Application Support/<subsystem>/<name>`, or nil if it
8+
/// can't be resolved. Shared by the `*State` stores.
9+
func subsystemSupportURL(_ name: String) -> URL? {
10+
guard let appSupport = try? FileManager.default.url(
11+
for: .applicationSupportDirectory,
12+
in: .userDomainMask,
13+
appropriateFor: nil,
14+
create: false,
15+
) else { return nil }
16+
return appSupport
17+
.appendingPathComponent(Log.subsystem, isDirectory: true)
18+
.appendingPathComponent(name)
19+
}
20+
621
struct AdapterArtifacts {
722
let scriptPath: String
823
let frameworkPath: String

0 commit comments

Comments
 (0)