diff --git a/README.md b/README.md index 7b59916..29dcd79 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,15 @@ Works on Windows and Linux. Default config file will be autogenerated for you on the first run. You can access it from from: `Click Tray Icon > Configure`. + +Config file name is `config.toml`. + On Linux, the config folder location is `~/.config/kanata-tray`. On Windows, it's `C:\Users\\AppData\Roaming\kanata-tray` +Alternatively, you can place your config file in the same folder as kanata-tray executable, +and it will be have higher priority than the global config in user folder. + ### Examples An example of customized configuration file: diff --git a/main.go b/main.go index f787f32..c1197d9 100644 --- a/main.go +++ b/main.go @@ -43,23 +43,38 @@ func main() { } func mainImpl() error { - configFolder := configdir.LocalConfig("kanata-tray") - fmt.Printf("kanata-tray config folder: %s\n", configFolder) + configFileName := "config.toml" + var configFile string + var configFolder string - // Create folder. No-op if exists. - err := configdir.MakePath(configFolder) + // First try reading config.toml from the folder where kanata-tray is located. + exePath, err := os.Executable() if err != nil { - return fmt.Errorf("failed to create folder: %v", err) + fmt.Println("Failed attempt to read config.toml from kanata-tray folder", err) + } + localConfigFolder := filepath.Dir(exePath) + localConfigFile := filepath.Join(localConfigFolder, configFileName) + if _, err := os.Stat(localConfigFile); os.IsNotExist(err) { + configFolder = configdir.LocalConfig("kanata-tray") + configFile = filepath.Join(configFolder, configFileName) + // Create folder. No-op if exists. + err = configdir.MakePath(configFolder) + if err != nil { + return fmt.Errorf("failed to create folder: %v", err) + } + } else { + configFolder = localConfigFolder + configFile = localConfigFile } + fmt.Printf("kanata-tray config folder: %s\n", configFolder) + // Make sure "icons" folder exists too. err = configdir.MakePath(filepath.Join(configFolder, "icons")) if err != nil { return fmt.Errorf("failed to create folder: %v", err) } - configFile := filepath.Join(configFolder, "config.toml") - cfg, err := config.ReadConfigOrCreateIfNotExist(configFile) if err != nil { return fmt.Errorf("loading config failed: %v", err)