Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
修复编辑建议Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Dec 2, 2018
1 parent e583c70 commit 2ce1961
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
清华大学校园网客户端,UWP架构,使用C++/WinRT编写。

其内核与我的另一个使用WPF编写的[客户端](https://github.com/Berrysoft/Tsinghua_Auth4_Net)相似,不过使用的是WinRT的库。

在UWP架构下使用C++,速度不一定会有很大提升,因此这个项目仅仅是用来练习。
为了满足认证要求,采用组合而非继承的架构(因为JavaScript不支持继承)。

## 功能特点
* 自动连接,并针对不同的网络类型给出建议
* 针对不同的网络类型给出建议
* 使用Windows凭据管理用户名与密码。
* 在网络状态改变时会自动判断,后台连接。
* 后台刷新流量。

## 注意事项
* 请正常注销Auth连接,否则可能会有短时间难以登录的问题。
Expand Down
13 changes: 9 additions & 4 deletions TsinghuaNetHelper/SettingsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace winrt::TsinghuaNetHelper::implementation
auto settings = ApplicationData::Current().LocalSettings();
auto values = settings.Values();
auto value = values.TryLookup(key);
if (value != nullptr)
if (value)
{
return unbox_value<T>(value);
}
Expand Down Expand Up @@ -64,10 +64,15 @@ namespace winrt::TsinghuaNetHelper::implementation
type SettingsHelper::name() { return GetValue<type>(name##Key, def); } \
void SettingsHelper::name(type const& value) { SetValue(name##Key, value); }

#define SETTINGS_PROP_CONV_IMPL(name, key, type, ctype, def) \
constexpr wchar_t name##Key[] = key; \
type SettingsHelper::name() { return (type)GetValue<ctype>(name##Key, def); } \
void SettingsHelper::name(type value) { SetValue<ctype>(name##Key, (ctype)value); }

SETTINGS_PROP_REF_IMPL(StoredUsername, L"Username", hstring, {})
SETTINGS_PROP_IMPL(AutoLogin, L"AutoLogin", bool, true)
SETTINGS_PROP_IMPL(LanState, L"LanState", NetState, NetState::Auth4)
SETTINGS_PROP_IMPL(WwanState, L"WwanState", NetState, NetState::Direct)
SETTINGS_PROP_CONV_IMPL(LanState, L"LanState", NetState, int, (int)NetState::Auth4)
SETTINGS_PROP_CONV_IMPL(WwanState, L"WwanState", NetState, int, (int)NetState::Direct)

NetState SettingsHelper::WlanState(hstring const& ssid)
{
Expand All @@ -86,7 +91,7 @@ namespace winrt::TsinghuaNetHelper::implementation
InternetStatus SettingsHelper::GetCurrentInternetStatus(hstring& ssid)
{
auto profile = NetworkInformation::GetInternetConnectionProfile();
if (profile == nullptr)
if (!profile)
return InternetStatus::Unknown;
auto cl = profile.GetNetworkConnectivityLevel();
if (cl == NetworkConnectivityLevel::None)
Expand Down
6 changes: 3 additions & 3 deletions TsinghuaNetUWP/EditSuggestionDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Margin="10" Style="{ThemeResource BaseTextBlockStyle}">有线网</TextBlock>
<ComboBox x:Name="LanCombo" Grid.Column="1" Grid.Row="0" Width="390" VerticalAlignment="Center" ItemsSource="{x:Bind States}" ItemTemplate="{StaticResource NetStateTemplate}"/>
<ComboBox x:Name="LanCombo" Grid.Column="1" Grid.Row="0" Width="290" VerticalAlignment="Center" ItemsSource="{x:Bind States}" ItemTemplate="{StaticResource NetStateTemplate}"/>
<TextBlock Grid.Column="0" Grid.Row="1" Margin="10" Style="{ThemeResource BaseTextBlockStyle}">移动流量</TextBlock>
<ComboBox x:Name="WwanCombo" Grid.Column="1" Grid.Row="1" Width="390" VerticalAlignment="Center" ItemsSource="{x:Bind States}" ItemTemplate="{StaticResource NetStateTemplate}"/>
<ComboBox x:Name="WwanCombo" Grid.Column="1" Grid.Row="1" Width="290" VerticalAlignment="Center" ItemsSource="{x:Bind States}" ItemTemplate="{StaticResource NetStateTemplate}"/>
</Grid>
</ContentDialog>

0 comments on commit 2ce1961

Please sign in to comment.