Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
w-ahmad committed Jul 1, 2024
1 parent ecf099c commit b0852cb
Show file tree
Hide file tree
Showing 21 changed files with 1,585 additions and 1,085 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# BlazorWebView.WinUI3
A clone of WPF BlazorWebView to use in WinUI3
# BlazorWebView.WinUI
Build WinUI apps with Blazor and WebView2.


https://github.com/w-ahmad/BlazorWebView.WinUI3/assets/17172092/ee581dab-cd60-49e8-b11e-ff7ca23784c2
Expand Down
67 changes: 39 additions & 28 deletions src/BlazorWebView.WinUI/AutoCloseOnReadCompleteStream.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
using System.IO;

namespace Microsoft.AspNetCore.Components.WebView.WebView2
namespace Microsoft.AspNetCore.Components.WebView.WebView2;

internal class AutoCloseOnReadCompleteStream : Stream
{
internal class AutoCloseOnReadCompleteStream : Stream
private readonly Stream _baseStream;

public AutoCloseOnReadCompleteStream(Stream baseStream)
{
private readonly Stream _baseStream;
_baseStream = baseStream;
}

public AutoCloseOnReadCompleteStream(Stream baseStream)
{
_baseStream = baseStream;
}
public override bool CanRead => _baseStream.CanRead;

public override bool CanRead => _baseStream.CanRead;
public override bool CanSeek => _baseStream.CanSeek;

public override bool CanSeek => _baseStream.CanSeek;
public override bool CanWrite => _baseStream.CanWrite;

public override bool CanWrite => _baseStream.CanWrite;
public override long Length => _baseStream.Length;

public override long Length => _baseStream.Length;
public override long Position { get => _baseStream.Position; set => _baseStream.Position = value; }

public override long Position { get => _baseStream.Position; set => _baseStream.Position = value; }
public override void Flush()
{
_baseStream.Flush();
}

public override void Flush() => _baseStream.Flush();
public override int Read(byte[] buffer, int offset, int count)
{
var bytesRead = _baseStream.Read(buffer, offset, count);

public override int Read(byte[] buffer, int offset, int count)
// Stream.Read only returns 0 when it has reached the end of stream
// and no further bytes are expected. Otherwise it blocks until
// one or more (and at most count) bytes can be read.
if (bytesRead == 0)
{
var bytesRead = _baseStream.Read(buffer, offset, count);

// Stream.Read only returns 0 when it has reached the end of stream
// and no further bytes are expected. Otherwise it blocks until
// one or more (and at most count) bytes can be read.
if (bytesRead == 0)
{
_baseStream.Close();
}

return bytesRead;
_baseStream.Close();
}

public override long Seek(long offset, SeekOrigin origin) => _baseStream.Seek(offset, origin);
return bytesRead;
}

public override long Seek(long offset, SeekOrigin origin)
{
return _baseStream.Seek(offset, origin);
}

public override void SetLength(long value) => _baseStream.SetLength(value);
public override void SetLength(long value)
{
_baseStream.SetLength(value);
}

public override void Write(byte[] buffer, int offset, int count) => _baseStream.Write(buffer, offset, count);
public override void Write(byte[] buffer, int offset, int count)
{
_baseStream.Write(buffer, offset, count);
}
}
2 changes: 1 addition & 1 deletion src/BlazorWebView.WinUI/BlazorWebView.WinUI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Microsoft.AspNetCore.Components.WebView.WinUI</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
Expand Down
Loading

0 comments on commit b0852cb

Please sign in to comment.