Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Throw exception as JS exception
Browse files Browse the repository at this point in the history
  • Loading branch information
seo-rii committed Apr 13, 2020
1 parent 2679f12 commit 98986a4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img alt="logo" src="./logo.png" width="300">

[![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)

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
104 changes: 56 additions & 48 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Napi::Number>().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<Napi::Number>().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<Napi::Number>().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<Napi::Number>().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();
}
}

Expand Down

0 comments on commit 98986a4

Please sign in to comment.