-
Notifications
You must be signed in to change notification settings - Fork 2
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 #4 from LinusU/lu-1
💥 Use Node-API to build addon
- Loading branch information
Showing
13 changed files
with
236 additions
and
154 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
build/ | ||
node_modules/ | ||
/build/ | ||
/node_modules/ |
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 @@ | ||
package-lock=false |
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,7 @@ | ||
/** | ||
* Captures the window with the title `title` of type `bundle`. `bundle` is usually the name of the application, e.g. `Finder`, `Safari`, `Terminal`. | ||
* | ||
* @returns path to a png file | ||
*/ | ||
declare async function captureWindow (bundle: string, title: string, filePath?: string | null): Promise<string> | ||
export = captureWindow |
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,19 +1,8 @@ | ||
var temp = require('fs-temp').template('%s.png') | ||
var addon = require('./build/Release/capture-window') | ||
const temp = require('fs-temp/promise').template('%s.png') | ||
const addon = require('./build/Release/capture_window') | ||
|
||
module.exports = function captureWindow (bundle, title, filePath, cb) { | ||
var done = (typeof filePath === 'function' ? filePath : cb) | ||
var hasPath = (typeof filePath === 'string') | ||
module.exports = async function captureWindow (bundle, title, filePath) { | ||
if (filePath == null) filePath = await temp.writeFile('') | ||
|
||
function withPath (err, filePath) { | ||
if (err) return done(err) | ||
|
||
addon.captureWindow(bundle, title, filePath, done) | ||
} | ||
|
||
if (hasPath) { | ||
withPath(null, filePath) | ||
} else { | ||
temp.writeFile('', withPath) | ||
} | ||
return addon.capture(bundle, title, filePath) | ||
} |
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 |
---|---|---|
|
@@ -2,21 +2,20 @@ | |
"name": "capture-window", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
"author": "Linus Unnebäck <[email protected]>", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard && mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/LinusU/node-capture-window.git" | ||
"test": "standard && mocha && ts-readme-generator --check" | ||
}, | ||
"repository": "LinusU/node-capture-window", | ||
"dependencies": { | ||
"fs-temp": "^0.1.1", | ||
"nan": "^2.0.5" | ||
"fs-temp": "^1.2.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.1.0", | ||
"standard": "^4.3.1" | ||
"mocha": "^7.2.0", | ||
"standard": "^15.0.1", | ||
"ts-readme-generator": "^0.7.3" | ||
}, | ||
"engines": { | ||
"node": ">=8.10.0" | ||
} | ||
} |
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,38 @@ | ||
# `capture-window` | ||
|
||
Capture a desktop window to a png file. Simple and easy. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install --save capture-window | ||
``` | ||
|
||
## Usage | ||
|
||
```javascript | ||
const captureWindow = require('capture-window') | ||
|
||
captureWindow('Finder', 'Downloads').then((filePath) => { | ||
// filePath is the path to a png file | ||
}) | ||
``` | ||
|
||
## API | ||
|
||
### `captureWindow(bundle, title[, filePath])` | ||
|
||
- `bundle` (`string`, required) | ||
- `title` (`string`, required) | ||
- `filePath` (`string | null`, optional) | ||
- returns `Promise<string>` - path to a png file | ||
|
||
Captures the window with the title `title` of type `bundle`. `bundle` is usually the name of the application, e.g. `Finder`, `Safari`, `Terminal`. | ||
|
||
## OS Support | ||
|
||
Only `Mac OS X` at the time being. The source is well prepared for other systems, pull requests welcome. | ||
|
||
## License | ||
|
||
MIT |
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 was deleted.
Oops, something went wrong.
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,23 @@ | ||
#include <assert.h> | ||
|
||
#define NAPI_VERSION 1 | ||
#include <node_api.h> | ||
|
||
#ifdef __APPLE__ | ||
#include "apple.m" | ||
#else | ||
#error Platform not supported | ||
#endif | ||
|
||
static napi_value Init(napi_env env, napi_value exports) { | ||
napi_value result; | ||
assert(napi_create_object(env, &result) == napi_ok); | ||
|
||
napi_value capture_fn; | ||
assert(napi_create_function(env, "capture", NAPI_AUTO_LENGTH, capture, NULL, &capture_fn) == napi_ok); | ||
assert(napi_set_named_property(env, result, "capture", capture_fn) == napi_ok); | ||
|
||
return result; | ||
} | ||
|
||
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) |
Oops, something went wrong.