[BUG] Microsoft Store Autostart not working (#131), version 1.0.23.0

This commit is contained in:
Markus Hofknecht 2021-10-23 11:59:39 +02:00
parent 8a6101d329
commit f5234bcec3
5 changed files with 102 additions and 86 deletions

View file

@ -10,7 +10,7 @@
<Identity
Name="49543SystemTrayMenu.SystemTrayMenu"
Publisher="CN=5884501C-92ED-45DE-9508-9D987C314243"
Version="1.0.22.0" />
Version="1.0.23.0" />
<Properties>
<DisplayName>SystemTrayMenu</DisplayName>

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.22.2")]
[assembly: AssemblyFileVersion("1.0.22.2")]
[assembly: AssemblyVersion("1.0.23.0")]
[assembly: AssemblyFileVersion("1.0.23.0")]

View file

@ -286,7 +286,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.22000.194" />
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.22000.196" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@ -297,6 +297,9 @@
<Folder Include="Packaging\AppPackages\" />
</ItemGroup>
<ItemGroup>
<None Update="Package.appxmanifest">
<SubType>Designer</SubType>
</None>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View file

@ -264,6 +264,7 @@ namespace SystemTrayMenu.UserInterface
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.colorDialog = new System.Windows.Forms.ColorDialog();
this.buttonAddTaskManagerStartupTask = new System.Windows.Forms.Button();
this.tableLayoutPanelMain.SuspendLayout();
this.tabControl.SuspendLayout();
this.tabPageGeneral.SuspendLayout();
@ -666,7 +667,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxAutostart.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxAutostart.Name = "groupBoxAutostart";
this.groupBoxAutostart.Padding = new System.Windows.Forms.Padding(3, 6, 3, 6);
this.groupBoxAutostart.Size = new System.Drawing.Size(400, 53);
this.groupBoxAutostart.Size = new System.Drawing.Size(400, 59);
this.groupBoxAutostart.TabIndex = 0;
this.groupBoxAutostart.TabStop = false;
this.groupBoxAutostart.Text = "groupBoxAutostart";
@ -675,15 +676,18 @@ namespace SystemTrayMenu.UserInterface
//
this.tableLayoutPanelAutostart.AutoSize = true;
this.tableLayoutPanelAutostart.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableLayoutPanelAutostart.ColumnCount = 1;
this.tableLayoutPanelAutostart.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanelAutostart.ColumnCount = 3;
this.tableLayoutPanelAutostart.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelAutostart.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelAutostart.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanelAutostart.Controls.Add(this.buttonAddTaskManagerStartupTask, 0, 0);
this.tableLayoutPanelAutostart.Controls.Add(this.checkBoxAutostart, 0, 0);
this.tableLayoutPanelAutostart.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanelAutostart.Location = new System.Drawing.Point(3, 22);
this.tableLayoutPanelAutostart.Name = "tableLayoutPanelAutostart";
this.tableLayoutPanelAutostart.RowCount = 1;
this.tableLayoutPanelAutostart.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanelAutostart.Size = new System.Drawing.Size(394, 25);
this.tableLayoutPanelAutostart.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanelAutostart.Size = new System.Drawing.Size(394, 31);
this.tableLayoutPanelAutostart.TabIndex = 0;
//
// checkBoxAutostart
@ -692,7 +696,7 @@ namespace SystemTrayMenu.UserInterface
this.checkBoxAutostart.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkBoxAutostart.Location = new System.Drawing.Point(3, 3);
this.checkBoxAutostart.Name = "checkBoxAutostart";
this.checkBoxAutostart.Size = new System.Drawing.Size(388, 19);
this.checkBoxAutostart.Size = new System.Drawing.Size(126, 25);
this.checkBoxAutostart.TabIndex = 0;
this.checkBoxAutostart.Text = "checkBoxAutostart";
this.checkBoxAutostart.UseVisualStyleBackColor = true;
@ -702,7 +706,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxHotkey.AutoSize = true;
this.groupBoxHotkey.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBoxHotkey.Controls.Add(this.tableLayoutPanelHotkey);
this.groupBoxHotkey.Location = new System.Drawing.Point(3, 289);
this.groupBoxHotkey.Location = new System.Drawing.Point(3, 295);
this.groupBoxHotkey.MaximumSize = new System.Drawing.Size(400, 0);
this.groupBoxHotkey.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxHotkey.Name = "groupBoxHotkey";
@ -755,7 +759,7 @@ namespace SystemTrayMenu.UserInterface
this.groupBoxLanguage.AutoSize = true;
this.groupBoxLanguage.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBoxLanguage.Controls.Add(this.tableLayoutPanelLanguage);
this.groupBoxLanguage.Location = new System.Drawing.Point(3, 354);
this.groupBoxLanguage.Location = new System.Drawing.Point(3, 360);
this.groupBoxLanguage.MaximumSize = new System.Drawing.Size(400, 0);
this.groupBoxLanguage.MinimumSize = new System.Drawing.Size(400, 0);
this.groupBoxLanguage.Name = "groupBoxLanguage";
@ -3649,6 +3653,19 @@ namespace SystemTrayMenu.UserInterface
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// buttonAddTaskManagerStartupTask
//
this.buttonAddTaskManagerStartupTask.AutoSize = true;
this.buttonAddTaskManagerStartupTask.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.buttonAddTaskManagerStartupTask.Location = new System.Drawing.Point(135, 3);
this.buttonAddTaskManagerStartupTask.MinimumSize = new System.Drawing.Size(75, 23);
this.buttonAddTaskManagerStartupTask.Name = "buttonAddTaskManagerStartupTask";
this.buttonAddTaskManagerStartupTask.Size = new System.Drawing.Size(204, 25);
this.buttonAddTaskManagerStartupTask.TabIndex = 1;
this.buttonAddTaskManagerStartupTask.Text = "buttonAddTaskManagerStartupTask";
this.buttonAddTaskManagerStartupTask.UseVisualStyleBackColor = true;
this.buttonAddTaskManagerStartupTask.Click += new System.EventHandler(this.ButtonAddTaskManagerStartupTask_Click);
//
// SettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@ -4104,5 +4121,6 @@ namespace SystemTrayMenu.UserInterface
private System.Windows.Forms.TextBox textBoxColorIconsDarkMode;
private System.Windows.Forms.CheckBox checkBoxPossibilityToSelectFolderByWindowsContextMenu;
private System.Windows.Forms.Button buttonOpenFolder;
private System.Windows.Forms.Button buttonAddTaskManagerStartupTask;
}
}

