mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-17 13:52:40 +00:00
disable autorun and update check when running as an UWP
This commit is contained in:
@@ -31,6 +31,7 @@ namespace QuickLook
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -31,6 +31,9 @@ namespace QuickLook.Helpers
|
||||
{
|
||||
public static void CheckForUpdates(bool silent = false)
|
||||
{
|
||||
if (App.IsUWP)
|
||||
return;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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())
|
||||
})
|
||||
|
Reference in New Issue
Block a user