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;
|
2021-12-27 00:38:44 +00:00
|
|
|
|
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;
|
2022-01-03 22:46:28 +00:00
|
|
|
|
using Wabbajack.Messages;
|
|
|
|
|
using Wabbajack.Models;
|
2021-12-30 00:15:37 +00:00
|
|
|
|
using Wabbajack.WebAutomation;
|
2021-12-26 21:56:44 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public class WebBrowserVM : ViewModel, IBackNavigatingVM, IDisposable
|
|
|
|
|
{
|
2022-01-03 22:46:28 +00:00
|
|
|
|
private readonly ILogger<WebBrowserVM> _logger;
|
|
|
|
|
private readonly CefService _cefService;
|
2021-12-27 00:38:44 +00:00
|
|
|
|
|
2021-12-26 21:56:44 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public string Instructions { get; set; }
|
|
|
|
|
|
2022-01-03 22:46:28 +00:00
|
|
|
|
public IWebBrowser Browser { get; }
|
|
|
|
|
public CefSharpWrapper Driver { get; set; }
|
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; }
|
|
|
|
|
|
2022-01-03 22:46:28 +00:00
|
|
|
|
public WebBrowserVM(ILogger<WebBrowserVM> logger, CefService cefService)
|
2021-12-26 21:56:44 +00:00
|
|
|
|
{
|
2022-01-03 22:46:28 +00:00
|
|
|
|
// CefService is required so that Cef is initalized
|
2021-12-27 00:38:44 +00:00
|
|
|
|
_logger = logger;
|
2022-01-03 22:46:28 +00:00
|
|
|
|
_cefService = cefService;
|
2021-12-26 21:56:44 +00:00
|
|
|
|
Instructions = "Wabbajack Web Browser";
|
2022-01-03 22:46:28 +00:00
|
|
|
|
|
|
|
|
|
BackCommand = ReactiveCommand.Create(NavigateBack.Send);
|
|
|
|
|
Browser = cefService.CreateBrowser();
|
2022-01-04 21:16:53 +00:00
|
|
|
|
Driver = new CefSharpWrapper(_logger, Browser, cefService);
|
2021-12-26 21:56:44 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Browser.Dispose();
|
|
|
|
|
base.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|