Repository: jfversluis/Plugin.Maui.ScreenRecording
Pull request #24: Windows support
Author: login: cheburashkalev
Created: 2025-04-26T21:35:49Z | Merged: 2025-05-14T09:44:16Z

#6 


Diff:
diff --git a/samples/ScreenRecordingSample/ScreenRecordingSample.csproj b/samples/ScreenRecordingSample/ScreenRecordingSample.csproj
index 8665640..b82f91e 100644
--- a/samples/ScreenRecordingSample/ScreenRecordingSample.csproj
+++ b/samples/ScreenRecordingSample/ScreenRecordingSample.csproj
@@ -2,7 +2,7 @@
 
 	<PropertyGroup>
 		<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
-		<!--<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>-->
+		<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
 		<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
 		<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
 		<OutputType>Exe</OutputType>
@@ -48,7 +48,7 @@
 	</ItemGroup>
 
 	<ItemGroup>
-	  <ProjectReference Include="..\..\src\Plugin.Maui.ScreenRecording\Plugin.Maui.ScreenRecording.csproj" />
+		<ProjectReference Include="..\..\src\Plugin.Maui.ScreenRecording\Plugin.Maui.ScreenRecording.csproj" />
 	  <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
 	</ItemGroup>
 </Project>
diff --git a/src/Plugin.Maui.ScreenRecording/Plugin.Maui.ScreenRecording.csproj b/src/Plugin.Maui.ScreenRecording/Plugin.Maui.ScreenRecording.csproj
index 906b55f..63bba48 100644
--- a/src/Plugin.Maui.ScreenRecording/Plugin.Maui.ScreenRecording.csproj
+++ b/src/Plugin.Maui.ScreenRecording/Plugin.Maui.ScreenRecording.csproj
@@ -1,7 +1,8 @@
 ﻿<Project Sdk="Microsoft.NET.Sdk">
 	<PropertyGroup>
 		<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0</TargetFrameworks>
-    <!--<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>-->
+		<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
+		
 		<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
 		<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
 		<SingleProject>true</SingleProject>
@@ -34,8 +35,8 @@
 		<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
 		<DebugType>portable</DebugType>
 		<PackageIcon>icon.png</PackageIcon>
+		<Platforms Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">AnyCPU;x86;x64</Platforms>
 	</PropertyGroup>
-
 	<!-- iOS & MacCatalyst -->
 	<ItemGroup Condition="$(TargetFramework.StartsWith('net')) == true AND $(TargetFramework.Contains('-ios')) != true AND $(TargetFramework.Contains('-maccatalyst')) != true ">
 		<Compile Remove="**\**\*.ios.cs" />
@@ -56,7 +57,8 @@
 	</ItemGroup>
 	<!-- Windows -->
 	<ItemGroup Condition="$(TargetFramework.StartsWith('net')) == true AND $(TargetFramework.Contains('-windows')) != true">
-		<Compile Remove="**\*.windows.cs" />
+		<Compile Remove="**\**\*.windows.cs" />
+		<None Include="**\**\*.windows.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
 		<Compile Remove="**\windows\**\*.cs" />
 		<None Include="**\windows\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
 	</ItemGroup>
@@ -70,11 +72,17 @@
 	<ItemGroup>
 		<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" IsImplicitlyDefined="true" />
 		<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
+		
 	</ItemGroup>
 
 	<!-- Package additions -->
 	<ItemGroup>
 		<None Include="..\..\nuget.png" PackagePath="icon.png" Pack="true" />
 	</ItemGroup>
-
+	<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
+	  <PackageReference Include="ScreenRecorderLib.Levchenko">
+	    <Version>6.5.4</Version>
+	  </PackageReference>
+	</ItemGroup>
+	
 </Project>
