Skip to content

Commit 54d4b87

Browse files
committed
Update WIP 0.9.4
1 parent c03fbbe commit 54d4b87

11 files changed

Lines changed: 625 additions & 217 deletions

source/App.xaml.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ public partial class App : System.Windows.Application
1212

1313
protected override void OnStartup(StartupEventArgs e)
1414
{
15-
// Check for existing instance
1615
const string mutexName = "TeeHee_SingleInstance_Mutex";
1716
_mutex = new Mutex(true, mutexName, out bool createdNew);
1817

1918
if (!createdNew)
2019
{
21-
// Another instance is already running
2220
System.Windows.MessageBox.Show(
2321
"TeeHee is already running.\n\nCheck your system tray for the TeeHee icon.",
2422
"TeeHee Already Running",
@@ -33,8 +31,28 @@ protected override void OnStartup(StartupEventArgs e)
3331

3432
System.Diagnostics.Debug.WriteLine("App starting...");
3533

34+
// Detect settings location before loading
35+
var locationResult = TriggerDatabase.Instance.DetectSettingsLocation();
36+
37+
if (locationResult == SettingsLocationResult.NotFound)
38+
{
39+
// Show dialog to let user choose location (hide cancel on first launch)
40+
var dialog = new SettingsLocationDialog();
41+
dialog.ShowCancelButton = false;
42+
if (dialog.ShowDialog() == true)
43+
{
44+
TriggerDatabase.Instance.SetSettingsLocation(dialog.SelectedMode, dialog.CustomPath);
45+
}
46+
else
47+
{
48+
// User cancelled - default to AppData
49+
TriggerDatabase.Instance.SetSettingsLocation(SettingsLocationMode.AppData);
50+
}
51+
}
52+
3653
TriggerDatabase.Instance.Load();
3754
System.Diagnostics.Debug.WriteLine($"Loaded {TriggerDatabase.Instance.Triggers.Count} triggers");
55+
System.Diagnostics.Debug.WriteLine($"Settings location: {TriggerDatabase.SettingsPath}");
3856

3957
_keyboardHook = new KeyboardHook();
4058
_keyboardHook.IsEnabled = TriggerDatabase.Instance.Settings.IsEnabled;
@@ -47,7 +65,8 @@ protected override void OnStartup(StartupEventArgs e)
4765
_trayIconManager.OnToggleRequested += ToggleEnabled;
4866
_trayIconManager.Initialize();
4967
System.Diagnostics.Debug.WriteLine("Tray icon initialized");
50-
ShowMainWindow();
68+
69+
ShowMainWindow();
5170
}
5271

5372
public void RefreshKeyboardHook()
@@ -112,4 +131,4 @@ protected override void OnExit(ExitEventArgs e)
112131
_mutex?.Dispose();
113132
base.OnExit(e);
114133
}
115-
}
134+
}

source/InfoDialog.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ private void Close_Click(object sender, RoutedEventArgs e)
1313
{
1414
Close();
1515
}
16-
}
16+
}

source/MainWindow.xaml

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,17 @@
378378
Style="{StaticResource ModernCheckBox}"
379379
Checked="MinimizeToTrayCheckBox_Changed"
380380
Unchecked="MinimizeToTrayCheckBox_Changed"
381-
Margin="0,8,0,0"/>
381+
Margin="0,8,0,0"/>
382382
</StackPanel>
383383
</Border>
384384

385+
386+
387+
388+
389+
390+
391+
385392
<!-- Speed Section -->
386393
<TextBlock Text="Trigger Speed"
387394
FontSize="11"
@@ -433,7 +440,31 @@
433440
</Border>
434441

