6944db8ab4
Core MainViewModel.cs 758 -> 495 lines. Moved the source add/remove/image block (AddSource, NextSourceName, AddImage, BuildImageCandidates, PickImageBytes, AddAsset, AddImageSource, AddReusedImage, RemoveElement) into a new MainViewModel.Sources.cs partial, and WebView2 source hosting (RegisterLoadedWebSources, InitWebView2, OnWebView2PreviewBitmapChanged) into a new MainViewModel.Web.cs partial. Pruned now-dead usings from core. Zero behavior change; build 0 warnings; 246 pass, only the 2 known failures. Docs: ViewModels/index.md Phase 3 tracker updated in same commit.
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.Linq;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media.Imaging;
|
|
using ytLive.Models;
|
|
using ytLive.Services;
|
|
using ytLive.ViewModels;
|
|
|
|
namespace ytLive.ViewModels;
|
|
|
|
public partial class MainViewModel
|
|
{
|
|
private void RegisterLoadedWebSources()
|
|
{
|
|
if (_webView2Manager == null) return;
|
|
|
|
foreach (var source in Scenes.SelectMany(s => s.Elements).OfType<Source>()
|
|
.Where(s => s.Type == SourceType.WebSource))
|
|
{
|
|
_webView2Manager.Register(source);
|
|
source.PropertyChanged += (_, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(Source.WebUri))
|
|
_webView2Manager.OnWebUriChanged(source);
|
|
};
|
|
}
|
|
}
|
|
|
|
public void InitWebView2(Panel hostPanel)
|
|
{
|
|
_webView2Manager = new WebView2Manager(hostPanel, System.Windows.Application.Current.Dispatcher);
|
|
_webView2Manager.PreviewBitmapChanged += OnWebView2PreviewBitmapChanged;
|
|
RegisterLoadedWebSources();
|
|
}
|
|
|
|
private void OnWebView2PreviewBitmapChanged(string sourceId, WriteableBitmap bitmap)
|
|
{
|
|
foreach (var scene in Scenes)
|
|
foreach (var el in scene.Elements.OfType<Source>().Where(s => s.Id == sourceId))
|
|
el.VideoImageSource = bitmap;
|
|
}
|
|
}
|