Configure startup async

This commit is contained in:
Jaex 2017-06-05 18:11:43 +03:00
parent 1967af93d9
commit b7cb663a29
2 changed files with 39 additions and 20 deletions

View file

@ -336,6 +336,43 @@ private void CheckWindowsStoreStartup()
});
}
private void ConfigureWindowsStoreStartup()
{
if (cbStartWithWindows.Enabled)
{
cbStartWithWindows.Enabled = false;
lblWindowsStoreStartupStatus.Text = "Configuring startup...";
lblWindowsStoreStartupStatus.Visible = true;
bool enable = cbStartWithWindows.Checked;
StartupTaskState state = StartupTaskState.Error;
TaskEx.Run(() =>
{
state = IntegrationHelpers.ConfigureStartupWindowsStore(enable);
},
() =>
{
if (!IsDisposed)
{
if (state == StartupTaskState.Error)
{
lblWindowsStoreStartupStatus.Text = "Startup configuration failed. Check debug log for more info.";
}
else if (state == StartupTaskState.DisabledByUser)
{
lblWindowsStoreStartupStatus.Text = "The startup has been disabled by the user.";
}
else
{
lblWindowsStoreStartupStatus.Visible = false;
cbStartWithWindows.Enabled = true;
}
}
});
}
}
#region General
private void cbShowTray_CheckedChanged(object sender, EventArgs e)
@ -414,25 +451,7 @@ private void cbStartWithWindows_CheckedChanged(object sender, EventArgs e)
if (ready)
{
#if WindowsStore
if (cbStartWithWindows.Enabled)
{
StartupTaskState state = IntegrationHelpers.SetStartupWindowsStore(cbStartWithWindows.Checked);
if (state == StartupTaskState.Error)
{
lblWindowsStoreStartupStatus.Text = "Startup configuration failed. Check debug log for more info.";
lblWindowsStoreStartupStatus.Visible = true;
}
else if (state == StartupTaskState.DisabledByUser)
{
lblWindowsStoreStartupStatus.Text = "The startup has been disabled by the user.";
lblWindowsStoreStartupStatus.Visible = true;
}
else
{
lblWindowsStoreStartupStatus.Visible = false;
}
}
ConfigureWindowsStoreStartup();
#else
IntegrationHelpers.CreateStartupShortcut(cbStartWithWindows.Checked);
#endif

View file

@ -170,7 +170,7 @@ public static StartupTaskState CheckStartupWindowsStore()
return RunStartupWindowsStore("-StartupState", "Startup state check");
}
public static StartupTaskState SetStartupWindowsStore(bool enable)
public static StartupTaskState ConfigureStartupWindowsStore(bool enable)
{
return RunStartupWindowsStore(enable ? "-StartupEnable" : "-StartupDisable", "Startup configuration");
}