Add application icons

This commit is contained in:
Paddy Xu
2017-05-08 23:23:33 +03:00
parent 8388d7d347
commit b07457b53c
11 changed files with 143 additions and 37 deletions

View File

@@ -41,7 +41,7 @@ namespace QuickLook.Plugin.VideoViewer
public void View(string path, ContextObject context) public void View(string path, ContextObject context)
{ {
_vp = new ViewerPanel(); _vp = new ViewerPanel(context);
context.ViewerContent = _vp; context.ViewerContent = _vp;

View File

@@ -13,7 +13,9 @@ namespace QuickLook.Plugin.VideoViewer
/// </summary> /// </summary>
public partial class ViewerPanel : UserControl, IDisposable public partial class ViewerPanel : UserControl, IDisposable
{ {
public ViewerPanel() private ContextObject _context;
public ViewerPanel(ContextObject context)
{ {
InitializeComponent(); InitializeComponent();
@@ -21,8 +23,8 @@ namespace QuickLook.Plugin.VideoViewer
mediaElement.PropertyChanged += ChangePlayPauseButton; mediaElement.PropertyChanged += ChangePlayPauseButton;
mediaElement.MouseLeftButtonUp += TogglePlayPause; mediaElement.MouseLeftButtonUp += TogglePlayPause;
mediaElement.MediaErrored += ShowErrorOverlay; mediaElement.MediaErrored += ShowErrorNotification;
mediaElement.MediaFailed += ShowErrorOverlay; mediaElement.MediaFailed += ShowErrorNotification;
} }
public void Dispose() public void Dispose()
@@ -48,10 +50,11 @@ namespace QuickLook.Plugin.VideoViewer
: FontAwesomeIcon.PlayCircleOutline; : FontAwesomeIcon.PlayCircleOutline;
} }
private void ShowErrorOverlay(object sender, MediaErrorRoutedEventArgs e) private void ShowErrorNotification(object sender, MediaErrorRoutedEventArgs e)
{ {
mediaElement.Stop(); mediaElement.Stop();
errorOverlay.Visibility = Visibility.Visible;
_context.ShowNotification("", "An error occurred while loading the video.");
} }
public void LoadAndPlay(string path) public void LoadAndPlay(string path)

View File

@@ -1,6 +1,8 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading;
using System.Windows; using System.Windows;
namespace QuickLook namespace QuickLook
@@ -13,6 +15,8 @@ namespace QuickLook
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location; public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location;
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath); public static readonly string AppPath = Path.GetDirectoryName(AppFullPath);
private Mutex isRunning;
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
AppDomain.CurrentDomain.UnhandledException += AppDomain.CurrentDomain.UnhandledException +=
@@ -24,9 +28,25 @@ namespace QuickLook
private void Application_Startup(object sender, StartupEventArgs e) private void Application_Startup(object sender, StartupEventArgs e)
{ {
EnsureSingleInstance();
if (!e.Args.Contains("/autorun"))
TrayIcon.GetInstance().ShowNotification("", "QuickLook is running in the background.");
PluginManager.GetInstance(); PluginManager.GetInstance();
BackgroundListener.GetInstance(); BackgroundListener.GetInstance();
} }
private void EnsureSingleInstance()
{
bool isNew = false;
isRunning = new Mutex(true, "QuickLook.App", out isNew);
if (!isNew)
{
MessageBox.Show("QuickLook is already running in the background.");
Current.Shutdown();
}
}
} }
} }

View File

@@ -30,6 +30,17 @@ namespace QuickLook.Plugin
} }
} }
/// <summary>
/// Show a notification balloon.
/// </summary>
/// <param name="title">Title of the notification.</param>
/// <param name="content">The content.</param>
/// <param name="isError">Is this indicates a error?</param>
public void ShowNotification(string title, string content, bool isError = false)
{
TrayIcon.GetInstance().ShowNotification(title, content, isError);
}
/// <summary> /// <summary>
/// Get or set the viewer content control. /// Get or set the viewer content control.
/// </summary> /// </summary>

View File

