mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-28 20:57:53 +08:00
add launch app page
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user