|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
using Avalonia; |
|
|
|
|
using Avalonia.Controls; |
|
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
|
using Avalonia.Media; |
|
|
|
|
using Avalonia.Styling; |
|
|
|
|
using ReactiveUI; |
|
|
|
|
using ReactiveUI.Fody.Helpers; |
|
|
|
@ -9,14 +11,11 @@ namespace v2rayN.Desktop.ViewModels
|
|
|
|
|
{ |
|
|
|
|
public class ThemeSettingViewModel : MyReactiveObject |
|
|
|
|
{ |
|
|
|
|
[Reactive] |
|
|
|
|
public bool ColorModeDark { get; set; } |
|
|
|
|
[Reactive] public bool ColorModeDark { get; set; } |
|
|
|
|
|
|
|
|
|
[Reactive] |
|
|
|
|
public int CurrentFontSize { get; set; } |
|
|
|
|
[Reactive] public int CurrentFontSize { get; set; } |
|
|
|
|
|
|
|
|
|
[Reactive] |
|
|
|
|
public string CurrentLanguage { get; set; } |
|
|
|
|
[Reactive] public string CurrentLanguage { get; set; } |
|
|
|
|
|
|
|
|
|
public ThemeSettingViewModel() |
|
|
|
|
{ |
|
|
|
@ -29,6 +28,7 @@ namespace v2rayN.Desktop.ViewModels
|
|
|
|
|
private void RestoreUI() |
|
|
|
|
{ |
|
|
|
|
ModifyTheme(_config.UiItem.ColorModeDark); |
|
|
|
|
ModifyFontFamily(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void BindingUI() |
|
|
|
@ -38,34 +38,34 @@ namespace v2rayN.Desktop.ViewModels
|
|
|
|
|
CurrentLanguage = _config.UiItem.CurrentLanguage; |
|
|
|
|
|
|
|
|
|
this.WhenAnyValue(x => x.ColorModeDark) |
|
|
|
|
.Subscribe(c => |
|
|
|
|
{ |
|
|
|
|
if (_config.UiItem.ColorModeDark != ColorModeDark) |
|
|
|
|
{ |
|
|
|
|
_config.UiItem.ColorModeDark = ColorModeDark; |
|
|
|
|
ModifyTheme(ColorModeDark); |
|
|
|
|
ConfigHandler.SaveConfig(_config); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
.Subscribe(c => |
|
|
|
|
{ |
|
|
|
|
if (_config.UiItem.ColorModeDark != ColorModeDark) |
|
|
|
|
{ |
|
|
|
|
_config.UiItem.ColorModeDark = ColorModeDark; |
|
|
|
|
ModifyTheme(ColorModeDark); |
|
|
|
|
ConfigHandler.SaveConfig(_config); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.WhenAnyValue( |
|
|
|
|
x => x.CurrentFontSize, |
|
|
|
|
y => y > 0) |
|
|
|
|
.Subscribe(c => |
|
|
|
|
{ |
|
|
|
|
if (CurrentFontSize >= Global.MinFontSize) |
|
|
|
|
{ |
|
|
|
|
_config.UiItem.CurrentFontSize = CurrentFontSize; |
|
|
|
|
double size = CurrentFontSize; |
|
|
|
|
ModifyFontSize(size); |
|
|
|
|
x => x.CurrentFontSize, |
|
|
|
|
y => y > 0) |
|
|
|
|
.Subscribe(c => |
|
|
|
|
{ |
|
|
|
|
if (CurrentFontSize >= Global.MinFontSize) |
|
|
|
|
{ |
|
|
|
|
_config.UiItem.CurrentFontSize = CurrentFontSize; |
|
|
|
|
double size = CurrentFontSize; |
|
|
|
|
ModifyFontSize(size); |
|
|
|
|
|
|
|
|
|
ConfigHandler.SaveConfig(_config); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
ConfigHandler.SaveConfig(_config); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.WhenAnyValue( |
|
|
|
|
x => x.CurrentLanguage, |
|
|
|
|
y => y != null && !y.IsNullOrEmpty()) |
|
|
|
|
x => x.CurrentLanguage, |
|
|
|
|
y => y != null && !y.IsNullOrEmpty()) |
|
|
|
|
.Subscribe(c => |
|
|
|
|
{ |
|
|
|
|
if (Utils.IsNotEmpty(CurrentLanguage) && _config.UiItem.CurrentLanguage != CurrentLanguage) |
|
|
|
@ -89,53 +89,51 @@ namespace v2rayN.Desktop.ViewModels
|
|
|
|
|
|
|
|
|
|
private void ModifyFontSize(double size) |
|
|
|
|
{ |
|
|
|
|
Style buttonStyle = new(x => x.OfType<Button>()); |
|
|
|
|
buttonStyle.Add(new Setter() |
|
|
|
|
{ |
|
|
|
|
Property = Button.FontSizeProperty, |
|
|
|
|
Value = size, |
|
|
|
|
}); |
|
|
|
|
Application.Current?.Styles.Add(buttonStyle); |
|
|
|
|
|
|
|
|
|
Style textStyle = new(x => x.OfType<TextBox>()); |
|
|
|
|
textStyle.Add(new Setter() |
|
|
|
|
{ |
|
|
|
|
Property = TextBox.FontSizeProperty, |
|
|
|
|
Value = size, |
|
|
|
|
}); |
|
|
|
|
Application.Current?.Styles.Add(textStyle); |
|
|
|
|
|
|
|
|
|
Style textBlockStyle = new(x => x.OfType<TextBlock>()); |
|
|
|
|
textBlockStyle.Add(new Setter() |
|
|
|
|
Style style = new(x => Selectors.Or( |
|
|
|
|
x.OfType<Button>(), |
|
|
|
|
x.OfType<TextBox>(), |
|
|
|
|
x.OfType<TextBlock>(), |
|
|
|
|
x.OfType<Menu>(), |
|
|
|
|
x.OfType<DataGridRow>(), |
|
|
|
|
x.OfType<ListBoxItem>() |
|
|
|
|
)); |
|
|
|
|
style.Add(new Setter() |
|
|
|
|
{ |
|
|
|
|
Property = TextBlock.FontSizeProperty, |
|
|
|
|
Property = TemplatedControl.FontSizeProperty, |
|
|
|
|
Value = size, |
|
|
|
|
}); |
|
|
|
|
Application.Current?.Styles.Add(textBlockStyle); |
|
|
|
|
Application.Current?.Styles.Add(style); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Style menuStyle = new(x => x.OfType<Menu>()); |
|
|
|
|
menuStyle.Add(new Setter() |
|
|
|
|
private void ModifyFontFamily() |
|
|
|
|
{ |
|
|
|
|
var currentFontFamily = _config.UiItem.CurrentFontFamily; |
|
|
|
|
if (currentFontFamily.IsNullOrEmpty()) |
|
|
|
|
{ |
|
|
|
|
Property = Menu.FontSizeProperty, |
|
|
|
|
Value = size, |
|
|
|
|
}); |
|
|
|
|
Application.Current?.Styles.Add(menuStyle); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Style dataStyle = new(x => x.OfType<DataGridRow>()); |
|
|
|
|
dataStyle.Add(new Setter() |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
Property = DataGridRow.FontSizeProperty, |
|
|
|
|
Value = size, |
|
|
|
|
}); |
|
|
|
|
Application.Current?.Styles.Add(dataStyle); |
|
|
|
|
|
|
|
|
|
Style listStyle = new(x => x.OfType<ListBoxItem>()); |
|
|
|
|
listStyle.Add(new Setter() |
|
|
|
|
Style style = new(x => Selectors.Or( |
|
|
|
|
x.OfType<Button>(), |
|
|
|
|
x.OfType<TextBox>(), |
|
|
|
|
x.OfType<TextBlock>(), |
|
|
|
|
x.OfType<Menu>(), |
|
|
|
|
x.OfType<DataGridRow>(), |
|
|
|
|
x.OfType<ListBoxItem>() |
|
|
|
|
)); |
|
|
|
|
style.Add(new Setter() |
|
|
|
|
{ |
|
|
|
|
Property = TemplatedControl.FontFamilyProperty, |
|
|
|
|
Value = new FontFamily(currentFontFamily), |
|
|
|
|
}); |
|
|
|
|
Application.Current?.Styles.Add(style); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Property = ListBoxItem.FontSizeProperty, |
|
|
|
|
Value = size, |
|
|
|
|
}); |
|
|
|
|
Application.Current?.Styles.Add(listStyle); |
|
|
|
|
Logging.SaveLog("ModifyFontFamily", ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |