-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alex.wei
committed
Apr 23, 2019
1 parent
70c2303
commit de066ba
Showing
13 changed files
with
282 additions
and
0 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,7 @@ | ||
build | ||
lib/binding | ||
npm-debug.log | ||
yarn-error.log | ||
package-lock.json | ||
.DS_Store | ||
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,6 @@ | ||
/build | ||
/node_modules | ||
/npm-debug.log | ||
/lib/binding | ||
yarn.lock | ||
npm-debug.log |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 zman | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,27 @@ | ||
# clipboard-files | ||
|
||
A nodejs addon, read file path from clipboard, support win32 and mac osx. | ||
|
||
## build for nwjs | ||
|
||
```shell | ||
npm i clipboard-files --target=0.14.0 --target-arch=ia32 | ||
``` | ||
## build for electron | ||
|
||
```shell | ||
npm i clipboard-files --target=2.0.5 --target-arch=ia32 | ||
``` | ||
|
||
## build for nodejs | ||
|
||
```shell | ||
npm i clipboard-files | ||
``` | ||
|
||
## example | ||
|
||
```js | ||
const clipboard = require('clipboard-files') | ||
let fileNames = clipboard.readFiles() | ||
``` |
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,58 @@ | ||
{ | ||
"targets": [{ | ||
"target_name": "binding", | ||
"sources": [ | ||
"src/main.cc" | ||
], | ||
"include_dirs": ["<!(node -e \"require('nan')\")"], | ||
"conditions": [ | ||
['OS=="mac"', | ||
{ | ||
"sources":[ | ||
"src/clip_osx.h", | ||
"src/clip_osx.mm" | ||
], | ||
'defines': [ | ||
'__MACOSX_CORE__', | ||
'__MAC__' | ||
], | ||
'link_settings': { | ||
'libraries': [ | ||
'-framework Cocoa', | ||
'-framework CoreFoundation', | ||
] | ||
}, | ||
'xcode_settings': { | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', | ||
'OTHER_CFLAGS': [ | ||
'-ObjC++', | ||
'-std=c++11' | ||
] | ||
} | ||
} | ||
], | ||
['OS=="win"', | ||
{ | ||
"sources":[ | ||
"src/clip_win.h", | ||
"src/clip_win.cc" | ||
], | ||
'defines': [ | ||
'__WIN32__' | ||
] | ||
} | ||
], | ||
['OS=="linux"', | ||
{} | ||
] | ||
] | ||
}, { | ||
"target_name": "action_after_build", | ||
"type": "none", | ||
"dependencies": ["<(module_name)"], | ||
"copies": [{ | ||
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ], | ||
"destination": "<(module_path)" | ||
}] | ||
}] | ||
} |
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,5 @@ | ||
var binary = require('node-pre-gyp'); | ||
var path = require('path'); | ||
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json'))); | ||
var binding = require(binding_path); | ||
module.exports = exports = binding; |
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 @@ | ||
{ | ||
"name": "clipboard-files", | ||
"version": "0.0.7", | ||
"description": "A nodejs addon, read file path from clipboard, support win32 and mac osx", | ||
"main": "./lib/index.js", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"binary": { | ||
"module_name": "binding", | ||
"module_path": "./lib/binding/{node_abi}-{platform}-{arch}/", | ||
"package_name": "{node_abi}-{platform}-{arch}.tar.gz", | ||
"host": "https://github.com/alex8088/clipboard-files/releases/download/", | ||
"remote_path": "v{version}" | ||
}, | ||
"keywords": [ | ||
"clipboard", | ||
"files", | ||
"nwjs", | ||
"electron" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alex8088/clipboard-files.git" | ||
}, | ||
"scripts": { | ||
"test": "node ./test", | ||
"install": "node-pre-gyp install --fallback-to-build" | ||
}, | ||
"author": "alex.wei", | ||
"license": "MIT", | ||
"gypfile": true, | ||
"dependencies": { | ||
"nan": "^2.13.2", | ||
"node-pre-gyp": "^0.12.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,13 @@ | ||
#include <Cocoa/Cocoa.h> | ||
#include <string> | ||
#include <node.h> | ||
using namespace std; | ||
using v8::Array; | ||
using v8::FunctionCallbackInfo; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
Local<Array> get_file_names(Isolate *isolate); |
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,25 @@ | ||
#include "clip_osx.h" | ||
|
||
Local<Array> get_file_names(Isolate *isolate){ | ||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; | ||
NSArray* tempArray = [pasteboard pasteboardItems]; | ||
int count = 0; | ||
for(NSPasteboardItem *tmpItem in tempArray){ | ||
NSString *pathString = [tmpItem stringForType:@"public.file-url"]; | ||
const char* str = [pathString UTF8String]; | ||
if(str){ | ||
count++; | ||
} | ||
} | ||
Local<Array> fileNames = Array::New(isolate, count); | ||
count =0; | ||
for(NSPasteboardItem *tmpItem in tempArray){ | ||
NSString *pathString = [tmpItem stringForType:@"public.file-url"]; | ||
const char* str = [pathString UTF8String]; | ||
if(str){ | ||
fileNames->Set(count,String::NewFromUtf8(isolate,str)); | ||
count++; | ||
} | ||
} | ||
return fileNames; | ||
} |
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 @@ | ||
#include "clip_win.h" | ||
|
||
char *GBK2Utf8(const char *strGBK) | ||
{ | ||
WCHAR *str1; | ||
int n = MultiByteToWideChar(CP_ACP, 0, strGBK, -1, NULL, 0); | ||
str1 = new WCHAR[n]; | ||
MultiByteToWideChar(CP_ACP, 0, strGBK, -1, str1, n); | ||
n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL); | ||
char *str2 = new char[n]; | ||
WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL); | ||
delete[] str1; | ||
str1 = NULL; | ||
return str2; | ||
} | ||
|
||
Local<Array> get_file_names(Isolate *isolate) | ||
{ | ||
Local<Array> fileNames = Array::New(isolate, 0); | ||
if (OpenClipboard(NULL)) // open clipboard | ||
{ | ||
HDROP hDrop = HDROP(::GetClipboardData(CF_HDROP)); // get the file path hwnd of clipboard | ||
if (hDrop != NULL) | ||
{ | ||
char szFilePathName[MAX_PATH + 1] = { 0 }; | ||
UINT nNumOfFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); // get the count of files | ||
fileNames = Array::New(isolate, nNumOfFiles); | ||
for (UINT nIndex = 0; nIndex < nNumOfFiles; ++nIndex) | ||
{ | ||
memset(szFilePathName, 0, MAX_PATH + 1); | ||
DragQueryFile(hDrop, nIndex, szFilePathName, MAX_PATH); // get file name | ||
fileNames->Set(nIndex, String::NewFromUtf8(isolate, GBK2Utf8(szFilePathName))); | ||
} | ||
} | ||
CloseClipboard(); // close clipboard | ||
} | ||
return fileNames; | ||
} |
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,12 @@ | ||
#include <windows.h> | ||
#include <node.h> | ||
|
||
using v8::Array; | ||
using v8::FunctionCallbackInfo; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
Local<Array> get_file_names(Isolate *isolate); |
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,30 @@ | ||
#include <node.h> | ||
#ifdef __WIN32__ | ||
#include "clip_win.h" | ||
#elif __APPLE__ | ||
#include "clip_osx.h" | ||
#endif | ||
|
||
namespace clipboard | ||
{ | ||
using v8::Array; | ||
using v8::FunctionCallbackInfo; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
void readFiles(const FunctionCallbackInfo<Value> &args) | ||
{ | ||
Isolate *isolate = args.GetIsolate(); | ||
Local<Array> fileNames = get_file_names(isolate); | ||
args.GetReturnValue().Set(fileNames); | ||
} | ||
void Init(Local<Object> exports) | ||
{ | ||
NODE_SET_METHOD(exports, "readFiles", readFiles); | ||
} | ||
|
||
NODE_MODULE(NODE_GYP_MODULE_NAME, Init) | ||
} |
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,2 @@ | ||
const clipboard = require("../lib"); | ||
console.log("files:", clipboard.readFiles()); |