Skip to content

Commit 44d28c8

Browse files
committed
CheckRunningInstances improved
1 parent df62f7d commit 44d28c8

3 files changed

Lines changed: 19 additions & 201 deletions

File tree

winUpdateMiniTool/Common/PipeIPC.cs

Lines changed: 0 additions & 177 deletions
This file was deleted.

winUpdateMiniTool/MainForm.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public MainForm() {
5252
}
5353

5454
if (!OperatingSystemHelper.IsRunningAsUwp())
55-
Text = $"{Updater.ApplicationTitle} v{Updater.CurrentVersion}";
55+
Text = Updater.ApplicationTitle;
5656

5757
btnWinUpd.Text = string.Format("Windows Update ({0})", 0);
5858
btnInstalled.Text = string.Format("Installed Updates ({0})", 0);
@@ -237,9 +237,6 @@ public MainForm() {
237237
mTimer.Tick += OnTimedEvent;
238238
mTimer.Enabled = true;
239239

240-
Program.Ipc.PipeMessage += PipesMessageHandler;
241-
Program.Ipc.Listen();
242-
243240
Updater.Subscribe(
244241
(message, isError) => { MessageBox.Show(message, Updater.ApplicationTitle, MessageBoxButtons.OK, isError ? MessageBoxIcon.Warning : MessageBoxIcon.Information); },
245242
(message) => { return MessageBox.Show(message, Updater.ApplicationTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK; },
@@ -291,6 +288,20 @@ private void InitializeTheme() {
291288

292289
#endregion
293290

291+
protected override void WndProc(ref Message m) {
292+
if (m.Msg == WinApiHelper.WM_SHOWME) {
293+
notifyIcon_BalloonTipClicked(null, null);
294+
Visible = true;
295+
WindowState = FormWindowState.Normal;
296+
Activate();
297+
BringToFront();
298+
WinApiHelper.SetForegroundWindow(this.Handle);
299+
}
300+
else {
301+
base.WndProc(ref m);
302+
}
303+
}
304+
294305
private void siteToolStripMenuItem_Click(object sender, EventArgs e) {
295306
Updater.VisitAppSite();
296307
}
@@ -318,16 +329,6 @@ protected override void SetVisibleCore(bool value) {
318329
base.SetVisibleCore(allowShowDisplay ? value : allowShowDisplay);
319330
}
320331

321-
private void PipesMessageHandler(PipeIpc.PipeServer pipe, string data) {
322-
if (data.Equals("show", StringComparison.CurrentCultureIgnoreCase)) {
323-
notifyIcon_BalloonTipClicked(null, null);
324-
pipe.Send("ok");
325-
}
326-
else {
327-
pipe.Send("unknown");
328-
}
329-
}
330-
331332
private void OnTimedEvent(object source, EventArgs e) {
332333
var updateNow = false;
333334
if (notifyIcon.Visible) {

winUpdateMiniTool/Program.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ internal static class Program {
2121
private static string appPath;
2222
public static string WrkPath;
2323
private static WuAgent agent;
24-
public static PipeIpc Ipc;
2524

2625
private static string GetIniPath() {
2726
return Path.Combine(WrkPath, Path.ChangeExtension(Path.GetFileName(typeof(Program).Assembly.Location), ".ini"));
@@ -64,15 +63,10 @@ private static void Main(string[] mainArgs) {
6463
Environment.Exit(0);
6564
}
6665

67-
Ipc = new PipeIpc("wumt_pipe");
68-
69-
var client = Ipc.Connect(100);
70-
if (client != null) {
71-
AppLog.Line("Application is already running.");
72-
client.Send("show");
73-
var ret = client.Read(1000);
74-
if (!ret.Equals("ok", StringComparison.CurrentCultureIgnoreCase))
75-
MessageBox.Show("Application is already running.", Updater.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
66+
if (WinApiHelper.CheckRunningInstances(true, true)) {
67+
// fallback
68+
MessageBox.Show($"{Updater.ApplicationName} is already running.", Updater.ApplicationName,
69+
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
7670
return;
7771
}
7872

0 commit comments

Comments
 (0)