-
Notifications
You must be signed in to change notification settings - Fork 7
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
Masaki Tojo
committed
Nov 21, 2017
0 parents
commit 6a12572
Showing
13 changed files
with
737 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,50 @@ | ||
AccessModifierOffset: -2 | ||
AlignEscapedNewlinesLeft: true | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakBeforeMultilineStrings: true | ||
AlwaysBreakTemplateDeclarations: true | ||
BinPackParameters: true | ||
BreakBeforeBinaryOperators: false | ||
BreakBeforeBraces: Allman | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: false | ||
ColumnLimit: 80 | ||
CommentPragmas: \* | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
ConstructorInitializerIndentWidth: 2 | ||
ContinuationIndentWidth: 2 | ||
Cpp11BracedListStyle: true | ||
DerivePointerBinding: false | ||
ExperimentalAutoDetectBinPacking: false | ||
#ForEachMacros: | ||
IndentCaseLabels: true | ||
IndentFunctionDeclarationAfterType: true | ||
IndentWidth: 2 | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
#Language: Cpp | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCSpaceAfterProperty: true | ||
ObjCSpaceBeforeProtocolList: false | ||
PenaltyBreakBeforeFirstCallParameter: 1 | ||
PenaltyBreakComment: 60 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 200 | ||
PointerBindsToType: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInContainerLiterals: false | ||
SpacesInParentheses: false | ||
Standard: Cpp11 | ||
TabWidth: 8 | ||
UseTab: Never |
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 @@ | ||
/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,2 @@ | ||
-std=c++11 | ||
-Inode_modules/nan |
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,77 @@ | ||
# system-icon | ||
|
||
Get associated file/folder icon for Node.js. | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm install --save system-icon | ||
``` | ||
|
||
## Usage | ||
|
||
Get icon for file or folder path: | ||
|
||
```js | ||
const {writeFileSync} = require('fs'); | ||
const { | ||
getIconForPath, | ||
ICON_SIZE_MEDIUM | ||
} = require('system-icon'); | ||
|
||
getIconForPath("/path/to/file_or_folder", ICON_SIZE_MEDIUM, (err, result) => { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
writeFileSync("icon.png", result); | ||
} | ||
}); | ||
``` | ||
|
||
Get icon for file extension: | ||
|
||
```js | ||
const {writeFileSync} = require('fs'); | ||
const { | ||
getIconForExtension, | ||
ICON_SIZE_MEDIUM | ||
} = require('system-icon'); | ||
|
||
getIconForExtension(".ext", ICON_SIZE_MEDIUM, (err, result) => { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
writeFileSync("icon.png", result); | ||
} | ||
}); | ||
``` | ||
|
||
## API | ||
|
||
### Constants | ||
|
||
#### Size constants | ||
|
||
The correspondence between the size constants and the icon size actually obtainable on each platform is as follows: | ||
|
||
| Constant | Windows | macOS | | ||
| ----------------------- | ------- | ------- | | ||
| `ICON_SIZE_EXTRA_SMALL` | 16x16 | 16x16 | | ||
| `ICON_SIZE_SMALL` | 32x32 | 32x32 | | ||
| `ICON_SIZE_MEDIUM` | 64x64 | 64x64 | | ||
| `ICON_SIZE_LARGE` | 256x256 | 256x256 | | ||
| `ICON_SIZE_EXTRA_LARGE` | 256x256 | 512x512 | | ||
|
||
### Functions | ||
|
||
#### getIconForPath(path, size, callback) | ||
|
||
Gets associated icon for file or folder path, and returns it in the PNG format. | ||
|
||
#### getIconForExtension(extension, size, callback) | ||
|
||
Gets associated icon for file extension, and returns it in the PNG format. | ||
|
||
## 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "system_icon.hpp" | ||
#include <nan.h> | ||
|
||
NAN_METHOD(getIconForExtension) | ||
{ | ||
if (info.Length() < 3) | ||
{ | ||
Nan::ThrowTypeError("Wrong number of arguments"); | ||
return; | ||
} | ||
|
||
if (!info[0]->IsString() || !info[1]->IsNumber() || !info[2]->IsFunction()) | ||
{ | ||
Nan::ThrowTypeError("Wrong arguments"); | ||
return; | ||
} | ||
|
||
v8::String::Utf8Value extension{info[0]->ToString()}; | ||
auto size = static_cast<IconSize>(info[1]->Int32Value()); | ||
auto callback = new Nan::Callback(info[2].As<v8::Function>()); | ||
Nan::AsyncQueueWorker( | ||
new SystemIconAsyncWorker<ExtensionTag>(*extension, size, callback)); | ||
} | ||
|
||
NAN_METHOD(getIconForPath) | ||
{ | ||
if (info.Length() < 3) | ||
{ | ||
Nan::ThrowTypeError("Wrong number of arguments"); | ||
return; | ||
} | ||
|
||
if (!info[0]->IsString() || !info[1]->IsNumber() || !info[2]->IsFunction()) | ||
{ | ||
Nan::ThrowTypeError("Wrong arguments"); | ||
return; | ||
} | ||
|
||
v8::String::Utf8Value path{info[0]->ToString()}; | ||
auto size = static_cast<IconSize>(info[1]->Int32Value()); | ||
auto callback = new Nan::Callback(info[2].As<v8::Function>()); | ||
Nan::AsyncQueueWorker( | ||
new SystemIconAsyncWorker<PathTag>(*path, size, callback)); | ||
} | ||
|
||
NAN_MODULE_INIT(init) | ||
{ | ||
NAN_EXPORT(target, getIconForExtension); | ||
NAN_EXPORT(target, getIconForPath); | ||
|
||
Nan::Set(target, Nan::New("ICON_SIZE_EXTRA_SMALL").ToLocalChecked(), | ||
Nan::New(static_cast<int>(IconSize::ExtraSmall))); | ||
Nan::Set(target, Nan::New("ICON_SIZE_SMALL").ToLocalChecked(), | ||
Nan::New(static_cast<int>(IconSize::Small))); | ||
Nan::Set(target, Nan::New("ICON_SIZE_MEDIUM").ToLocalChecked(), | ||
Nan::New(static_cast<int>(IconSize::Medium))); | ||
Nan::Set(target, Nan::New("ICON_SIZE_LARGE").ToLocalChecked(), | ||
Nan::New(static_cast<int>(IconSize::Large))); | ||
Nan::Set(target, Nan::New("ICON_SIZE_EXTRA_LARGE").ToLocalChecked(), | ||
Nan::New(static_cast<int>(IconSize::ExtraLarge))); | ||
} | ||
|
||
NODE_MODULE(system_icon, 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,79 @@ | ||
{ | ||
'target_defaults': { | ||
'conditions': [ | ||
['OS=="win"', { | ||
'defines': [ | ||
'_WIN32_WINNT=0x0600', | ||
], | ||
}], | ||
], | ||
'msbuild_settings': { | ||
'ClCompile': { | ||
'WarningLevel': 'Level3', | ||
'Optimization': 'Full', | ||
'FunctionLevelLinking': 'true', | ||
}, | ||
'Lib': { | ||
'LinkTimeCodeGeneration': 'true', | ||
}, | ||
}, | ||
'msvs_settings': { | ||
'VCCLCompilerTool': { | ||
'WarningLevel': '3', | ||
'Optimization': '3', | ||
'EnableFunctionLevelLinking': 'true', | ||
}, | ||
'VCLibrarianTool': { | ||
'LinkTimeCodeGeneration': 'true', | ||
}, | ||
}, | ||
'xcode_settings': { | ||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', | ||
'CLANG_CXX_LIBRARY': 'libc++', | ||
'CLANG_ENABLE_OBJC_ARC': 'YES', | ||
'GCC_OPTIMIZATION_LEVEL': '3', | ||
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0', | ||
'GCC_WARN_SHADOW': 'YES', | ||
'GCC_WARN_UNUSED_VARIABLE': 'YES', | ||
'WARNING_CFLAGS': ['-Wall'], | ||
}, | ||
}, | ||
'targets': [ | ||
{ | ||
'target_name': 'addon', | ||
'include_dirs': [ | ||
'<!(node -e "require(\'nan\')")', | ||
], | ||
'sources': [ | ||
'addon.cpp', | ||
], | ||
'conditions': [ | ||
['OS=="mac"', { | ||
'link_settings': { | ||
'libraries': [ | ||
'-framework AppKit', | ||
], | ||
}, | ||
'sources': [ | ||
'system_icon_mac.mm', | ||
], | ||
}], | ||
['OS=="win"', { | ||
'link_settings': { | ||
'libraries': [ | ||
'Gdiplus.lib', | ||
], | ||
}, | ||
'sources': [ | ||
'system_icon_win.cpp', | ||
], | ||
}], | ||
['OS!="mac" and OS!="win"', { | ||
'sources': [ | ||
'system_icon.cpp', | ||
], | ||
}], | ||
], | ||
}, | ||
], | ||
} |
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 @@ | ||
module.exports = require('bindings')('addon'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,26 @@ | ||
{ | ||
"name": "system-icon", | ||
"description": "Get associated file/folder icon", | ||
"version": "0.0.0", | ||
"author": "Masaki Tojo", | ||
"bugs": { | ||
"url": "https://github.com/mtojo/node-system-icon/issues" | ||
}, | ||
"devDependencies": { | ||
"bindings": "~1.3.0", | ||
"nan": "~2.8.0" | ||
}, | ||
"engines": { | ||
"node": ">=6.0.0" | ||
}, | ||
"homepage": "https://github.com/mtojo/node-system-icon", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mtojo/node-system-icon.git" | ||
}, | ||
"scripts": { | ||
"install": "node-gyp rebuild" | ||
} | ||
} |
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 "system_icon.hpp" | ||
|
||
template <> | ||
void SystemIconAsyncWorker<ExtensionTag>::Execute() | ||
{ | ||
// Do nothing. | ||
} | ||
|
||
template <> | ||
void SystemIconAsyncWorker<PathTag>::Execute() | ||
{ | ||
// Do nothing. | ||
} |
Oops, something went wrong.