-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from romgrk/signal-loop-issues
Fix signal errors & loop issues
- Loading branch information
Showing
12 changed files
with
182 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* native.js | ||
*/ | ||
|
||
let native | ||
|
||
try { | ||
native = require('../build/Release/node-gtk'); | ||
} catch(e) { | ||
native = require('../build/Debug/node-gtk'); | ||
} | ||
|
||
module.exports = native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
|
||
#pragma once | ||
|
||
#include <nan.h> | ||
#include <v8.h> | ||
|
||
using namespace v8; | ||
|
||
namespace GNodeJS { | ||
|
||
void StartLoop(); | ||
void StartLoop(); | ||
|
||
void QuitLoopStack(); | ||
|
||
Local<Array> GetLoopStack(); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* loop.js | ||
*/ | ||
|
||
|
||
const gi = require('../lib/') | ||
const Gtk = gi.require('Gtk', '3.0') | ||
|
||
gi.startLoop() | ||
Gtk.init() | ||
|
||
let didCallTimeout = false | ||
let didCallPromise = false | ||
|
||
setTimeout(() => { | ||
console.log('timeout') | ||
didCallTimeout = true | ||
}, 500) | ||
|
||
const promise = new Promise(resolve => resolve('promise resolved')) | ||
promise.then(result => { | ||
console.log(result) | ||
didCallPromise = true | ||
}) | ||
|
||
setTimeout(() => { | ||
Gtk.mainQuit() | ||
console.assert(didCallTimeout, 'did not call timeout') | ||
console.assert(didCallPromise, 'did not call promise') | ||
console.log('done') | ||
}, 1000) | ||
|
||
Gtk.main() |