Skip to content

Commit

Permalink
Merge pull request #21 from mischnic/node-4
Browse files Browse the repository at this point in the history
Node 6
  • Loading branch information
parro-it authored May 11, 2018
2 parents efc186e + 948948f commit 2b7c617
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 228 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ language: node_js
dist: trusty

node_js:
- node
- '10'
- '9'
- '8'
- '6'

addons:
apt:
Expand Down Expand Up @@ -39,6 +42,6 @@ deploy:
on:
branch: master
tags: true
node: node
node: '10'
api_key:
secure: kkdWKa9iqJNKrfvW1pLgVx0EUBGcx+VGOzKG7xvxSfpNudZpuoGjWL4p9fQQD5TRELGwY7KCpFfZPbp2dnHQ9z82lW2XmnEC+bcskmfO/PXLJi3uyLrEY7iBwR3UhiWSdKRaPptfnndQrC21jmlweJNMCTWW8VqgvYupYITf9mfIq0WbEmFMeXJr7KzRO1yX4uAOOqnSTb60uRSrg+9V000cmDi246ir2ApaRw6NBOmI2v0kbirdbDe/vcAclgD2K0CFV7h8HIucbiU1DWBF2aQY3u5II4mItM4yskv0BmOr4vxXR0+7B/iysZNjWtXLbt4CiekvQKADUqPFpPk33LTjPxtAzdUYhHaoGTwchCIpkJG32KqTBL1+9h2I8WyhB3tKgxbFTZynkBihS2mYJad+rdO2RCXZtFZxf9bPWv6+PGelKnTFFBR9gPGTha4FeIeYZyuxuecAE7I+0UhS+wvwls3Xstro9fw+OwyvTysMEWOrjm1DvBuZyNnkqcfBKt3q4MOZsEHFnTEu6A1htr96FutAj/vap0e1RMokhMSIbe/hwq3whmELzWpRkOVDPEZfN47PCYc3f/UfYf0RMSWthibZOD30IX3207LsOgxZXfH3PDVcG9q0lvowGKWMcKy7d6+VVqgE97Aq7i07fizbpMWbNY7cStNy26m6IxM=
13 changes: 9 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ skip_branch_with_pr: true
image: Visual Studio 2017

environment:
nodejs_version: "10"
matrix:
- nodejs_version: "10"
- nodejs_version: "9"
- nodejs_version: "8"
- nodejs_version: "6"

configuration: Release
platform: x64

install:
- ps: Install-Product node $env:nodejs_version $env:platform
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)
- node --version
- npm --version
- npm install

test_script:
- node --version
- npm --version
- npm test

after_test:
Expand All @@ -37,3 +41,4 @@ deploy:
secure: eMIAnmLDhZy2Sq/UAXB50fYr1C2BugaafN8XiV6Wur8wMvPLXWIuCKU7Jt/Y9Of6
on:
appveyor_repo_tag: true
nodejs_version: "10"
50 changes: 50 additions & 0 deletions example/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const libui = require('..');

const win = new libui.UiWindow('Errors example', 320, 60, true);
win.margined = true;

const msg = (err) => {
console.log('Another click will terminate the app.');
process.removeListener('uncaughtException', msg);
};

process.on('uncaughtException', msg);

const toolbar = new libui.UiHorizontalBox();
const setEntryBtn = new libui.UiButton('Uncaught error');
setEntryBtn.onClicked(() => {
throw new Error('ciao');
});
toolbar.append(setEntryBtn, false);
const setSearchBtn = new libui.UiButton('No errors');
setSearchBtn.onClicked(() => {
console.log('clicked');
});
toolbar.append(setSearchBtn, false);
const setPasswordBtn = new libui.UiButton('Set password');
setPasswordBtn.onClicked(() => {});
toolbar.append(setPasswordBtn, false);

const setSpinboxBtn = new libui.UiButton('Set number');
setSpinboxBtn.onClicked(() => {});
toolbar.append(setSpinboxBtn, false);

