Skip to content

Commit

Permalink
✨ UI 样式变更; 加载条新位置
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiHuaDou committed Dec 14, 2023
1 parent 3984b5a commit a4b6f4d
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 87 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### RC3 (开发中)

+ :arrow_up: 迁移到 .NET 6
+ :bug: 修正下载功能的错误
+ :lipstick: 修正主界面样式
+ :sparkles: 添加网页搜索功能
Expand Down
2 changes: 2 additions & 0 deletions 极简浏览器.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Global
{42E299F0-DF88-406B-9E7E-C9FA72DF8064}.Debug|x86.ActiveCfg = Debug|x86
{42E299F0-DF88-406B-9E7E-C9FA72DF8064}.Debug|x86.Build.0 = Debug|x86
{42E299F0-DF88-406B-9E7E-C9FA72DF8064}.Release|x86.ActiveCfg = Release|x86
{42E299F0-DF88-406B-9E7E-C9FA72DF8064}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -45,6 +46,7 @@ Global
{31456189-B7AF-4812-A5E2-219A82969B9A} = {7B586149-A468-46FC-9EC3-7D08428F07E4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_NeutralResourcesLanguage = zh-CN
SolutionGuid = {1E289B48-8FD0-40ED-8347-C0F117C44526}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions 极简浏览器/Api/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

namespace 极简浏览器.Api;

public enum UIThemes
{
AeroNormalColor = 0, Aero2NormalColor,
LunaNormalColor, LunaHomestead, LunaMetallic, RoyaleNormalColor,
Classic
}

public class Config
{
// 静态对象
public const string mainPageDefault = "about:blank";
public const string searchEngineDefault = "https://cn.bing.com/search?q=";
public const string UIThemeDefault = "Aero.NormalColor";
public const string UANormal = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Easy/3.4.7.2 Chrome/87.0.4280.141 Safari/537.36";
public const string UACheated = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Easy/3.4.7.2 Chrome/114.0.0.0 Safari/537.36";

// 实例对象
private string mainPage = mainPageDefault;
private string searchEngine = searchEngineDefault;

Expand All @@ -28,4 +38,7 @@ public string SearchEngine

[DefaultValue(false)]
public bool CheatUA { get; set; }

[DefaultValue(UIThemes.AeroNormalColor)]
public UIThemes UITheme { get; set; }
}
2 changes: 1 addition & 1 deletion 极简浏览器/Api/DataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Read( )

public void Save( )
{
XmlStream.Seek(0, SeekOrigin.Begin);
XmlStream.SetLength(0);
XmlSerializer serializer = new(typeof(List<T>));
serializer.Serialize(XmlStream, Content);
}
Expand Down
10 changes: 8 additions & 2 deletions 极简浏览器/Api/Formatter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace 极简浏览器.Api;

Expand All @@ -9,9 +11,9 @@ namespace 极简浏览器.Api;
///
public static class Formatter
{
public static string Format(string code)
public static async Task<string> FormatAsync(string code, CancellationToken token)
{
code = HTMLFormatter.Format(code);
code = await Task.Run(( ) => HTMLFormatter.Format(code), token);
return code;
}
}
Expand Down Expand Up @@ -80,6 +82,10 @@ private static string[] FormatLines(string[] lines)
if (prevTag is TagType.Begin) indent++;
prevTag = TagType.Begin;
}
else if (Regex.IsMatch(lines[i], "<\\/(script|style|meta|link|br)>"))
{
prevTag = TagType.End;
}
else if (Regex.IsMatch(lines[i], "<\\/.+>"))
{
if (prevTag is not TagType.Begin or TagType.Code)
Expand Down
9 changes: 1 addition & 8 deletions 极简浏览器/App.xaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<Application x:Class="极简浏览器.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:极简浏览器"
DispatcherUnhandledException="ExceptionOpen"
Exit="AppExit"
ShutdownMode="OnLastWindowClose"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary x:Key="MainResourceDictionary">
<ResourceDictionary.MergedDictionaries>
<!--For Win9x: <ResourceDictionary Source="/PresentationFramework.Classic,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Classic.xaml" />-->
<!--For WinXP: <ResourceDictionary Source="/PresentationFramework.Luna,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Luna.NormalColor.xaml" />-->
<!--For Win8+: <ResourceDictionary Source="/PresentationFramework.Aero2,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Aero2.NormalColor.xaml" />-->

<!--For my dear Windows Vista/7-->
<ResourceDictionary Source="/PresentationFramework.Aero,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml" />
<ResourceDictionary Source="/Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
18 changes: 17 additions & 1 deletion 极简浏览器/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,26 @@ protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

RuntimeFix( );
Bookmark = new(FilePath.BookMark);
History = new(FilePath.History);
Setting = new(FilePath.Setting, false);

Resources.MergedDictionaries.Add(new ResourceDictionary( )
{
Source = new Uri(Setting.Content[0].UITheme switch
{
UIThemes.Classic => "pack://application:,,,/PresentationFramework.Classic,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Classic.xaml",
UIThemes.LunaNormalColor => "pack://application:,,,/PresentationFramework.Luna,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Luna.NormalColor.xaml",
UIThemes.LunaHomestead => "pack://application:,,,/PresentationFramework.Luna,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Luna.Homestead.xaml",
UIThemes.LunaMetallic => "pack://application:,,,/PresentationFramework.Luna,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Luna.Metallic.xaml",
UIThemes.RoyaleNormalColor => "pack://application:,,,/PresentationFramework.Luna,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Royale.NormalColor.xaml",
UIThemes.AeroNormalColor => "pack://application:,,,/PresentationFramework.Aero,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml",
UIThemes.Aero2NormalColor => "pack://application:,,,/PresentationFramework.Aero2,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Aero2.NormalColor.xaml",
_ => "pack://application:,,,/PresentationFramework.Aero,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,ProcessorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml",
})
});

RuntimeFix( );
Instance.Init( );
}

