diff --git a/src/StarfaceOutlookSync/Models/UserSettings.cs b/src/StarfaceOutlookSync/Models/UserSettings.cs index 2ed19bf1..ce22524d 100644 --- a/src/StarfaceOutlookSync/Models/UserSettings.cs +++ b/src/StarfaceOutlookSync/Models/UserSettings.cs @@ -7,6 +7,7 @@ namespace StarfaceOutlookSync.Models public class UserSettings { public bool StartMinimized { get; set; } = false; + public bool SyncOnStart { get; set; } = false; private static readonly string SettingsFile = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), diff --git a/src/StarfaceOutlookSync/UI/MainForm.cs b/src/StarfaceOutlookSync/UI/MainForm.cs index 902aa8c3..774fede1 100644 --- a/src/StarfaceOutlookSync/UI/MainForm.cs +++ b/src/StarfaceOutlookSync/UI/MainForm.cs @@ -22,6 +22,7 @@ namespace StarfaceOutlookSync.UI private StatusStrip _statusBar; private ToolStripStatusLabel _statusLabel; private Timer _autoSyncTimer; + private volatile bool _syncRunning = false; public MainForm() { @@ -38,6 +39,21 @@ namespace StarfaceOutlookSync.UI ShowInTaskbar = false; Visible = false; } + + // Beim Start automatisch synchronisieren + if (settings.SyncOnStart) + { + _ = SyncAllProfiles(); + } + } + + private async Task SyncAllProfiles() + { + var profiles = _profileManager.GetProfiles().Where(p => p.Enabled).ToList(); + foreach (var profile in profiles) + { + await RunSync(profile); + } } protected override void SetVisibleCore(bool value) @@ -158,6 +174,7 @@ namespace StarfaceOutlookSync.UI if (profiles.Any(p => p.Enabled)) _trayMenu.Items.Add("-"); + _trayMenu.Items.Add("Ueber", null, (s, e) => ShowAbout()); _trayMenu.Items.Add("Beenden", null, (s, e) => ExitApplication()); } @@ -318,6 +335,13 @@ namespace StarfaceOutlookSync.UI private async Task RunSync(SyncProfile profile) { + if (_syncRunning) + { + SetStatus("Sync laeuft bereits, bitte warten..."); + return; + } + + _syncRunning = true; try { SetStatus($"Synchronisiere '{profile.Name}'..."); @@ -340,6 +364,10 @@ namespace StarfaceOutlookSync.UI ex.Message, ToolTipIcon.Error); SetStatus($"Fehler: {ex.Message}"); } + finally + { + _syncRunning = false; + } } private void SetStatus(string text) diff --git a/src/StarfaceOutlookSync/UI/SettingsForm.cs b/src/StarfaceOutlookSync/UI/SettingsForm.cs index 29874f0a..592e37e3 100644 --- a/src/StarfaceOutlookSync/UI/SettingsForm.cs +++ b/src/StarfaceOutlookSync/UI/SettingsForm.cs @@ -6,7 +6,7 @@ namespace StarfaceOutlookSync.UI { public class SettingsForm : Form { - private CheckBox _chkStartMinimized; + private CheckBox _chkStartMinimized, _chkSyncOnStart; private Button _btnSave, _btnCancel; private readonly UserSettings _settings; @@ -19,7 +19,7 @@ namespace StarfaceOutlookSync.UI private void InitializeComponent() { Text = "Einstellungen"; - Size = new Size(350, 180); + Size = new Size(350, 210); FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; @@ -33,20 +33,27 @@ namespace StarfaceOutlookSync.UI Checked = _settings.StartMinimized }; + _chkSyncOnStart = new CheckBox + { + Text = "Beim Start automatisch synchronisieren", + Left = 20, Top = 52, AutoSize = true, + Checked = _settings.SyncOnStart + }; + _btnSave = new Button { - Text = "Speichern", Left = 80, Top = 100, Width = 85, Height = 28, + Text = "Speichern", Left = 80, Top = 130, Width = 85, Height = 28, DialogResult = DialogResult.None }; _btnSave.Click += (s, e) => Save(); _btnCancel = new Button { - Text = "Abbrechen", Left = 174, Top = 100, Width = 85, Height = 28, + Text = "Abbrechen", Left = 174, Top = 130, Width = 85, Height = 28, DialogResult = DialogResult.Cancel }; - Controls.AddRange(new Control[] { _chkStartMinimized, _btnSave, _btnCancel }); + Controls.AddRange(new Control[] { _chkStartMinimized, _chkSyncOnStart, _btnSave, _btnCancel }); AcceptButton = _btnSave; CancelButton = _btnCancel; } @@ -54,6 +61,7 @@ namespace StarfaceOutlookSync.UI private void Save() { _settings.StartMinimized = _chkStartMinimized.Checked; + _settings.SyncOnStart = _chkSyncOnStart.Checked; _settings.Save(); DialogResult = DialogResult.OK; Close();