const toggleReadOnlyBtn = new libui.UiButton('Set ReadOnly');
toggleReadOnlyBtn.onClicked(() => {

});
toolbar.append(toggleReadOnlyBtn, false);

const box = new libui.UiVerticalBox();
box.padded = true;
box.append(toolbar);
win.setChild(box);

win.onClosing(() => {
win.close();
libui.stopLoop();
});

win.show();

libui.startLoop();
6 changes: 4 additions & 2 deletions example/event-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ function makeToolbar() {

timeoutHandle = setTimeout((a, b, c) => {
const elapsed = Date.now() - now;
logAppend(`Custom setTimeout: ${now} - elapsed ${elapsed} ms. Args: ${a} ${b} ${c}`);
logAppend(`Custom setTimeout: ${now} - elapsed ${elapsed} ms. Args: ${a} ${
b} ${c}`);
}, 1000, 'custom', 'args', 2);
});
toolbar.append(btnCustom, false);
Expand All @@ -144,7 +145,8 @@ function makeToolbar() {
let now = Date.now();
intervalHandler = setInterval((a, b, c) => {
const elapsed = Date.now() - now;
logAppend(`Custom setInterval: ${now} - elapsed ${elapsed} ms. Args: ${a} ${b} ${c}`);
logAppend(`Custom setInterval: ${now} - elapsed ${elapsed} ms. Args: ${a} ${
b} ${c}`);
now = Date.now();
}, 50, 'my', 'args', 2);
});
Expand Down
6 changes: 1 addition & 5 deletions example/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ win.show();
libui.startLoop();

