55import com .fasterxml .jackson .dataformat .toml .TomlMapper ;
66import io .temporal .common .Experimental ;
77import java .io .*;
8+ import java .nio .file .Paths ;
89import java .util .HashMap ;
910import java .util .Map ;
1011import java .util .Objects ;
1112
12- /** ClientConfig represents a client config file. */
13+ /**
14+ * ClientConfig represents a client config file.
15+ *
16+ * <p>The default config file path is OS-specific:
17+ *
18+ * <ul>
19+ * <li>macOS: $HOME/Library/Application Support/temporalio/temporal.toml
20+ * <li>Windows: %APPDATA%\temporalio\temporal.toml
21+ * <li>Linux/other: $HOME/.config/temporalio/temporal.toml
22+ * </ul>
23+ */
1324@ Experimental
1425public class ClientConfig {
1526 /** Creates a new builder to build a {@link ClientConfig}. */
@@ -32,13 +43,31 @@ public static ClientConfig getDefaultInstance() {
3243 return new ClientConfig .Builder ().build ();
3344 }
3445
35- /** Get the default config file path: $HOME/.config/temporalio/temporal.toml */
3646 private static String getDefaultConfigFilePath () {
3747 String userDir = System .getProperty ("user.home" );
3848 if (userDir == null || userDir .isEmpty ()) {
3949 throw new RuntimeException ("failed getting user home directory" );
4050 }
41- return userDir + "/.config/temporalio/temporal.toml" ;
51+ return getDefaultConfigFilePath (userDir , System .getProperty ("os.name" ), System .getenv ());
52+ }
53+
54+ static String getDefaultConfigFilePath (
55+ String userDir , String osName , Map <String , String > environment ) {
56+ if (osName != null ) {
57+ String osNameLower = osName .toLowerCase ();
58+ if (osNameLower .contains ("mac" )) {
59+ return Paths .get (userDir , "Library" , "Application Support" , "temporalio" , "temporal.toml" )
60+ .toString ();
61+ }
62+ if (osNameLower .contains ("win" )) {
63+ String appData = environment != null ? environment .get ("APPDATA" ) : null ;
64+ if (appData == null || appData .isEmpty ()) {
65+ throw new RuntimeException ("%APPDATA% is not defined" );
66+ }
67+ return Paths .get (appData , "temporalio" , "temporal.toml" ).toString ();
68+ }
69+ }
70+ return Paths .get (userDir , ".config" , "temporalio" , "temporal.toml" ).toString ();
4271 }
4372
4473 /**
0 commit comments