Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
可以登出了
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed Apr 24, 2019
1 parent 6722fd6 commit 36c8142
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 40 deletions.
16 changes: 16 additions & 0 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using PixivFSCS;
using Windows.ApplicationModel.Core;
using Windows.Graphics.Imaging;
using Windows.Security.Credentials;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Core;
Expand Down Expand Up @@ -116,5 +117,20 @@ await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
});
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}

//从Vault中获取身份信息
//此版本只储存一个,未来可以储存多到20个
public static PasswordCredential GetCredentialFromLocker(string resourceName)
{
PasswordCredential credential = null;
var vault = new PasswordVault();
try
{
var credentialList = vault.FindAllByResource(resourceName);
if (credentialList.Count > 0) credential = credentialList[0];
}
catch { }
return credential;
}
}
}
15 changes: 0 additions & 15 deletions PixivFSUWP/LoginPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,5 @@ await Launcher.LaunchUriAsync(new
txtPassword.Focus(FocusState.Programmatic);
txtPassword.SelectAll();
}

//从Vault中获取身份信息
//此版本只储存一个,未来可以储存多到20个
private PasswordCredential GetCredentialFromLocker(string resourceName)
{
PasswordCredential credential = null;
var vault = new PasswordVault();
try
{
var credentialList = vault.FindAllByResource(resourceName);
if (credentialList.Count > 0) credential = credentialList[0];
}
catch { }
return credential;
}
}
}
58 changes: 33 additions & 25 deletions PixivFSUWP/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,40 @@ public MainPage()

private async void NavControl_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
switch (sender.MenuItems.IndexOf(args.SelectedItem))
if (args.IsSettingsSelected)
{
case 0:
OverAll.RefreshRecommendList();
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Recommend);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
NavPlaceholder.Visibility = Visibility.Collapsed;
break;
case 1:
OverAll.RefreshBookmarkList();
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Bookmark);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
NavPlaceholder.Visibility = Visibility.Collapsed;
break;
case 2:
OverAll.RefreshFollowingList();
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Following);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
NavPlaceholder.Visibility = Visibility.Collapsed;
break;
SelectNavPlaceholder("设置");
ContentFrame.Navigate(typeof(SettingsPage));
}
else
{
switch (sender.MenuItems.IndexOf(args.SelectedItem))
{
case 0:
OverAll.RefreshRecommendList();
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Recommend);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
NavPlaceholder.Visibility = Visibility.Collapsed;
break;
case 1:
OverAll.RefreshBookmarkList();
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Bookmark);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
NavPlaceholder.Visibility = Visibility.Collapsed;
break;
case 2:
OverAll.RefreshFollowingList();
ContentFrame.Navigate(typeof(WaterfallPage), WaterfallPage.ListContent.Following);
NavPlaceholder.IsEnabled = false;
await Task.Delay(TimeSpan.FromMilliseconds(350));
NavSeparator.Visibility = Visibility.Collapsed;
NavPlaceholder.Visibility = Visibility.Collapsed;
break;
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions PixivFSUWP/PixivFSUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\CommentViewModel.cs" />
<Compile Include="ViewModels\ImageItemViewModel.cs" />
<Compile Include="ViewModels\WaterfallItemViewModel.cs" />
Expand Down Expand Up @@ -200,6 +203,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="SettingsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WaterfallPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
18 changes: 18 additions & 0 deletions PixivFSUWP/SettingsPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Page
x:Class="PixivFSUWP.SettingsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PixivFSUWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer>
<ScrollViewer.Background>
<AcrylicBrush BackgroundSource="HostBackdrop" TintColor="White" TintOpacity="0.5" FallbackColor="White"/>
</ScrollViewer.Background>
<StackPanel Margin="0,75,0,0">
<Button x:Name="btnLogout" Click="BtnLogout_Click">注销登录</Button>
</StackPanel>
</ScrollViewer>
</Page>
47 changes: 47 additions & 0 deletions PixivFSUWP/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Security.Credentials;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using static PixivFSUWP.Data.OverAll;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

namespace PixivFSUWP
{
/// <summary>
/// 可用于自身或导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class SettingsPage : Page
{
public SettingsPage()
{
this.InitializeComponent();
}

private void BtnLogout_Click(object sender, RoutedEventArgs e)
{
var vault = new PasswordVault();
try
{
vault.Remove(GetCredentialFromLocker(passwordResource));
vault.Remove(GetCredentialFromLocker(refreshTokenResource));
}
catch { }
finally
{
((Frame.Parent as Grid).Parent as MainPage).Frame.Navigate(typeof(LoginPage));
}
}
}
}

0 comments on commit 36c8142

Please sign in to comment.