mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Implement settings proxy pane
This commit is contained in:
parent
74825fc27a
commit
f7b2d9df3b
3 changed files with 133 additions and 179 deletions
|
|
@ -0,0 +1,62 @@
|
|||
using System.Net;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
public partial class SettingsPaneProxyViewModel : BaseModel
|
||||
{
|
||||
private readonly Updater _updater;
|
||||
public Settings Settings { get; }
|
||||
|
||||
public SettingsPaneProxyViewModel(Settings settings, Updater updater)
|
||||
{
|
||||
_updater = updater;
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnTestProxyClicked()
|
||||
{
|
||||
var message = TestProxy();
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation(message));
|
||||
}
|
||||
|
||||
private string TestProxy()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Settings.Proxy.Server)) return "serverCantBeEmpty";
|
||||
if (Settings.Proxy.Port <= 0) return "portCantBeEmpty";
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_updater.GitHubRepository);
|
||||
|
||||
if (string.IsNullOrEmpty(Settings.Proxy.UserName) || string.IsNullOrEmpty(Settings.Proxy.Password))
|
||||
{
|
||||
request.Proxy = new WebProxy(Settings.Proxy.Server, Settings.Proxy.Port);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Proxy = new WebProxy(Settings.Proxy.Server, Settings.Proxy.Port)
|
||||
{
|
||||
Credentials = new NetworkCredential(Settings.Proxy.UserName, Settings.Proxy.Password)
|
||||
};
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
return response.StatusCode switch
|
||||
{
|
||||
HttpStatusCode.OK => "proxyIsCorrect",
|
||||
_ => "proxyConnectFailed"
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "proxyConnectFailed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,181 +1,77 @@
|
|||
<Page
|
||||
<ui:Page
|
||||
x:Class="Flow.Launcher.SettingPages.Views.SettingsPaneProxy"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Flow.Launcher.SettingPages.Views"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:ui="http://schemas.modernwpf.com/2019"
|
||||
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
|
||||
xmlns:viewModels="clr-namespace:Flow.Launcher.SettingPages.ViewModels"
|
||||
Title="Proxy"
|
||||
d:DataContext="{d:DesignInstance viewModels:SettingsPaneProxyViewModel}"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<Page.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Resources/SettingWindowStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<CollectionViewSource x:Key="SortedFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}" />
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="pack://application:,,,/Resources/SettingWindowStyle.xaml" />
|
||||
</Page.Resources>
|
||||
<ScrollViewer
|
||||
Margin="0,0,0,0"
|
||||
Padding="5,0,24,0"
|
||||
FontSize="14"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
Margin="0 0 0 0"
|
||||
Padding="5 0 24 0"
|
||||
CanContentScroll="True"
|
||||
VirtualizingStackPanel.IsVirtualizing="True"
|
||||
VirtualizingStackPanel.ScrollUnit="Pixel">
|
||||
<Border>
|
||||
|
||||
<StackPanel>
|
||||
<Border Margin="0,18,0,0">
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Margin="0,5,0,0"
|
||||
FontSize="30"
|
||||
Style="{StaticResource PageTitle}"
|
||||
Text="{DynamicResource proxy}"
|
||||
TextAlignment="left" />
|
||||
</Border>
|
||||
<StackPanel>
|
||||
<TextBlock
|
||||
Margin="0 23 0 10"
|
||||
FontSize="30"
|
||||
Style="{StaticResource PageTitle}"
|
||||
Text="{DynamicResource proxy}"
|
||||
TextAlignment="left" />
|
||||
|
||||
<cc:CardGroup>
|
||||
<cc:Card Title="{DynamicResource enableProxy}">
|
||||
<ui:ToggleSwitch IsOn="{Binding Settings.Proxy.Enabled}" />
|
||||
</cc:Card>
|
||||
|
||||
<Border
|
||||
Margin="0,10,0,0"
|
||||
Padding="0"
|
||||
CornerRadius="5"
|
||||
Style="{DynamicResource SettingGroupBox}">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Border
|
||||
Margin="0"
|
||||
BorderThickness="0"
|
||||
Style="{DynamicResource SettingGroupBox}">
|
||||
<ItemsControl Style="{StaticResource SettingGrid}">
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Style="{DynamicResource SettingTitleLabel}"
|
||||
Text="{DynamicResource enableProxy}" />
|
||||
<ui:ToggleSwitch
|
||||
Grid.Column="2"
|
||||
Margin="0,0,18,0"
|
||||
IsOn="{Binding Settings.Proxy.Enabled}" />
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
<Separator
|
||||
Width="Auto"
|
||||
BorderThickness="1"
|
||||
Style="{StaticResource SettingSeparatorStyle}" />
|
||||
<Border
|
||||
Margin="0"
|
||||
BorderThickness="0"
|
||||
Style="{DynamicResource SettingGroupBox}">
|
||||
<ItemsControl Style="{StaticResource SettingGrid}">
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="22,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Style="{DynamicResource SettingTitleLabel}"
|
||||
Text="{DynamicResource server}" />
|
||||
<TextBox
|
||||
Grid.Column="2"
|
||||
Width="300"
|
||||
Margin="0,0,16,0"
|
||||
Padding="5"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.Server}" />
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
<Separator
|
||||
Width="Auto"
|
||||
BorderThickness="1"
|
||||
Style="{StaticResource SettingSeparatorStyle}" />
|
||||
<Border
|
||||
Margin="0"
|
||||
BorderThickness="0"
|
||||
Style="{DynamicResource SettingGroupBox}">
|
||||
<ItemsControl Style="{StaticResource SettingGrid}">
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="22,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Style="{DynamicResource SettingTitleLabel}"
|
||||
Text="{DynamicResource port}" />
|
||||
<TextBox
|
||||
Grid.Column="2"
|
||||
Width="100"
|
||||
Margin="0,0,16,0"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.Port, TargetNullValue={x:Static sys:String.Empty}}" />
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
<Separator
|
||||
Width="Auto"
|
||||
BorderThickness="1"
|
||||
Style="{StaticResource SettingSeparatorStyle}" />
|
||||
<Border
|
||||
Margin="0"
|
||||
BorderThickness="0"
|
||||
Style="{DynamicResource SettingGroupBox}">
|
||||
<ItemsControl Style="{StaticResource SettingGrid}">
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="22,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Style="{DynamicResource SettingTitleLabel}"
|
||||
Text="{DynamicResource userName}" />
|
||||
<TextBox
|
||||
Grid.Column="2"
|
||||
Width="200"
|
||||
Margin="0,0,16,0"
|
||||
Padding="5"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.UserName}" />
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
<Separator
|
||||
Width="Auto"
|
||||
BorderThickness="1"
|
||||
Style="{StaticResource SettingSeparatorStyle}" />
|
||||
<Border
|
||||
Margin="0"
|
||||
BorderThickness="0"
|
||||
Style="{DynamicResource SettingGroupBox}">
|
||||
<ItemsControl Style="{StaticResource SettingGrid}">
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="22,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Style="{DynamicResource SettingTitleLabel}"
|
||||
Text="{DynamicResource password}" />
|
||||
<TextBox
|
||||
Grid.Column="2"
|
||||
Width="200"
|
||||
Margin="0,0,16,0"
|
||||
Padding="5"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.Password}" />
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border Margin="0,12,0,0" Style="{DynamicResource SettingGroupBox}">
|
||||
<ItemsControl Style="{StaticResource SettingGrid}">
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Style="{DynamicResource SettingTitleLabel}"
|
||||
Text="{DynamicResource testProxy}" />
|
||||
<Button
|
||||
Grid.Column="2"
|
||||
Width="150"
|
||||
Margin="0,0,16,0"
|
||||
HorizontalAlignment="Right"
|
||||
Content="{DynamicResource testProxy}"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}" />
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<cc:Card Title="{DynamicResource server}">
|
||||
<TextBox
|
||||
Width="300"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.Server}" />
|
||||
</cc:Card>
|
||||
|
||||
<cc:Card Title="{DynamicResource port}">
|
||||
<TextBox
|
||||
Width="100"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.Port, TargetNullValue={x:Static sys:String.Empty}}" />
|
||||
</cc:Card>
|
||||
|
||||
<cc:Card Title="{DynamicResource userName}">
|
||||
<TextBox
|
||||
Width="200"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.UserName}" />
|
||||
</cc:Card>
|
||||
|
||||
<cc:Card Title="{DynamicResource password}">
|
||||
<TextBox
|
||||
Width="200"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Text="{Binding Settings.Proxy.Password}" />
|
||||
</cc:Card>
|
||||
</cc:CardGroup>
|
||||
|
||||
<cc:Card Title="{DynamicResource testProxy}" Margin="0 8 0 0">
|
||||
<Button
|
||||
Width="150"
|
||||
Content="{DynamicResource testProxy}"
|
||||
IsEnabled="{Binding Settings.Proxy.Enabled}"
|
||||
Command="{Binding TestProxyClickedCommand}"/>
|
||||
</cc:Card>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Page>
|
||||
</ui:Page>
|
||||
|
|
|
|||
|
|
@ -1,28 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
public partial class SettingsPaneProxy
|
||||
{
|
||||
/// <summary>
|
||||
/// Proxy.xaml에 대한 상호 작용 논리
|
||||
/// </summary>
|
||||
public partial class SettingsPaneProxy : Page
|
||||
private SettingsPaneProxyViewModel _viewModel = null!;
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
public SettingsPaneProxy()
|
||||
if (!IsInitialized)
|
||||
{
|
||||
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: { } updater })
|
||||
throw new ArgumentException($"Settings are required for {nameof(SettingsPaneProxy)}.");
|
||||
_viewModel = new SettingsPaneProxyViewModel(settings, updater);
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue