diff --git a/QuickLook/App.xaml.cs b/QuickLook/App.xaml.cs index d6e6096..967ed15 100644 --- a/QuickLook/App.xaml.cs +++ b/QuickLook/App.xaml.cs @@ -31,6 +31,7 @@ namespace QuickLook /// public partial class App : Application { + public static readonly bool IsUWP = ProcessHelper.IsRunningAsUWP(); public static readonly bool Is64Bit = Environment.Is64BitProcess; public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location; public static readonly string AppPath = Path.GetDirectoryName(AppFullPath); @@ -82,7 +83,7 @@ namespace QuickLook private void RunListener(StartupEventArgs e) { TrayIconManager.GetInstance(); - if (!e.Args.Contains("/autorun")) + if (!e.Args.Contains("/autorun") && !IsUWP) TrayIconManager.GetInstance().ShowNotification("", "QuickLook is running in the background."); if (e.Args.Contains("/first")) AutoStartupHelper.CreateAutorunShortcut(); @@ -93,7 +94,7 @@ namespace QuickLook BackgroundListener.GetInstance(); PipeServerManager.GetInstance().MessageReceived += (msg, ea) => Dispatcher.BeginInvoke( - new Action(() => ViewWindowManager.GetInstance().InvokeViewer(msg as string, closeIfSame: true)), + new Action(() => ViewWindowManager.GetInstance().InvokeViewer(msg as string, true)), DispatcherPriority.ApplicationIdle); } diff --git a/QuickLook/Helpers/AutoStartupHelper.cs b/QuickLook/Helpers/AutoStartupHelper.cs index d7afe6c..6988cdd 100644 --- a/QuickLook/Helpers/AutoStartupHelper.cs +++ b/QuickLook/Helpers/AutoStartupHelper.cs @@ -29,6 +29,9 @@ namespace QuickLook.Helpers internal static void CreateAutorunShortcut() { + if (App.IsUWP) + return; + try { File.Create(_startupFullPath).Close(); @@ -53,11 +56,17 @@ namespace QuickLook.Helpers internal static void RemoveAutorunShortcut() { + if (App.IsUWP) + return; + File.Delete(_startupFullPath); } internal static bool IsAutorun() { + if (App.IsUWP) + return true; + return File.Exists(_startupFullPath); } } diff --git a/QuickLook/Helpers/ProcessHelper.cs b/QuickLook/Helpers/ProcessHelper.cs index 4006529..726b6a3 100644 --- a/QuickLook/Helpers/ProcessHelper.cs +++ b/QuickLook/Helpers/ProcessHelper.cs @@ -17,16 +17,34 @@ using System; using System.Threading.Tasks; +using QuickLook.NativeMethods; namespace QuickLook.Helpers { internal class ProcessHelper { + private const int ErrorInsufficientBuffer = 0x7A; + // ReSharper disable once InconsistentNaming public static void PerformAggressiveGC() { // delay some time to make sure that all windows are closed Task.Delay(1000).ContinueWith(t => GC.Collect(GC.MaxGeneration)); } + + public static bool IsRunningAsUWP() + { + try + { + uint len = 0; + var r = Kernel32.GetCurrentPackageFullName(ref len, null); + + return r == ErrorInsufficientBuffer; + } + catch (EntryPointNotFoundException) + { + return false; + } + } } } \ No newline at end of file diff --git a/QuickLook/Helpers/Updater.cs b/QuickLook/Helpers/Updater.cs index 73cd904..593dacc 100644 --- a/QuickLook/Helpers/Updater.cs +++ b/QuickLook/Helpers/Updater.cs @@ -31,6 +31,9 @@ namespace QuickLook.Helpers { public static void CheckForUpdates(bool silent = false) { + if (App.IsUWP) + return; + Task.Run(() => { try diff --git a/QuickLook/NativeMethods/Kernel32.cs b/QuickLook/NativeMethods/Kernel32.cs index 9a2d721..eec903c 100644 --- a/QuickLook/NativeMethods/Kernel32.cs +++ b/QuickLook/NativeMethods/Kernel32.cs @@ -17,6 +17,7 @@ using System; using System.Runtime.InteropServices; +using System.Text; namespace QuickLook.NativeMethods { @@ -25,6 +26,10 @@ namespace QuickLook.NativeMethods [DllImport("kernel32.dll")] internal static extern IntPtr LoadLibrary(string lpFileName); + [DllImport("kernel32.dll")] + internal static extern int GetCurrentPackageFullName(ref uint packageFullNameLength, + [MarshalAs(UnmanagedType.LPWStr)] StringBuilder packageFullName); + [DllImport("kernel32.dll")] internal static extern IntPtr GetCurrentThreadId(); } diff --git a/QuickLook/TrayIconManager.cs b/QuickLook/TrayIconManager.cs index 6b54c54..2192233 100644 --- a/QuickLook/TrayIconManager.cs +++ b/QuickLook/TrayIconManager.cs @@ -16,7 +16,6 @@ // along with this program. If not, see . using System; -using System.Diagnostics; using System.Windows.Forms; using QuickLook.Helpers; using QuickLook.Properties; @@ -36,7 +35,7 @@ namespace QuickLook AutoStartupHelper.RemoveAutorunShortcut(); else AutoStartupHelper.CreateAutorunShortcut(); - }); + }) {Enabled = !App.IsUWP}; private TrayIconManager() { @@ -50,7 +49,7 @@ namespace QuickLook new MenuItem($"v{Application.ProductVersion}") {Enabled = false}, new MenuItem("-"), new MenuItem("Check for &Updates...", - (sender, e) => Updater.CheckForUpdates()), + (sender, e) => Updater.CheckForUpdates()) {Enabled = !App.IsUWP}, _itemAutorun, new MenuItem("&Quit", (sender, e) => System.Windows.Application.Current.Shutdown()) })