diff --git a/README.md b/README.md index 51661e5..ad17f49 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ logo -[![Build Status](https://travis-ci.org/04seohyun/electron-acrylic-window.svg?branch=master)](https://travis-ci.org/04seohyun/electron-acrylic-window) +[![Build Status](https://travis-ci.com/04seohyun/electron-acrylic-window.svg?branch=master)](https://travis-ci.com/04seohyun/electron-acrylic-window) [![Dependencies](https://david-dm.org/04seohyun/electron-acrylic-window.svg)](https://david-dm.org/04seohyun/electron-acrylic-window) [![npm version](https://badge.fury.io/js/electron-acrylic-window.svg)](https://badge.fury.io/js/electron-acrylic-window) diff --git a/package-lock.json b/package-lock.json index 7c9b63b..fa79e44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "electron-acrylic-window", - "version": "0.0.1", + "version": "0.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -415,9 +415,9 @@ } }, "node-addon-api": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.1.tgz", - "integrity": "sha512-2+DuKodWvwRTrCfKOeR24KIc5unKjOh8mz17NCzVnHWfjAdDqbfbjqh7gUT+BkXBRQM52+xCHciKWonJ3CbJMQ==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.0.tgz", + "integrity": "sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA==" }, "node-gyp": { "version": "6.1.0", diff --git a/package.json b/package.json index a451344..4fc6293 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electron-acrylic-window", - "version": "0.0.2", + "version": "0.0.3", "description": "Add vibrancy effect for electron", "main": "index.js", "keywords": [ diff --git a/src/main.cc b/src/main.cc index 472936c..d6e33a7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -33,67 +33,75 @@ const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll")); void setVibrancy(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); - if (!IsWindows10OrGreater()) { - Napi::Error::New(env, "NOT_MATCHING_PLATFORM").ThrowAsJavaScriptException(); - return; - } - if (info.Length() != 1) { - Napi::TypeError::New(env, "WINDOW_NOT_GIVEN").ThrowAsJavaScriptException(); - return; - } - if (!info[0].IsNumber()) { - Napi::TypeError::New(env, "UNKNOWN").ThrowAsJavaScriptException(); - return; - } - HWND hWnd = (HWND) info[0].As().Int32Value(); - if (hModule) { - const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute) GetProcAddress( - hModule, "SetWindowCompositionAttribute"); - if (SetWindowCompositionAttribute) { - AccentPolicy policy = {ACCENT_ENABLE_BLURBEHIND, 2, 0, 0}; - WindowCompositionAttributeData data = {WCA_ACCENT_POLICY, &policy, sizeof(AccentPolicy)}; - SetWindowCompositionAttribute(hWnd, &data); + try { + if (!IsWindows10OrGreater()) { + Napi::Error::New(env, "NOT_MATCHING_PLATFORM").ThrowAsJavaScriptException(); + return; + } + if (info.Length() != 1) { + Napi::TypeError::New(env, "WINDOW_NOT_GIVEN").ThrowAsJavaScriptException(); + return; + } + if (!info[0].IsNumber()) { + Napi::TypeError::New(env, "UNKNOWN").ThrowAsJavaScriptException(); + return; + } + HWND hWnd = (HWND) info[0].As().Int64Value(); + if (hModule) { + const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute) GetProcAddress( + hModule, "SetWindowCompositionAttribute"); + if (SetWindowCompositionAttribute) { + AccentPolicy policy = {ACCENT_ENABLE_BLURBEHIND, 2, 0, 0}; + WindowCompositionAttributeData data = {WCA_ACCENT_POLICY, &policy, sizeof(AccentPolicy)}; + SetWindowCompositionAttribute(hWnd, &data); + } else { + Napi::Error::New(env, "FAIL_LOAD_DLL").ThrowAsJavaScriptException(); + return; + } + FreeLibrary(hModule); } else { Napi::Error::New(env, "FAIL_LOAD_DLL").ThrowAsJavaScriptException(); return; } - FreeLibrary(hModule); - } else { - Napi::Error::New(env, "FAIL_LOAD_DLL").ThrowAsJavaScriptException(); - return; + } catch (const char *ex) { + Napi::Error::New(env, "UNKNOWN").ThrowAsJavaScriptException(); } } void disableVibrancy(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); - if (!IsWindows10OrGreater()) { - Napi::Error::New(env, "NOT_MATCHING_PLATFORM").ThrowAsJavaScriptException(); - return; - } - if (info.Length() != 1) { - Napi::TypeError::New(env, "WINDOW_NOT_GIVEN").ThrowAsJavaScriptException(); - return; - } - if (!info[0].IsNumber()) { - Napi::TypeError::New(env, "UNKNOWN").ThrowAsJavaScriptException(); - return; - } - HWND hWnd = (HWND) info[0].As().Int64Value(); - if (hModule) { - const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute) GetProcAddress( - hModule, "SetWindowCompositionAttribute"); - if (SetWindowCompositionAttribute) { - AccentPolicy policy = {ACCENT_DISABLED, 0, 0, 0}; - WindowCompositionAttributeData data = {WCA_ACCENT_POLICY, &policy, sizeof(AccentPolicy)}; - SetWindowCompositionAttribute(hWnd, &data); + try { + if (!IsWindows10OrGreater()) { + Napi::Error::New(env, "NOT_MATCHING_PLATFORM").ThrowAsJavaScriptException(); + return; + } + if (info.Length() != 1) { + Napi::TypeError::New(env, "WINDOW_NOT_GIVEN").ThrowAsJavaScriptException(); + return; + } + if (!info[0].IsNumber()) { + Napi::TypeError::New(env, "UNKNOWN").ThrowAsJavaScriptException(); + return; + } + HWND hWnd = (HWND) info[0].As().Int64Value(); + if (hModule) { + const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute) GetProcAddress( + hModule, "SetWindowCompositionAttribute"); + if (SetWindowCompositionAttribute) { + AccentPolicy policy = {ACCENT_DISABLED, 0, 0, 0}; + WindowCompositionAttributeData data = {WCA_ACCENT_POLICY, &policy, sizeof(AccentPolicy)}; + SetWindowCompositionAttribute(hWnd, &data); + } else { + Napi::Error::New(env, "FAIL_LOAD_DLL").ThrowAsJavaScriptException(); + return; + } + FreeLibrary(hModule); } else { Napi::Error::New(env, "FAIL_LOAD_DLL").ThrowAsJavaScriptException(); return; } - FreeLibrary(hModule); - } else { - Napi::Error::New(env, "FAIL_LOAD_DLL").ThrowAsJavaScriptException(); - return; + } catch (const char *ex) { + Napi::Error::New(env, "UNKNOWN").ThrowAsJavaScriptException(); } }