Skip to content

Commit 103effb

Browse files
committed
refactor(homepage): add tab state persistence and fix multiple issues
- auto run decode/format action when page loads with non-empty input - add null check for process main module in settings page - reduce balloon tip display time for API server startup - add tab selection state save/restore functionality - fix nullable warning for selected tab variable
1 parent c3c2508 commit 103effb

7 files changed

Lines changed: 64 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.
44

55
---
66

7+
## [2.3.1] - 2026-07-06
8+
9+
### Added
10+
- **Tab State Persistence** - Return to previously selected tab after navigating back from a tool
11+
- **Auto-Execute on Entry** - Automatically process content when entering pages
12+
- Base64 to Image: auto-generates image if textbox contains content
13+
- JSON Format: auto-formats if textbox contains content
14+
15+
### Changed
16+
- **Notification Duration** - Reduced popup notification time from 3 seconds to 1 second
17+
18+
### Fixed
19+
- **Compilation Warnings** - Resolved null reference warnings in multiple pages
20+
- HomePage: nullable type annotations for TabItem variables
21+
- Base64ImagePage/JsonFormatPage: named parameters for null arguments
22+
- SettingsPage: null check for MainModule before accessing
23+
24+
---
25+
726
## [2.3.0] - 2026-06-25
827

928
### Added

MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private void InitializeNotifyIcon()
130130

131131
if (_apiServerEnabled)
132132
{
133-
_notifyIcon.ShowBalloonTip(3000, "Toolbox", "API Server starting...", ToolTipIcon.Info);
133+
_notifyIcon.ShowBalloonTip(1000, "Toolbox", "API Server starting...", ToolTipIcon.Info);
134134
}
135135
}
136136

@@ -155,7 +155,7 @@ private async void InitializeApiServer()
155155
{
156156
if (_notifyIcon != null)
157157
{
158-
_notifyIcon.ShowBalloonTip(3000, "Toolbox", $"API Server started on port {port}", ToolTipIcon.Info);
158+
_notifyIcon.ShowBalloonTip(1000, "Toolbox", $"API Server started on port {port}", ToolTipIcon.Info);
159159
}
160160
}
161161
else

Pages/Base64ImagePage.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ private void LoadState()
5757
{
5858
InputText.Text = state.GetValueOrDefault("InputText", string.Empty);
5959
}
60+
if (!string.IsNullOrWhiteSpace(InputText.Text))
61+
{
62+
Decode_Click(sender: null, e: null);
63+
}
6064
}
6165

6266
private void Decode_Click(object sender, RoutedEventArgs e)

Pages/HomePage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@
158158
IsUndoEnabled="True"
159159
UndoLimit="20"/>
160160

161-
<TabControl Style="{StaticResource ModernTabControl}"
162-
Margin="20,60,20,20">
161+
<TabControl x:Name="MainTabControl" Style="{StaticResource ModernTabControl}"
162+
Margin="20,60,20,20" SelectionChanged="MainTabControl_SelectionChanged">
163163

164164
<!-- 编码工具 -->
165165
<TabItem Header="{x:Static resources:Strings.CategoryEncoding}" Tag="&#xf121;" Style="{StaticResource ModernTabItem}">

Pages/HomePage.xaml.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Windows.Media;
66
using System.Windows.Media.Media3D;
77
using System.Windows.Threading;
8+
using DevTools.Helpers;
89

910
namespace DevTools.Pages
1011
{
@@ -19,13 +20,36 @@ public HomePage()
1920
// Initialize search debounce timer
2021
_searchTimer = new System.Windows.Threading.DispatcherTimer
2122
{
22-
Interval = TimeSpan.FromMilliseconds(300) // 300ms delay
23+
Interval = TimeSpan.FromMilliseconds(300)
2324
};
2425
_searchTimer.Tick += (s, e) =>
2526
{
2627
_searchTimer.Stop();
2728
FilterTools(SearchBox.Text);
2829
};
30+
31+
LoadTabState();
32+
}
33+
34+
private void LoadTabState()
35+
{
36+
var state = PageStateManager.GetPageState(this);
37+
if (state != null && state.TryGetValue("SelectedTabIndex", out var indexStr) && int.TryParse(indexStr, out var index))
38+
{
39+
if (index >= 0 && index < MainTabControl.Items.Count)
40+
{
41+
MainTabControl.SelectedIndex = index;
42+
}
43+
}
44+
}
45+
46+
private void MainTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
47+
{
48+
var state = new Dictionary<string, string>
49+
{
50+
{ "SelectedTabIndex", MainTabControl.SelectedIndex.ToString() }
51+
};
52+
PageStateManager.SavePageState(this, state);
2953
}
3054

3155
private void BtnMd5_Click(object sender, RoutedEventArgs e)
@@ -121,7 +145,7 @@ private void FilterTools(string searchText)
121145

122146
// Get TabControl and current selected tab first
123147
var tabControl = FindVisualChildren<System.Windows.Controls.TabControl>(this).FirstOrDefault();
124-
TabItem currentSelectedTab = tabControl?.SelectedItem as TabItem;
148+
var currentSelectedTab = tabControl?.SelectedItem as TabItem;
125149

126150
// Filter buttons in all tabs
127151
var allButtons = FindVisualChildren<System.Windows.Controls.Button>(this);
@@ -142,8 +166,8 @@ private void FilterTools(string searchText)
142166
}
143167

144168
// Filter tabs and find first visible tab
145-
var allTabs = FindVisualChildren<TabItem>(this);
146-
TabItem firstVisibleTab = null;
169+
var allTabs = FindVisualChildren<TabItem>(this).ToList();
170+
TabItem? firstVisibleTab = null;
147171

148172
foreach (var tab in allTabs)
149173
{

Pages/JsonFormatPage.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ private void LoadState()
5353
InputText.Text = state.GetValueOrDefault("InputText", string.Empty);
5454
_lastFormattedJson = state.GetValueOrDefault("LastFormattedJson", string.Empty);
5555
}
56+
if (!string.IsNullOrWhiteSpace(InputText.Text))
57+
{
58+
Format_Click(sender: null, e: null);
59+
}
5660
}
5761

5862
private async void Format_Click(object sender, RoutedEventArgs e)

Pages/SettingsPage.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@ private void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEv
9898

9999
// Restart to apply changes
100100
var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
101-
var startInfo = new System.Diagnostics.ProcessStartInfo(currentProcess.MainModule.FileName);
102-
System.Diagnostics.Process.Start(startInfo);
101+
if (currentProcess.MainModule != null)
102+
{
103+
var startInfo = new System.Diagnostics.ProcessStartInfo(currentProcess.MainModule.FileName);
104+
System.Diagnostics.Process.Start(startInfo);
105+
}
103106
Application.Current.Shutdown();
104107
}
105108
}

0 commit comments

Comments
 (0)