-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsystem_icon.hpp
58 lines (51 loc) · 1013 Bytes
/
system_icon.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <nan.h>
#include <string>
enum class IconSize
{
ExtraSmall,
Small,
Medium,
Large,
ExtraLarge
};
struct ExtensionTag
{
};
struct PathTag
{
};
template <class Tag>
class SystemIconAsyncWorker : public Nan::AsyncWorker
{
public:
SystemIconAsyncWorker(const char* name, IconSize size,
Nan::Callback* callback)
: Nan::AsyncWorker{callback}, name{name}, size{size}
{
}
void Execute() override;
protected:
void HandleOKCallback() override
{
if (!this->result.empty())
{
v8::Local<v8::Value> argv[] = {
Nan::Null(),
Nan::CopyBuffer(
static_cast<char*>(static_cast<void*>(this->result.data())),
this->result.size())
.ToLocalChecked(),
};
callback->Call(2, argv);
}
else
{
v8::Local<v8::Value> argv[] = {Nan::Error("Failed to load icon")};
callback->Call(1, argv);
}
}
private:
std::string name;
IconSize size;
std::vector<unsigned char> result;
};