Napi demo (#7)
* napi_demo * lifecycle注册问题 * finclip_register_lifecycle * electron * 补全几个函数 * electron demo Co-authored-by: caojiawen <caojiawen@finogeeks.club>master
parent
4e8c53bd20
commit
d41cbacc27
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,6 @@
|
|||
"electron": "^18.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"finclip": "file:../../vendor/win/x64"
|
||||
"finclip": "file:../../src/npm/build/Release"
|
||||
}
|
||||
}
|
|
@ -4,40 +4,119 @@ const path = require('path');
|
|||
const finclip = require('finclip');
|
||||
|
||||
let hwnd = 0;
|
||||
let appid_ = "";
|
||||
let config_;
|
||||
let mainWindow = null;
|
||||
let childWindow = null;
|
||||
let embed = { x: 300, y: 0 };
|
||||
let isOpen = false;
|
||||
let isEmbed = false;
|
||||
|
||||
const createMainWindow = () => {
|
||||
const win = new BrowserWindow({
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'mainPreload.js'),
|
||||
},
|
||||
});
|
||||
win.loadFile('../view/index.html');
|
||||
const handleBuffer = win.getNativeWindowHandle();
|
||||
mainWindow.loadFile('../view/index.html');
|
||||
};
|
||||
|
||||
const createChildWindow = () => {
|
||||
childWindow = new BrowserWindow({
|
||||
parent: mainWindow,
|
||||
transparent: true,
|
||||
frame: false,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'mainPreload.js'),
|
||||
},
|
||||
});
|
||||
const handleBuffer = childWindow.getNativeWindowHandle();
|
||||
hwnd = os.endianness() == 'LE' ? handleBuffer.readInt32LE() : handleBuffer.readInt32BE();
|
||||
console.log(hwnd);
|
||||
};
|
||||
|
||||
const openFinClipWindow = (arg) => {
|
||||
if (isOpen) return;
|
||||
const { domain, appkey, appid, secret } = arg;
|
||||
finclip.setDomain(domain);
|
||||
finclip.setAppkey(appkey);
|
||||
finclip.setAppid(appid);
|
||||
finclip.setSecret(secret);
|
||||
appid_ = appid;
|
||||
const factory = finclip.finclip_get_packer_factory();
|
||||
const packer = finclip.finclip_packer_factory_get_config_packer(factory);
|
||||
finclip.finclip_initialize(packer);
|
||||
const config = finclip.finclip_create_params();
|
||||
finclip.finclip_params_set(config, "appstore", "1");
|
||||
finclip.finclip_params_set(config, "appkey", appkey);
|
||||
finclip.finclip_params_set(config, "secret", secret);
|
||||
finclip.finclip_params_set(config, "domain", domain);
|
||||
const finclipPath = path.resolve(__dirname, '../../../vendor/win/x64/finclip.exe');
|
||||
const result = finclip.start({
|
||||
handle: 0,
|
||||
finclipPath,
|
||||
});
|
||||
finclip.finclip_params_set(config, "exe_path", finclipPath);
|
||||
finclip.finclip_config_packer_add_config(packer, config);
|
||||
finclip.finclip_params_set(config, "window_type", "1");
|
||||
config_ = config;
|
||||
finclip.finclip_start_applet("1", appid);
|
||||
isOpen = true;
|
||||
};
|
||||
|
||||
const embedFinClipWindow = () => {
|
||||
finclip.embed({ handle: hwnd });
|
||||
if (!isOpen) return;
|
||||
createChildWindow();
|
||||
finclip.finclip_start_applet_embed("1", appid_, config_, hwnd);
|
||||
resizeChildWindow();
|
||||
subscribe();
|
||||
isEmbed = true;
|
||||
};
|
||||
|
||||
const closeFinClipWindow = () => {
|
||||
const result = finclip.close();
|
||||
console.log(result);
|
||||
if (!isOpen) return;
|
||||
finclip.finclip_close_applet(appid_);
|
||||
isOpen = false;
|
||||
if (isEmbed) {
|
||||
unsubscribe();
|
||||
}
|
||||
isEmbed = false;
|
||||
};
|
||||
|
||||
const onResize = () => {
|
||||
const bounds = childWindow.getContentBounds();
|
||||
finclip.finclip_set_position(appid_, bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
};
|
||||
|
||||
const subscribe = () => {
|
||||
mainWindow.on('move', resizeChildWindow);
|
||||
mainWindow.on('resize', resizeChildWindow);
|
||||
mainWindow.on('minimize', childWindow.minimize);
|
||||
mainWindow.on('restore', restoreChildWindow);
|
||||
|
||||
childWindow.on('resize', onResize);
|
||||
}
|
||||
|
||||
const unsubscribe = () => {
|
||||
mainWindow.removeListener('move', resizeChildWindow);
|
||||
mainWindow.removeListener('resize', resizeChildWindow);
|
||||
mainWindow.removeListener('minimize', childWindow.minimize);
|
||||
mainWindow.removeListener('restore', restoreChildWindow);
|
||||
|
||||
childWindow.removeListener('resize', onResize);
|
||||
|
||||
childWindow.close();
|
||||
}
|
||||
|
||||
const resizeChildWindow = () => {
|
||||
const parentBounds = mainWindow.getContentBounds();
|
||||
childWindow.setBounds({
|
||||
x: parentBounds.x + embed.x,
|
||||
y: parentBounds.y + embed.y,
|
||||
width: parentBounds.width - embed.x,
|
||||
height: parentBounds.height - embed.y,
|
||||
});
|
||||
};
|
||||
|
||||
const restoreChildWindow = () => {
|
||||
childWindow.restore();
|
||||
resizeChildWindow();
|
||||
};
|
||||
|
||||
ipcMain.on('OPEN_FINCLIP_WINDOW', (event, arg) => {
|
||||
|
@ -58,7 +137,6 @@ ipcMain.on('SET_FINCLIP_POSITION', (event, arg) => {
|
|||
left, top,
|
||||
width, height,
|
||||
});
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
app.whenReady().then(() => {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<div>
|
||||
<br />
|
||||
</div>
|
||||
<div>
|
||||
<!-- <div>
|
||||
<div>
|
||||
设置位置
|
||||
</div>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<div>width<input type="number" id="width" name="width" value="1000"></div>
|
||||
<div>height<input type="number" id="height" name="height" value="1000"></div>
|
||||
<div><button onclick="setFinClipPosition()">set position</button></div>
|
||||
</div>
|
||||
</div> -->
|
||||
</body>
|
||||
<script src="../src/mainScript.js"></script>
|
||||
</html>
|
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "_finclip",
|
||||
"target_name": "finclip",
|
||||
"win_delay_load_hook": "true",
|
||||
"sources": [
|
||||
"finclip.cpp"
|
||||
|
@ -12,15 +12,15 @@
|
|||
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
|
||||
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
|
||||
"libraries": [
|
||||
"../../../vendor/win/x64/FinClipSDKWrapper.lib",
|
||||
"../FinClipSDKWrapper.lib",
|
||||
],
|
||||
"defines": ["_UNICODE", "UNICODE", "NAPI_DISABLE_CPP_EXCEPTIONS"],
|
||||
"copies": [
|
||||
{
|
||||
"destination": "<(module_root_dir)/build/Release/",
|
||||
"files": [
|
||||
"../../vendor/win/x64/FinClipSDKWrapper.lib",
|
||||
"../../vendor/win/x64/FinClipSDKWrapper.dll",
|
||||
"./FinClipSDKWrapper.lib",
|
||||
"./FinClipSDKWrapper.dll",
|
||||
"../../vendor/win/x64/finclip.exe",
|
||||
"../../vendor/win/x64/finclip.exp",
|
||||
"../../vendor/win/x64/finclip.lib",
|
||||
|
|
|
@ -1,137 +1,228 @@
|
|||
#include "../finclip_api.h"
|
||||
#include "./finclip.h"
|
||||
#include <windows.h>
|
||||
#include "./finclip_api.h"
|
||||
#include "./finclip_api_const.h"
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <napi.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
#include <winuser.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
#pragma comment(lib, "FinClipSDKWrapper.lib")
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace NodeFinClip {
|
||||
using namespace Napi;
|
||||
std::string domain;
|
||||
std::string appkey;
|
||||
std::string appid;
|
||||
std::string secret;
|
||||
char app_store[] = "1";
|
||||
namespace NodeFinClip {
|
||||
|
||||
Napi::String start(const Napi::CallbackInfo& info) {
|
||||
std::vector<IPackerFactory*> factory_vector;
|
||||
std::vector<IFinConfigPacker*> packer_vector;
|
||||
std::vector<FinclipParams*> config_vector;
|
||||
std::map<int, Napi::ThreadSafeFunction> lifecycle_callback;
|
||||
std::map<int, Napi::ObjectReference> lifecycle_value;
|
||||
|
||||
Napi::Object FinclipGetPackerFactory(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::Object args = info[0].ToObject();
|
||||
int handle = args.Get("handle").ToNumber().Int32Value();
|
||||
|
||||
std::string path = args.Get("finclipPath").ToString();
|
||||
|
||||
auto *factory = finclip_get_packer_factory();
|
||||
auto *packer = finclip_packer_factory_get_config_packer(factory);
|
||||
finclip_initialize(packer);
|
||||
FinclipParams *config;
|
||||
config = finclip_config_packer_get_config(packer, app_store);
|
||||
if (config == nullptr) config = finclip_create_params();
|
||||
|
||||
finclip_params_set(config, FINCLIP_CONFIG_EXE_PATH, path.c_str());
|
||||
finclip_params_set(config, FINCLIP_CONFIG_APPSTORE, "1");
|
||||
finclip_params_set(config, FINCLIP_CONFIG_APPKEY, appkey.c_str());
|
||||
finclip_params_set(config, FINCLIP_CONFIG_SECRET, secret.c_str());
|
||||
finclip_params_set(config, FINCLIP_CONFIG_DOMAIN, domain.c_str());
|
||||
// 可选参数
|
||||
finclip_params_set(config, FINCLIP_CONFIG_SHOW_LOADING, "0");
|
||||
finclip_config_packer_add_config(packer, config);
|
||||
|
||||
if (handle) {
|
||||
finclip_start_applet_embed(app_store, appid.c_str(), (HWND)handle);
|
||||
} else {
|
||||
finclip_start_applet(app_store, appid.c_str());
|
||||
}
|
||||
|
||||
return Napi::String::New(env, "success");
|
||||
factory_vector.push_back(factory);
|
||||
auto result = Napi::Object::New(env);
|
||||
result.Set("id", factory_vector.size() - 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::String embed(const Napi::CallbackInfo& info) {
|
||||
Napi::Object FinclipPackerFactoryGetConfigPacker(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::Object args = info[0].ToObject();
|
||||
int handle = args.Get("handle").ToNumber().Int32Value();
|
||||
finclip_embed_applet(app_store, appid.c_str(), (HWND)handle);
|
||||
return Napi::String::New(env, "success");
|
||||
Napi::Object factory_object = info[0].ToObject();
|
||||
int factory_id = factory_object.Get("id").ToNumber();
|
||||
auto *factory = factory_vector.at(factory_id);
|
||||
auto *packer = finclip_packer_factory_get_config_packer(factory);
|
||||
packer_vector.push_back(packer);
|
||||
auto result = Napi::Object::New(env);
|
||||
result.Set("id", packer_vector.size() - 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::String close(const Napi::CallbackInfo& info) {
|
||||
Napi::Number FinclipInitialize(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::Object packer_object = info[0].ToObject();
|
||||
int packer_id = packer_object.Get("id").ToNumber();
|
||||
auto *packer = packer_vector.at(packer_id);
|
||||
finclip_initialize(packer);
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Object FinclipCreateParams(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
auto *config = finclip_create_params();
|
||||
config_vector.push_back(config);
|
||||
auto result = Napi::Object::New(env);
|
||||
result.Set("id", config_vector.size() - 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipParamsSet(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::Object config_object = info[0].ToObject();
|
||||
Napi::String key = info[1].ToString();
|
||||
Napi::String value = info[2].ToString();
|
||||
int config_id = config_object.Get("id").ToNumber();
|
||||
auto *config = config_vector.at(config_id);
|
||||
finclip_params_set(config, key.Utf8Value().c_str(), value.Utf8Value().c_str());
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipConfigPackerAddConfig(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::Object packer_object = info[0].ToObject();
|
||||
int packer_id = packer_object.Get("id").ToNumber();
|
||||
auto *packer = packer_vector.at(packer_id);
|
||||
Napi::Object config_object = info[1].ToObject();
|
||||
int config_id = config_object.Get("id").ToNumber();
|
||||
auto *config = config_vector.at(config_id);
|
||||
finclip_config_packer_add_config(packer, config);
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipStartApplet(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::String app_store = info[0].ToString();
|
||||
Napi::String app_id = info[1].ToString();
|
||||
finclip_start_applet(app_store.Utf8Value().c_str(), app_id.Utf8Value().c_str());
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipStartAppletEmbed(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::String app_store = info[0].ToString();
|
||||
Napi::String app_id = info[1].ToString();
|
||||
Napi::Object config_object = info[2].ToObject();
|
||||
int config_id = config_object.Get("id").ToNumber();
|
||||
auto *config = config_vector.at(config_id);
|
||||
Napi::Number hwnd_number = info[3].ToNumber();
|
||||
HWND hwnd = (HWND)hwnd_number.Int64Value();
|
||||
finclip_start_applet_embed(app_store.Utf8Value().c_str(), app_id.Utf8Value().c_str(), config, hwnd);
|
||||
auto style = GetWindowLongPtrA(hwnd, GWL_STYLE);
|
||||
if (!(style & WS_CLIPCHILDREN)) {
|
||||
SetWindowLongPtrA(hwnd, GWL_STYLE, style ^ WS_CLIPCHILDREN ^ WS_CLIPSIBLINGS);
|
||||
}
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipEmbedApplet(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::String app_store = info[0].ToString();
|
||||
Napi::String app_id = info[1].ToString();
|
||||
Napi::Number hwnd_number = info[2].ToNumber();
|
||||
HWND hwnd = (HWND)hwnd_number.Int64Value();
|
||||
finclip_embed_applet(app_store.Utf8Value().c_str(), app_id.Utf8Value().c_str(), hwnd);
|
||||
auto style = GetWindowLongPtrA(hwnd, GWL_STYLE);
|
||||
if (!(style & WS_CLIPCHILDREN)) {
|
||||
SetWindowLongPtrA(hwnd, GWL_STYLE, style ^ WS_CLIPCHILDREN ^ WS_CLIPSIBLINGS);
|
||||
}
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipSetPosition(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::String app_id = info[0].ToString();
|
||||
Napi::Number left = info[1].ToNumber();
|
||||
Napi::Number top = info[2].ToNumber();
|
||||
Napi::Number width = info[3].ToNumber();
|
||||
Napi::Number height = info[4].ToNumber();
|
||||
finclip_set_position(app_id.Utf8Value().c_str(), left.Int64Value(), top.Int64Value(), width.Int64Value(), height.Int64Value());
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipCloseApplet(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::String app_id = info[0].ToString();
|
||||
finclip_close_applet(app_id.Utf8Value().c_str());
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Number FinclipCloseAllApplet(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
finclip_close_all_applet();
|
||||
return Napi::String::New(env, "success");
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::String setAppletPos(const Napi::CallbackInfo& info) {
|
||||
Napi::Number FinclipHideApplet(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::Object args = info[0].ToObject();
|
||||
int left = args.Get("left").ToNumber().Int32Value();
|
||||
int top = args.Get("top").ToNumber().Int32Value();
|
||||
int width = args.Get("width").ToNumber().Int32Value();
|
||||
int height = args.Get("height").ToNumber().Int32Value();
|
||||
finclip_set_position(appid.c_str(), left, top, width, height);
|
||||
return Napi::String::New(env, "success");
|
||||
Napi::String app_id = info[0].ToString();
|
||||
finclip_hide_applet(app_id.Utf8Value().c_str());
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::String createWindow(const Napi::CallbackInfo& info) {
|
||||
Napi::Number FinclipShowApplet(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::Object args = info[0].ToObject();
|
||||
CreateWindowW(L"child_finclip", L"test", WS_VISIBLE, 0, 0, 1024, 768, nullptr,
|
||||
nullptr, nullptr, nullptr);
|
||||
return Napi::String::New(env, "success");
|
||||
Napi::String app_id = info[0].ToString();
|
||||
finclip_show_applet(app_id.Utf8Value().c_str());
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::String setDomain(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
domain = info[0].ToString();
|
||||
return Napi::String::New(env, "success");
|
||||
void LifecicleHandle(LifecycleType type, const char* appid, void* input) {
|
||||
auto callback = [type](Napi::Env env,
|
||||
Napi::Function jsCallback) {
|
||||
auto value_it = lifecycle_value.find(type);
|
||||
if (value_it != lifecycle_value.end()) {
|
||||
auto& value = value_it->second;
|
||||
jsCallback.Call({value.Value()});
|
||||
}
|
||||
};
|
||||
|
||||
auto it = lifecycle_callback.find(type);
|
||||
if (it != lifecycle_callback.end()) {
|
||||
auto& thread_safe_Callback = it->second;
|
||||
thread_safe_Callback.NonBlockingCall(callback);
|
||||
thread_safe_Callback.Release();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::String setAppid(const Napi::CallbackInfo& info) {
|
||||
Napi::Number FinclipRegisterLifecycle(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
appid = info[0].ToString();
|
||||
return Napi::String::New(env, "success");
|
||||
}
|
||||
Napi::String app_id = info[0].ToString();
|
||||
Napi::Number liftcycle = info[1].ToNumber();
|
||||
Napi::Function api_function = info[2].As<Napi::Function>();
|
||||
Napi::Object value = info[3].ToObject();
|
||||
|
||||
lifecycle_callback[liftcycle.Int32Value()] =
|
||||
Napi::ThreadSafeFunction::New(env, api_function, "Callback", 0, 1);
|
||||
lifecycle_value[liftcycle.Int32Value()] = Napi::Persistent(value);
|
||||
|
||||
finclip_register_lifecycle(app_id.Utf8Value().c_str(),
|
||||
(LifecycleType)liftcycle.Int32Value(),
|
||||
LifecicleHandle,
|
||||
env
|
||||
);
|
||||
|
||||
Napi::String setAppkey(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
appkey = info[0].ToString();
|
||||
return Napi::String::New(env, "success");
|
||||
}
|
||||
|
||||
Napi::String setSecret(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
secret = info[0].ToString();
|
||||
return Napi::String::New(env, "success");
|
||||
auto result = Napi::Number::New(env, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
exports.Set(Napi::String::New(env, "start"), Napi::Function::New(env, start));
|
||||
exports.Set(Napi::String::New(env, "close"), Napi::Function::New(env, close));
|
||||
|
||||
exports.Set(Napi::String::New(env, "setDomain"), Napi::Function::New(env, setDomain));
|
||||
exports.Set(Napi::String::New(env, "setAppid"), Napi::Function::New(env, setAppid));
|
||||
exports.Set(Napi::String::New(env, "setAppkey"), Napi::Function::New(env, setAppkey));
|
||||
exports.Set(Napi::String::New(env, "setSecret"), Napi::Function::New(env, setSecret));
|
||||
|
||||
exports.Set(Napi::String::New(env, "setAppletPos"),
|
||||
Napi::Function::New(env, setAppletPos));
|
||||
exports.Set(Napi::String::New(env, "createWindow"),
|
||||
Napi::Function::New(env, createWindow));
|
||||
exports.Set(Napi::String::New(env, "embed"),
|
||||
Napi::Function::New(env, embed));
|
||||
exports.Set(Napi::String::New(env, "finclip_get_packer_factory"), Napi::Function::New(env, FinclipGetPackerFactory));
|
||||
exports.Set(Napi::String::New(env, "finclip_packer_factory_get_config_packer"), Napi::Function::New(env, FinclipPackerFactoryGetConfigPacker));
|
||||
exports.Set(Napi::String::New(env, "finclip_initialize"), Napi::Function::New(env, FinclipInitialize));
|
||||
exports.Set(Napi::String::New(env, "finclip_create_params"), Napi::Function::New(env, FinclipCreateParams));
|
||||
exports.Set(Napi::String::New(env, "finclip_params_set"), Napi::Function::New(env, FinclipParamsSet));
|
||||
exports.Set(Napi::String::New(env, "finclip_config_packer_add_config"), Napi::Function::New(env, FinclipConfigPackerAddConfig));
|
||||
exports.Set(Napi::String::New(env, "finclip_start_applet"), Napi::Function::New(env, FinclipStartApplet));
|
||||
exports.Set(Napi::String::New(env, "finclip_start_applet_embed"), Napi::Function::New(env, FinclipStartAppletEmbed));
|
||||
exports.Set(Napi::String::New(env, "finclip_embed_applet"), Napi::Function::New(env, FinclipEmbedApplet));
|
||||
exports.Set(Napi::String::New(env, "finclip_set_position"), Napi::Function::New(env, FinclipSetPosition));
|
||||
exports.Set(Napi::String::New(env, "finclip_close_applet"), Napi::Function::New(env, FinclipCloseApplet));
|
||||
exports.Set(Napi::String::New(env, "finclip_close_all_applet"), Napi::Function::New(env, FinclipCloseAllApplet));
|
||||
exports.Set(Napi::String::New(env, "finclip_hide_applet"), Napi::Function::New(env, FinclipHideApplet));
|
||||
exports.Set(Napi::String::New(env, "finclip_show_applet"), Napi::Function::New(env, FinclipShowApplet));
|
||||
exports.Set(Napi::String::New(env, "finclip_register_lifecycle"), Napi::Function::New(env, FinclipRegisterLifecycle));
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_API_MODULE(addon, Init)
|
||||
} // namespace NodeFinClip
|
||||
} // namespace NodeFinClip
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef FINCLIP_H
|
||||
#define FINCLIP_H
|
||||
|
||||
#include "../finclip_api.h"
|
||||
|
||||
typedef IPackerFactory *(FINSTDMETHODCALLTYPE *findll_get_packer_factory)();
|
||||
typedef IFinConfigPacker *(
|
||||
FINSTDMETHODCALLTYPE *findll_packer_factory_get_config_packer)(
|
||||
IPackerFactory *factory);
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_config_packer_add_config)(
|
||||
IFinConfigPacker *packer, FinclipParams *config);
|
||||
|
||||
typedef void(FINSTDMETHODCALLTYPE *findll_register_api)(
|
||||
IFinConfigPacker *packer, FinClipApiType type, const char *apis,
|
||||
FinclipApiHandle handle, void *input);
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_initialize)(
|
||||
IFinConfigPacker *configpacker);
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_start_applet)(char *appstore,
|
||||
const char *appid);
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_invoke_api)(
|
||||
FinClipApiType type, const char *app_id, const char *api_name,
|
||||
const char *params, FinclipApiCallback callback, void *input);
|
||||
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_embed_applet)(const char *appstore,
|
||||
const char *appid,
|
||||
HWND container);
|
||||
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_params_set)(FinclipParams *params,
|
||||
const char *key,
|
||||
const char *value);
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_params_del)(FinclipParams *params,
|
||||
const char *key);
|
||||
typedef FinclipParams *(FINSTDMETHODCALLTYPE *findll_create_params)();
|
||||
typedef void(FINSTDMETHODCALLTYPE *findll_destory_params)(
|
||||
FinclipParams *params);
|
||||
typedef int(FINSTDMETHODCALLTYPE *findll_close_all_applet)();
|
||||
|
||||
#endif // MAINWINDOW_H
|
|
@ -0,0 +1,182 @@
|
|||
#ifndef WRAPPER_SRC_PUBLIC_FINCLIP_API_H_
|
||||
#define WRAPPER_SRC_PUBLIC_FINCLIP_API_H_
|
||||
|
||||
#include "finclip_api_const.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct IKnown IKnown;
|
||||
typedef struct IResultSet IResultSet;
|
||||
typedef struct IEvent IEvent;
|
||||
typedef struct IFinPacker IFinPacker;
|
||||
typedef struct FinclipParams FinclipParams;
|
||||
typedef struct IFinConfigPacker IFinConfigPacker;
|
||||
typedef struct IPackerFactory IPackerFactory;
|
||||
typedef struct FinclipCallback FinclipCallback;
|
||||
typedef void (*FinClipSDKCallback)(IEvent*);
|
||||
|
||||
/**
|
||||
* @brief SDK初始化
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE
|
||||
finclip_initialize(IFinConfigPacker* configpacker);
|
||||
|
||||
/**
|
||||
* @brief 获取配置工厂
|
||||
*/
|
||||
DLL_EXPORT IPackerFactory* FINSTDMETHODCALLTYPE finclip_get_packer_factory();
|
||||
|
||||
/**
|
||||
* @brief 启动
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_start_applet(const char* appstore,
|
||||
const char* appid);
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_start_applet_params(
|
||||
const char* appstore, const char* appid, void* params);
|
||||
/**
|
||||
* @brief 关闭所有小程序
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_close_all_applet();
|
||||
|
||||
/**
|
||||
* @brief 根据appid关闭小程序
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_close_applet(const char* appid);
|
||||
|
||||
/**
|
||||
* @brief 根据appid隐藏小程序
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_hide_applet(const char* appid);
|
||||
|
||||
/**
|
||||
* @brief 根据appid显示小程序
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_show_applet(const char* appid);
|
||||
|
||||
/**
|
||||
* @brief 根据appid显示小程序
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_register_lifecycle(const char* appid,
|
||||
LifecycleType lifecycle,
|
||||
FinclipLifecycleHandle handle,
|
||||
void* input);
|
||||
|
||||
/**
|
||||
* @brief 设置小程序窗口位置
|
||||
*
|
||||
*/
|
||||
DLL_EXPORT void FINSTDMETHODCALLTYPE finclip_set_position(const char* appid,
|
||||
int left, int top,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
DLL_EXPORT IFinConfigPacker* FINSTDMETHODCALLTYPE
|
||||
finclip_packer_factory_get_config_packer(IPackerFactory* factory);
|
||||
|
||||
/**
|
||||
* @brief 新建配置
|
||||
*/
|
||||
DLL_EXPORT FinclipParams* FINSTDMETHODCALLTYPE
|
||||
finclip_config_packer_new_config(IFinConfigPacker* packer);
|
||||
|
||||
/**
|
||||
* @brief 获取配置, 如果获取失败, 则返回NULL
|
||||
*/
|
||||
DLL_EXPORT FinclipParams* FINSTDMETHODCALLTYPE
|
||||
finclip_config_packer_get_config(IFinConfigPacker* packer, char* appstore);
|
||||
|
||||
/**
|
||||
* @brief 增加配置
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_config_packer_add_config(
|
||||
IFinConfigPacker* packer, FinclipParams* config);
|
||||
|
||||
/**
|
||||
* @brief 注册自定义api, 供小程序或h5调用
|
||||
* @param packer
|
||||
* @param type 类型, 区分h5与小程序
|
||||
* @param apis api名称
|
||||
* @param handle 处理函数
|
||||
* @param input 自定义参数, 透传给handle
|
||||
*/
|
||||
DLL_EXPORT void FINSTDMETHODCALLTYPE
|
||||
finclip_register_api(IFinConfigPacker* packer, FinClipApiType type,
|
||||
const char* apis, FinclipApiHandle handle, void* input);
|
||||
|
||||
/**
|
||||
* @brief 创建启动参数
|
||||
*/
|
||||
DLL_EXPORT FinclipParams* FINSTDMETHODCALLTYPE finclip_create_params();
|
||||
|
||||
/**
|
||||
* @brief 销毁启动参数
|
||||
*/
|
||||
DLL_EXPORT void FINSTDMETHODCALLTYPE
|
||||
finclip_destory_params(FinclipParams* params);
|
||||
|
||||
/**
|
||||
* @brief 设置启动参数
|
||||
*/
|
||||
DLL_EXPORT void FINSTDMETHODCALLTYPE finclip_params_set(FinclipParams* params,
|
||||
const char* key,
|
||||
const char* value);
|
||||
/**
|
||||
* @brief 根据key删除启动启动参数
|
||||
*/
|
||||
DLL_EXPORT void FINSTDMETHODCALLTYPE finclip_params_del(FinclipParams* params,
|
||||
const char* key);
|
||||
|
||||
#ifdef _WIN32
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_embed_applet(const char* appstore,
|
||||
const char* appid,
|
||||
HWND container);
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_start_applet_embed(
|
||||
const char* appstore, const char* appid, void* params, HWND container);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief 调用h5中的自定义api, 小程序不支持自定义api
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_invoke_api(
|
||||
FinClipApiType type, const char* app_id, const char* api_name,
|
||||
const char* params, FinclipApiCallback callback, void* input);
|
||||
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE
|
||||
finclip_batch_app_info(const char* app_id, const char* req_list,
|
||||
FinclipApiCallback callback, void* input);
|
||||
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE
|
||||
finclip_search_app(const char* app_id, const char* search_text,
|
||||
FinclipApiCallback callback, void* input);
|
||||
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE
|
||||
finclip_set_app_cache_params(int count, int lifetime, const char* ignore_list);
|
||||
|
||||
/**
|
||||
* @brief 回调函数设置返回值
|
||||
*/
|
||||
DLL_EXPORT int FINSTDMETHODCALLTYPE finclip_callback_res(const char* app_id,
|
||||
int callback_id,
|
||||
void* result);
|
||||
|
||||
/**
|
||||
* @brief 获取已经打开的小程序
|
||||
*/
|
||||
DLL_EXPORT bool FINSTDMETHODCALLTYPE finclip_is_applet_open(const char* app_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WRAPPER_SRC_PUBLIC_FINCLIP_API_H_ */
|
|
@ -0,0 +1,130 @@
|
|||
#ifndef WRAPPER_SRC_PUBLIC_FINCLIP_API_CONST_H_
|
||||
#define WRAPPER_SRC_PUBLIC_FINCLIP_API_CONST_H_
|
||||
|
||||
#define FIN_SID const char*
|
||||
#define FIN_OK 0
|
||||
#define FIN_FAIL 1
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define FINCLIP_WINDOW_HANDLE HWND
|
||||
#elif defined __linux__
|
||||
#include <gtk/gtk.h>
|
||||
#define FINCLIP_WINDOW_HANDLE GtkWindow*
|
||||
#elif defined __APPLE__
|
||||
typedef struct objc_object* FINCLIP_WINDOW_HANDLE;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef FINSTDMETHODCALLTYPE
|
||||
#define FINSTDMETHODCALLTYPE
|
||||
#define DLL_EXPORT extern "C" __declspec(dllexport)
|
||||
#endif
|
||||
#else
|
||||
#define FINSTDMETHODCALLTYPE
|
||||
#define DLL_EXPORT
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Config: 小程序框架的配置信息
|
||||
#define FINCLIP_CONFIG_APPSTORE "appstore"
|
||||
// appkey, secret, domain 从管理后台获取, 必填
|
||||
#define FINCLIP_CONFIG_APPKEY "appkey"
|
||||
#define FINCLIP_CONFIG_SECRET "secret"
|
||||
#define FINCLIP_CONFIG_DOMAIN "domain"
|
||||
// windows: finclip.exe位置, 默认为 ./finclip, 即当前目录下的finclip文件夹
|
||||
// macos: finclip.app的位置, 默认为
|
||||
#define FINCLIP_CONFIG_EXE_PATH "exe_path"
|
||||
// cef路径,不设置则跟exe_path相同
|
||||
#define FINCLIP_CONFIG_CEF_PATH "cef_path"
|
||||
|
||||
#define FINCLIP_CONFIG_WEB_PATH "web_path"
|
||||
#define FINCLIP_CONFIG_WEB_PORT "web_port"
|
||||
|
||||
// Params: 每个小程序独立设置, 0: 独立模式, 1: 嵌入模式
|
||||
// 注意, 嵌入模式目前仅支持windows, 且必须调用finclip_embed_applet, 完成嵌入.
|
||||
#define FINCLIP_UI_CONFIG_WINDOW_TYPE "window_type"
|
||||
// 是否展示loading动画, 1: 展示, 0: 不展示
|
||||
#define FINCLIP_UI_CONFIG_SHOW_LOADING "show_loading"
|
||||
// 是否强制小程序更新,1: 强制, 0, 不强制
|
||||
#define FINCLIP_UI_CONFIG_FORCE_APPLET_UPDATE "force_applet_update"
|
||||
// 是否展示返回按钮, hidden: 隐藏, normal: 显示
|
||||
#define FINCLIP_UI_CONFIG_TITLE_BAR_BACK_BUTTON "title_bar_back_button"
|
||||
// 是否展示关闭按钮, hidden: 隐藏, normal: 显示
|
||||
#define FINCLIP_UI_CONFIG_TITLE_BAR_CLOSE_BUTTON "title_bar_close_button"
|
||||
// 标题栏更多菜单设置, hidden: 隐藏, normal: 显示
|
||||
#define FINCLIP_UI_CONFIG_TITLE_BAR_MORE_BUTTON "title_bar_more_button"
|
||||
// 初始窗口高度
|
||||
#define FINCLIP_UI_CONFIG_WINDOW_HEIGHT "window_height"
|
||||
// 初始窗口宽度
|
||||
#define FINCLIP_UI_CONFIG_WINDOW_WIDTH "window_width"
|
||||
// 最小窗口高度
|
||||
#define FINCLIP_UI_CONFIG_WINDOW_MIN_HEIGHT "window_min_height"
|
||||
// 最小窗口宽度
|
||||
#define FINCLIP_UI_CONFIG_WINDOW_MIN_WIDTH "window_min_width"
|
||||
// 右上角关闭按钮使用隐藏窗口代替关闭功能(样式无关), 1: 隐藏, 0: 关闭
|
||||
#define FINCLIP_UI_CONFIG_TITLE_BAR_CLOSE_BUTTON_HIDE "title_bar_close_button_hide"
|
||||
|
||||
// 小程序首屏路径
|
||||
#define FINCLIP_PARAMS_PAGE_PATH "page_path"
|
||||
// 传给小程序的启动参数
|
||||
#define FINCLIP_PARAMS_START_PARAMS "start_params"
|
||||
// 启动设置, 可以设置是否同步更新小程序, 基础库等, 默认异步,
|
||||
// 参见下面的StartFlags
|
||||
#define FINCLIP_PARAMS_START_FLAG "start_flag"
|
||||
|
||||
/**
|
||||
* @brief 启动机制设置
|
||||
* kAsync: 异步启动
|
||||
* kBaseLibrarySync: 基础库同步加载
|
||||
* kAppletSync: 小程序同步加载
|
||||
*/
|
||||
enum StartFlags {
|
||||
kAsync = 0,
|
||||
kBaseLibrarySync = 1 << 0,
|
||||
kAppletSync = 1 << 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 生命周期类型
|
||||
*
|
||||
*/
|
||||
enum LifecycleType {
|
||||
kLifecycleStarted = 1,
|
||||
kLifecycleClosed = 2,
|
||||
kLifecycleHide = 3,
|
||||
kLifecycleShow = 4,
|
||||
kLifecycleDomReady = 5,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 自定义API类型,分别用于小程序和jssdk
|
||||
*
|
||||
*/
|
||||
typedef enum { kApplet, kWebView } FinClipApiType;
|
||||
/**
|
||||
* @brief 调用h5方法后的返回值回调
|
||||
*
|
||||
*/
|
||||
typedef void (*FinclipApiCallback)(const char* res, void* input);
|
||||
|
||||
/**
|
||||
* @brief 自定义api
|
||||
*
|
||||
*/
|
||||
typedef void (*FinclipApiHandle)(const char* event, const char* param,
|
||||
void* input, int callbackid);
|
||||
|
||||
/**
|
||||
* @brief 生命周期handler
|
||||
*
|
||||
*/
|
||||
typedef void (*FinclipLifecycleHandle)(LifecycleType type, const char* appid, void* input);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* WRAPPER_SRC_PUBLIC_FINCLIP_API_CONST_H_ */
|
|
@ -1,14 +1,19 @@
|
|||
const path = require('path');
|
||||
const finclip = require('./build/Release/_finclip.node');
|
||||
finclip.setDomain('https://finclip-testing.finogeeks.club');
|
||||
finclip.setAppkey('22LyZEib0gLTQdU3MUauAfJ/xujwNfM6OvvEqQyH4igA');
|
||||
finclip.setAppid('6152b5dbfcfb4e0001448e6e');
|
||||
finclip.setSecret('703b9026be3d6bc5');
|
||||
const finclip = require('./build/Release/finclip.node');
|
||||
const finclipPath = path.resolve(__dirname, '../../vendor/win/x64/finclip.exe');
|
||||
console.log('finclipPath', finclipPath);
|
||||
const result = finclip.start({
|
||||
handle: 0,
|
||||
finclipPath,
|
||||
});
|
||||
setTimeout(() => {
|
||||
}, 1000 * 60 * 60);
|
||||
|
||||
const factory = finclip.finclip_get_packer_factory();
|
||||
const packer = finclip.finclip_packer_factory_get_config_packer(factory);
|
||||
finclip.finclip_initialize(packer);
|
||||
const config = finclip.finclip_create_params();
|
||||
finclip.finclip_params_set(config, "appstore", "1");
|
||||
finclip.finclip_params_set(config, "appkey", "22LyZEib0gLTQdU3MUauAfJ/xujwNfM6OvvEqQyH4igA");
|
||||
finclip.finclip_params_set(config, "secret", "703b9026be3d6bc5");
|
||||
finclip.finclip_params_set(config, "domain", "https://finclip-testing.finogeeks.club");
|
||||
finclip.finclip_params_set(config, "exe_path", finclipPath);
|
||||
finclip.finclip_config_packer_add_config(packer, config);
|
||||
finclip.finclip_params_set(config, "window_type", "1");
|
||||
finclip.finclip_register_lifecycle("6152b5dbfcfb4e0001448e6e", 1, console.log, {a:1});
|
||||
finclip.finclip_start_applet("1", "6152b5dbfcfb4e0001448e6e");
|
||||
|
||||
setTimeout(() => {}, 600 * 1000);
|
|
@ -2,7 +2,7 @@
|
|||
"name": "finclip",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "./_finclip.node",
|
||||
"main": "./finclip.node",
|
||||
"scripts": {
|
||||
"configure": "node-gyp configure",
|
||||
"build": "node-gyp build",
|
||||
|
|
Loading…
Reference in New Issue