Expand Down
29 changes: 23 additions & 6 deletions 极简浏览器/Dialog/Setting.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Window x:Class="极简浏览器.Setting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="设置"
MinWidth="400"
Closing="WindowClosing"
Loaded="WindowLoaded"
ResizeMode="NoResize"
SizeToContent="WidthAndHeight">
<Grid Margin="10">
Expand All @@ -17,11 +18,11 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Height="34" Margin="0,0,0,5" Content="主页:" />
<TextBox x:Name="MainPageBox"
Grid.Column="1"
Height="35"
Margin="0,0,0,5"
TextWrapping="NoWrap" />
<Label Grid.Row="1"
Expand All @@ -30,23 +31,39 @@
Content="搜索引擎:" />
<TextBox x:Name="SearchEngineBox"
Grid.Row="1" Grid.Column="1"
Height="35"
Margin="0,5,0,5"
TextWrapping="NoWrap" ToolTip="使用%1替代搜索关键词" />
<Label Grid.Row="2"
Height="34"
Margin="0,5,0,5"
Content="界面主题:" />
<StackPanel Grid.Row="2" Grid.Column="1" Margin="0,5,0,5">
<ComboBox x:Name="UIThemeBox" SelectedIndex="5" SelectionChanged="UIThemeBoxSelectionChanged">
<System:String>Classic</System:String>
<System:String>Luna.NormalColor</System:String>
<System:String>Luna.Homestead</System:String>
<System:String>Luna.Metallic</System:String>
<System:String>Royale.NormalColor</System:String>
<System:String>Aero.NormalColor</System:String>
<System:String>Aero2.NormalColor</System:String>
</ComboBox>
<Label x:Name="UIThemeText" />
</StackPanel>
<CheckBox x:Name="CheckUaBox"
Grid.Row="2" Grid.ColumnSpan="2"
Grid.Row="3" Grid.ColumnSpan="2"
Margin="0,5,0,5"
Content="伪装 User-Agent" />
<StackPanel Grid.Row="3" Grid.ColumnSpan="2" Orientation="Horizontal">
<StackPanel Grid.Row="4" Grid.ColumnSpan="2" Orientation="Horizontal">
<Button x:Name="CacheButton"
Margin="0,5,5,5" Padding="30,3"
Click="ClearCache" Content="清除缓存" />
<Button x:Name="LogButton"
Margin="5,5,0,5" Padding="30,3"
Click="ClearLog" Content="清除日志" />
</StackPanel>

