2023-10-20 04:59:28 +00:00
|
|
|
using System.Numerics;
|
|
|
|
using FluentFTP.Helpers;
|
2023-10-02 18:49:24 +00:00
|
|
|
using ImGuiNET;
|
|
|
|
|
|
|
|
namespace Shoko;
|
|
|
|
|
|
|
|
class Tab
|
|
|
|
{
|
|
|
|
ProtoHandler Handler;
|
|
|
|
public bool IsOpen = true;
|
|
|
|
Exception Error = null;
|
2023-10-02 22:13:48 +00:00
|
|
|
Stack<Uri> History;
|
2023-10-02 18:49:24 +00:00
|
|
|
|
|
|
|
string txtURL = "";
|
|
|
|
|
|
|
|
public Tab(string url)
|
|
|
|
{
|
2023-10-02 22:13:48 +00:00
|
|
|
History = new Stack<Uri>();
|
2023-10-02 18:49:24 +00:00
|
|
|
Load(url);
|
|
|
|
txtURL = url;
|
|
|
|
}
|
|
|
|
|
2023-10-20 04:59:28 +00:00
|
|
|
public async Task Load(string url)
|
2023-10-02 18:49:24 +00:00
|
|
|
{
|
|
|
|
Error = null;
|
2023-10-02 22:13:48 +00:00
|
|
|
ImGui.SetScrollX(0);
|
|
|
|
ImGui.SetScrollY(0);
|
2023-10-02 18:49:24 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Handler = ProtoHandler.GetHandler(url);
|
|
|
|
Handler.CurrentTab = this;
|
2023-10-02 22:13:48 +00:00
|
|
|
txtURL = Handler.URL.ToString();
|
|
|
|
History.Push(Handler.URL);
|
2023-10-20 04:59:28 +00:00
|
|
|
await Handler.Load();
|
2023-10-02 18:49:24 +00:00
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
{
|
|
|
|
Error = ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-02 22:13:48 +00:00
|
|
|
public void Previous()
|
|
|
|
{
|
|
|
|
if(History.Count > 1)
|
|
|
|
{
|
|
|
|
History.Pop();
|
|
|
|
Load(History.Pop().ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-02 18:49:24 +00:00
|
|
|
public void Render()
|
|
|
|
{
|
|
|
|
var title = txtURL;
|
2023-10-20 04:59:28 +00:00
|
|
|
if(Handler.Media is not null)
|
2023-10-02 18:49:24 +00:00
|
|
|
{
|
2023-10-20 04:59:28 +00:00
|
|
|
title = Handler.Media.Title;
|
2023-10-02 18:49:24 +00:00
|
|
|
}
|
|
|
|
Gui.Window(title+"###"+GetHashCode().ToString(), ref IsOpen, ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.HorizontalScrollbar, ()=>
|
|
|
|
{
|
|
|
|
Gui.MenuBar(()=>{
|
|
|
|
Gui.Menu("File", ()=>{
|
|
|
|
Gui.MenuItem("Close", null, ()=> IsOpen = false);
|
|
|
|
});
|
|
|
|
|
|
|
|
if(Error is null)
|
|
|
|
{
|
2023-10-20 04:59:28 +00:00
|
|
|
if(Handler.IsLoaded)
|
|
|
|
{
|
|
|
|
Handler.MenuBar();
|
|
|
|
if(Handler.Media.IsLoaded)
|
|
|
|
Handler.Media.MenuBar();
|
|
|
|
}
|
2023-10-02 18:49:24 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 22:13:48 +00:00
|
|
|
Gui.Button("<<", ()=>{
|
|
|
|
Previous();
|
|
|
|
});
|
|
|
|
|
2023-10-02 18:49:24 +00:00
|
|
|
ImGui.InputText("##url", ref txtURL, 1024);
|
|
|
|
|
|
|
|
Gui.Button("Go", ()=>{
|
|
|
|
Load(txtURL);
|
|
|
|
});
|
2023-10-20 04:59:28 +00:00
|
|
|
if(!Handler.IsLoaded)
|
|
|
|
{
|
|
|
|
ImGui.Text("Loading...");
|
|
|
|
if(Handler.TotalBytes != 0 && Handler.TotalBytes != Handler.LoadedBytes)
|
|
|
|
ImGui.ProgressBar(Handler.LoadedBytes / Handler.TotalBytes, new Vector2(200, 20),
|
|
|
|
Handler.LoadedBytes.FileSizeToString() + "/" + Handler.TotalBytes.FileSizeToString());
|
|
|
|
}
|
|
|
|
else if(!Handler.Media.IsLoaded)
|
|
|
|
{
|
|
|
|
ImGui.Text("Rendering...");
|
|
|
|
}
|
2023-10-02 18:49:24 +00:00
|
|
|
});
|
|
|
|
if(Error is not null)
|
|
|
|
{
|
|
|
|
ImGui.Text("error: can't load page");
|
|
|
|
ImGui.Text(Error.Message);
|
2023-10-20 04:59:28 +00:00
|
|
|
ImGui.Text(Error.StackTrace);
|
2023-10-02 18:49:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-20 04:59:28 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(Handler.IsLoaded)
|
|
|
|
{
|
|
|
|
if(Handler.Media.IsLoaded)
|
|
|
|
Handler.Media.Render();
|
|
|
|
Handler.Render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
{
|
|
|
|
ImGui.Text("error: can't render page");
|
|
|
|
ImGui.Text(ex.Message);
|
|
|
|
ImGui.Text(ex.StackTrace);
|
|
|
|
}
|
2023-10-02 18:49:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|