basic qt wrap

This commit is contained in:
Atul R 2019-05-15 18:49:12 +02:00
parent 13a6db4162
commit 3e17864ec5
13 changed files with 236 additions and 1479 deletions

50
.clang-format Normal file
View File

@ -0,0 +1,50 @@
Language: Cpp
AccessModifierOffset: -4
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Stroustrup
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
Cpp11BracedListStyle: true
Standard: Cpp11
TabWidth: 4
UseTab: Never

View File

@ -4,15 +4,87 @@
"cflags!": ["-fno-exceptions"],
"cflags_cc!": ["-fno-exceptions"],
"sources": [
"src/cpp/main.cpp"
"src/cpp/main.cpp",
"src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
],
'conditions': [
['OS=="mac"', {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
},
'include_dirs': [
# install qt via homebrew only
'<!(echo $QN_QT_HOME_DIR)/include',
'<!(echo $QN_QT_HOME_DIR)/include/QtCore',
'<!(echo $QN_QT_HOME_DIR)/include/QtGui',
'<!(echo $QN_QT_HOME_DIR)/include/QtTest',
'<!(echo $QN_QT_HOME_DIR)/include/QtWidgets',
],
'libraries': [
'<!(echo $QN_QT_HOME_DIR)/lib/QtCore.framework/QtCore',
'<!(echo $QN_QT_HOME_DIR)/lib/QtGui.framework/QtGui',
'<!(echo $QN_QT_HOME_DIR)/lib/QtTest.framework/QtTest',
'<!(echo $QN_QT_HOME_DIR)/lib/QtWidgets.framework/QtWidgets',
'<!(echo $QN_QT_HOME_DIR)/lib/QtPrintSupport.framework/QtPrintSupport',
],
'link_settings': {
'libraries': [
'-Wl,-rpath,<!(echo $QN_QT_HOME_DIR)/lib/',
],
},
}],
['OS=="linux"', {
'cflags': [
'<!@(pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets Qt5Test)',
],
'ldflags': [
'<!@(pkg-config --libs-only-L --libs-only-other Qt5Core Qt5Gui Qt5Widgets Qt5Test)',
],
'libraries': [
'<!@(pkg-config --libs-only-l Qt5Core Qt5Gui Qt5Widgets Qt5Test)',
]
}],
['OS=="win"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
'/GR-',
'/MT',
'/EHsc'
]
},
},
'include_dirs': [
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/includes',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/includes/QtCore',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/includes/QtGui',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/includes/QtTest',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/includes/QtWidgets',
],
'libraries': [
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/lib/Qt5Core.lib',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/lib/Qt5Gui.lib',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/lib/Qt5Test.lib',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/lib/Qt5Widgets.lib',
],
'copies': [{
'files': [
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/dll/Qt5Core.dll',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/dll/Qt5Gui.dll',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/dll/Qt5Test.dll',
'<(module_root_dir)/dep/qt-5.11.0/win32/msvc2017_64/dll/Qt5Widgets.dll',
],
'destination': '<(module_root_dir)/build/Release',
}]
}],
],
'include_dirs': [
"<!@(node -p \"require('node-addon-api').include\")"
"<!@(node -p \"require('node-addon-api').include\")",
],
'libraries': [],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"
"<!(node -p \"require('node-addon-api').gyp\")",
],
'defines': ['NAPI_DISABLE_CPP_EXCEPTIONS']
'defines': ['NAPI_CPP_EXCEPTIONS'],
}]
}

3
demo.js Normal file
View File

@ -0,0 +1,3 @@
const nodeDesktop = require("./src/index");
console.log(nodeDesktop);

View File

@ -1,3 +0,0 @@
import nodeDesktop from "./src/index";
console.log(nodeDesktop);

5
index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
interface NodeDesktop {
myMethod1: (arg1: number) => null;
}
export default NodeDesktop;

View File

@ -1,22 +1,17 @@
{
"name": "node-desktop",
"name": "node_desktop",
"version": "1.0.0",
"description": "A cross platform library to build native desktop apps. Based on Qt5.",
"main": "dist/index.js",
"main": "src/index.js",
"author": "Atul R <atulanand94@gmail.com>",
"license": "MIT",
"private": false,
"devDependencies": {
"@types/node": "^12.0.1",
"node-gyp": "^4.0.0",
"nodemon": "^1.19.0",
"ts-node": "^8.1.0",
"typescript": "^3.4.5"
"node-gyp": "^4.0.0"
},
"scripts": {
"build": "node-gyp -j 8 rebuild && tsc",
"tsc": "tsc",
"dev": "nodemon --exec ts-node -- demo.ts"
"build": "node-gyp -j 8 rebuild",
"dev": "node demo.js"
},
"dependencies": {
"node-addon-api": "^1.6.3"

View File

@ -0,0 +1,53 @@
#include "qapplication_wrap.h"
Napi::FunctionReference QApplicationWrap::constructor;
int QApplicationWrap::argc = 0;
char** QApplicationWrap::argv = NULL;
Napi::Object QApplicationWrap::init(Napi::Env env, Napi::Object exports)
{
Napi::HandleScope scope(env);
char CLASSNAME[] = "QApplication";
Napi::Function func =
DefineClass(env, CLASSNAME,
{InstanceMethod("processEvents", &QApplicationWrap::processEvents),
InstanceMethod("exec", &QApplicationWrap::exec)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QApplicationWrap::QApplicationWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QApplicationWrap>(info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance = new QApplication(this->argc, this->argv);
}
QApplicationWrap::~QApplicationWrap()
{
delete this->instance;
}
QApplication* QApplicationWrap::getInternalInstance()
{
return this->instance;
}
Napi::Value QApplicationWrap::processEvents(const Napi::CallbackInfo& info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->processEvents();
return env.Null();
}
Napi::Value QApplicationWrap::exec(const Napi::CallbackInfo& info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->exec();
return env.Null();
}

View File

@ -0,0 +1,24 @@
#ifndef QAPPLICATION_WRAP_H
#define QAPPLICATION_WRAP_H
#include <QApplication>
#include <napi.h>
class QApplicationWrap : public Napi::ObjectWrap<QApplicationWrap> {
private:
QApplication* instance;
static int argc;
static char** argv;
public:
static Napi::FunctionReference constructor;
static Napi::Object init(Napi::Env env, Napi::Object exports);
QApplicationWrap(const Napi::CallbackInfo& info);
~QApplicationWrap();
QApplication* getInternalInstance();
// Wrapped methods
Napi::Value processEvents(const Napi::CallbackInfo& info);
Napi::Value exec(const Napi::CallbackInfo& info);
};
#endif

View File

@ -1,8 +1,10 @@
#include <napi.h>
#include "QtGui/QApplication/qapplication_wrap.h"
Napi::Object Main(Napi::Env env, Napi::Object exports)
{
QApplicationWrap::init(env, exports);
return exports;
}
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Main)
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Main)

3
src/index.js Normal file
View File

@ -0,0 +1,3 @@
const addon = require("../build/Release/node_desktop.node");
module.exports = addon;

View File

@ -1,5 +0,0 @@
interface NodeDesktop {
myMethod1: (arg1: number) => null;
}
export default require("../build/Release/node_desktop.node") as NodeDesktop;

View File

@ -1,62 +0,0 @@
{
"compilerOptions": {
/* Basic Options */
"target": "ES2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "dist" /* Redirect output structure to the directory. */,
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "incremental": true, /* Enable incremental compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}

1406
yarn.lock

File diff suppressed because it is too large Load Diff