<Button x:Name="OKButton"
Grid.Row="4" Grid.Column="1"
Grid.Row="5" Grid.Column="1"
Margin="0,5,0,0" Padding="30,3" HorizontalAlignment="Right"
Click="OKClick" Content="确定" />
</Grid>
Expand Down
20 changes: 15 additions & 5 deletions 极简浏览器/Dialog/Setting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.ComponentModel;
using System.IO;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using 极简浏览器.Api;
using 极简浏览器.Resources;

namespace 极简浏览器;

Expand All @@ -13,6 +14,7 @@ public Setting( )
MainPageBox.Text = App.Setting.Content[0].MainPage;
SearchEngineBox.Text = App.Setting.Content[0].SearchEngine;
CheckUaBox.IsChecked = App.Setting.Content[0].CheatUA;
UIThemeBox.SelectedIndex = (int) App.Setting.Content[0].UITheme;
}

private void OKClick(object o, RoutedEventArgs e)
Expand All @@ -23,8 +25,10 @@ private void OKClick(object o, RoutedEventArgs e)
{
MainPage = MainPageBox.Text,
SearchEngine = SearchEngineBox.Text,
CheatUA = (bool) CheckUaBox.IsChecked
CheatUA = (bool) CheckUaBox.IsChecked,
UITheme = (UIThemes) UIThemeBox.SelectedIndex
});
App.Setting.Save( );
Close( );
}

Expand All @@ -42,6 +46,12 @@ private void ClearLog(object o, RoutedEventArgs e)
{ try { File.Delete(file); } catch { } }
}

private void WindowClosing(object o, CancelEventArgs e)
=> App.Setting.Save( );
private void UIThemeBoxSelectionChanged(object o, SelectionChangedEventArgs e)
{
if (UIThemeText is null || UIThemeBox is null) return;
UIThemeText.Content = GuiText.ResourceManager.GetString($"UITheme.{UIThemeBox.SelectedValue}");
}

private void WindowLoaded(object o, RoutedEventArgs e)
=> UIThemeBoxSelectionChanged(null, null);
}
30 changes: 15 additions & 15 deletions 极简浏览器/Dialog/WebSource.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Windows;
Expand All @@ -7,10 +8,10 @@

namespace 极简浏览器;

public partial class WebSource : Window
public partial class WebSource : Window, IDisposable
{
private int Id;
private Thread formatter;
private CancellationTokenSource cancellation = new( );

public WebSource(int id)
{
Expand All @@ -22,19 +23,12 @@ public WebSource(int id)
private async void RefreshSource(object o, RoutedEventArgs e)
=> sourceBox.Text = await Instance.PageSourceAsync(Id);

private void FormatSource(object o, RoutedEventArgs e)
private async void FormatSource(object o, RoutedEventArgs e)
{
formatter = new((source) =>
{
string result = Formatter.Format((string) source);
Dispatcher.Invoke(( ) =>
{
sourceBox.Text = result;
formatButton.IsEnabled = true;
});
});
formatter.Start(sourceBox.Text);
formatButton.IsEnabled = false;
string result = await Formatter.FormatAsync(sourceBox.Text, cancellation.Token);
sourceBox.Text = result;
formatButton.IsEnabled = true;
}

private void SaveSource(object o, RoutedEventArgs e)
Expand All @@ -51,5 +45,11 @@ private void SaveSource(object o, RoutedEventArgs e)
}

private void WindowClosing(object o, CancelEventArgs e)
=> formatter?.Abort( );
=> cancellation.Cancel( );

public void Dispose( )
{
cancellation.Dispose( );
GC.SuppressFinalize(this);
}
}
Loading

0 comments on commit a4b6f4d

Please sign in to comment.