diff --git a/src/modules/espresso/Espresso/Program.cs b/src/modules/espresso/Espresso/Program.cs index 1d0dc6695e..8579c00baf 100644 --- a/src/modules/espresso/Espresso/Program.cs +++ b/src/modules/espresso/Espresso/Program.cs @@ -52,12 +52,12 @@ namespace Espresso.Shell log.Debug($"OS: {Environment.OSVersion}"); log.Debug($"OS Build: {APIHelper.GetOperatingSystemBuild()}"); - var configOption = new Option( - aliases: new[] { "--config", "-c" }, - getDefaultValue: () => string.Empty, - description: "Pointer to a PowerToys configuration file that the tool will be watching for changes. All other options are disregarded if config is used.") + var configOption = new Option( + aliases: new[] { "--use-pt-config", "-c" }, + getDefaultValue: () => true, + description: "Specifies whether Espresso will be using the PowerToys configuration file for managing the state.") { - Argument = new Argument(() => string.Empty) + Argument = new Argument(() => true) { Arity = ArgumentArity.ZeroOrOne, }, @@ -114,7 +114,7 @@ namespace Espresso.Shell rootCommand.Description = appName; - rootCommand.Handler = CommandHandler.Create(HandleCommandLineArguments); + rootCommand.Handler = CommandHandler.Create(HandleCommandLineArguments); return rootCommand.InvokeAsync(args).Result; } @@ -127,25 +127,28 @@ namespace Espresso.Shell Environment.Exit(exitCode); } - private static void HandleCommandLineArguments(string config, bool displayOn, long timeLimit, int pid) + private static void HandleCommandLineArguments(bool usePtConfig, bool displayOn, long timeLimit, int pid) { - log.Info($"The value for --config is: {config}"); + log.Info($"The value for --use-pt-config is: {usePtConfig}"); log.Info($"The value for --display-on is: {displayOn}"); log.Info($"The value for --time-limit is: {timeLimit}"); log.Info($"The value for --pid is: {pid}"); - if (!string.IsNullOrWhiteSpace(config)) + if (usePtConfig) { // Configuration file is used, therefore we disregard any other command-line parameter // and instead watch for changes in the file. try { + var settingsPath = settingsUtils.GetSettingsFilePath(appName); + log.Info($"Reading configuration file: {settingsPath}"); + watcher = new FileSystemWatcher { - Path = Path.GetDirectoryName(config), + Path = Path.GetDirectoryName(settingsPath), EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite, - Filter = Path.GetFileName(config) + Filter = Path.GetFileName(settingsPath) }; Observable.FromEventPattern( diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ISettingsUtils.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ISettingsUtils.cs index ea7b615fcf..7cfa33be62 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ISettingsUtils.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ISettingsUtils.cs @@ -19,5 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library bool SettingsExists(string powertoy = "", string fileName = "settings.json"); void DeleteSettings(string powertoy = ""); + + string GetSettingsFilePath(string powertoy = "", string fileName = "settings.json"); } } diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SettingsUtils.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SettingsUtils.cs index eb40f04cf6..926674ab03 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SettingsUtils.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/SettingsUtils.cs @@ -135,5 +135,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library #endif } } + + // Returns the file path to the settings file, that is exposed from the local ISettingsPath instance. + public string GetSettingsFilePath(string powertoy = "", string fileName = "settings.json") + { + return _settingsPath.GetSettingsPath(powertoy, fileName); + } } }