435442
<!-- Data Section -->
436-
<TextBlock Text="Data Management"
443+
<TextBlock Text="Database (Triggers)"
444+
FontSize="11"
445+
FontWeight="SemiBold"
446+
Foreground="{DynamicResource TextMutedBrush}"
447+
Margin="0,0,0,10"/>
448+
449+
<Border Background="{DynamicResource SurfaceBrush}"
450+
BorderBrush="{DynamicResource BorderBrush}"
451+
BorderThickness="1"
452+
CornerRadius="8"
453+
Padding="16"
454+
Margin="0,0,0,20">
455+
<StackPanel Orientation="Horizontal">
456+
<Button Content="Export"
457+
Style="{StaticResource SecondaryButton}"
458+
Click="Export_Click"
459+
Margin="0,0,10,0"/>
460+
<Button Content="Import"
461+
Style="{StaticResource SecondaryButton}"
462+
Click="Import_Click"/>
463+
</StackPanel>
464+
</Border>
465+
466+
<!-- Settings and Database Location Section -->
467+
<TextBlock Text="Settings and Database Location"
437468
FontSize="11"
438469
FontWeight="SemiBold"
439470
Foreground="{DynamicResource TextMutedBrush}"
@@ -446,35 +477,29 @@
446477
Padding="16"
447478
Margin="0,0,0,20">
448479
<StackPanel>
449-
<StackPanel Orientation="Horizontal" Margin="0,0,0,16">
450-
<Button Content="Export"
451-
Style="{StaticResource SecondaryButton}"
452-
Click="Export_Click"
453-
Margin="0,0,10,0"/>
454-
<Button Content="Import"
455-
Style="{StaticResource SecondaryButton}"
456-
Click="Import_Click"/>
457-
</StackPanel>
480+
<TextBlock Text="Settings file (settings.json)"
481+
Foreground="{DynamicResource TextMutedBrush}"
482+
FontSize="11"
483+
Margin="0,0,0,4"/>
484+
<TextBox x:Name="SettingsPathTextBox"
485+
Style="{StaticResource ModernTextBox}"
486+
IsReadOnly="True"
487+
FontSize="11"
488+
Margin="0,0,0,12"/>
458489

459-
<TextBlock Text="Database Location"
490+
<TextBlock Text="Database file (triggers.json)"
460491
Foreground="{DynamicResource TextMutedBrush}"
461492
FontSize="11"
462-
FontWeight="SemiBold"
463-
Margin="0,0,0,8"/>
493+
Margin="0,0,0,4"/>
464494
<TextBox x:Name="DatabaseLocationText"
465495
Style="{StaticResource ModernTextBox}"
466496
IsReadOnly="True"
467497
FontSize="11"
468-
Margin="0,0,0,10"/>
469-
<StackPanel Orientation="Horizontal">
470-
<Button Content="Browse"
471-
Style="{StaticResource SecondaryButton}"
472-
Click="BrowseDatabase_Click"
473-
Margin="0,0,10,0"/>
474-
<Button Content="Reset to Default"
475-
Style="{StaticResource SecondaryButton}"
476-
Click="ResetDatabaseLocation_Click"/>
477-
</StackPanel>
498+
Margin="0,0,0,12"/>
499+
500+
<Button Content="Change Location..."
501+
Style="{StaticResource SecondaryButton}"
502+
Click="ChangeLocationButton_Click"/>
478503
</StackPanel>
479504
</Border>
480505
<!-- About Section -->
@@ -498,8 +523,6 @@
498523
<RowDefinition Height="Auto"/>
499524
<RowDefinition Height="Auto"/>
500525
<RowDefinition Height="Auto"/>
501-
<RowDefinition Height="Auto"/>
502-
<RowDefinition Height="Auto"/>
503526
</Grid.RowDefinitions>
504527

