common helper for execute shell process from run plugins (#9538)

This commit is contained in:
Davide Giacometti
2021-02-23 09:53:08 +01:00
committed by GitHub
parent 20a922ce21
commit 571bceb386
17 changed files with 77 additions and 128 deletions

View File

@@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO.Abstractions;
using System.Linq;
@@ -16,6 +14,7 @@ using Microsoft.Plugin.Indexer.DriveDetection;
using Microsoft.Plugin.Indexer.SearchHelper;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.Search.Interop;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Wox.Plugin.Logger;
@@ -85,15 +84,7 @@ namespace Microsoft.Plugin.Indexer
IcoPath = WarningIconPath,
Action = e =>
{
try
{
Process.Start(GetWindowsSearchSettingsProcessInfo());
}
catch (Exception ex)
{
Log.Exception($"Unable to launch Windows Search Settings: {ex.Message}", ex, GetType());
}
Helper.OpenInShell("ms-settings:cortana-windowssearch");
return true;
},
});
@@ -129,23 +120,13 @@ namespace Microsoft.Plugin.Indexer
r.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
r.Action = c =>
{
bool hide;
try
{
Process.Start(new ProcessStartInfo
{
FileName = path,
UseShellExecute = true,
WorkingDirectory = workingDir,
});
hide = true;
}
catch (Win32Exception)
bool hide = true;
if (!Helper.OpenInShell(path, null, workingDir))
{
hide = false;
var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
var msg = Properties.Resources.Microsoft_plugin_indexer_file_open_failed;
_context.API.ShowMsg(name, msg, string.Empty);
hide = false;
}
return hide;
@@ -239,18 +220,6 @@ namespace Microsoft.Plugin.Indexer
throw new NotImplementedException();
}
// Returns the Process Start Information for the new Windows Search Settings
public static ProcessStartInfo GetWindowsSearchSettingsProcessInfo()
{
var ps = new ProcessStartInfo("ms-settings:cortana-windowssearch")
{
UseShellExecute = true,
Verb = "open",
};
return ps;
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)