[VCM] Fix issues on certain systems (#12481)

- Don't depend on System.Windows.Forms in the Settings -> use callback instead
- Fix overlay image setting saving
- Use dynamic DLL loading in Interop
- Load VCM only when mf.dll is available
This commit is contained in:
Andrey Nekrasov
2021-07-23 16:59:22 +03:00
committed by GitHub
parent 24a80de2ec
commit d57773e8ef
16 changed files with 121 additions and 38 deletions

View File

@@ -59,10 +59,4 @@
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Windows.Forms.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -8,7 +8,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
@@ -28,10 +28,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private Func<string, int> SendConfigMSG { get; }
private Func<Task<string>> PickFileDialog { get; }
private string _settingsConfigFileFolder = string.Empty;
public VideoConferenceViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
public VideoConferenceViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<Task<string>> pickFileDialog, string configFileSubfolder = "")
{
PickFileDialog = pickFileDialog;
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
@@ -161,21 +165,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
RaisePropertyChanged(nameof(CameraImageOverlayPath));
}
private void SelectOverlayImageAction()
private async void SelectOverlayImageAction()
{
try
{
string pickedImage = null;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Image Files (*.jpeg;*.jpg;*.png)|*.jpeg;*.jpg;*.png";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
pickedImage = openFileDialog.FileName;
}
}
string pickedImage = await PickFileDialog().ConfigureAwait(true);
if (pickedImage != null)
{
CameraImageOverlayPath = pickedImage;
@@ -417,8 +411,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
OnPropertyChanged(propertyName);
SndVideoConferenceSettings outsettings = new SndVideoConferenceSettings(Settings);
SndModuleSettings<SndVideoConferenceSettings> ipcMessage = new SndModuleSettings<SndVideoConferenceSettings>(outsettings);
SendConfigMSG(ipcMessage.ToJsonString());
_settingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
}
}

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
@@ -37,11 +38,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
set { Set(ref isBackEnabled, value); }
}
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern bool FreeLibrary(IntPtr hModule);
public bool IsVideoConferenceBuild
{
get
{
return this != null && File.Exists("modules/VideoConference/VideoConferenceModule.dll");
var mfHandle = LoadLibrary("mf.dll");
bool mfAvailable = mfHandle != null;
if (mfAvailable)
{
FreeLibrary(mfHandle);
}
return this != null && File.Exists("modules/VideoConference/VideoConferenceModule.dll") && mfAvailable;
}
}

View File

@@ -2,9 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
@@ -13,10 +16,24 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{
private VideoConferenceViewModel ViewModel { get; set; }
private static async Task<string> PickFileDialog()
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
((IInitializeWithWindow)(object)openPicker).Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
StorageFile file = await openPicker.PickSingleFileAsync();
return file?.Path;
}
public VideoConferencePage()
{
var settingsUtils = new SettingsUtils();
ViewModel = new VideoConferenceViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
ViewModel = new VideoConferenceViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, PickFileDialog);
DataContext = ViewModel;
InitializeComponent();
}