Skip to content
10 changes: 5 additions & 5 deletions Wox.Plugin.Runner/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Wox.Plugin.Runner
{
public class Command
{
public string Shortcut { get; set; }
public string Description { get; set; }
public string Path { get; set; }
public string WorkingDirectory { get; set; }
public string ArgumentsFormat { get; set; }
public string Shortcut { get; set; } = "";
public string Description { get; set; } = "";
public string Path { get; set; } = "";
public string WorkingDirectory { get; set; } = "";
public string ArgumentsFormat { get; set; } = "";
}
}
4 changes: 2 additions & 2 deletions Wox.Plugin.Runner/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface IConfigurationLoader
class ConfigurationLoader : IConfigurationLoader
{
readonly static string configPath = Environment.ExpandEnvironmentVariables(
@$"%appdata%\FlowLauncher\Settings\Plugins\{Runner.Context.CurrentPluginMetadata.Name}");
@$"%appdata%\FlowLauncher\Settings\Plugins\{Runner.Context!.CurrentPluginMetadata.Name}");
readonly static string configFile = Path.Combine(configPath, "commands.json");

public ConfigurationLoader()
Expand All @@ -33,7 +33,7 @@ public IEnumerable<Command> LoadCommands()
{
var text = File.ReadAllText(configFile);
if (!string.IsNullOrEmpty(text))
return JsonSerializer.Deserialize<IEnumerable<Command>>(text);
return JsonSerializer.Deserialize<IEnumerable<Command>>(text) ?? new List<Command>();

return new List<Command>();
}
Expand Down
18 changes: 9 additions & 9 deletions Wox.Plugin.Runner/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Wox.Plugin.Runner
{
public class Runner : IPlugin, ISettingProvider
{
internal static PluginInitContext Context;
RunnerSettingsViewModel viewModel;
internal static PluginInitContext? Context;
RunnerSettingsViewModel? viewModel;

public void Init(PluginInitContext context)
{
Expand Down Expand Up @@ -82,7 +82,7 @@ private List<Result> FuzzySearchCommand(string shortcut, string[] terms)
{
return RunnerConfiguration.Commands.Select(c => new Result()
{
Score = Context.API.FuzzySearch(shortcut, c.Shortcut).Score,
Score = Context!.API.FuzzySearch(shortcut, c.Shortcut).Score,
Title = c.Shortcut,
SubTitle = c.Description,
Action = e => RunCommand(e, c, terms),
Expand All @@ -93,7 +93,7 @@ private List<Result> FuzzySearchCommand(string shortcut, string[] terms)

public Control CreateSettingPanel()
{
return new RunnerSettings(viewModel);
return new RunnerSettings(viewModel!);
}

private bool RunCommand(ActionContext e, Command command, IEnumerable<string>? terms = null)
Expand All @@ -120,8 +120,8 @@ private bool RunCommand(ActionContext e, Command command, IEnumerable<string>? t
}
catch (FormatException ex)
{
Context.API.ShowMsg("There was a problem. Please check the arguments format for the command.");
Context.API.LogException(nameof(Runner), "Argument format was invalid", ex);
Context!.API.ShowMsg("There was a problem. Please check the arguments format for the command.");
Context!.API.LogException(nameof(Runner), "Argument format was invalid", ex);
}
return true;
}
Expand Down Expand Up @@ -173,9 +173,9 @@ private ProcessArguments GetProcessArguments(Command c, IEnumerable<string>? ter

class ProcessArguments
{
public string FileName { get; set; }
public string Arguments { get; set; }
public string WorkingDirectory { get; set; }
public string FileName { get; set; } = "";
public string Arguments { get; set; } = "";
public string? WorkingDirectory { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions Wox.Plugin.Runner/RunnerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Wox.Plugin.Runner
{
static class RunnerConfiguration
{
private static IConfigurationLoader loader;
private static IConfigurationLoader? loader;
public static IConfigurationLoader Loader
{
get
Expand All @@ -21,7 +21,7 @@ public static IConfigurationLoader Loader
}
}

private static IEnumerable<Command> commands;
private static IEnumerable<Command>? commands;
public static IEnumerable<Command> Commands
{
get
Expand Down
14 changes: 7 additions & 7 deletions Wox.Plugin.Runner/Settings/RunnerSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Wox.Plugin.Runner.Settings
{
public class RunnerSettingsViewModel
{
private readonly PluginInitContext context;
private readonly PluginInitContext? context;

public RunnerSettingsViewModel() { }

Expand All @@ -21,9 +21,9 @@ public void LoadCommands()
RunnerConfiguration.Commands.Select( c => new CommandViewModel( c ) ) );
}

public ObservableCollection<CommandViewModel> Commands { get; set; }
public ObservableCollection<CommandViewModel>? Commands { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe refactor a bit to make this not nullable. The viewmodel is not intended to have null Commands.


public CommandViewModel SelectedCommand { get; set; }
public CommandViewModel? SelectedCommand { get; set; }

public bool CommandIsSelected
{
Expand All @@ -36,22 +36,22 @@ public bool CommandIsSelected
public void Add()
{
var cmd = new CommandViewModel(new Command());
Commands.Add(cmd);
Commands!.Add(cmd);
SelectedCommand = cmd;
}

public void SaveChanges()
{
RunnerConfiguration.Commands = Commands.Select(c => c.GetCommand());
RunnerConfiguration.Commands = Commands!.Select(c => c.GetCommand());

context.API.ShowMsg("Your changes have been saved!");
context!.API.ShowMsg("Your changes have been saved!");
}

public void Delete(CommandViewModel cmdToDelete)
{
if (cmdToDelete != null)
{
Commands.Remove(cmdToDelete);
Commands!.Remove(cmdToDelete);
SelectedCommand = null;
}
}
Expand Down