Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 290 additions & 36 deletions WireSockUI.Tests/Program.cs

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions WireSockUI/Forms/AutoRunOperationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ internal enum AutoRunHelperOperation
{
Inspect,
Enable,
EnableMigratingLegacyTask,
Disable,
DisableMigratingLegacyTask,
DeleteLegacyShortcut
}

Expand Down Expand Up @@ -433,8 +435,12 @@ private static string GetOperationArgument(AutoRunHelperOperation operation)
return "inspect";
case AutoRunHelperOperation.Enable:
return "enable";
case AutoRunHelperOperation.EnableMigratingLegacyTask:
return "enable-migrating-legacy-task";
case AutoRunHelperOperation.Disable:
return "disable";
case AutoRunHelperOperation.DisableMigratingLegacyTask:
return "disable-migrating-legacy-task";
case AutoRunHelperOperation.DeleteLegacyShortcut:
return "delete-legacy-shortcut";
default:
Expand All @@ -452,9 +458,15 @@ private static bool TryParseOperation(string value, out AutoRunHelperOperation o
case "enable":
operation = AutoRunHelperOperation.Enable;
return true;
case "enable-migrating-legacy-task":
operation = AutoRunHelperOperation.EnableMigratingLegacyTask;
return true;
case "disable":
operation = AutoRunHelperOperation.Disable;
return true;
case "disable-migrating-legacy-task":
operation = AutoRunHelperOperation.DisableMigratingLegacyTask;
return true;
case "delete-legacy-shortcut":
operation = AutoRunHelperOperation.DeleteLegacyShortcut;
return true;
Expand Down
59 changes: 45 additions & 14 deletions WireSockUI/Forms/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,43 @@ internal static void ConfigureBottomActionRow(
actions.WrapContents = false;
}

internal static void ConcealFromTaskbar(Form form)
{
if (form == null)
throw new ArgumentNullException(nameof(form));

// ShowInTaskbar recreates an existing WinForms top-level handle.
// Hide first so the replacement handle can never be painted as an
// empty frame while the window is being minimized or closed.
form.Hide();
form.ShowInTaskbar = false;
}

internal static bool TryShowMainWindow(
Form form,
bool exitRequested,
bool shutdownComplete)
{
if (form == null)
throw new ArgumentNullException(nameof(form));
if (exitRequested || shutdownComplete || form.IsDisposed || form.Disposing)
return false;

form.TopMost = true;
form.ShowInTaskbar = true;
form.Show();
form.WindowState = FormWindowState.Normal;
form.BringToFront();
form.Activate();
form.TopMost = false;
return true;
}

internal bool TryShowMainWindow()
{
return TryShowMainWindow(this, _exitRequested, _shutdownComplete);
}

internal static void ArrangeProfileDetails(
Panel host,
Control state,
Expand Down Expand Up @@ -2211,8 +2248,7 @@ protected override async void OnLoad(EventArgs e)
if (Settings.Default.AutoMinimize)
{
WindowState = FormWindowState.Minimized;
ShowInTaskbar = false;
Hide();
ConcealFromTaskbar(this);
}

if (lstProfiles.Items.ContainsKey(PrivilegedSettingsStore.LastProfile))
Expand Down Expand Up @@ -2332,8 +2368,7 @@ private void OnFormClosing(object sender, FormClosingEventArgs e)
if (e.CloseReason == CloseReason.UserClosing && !_exitRequested)
{
e.Cancel = true;
ShowInTaskbar = false;
Hide();
ConcealFromTaskbar(this);
return;
}

Expand All @@ -2342,8 +2377,11 @@ private void OnFormClosing(object sender, FormClosingEventArgs e)

e.Cancel = true;
_exitRequested = true;
trayIcon.Visible = false;
Enabled = false;
ShowInTaskbar = false;
// The form is about to be disposed, so hiding it is sufficient to
// remove its taskbar button. Avoid changing ShowInTaskbar here: it
// would recreate the handle and briefly restart handle-bound work.
Hide();
CloseOwnedFormsForShutdown();
BeginShutdownAndClose();
Expand Down Expand Up @@ -2404,21 +2442,14 @@ private async void CompleteShutdownAndCloseAsync()
/// <param name="e">An EventArgs that contains the event data.</param>
private void OnFormShow(object sender, EventArgs e)
{
TopMost = true;
ShowInTaskbar = true;
Show();
WindowState = FormWindowState.Normal;
BringToFront();
Activate();
TopMost = false;
TryShowMainWindow();
}

private void OnFormMinimize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
ShowInTaskbar = false;
Hide();
ConcealFromTaskbar(this);
}
}

Expand Down
Loading