mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Initial kinda working implementation.
This commit is contained in:
parent
f8ea055e4b
commit
07f48747eb
8 changed files with 116 additions and 82 deletions
|
@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.Properties;
|
||||
using ShareX.StartupManagers;
|
||||
using ShareX.UploadersLib;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
@ -40,6 +41,8 @@ public partial class ApplicationSettingsForm : Form
|
|||
private bool ready;
|
||||
private string lastPersonalPath;
|
||||
|
||||
private IStartupManager startupManager = StartupManagerFactory.GetStartupManager();
|
||||
|
||||
public ApplicationSettingsForm()
|
||||
{
|
||||
InitializeControls();
|
||||
|
@ -70,12 +73,10 @@ private void SettingsForm_FormClosed(object sender, FormClosedEventArgs e)
|
|||
|
||||
private void tttvMain_TabChanged(TabPage tabPage)
|
||||
{
|
||||
#if WindowsStore
|
||||
if (tabPage == tpIntegration)
|
||||
{
|
||||
CheckWindowsStoreStartup();
|
||||
UpdateStartWithWindows();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitializeControls()
|
||||
|
@ -131,13 +132,11 @@ private void UpdateControls()
|
|||
|
||||
// Integration
|
||||
#if WindowsStore
|
||||
cbStartWithWindows.Enabled = false;
|
||||
cbShellContextMenu.Visible = false;
|
||||
cbSendToMenu.Visible = false;
|
||||
gbChrome.Visible = false;
|
||||
gbFirefox.Visible = false;
|
||||
#else
|
||||
cbStartWithWindows.Checked = IntegrationHelpers.CheckStartupShortcut();
|
||||
cbShellContextMenu.Checked = IntegrationHelpers.CheckShellContextMenuButton();
|
||||
cbSendToMenu.Checked = IntegrationHelpers.CheckSendToMenuButton();
|
||||
cbChromeExtensionSupport.Checked = IntegrationHelpers.CheckChromeExtensionSupport();
|
||||
|
@ -146,6 +145,8 @@ private void UpdateControls()
|
|||
btnFirefoxOpenAddonPage.Enabled = cbFirefoxAddonSupport.Checked;
|
||||
#endif
|
||||
|
||||
UpdateStartWithWindows();
|
||||
|
||||
#if STEAM
|
||||
cbSteamShowInApp.Checked = IntegrationHelpers.CheckSteamShowInApp();
|
||||
#else
|
||||
|
@ -251,6 +252,17 @@ private void ChangeLanguage(SupportedLanguage language)
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdateStartWithWindows()
|
||||
{
|
||||
StartupTaskState state = startupManager.State;
|
||||
cbStartWithWindows.Checked = state == StartupTaskState.Enabled;
|
||||
if (state == StartupTaskState.DisabledByUser)
|
||||
{
|
||||
cbStartWithWindows.Enabled = false;
|
||||
lblWindowsStoreStartupStatus.Text = Resources.ApplicationSettingsForm_lblWindowsStoreStartupStatus_DisabledByUser;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateProxyControls()
|
||||
{
|
||||
switch (Program.Settings.ProxySettings.ProxyMethod)
|
||||
|
@ -301,78 +313,6 @@ private void UpdateExportButton()
|
|||
btnExport.Enabled = Program.Settings.ExportSettings || Program.Settings.ExportHistory || Program.Settings.ExportLogs;
|
||||
}
|
||||
|
||||
private void CheckWindowsStoreStartup()
|
||||
{
|
||||
if (cbStartWithWindows.Enabled) return;
|
||||
|
||||
lblWindowsStoreStartupStatus.Text = "Checking startup state...";
|
||||
lblWindowsStoreStartupStatus.Visible = true;
|
||||
|
||||
StartupTaskState state = StartupTaskState.Error;
|
||||
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
state = IntegrationHelpers.CheckStartupWindowsStore();
|
||||
},
|
||||
() =>
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (state == StartupTaskState.Error)
|
||||
{
|
||||
lblWindowsStoreStartupStatus.Text = "Startup state check 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.Checked = state == StartupTaskState.Enabled;
|
||||
cbStartWithWindows.Enabled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -450,11 +390,7 @@ private void cbStartWithWindows_CheckedChanged(object sender, EventArgs e)
|
|||
{
|
||||
if (ready)
|
||||
{
|
||||
#if WindowsStore
|
||||
ConfigureWindowsStoreStartup();
|
||||
#else
|
||||
IntegrationHelpers.CreateStartupShortcut(cbStartWithWindows.Checked);
|
||||
#endif
|
||||
startupManager.State = cbStartWithWindows.Checked ? StartupTaskState.Enabled : StartupTaskState.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
ShareX/Properties/Resources.Designer.cs
generated
9
ShareX/Properties/Resources.Designer.cs
generated
|
@ -474,6 +474,15 @@ public static string ApplicationSettingsForm_cbSteamShowInApp_CheckedChanged_For
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Startup has been disabled in Task Manager..
|
||||
/// </summary>
|
||||
public static string ApplicationSettingsForm_lblWindowsStoreStartupStatus_DisabledByUser {
|
||||
get {
|
||||
return ResourceManager.GetString("ApplicationSettingsForm_lblWindowsStoreStartupStatus_DisabledByUser", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
|
|
|
@ -960,4 +960,7 @@ Middle click to close</value>
|
|||
<data name="QRCodeForm_InputTextToEncode" xml:space="preserve">
|
||||
<value>Input text to encode</value>
|
||||
</data>
|
||||
<data name="ApplicationSettingsForm_lblWindowsStoreStartupStatus_DisabledByUser" xml:space="preserve">
|
||||
<value>Startup has been disabled in Task Manager.</value>
|
||||
</data>
|
||||
</root>
|
|
@ -309,6 +309,10 @@
|
|||
</Compile>
|
||||
<Compile Include="LanguageHelper.cs" />
|
||||
<Compile Include="RecentTaskManager.cs" />
|
||||
<Compile Include="StartupManagers\CentennialStartupManager.cs" />
|
||||
<Compile Include="StartupManagers\DesktopStartupManager.cs" />
|
||||
<Compile Include="StartupManagers\IStartupManager.cs" />
|
||||
<Compile Include="StartupManagers\StartupManagerFactory.cs" />
|
||||
<Compile Include="TaskHelpers.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
30
ShareX/StartupManagers/CentennialStartupManager.cs
Normal file
30
ShareX/StartupManagers/CentennialStartupManager.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ShareX.StartupManagers
|
||||
{
|
||||
class CentennialStartupManager : IStartupManager
|
||||
{
|
||||
public StartupTaskState State
|
||||
{
|
||||
get => IntegrationHelpers.CheckStartupWindowsStore();
|
||||
set
|
||||
{
|
||||
bool enable;
|
||||
if (value == StartupTaskState.Enabled)
|
||||
{
|
||||
enable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
enable = false;
|
||||
}
|
||||
|
||||
IntegrationHelpers.ConfigureStartupWindowsStore(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
ShareX/StartupManagers/DesktopStartupManager.cs
Normal file
22
ShareX/StartupManagers/DesktopStartupManager.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ShareX.StartupManagers
|
||||
{
|
||||
class DesktopStartupManager : IStartupManager
|
||||
{
|
||||
public StartupTaskState State
|
||||
{
|
||||
get => IntegrationHelpers.CheckStartupShortcut() ? StartupTaskState.Enabled : StartupTaskState.Disabled;
|
||||
set
|
||||
{
|
||||
if (value == StartupTaskState.Disabled)
|
||||
IntegrationHelpers.CreateStartupShortcut(false);
|
||||
else if (value == StartupTaskState.Enabled)
|
||||
IntegrationHelpers.CreateStartupShortcut(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
ShareX/StartupManagers/IStartupManager.cs
Normal file
11
ShareX/StartupManagers/IStartupManager.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace ShareX.StartupManagers
|
||||
{
|
||||
interface IStartupManager
|
||||
{
|
||||
StartupTaskState State
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
19
ShareX/StartupManagers/StartupManagerFactory.cs
Normal file
19
ShareX/StartupManagers/StartupManagerFactory.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ShareX.StartupManagers
|
||||
{
|
||||
class StartupManagerFactory
|
||||
{
|
||||
static public IStartupManager GetStartupManager()
|
||||
{
|
||||
#if WindowsStore
|
||||
return new CentennialStartupManager();
|
||||
#else
|
||||
return new DesktopStartupManager();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue