mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Set startup state in WindowsStore build
This commit is contained in:
parent
a2e98147f2
commit
0c79efe263
3 changed files with 70 additions and 12 deletions
|
@ -258,6 +258,7 @@ public enum RegionCaptureType
|
|||
|
||||
public enum StartupTaskState
|
||||
{
|
||||
Error = -1,
|
||||
Disabled = 0,
|
||||
DisabledByUser = 1,
|
||||
Enabled = 2
|
||||
|
|
|
@ -113,14 +113,32 @@ private void UpdateControls()
|
|||
cbTrayLeftClickAction.SelectedIndex = (int)Program.Settings.TrayLeftClickAction;
|
||||
cbTrayMiddleClickAction.SelectedIndex = (int)Program.Settings.TrayMiddleClickAction;
|
||||
|
||||
#if STEAM
|
||||
#if STEAM || WindowsStore
|
||||
cbCheckPreReleaseUpdates.Visible = false;
|
||||
#else
|
||||
cbCheckPreReleaseUpdates.Checked = Program.Settings.CheckPreReleaseUpdates;
|
||||
#endif
|
||||
|
||||
// Integration
|
||||
#if WindowsStore
|
||||
cbStartWithWindows.Enabled = false;
|
||||
StartupTaskState state = StartupTaskState.Error;
|
||||
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
state = IntegrationHelpers.CheckStartupWindowsStore();
|
||||
},
|
||||
() =>
|
||||
{
|
||||
if (!IsDisposed && state != StartupTaskState.Error && state != StartupTaskState.DisabledByUser)
|
||||
{
|
||||
cbStartWithWindows.Enabled = true;
|
||||
cbStartWithWindows.Checked = state == StartupTaskState.Enabled;
|
||||
}
|
||||
});
|
||||
#else
|
||||
cbStartWithWindows.Checked = IntegrationHelpers.CheckStartupShortcut();
|
||||
#endif
|
||||
cbShellContextMenu.Checked = IntegrationHelpers.CheckShellContextMenuButton();
|
||||
cbSendToMenu.Checked = IntegrationHelpers.CheckSendToMenuButton();
|
||||
cbChromeExtensionSupport.Checked = IntegrationHelpers.CheckChromeExtensionSupport();
|
||||
|
@ -360,7 +378,11 @@ private void cbStartWithWindows_CheckedChanged(object sender, EventArgs e)
|
|||
{
|
||||
if (ready)
|
||||
{
|
||||
#if WindowsStore
|
||||
IntegrationHelpers.SetStartupWindowsStore(cbStartWithWindows.Checked);
|
||||
#else
|
||||
IntegrationHelpers.CreateStartupShortcut(cbStartWithWindows.Checked);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,16 +80,51 @@ public static bool CheckStartupShortcut()
|
|||
return ShortcutHelpers.CheckShortcut(Environment.SpecialFolder.Startup, StartupTargetPath);
|
||||
}
|
||||
|
||||
public static bool CreateStartupShortcut(bool create)
|
||||
public static StartupTaskState CheckStartupWindowsStore()
|
||||
{
|
||||
#if WindowsStore
|
||||
return CreateStartupShortcutWindowsStore(create);
|
||||
#else
|
||||
return ShortcutHelpers.SetShortcut(create, Environment.SpecialFolder.Startup, StartupTargetPath, "-silent");
|
||||
#endif
|
||||
string filepath = Helpers.GetAbsolutePath("ShareX_DesktopBridgeHelper.exe");
|
||||
|
||||
if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath))
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = filepath,
|
||||
Arguments = "-StartupState",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
Process process = Process.Start(startInfo);
|
||||
|
||||
if (process.WaitForExit(5000))
|
||||
{
|
||||
int code = process.ExitCode;
|
||||
|
||||
DebugHelper.WriteLine($"CheckStartupWindowsStore: {code}");
|
||||
|
||||
if (code > -1)
|
||||
{
|
||||
return (StartupTaskState)code;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show("Startup state check failed:\r\n" + e.ToString(), "ShareX");
|
||||
}
|
||||
}
|
||||
|
||||
return StartupTaskState.Error;
|
||||
}
|
||||
|
||||
private static bool CreateStartupShortcutWindowsStore(bool create)
|
||||
public static bool CreateStartupShortcut(bool create)
|
||||
{
|
||||
return ShortcutHelpers.SetShortcut(create, Environment.SpecialFolder.Startup, StartupTargetPath, "-silent");
|
||||
}
|
||||
|
||||
public static bool SetStartupWindowsStore(bool enable)
|
||||
{
|
||||
string filepath = Helpers.GetAbsolutePath("ShareX_DesktopBridgeHelper.exe");
|
||||
|
||||
|
@ -99,7 +134,7 @@ private static bool CreateStartupShortcutWindowsStore(bool create)
|
|||
{
|
||||
string argument;
|
||||
|
||||
if (create)
|
||||
if (enable)
|
||||
{
|
||||
argument = "-StartupEnable";
|
||||
}
|
||||
|
@ -122,15 +157,16 @@ private static bool CreateStartupShortcutWindowsStore(bool create)
|
|||
{
|
||||
int code = process.ExitCode;
|
||||
|
||||
DebugHelper.WriteLine($"CreateStartupWindowsStore: {code}");
|
||||
|
||||
if (code > -1)
|
||||
{
|
||||
StartupTaskState state = (StartupTaskState)code;
|
||||
|
||||
if (create)
|
||||
if (enable)
|
||||
{
|
||||
if (state == StartupTaskState.Enabled)
|
||||
{
|
||||
MessageBox.Show("Startup successfully enabled.", "ShareX");
|
||||
return true;
|
||||
}
|
||||
else if (state == StartupTaskState.DisabledByUser)
|
||||
|
@ -141,7 +177,6 @@ private static bool CreateStartupShortcutWindowsStore(bool create)
|
|||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Startup successfully disabled.", "ShareX");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue