mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 15:53:30 -07:00
Hide token using password box
This commit is contained in:
parent
51192425b7
commit
c4137cf77e
|
|
@ -31,12 +31,12 @@ public class Bootstrapper : Bootstrapper<RootViewModel>
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
|
protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs args)
|
||||||
{
|
{
|
||||||
base.OnUnhandledException(e);
|
base.OnUnhandledException(args);
|
||||||
|
|
||||||
MessageBox.Show(
|
MessageBox.Show(
|
||||||
e.Exception.ToString(),
|
args.Exception.ToString(),
|
||||||
"Error occured",
|
"Error occured",
|
||||||
MessageBoxButton.OK,
|
MessageBoxButton.OK,
|
||||||
MessageBoxImage.Error
|
MessageBoxImage.Error
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,6 @@ public class DashboardViewModel : PropertyChangedBase
|
||||||
|
|
||||||
public string? Token { get; set; }
|
public string? Token { get; set; }
|
||||||
|
|
||||||
public bool IsTokenSet => !string.IsNullOrWhiteSpace(Token);
|
|
||||||
|
|
||||||
private IReadOnlyDictionary<Guild, IReadOnlyList<Channel>>? ChannelsByGuild { get; set; }
|
private IReadOnlyDictionary<Guild, IReadOnlyList<Channel>>? ChannelsByGuild { get; set; }
|
||||||
|
|
||||||
public IReadOnlyList<Guild>? AvailableGuilds => ChannelsByGuild?.Keys.ToArray();
|
public IReadOnlyList<Guild>? AvailableGuilds => ChannelsByGuild?.Keys.ToArray();
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
xmlns:behaviors="clr-namespace:DiscordChatExporter.Gui.Behaviors"
|
xmlns:behaviors="clr-namespace:DiscordChatExporter.Gui.Behaviors"
|
||||||
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
|
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
|
||||||
xmlns:components="clr-namespace:DiscordChatExporter.Gui.ViewModels.Components"
|
xmlns:components="clr-namespace:DiscordChatExporter.Gui.ViewModels.Components"
|
||||||
|
xmlns:controls="clr-namespace:DiscordChatExporter.Gui.Views.Controls"
|
||||||
xmlns:converters="clr-namespace:DiscordChatExporter.Gui.Converters"
|
xmlns:converters="clr-namespace:DiscordChatExporter.Gui.Converters"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:data="clr-namespace:DiscordChatExporter.Core.Discord.Data;assembly=DiscordChatExporter.Core"
|
xmlns:data="clr-namespace:DiscordChatExporter.Core.Discord.Data;assembly=DiscordChatExporter.Core"
|
||||||
|
|
@ -75,38 +76,29 @@
|
||||||
Kind="Key" />
|
Kind="Key" />
|
||||||
|
|
||||||
<!-- Token value -->
|
<!-- Token value -->
|
||||||
<TextBox
|
<controls:RevealablePasswordBox
|
||||||
x:Name="TokenValueTextBox"
|
x:Name="TokenValueTextBox"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="0,6,6,8"
|
Margin="0,6,6,8"
|
||||||
VerticalAlignment="Bottom"
|
VerticalAlignment="Bottom"
|
||||||
materialDesign:HintAssist.Hint="Token"
|
materialDesign:HintAssist.Hint="Token"
|
||||||
materialDesign:TextFieldAssist.DecorationVisibility="Hidden"
|
|
||||||
materialDesign:TextFieldAssist.TextBoxViewMargin="0,0,2,0"
|
|
||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
|
FontFamily="Consolas"
|
||||||
FontSize="16"
|
FontSize="16"
|
||||||
Text="{Binding Token, UpdateSourceTrigger=PropertyChanged}">
|
Password="{Binding Token, UpdateSourceTrigger=PropertyChanged}">
|
||||||
<TextBox.Style>
|
<controls:RevealablePasswordBox.Style>
|
||||||
<Style BasedOn="{StaticResource {x:Type TextBox}}" TargetType="{x:Type TextBox}">
|
<Style TargetType="{x:Type controls:RevealablePasswordBox}">
|
||||||
<Style.Triggers>
|
<Style.Triggers>
|
||||||
<!-- Blur the token when it's out of focus -->
|
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=materialDesign:Card}}" Value="True">
|
||||||
<MultiDataTrigger>
|
<Setter Property="IsRevealed" Value="True" />
|
||||||
<MultiDataTrigger.Conditions>
|
</DataTrigger>
|
||||||
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=materialDesign:Card}}" Value="False" />
|
<DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=materialDesign:Card}}" Value="True">
|
||||||
<Condition Binding="{Binding IsFocused, RelativeSource={RelativeSource Self}}" Value="False" />
|
<Setter Property="IsRevealed" Value="True" />
|
||||||
<!-- Don't blur if the token is not set, so the user can see the hint text -->
|
</DataTrigger>
|
||||||
<Condition Binding="{Binding IsTokenSet}" Value="True" />
|
|
||||||
</MultiDataTrigger.Conditions>
|
|
||||||
<Setter Property="Effect">
|
|
||||||
<Setter.Value>
|
|
||||||
<BlurEffect Radius="12" />
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</MultiDataTrigger>
|
|
||||||
</Style.Triggers>
|
</Style.Triggers>
|
||||||
</Style>
|
</Style>
|
||||||
</TextBox.Style>
|
</controls:RevealablePasswordBox.Style>
|
||||||
</TextBox>
|
</controls:RevealablePasswordBox>
|
||||||
|
|
||||||
<!-- Pull data button -->
|
<!-- Pull data button -->
|
||||||
<Button
|
<Button
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<UserControl
|
||||||
|
x:Class="DiscordChatExporter.Gui.Views.Controls.RevealablePasswordBox"
|
||||||
|
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:s="https://github.com/canton7/Stylet"
|
||||||
|
x:Name="Root"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<Grid>
|
||||||
|
<TextBox
|
||||||
|
materialDesign:TextFieldAssist.DecorationVisibility="Hidden"
|
||||||
|
BorderThickness="{Binding BorderThickness, ElementName=Root}"
|
||||||
|
Text="{Binding Password, ElementName=Root}"
|
||||||
|
Visibility="{Binding IsRevealed, ElementName=Root, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
|
||||||
|
<PasswordBox
|
||||||
|
x:Name="PasswordBox"
|
||||||
|
materialDesign:TextFieldAssist.DecorationVisibility="Hidden"
|
||||||
|
BorderThickness="{Binding BorderThickness, ElementName=Root}"
|
||||||
|
PasswordChanged="PasswordBox_OnPasswordChanged"
|
||||||
|
Visibility="{Binding IsRevealed, ElementName=Root, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}" />
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Gui.Views.Controls;
|
||||||
|
|
||||||
|
public partial class RevealablePasswordBox
|
||||||
|
{
|
||||||
|
public static readonly DependencyProperty PasswordProperty = DependencyProperty.Register(
|
||||||
|
nameof(Password),
|
||||||
|
typeof(string),
|
||||||
|
typeof(RevealablePasswordBox),
|
||||||
|
new FrameworkPropertyMetadata(
|
||||||
|
string.Empty,
|
||||||
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||||
|
(sender, args) =>
|
||||||
|
{
|
||||||
|
var revealablePasswordBox = (RevealablePasswordBox)sender;
|
||||||
|
var password = (string)args.NewValue;
|
||||||
|
|
||||||
|
revealablePasswordBox.PasswordBox.Password = password;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IsRevealedProperty = DependencyProperty.Register(
|
||||||
|
nameof(IsRevealed),
|
||||||
|
typeof(bool),
|
||||||
|
typeof(RevealablePasswordBox),
|
||||||
|
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.None)
|
||||||
|
);
|
||||||
|
|
||||||
|
public string Password
|
||||||
|
{
|
||||||
|
get => (string)GetValue(PasswordProperty);
|
||||||
|
set => SetValue(PasswordProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsRevealed
|
||||||
|
{
|
||||||
|
get => (bool)GetValue(IsRevealedProperty);
|
||||||
|
set => SetValue(IsRevealedProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RevealablePasswordBox()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PasswordBox_OnPasswordChanged(object sender, RoutedEventArgs args) =>
|
||||||
|
Password = PasswordBox.Password;
|
||||||
|
}
|
||||||
|
|
@ -60,10 +60,10 @@
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
x:Name="DarkModeToggleButton"
|
x:Name="DarkModeToggleButton"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Checked="DarkModeToggleButton_Checked"
|
Checked="DarkModeToggleButton_OnChecked"
|
||||||
DockPanel.Dock="Right"
|
DockPanel.Dock="Right"
|
||||||
IsChecked="{Binding IsDarkModeEnabled}"
|
IsChecked="{Binding IsDarkModeEnabled}"
|
||||||
Unchecked="DarkModeToggleButton_Unchecked" />
|
Unchecked="DarkModeToggleButton_OnUnchecked" />
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|
||||||
<!-- Persist token -->
|
<!-- Persist token -->
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ public partial class SettingsView
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DarkModeToggleButton_Checked(object sender, RoutedEventArgs e) =>
|
private void DarkModeToggleButton_OnChecked(object sender, RoutedEventArgs args) =>
|
||||||
App.SetDarkTheme();
|
App.SetDarkTheme();
|
||||||
|
|
||||||
private void DarkModeToggleButton_Unchecked(object sender, RoutedEventArgs e) =>
|
private void DarkModeToggleButton_OnUnchecked(object sender, RoutedEventArgs args) =>
|
||||||
App.SetLightTheme();
|
App.SetLightTheme();
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue