wabbajack/Wabbajack.App.Wpf/View Models/WebBrowserVM.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2021-12-26 21:56:44 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
using CefSharp;
using CefSharp.Wpf;
using Microsoft.Extensions.Logging;
2021-12-26 21:56:44 +00:00
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
2021-12-30 00:15:37 +00:00
using Wabbajack;
using Wabbajack.LibCefHelpers;
using Wabbajack.WebAutomation;
2021-12-26 21:56:44 +00:00
namespace Wabbajack
{
public class WebBrowserVM : ViewModel, IBackNavigatingVM, IDisposable
{
private readonly ILogger _logger;
2021-12-26 21:56:44 +00:00
[Reactive]
public string Instructions { get; set; }
public IWebBrowser Browser { get; } = new ChromiumWebBrowser();
public CefSharpWrapper Driver => new(_logger, Browser);
2021-12-26 21:56:44 +00:00
[Reactive]
public ViewModel NavigateBackTarget { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> BackCommand { get; set; }
public Subject<bool> IsBackEnabledSubject { get; } = new Subject<bool>();
public IObservable<bool> IsBackEnabled { get; }
private WebBrowserVM(ILogger logger, string url = "http://www.wabbajack.org")
2021-12-26 21:56:44 +00:00
{
_logger = logger;
2021-12-26 21:56:44 +00:00
IsBackEnabled = IsBackEnabledSubject.StartWith(true);
Instructions = "Wabbajack Web Browser";
}
public static async Task<WebBrowserVM> GetNew(ILogger logger, string url = "http://www.wabbajack.org")
2021-12-26 21:56:44 +00:00
{
// Make sure libraries are extracted first
return new WebBrowserVM(logger, url);
2021-12-26 21:56:44 +00:00
}
public override void Dispose()
{
Browser.Dispose();
base.Dispose();
}
}
}