View file

@ -119,6 +119,7 @@ namespace SystemTrayMenu.UserInterface
buttonOpenAssemblyLocation.Text = Translator.GetText("Open the assembly location");
groupBoxAutostart.Text = Translator.GetText("Autostart");
checkBoxAutostart.Text = Translator.GetText("Launch on startup");
buttonAddTaskManagerStartupTask.Text = Translator.GetText("Launch on startup");
groupBoxHotkey.Text = Translator.GetText("Hotkey");
buttonHotkeyDefault.Text = Translator.GetText("Default");
groupBoxLanguage.Text = Translator.GetText("Language");
@ -203,14 +204,19 @@ namespace SystemTrayMenu.UserInterface
InitializeAutostart();
void InitializeAutostart()
{
checkBoxAutostart.Checked =
Settings.Default.IsAutostartActivated;
bool useStartupTask = false;
#if RELEASEPACKAGE
if (Settings.Default.IsAutostartActivated)
{
checkBoxAutostart.Enabled = false;
}
useStartupTask = true;
#endif
if (useStartupTask)
{
checkBoxAutostart.Visible = false;
}
else
{
buttonAddTaskManagerStartupTask.Visible = false;
checkBoxAutostart.Checked = Settings.Default.IsAutostartActivated;
}
}
InitializeHotkey();
@ -568,84 +574,21 @@ namespace SystemTrayMenu.UserInterface
private void ButtonOk_Click(object sender, EventArgs e)
{
Settings.Default.UseIconFromRootFolder =
checkBoxUseIconFromRootFolder.Checked;
_ = SaveAutostartAsync().Wait(8000);
async Task SaveAutostartAsync()
{
bool useStartupTask = false;
#if RELEASEPACKAGE
useStartupTask = true;
Settings.Default.UseIconFromRootFolder = checkBoxUseIconFromRootFolder.Checked;
#if !RELEASEPACKAGE
SaveAutostartRegistryEntry();
#endif
if (checkBoxAutostart.Checked)
{
if (useStartupTask)
{
// Pass the task ID you specified in the appxmanifest file
StartupTask startupTask = await StartupTask.GetAsync("MyStartupId");
Log.Info($"Autostart {startupTask.State}.");
switch (startupTask.State)
{
case StartupTaskState.Enabled:
break;
case StartupTaskState.Disabled:
// Task is disabled but can be enabled.
StartupTaskState newState = await startupTask.RequestEnableAsync();
break;
case StartupTaskState.DisabledByUser:
Log.Info($"Please enable autostart via Task Manager.");
break;
case StartupTaskState.DisabledByPolicy:
Log.Info($"Autostart disabled by policy. Please add autostart manually, see issue #131");
break;
case StartupTaskState.EnabledByPolicy:
default:
break;
}
}
else
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue(
Assembly.GetExecutingAssembly().GetName().Name,
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}
Settings.Default.IsAutostartActivated = true;
}
else
{
if (useStartupTask)
{
// when added by StartupTask, then only possible to disable autostart via Task Manager.
}
else
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
key.DeleteValue("SystemTrayMenu", false);
}
Settings.Default.IsAutostartActivated = false;
}
}
SaveHotkey();
void SaveHotkey()
{
Settings.Default.HotKey =
new KeysConverter().ConvertToInvariantString(
Settings.Default.HotKey = new KeysConverter().ConvertToInvariantString(
textBoxHotkey.Hotkey | textBoxHotkey.HotkeyModifiers);
}
SaveLanguage();
void SaveLanguage()
{
Settings.Default.CurrentCultureInfoName =
comboBoxLanguage.SelectedValue.ToString();
Settings.Default.CurrentCultureInfoName = comboBoxLanguage.SelectedValue.ToString();
Translator.Initialize();
}
@ -689,6 +632,58 @@ namespace SystemTrayMenu.UserInterface
Close();
}
private void SaveAutostartRegistryEntry()
{
if (checkBoxAutostart.Checked)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue(
Assembly.GetExecutingAssembly().GetName().Name,
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Settings.Default.IsAutostartActivated = true;
}
else
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
key.DeleteValue("SystemTrayMenu", false);
Settings.Default.IsAutostartActivated = false;
}
}
private void ButtonAddTaskManagerStartupTask_Click(object sender, EventArgs e)
{
_ = AddStartUpAsync();
static async Task AddStartUpAsync()
{
// Pass the task ID you specified in the appxmanifest file
StartupTask startupTask = await StartupTask.GetAsync("MyStartupId");
Log.Info($"Autostart {startupTask.State}.");
switch (startupTask.State)
{
case StartupTaskState.Enabled:
break;
case StartupTaskState.Disabled:
// Task is disabled but can be enabled.
StartupTaskState newState = await startupTask.RequestEnableAsync();
break;
case StartupTaskState.DisabledByUser:
Log.Info($"Please enable autostart via Task Manager.");
break;
case StartupTaskState.DisabledByPolicy:
Log.Info($"Autostart disabled by policy. Please add autostart manually, see issue #131");
break;
case StartupTaskState.EnabledByPolicy:
default:
break;
}
}
}
private void ButtonHotkeyDefault_Click(object sender, EventArgs e)
{
textBoxHotkey.SetHotkey("Ctrl+LWin");