add launch app page

This commit is contained in:
张广建
2023-09-28 12:06:24 +08:00
parent 4fce67eaa2
commit b60bbede0f
8 changed files with 415 additions and 13 deletions
+3
View File
@@ -157,6 +157,9 @@ public partial class App : Application
services.AddTransient<RandomContentPage>();
services.AddTransient<RandomContentViewModel>();
services.AddTransient<LaunchAppPage>();
services.AddTransient<LaunchAppViewModel>();
services.AddTransient<EmojisInfoDialogViewModel>();
services.AddTransient<GamepadViewModel>();
+2
View File
@@ -18,6 +18,8 @@ public class Constants
public const string RandomContentListKey = "RandomContentListKey";
public const string LaunchAppListKey = "LaunchAppListKey";
public const string EmojisFolder = "EmojisAction";
public const string EmojisTempFileFolder = "EmojisFileTemp";
@@ -0,0 +1,112 @@
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
<!-- Licensed under the MIT License. -->
<Page
x:Class="Controls.LaunchAppPage"
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:data="using:ElectronBot.Braincase.Core.Models"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
xmlns:local="using:Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:package="using:Windows.ApplicationModel"
MinWidth="400"
MinHeight="300"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
CornerRadius="8"
mc:Ignorable="d">
<Grid>
<ScrollViewer>
<Grid
Width="800"
Height="600"
Margin="12">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock
Width="100"
VerticalAlignment="Center"
Text="应用类型:" />
<RadioButtons
x:Uid="ModeRadioBtn"
MaxColumns="4"
SelectedIndex="0"
SelectionChanged="{x:Bind ViewModel.RadioButtons_SelectionChanged}">
<RadioButton Content="Msix类型" />
<RadioButton Content="Win32类型" />
</RadioButtons>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock
Width="100"
VerticalAlignment="Center"
Text="唤醒关键词:" />
<TextBox
Width="280"
Margin="4"
Text="{x:Bind ViewModel.VoiceText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="NoWrap" />
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{x:Bind ViewModel.Win32PathVisibility, Mode=OneWay}">
<TextBlock
Width="100"
VerticalAlignment="Center"
Text="选取应用路径:" />
<Button
x:Uid="EmojisAvatarAddBtn"
Margin="4"
Command="{x:Bind ViewModel.AddWin32AppPathCommand}">
<FontIcon
FontFamily="/Assets/Font/Segoe Fluent Icons.ttf#Segoe Fluent Icons"
FontSize="48"
Glyph="&#xE158;" />
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{x:Bind ViewModel.Win32PathVisibility, Mode=OneWay}">
<TextBlock
Width="100"
VerticalAlignment="Center"
Text="应用路径:" />
<TextBox
Width="280"
Margin="4"
IsReadOnly="True"
Text="{x:Bind ViewModel.Win32Path, Mode=OneWay}"
TextWrapping="NoWrap" />
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{x:Bind ViewModel.MsixVisibility, Mode=OneWay}">
<TextBlock
Width="100"
VerticalAlignment="Center"
Text="Msix应用选择:" />
<ComboBox
x:Uid="ChangeClockViewCB"
Width="120"
Margin="4"
VerticalAlignment="Center"
IsEditable="True"
ItemsSource="{x:Bind ViewModel.AppPackages, Mode=OneWay}"
SelectedItem="{x:Bind ViewModel.SelectPackage, Mode=TwoWay}"
SelectionChanged="{x:Bind ViewModel.Selector_OnSelectionChanged}"
TextSubmitted="{x:Bind ViewModel.ComboBox_OnTextSubmitted}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="package:Package">
<TextBlock Text="{x:Bind DisplayName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
<!--<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="SelectionChanged">
<ic:InvokeCommandAction Command="{x:Bind ViewModel.SaveLaunchAppCommand}" />
</ic:EventTriggerBehavior>
</i:Interaction.Behaviors>-->
</ComboBox>
</StackPanel>
</StackPanel>
</Grid>
</ScrollViewer>
</Grid>
</Page>
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
using ElectronBot.Braincase;
using ElectronBot.Braincase.ViewModels;
using Microsoft.UI.Xaml.Controls;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace Controls
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class LaunchAppPage : Page
{
public LaunchAppViewModel ViewModel
{
get;
}
public LaunchAppPage()
{
ViewModel = App.GetService<LaunchAppViewModel>();
this.InitializeComponent();
}
}
}
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<RootNamespace>ElectronBot.Braincase</RootNamespace>
<ApplicationIcon>Assets/WindowIcon.ico</ApplicationIcon>
@@ -71,6 +71,7 @@
<None Remove="Controls\EmojisInfoContentDialog.xaml" />
<None Remove="Controls\EmojisInfoPage.xaml" />
<None Remove="Controls\GestureAppConfigItems.xaml" />
<None Remove="Controls\LaunchAppPage.xaml" />
<None Remove="Controls\MarketplacePage.xaml" />
<None Remove="Controls\RandomContentPage.xaml" />
<None Remove="Controls\UploadEmojisPage.xaml" />
@@ -242,14 +243,14 @@
<PackageReference Include="CommunityToolkit.WinUI.Helpers" Version="8.0.230907" />
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.16.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.5.1" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.1.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.230913002" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.8.0.20230708" />
<PackageReference Include="OpenCvSharp4.Windows" Version="4.8.0.20230708" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Management" Version="7.0.2" />
<PackageReference Include="WinUIEx" Version="2.3.0" />
<PackageReference Include="WinUIEx" Version="2.3.1" />
<PackageReference Include="HelixToolkit" Version="2.24.0" />
<PackageReference Include="HelixToolkit.SharpDX.Assimp" Version="2.24.0" />
<PackageReference Include="HelixToolkit.SharpDX.Core" Version="2.24.0" />
@@ -338,6 +339,9 @@
<Page Update="Controls\GestureAppConfigItems.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Controls\LaunchAppPage.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="Views\GestureAppConfigPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
@@ -4,16 +4,21 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Input;
using Windows.ApplicationModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ElectronBot.Braincase.Contracts.Services;
using ElectronBot.Braincase.Contracts.ViewModels;
using ElectronBot.Braincase.Helpers;
using ElectronBot.Braincase.Models;
using Windows.Management.Deployment;
using Controls;
using Microsoft.UI.Xaml.Controls;
using ElectronBot.Braincase.Core.Models;
namespace ElectronBot.Braincase.ViewModels;
public partial class GestureAppConfigViewModel : ObservableRecipient
public partial class GestureAppConfigViewModel : ObservableRecipient,INavigationAware
{
private readonly ILocalSettingsService _localSettingsService;
@@ -24,6 +29,8 @@ public partial class GestureAppConfigViewModel : ObservableRecipient
set => SetProperty(ref _gestureAppConfigs, value);
}
private readonly PackageManager _packageManager = new();
public List<string> GestureLabels { get; set; } = new()
{
Constants.Land,
@@ -38,6 +45,7 @@ public partial class GestureAppConfigViewModel : ObservableRecipient
Constants.ThirdFinger,
};
[ObservableProperty] private ObservableCollection<Package> _appPackages;
public GestureAppConfigViewModel(ILocalSettingsService localSettingsService)
{
_localSettingsService = localSettingsService;
@@ -114,4 +122,51 @@ public partial class GestureAppConfigViewModel : ObservableRecipient
};
GestureAppConfigs.Add(gestureAppConfig);
}
[RelayCommand]
public async Task AddLaunchApp()
{
try
{
var theme = App.GetService<IThemeSelectorService>();
var addLaunchApDialog = new ContentDialog()
{
Title = "AddRandomContentTitle".GetLocalized(),
PrimaryButtonText = "AddEmojisOkBtnContent".GetLocalized(),
CloseButtonText = "AddEmojisCancelBtnContent".GetLocalized(),
DefaultButton = ContentDialogButton.Primary,
XamlRoot = App.MainWindow.Content.XamlRoot,
Content = new LaunchAppPage(),
RequestedTheme = theme.Theme
};
addLaunchApDialog.Closed += LaunchAppDialog_Closed;
await addLaunchApDialog.ShowAsync();
}
catch
{
}
}
private async void LaunchAppDialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args)
{
var list = (await _localSettingsService.ReadSettingAsync<List<RandomContent>>(Constants.LaunchAppListKey)) ?? new List<RandomContent>();
}
public void OnNavigatedTo(object parameter)
{
Task.Run(() =>
{
var apps = _packageManager.FindPackagesForUser(string.Empty)
.Where(p => p.IsFramework == false && !string.IsNullOrEmpty(p.DisplayName)).ToList();
App.MainWindow.DispatcherQueue.TryEnqueue(() => AppPackages = new ObservableCollection<Package>(apps));
});
}
public void OnNavigatedFrom()
{
}
}
@@ -0,0 +1,126 @@
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Windows.ApplicationModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ElectronBot.Braincase.Contracts.Services;
using ElectronBot.Braincase.Controls;
using ElectronBot.Braincase.Helpers;
using ElectronBot.Braincase.Models;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
using Services;
using Windows.Management.Deployment;
using Windows.Storage;
namespace ElectronBot.Braincase.ViewModels;
public partial class LaunchAppViewModel : ObservableRecipient
{
private readonly PackageManager _packageManager = new();
[ObservableProperty] private ObservableCollection<Package> _appPackages;
[ObservableProperty] private string _win32Path;
[ObservableProperty] private string _VoiceText;
[ObservableProperty] private Package _selectPackage;
private readonly ILocalSettingsService _localSettingsService;
public LaunchAppViewModel(ILocalSettingsService localSettingsService)
{
_localSettingsService = localSettingsService;
}
public void ComboBox_OnTextSubmitted(ComboBox sender, ComboBoxTextSubmittedEventArgs args)
{
if(args.Text is not null)
{
var text = args.Text;
var apps = _packageManager.FindPackagesForUser(string.Empty)
.Where(p => p.IsFramework == false && p.DisplayName.Contains(text)).ToList();
App.MainWindow.DispatcherQueue.TryEnqueue(() => AppPackages = new ObservableCollection<Package>(apps));
}
else
{
Task.Run(() =>
{
var apps = _packageManager.FindPackagesForUser(string.Empty)
.Where(p => p.IsFramework == false && !string.IsNullOrEmpty(p.DisplayName)).ToList();
App.MainWindow.DispatcherQueue.TryEnqueue(() => AppPackages = new ObservableCollection<Package>(apps));
});
}
}
public void RadioButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var radioButtons = (RadioButtons)sender;
if (radioButtons.SelectedIndex == 0)
{
Win32PathVisibility = Visibility.Collapsed;
MsixVisibility = Visibility.Visible;
Task.Run(() =>
{
var apps = _packageManager.FindPackagesForUser(string.Empty)
.Where(p => p.IsFramework == false && !string.IsNullOrEmpty(p.DisplayName)).ToList();
App.MainWindow.DispatcherQueue.TryEnqueue(() => AppPackages = new ObservableCollection<Package>(apps));
});
}
else
{
Win32PathVisibility = Visibility.Visible;
MsixVisibility = Visibility.Collapsed;
}
}
[ObservableProperty] private Visibility _win32PathVisibility = Visibility.Collapsed;
[ObservableProperty] private Visibility _msixVisibility = Visibility.Visible;
[RelayCommand]
private async Task AddWin32AppPath()
{
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow);
var picker = new Windows.Storage.Pickers.FileOpenPicker
{
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
};
picker.FileTypeFilter.Add(".exe");
WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd);
var file = await picker.PickSingleFileAsync();
if (file is null)
{
return;
}
var propList = await file.GetBasicPropertiesAsync();
Win32Path = file.Path;
}
public void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
[RelayCommand]
private async Task SaveLaunchApp()
{
}
}
@@ -9,19 +9,90 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
xmlns:package="using:Windows.ApplicationModel"
mc:Ignorable="d">
<Grid>
<Grid x:Name="ContentArea">
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Margin="3" Orientation="Horizontal">
<Button x:Uid="GestureAppConfig_Add" HorizontalAlignment="Left" Command="{x:Bind ViewModel.AddConfigCommand}" />
<Button x:Uid="GestureAppConfig_Save" Margin="7,0,0,0" HorizontalAlignment="Left" Command="{x:Bind ViewModel.SaveConfigCommand}" />
<StackPanel>
<AppBarButton
x:Uid="AddRandomContentBtn"
HorizontalAlignment="Right"
Command="{x:Bind ViewModel.AddLaunchAppCommand}"
Foreground="{ThemeResource SystemAccentColor}">
<AppBarButton.Icon>
<FontIcon
FontFamily="/Assets/Font/Segoe Fluent Icons.ttf#Segoe Fluent Icons"
FontWeight="Bold"
Glyph="&#xECC8;" />
</AppBarButton.Icon>
</AppBarButton>
</StackPanel>
<StackPanel Grid.Row="1" HorizontalAlignment="Center">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Margin="3" Orientation="Horizontal">
<Button
x:Uid="GestureAppConfig_Add"
HorizontalAlignment="Left"
Command="{x:Bind ViewModel.AddConfigCommand}" />
<Button
x:Uid="GestureAppConfig_Save"
Margin="7,0,0,0"
HorizontalAlignment="Left"
Command="{x:Bind ViewModel.SaveConfigCommand}" />
</StackPanel>
<ScrollViewer Grid.Row="1">
<StackPanel>
<cusControl:GestureAppConfigItems
DeleteItemCommand="{x:Bind ViewModel.DelConfigCommand}"
GestureLabels="{x:Bind ViewModel.GestureLabels}"
ItemsSource="{x:Bind ViewModel.GestureAppConfigs, Mode=TwoWay}" />
<ListView ItemsSource="{x:Bind ViewModel.AppPackages, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="package:Package">
<Grid Margin="0,12,0,12" AutomationProperties.Name="{x:Bind DisplayName}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="150" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" Margin="12,0,0,0">
<TextBlock
Margin="0,0,0,6"
HorizontalAlignment="Left"
FontSize="14"
FontWeight="SemiBold"
LineHeight="20"
Style="{ThemeResource BaseTextBlockStyle}"
Text="{x:Bind DisplayName}" />
<TextBlock
Width="350"
HorizontalAlignment="Left"
FontFamily="/Assets/Font/SmileySans-Oblique.ttf#得意黑"
FontWeight="Normal"
MaxLines="1"
Text="{x:Bind Description}"
TextTrimming="CharacterEllipsis" />
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="0,0,0,0"
HorizontalAlignment="Left"
Style="{ThemeResource CaptionTextBlockStyle}"
Text="{x:Bind InstalledDate}" />
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</ScrollViewer>
</Grid>
</StackPanel>
<ScrollViewer Grid.Row="1">
<cusControl:GestureAppConfigItems DeleteItemCommand="{x:Bind ViewModel.DelConfigCommand}" GestureLabels="{x:Bind ViewModel.GestureLabels}" ItemsSource="{x:Bind ViewModel.GestureAppConfigs, Mode=TwoWay}" />
</ScrollViewer>
</Grid>
</Page>