Skip to content

Commit dac8297

Browse files
committed
feat: Start options
1 parent ffc9ce8 commit dac8297

5 files changed

Lines changed: 140 additions & 1 deletion

File tree

‎ActionPanel.cs‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ public static Flyout CreateSettings(string currentTheme, string currentBackdropT
199199
Action<Flyout>? onShowAi = null, Action<Flyout>? onShowPrompts = null,
200200
string? currentNoteStyle = null, Action<string>? onNoteStyleSelected = null,
201201
string? currentFont = null, Action<string>? onFontSelected = null,
202-
Action? onResetPassword = null, Action? onResetNotes = null)
202+
Action? onResetPassword = null, Action? onResetNotes = null,
203+
bool startWithWindows = false, bool startMinimized = false,
204+
Action<bool>? onStartWithWindowsToggled = null, Action<bool>? onStartMinimizedToggled = null)
203205
{
204206
var flyout = new Flyout();
205207
flyout.FlyoutPresenterStyle = CreateFlyoutPresenterStyle(260, 320);
@@ -333,6 +335,17 @@ static string FindLabel((string key, string label)[] items, string current)
333335
panel.Children.Add(langBtn);
334336
}
335337

338+
// Startup
339+
if (onStartWithWindowsToggled != null || onStartMinimizedToggled != null)
340+
{
341+
var startupBtn = CreateNavigateButton(Lang.T("startup"), () =>
342+
ShowStartupSubPanel(flyout, startWithWindows, startMinimized,
343+
onStartWithWindowsToggled, onStartMinimizedToggled));
344+
startupBtn.Tag = Lang.T("startup") + " Démarrage Startup Windows Tray";
345+
allButtons.Add(startupBtn);
346+
panel.Children.Add(startupBtn);
347+
}
348+
336349
// Reset
337350
if (onResetPassword != null || onResetNotes != null)
338351
{
@@ -693,6 +706,52 @@ internal static Button CreateButton(ActionItem action, Action handler)
693706

694707
// ── Reset sub-panel ──
695708

709+
private static void ShowStartupSubPanel(Flyout flyout,
710+
bool startWithWindows, bool startMinimized,
711+
Action<bool>? onStartWithWindowsToggled, Action<bool>? onStartMinimizedToggled)
712+
{
713+
var panel = CreateSubPanelWithHeader(Lang.T("startup"), () =>
714+
{
715+
flyout.Hide();
716+
});
717+
718+
if (onStartWithWindowsToggled != null)
719+
{
720+
var swBtn = CreateCheckItem(Lang.T("startup_with_windows"), startWithWindows, () =>
721+
{
722+
startWithWindows = !startWithWindows;
723+
onStartWithWindowsToggled(startWithWindows);
724+
ShowStartupSubPanel(flyout, startWithWindows, startMinimized,
725+
onStartWithWindowsToggled, onStartMinimizedToggled);
726+
});
727+
panel.Children.Add(swBtn);
728+
}
729+
730+
if (onStartMinimizedToggled != null)
731+
{
732+
var smBtn = CreateCheckItem(Lang.T("startup_minimized"), startMinimized, () =>
733+
{
734+
startMinimized = !startMinimized;
735+
onStartMinimizedToggled(startMinimized);
736+
ShowStartupSubPanel(flyout, startWithWindows, startMinimized,
737+
onStartWithWindowsToggled, onStartMinimizedToggled);
738+
});
739+
panel.Children.Add(smBtn);
740+
741+
var desc = new TextBlock
742+
{
743+
Text = Lang.T("startup_minimized_desc"),
744+
FontSize = 11,
745+
Opacity = 0.45,
746+
Margin = new Thickness(12, 0, 8, 4),
747+
TextWrapping = TextWrapping.Wrap
748+
};
749+
panel.Children.Add(desc);
750+
}
751+
752+
flyout.Content = panel;
753+
}
754+
696755
private static void ShowResetSubPanel(Flyout flyout, Action? onResetPassword, Action? onResetNotes)
697756
{
698757
var panel = CreateSubPanelWithHeader(Lang.T("reset"), () =>

‎App.xaml.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
1919
ReminderService.Initialize();
2020
_window = new MainWindow();
2121
_window.Activate();
22+
23+
if (AppSettings.LoadStartMinimized())
24+
{
25+
var appWindow = _window.AppWindow;
26+
appWindow.Hide();
27+
}
2228
}
2329

2430
public static void ApplyFontResource(string font)

‎AppSettings.cs‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,62 @@ public static void SaveNoteStyle(string style)
176176
MergeAndSaveSettings(new Dictionary<string, object> { ["noteStyle"] = style });
177177
}
178178

179+
// ── Startup ─────────────────────────────────────────────────
180+
181+
private const string StartupRegistryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
182+
private const string StartupRegistryName = "NoteUI";
183+
184+
public static bool LoadStartWithWindows()
185+
{
186+
try
187+
{
188+
using var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(StartupRegistryKey, false);
189+
return key?.GetValue(StartupRegistryName) is string;
190+
}
191+
catch { return false; }
192+
}
193+
194+
public static void SaveStartWithWindows(bool enabled)
195+
{
196+
try
197+
{
198+
using var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(StartupRegistryKey, true);
199+
if (key == null) return;
200+
if (enabled)
201+
{
202+
var exePath = Environment.ProcessPath ?? "";
203+
if (!string.IsNullOrEmpty(exePath))
204+
key.SetValue(StartupRegistryName, $"\"{exePath}\"");
205+
}
206+
else
207+
{
208+
key.DeleteValue(StartupRegistryName, false);
209+
}
210+
}
211+
catch { }
212+
}
213+
214+
public static bool LoadStartMinimized()
215+
{
216+
try
217+
{
218+
if (File.Exists(SettingsPath))
219+
{
220+
var json = File.ReadAllText(SettingsPath);
221+
var doc = JsonDocument.Parse(json);
222+
if (doc.RootElement.TryGetProperty("startMinimized", out var prop))
223+
return prop.GetBoolean();
224+
}
225+
}
226+
catch { }
227+
return false;
228+
}
229+
230+
public static void SaveStartMinimized(bool enabled)
231+
{
232+
MergeAndSaveSettings(new Dictionary<string, object> { ["startMinimized"] = enabled });
233+
}
234+
179235
// ── Slash commands ──────────────────────────────────────────
180236

181237
public static bool LoadSlashEnabled()

‎Lang.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ public static class Lang
267267
["passwords_dont_match"] = "Passwords don't match",
268268
["wrong_password"] = "Wrong password",
269269
["password_required"] = "Password required",
270+
["startup"] = "Startup",
271+
["startup_with_windows"] = "Start with Windows",
272+
["startup_minimized"] = "Start minimized",
273+
["startup_minimized_desc"] = "Start in system tray only",
270274
["reset"] = "Reset",
271275
["reset_password"] = "Lock password",
272276
["reset_notes"] = "Notes list",
@@ -597,6 +601,10 @@ public static class Lang
597601
["passwords_dont_match"] = "Les mots de passe ne correspondent pas",
598602
["wrong_password"] = "Mauvais mot de passe",
599603
["password_required"] = "Mot de passe requis",
604+
["startup"] = "Démarrage",
605+
["startup_with_windows"] = "Démarrer avec Windows",
606+
["startup_minimized"] = "Démarrer minimisé",
607+
["startup_minimized_desc"] = "Démarrer dans le system tray seulement",
600608
["reset"] = "Réinitialiser",
601609
["reset_password"] = "Mot de passe verrouillage",
602610
["reset_notes"] = "Liste de notes",

‎MainWindow.xaml.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,16 @@ private void Settings_Click(object sender, RoutedEventArgs e)
11991199
_openNoteWindows.Clear();
12001200
_notes.DeleteAllNotes();
12011201
RefreshCurrentView();
1202+
},
1203+
startWithWindows: AppSettings.LoadStartWithWindows(),
1204+
startMinimized: AppSettings.LoadStartMinimized(),
1205+
onStartWithWindowsToggled: enabled =>
1206+
{
1207+
AppSettings.SaveStartWithWindows(enabled);
1208+
},
1209+
onStartMinimizedToggled: enabled =>
1210+
{
1211+
AppSettings.SaveStartMinimized(enabled);
12021212
});
12031213

12041214
flyout.Placement = Microsoft.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.TopEdgeAlignedRight;

0 commit comments

Comments
 (0)