@@ -8,8 +8,8 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace QuickLook.Properties namespace QuickLook.Properties {
{ using System;
/// <summary> /// <summary>
@@ -22,28 +22,23 @@ namespace QuickLook.Properties
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources internal class Resources {
{
private static global::System.Resources.ResourceManager resourceMan; private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture; private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() internal Resources() {
{
} }
/// <summary> /// <summary>
/// Returns the cached ResourceManager instance used by this class. /// Returns the cached ResourceManager instance used by this class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager internal static global::System.Resources.ResourceManager ResourceManager {
{ get {
get if (object.ReferenceEquals(resourceMan, null)) {
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("QuickLook.Properties.Resources", typeof(Resources).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("QuickLook.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp; resourceMan = temp;
} }
@@ -56,16 +51,33 @@ namespace QuickLook.Properties
/// resource lookups using this strongly typed resource class. /// resource lookups using this strongly typed resource class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture internal static global::System.Globalization.CultureInfo Culture {
{ get {
get
{
return resourceCulture; return resourceCulture;
} }
set set {
{
resourceCulture = value; resourceCulture = value;
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon app {
get {
object obj = ResourceManager.GetObject("app", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon app_white {
get {
object obj = ResourceManager.GetObject("app_white", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
} }
} }

View File

@@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64 mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
@@ -60,6 +60,7 @@
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>
<xsd:choice maxOccurs="unbounded"> <xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
<xsd:sequence> <xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" /> <xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence> </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" /> <xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" /> <xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" /> <xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="assembly"> <xsd:element name="assembly">
@@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence> </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="resheader"> <xsd:element name="resheader">
@@ -109,9 +112,16 @@
<value>2.0</value> <value>2.0</value>
</resheader> </resheader>
<resheader name="reader"> <resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="app" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\app.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="app_white" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\app_white.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

View File

@@ -48,6 +48,9 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\app.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="FontAwesome.WPF, Version=4.7.0.37774, Culture=neutral, PublicKeyToken=0758b07a11a4f466, processorArchitecture=MSIL"> <Reference Include="FontAwesome.WPF, Version=4.7.0.37774, Culture=neutral, PublicKeyToken=0758b07a11a4f466, processorArchitecture=MSIL">
<HintPath>..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll</HintPath> <HintPath>..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll</HintPath>
@@ -90,6 +93,7 @@
<Compile Include="Plugin\InfoPanel\WindowsThumbnailProvider.cs" /> <Compile Include="Plugin\InfoPanel\WindowsThumbnailProvider.cs" />
<Compile Include="Plugin\IViewer.cs" /> <Compile Include="Plugin\IViewer.cs" />
<Compile Include="Helpers\DpiHelpers.cs" /> <Compile Include="Helpers\DpiHelpers.cs" />
<Compile Include="TrayIcon.cs" />
<Compile Include="ViewContentContainer.xaml.cs"> <Compile Include="ViewContentContainer.xaml.cs">
<DependentUpon>ViewContentContainer.xaml</DependentUpon> <DependentUpon>ViewContentContainer.xaml</DependentUpon>
</Compile> </Compile>
@@ -172,5 +176,11 @@
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Resources\app.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\app_white.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

BIN
QuickLook/Resources/app.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

36
QuickLook/TrayIcon.cs Normal file
View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace QuickLook
{
public class TrayIcon
{
private static TrayIcon _instance;
private NotifyIcon _icon;
internal TrayIcon()
{
_icon = new NotifyIcon
{
Icon = Properties.Resources.app_white,
Visible = true
};
}
public void ShowNotification(string title, string content, bool isError = false)
{
_icon.ShowBalloonTip(5000, title, content, isError ? ToolTipIcon.Error : ToolTipIcon.Info);
}
internal static TrayIcon GetInstance()
{
return _instance ?? (_instance = new TrayIcon());
}
}
}

View File

@@ -31,3 +31,7 @@ Hotkeys in preview window:
The previewing ability can be extended by new plugins. Read the [plugin interface](https://github.com/xupefei/QuickLook/blob/master/QuickLook/Plugin/IViewer.cs), [context object](https://github.com/xupefei/QuickLook/blob/master/QuickLook/Plugin/ContextObject.cs) for more information. [Pre-shipped plugins](https://github.com/xupefei/QuickLook/tree/master/QuickLook.Plugin) contains more detailed implementation. The previewing ability can be extended by new plugins. Read the [plugin interface](https://github.com/xupefei/QuickLook/blob/master/QuickLook/Plugin/IViewer.cs), [context object](https://github.com/xupefei/QuickLook/blob/master/QuickLook/Plugin/ContextObject.cs) for more information. [Pre-shipped plugins](https://github.com/xupefei/QuickLook/tree/master/QuickLook.Plugin) contains more detailed implementation.
Note that any plugin must be under the `QuickLook.Plugin` namespace, has the filename similar to `QuickLook.Plugin.YourPlugin.dll` and placed under `<Application>\Plugins\QuickLook.Plugin.YourPlugin\` subfolder. Note that any plugin must be under the `QuickLook.Plugin` namespace, has the filename similar to `QuickLook.Plugin.YourPlugin.dll` and placed under `<Application>\Plugins\QuickLook.Plugin.YourPlugin\` subfolder.
## Licenses
Application icons made by Freepik from www.flaticon.com. Used under the [Flaticon Basic License](http://file000.flaticon.com/downloads/license/license.pdf).