Fix browser startup
This commit is contained in:
parent
437136804d
commit
f73997e563
@ -31,34 +31,35 @@ public class Mangasee : Connector
|
|||||||
private async void DownloadBrowser()
|
private async void DownloadBrowser()
|
||||||
{
|
{
|
||||||
BrowserFetcher browserFetcher = new BrowserFetcher();
|
BrowserFetcher browserFetcher = new BrowserFetcher();
|
||||||
if (browserFetcher.LocalRevisions().Contains(ChromiumVersion))
|
foreach(string rev in browserFetcher.LocalRevisions().Where(rev => rev != ChromiumVersion))
|
||||||
return;
|
browserFetcher.Remove(rev);
|
||||||
else
|
if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion))
|
||||||
foreach(string rev in browserFetcher.LocalRevisions())
|
|
||||||
browserFetcher.Remove(rev);
|
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser");
|
|
||||||
DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5));
|
|
||||||
browserFetcher.DownloadProgressChanged += async (sender, args) =>
|
|
||||||
{
|
{
|
||||||
double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive);
|
logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser");
|
||||||
if (args.TotalBytesToReceive == args.BytesReceived)
|
DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5));
|
||||||
|
browserFetcher.DownloadProgressChanged += async (sender, args) =>
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), "Browser downloaded. Launching...");
|
double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive);
|
||||||
}
|
if (args.TotalBytesToReceive == args.BytesReceived)
|
||||||
else if (DateTime.Now > last.AddSeconds(5))
|
{
|
||||||
{
|
logger?.WriteLine(this.GetType().ToString(), "Browser downloaded.");
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Browser progress: {currentBytes:P2}");
|
}
|
||||||
last = DateTime.Now;
|
else if (DateTime.Now > last.AddSeconds(5))
|
||||||
}
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Browser download progress: {currentBytes:P2}");
|
||||||
|
last = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
if (!browserFetcher.CanDownloadAsync(ChromiumVersion).Result)
|
if (!browserFetcher.CanDownloadAsync(ChromiumVersion).Result)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Can't download browser version {ChromiumVersion}");
|
logger?.WriteLine(this.GetType().ToString(), $"Can't download browser version {ChromiumVersion}");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
await browserFetcher.DownloadAsync(ChromiumVersion);
|
||||||
}
|
}
|
||||||
await browserFetcher.DownloadAsync(ChromiumVersion);
|
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Starting browser.");
|
||||||
this._browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
this._browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||||
{
|
{
|
||||||
Headless = true,
|
Headless = true,
|
||||||
@ -207,7 +208,8 @@ public class Mangasee : Connector
|
|||||||
logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download...");
|
logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download...");
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
IPage page = _browser.NewPageAsync().Result;
|
IPage page = _browser.NewPageAsync().Result;
|
||||||
IResponse response = page.GoToAsync(chapter.url).Result;
|
IResponse response = page.GoToAsync(chapter.url).Result;
|
||||||
if (response.Ok)
|
if (response.Ok)
|
||||||
|
Loading…
Reference in New Issue
Block a user