505528
<TextBlock Grid.Row="0" Grid.Column="0" Text="Name"
@@ -521,30 +544,6 @@
521544
dayeggpi
522545
</Hyperlink>
523546
</TextBlock>
524-
525-
<TextBlock Grid.Row="3" Grid.Column="0" Text="Database"
526-
Foreground="{DynamicResource TextMutedBrush}" FontSize="12" Margin="0,6,0,0"/>
527-
<TextBox Grid.Row="3" Grid.Column="1"
528-
x:Name="DatabasePathText"
529-
IsReadOnly="True"
530-
Background="Transparent"
531-
BorderThickness="0"
532-
Foreground="{DynamicResource TextBrush}"
533-
FontSize="11"
534-
TextWrapping="Wrap"
535-
Margin="0,6,0,0"/>
536-
537-
<TextBlock Grid.Row="4" Grid.Column="0" Text="Settings"
538-
Foreground="{DynamicResource TextMutedBrush}" FontSize="12" Margin="0,6,0,0"/>
539-
<TextBox Grid.Row="4" Grid.Column="1"
540-
x:Name="SettingsPathText"
541-
IsReadOnly="True"
542-
Background="Transparent"
543-
BorderThickness="0"
544-
Foreground="{DynamicResource TextBrush}"
545-
FontSize="11"
546-
TextWrapping="Wrap"
547-
Margin="0,6,0,0"/>
548547
</Grid>
549548
</Border>
550549

@@ -555,4 +554,4 @@
555554
</TabControl>
556555
</Grid>
557556
</Grid>
558-
</Window>
557+
</Window>

source/MainWindow.xaml.cs

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public partial class MainWindow : Window
1717
public MainWindow()
1818
{
1919
InitializeComponent();
20-
Closing += MainWindow_Closing;
20+
UpdateSettingsPathDisplay();
21+
Closing += MainWindow_Closing;
2122
LoadSettings();
2223
LoadCategories();
2324
RefreshTriggerList();
@@ -26,9 +27,48 @@ public MainWindow()
2627
ApplyTheme(_currentTheme);
2728
}
2829

29-
#region Theme Management
3030

3131

32+
33+
#region Settings management
34+
private void UpdateSettingsPathDisplay()
35+
{
36+
SettingsPathTextBox.Text = TriggerDatabase.SettingsPath;
37+
DatabaseLocationText.Text = TriggerDatabase.DatabasePath;
38+
}
39+
40+
private void ChangeLocationButton_Click(object sender, RoutedEventArgs e)
41+
{
42+
var dialog = new SettingsLocationDialog();
43+
if (dialog.ShowDialog() == true)
44+
{
45+
try
46+
{
47+
TriggerDatabase.Instance.MoveSettingsTo(dialog.SelectedMode, dialog.CustomPath);
48+
UpdateSettingsPathDisplay();
49+
50+
// Refresh trigger list and keyboard hook since database may have moved
51+
RefreshTriggerList();
52+
((App)Application.Current).RefreshKeyboardHook();
53+
54+
var confirmDialog = new ConfirmDialog("Success", $"Location of settings and database files changed successfully.", "OK", false, null);
55+
confirmDialog.Owner = this;
56+
confirmDialog.ShowDialog();
57+
}
58+
catch (Exception ex)
59+
{
60+
var errorDialog = new ConfirmDialog("Error", $"Failed to change location: {ex.Message}", "OK", false, null);
61+
errorDialog.Owner = this;
62+
errorDialog.ShowDialog();
63+
}
64+
}
65+
}
66+
#endregion
67+
68+
69+
70+
#region Closing window management
71+
3272
private void MainWindow_Closing(object? sender, CancelEventArgs e)
3373
{
3474
if (TriggerDatabase.Instance.Settings.MinimizeToTrayOnClose)
@@ -48,6 +88,10 @@ private void MinimizeToTrayCheckBox_Changed(object sender, RoutedEventArgs e)
4888
TriggerDatabase.Instance.Save();
4989
}
5090

91+
#endregion
92+
93+
#region Theme Management
94+
5195
private void Theme_Click(object sender, RoutedEventArgs e)
5296
{
5397
_currentTheme = _currentTheme switch
@@ -357,17 +401,15 @@ private void SettingsScrollViewer_Loaded(object sender, RoutedEventArgs e)
357401
SettingsScrollViewer.ScrollToTop();
358402
}
359403

