mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Add error info when file/application can't be open
1. Fix #492 2. FIx #478
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -56,13 +57,24 @@ namespace Wox.Plugin.Everything
|
|||||||
r.IcoPath = GetIconPath(s);
|
r.IcoPath = GetIconPath(s);
|
||||||
r.Action = c =>
|
r.Action = c =>
|
||||||
{
|
{
|
||||||
_context.API.HideApp();
|
bool hide;
|
||||||
Process.Start(new ProcessStartInfo
|
try
|
||||||
{
|
{
|
||||||
FileName = path,
|
Process.Start(new ProcessStartInfo
|
||||||
UseShellExecute = true
|
{
|
||||||
});
|
FileName = path,
|
||||||
return true;
|
UseShellExecute = true
|
||||||
|
});
|
||||||
|
hide = true;
|
||||||
|
}
|
||||||
|
catch (Win32Exception)
|
||||||
|
{
|
||||||
|
var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
|
||||||
|
var message = "Can't open this file";
|
||||||
|
_context.API.ShowMsg(name, message, string.Empty);
|
||||||
|
hide = false;
|
||||||
|
}
|
||||||
|
return hide;
|
||||||
};
|
};
|
||||||
r.ContextData = s;
|
r.ContextData = s;
|
||||||
results.Add(r);
|
results.Add(r);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -25,7 +26,7 @@ namespace Wox.Plugin.Program
|
|||||||
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
|
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
|
||||||
{"AppPathsProgramSource", typeof(AppPathsProgramSource)}
|
{"AppPathsProgramSource", typeof(AppPathsProgramSource)}
|
||||||
};
|
};
|
||||||
private PluginInitContext context;
|
private PluginInitContext _context;
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
@@ -43,9 +44,8 @@ namespace Wox.Plugin.Program
|
|||||||
ContextData = c,
|
ContextData = c,
|
||||||
Action = e =>
|
Action = e =>
|
||||||
{
|
{
|
||||||
context.API.HideApp();
|
var hide = StartProcess(new ProcessStartInfo(c.ExecutePath));
|
||||||
Process.Start(c.ExecutePath);
|
return hide;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}).ToList();
|
}).ToList();
|
||||||
return results;
|
return results;
|
||||||
@@ -60,7 +60,7 @@ namespace Wox.Plugin.Program
|
|||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this._context = context;
|
||||||
Stopwatch.Debug("Preload programs", () =>
|
Stopwatch.Debug("Preload programs", () =>
|
||||||
{
|
{
|
||||||
programs = ProgramCacheStorage.Instance.Programs;
|
programs = ProgramCacheStorage.Instance.Programs;
|
||||||
@@ -163,19 +163,19 @@ namespace Wox.Plugin.Program
|
|||||||
|
|
||||||
public Control CreateSettingPanel()
|
public Control CreateSettingPanel()
|
||||||
{
|
{
|
||||||
return new ProgramSetting(context);
|
return new ProgramSetting(_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("wox_plugin_program_plugin_name");
|
return _context.API.GetTranslation("wox_plugin_program_plugin_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
public string GetTranslatedPluginDescription()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("wox_plugin_program_plugin_description");
|
return _context.API.GetTranslation("wox_plugin_program_plugin_description");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> LoadContextMenus(Result selectedResult)
|
public List<Result> LoadContextMenus(Result selectedResult)
|
||||||
@@ -185,35 +185,51 @@ namespace Wox.Plugin.Program
|
|||||||
{
|
{
|
||||||
new Result
|
new Result
|
||||||
{
|
{
|
||||||
Title = context.API.GetTranslation("wox_plugin_program_run_as_administrator"),
|
Title = _context.API.GetTranslation("wox_plugin_program_run_as_administrator"),
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
context.API.HideApp();
|
var hide = StartProcess(new ProcessStartInfo
|
||||||
Process.Start( new ProcessStartInfo
|
|
||||||
{
|
{
|
||||||
FileName = p.ExecutePath,
|
FileName = p.ExecutePath,
|
||||||
Verb = "runas"
|
Verb = "runas"
|
||||||
});
|
});
|
||||||
return true;
|
return hide;
|
||||||
},
|
},
|
||||||
IcoPath = "Images/cmd.png"
|
IcoPath = "Images/cmd.png"
|
||||||
},
|
},
|
||||||
new Result
|
new Result
|
||||||
{
|
{
|
||||||
Title = context.API.GetTranslation("wox_plugin_program_open_containing_folder"),
|
Title = _context.API.GetTranslation("wox_plugin_program_open_containing_folder"),
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
context.API.HideApp();
|
|
||||||
//get parent folder
|
//get parent folder
|
||||||
var folderPath = Directory.GetParent(p.ExecutePath).FullName;
|
var folderPath = Directory.GetParent(p.ExecutePath).FullName;
|
||||||
//open the folder
|
//open the folder
|
||||||
Process.Start(folderPath);
|
var hide = StartProcess(new ProcessStartInfo(folderPath));
|
||||||
return true;
|
return hide;
|
||||||
},
|
},
|
||||||
IcoPath = "Images/folder.png"
|
IcoPath = "Images/folder.png"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return contextMenus;
|
return contextMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool StartProcess(ProcessStartInfo info)
|
||||||
|
{
|
||||||
|
bool hide;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Process.Start(info);
|
||||||
|
hide = true;
|
||||||
|
}
|
||||||
|
catch (Win32Exception)
|
||||||
|
{
|
||||||
|
var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
|
||||||
|
var message = "Can't open this file";
|
||||||
|
_context.API.ShowMsg(name, message, string.Empty);
|
||||||
|
hide = false;
|
||||||
|
}
|
||||||
|
return hide;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ namespace Wox
|
|||||||
|
|
||||||
// Create the fade out storyboard
|
// Create the fade out storyboard
|
||||||
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
|
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
|
||||||
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(0.3)))
|
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(1)))
|
||||||
{
|
{
|
||||||
AccelerationRatio = 0.2
|
AccelerationRatio = 0.2
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user