diff --git a/src/Plugin.Maui.ScreenRecording/ScreenRecording.windows.cs b/src/Plugin.Maui.ScreenRecording/ScreenRecording.windows.cs
new file mode 100644
index 0000000..b8370db
--- /dev/null
+++ b/src/Plugin.Maui.ScreenRecording/ScreenRecording.windows.cs
@@ -0,0 +1,65 @@
+﻿using System.Diagnostics;
+using ScreenRecorderLib;
+using Windows.Graphics.Capture;
+namespace Plugin.Maui.ScreenRecording;
+
+public partial class ScreenRecordingImplementation : IScreenRecording
+{
+    public ScreenRecordingImplementation()
+    {
+
+    }
+    public bool IsRecording => _IsRecording;
+    private bool _IsRecording { get; set; } = false;
+    public bool IsSupported => GraphicsCaptureSession.IsSupported();
+    private Recorder? rec;
+
+    public async Task<bool> StartRecording(ScreenRecordingOptions? options)
+    {
+        if (!IsSupported)
+            throw new Exception("Screen recording not supported on this device.");
+        var enableMicrophone = options?.EnableMicrophone ?? false;
+
+        var saveOptions = options ?? new();
+        var savePath = saveOptions.SavePath;
+        var filename = $"screenrecording_{DateTime.Now:ddMMyyyy_HHmmss}.mp4";
+        if (string.IsNullOrWhiteSpace(savePath))
+        {
+            savePath = Path.Combine(Path.GetTempPath(), filename);
+        }
+        if (saveOptions.SaveToGallery)
+        {
+            string myVideosPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
+            savePath = Path.Combine(myVideosPath, filename);
+        }
+        var source = DisplayRecordingSource.MainMonitor;
+        source.RecorderApi = RecorderApi.WindowsGraphicsCapture;
+        
+        var opts = new RecorderOptions
+        {
+            SourceOptions = new SourceOptions
+            {
+                RecordingSources = { { source } },
+            },
+            AudioOptions = new AudioOptions { IsInputDeviceEnabled = enableMicrophone, IsOutputDeviceEnabled = true, IsAudioEnabled = true }
+
+        };
+        rec = Recorder.CreateRecorder(opts);
+        rec.OnRecordingComplete += (s, e) =>
+        {
+            path = e.FilePath;
+            Debug.WriteLine("Recording completed");
+            _IsRecording = false;
+        };
+        rec.Record(path = savePath);
+        return true;
+    }
+    private string path { get; set; }
+    public async Task<ScreenRecordingFile?> StopRecording()
+    {
+        rec?.Stop();
+        rec?.Dispose();
+        rec = null;
+        return new(path);
+    }
+}
\ No newline at end of file


Reviews:
user: login: jfversluis
state: CHANGES_REQUESTED
author_association: OWNER
submitted_at: 2025-05-12T13:39:17Z
user: login: jfversluis
state: APPROVED
author_association: OWNER
submitted_at: 2025-05-14T09:34:21Z

Review comments:
diff_hunk: @@ -0,0 +1,259 @@
+# Remove the line below if you want to inherit .editorconfig settings from higher directories
path: src/Plugin.Maui.ScreenRecording/.editorconfig
user: login: jfversluis
body: Lets not add this file, or at least make it another PR
created_at: 2025-05-12T13:37:26Z
author_association: OWNER
diff_hunk: @@ -34,8 +35,10 @@
 		<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
 		<DebugType>portable</DebugType>
 		<PackageIcon>icon.png</PackageIcon>
+		<Platforms Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">AnyCPU;x86;x64</Platforms>
+		<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
+		<Version>1.0.1</Version>
path: src/Plugin.Maui.ScreenRecording/Plugin.Maui.ScreenRecording.csproj
user: login: jfversluis
body: Do we need these?
created_at: 2025-05-12T13:38:14Z
author_association: OWNER
diff_hunk: @@ -70,11 +74,20 @@
 	<ItemGroup>
 		<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" IsImplicitlyDefined="true" />
 		<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
+		
 	</ItemGroup>
 
 	<!-- Package additions -->
 	<ItemGroup>
 		<None Include="..\..\nuget.png" PackagePath="icon.png" Pack="true" />
 	</ItemGroup>
-
+	<ItemGroup>
+	  <EditorConfigFiles Remove="C:\Users\duxan\source\repos\Plugin.Maui.ScreenRecording\Plugin.Maui.ScreenRecording\src\Plugin.Maui.ScreenRecording\.editorconfig" />
+	</ItemGroup>
path: src/Plugin.Maui.ScreenRecording/Plugin.Maui.ScreenRecording.csproj
user: login: jfversluis
body: I don't think we'll be able to use your local file path 😝 

```suggestion
```
created_at: 2025-05-12T13:38:49Z
author_association: OWNER
diff_hunk: @@ -70,11 +74,20 @@
 	<ItemGroup>
 		<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" IsImplicitlyDefined="true" />
 		<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
+		
 	</ItemGroup>
 
 	<!-- Package additions -->
 	<ItemGroup>
 		<None Include="..\..\nuget.png" PackagePath="icon.png" Pack="true" />
 	</ItemGroup>
-
+	<ItemGroup>
+	  <EditorConfigFiles Remove="C:\Users\duxan\source\repos\Plugin.Maui.ScreenRecording\Plugin.Maui.ScreenRecording\src\Plugin.Maui.ScreenRecording\.editorconfig" />
+	</ItemGroup>
+	<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows10.0.19041.0'">
path: src/Plugin.Maui.ScreenRecording/Plugin.Maui.ScreenRecording.csproj
user: login: jfversluis
body: ```suggestion
	<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'>
```
created_at: 2025-05-12T13:39:02Z
author_association: OWNER

PR comments:
user: login: cheburashkalev
created_at: 2025-05-11T16:23:35Z
body: @jfversluis 
author_association: CONTRIBUTOR
user: login: jfversluis
created_at: 2025-05-12T11:20:31Z
body: Sorry, I've been super busy! I'll look into this asap, thank you for this amazing work!
author_association: OWNER
user: login: cheburashkalev
created_at: 2025-05-12T22:10:11Z
body: 🫡done
author_association: CONTRIBUTOR