Skip to content

Commit da19794

Browse files
committed
代码优化
1 parent f7ca16a commit da19794

File tree

6 files changed

+22
-29
lines changed

6 files changed

+22
-29
lines changed

App.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace Edge
1616
public partial class App : Application
1717
{
1818
public static List<MainWindow> mainWindows = [];
19-
public static string LatestVersion = null;
2019
public static Settings settings;
2120
public static WebView2 webView2 = new();
2221
public static ObservableCollection<WebViewHistory> Histories = [];

Controls/WebSearch.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void StartSearch(string text, MainWindow mainWindow)
3939
}
4040
else if (Info.ImageDict.TryGetValue(ext, out var _))
4141
{
42-
mainWindow.AddNewTab(new ImageViewer(text), fileInfo.Name);
42+
mainWindow.AddNewTab(new ImageViewer(fileInfo), fileInfo.Name);
4343
}
4444
else
4545
{

MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private LRESULT MainWindowSubClassProc(HWND hWnd, uint Msg, WPARAM wParam, LPARA
184184

185185
TitlebarMenuFlyout.ShowAt(Content, options);
186186
}
187-
return (LRESULT)0;
187+
return new(0);
188188
}
189189
}
190190
return PInvoke.DefSubclassProc(hWnd, Msg, wParam, lParam);

Pages/HomePage.xaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,13 @@
1515
<RowDefinition Height="*"/>
1616
</Grid.RowDefinitions>
1717

18-
<Grid.ColumnDefinitions>
19-
<ColumnDefinition Width="*"/>
20-
<ColumnDefinition Width="5*"/>
21-
<ColumnDefinition Width="*"/>
22-
</Grid.ColumnDefinitions>
23-
24-
<local:BrowserMenuItems Grid.Column="2" HorizontalAlignment="Right"/>
18+
<local:BrowserMenuItems Grid.Column="1" HorizontalAlignment="Right"/>
2519

2620
<local:WebSearch
27-
Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"
21+
Grid.Row="1" VerticalAlignment="Center" Margin="200"
2822
CornerRadius="15" FontSize="18"/>
2923

30-
<GridView Name="View" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center"
24+
<GridView Name="View" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center"
3125
IsItemClickEnabled="True" ItemClick="OpenSuggestWebsite" SelectionMode="Single">
3226

3327
<GridView.ItemContainerStyle>

Pages/ImageViewer.xaml.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ namespace Edge
1919
{
2020
public sealed partial class ImageViewer : Page
2121
{
22-
public FileInfo fileInfo;
22+
public FileInfo info;
2323
public BitmapImage source;
2424

2525
private PrintManager printManager;
2626
private PrintDocument printDocument;
2727
private IPrintDocumentSource printDocumentSource;
2828

29-
public ImageViewer(string filepath)
29+
public ImageViewer(FileInfo fileInfo)
3030
{
3131
this.InitializeComponent();
32-
fileInfo = new(filepath);
33-
source = new(new Uri(filepath));
32+
info = fileInfo;
33+
source = new(new Uri(info.FullName));
3434
image.Source = source;
3535
source.ImageOpened += ImageOpened;
3636
}
@@ -66,7 +66,7 @@ private void PrintDocument_Paginate(object sender, PaginateEventArgs e)
6666

6767
private void PrintManager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
6868
{
69-
PrintTask task = args.Request.CreatePrintTask(fileInfo.Name, PrintTaskSourceRequested);
69+
PrintTask task = args.Request.CreatePrintTask(info.Name, PrintTaskSourceRequested);
7070
}
7171

7272
private void PrintTaskSourceRequested(PrintTaskSourceRequestedArgs args)
@@ -86,17 +86,17 @@ private async void PrintImageRequest(object sender, RoutedEventArgs e)
8686

8787
private void ImageOpened(object sender, RoutedEventArgs e)
8888
{
89-
imageNameBlock.Text = fileInfo.Name;
89+
imageNameBlock.Text = info.Name;
9090
imagePixel.Text = $"{source.PixelWidth} x {source.PixelHeight}";
91-
imageSize.Text = Converters.ToFileSizeString(fileInfo.Length);
91+
imageSize.Text = Converters.ToFileSizeString(info.Length);
9292
}
9393

9494
private async void ImageDeleteRequest(object sender, RoutedEventArgs e)
9595
{
9696
ContentDialogResult result = await deleteDialog.ShowAsync();
9797
if (result == ContentDialogResult.Primary)
9898
{
99-
fileInfo.Delete();
99+
info.Delete();
100100
}
101101
}
102102

@@ -109,7 +109,7 @@ private void ImageRotateRequest(object sender, RoutedEventArgs e)
109109

110110
private void OpenFileLocation(object sender, RoutedEventArgs e)
111111
{
112-
System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{fileInfo.FullName}\"");
112+
System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{info.FullName}\"");
113113
}
114114

