Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
bump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
a7ul committed Nov 22, 2019
1 parent 3e50ce8 commit cc8a49b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 93 deletions.
2 changes: 1 addition & 1 deletion npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodegui/qode",
"version": "1.0.5",
"version": "1.0.6",
"description": "Qode is a lightly modified fork of Node.js that merges Node's event loop with Qt's event loop. It is designed to be used together with `@nodegui/nodegui`",
"main": "index.js",
"files": [
Expand Down
177 changes: 86 additions & 91 deletions src/qode.cc
Original file line number Diff line number Diff line change
@@ -1,107 +1,102 @@
// Copyright 2017 Atul R. All rights reserved.

#include "qode.h"
#include "src/integration/node_integration.h"
#include "node/src/env-inl.h"
#include <string.h>

#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "helpers/qode_helpers.h"
#include "node/src/env-inl.h"
#include "src/integration/node_integration.h"

std::string qodeVersion = "1.0.5";
std::string qodeVersion = "1.0.6";

namespace qode {

QApplication *qtAppInstance = nullptr;
static int qode_argc = 0;
static char **qode_argv = nullptr;
// The global instance of NodeIntegration.
std::unique_ptr<NodeIntegration> g_node_integration;
// Has we run message loop before.
bool g_first_runloop = true;

inline v8::Local<v8::String> ToV8String(node::Environment *env, const std::string str) {
return v8::String::NewFromUtf8(
env->isolate(),
str.c_str(),
v8::NewStringType::kNormal,
static_cast<int>(str.length()))
.ToLocalChecked();
}
QApplication *qtAppInstance = nullptr;
static int qode_argc = 0;
static char **qode_argv = nullptr;
// The global instance of NodeIntegration.
std::unique_ptr<NodeIntegration> g_node_integration;
// Has we run message loop before.
bool g_first_runloop = true;

// Force running uv loop.
void ActivateUvLoop(const v8::FunctionCallbackInfo<v8::Value>& args) {
g_node_integration->CallNextTick();
}
inline v8::Local<v8::String> ToV8String(node::Environment *env,
const std::string str) {
return v8::String::NewFromUtf8(env->isolate(), str.c_str(),
v8::NewStringType::kNormal,
static_cast<int>(str.length()))
.ToLocalChecked();
}

bool InitWrapper(node::Environment *env)
{
v8::HandleScope handle_scope(env->isolate());
v8::Local<v8::Value> versions = env->process_object()->Get(
env->context(),
ToV8String(env, "versions"))
.ToLocalChecked();
versions.As<v8::Object>()->Set(
env->context(),
ToV8String(env, "qode"),
ToV8String(env, qodeVersion))
.ToChecked();
versions.As<v8::Object>()->Set(
env->context(),
ToV8String(env, "qt(compiled)"),
ToV8String(env, QT_VERSION_STR))
.ToChecked();
versions.As<v8::Object>()->Set(
env->context(),
ToV8String(env, "qt(runtime)"),
ToV8String(env, qVersion())
).ToChecked();

env->SetMethod(env->process_object(), "activateUvLoop", &ActivateUvLoop);
return true;
}
// Force running uv loop.
void ActivateUvLoop(const v8::FunctionCallbackInfo<v8::Value> &args) {
g_node_integration->CallNextTick();
}

bool RunLoopWrapper(node::Environment *env)
{
// Run uv loop for once before entering GUI message loop.
if (g_first_runloop)
{
g_node_integration->UvRunOnce();
g_first_runloop = false;
}
int exitCode = qtAppInstance->exec();
std::cout << "Qt exited with " << exitCode;
exit(exitCode);
// No need to keep uv loop alive.
// g_node_integration->ReleaseHandleRef();
// Enter uv loop to handle unfinished uv tasks.
// return uv_run(env->event_loop(), UV_RUN_DEFAULT);
}
bool InitWrapper(node::Environment *env) {
v8::HandleScope handle_scope(env->isolate());
v8::Local<v8::Value> versions =
env->process_object()
->Get(env->context(), ToV8String(env, "versions"))
.ToLocalChecked();
versions.As<v8::Object>()
->Set(env->context(), ToV8String(env, "qode"),
ToV8String(env, qodeVersion))
.ToChecked();
versions.As<v8::Object>()
->Set(env->context(), ToV8String(env, "qt(compiled)"),
ToV8String(env, QT_VERSION_STR))
.ToChecked();
versions.As<v8::Object>()
->Set(env->context(), ToV8String(env, "qt(runtime)"),
ToV8String(env, qVersion()))
.ToChecked();

env->SetMethod(env->process_object(), "activateUvLoop", &ActivateUvLoop);
return true;
}

int Start(int argc, char *argv[])
{
qode_argc = argc;
qode_argv = argv;

qtAppInstance = new QApplication(qode_argc, qode_argv);
qtAppInstance->processEvents(); // Just run it once.
// Prepare node integration.
g_node_integration.reset(NodeIntegration::Create());
g_node_integration->Init();
// Set run loop and init function on node.
node::InjectQode(&InitWrapper, &RunLoopWrapper);
// Always enable GC this app is almost always running on desktop.
v8::V8::SetFlagsFromString("--expose_gc", 11);

QJsonDocument qodeConfig = QodeHelpers::readConfig();
QodeHelpers::setStartFile(qodeConfig);
QodeHelpers::setConsoleVisibility(qodeConfig);
QodeHelpers::addLibraryPaths(qodeConfig);

int code = node::Start(qode_argc, qode_argv);
// Clean up node integration and quit.
g_node_integration.reset();
return code;
bool RunLoopWrapper(node::Environment *env) {
// Run uv loop for once before entering GUI message loop.
if (g_first_runloop) {
g_node_integration->UvRunOnce();
g_first_runloop = false;
}
int exitCode = qtAppInstance->exec();
std::cout << "Qt exited with " << exitCode;
exit(exitCode);
// No need to keep uv loop alive.
// g_node_integration->ReleaseHandleRef();
// Enter uv loop to handle unfinished uv tasks.
// return uv_run(env->event_loop(), UV_RUN_DEFAULT);
}

int Start(int argc, char *argv[]) {
qode_argc = argc;
qode_argv = argv;

qtAppInstance = new QApplication(qode_argc, qode_argv);
qtAppInstance->processEvents(); // Just run it once.
// Prepare node integration.
g_node_integration.reset(NodeIntegration::Create());
g_node_integration->Init();
// Set run loop and init function on node.
node::InjectQode(&InitWrapper, &RunLoopWrapper);
// Always enable GC this app is almost always running on desktop.
v8::V8::SetFlagsFromString("--expose_gc", 11);

QJsonDocument qodeConfig = QodeHelpers::readConfig();
QodeHelpers::setStartFile(qodeConfig);
QodeHelpers::setConsoleVisibility(qodeConfig);
QodeHelpers::addLibraryPaths(qodeConfig);

int code = node::Start(qode_argc, qode_argv);
// Clean up node integration and quit.
g_node_integration.reset();
return code;
}

} // namespace qode
} // namespace qode

0 comments on commit cc8a49b

Please sign in to comment.