function setJSON() {
const data = {
name: name.text,
surname: surname.text,
age: age.value
};
const data = {name: name.text, surname: surname.text, age: age.value};
JSONData.text = JSON.stringify(data, null, 4);
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const libui = require(`${__dirname}/node_libui.node`);
const async_hooks = require('async_hooks');
const async_hooks = require('@creditkarma/async-hooks');
const EventLoop = libui.EventLoop;
delete libui.EventLoop;

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"GUI"
],
"engines": {
"node": ">=8"
"node": ">=6.14.2"
},
"libui": "alpha3.5-master-002",
"scripts": {
Expand All @@ -25,9 +25,10 @@
"install": "npm run --silent download-libui && npm run --silent download-libui-napi || npm run build",
"test": "tape test.js",
"precommit": "check-clang-format \"'npm run lint'\"",
"lint": "clang-format -i --glob='{js/*.js,src/**/*.{h,c,m},index.js,example.js,test.js,example/*/*.js}'"
"lint": "clang-format -i --glob='{example/*.js, js/*.js,src/**/*.{h,c,m},index.js,example.js,test.js,example/*/*.js,tools/*.js}'"
},
"dependencies": {
"@creditkarma/async-hooks": "0.0.4",
"home-path": "^1.0.5",
"is-ci": "^1.1.0",
"mkdirp": "^0.5.1",
Expand Down
27 changes: 16 additions & 11 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ napi_value fire_event(struct event_t *event) {
napi_value resource_object;
status = napi_create_object(env, &resource_object);
CHECK_STATUS_UNCAUGHT(status, napi_create_object, NULL);

napi_callback_scope scope;
status = napi_open_callback_scope(env, resource_object, event->context, &scope);
CHECK_STATUS_UNCAUGHT(status, napi_open_callback_scope, NULL);

/*
napi_callback_scope scope;
status = napi_open_callback_scope(env, resource_object, event->context, &scope);
CHECK_STATUS_UNCAUGHT(status, napi_open_callback_scope, NULL);
*/
napi_value cb;
status = napi_get_reference_value(env, event->cb_ref, &cb);
CHECK_STATUS_UNCAUGHT(status, napi_get_reference_value, NULL);
Expand All @@ -28,15 +28,20 @@ napi_value fire_event(struct event_t *event) {
if (status == napi_pending_exception) {
napi_value last_exception;
napi_get_and_clear_last_exception(env, &last_exception);
napi_fatal_exception(env, last_exception);
return NULL;
napi_value stack;
size_t string_len = 5000;
char stack_str[5001];
napi_get_named_property(env, last_exception, "stack", &stack);
napi_get_value_string_utf8(env, stack, stack_str, string_len + 1, &string_len);
napi_fatal_error("fire_event", NAPI_AUTO_LENGTH, stack_str, NAPI_AUTO_LENGTH);
return last_exception;
}

CHECK_STATUS_UNCAUGHT(status, napi_make_callback, NULL);

status = napi_close_callback_scope(env, scope);
CHECK_STATUS_UNCAUGHT(status, napi_close_callback_scope, NULL);

/*
status = napi_close_callback_scope(env, scope);
CHECK_STATUS_UNCAUGHT(status, napi_close_callback_scope, NULL);
*/
status = napi_close_handle_scope(env, handle_scope);
CHECK_STATUS_UNCAUGHT(status, napi_close_handle_scope, NULL);

Expand Down
6 changes: 1 addition & 5 deletions src/includes/napi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ NULL, &ret); \
char err[1024]; \
snprintf(err, 1024, #FN " failed with code %d: %s\n", result->engine_error_code, \
result->error_message); \
napi_value error; \
napi_value error_msg; \
napi_create_string_utf8(env, err, NAPI_AUTO_LENGTH, &error_msg); \
napi_create_error(env, NULL, error_msg, &error); \
napi_fatal_exception(env, error); \
napi_fatal_error("", NAPI_AUTO_LENGTH, err, NAPI_AUTO_LENGTH); \
return ERROR_RET; \
}

Expand Down
80 changes: 80 additions & 0 deletions tools/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const fs = require('fs');
const path = require('path');
const mv = require('mv');
const https = require('https');
const homePath = require('home-path');
const mkdirp = require('mkdirp');

const debug = require('debug')('libui-download');

const requestHttps = url => new Promise((resolve, reject) => {
const req = https.get(url, resolve);
req.on('error', reject);
});

module.exports = function(project) {
const PROJECT = project.toUpperCase();
return {
requestHttps,
mkCacheDir(cache) {
try {
mkdirp.sync(cache);
return cache;
} catch (err) {
if (err.code !== 'EACCES') {
debug('mkCacheDir error: ', err.stack);
throw err;
}

// try local folder if homedir is off limits (e.g. some linuxes return '/'
// as homedir)
var localCache = path.resolve('./.' + project);

mkdirp.sync(localCache);
return localCache;
}
},
cacheDir(opts) {
opts = opts || {};
var homeDir = homePath();
return opts.cache || path.join(homeDir, './.' + project);
},
buildUrl(opts, filename) {
var url = process.env[`NPM_CONFIG_${PROJECT}_MIRROR`] ||
process.env[`${PROJECT}_MIRROR`] || opts.mirror ||
`https://github.com/parro-it/${project}/releases/download/`;

url += process.env[`${PROJECT}_CUSTOM_DIR`] || opts.customDir || opts.version;
url += '/';
url += process.env[`${PROJECT}_CUSTOM_FILENAME`] || opts.customFilename ||
filename;
return url;
},
doDownload(res, url, target, cachedZip) {
if (res.statusCode !== 200) {
throw new Error(`Https request failed for ${
res.headers.location} with code ${res.statusCode}.`);
}

debug(`Https request for ${url} ok with code 200.`);

const fileWrite = res.pipe(fs.createWriteStream(target));

return new Promise((resolve, reject) => {
const finish = () => {
debug('end stream reached', target, cachedZip);
mv(target, cachedZip, function(err) {
if (err) {
reject(err);
} else {
resolve(cachedZip);
}
});
};

fileWrite.on('finish', finish);
fileWrite.on('error', reject);
});
}
};
};
Loading

0 comments on commit 2b7c617

Please sign in to comment.