115115
private void Image_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
@@ -141,17 +141,17 @@ private void ImageFullScreen(object sender, RoutedEventArgs e)
141141

142142
private void SaveImageAs(object sender, RoutedEventArgs e)
143143
{
144-
string path = Utilities.Win32SaveFile(fileInfo.FullName, this.GetWindowHandle());
144+
string path = Utilities.Win32SaveFile(info.FullName, this.GetWindowHandle());
145145
if (path != string.Empty)
146146
{
147-
fileInfo.CopyTo(path, true);
147+
info.CopyTo(path, true);
148148
}
149149
}
150150

151151
private void CopyFilePath(object sender, RoutedEventArgs e)
152152
{
153153
DataPackage package = new();
154-
package.SetText(fileInfo.FullName);
154+
package.SetText(info.FullName);
155155
Clipboard.SetContent(package);
156156
}
157157

@@ -160,7 +160,7 @@ private async void SetImageAsLockScreen(object sender, RoutedEventArgs e)
160160
if (UserProfilePersonalizationSettings.IsSupported())
161161
{
162162
UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
163-
StorageFile imageFile = await StorageFile.GetFileFromPathAsync(fileInfo.FullName);
163+
StorageFile imageFile = await StorageFile.GetFileFromPathAsync(info.FullName);
164164
await settings.TrySetLockScreenImageAsync(imageFile);
165165
}
166166
}
@@ -170,7 +170,7 @@ private async void SetImageAsWallpaper(object sender, RoutedEventArgs e)
170170
if (UserProfilePersonalizationSettings.IsSupported())
171171
{
172172
UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
173-
StorageFile imageFile = await StorageFile.GetFileFromPathAsync(fileInfo.FullName);
173+
StorageFile imageFile = await StorageFile.GetFileFromPathAsync(info.FullName);
174174
await settings.TrySetWallpaperImageAsync(imageFile);
175175
}
176176
}

Settings/AboutItem.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ private async void CheckUpdate(object sender, RoutedEventArgs e)
2626
{
2727
string fileUri = "https://raw.githubusercontent.com/wtcpython/WinUIEdge/main/Assets/version.txt";
2828
using HttpClient client = new();
29-
App.LatestVersion = await client.GetStringAsync(fileUri);
29+
string version = await client.GetStringAsync(fileUri);
3030

31-
if (App.LatestVersion.CompareTo(appVersion) > 0)
31+
if (version.CompareTo(appVersion) > 0)
3232
{
3333
var builder = new AppNotificationBuilder()
34-
.AddText($"发现新版本:{App.LatestVersion},是否要更新?\n当前版本:{appVersion}")
34+
.AddText($"发现新版本:{version},是否要更新?\n当前版本:{appVersion}")
3535
.AddArgument("Notification", "LaunchReleaseWebsite")
3636
.AddButton(new AppNotificationButton("确定")
3737
.AddArgument("Notification", "LaunchReleaseWebsite"))

0 commit comments

Comments
 (0)