First Commit

This commit is contained in:
2025-10-14 23:17:27 -05:00
commit f5890d070f
6 changed files with 243 additions and 0 deletions

99
src/lib.cpp Normal file
View File

@@ -0,0 +1,99 @@
#include "TF_WebApp.hpp"
#include "webview/webview.h"
namespace Tesses::Framework {
static std::string wv_title;
static webview::webview* wv_hdl=nullptr;
static Tesses::Framework::Threading::Mutex wv_mtx;
void TF_WebAppSetTitle(std::string title)
{
wv_mtx.Lock();
wv_title = title;
if(wv_hdl != nullptr)
{
wv_hdl->dispatch([title]()->void {
wv_hdl->set_title(title);
});
}
wv_mtx.Unlock();
}
#if defined(_WIN32)
int TF_Main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd, std::function<std::shared_ptr<Tesses::Framework::Http::IHttpServer>(std::vector<std::string>& args)> cb, std::function<void(std::shared_ptr<Tesses::Framework::Http::IHttpServer>)> clo)
#else
int TF_Main(int argc, char** argv, std::function<std::shared_ptr<Tesses::Framework::Http::IHttpServer>(std::vector<std::string>& args)> cb, std::function<void(std::shared_ptr<Tesses::Framework::Http::IHttpServer>)> clo)
#endif
{
TF_InitWithConsole();
std::vector<std::string> args;
#if defined(_WIN32)
auto winargs = GetCommandLineW();
int argc=0;
auto argv = CommandLineToArgvW(
winargs,
&argc
);
for(int i = 0; i < argc; i++)
{
std::u16string str = (const char16_t*)argv[i];
std::string utf8;
Tesses::Framework::Text::StringConverter::UTF8::FromUTF16(utf8,str);
args.push_back(utf8);
}
LocalFree(argv);
#else
for(int i = 0; i < argc; i++)
{
args.push_back(argv[i]);
}
#endif
{
auto req = cb(args);
if(req)
{
Tesses::Framework::Http::HttpServer svr(0,req,false);
svr.StartAccepting();
auto port = svr.GetPort();
std::string url = "http://127.0.0.1:" + std::to_string((int)port) + "/";
webview::webview w(false, nullptr);
wv_mtx.Lock();
wv_hdl = &w;
w.set_title(wv_title);
wv_mtx.Unlock();
w.set_size(480, 320, WEBVIEW_HINT_NONE);
w.navigate(url);
w.run();
wv_mtx.Lock();
wv_mtx.Unlock();
}
else {
if(clo)
clo(req);
TF_Quit();
return 1;
}
if(clo)
clo(req);
}
TF_Quit();
return 0;
}
}