Skip to content

Conversation

@ZuluPro
Copy link

@ZuluPro ZuluPro commented Sep 19, 2025

This commit add the reading of a configuration file in ~/.config/apple-on-device.json.

Why

I need to reconfigure the IP/Port at each start of the app

How

At startup, the app try to read ~/.config/apple-on-device.json,
If it not exist, it creates it with the default configuration.
Then the file's configuration is used for define the original one.

Comments

It's my 1st swift contribution,
I may not be aware of anything important

Future

I also need a persitent memory to be able to let users define their Tools

@ZuluPro
Copy link
Author

ZuluPro commented Sep 27, 2025

Any news ?

Copy link
Contributor

@channing channing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @ZuluPro, and sorry for the late response!

I appreciate you tackling the persistent configuration problem. However, on macOS, apps shouldn't create custom files in the home directory. The standard approach would be to use UserDefaults (simplest) or the Application Support directory (~/Library/Application Support/). The ~/.config/ pattern is more of a Linux convention.

For this use case, I'd recommend using @AppStorage - it's built into SwiftUI and handles persistence automatically:

@AppStorage("serverHost") var host = "127.0.0.1"
@AppStorage("serverPort") var port = 11535

func readConfiguration() -> ServerConfiguration {
let homeDir = FileManager.default.homeDirectoryForCurrentUser
let configDir = homeDir.appendingPathComponent(".config")
let configFile = homeDir.appendingPathComponent("apple-on-device.json")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use configDir, not homeDir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants