Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Helpers/L.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static class L
public static string EditServer_Protocol => Loc.GetString("EditServer_Protocol");
public static string EditServer_Encryption => Loc.GetString("EditServer_Encryption");
public static string EditServer_Password => Loc.GetString("EditServer_Password");
public static string EditServer_ShowPassword => Loc.GetString("EditServer_ShowPassword");
public static string EditServer_HidePassword => Loc.GetString("EditServer_HidePassword");
public static string EditServer_Transport => Loc.GetString("EditServer_Transport");
public static string EditServer_Path => Loc.GetString("EditServer_Path");
public static string EditServer_WsHost => Loc.GetString("EditServer_WsHost");
Expand Down
47 changes: 46 additions & 1 deletion Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void SyncDialogButtons()
cmbEncryption.Items.Add(existingEnc);
cmbEncryption.SelectedItem = existing?.Encryption ?? "aes-128-gcm";
var txtUsername = new TextBox { Header = L.EditServer_SocksUsername, Text = existing?.Username ?? string.Empty };
var txtPassword = new PasswordBox { Header = L.EditServer_Password, Password = existing?.Password ?? string.Empty };
var txtPassword = CreateRevealablePasswordBox(L.EditServer_Password, existing?.Password);
var txtUuid = new TextBox { Header = "UUID (VMess / VLESS)", Text = existing?.Uuid ?? string.Empty };
var numAlterId = new NumberBox
{ Header = "AlterId (VMess)", Value = existing?.AlterId ?? 0, Minimum = 0, Maximum = 65535 };
Expand Down Expand Up @@ -1288,6 +1288,51 @@ public async Task<bool> ShowDnsSettingsDialogAsync(AppSettings settings, bool is
private static Border Wrap(FrameworkElement child) =>
new Border { Child = child };


private const string RevealGlyph = "\uE7B3"; // RedEye
private const string ConcealGlyph = "\uED1A"; // Hide

/// <summary>
/// A PasswordBox whose header carries a reveal toggle on the right.
/// <para>
/// PasswordRevealMode is forced to Hidden rather than left at the default Peek: the
/// built-in peek button only shows up once the box has focus <em>and the user has typed
/// a character</em>. An existing server's password is assigned here in code, so peek is
/// dead on arrival and the value can never be read back (issue #124).
/// </para>
/// </summary>
private static PasswordBox CreateRevealablePasswordBox(string header, string? value)
{
var box = new PasswordBox { Password = value ?? string.Empty };

var icon = new FontIcon { FontSize = 14 };
var toggle = new Button
{
Content = icon,
Padding = new Thickness(6, 0, 6, 0),
Height = 22,
VerticalAlignment = VerticalAlignment.Center,
};
if (Application.Current.Resources.TryGetValue("SubtleButtonStyle", out var subtleStyle))
toggle.Style = (Style)subtleStyle;

void SetRevealed(bool revealed)
{
box.PasswordRevealMode = revealed ? PasswordRevealMode.Visible : PasswordRevealMode.Hidden;
icon.Glyph = revealed ? ConcealGlyph : RevealGlyph;

var label = revealed ? L.EditServer_HidePassword : L.EditServer_ShowPassword;
ToolTipService.SetToolTip(toggle, label);
AutomationProperties.SetName(toggle, label);
}

SetRevealed(false);
toggle.Click += (_, _) => SetRevealed(box.PasswordRevealMode != PasswordRevealMode.Visible);

box.Header = CreateLabelRow(header, toggle);
return box;
}

/// <summary>Multi-line raw-JSON editor box (Finalmask / XHTTP extra).</summary>
private static TextBox CreateJsonTextBox(string header, string? value) => new()
{
Expand Down
6 changes: 6 additions & 0 deletions Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@
<data name="EditServer_Password" xml:space="preserve">
<value>Password</value>
</data>
<data name="EditServer_ShowPassword" xml:space="preserve">
<value>Show password</value>
</data>
<data name="EditServer_HidePassword" xml:space="preserve">
<value>Hide password</value>
</data>
<data name="EditServer_Transport" xml:space="preserve">
<value>Transport Protocol</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions Strings/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@
<data name="EditServer_Password" xml:space="preserve">
<value>密码</value>
</data>
<data name="EditServer_ShowPassword" xml:space="preserve">
<value>显示密码</value>
</data>
<data name="EditServer_HidePassword" xml:space="preserve">
<value>隐藏密码</value>
</data>
<data name="EditServer_Transport" xml:space="preserve">
<value>传输协议</value>
</data>
Expand Down
Loading