-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (54 loc) · 2.28 KB
/
Program.cs
File metadata and controls
61 lines (54 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Velopack;
using Velopack.Sources;
namespace WindowsSmartTaskbar
{
internal static class Program
{
static Mutex? mutex = null;
[DllImport("user32.dll")] private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public const int HWND_BROADCAST = 0xffff;
public static readonly int WM_SHOWME = RegisterWindowMessage("WM_SHOWME_SMARTTASKBAR");
[DllImport("user32.dll")] public static extern int RegisterWindowMessage(string message);
[STAThread]
static void Main(string[] args)
{
VelopackApp.Build().Run();
bool createdNew;
mutex = new Mutex(true, "WindowsSmartTaskbar_SingleInstance_App", out createdNew);
if (!createdNew)
{
SendMessage((IntPtr)HWND_BROADCAST, WM_SHOWME, 0, 0);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool autostart = false;
foreach (var arg in args)
{
if (arg.Trim('"', '\'').Equals("-autostart", StringComparison.OrdinalIgnoreCase)) autostart = true;
}
// Start an invisible background task to update the app quietly
Task.Run(async () => {
try {
var source = new GithubSource("https://github.com/nRn-World/WindowsSmartTaskbar", string.Empty, false);
var manager = new UpdateManager(source);
if (manager.IsInstalled) {
var newVersion = await manager.CheckForUpdatesAsync();
if (newVersion != null) {
await manager.DownloadUpdatesAsync(newVersion);
// Updates are now ready to be applied next time the app starts/restarts naturally
}
}
} catch {
// Ignore fail silently if internet is down, rate limit, etc.
}
});
Application.Run(new MainForm(autostart));
}
}
}