Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make node-pre-gyp work #53

Merged
merged 8 commits into from
Jul 18, 2018
Merged
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
14 changes: 9 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
.DS_Store
*~
.buildconfig
.ycm_extra_conf.*
*/.tags
\#*\#
build/
node_modules/

npm-debug.log
package-lock.json
.buildconfig
*/.tags
.ycm_extra_conf.*

build/
node_modules/

lib/binding
37 changes: 0 additions & 37 deletions Makefile

This file was deleted.

13 changes: 12 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"targets": [
{
"target_name": "node-gtk",
"target_name": "node_gtk",
"sources": [
"src/boxed.cc",
"src/closure.cc",
Expand Down Expand Up @@ -53,6 +53,17 @@
]
}]
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
]
}
20 changes: 20 additions & 0 deletions doc/overrides.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Implementing overrides

- [Functions that create GMainLoop](#functions-that-create-gmainloop)

### Functions that create GMainLoop

Functions that create a GMainLoop should be wrapped as shown in the snippet below.
The function to quit the created loop must be pushed unto the `loopStack`.
Internally, NodeGTK uses this stack to quit all running loops when an exception occurs.

```javascript
const originalMain = Gtk.main
Gtk.main = function main() {
const loopStack = require('../native.js').GetLoopStack()

loopStack.push(Gtk.mainQuit)
originalMain()
loopStack.pop()
}
```
27 changes: 14 additions & 13 deletions examples/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ const Gdk = gi.require('Gdk')
gi.startLoop()
Gtk.init()


process.on('uncaughtException', (err) => {
console.log('process.uncaughtException', err)
process.exit(1)
})
process.on('exit', (code) => {
console.log('process.exit', code)
})
process.on('SIGINT', () => {
console.log('process.SIGINT')
process.exit(2)
})


// main program window
const window = new Gtk.Window({
type : Gtk.WindowType.TOPLEVEL
Expand All @@ -20,26 +34,13 @@ const entry = new Gtk.Entry()
entry.on('key-press-event', (event) => {
console.log(event)
console.log(event.string)
console.log('')

console.log(event, Object.keys(event))
console.log(event.__proto__, Object.keys(event.__proto__))

const e = new Gdk.EventKey()
console.log(e, Object.keys(e))
console.log(e.__proto__, Object.keys(e.__proto__))

console.log(e.__proto__ === event.__proto__)
console.log(e.__proto__.__proto__ === event.__proto__.__proto__)
})


// configure main window
window.setDefaultSize(200, 50)
window.setResizable(true)
window.connect('show', () => {
// bring it on top in OSX
// window.setKeepAbove(true)
Gtk.main()
})
window.on('destroy', () => Gtk.mainQuit())
Expand Down
9 changes: 2 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#! /bin/sh
# install.sh
# Copyright (C) 2018 rgregoir <rgregoir@laurier>
# Copyright (C) 2018 romgrk <romgrk.cc@gmail.com>
#

if [ "$(uname)" = "Darwin" ] && [ "$(which brew)" != "" ]; then
export PKG_CONFIG_PATH=$(brew --prefix libffi)/lib/pkgconfig
fi

node-pre-gyp install

if [ -n $? ]; then
node-gyp configure
node-gyp build
fi
node-pre-gyp install --fallback-to-build
7 changes: 1 addition & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
const camelCase = require('lodash.camelcase')
const snakeCase = require('lodash.snakecase')

let gi;
try {
gi = require('../build/Release/node-gtk');
} catch(e) {
gi = require('../build/Debug/node-gtk');
}
const gi = require('./native.js')

// The bootstrap from C here contains functions and methods for each object,
// namespaced with underscores. See gi.cc for more information.
Expand Down
13 changes: 13 additions & 0 deletions lib/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* native.js
*/

const binary = require('node-pre-gyp')
const path = require('path')

const packagePath = path.resolve(path.join(__dirname,'../package.json'))
const bindingPath = binary.find(packagePath)

const binding = require(bindingPath)

module.exports = binding
12 changes: 12 additions & 0 deletions lib/overrides/Gtk-3.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@
* Gtk-3.0.js
*/

const internal = require('../native.js')

exports.apply = (Gtk) => {

const originalMain = Gtk.main
Gtk.main = function main() {
const loopStack = internal.GetLoopStack()

loopStack.push(Gtk.mainQuit)
originalMain()
loopStack.pop()
}

}
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"install": "./install.sh",
"test": "mocha tests/__run__.js",
"build": "node-gyp rebuild",
"build:incremental": "node-gyp build"
"build": "node-pre-gyp rebuild",
"build:incremental": "node-pre-gyp build"
},
"repository": {
"type": "git",
Expand All @@ -22,6 +22,9 @@
"bindings"
],
"author": "Jasper St. Pierre",
"contributors": [
"Romain Grégoire <romgrk.cc@gmail.com> (https://github.com/romgrk)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/romgrk/node-gtk/issues"
Expand All @@ -35,16 +38,17 @@
"node-pre-gyp": "0.10.2",
"node-pre-gyp-github": "1.3.1"
},
"binary": {
"module_name": "node-gtk",
"module_path": "./build/{configuration}/{node_abi}-{platform}-{arch}/",
"package_name": "{node_abi}-{platform}-{arch}.tar.gz",
"host": "https://github.com/romgrk/node-gtk/releases/download/",
"remote_path": "{version}"
},
"devDependencies": {
"assert": "^1.4.1",
"aws-sdk": "^2.276.1",
"chalk": "^2.4.1",
"mocha": "^5.2.0"
},
"binary": {
"module_name": "node_gtk",
"module_path": "./lib/binding/{node_abi}-{platform}-{arch}/",
"remote_path": "./{module_name}/v{version}/",
"package_name": "{module_name}-{node_abi}-{platform}-{arch}.tar.gz",
"host": "https://node-gtk-1.s3-us-east-1.amazonaws.com"
}
}
25 changes: 25 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
#
# publish.sh
# Copyright (C) 2018 romgrk <romgrk@arch>
#
# Distributed under terms of the MIT license.

if [ -f /usr/share/nvm/init-nvm.sh ]; then
source /usr/share/nvm/init-nvm.sh
fi

## NodeJS versions
# We publish more than the versions we officially support, to be nice.
# Should be updated when a new NODE_MODULE_VERSION appears in https://nodejs.org/en/download/releases/
declare -a versions=("6.0.0" "7.0.0" "8.0.0" "9.0.0" "10.0.0")

## Publish each version
for version in "${versions[@]}"
do
echo "##### Installing: $version ######"
nvm install $version
nvm use $version
npm install
./node_modules/.bin/node-pre-gyp package publish
done
35 changes: 8 additions & 27 deletions src/closure.cc
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
#include <glib.h>
#include <nan.h>

#include "closure.h"
#include "debug.h"
#include "function.h"
#include "loop.h"
#include "type.h"
#include "value.h"

using namespace v8;

namespace GNodeJS {

struct Closure {
GClosure base;
Persistent<Function> persistent;
GISignalInfo* info;

~Closure() {
if (info)
g_base_info_unref(info);
}

static void Marshal(GClosure *closure,
GValue *g_return_value,
uint argc, const GValue *g_argv,
gpointer invocation_hint,
gpointer marshal_data);

static void Invalidated(gpointer data, GClosure *closure);
};

void Closure::Marshal(GClosure *base,
GValue *g_return_value,
uint argc, const GValue *g_argv,
Expand Down Expand Up @@ -78,12 +60,11 @@ void Closure::Marshal(GClosure *base,
}
}
else {
auto stackTrace = try_catch.StackTrace();
if (!stackTrace.IsEmpty())
printf("%s\n", *Nan::Utf8String(stackTrace.ToLocalChecked()));
else
printf("%s\n", *Nan::Utf8String(try_catch.Exception()));
exit(1);
log("'%s' did throw", g_base_info_get_name (closure->info));

GNodeJS::QuitLoopStack();

try_catch.ReThrow();
}

#ifndef __linux__
Expand All @@ -96,7 +77,7 @@ void Closure::Invalidated(gpointer data, GClosure *base) {
closure->~Closure();
}

GClosure *MakeClosure(Isolate *isolate, Local<Function> function, GISignalInfo* info) {
GClosure *MakeClosure(Isolate *isolate, Local<Function> function, GIBaseInfo* info) {
Closure *closure = (Closure *) g_closure_new_simple (sizeof (*closure), NULL);
closure->persistent.Reset(isolate, function);
closure->info = info;
Expand Down
23 changes: 23 additions & 0 deletions src/closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,31 @@
#include <girepository.h>
#include <glib-object.h>

using v8::Function;
using v8::Persistent;

namespace GNodeJS {

struct Closure {
GClosure base;
Persistent<Function> persistent;
GIBaseInfo* info;

~Closure() {
persistent.Reset();
if (info)
g_base_info_unref(info);
}

static void Marshal(GClosure *closure,
GValue *g_return_value,
uint argc, const GValue *g_argv,
gpointer invocation_hint,
gpointer marshal_data);

static void Invalidated(gpointer data, GClosure *closure);
};

GClosure *MakeClosure(v8::Isolate *isolate, v8::Handle<v8::Function> function, GISignalInfo* info);

};
Loading