Modify how settings are handled by Espresso

This commit is contained in:
Den Delimarsky
2021-05-10 17:55:11 -07:00
parent f0e5be9982
commit 79c70b3998
3 changed files with 22 additions and 11 deletions

View File

@@ -52,12 +52,12 @@ namespace Espresso.Shell
log.Debug($"OS: {Environment.OSVersion}"); log.Debug($"OS: {Environment.OSVersion}");
log.Debug($"OS Build: {APIHelper.GetOperatingSystemBuild()}"); log.Debug($"OS Build: {APIHelper.GetOperatingSystemBuild()}");
var configOption = new Option<string>( var configOption = new Option<bool>(
aliases: new[] { "--config", "-c" }, aliases: new[] { "--use-pt-config", "-c" },
getDefaultValue: () => string.Empty, getDefaultValue: () => true,
description: "Pointer to a PowerToys configuration file that the tool will be watching for changes. All other options are disregarded if config is used.") description: "Specifies whether Espresso will be using the PowerToys configuration file for managing the state.")
{ {
Argument = new Argument<string>(() => string.Empty) Argument = new Argument<bool>(() => true)
{ {
Arity = ArgumentArity.ZeroOrOne, Arity = ArgumentArity.ZeroOrOne,
}, },
@@ -114,7 +114,7 @@ namespace Espresso.Shell
rootCommand.Description = appName; rootCommand.Description = appName;
rootCommand.Handler = CommandHandler.Create<string, bool, long, int>(HandleCommandLineArguments); rootCommand.Handler = CommandHandler.Create<bool, bool, long, int>(HandleCommandLineArguments);
return rootCommand.InvokeAsync(args).Result; return rootCommand.InvokeAsync(args).Result;
} }
@@ -127,25 +127,28 @@ namespace Espresso.Shell
Environment.Exit(exitCode); 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 --display-on is: {displayOn}");
log.Info($"The value for --time-limit is: {timeLimit}"); log.Info($"The value for --time-limit is: {timeLimit}");
log.Info($"The value for --pid is: {pid}"); 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 // Configuration file is used, therefore we disregard any other command-line parameter
// and instead watch for changes in the file. // and instead watch for changes in the file.
try try
{ {
var settingsPath = settingsUtils.GetSettingsFilePath(appName);
log.Info($"Reading configuration file: {settingsPath}");
watcher = new FileSystemWatcher watcher = new FileSystemWatcher
{ {
Path = Path.GetDirectoryName(config), Path = Path.GetDirectoryName(settingsPath),
EnableRaisingEvents = true, EnableRaisingEvents = true,
NotifyFilter = NotifyFilters.LastWrite, NotifyFilter = NotifyFilters.LastWrite,
Filter = Path.GetFileName(config) Filter = Path.GetFileName(settingsPath)
}; };
Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>( Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(

View File

@@ -19,5 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
bool SettingsExists(string powertoy = "", string fileName = "settings.json"); bool SettingsExists(string powertoy = "", string fileName = "settings.json");
void DeleteSettings(string powertoy = ""); void DeleteSettings(string powertoy = "");
string GetSettingsFilePath(string powertoy = "", string fileName = "settings.json");
} }
} }

View File

@@ -135,5 +135,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
#endif #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);
}
} }
} }