Возможность автозагрузки

This commit is contained in:
Danil Kislov
2019-03-26 09:51:01 +03:00
parent 5909336523
commit b5c85fa304
8 changed files with 93 additions and 39 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.33
1.0.34
+5
View File
@@ -9,6 +9,8 @@ using JiraTimeBot.TaskTime;
using JiraTimeBot.UI.Tray;
using System;
using System.Windows.Forms;
using JiraTimeBot.UI;
using JiraTimeBot.UI.Startup;
namespace JiraTimeBot.DI
{
@@ -53,6 +55,9 @@ namespace JiraTimeBot.DI
_builder.Register(c => new Job(c.Resolve<IAllMercurialProviders>(), c.Resolve<ITaskTimeCalculator>(), c.Resolve<ILog>())).AsSelf();
_builder.RegisterType<AutoStartUp>().AsSelf().AsImplementedInterfaces();
_builder.RegisterType<frmSettings>().AsSelf().AsImplementedInterfaces();
var container = _builder.Build();
return container;
}
+1
View File
@@ -116,6 +116,7 @@
<Compile Include="UI\frmSettings.Designer.cs">
<DependentUpon>frmSettings.cs</DependentUpon>
</Compile>
<Compile Include="UI\Startup\AutoStartUp.cs" />
<Compile Include="UI\Tray\SingleInstance.cs" />
<Compile Include="UI\Tray\ITrayMenu.cs" />
<Compile Include="UI\Tray\RestoreFromTray.cs" />
+3 -3
View File
@@ -26,6 +26,6 @@ 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.33")]
[assembly: AssemblyFileVersion("1.0.33")]
[assembly: AssemblyInformationalVersion("1.0.33")]
[assembly: AssemblyVersion("1.0.34")]
[assembly: AssemblyFileVersion("1.0.34")]
[assembly: AssemblyInformationalVersion("1.0.34")]
+27
View File
@@ -0,0 +1,27 @@
using System.Windows.Forms;
using Microsoft.Win32;
namespace JiraTimeBot.UI.Startup
{
public class AutoStartUp
{
readonly RegistryKey _rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public bool Get()
{
return _rkApp.GetValue(Application.ProductName) != null;
}
public void Set(bool autoStart)
{
if (autoStart)
{
_rkApp.SetValue(Application.ProductName, Application.ExecutablePath);
}
else
{
_rkApp.DeleteValue(Application.ProductName, false);
}
}
}
}
+3 -2
View File
@@ -11,6 +11,7 @@ using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using JiraTimeBot.UI.Startup;
// This is the code for your desktop app.
// Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
@@ -69,7 +70,7 @@ namespace JiraTimeBot.UI
_settingsWindowShow = () =>
{
var frmSettings = new frmSettings();
var frmSettings = new frmSettings(_container.Resolve<AutoStartUp>());
frmSettings.ShowDialog(this);
};
_settingsErrorReporter = msg => MessageBox.Show(msg, "Загрузка настроек", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);;
@@ -201,7 +202,7 @@ namespace JiraTimeBot.UI
private void btnSettings_Click(object sender, EventArgs e)
{
var frm = new frmSettings();
var frm = _container.Resolve<frmSettings>();
frm.ShowDialog();
PrintStartMessage();
+16 -3
View File
@@ -48,6 +48,7 @@
this.txtJQL = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.txtTimeControlTask = new System.Windows.Forms.TextBox();
this.chkAutostart = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// label5
@@ -152,7 +153,7 @@
// chkAddComments
//
this.chkAddComments.AutoSize = true;
this.chkAddComments.Location = new System.Drawing.Point(56, 267);
this.chkAddComments.Location = new System.Drawing.Point(56, 277);
this.chkAddComments.Name = "chkAddComments";
this.chkAddComments.Size = new System.Drawing.Size(133, 17);
this.chkAddComments.TabIndex = 31;
@@ -161,7 +162,7 @@
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(72, 299);
this.btnSave.Location = new System.Drawing.Point(72, 310);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(75, 23);
this.btnSave.TabIndex = 32;
@@ -223,11 +224,22 @@
this.txtTimeControlTask.Size = new System.Drawing.Size(99, 20);
this.txtTimeControlTask.TabIndex = 38;
//
// chkAutostart
//
this.chkAutostart.AutoSize = true;
this.chkAutostart.Location = new System.Drawing.Point(56, 254);
this.chkAutostart.Name = "chkAutostart";
this.chkAutostart.Size = new System.Drawing.Size(96, 17);
this.chkAutostart.TabIndex = 40;
this.chkAutostart.Text = "Автозагрузка";
this.chkAutostart.UseVisualStyleBackColor = true;
//
// frmSettings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(243, 334);
this.ClientSize = new System.Drawing.Size(243, 342);
this.Controls.Add(this.chkAutostart);
this.Controls.Add(this.label8);
this.Controls.Add(this.txtTimeControlTask);
this.Controls.Add(this.label7);
@@ -281,5 +293,6 @@
private System.Windows.Forms.TextBox txtJQL;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox txtTimeControlTask;
private System.Windows.Forms.CheckBox chkAutostart;
}
}
+8 -1
View File
@@ -1,13 +1,17 @@
using System;
using System.Windows.Forms;
using JiraTimeBot.Configuration;
using JiraTimeBot.UI.Startup;
namespace JiraTimeBot.UI
{
public partial class frmSettings : Form
{
public frmSettings()
private readonly AutoStartUp _autoStart;
public frmSettings(AutoStartUp autoStart)
{
_autoStart = autoStart;
InitializeComponent();
}
@@ -18,6 +22,8 @@ namespace JiraTimeBot.UI
{
SetSettings(settings);
}
chkAutostart.Checked = _autoStart.Get();
}
private void SetSettings(Settings settings)
@@ -67,6 +73,7 @@ namespace JiraTimeBot.UI
{
var settings = ReadSettingsAndLock();
settings.Save();
_autoStart.Set(chkAutostart.Checked);
MessageBox.Show("Настройки сохранены.");