mirror of
https://onedev.site.tesses.net/tesses-framework/tessesframework-webapp
synced 2026-02-08 08:25:46 +00:00
First Commit
This commit is contained in:
99
src/lib.cpp
Normal file
99
src/lib.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user