diff --git a/build/Release/.deps/Release/obj.target/addon/src/addon.o.d b/build/Release/.deps/Release/obj.target/addon/src/addon.o.d index 2df7ccd..50af8e0 100644 --- a/build/Release/.deps/Release/obj.target/addon/src/addon.o.d +++ b/build/Release/.deps/Release/obj.target/addon/src/addon.o.d @@ -728,7 +728,8 @@ Release/obj.target/addon/src/addon.o: ../src/addon.cc \ /usr/include/webkitgtk-4.0/webkit2/WebKitUserContentFilterStore.h \ /usr/include/webkitgtk-4.0/webkit2/WebKitUserMediaPermissionRequest.h \ /usr/include/webkitgtk-4.0/webkit2/WebKitVersion.h \ - /usr/include/webkitgtk-4.0/webkit2/WebKitAutocleanups.h + /usr/include/webkitgtk-4.0/webkit2/WebKitAutocleanups.h \ + ../src/windowworker.h ../src/addon.cc: /home/rafi/Projects/stuff_builder/node_modules/node-addon-api/napi.h: /home/rafi/.cache/node-gyp/12.16.3/include/node/node_api.h: @@ -1499,3 +1500,4 @@ Release/obj.target/addon/src/addon.o: ../src/addon.cc \ /usr/include/webkitgtk-4.0/webkit2/WebKitUserMediaPermissionRequest.h: /usr/include/webkitgtk-4.0/webkit2/WebKitVersion.h: /usr/include/webkitgtk-4.0/webkit2/WebKitAutocleanups.h: +../src/windowworker.h: diff --git a/build/Release/addon.node b/build/Release/addon.node index 6761b11..48ef9d2 100755 Binary files a/build/Release/addon.node and b/build/Release/addon.node differ diff --git a/build/Release/obj.target/addon.node b/build/Release/obj.target/addon.node index 6761b11..48ef9d2 100755 Binary files a/build/Release/obj.target/addon.node and b/build/Release/obj.target/addon.node differ diff --git a/build/Release/obj.target/addon/src/addon.o b/build/Release/obj.target/addon/src/addon.o index b617da0..3271371 100644 Binary files a/build/Release/obj.target/addon/src/addon.o and b/build/Release/obj.target/addon/src/addon.o differ diff --git a/example.js b/example.js index b550e65..9c87dff 100644 --- a/example.js +++ b/example.js @@ -1,4 +1,4 @@ -const Tiny = require("tinytron") +const Tiny = require("./index"); const window = new Tiny(); window.setSize(500, 600); @@ -6,5 +6,6 @@ window.setTitle("Your app"); // When using your own app use express to run the server and pass the url window.navigate("http://dev.to/"); -window.run(); -window.destroy() \ No newline at end of file +window.run(() => { + console.log("window has been closed"); +}); diff --git a/src/tiny.h b/src/tiny.h index d04be59..20e6c2b 100644 --- a/src/tiny.h +++ b/src/tiny.h @@ -1,8 +1,9 @@ #ifndef TINY_H #define TINY_H -#include "webview.h" #include +#include "webview.h" +#include "windowworker.h" class Tiny : public Napi::ObjectWrap { @@ -22,7 +23,6 @@ class Tiny : public Napi::ObjectWrap webview::webview window_; }; - Napi::FunctionReference Tiny::constructor; Napi::Object Tiny::Init(Napi::Env env, Napi::Object exports) @@ -130,13 +130,17 @@ void Tiny::Run(const Napi::CallbackInfo &info) Napi::Env env = info.Env(); Napi::HandleScope scope(env); - if (info.Length() > 0) + if (info.Length() == 0) { - Napi::TypeError::New(env, "It does not take any arguments") + Napi::TypeError::New(env, "You have to pass callback function") .ThrowAsJavaScriptException(); } - this->window_.run(); + Function cb = info[0].As(); + WindowWorker *worker = new WindowWorker(this->window_, cb); + worker->Queue(); + + // this->window_.run(); } void Tiny::Destroy(const Napi::CallbackInfo &info) @@ -153,5 +157,4 @@ void Tiny::Destroy(const Napi::CallbackInfo &info) this->window_.destroy(); } - #endif \ No newline at end of file diff --git a/src/windowworker.h b/src/windowworker.h new file mode 100644 index 0000000..d80f555 --- /dev/null +++ b/src/windowworker.h @@ -0,0 +1,36 @@ +#ifndef WINDOW_WORKER_H +#define WINDOW_WORKER_H + +#include +#include "webview.h" + +using namespace Napi; + +class WindowWorker : public AsyncWorker +{ +public: + WindowWorker(webview::webview window_, Function &callback); + + void Execute(); + void OnOK(); + +private: + webview::webview window_; +}; + +WindowWorker::WindowWorker(webview::webview window_, Function &callback) : AsyncWorker(callback) +{ + this->window_ = window_; +} + +void WindowWorker::Execute() +{ + this->window_.run(); +} + +void WindowWorker::OnOK() +{ + Callback().Call({}); +} + +#endif \ No newline at end of file