File tree Expand file tree Collapse file tree 9 files changed +148
-2
lines changed Expand file tree Collapse file tree 9 files changed +148
-2
lines changed Original file line number Diff line number Diff line change 1+ /build /
2+ npm-debug.log
Original file line number Diff line number Diff line change 1+ /.vscode
2+ /build
3+ /test
4+ .gitignore
5+ .npmignore
6+ npm-debug.log
Original file line number Diff line number Diff line change 1+ // Place your settings in this file to overwrite default and user settings.
2+ {
3+ "editor.insertSpaces" : true ,
4+ "files.trimTrailingWhitespace" : true ,
5+ "editor.tabSize" : 2 ,
6+ "files.exclude" : {
7+ "**/.git" : true ,
8+ "**/.DS_Store" : true ,
9+ "build/**" : true
10+ }
11+ }
Original file line number Diff line number Diff line change 1- # node-windows-foreground-love
2- API wrapper for AllowSetForegroundWindow
1+ # API wrapper for [ AllowSetForegroundWindow] ( https://msdn.microsoft.com/en-us/library/windows/desktop/ms632668.aspx )
2+
3+ ## Installing
4+
5+ ``` sh
6+ npm install windows-foreground-love
7+ ```
8+
9+ ## Using
10+
11+ ``` javascript
12+ var allowSetForegroundWindow = require (' windows-foreground-love' ).allowSetForegroundWindow
13+ console .log (allowSetForegroundWindow (pid))
14+ console .log (allowSetForegroundWindow ()) // all processes will be enabled to set the foreground window
15+ ```
16+
17+ ## Supported OSes
18+ * windows
19+
20+ ## Developing
21+ * ` npm install -g node-gyp `
22+ * ` node-gyp configure `
23+ * ` node-gyp build `
24+ * ` npm test `
25+
26+ ## License
27+ [ MIT] ( LICENSE )
Original file line number Diff line number Diff line change 1+ {
2+ "targets" : [
3+ {
4+ "target_name" : "foreground-love" ,
5+ "sources" : [
6+ "src/foreground-love.cc"
7+ ]
8+ }
9+ ]
10+ }
Original file line number Diff line number Diff line change 1+ var foregroundLove = null ;
2+ var tried = false ;
3+
4+ exports . allowSetForegroundWindow = function ( pid ) {
5+ if ( ! tried ) {
6+ tried = true ;
7+ try {
8+ foregroundLove = require ( './build/Release/foreground-love' ) ;
9+ } catch ( err ) {
10+ console . error ( err ) ;
11+ }
12+ }
13+
14+ if ( ! foregroundLove ) {
15+ return false ;
16+ }
17+
18+ var r = 0 ;
19+ try {
20+ r = foregroundLove . allowSetForegroundWindow ( pid ) ;
21+ } catch ( err ) {
22+ console . error ( err ) ;
23+ }
24+ return r ;
25+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " windows-foreground-love" ,
3+ "version" : " 0.1.0" ,
4+ "description" : " API wrapper for AllowSetForegroundWindow" ,
5+ "main" : " index.js" ,
6+ "os" : [
7+ " win32"
8+ ],
9+ "scripts" : {
10+ "test" : " node test/test.js"
11+ },
12+ "repository" : {
13+ "type" : " git" ,
14+ "url" : " git+https://github.com/the-ress/node-windows-foreground-love.git"
15+ },
16+ "author" : " Tereza Tomcova" ,
17+ "license" : " MIT" ,
18+ "bugs" : {
19+ "url" : " https://github.com/the-ress/node-windows-foreground-love/issues"
20+ },
21+ "homepage" : " https://github.com/the-ress/node-windows-foreground-love#readme"
22+ }
Original file line number Diff line number Diff line change 1+ #include < node.h>
2+ #include < windows.h>
3+ #include < iostream>
4+
5+ namespace foreground_love {
6+
7+ using v8::Boolean;
8+ using v8::FunctionCallbackInfo;
9+ using v8::Isolate;
10+ using v8::Local;
11+ using v8::Object;
12+ using v8::Value;
13+
14+ void AllowSetForegroundWindow (const FunctionCallbackInfo<Value>& args) {
15+ Isolate * isolate = args.GetIsolate ();
16+ uint32_t pid = args[0 ]->Uint32Value ();
17+
18+ BOOL result;
19+ if (pid != 0 ) {
20+ result = ::AllowSetForegroundWindow (pid);
21+ } else {
22+ // Send foreground love to all processes
23+ result = ::AllowSetForegroundWindow (ASFW_ANY);
24+ }
25+
26+ Local<Boolean> resultBool = Boolean::New (isolate, result);
27+ args.GetReturnValue ().Set (resultBool);
28+ }
29+
30+ void init (Local<Object> exports) {
31+ NODE_SET_METHOD (exports, " allowSetForegroundWindow" , AllowSetForegroundWindow);
32+ }
33+
34+ NODE_MODULE (foreground_love, init)
35+
36+ } // namespace foreground_love
Original file line number Diff line number Diff line change 1+ var index = require ( '../index' ) ;
2+
3+ console . log ( 'Sending foreground love to own process...' )
4+ var result = index . allowSetForegroundWindow ( process . pid ) ;
5+ console . log ( result ) ;
6+
7+ console . log ( 'Sending foreground love to all processes...' )
8+ result = index . allowSetForegroundWindow ( ) ;
9+ console . log ( result ) ;
You can’t perform that action at this time.
0 commit comments