360-
private void LoadSettings()
361-
{
362-
StartupCheckBox.IsChecked = StartupManager.IsRegisteredForStartup();
363-
SpeedSlider.Value = TriggerDatabase.Instance.Settings.TriggerSpeed;
364-
UpdateSpeedText();
365-
DatabasePathText.Text = TriggerDatabase.DatabasePath;
366-
DatabaseLocationText.Text = TriggerDatabase.DatabasePath;
367-
SettingsPathText.Text = TriggerDatabase.SettingsPath;
368-
369-
_currentTheme = TriggerDatabase.Instance.Settings.Theme ?? "Light";
370-
}
404+
private void LoadSettings()
405+
{
406+
StartupCheckBox.IsChecked = StartupManager.IsRegisteredForStartup();
407+
SpeedSlider.Value = TriggerDatabase.Instance.Settings.TriggerSpeed;
408+
UpdateSpeedText();
409+
DatabaseLocationText.Text = TriggerDatabase.DatabasePath;
410+
411+
_currentTheme = TriggerDatabase.Instance.Settings.Theme ?? "Light";
412+
}
371413

372414
private void StartupCheckBox_Changed(object sender, RoutedEventArgs e)
373415
{
@@ -490,59 +532,6 @@ private void Import_Click(object sender, RoutedEventArgs e)
490532
}
491533
}
492534

493-
private void BrowseDatabase_Click(object sender, RoutedEventArgs e)
494-
{
495-
var dialog = new Microsoft.Win32.SaveFileDialog
496-
{
497-
Filter = "JSON files (*.json)|*.json",
498-
FileName = "triggers.json",
499-
Title = "Choose Database Location"
500-
};
501-
502-
if (dialog.ShowDialog() == true)
503-
{
504-
var oldPath = TriggerDatabase.DatabasePath;
505-
506-
if (System.IO.File.Exists(oldPath) && oldPath != dialog.FileName)
507-
{
508-
if (System.IO.File.Exists(dialog.FileName))
509-
{
510-
var confirmDialog = new ConfirmDialog(
511-
"File Exists",
512-
"A file already exists at this location. Overwrite it?",
513-
"Overwrite",
514-
true);
515-
confirmDialog.Owner = this;
516-
517-
if (confirmDialog.ShowDialog() != true)
518-
return;
519-
520-
System.IO.File.Delete(dialog.FileName);
521-
}
522-
523-
System.IO.File.Move(oldPath, dialog.FileName);
524-
}
525-
526-
TriggerDatabase.Instance.SetCustomDatabasePath(dialog.FileName);
527-
TriggerDatabase.Instance.Load();
528-
RefreshTriggerList();
529-
DatabaseLocationText.Text = dialog.FileName;
530-
DatabasePathText.Text = dialog.FileName;
531-
532-
((App)Application.Current).RefreshKeyboardHook();
533-
}
534-
}
535-
536-
private void ResetDatabaseLocation_Click(object sender, RoutedEventArgs e)
537-
{
538-
TriggerDatabase.Instance.SetCustomDatabasePath(null);
539-
TriggerDatabase.Instance.Load();
540-
RefreshTriggerList();
541-
DatabaseLocationText.Text = TriggerDatabase.DatabasePath;
542-
DatabasePathText.Text = TriggerDatabase.DatabasePath;
543-
544-
((App)Application.Current).RefreshKeyboardHook();
545-
}
546535

547536
private void Author_Click(object sender, RoutedEventArgs e)
548537
{
@@ -564,4 +553,4 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
564553
Hide();
565554
e.Cancel = false;
566555
}
567-
}
556+
}

source/Models/AppSettings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@ public class AppSettings
77
public bool IsEnabled { get; set; } = true;
88
public string? Theme { get; set; } = "Light";
99
public bool MinimizeToTrayOnClose { get; set; } = true;
10+
1011
public int GetDelayMs() => Math.Max(3, 33 - (TriggerSpeed * 3));
1112
}
13+
14+
public enum SettingsLocationMode
15+
{
16+
AppData,
17+
Portable,
18+
Custom
19+
}

0 commit comments

Comments
 (0)