mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-29 05:10:45 +08:00
调整默认设备设置到设置页
This commit is contained in:
+1
-1
@@ -42,7 +42,7 @@
|
||||
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.12.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.3.1" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.4" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.5" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.8" />
|
||||
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.6.0.20220608" />
|
||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.6.0.20220608" />
|
||||
|
||||
+117
-14
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -7,6 +6,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using ElectronBot.BraincasePreview.Contracts.Services;
|
||||
using ElectronBot.BraincasePreview.Contracts.ViewModels;
|
||||
using ElectronBot.BraincasePreview.Core.Models;
|
||||
using ElectronBot.BraincasePreview.Helpers;
|
||||
using ElectronBot.BraincasePreview.Models;
|
||||
using Microsoft.UI.Xaml;
|
||||
@@ -21,7 +21,34 @@ public class SettingsViewModel : ObservableRecipient, INavigationAware
|
||||
private readonly ILocalSettingsService _localSettingsService;
|
||||
private ElementTheme _elementTheme;
|
||||
|
||||
private ObservableCollection<ComboxItemModel> _cameras;
|
||||
|
||||
private ObservableCollection<ComboxItemModel> _audioDevs;
|
||||
|
||||
|
||||
private ComboxItemModel _cameraSelect;
|
||||
|
||||
private ComboxItemModel _audioSelect;
|
||||
|
||||
|
||||
private string _customClockTitle;
|
||||
|
||||
public SettingsViewModel(
|
||||
IThemeSelectorService themeSelectorService,
|
||||
ILocalSettingsService localSettingsService)
|
||||
{
|
||||
_themeSelectorService = themeSelectorService;
|
||||
_elementTheme = _themeSelectorService.Theme;
|
||||
_localSettingsService = localSettingsService;
|
||||
VersionDescription = GetVersionDescription();
|
||||
}
|
||||
|
||||
|
||||
private ICommand _cameraCommand;
|
||||
public ICommand CameraCommand => _cameraCommand ??= new RelayCommand(CameraChanged);
|
||||
|
||||
private ICommand _audioCommand;
|
||||
public ICommand AudioCommand => _audioCommand ??= new RelayCommand(AudioChanged);
|
||||
public ElementTheme ElementTheme
|
||||
{
|
||||
get => _elementTheme;
|
||||
@@ -44,6 +71,46 @@ public class SettingsViewModel : ObservableRecipient, INavigationAware
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选中的相机
|
||||
/// </summary>
|
||||
public ComboxItemModel CameraSelect
|
||||
{
|
||||
get => _cameraSelect;
|
||||
set => SetProperty(ref _cameraSelect, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中的音频设备
|
||||
/// </summary>
|
||||
public ComboxItemModel AudioSelect
|
||||
{
|
||||
get => _audioSelect;
|
||||
set => SetProperty(ref _audioSelect, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 相机列表
|
||||
/// </summary>
|
||||
public ObservableCollection<ComboxItemModel> Cameras
|
||||
{
|
||||
get => _cameras;
|
||||
set => SetProperty(ref _cameras, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 音频设备列表
|
||||
/// </summary>
|
||||
public ObservableCollection<ComboxItemModel> AudioDevs
|
||||
{
|
||||
get => _audioDevs;
|
||||
set => SetProperty(ref _audioDevs, value);
|
||||
}
|
||||
|
||||
|
||||
private string _versionDescription;
|
||||
|
||||
public string VersionDescription
|
||||
@@ -97,28 +164,64 @@ public class SettingsViewModel : ObservableRecipient, INavigationAware
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsViewModel(
|
||||
IThemeSelectorService themeSelectorService,
|
||||
ILocalSettingsService localSettingsService)
|
||||
/// <summary>
|
||||
/// 音频切换方法
|
||||
/// </summary>
|
||||
private async void AudioChanged()
|
||||
{
|
||||
_themeSelectorService = themeSelectorService;
|
||||
_elementTheme = _themeSelectorService.Theme;
|
||||
_localSettingsService = localSettingsService;
|
||||
VersionDescription = GetVersionDescription();
|
||||
var audioName = _audioSelect?.DataKey;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(audioName))
|
||||
{
|
||||
await _localSettingsService.SaveSettingAsync(Constants.DefaultAudioNameKey, _audioSelect);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 相机选择方法
|
||||
/// </summary>
|
||||
private async void CameraChanged()
|
||||
{
|
||||
var cameraName = _cameraSelect?.DataKey;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(cameraName))
|
||||
{
|
||||
await _localSettingsService.SaveSettingAsync(Constants.DefaultCameraNameKey, _cameraSelect);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InitAsync()
|
||||
{
|
||||
//var ret = await _localSettingsService
|
||||
// .ReadSettingAsync<string>(Constants.CustomClockTitleKey);
|
||||
|
||||
//CustomClockTitle = ret ?? "";
|
||||
try
|
||||
{
|
||||
var ret2 = await _localSettingsService
|
||||
.ReadSettingAsync<CustomClockTitleConfig>(Constants.CustomClockTitleConfigKey);
|
||||
|
||||
ClockTitleConfig = ret2 ?? new CustomClockTitleConfig();
|
||||
|
||||
var camera = await EbHelper.FindCameraDeviceListAsync();
|
||||
|
||||
Cameras = new ObservableCollection<ComboxItemModel>(camera);
|
||||
|
||||
|
||||
var audioDevs = await EbHelper.FindAudioDeviceListAsync();
|
||||
|
||||
AudioDevs = new ObservableCollection<ComboxItemModel>(audioDevs);
|
||||
|
||||
var cameraModel = await _localSettingsService
|
||||
.ReadSettingAsync<ComboxItemModel>(Constants.DefaultCameraNameKey);
|
||||
|
||||
if (cameraModel != null)
|
||||
{
|
||||
CameraSelect = Cameras.FirstOrDefault(c => c.DataValue == cameraModel.DataValue);
|
||||
|
||||
}
|
||||
|
||||
var audioModel = await _localSettingsService
|
||||
.ReadSettingAsync<ComboxItemModel>(Constants.DefaultAudioNameKey);
|
||||
|
||||
if (audioModel != null)
|
||||
{
|
||||
AudioSelect = AudioDevs.FirstOrDefault(c => c.DataValue == audioModel.DataValue);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
+85
-15
@@ -13,8 +13,9 @@
|
||||
<helpers:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
|
||||
</Page.Resources>
|
||||
<Grid>
|
||||
<StackPanel x:Name="ContentArea">
|
||||
<ScrollViewer>
|
||||
<ScrollViewer>
|
||||
<StackPanel x:Name="ContentArea">
|
||||
|
||||
<StackPanel>
|
||||
<Expander
|
||||
Width="800"
|
||||
@@ -84,7 +85,7 @@
|
||||
|
||||
<Expander
|
||||
Width="800"
|
||||
Margin="0,8,0,24"
|
||||
Margin="0,8,0,4"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalContentAlignment="Left"
|
||||
ExpandDirection="Down"
|
||||
@@ -166,28 +167,97 @@
|
||||
|
||||
|
||||
</StackPanel>
|
||||
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Expander>
|
||||
|
||||
<Expander
|
||||
Width="800"
|
||||
Margin="0,8,0,24"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalContentAlignment="Left"
|
||||
ExpandDirection="Down"
|
||||
IsExpanded="False">
|
||||
<Expander.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border Margin="4,4,12,4">
|
||||
<FontIcon FontFamily="/Assets/Font/Segoe Fluent Icons.ttf#Segoe Fluent Icons" Glyph="" />
|
||||
</Border>
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Margin="0,4,0,4" FontSize="16">默认设备设置</TextBlock>
|
||||
<TextBlock Margin="0,0,0,4" FontSize="12">
|
||||
设置相关默认设备
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</Expander.HeaderTemplate>
|
||||
<Grid>
|
||||
<StackPanel Margin="{StaticResource SmallTopBottomMargin}">
|
||||
<!--<TextBlock x:Uid="Settings_Theme" />-->
|
||||
|
||||
<StackPanel Margin="{StaticResource XSmallTopMargin}">
|
||||
<ComboBox
|
||||
x:Uid="CameraCB"
|
||||
Width="240"
|
||||
Margin="0,0,0,8"
|
||||
DisplayMemberPath="DataValue"
|
||||
Header="默认相机"
|
||||
ItemsSource="{x:Bind ViewModel.Cameras, Mode=OneWay}"
|
||||
PlaceholderText="默认相机"
|
||||
SelectedItem="{x:Bind ViewModel.CameraSelect, Mode=TwoWay}">
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:EventTriggerBehavior EventName="SelectionChanged">
|
||||
<ic:InvokeCommandAction Command="{x:Bind ViewModel.CameraCommand}" />
|
||||
</ic:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
</ComboBox>
|
||||
<ComboBox
|
||||
x:Uid="AudioCB"
|
||||
Width="240"
|
||||
DisplayMemberPath="DataValue"
|
||||
Header="默认音频设备"
|
||||
ItemsSource="{x:Bind ViewModel.AudioDevs, Mode=OneWay}"
|
||||
PlaceholderText="默认音频设备"
|
||||
SelectedItem="{x:Bind ViewModel.AudioSelect, Mode=TwoWay}">
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:EventTriggerBehavior EventName="SelectionChanged">
|
||||
<ic:InvokeCommandAction Command="{x:Bind ViewModel.AudioCommand}" />
|
||||
</ic:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Expander>
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
|
||||
|
||||
|
||||
<TextBlock x:Uid="Settings_About" Style="{ThemeResource SubtitleTextBlockStyle}" />
|
||||
|
||||
<StackPanel Margin="{StaticResource XSmallTopMargin}">
|
||||
<TextBlock Style="{ThemeResource BodyTextBlockStyle}" Text="{x:Bind ViewModel.VersionDescription, Mode=OneWay}" />
|
||||
<TextBlock x:Uid="Settings_About" Style="{ThemeResource SubtitleTextBlockStyle}" />
|
||||
|
||||
<TextBlock
|
||||
x:Uid="Settings_AboutDescription"
|
||||
MaxWidth="500"
|
||||
Margin="{StaticResource XSmallTopMargin}"
|
||||
HorizontalAlignment="Left"
|
||||
Style="{ThemeResource BodyTextBlockStyle}" />
|
||||
<HyperlinkButton x:Uid="SettingsPage_PrivacyTermsLink" Margin="{StaticResource SettingsPageHyperlinkButtonMargin}" />
|
||||
<StackPanel Margin="{StaticResource XSmallTopMargin}">
|
||||
<TextBlock Style="{ThemeResource BodyTextBlockStyle}" Text="{x:Bind ViewModel.VersionDescription, Mode=OneWay}" />
|
||||
|
||||
<TextBlock
|
||||
x:Uid="Settings_AboutDescription"
|
||||
MaxWidth="500"
|
||||
Margin="{StaticResource XSmallTopMargin}"
|
||||
HorizontalAlignment="Left"
|
||||
Style="{ThemeResource BodyTextBlockStyle}" />
|
||||
<HyperlinkButton x:Uid="SettingsPage_PrivacyTermsLink" Margin="{StaticResource SettingsPageHyperlinkButtonMargin}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
Reference in New Issue
Block a user