Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build/Release/.deps/Release/obj.target/addon/src/addon.o.d
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Binary file modified build/Release/addon.node
Binary file not shown.
Binary file modified build/Release/obj.target/addon.node
Binary file not shown.
Binary file modified build/Release/obj.target/addon/src/addon.o
Binary file not shown.
7 changes: 4 additions & 3 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const Tiny = require("tinytron")
const Tiny = require("./index");

const window = new Tiny();
window.setSize(500, 600);
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()
window.run(() => {
console.log("window has been closed");
});
15 changes: 9 additions & 6 deletions src/tiny.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef TINY_H
#define TINY_H

#include "webview.h"
#include <napi.h>
#include "webview.h"
#include "windowworker.h"

class Tiny : public Napi::ObjectWrap<Tiny>
{
Expand All @@ -22,7 +23,6 @@ class Tiny : public Napi::ObjectWrap<Tiny>
webview::webview window_;
};


Napi::FunctionReference Tiny::constructor;

Napi::Object Tiny::Init(Napi::Env env, Napi::Object exports)
Expand Down Expand Up @@ -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<Function>();
WindowWorker *worker = new WindowWorker(this->window_, cb);
worker->Queue();

// this->window_.run();
}

void Tiny::Destroy(const Napi::CallbackInfo &info)
Expand All @@ -153,5 +157,4 @@ void Tiny::Destroy(const Napi::CallbackInfo &info)
this->window_.destroy();
}


#endif
36 changes: 36 additions & 0 deletions src/windowworker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef WINDOW_WORKER_H
#define WINDOW_WORKER_H

#include <napi.h>
#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