feat: 采用koffi库的electron demo (#9)
parent
95e9a9b7ec
commit
3fcd47bc33
File diff suppressed because it is too large
Load Diff
|
@ -10,9 +10,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^18.0.0"
|
"electron": "^25.0.0",
|
||||||
},
|
"koffi": "^2.5.0"
|
||||||
"dependencies": {
|
|
||||||
"finclip": "file:../../src/npm/build/Release"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
const koffi = require('koffi');
|
||||||
|
|
||||||
|
const finclip = {};
|
||||||
|
let lib;
|
||||||
|
|
||||||
|
const loadLibrary = libraryPath => {
|
||||||
|
lib = koffi.load(libraryPath);
|
||||||
|
koffi.pointer('POINT', koffi.opaque());
|
||||||
|
const lifecycleCallback = koffi.callback('lifecycleCallback', 'void', ['int', 'string', 'void*']);
|
||||||
|
const customApiCallback = koffi.callback('customApiCallback', 'void', ['string', 'string', 'string', 'int']);
|
||||||
|
|
||||||
|
finclip.finclip_create_params = lib.func('finclip_create_params', 'POINT', []);
|
||||||
|
finclip.finclip_destory_params = lib.func('finclip_destory_params', 'int', ['POINT']);
|
||||||
|
finclip.finclip_params_set = lib.func('finclip_params_set', 'int', ['POINT', 'string', 'string']);
|
||||||
|
finclip.finclip_init_with_config = lib.func('finclip_init_with_config', 'int', ['string', 'POINT']);
|
||||||
|
finclip.finclip_start_applet = lib.func('finclip_start_applet', 'int', ['string', 'string']);
|
||||||
|
finclip.finclip_start_applet_embed = lib.func('finclip_start_applet_embed', 'int', ['string', 'string', 'POINT', 'int']);
|
||||||
|
finclip.finclip_close_applet = lib.func('finclip_close_applet', 'int', ['string']);
|
||||||
|
finclip.finclip_set_position = lib.func('finclip_set_position', 'int', ['string', 'int', 'int', 'int', 'int']);
|
||||||
|
finclip.finclip_callback_success = lib.func('finclip_callback_success', 'int', ['int', 'POINT']);
|
||||||
|
finclip.finclip_callback_failure = lib.func('finclip_callback_failure', 'int', ['int', 'POINT']);
|
||||||
|
|
||||||
|
finclip.finclip_register_lifecycle = (appid, type, fn, data) => {
|
||||||
|
const callback = koffi.register(fn, koffi.pointer(lifecycleCallback));
|
||||||
|
const finclip_register_lifecycle = lib.func('finclip_register_lifecycle', 'int', ['string', 'int', koffi.pointer(lifecycleCallback), 'void*']);
|
||||||
|
return finclip_register_lifecycle(appid, type, callback, data);
|
||||||
|
};
|
||||||
|
|
||||||
|
finclip.finclip_register_api = (type, name, fn, data) => {
|
||||||
|
const callback = koffi.register(fn, koffi.pointer(customApiCallback));
|
||||||
|
const finclip_register_api = lib.func('finclip_register_api', 'int', ['int', 'string', koffi.pointer(customApiCallback), 'POINT']);
|
||||||
|
return finclip_register_api(type, name, callback, data);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
finclip.load_library = loadLibrary;
|
||||||
|
|
||||||
|
module.exports = finclip;
|
|
@ -1,7 +1,7 @@
|
||||||
const { app, BrowserWindow, ipcMain } = require('electron');
|
const { app, BrowserWindow, ipcMain } = require('electron');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const finclip = require('finclip');
|
const finclip = require('./finclip');
|
||||||
|
|
||||||
let hwnd = 0;
|
let hwnd = 0;
|
||||||
let appid_ = "";
|
let appid_ = "";
|
||||||
|
@ -12,6 +12,11 @@ let embed = { x: 300, y: 0 };
|
||||||
let isOpen = false;
|
let isOpen = false;
|
||||||
let isEmbed = false;
|
let isEmbed = false;
|
||||||
|
|
||||||
|
const finclipPath = path.resolve(__dirname, '../../../vendor/win/x64/FinClip/FinClip.exe');
|
||||||
|
const libraryPath = path.resolve(__dirname, '../../../vendor/win/x64', 'FinClipSDKWrapper.dll');
|
||||||
|
|
||||||
|
finclip.load_library(libraryPath);
|
||||||
|
|
||||||
const createMainWindow = () => {
|
const createMainWindow = () => {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
|
@ -43,19 +48,14 @@ const openFinClipWindow = (arg) => {
|
||||||
if (isOpen) return;
|
if (isOpen) return;
|
||||||
const { domain, appkey, appid, secret } = arg;
|
const { domain, appkey, appid, secret } = arg;
|
||||||
appid_ = appid;
|
appid_ = appid;
|
||||||
const factory = finclip.finclip_get_packer_factory();
|
const params = finclip.finclip_create_params();
|
||||||
const packer = finclip.finclip_packer_factory_get_config_packer(factory);
|
finclip.finclip_params_set(params, "appstore", "1");
|
||||||
finclip.finclip_initialize(packer);
|
finclip.finclip_params_set(params, "appkey", appkey);
|
||||||
const config = finclip.finclip_create_params();
|
finclip.finclip_params_set(params, "secret", secret);
|
||||||
finclip.finclip_params_set(config, "appstore", "1");
|
finclip.finclip_params_set(params, "domain", domain);
|
||||||
finclip.finclip_params_set(config, "appkey", appkey);
|
finclip.finclip_params_set(params, "exe_path", finclipPath);
|
||||||
finclip.finclip_params_set(config, "secret", secret);
|
finclip.finclip_init_with_config("1", params);
|
||||||
finclip.finclip_params_set(config, "domain", domain);
|
config_ = params;
|
||||||
const finclipPath = path.resolve(__dirname, '../../../vendor/win/x64/finclip.exe');
|
|
||||||
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);
|
finclip.finclip_start_applet("1", appid);
|
||||||
isOpen = true;
|
isOpen = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,32 +1,34 @@
|
||||||
<html>
|
<html>
|
||||||
<head></head>
|
|
||||||
<body>
|
<head></head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
启动参数
|
||||||
启动参数
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
domain<input type="string" id="domain" name="domain" value="https://finclip-testing.finogeeks.club">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
appkey<input type="string" id="appkey" name="appkey" value="22LyZEib0gLTQdU3MUauAfJ/xujwNfM6OvvEqQyH4igA">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
appid<input type="string" id="appid" name="appid" value="6152b5dbfcfb4e0001448e6e">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
secret<input type="string" id="secret" name="secret" value="703b9026be3d6bc5">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button onclick="openFinClipWindow()">open</button>
|
domain<input type="string" id="domain" name="domain" value="">
|
||||||
<button onclick="embedFinClipWindow()">embed</button>
|
|
||||||
<button onclick="closeFinClipWindow()">close</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<br />
|
appkey<input type="string" id="appkey" name="appkey" value="">
|
||||||
</div>
|
</div>
|
||||||
<!-- <div>
|
<div>
|
||||||
|
appid<input type="string" id="appid" name="appid" value="">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
secret<input type="string" id="secret" name="secret" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button onclick="openFinClipWindow()">open</button>
|
||||||
|
<button onclick="embedFinClipWindow()">embed</button>
|
||||||
|
<button onclick="closeFinClipWindow()">close</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<br />
|
||||||
|
</div>
|
||||||
|
<!-- <div>
|
||||||
<div>
|
<div>
|
||||||
设置位置
|
设置位置
|
||||||
</div>
|
</div>
|
||||||
|
@ -36,6 +38,7 @@
|
||||||
<div>height<input type="number" id="height" name="height" value="1000"></div>
|
<div>height<input type="number" id="height" name="height" value="1000"></div>
|
||||||
<div><button onclick="setFinClipPosition()">set position</button></div>
|
<div><button onclick="setFinClipPosition()">set position</button></div>
|
||||||
</div> -->
|
</div> -->
|
||||||
</body>
|
</body>
|
||||||
<script src="../src/mainScript.js"></script>
|
<script src="../src/mainScript.js"></script>
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -1 +0,0 @@
|
||||||
build/
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,8 +0,0 @@
|
||||||
### 编译
|
|
||||||
|
|
||||||
1. npm run configure
|
|
||||||
2. npm run build
|
|
||||||
|
|
||||||
### 运行
|
|
||||||
|
|
||||||
node index.js
|
|
|
@ -1,55 +0,0 @@
|
||||||
{
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target_name": "finclip",
|
|
||||||
"win_delay_load_hook": "true",
|
|
||||||
"sources": [
|
|
||||||
"finclip.cpp"
|
|
||||||
],
|
|
||||||
"cflags_cc": [
|
|
||||||
"-std=c++17"
|
|
||||||
],
|
|
||||||
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
|
|
||||||
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
||||||
"libraries": [
|
|
||||||
"../FinClipSDKWrapper.lib",
|
|
||||||
],
|
|
||||||
"defines": ["_UNICODE", "UNICODE", "NAPI_DISABLE_CPP_EXCEPTIONS"],
|
|
||||||
"copies": [
|
|
||||||
{
|
|
||||||
"destination": "<(module_root_dir)/build/Release/",
|
|
||||||
"files": [
|
|
||||||
"./FinClipSDKWrapper.lib",
|
|
||||||
"./FinClipSDKWrapper.dll",
|
|
||||||
"../../vendor/win/x64/finclip.exe",
|
|
||||||
"../../vendor/win/x64/finclip.exp",
|
|
||||||
"../../vendor/win/x64/finclip.lib",
|
|
||||||
"package.json"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"conditions": [
|
|
||||||
['OS=="mac"', {
|
|
||||||
"xcode_settings": {
|
|
||||||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
||||||
"CLANG_CXX_LIBRARY": "libc++",
|
|
||||||
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
|
|
||||||
'MACOSX_DEPLOYMENT_TARGET': '10.14'
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
['OS=="win"', {
|
|
||||||
"msvs_settings": {
|
|
||||||
"VCCLCompilerTool": {
|
|
||||||
"AdditionalOptions": ["-std:c++17", ],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"msbuild_settings": {
|
|
||||||
"ClCompile": {
|
|
||||||
"LanguageStandard": "stdcpp17"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,228 +0,0 @@
|
||||||
#include "./finclip_api.h"
|
|
||||||
#include "./finclip_api_const.h"
|
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <napi.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace Napi;
|
|
||||||
namespace NodeFinClip {
|
|
||||||
|
|
||||||
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();
|
|
||||||
auto *factory = finclip_get_packer_factory();
|
|
||||||
factory_vector.push_back(factory);
|
|
||||||
auto result = Napi::Object::New(env);
|
|
||||||
result.Set("id", factory_vector.size() - 1);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Napi::Object FinclipPackerFactoryGetConfigPacker(const Napi::CallbackInfo& info) {
|
|
||||||
Napi::Env env = info.Env();
|
|
||||||
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::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();
|
|
||||||
auto result = Napi::Number::New(env, 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Napi::Number FinclipHideApplet(const Napi::CallbackInfo& info) {
|
|
||||||
Napi::Env env = info.Env();
|
|
||||||
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::Number FinclipShowApplet(const Napi::CallbackInfo& info) {
|
|
||||||
Napi::Env env = info.Env();
|
|
||||||
Napi::String app_id = info[0].ToString();
|
|
||||||
finclip_show_applet(app_id.Utf8Value().c_str());
|
|
||||||
auto result = Napi::Number::New(env, 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
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::Number FinclipRegisterLifecycle(const Napi::CallbackInfo& info) {
|
|
||||||
Napi::Env env = info.Env();
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
auto result = Napi::Number::New(env, 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
||||||
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
|
|
|
@ -1,182 +0,0 @@
|
||||||
#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_ */
|
|
|
@ -1,130 +0,0 @@
|
||||||
#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,19 +0,0 @@
|
||||||
const path = require('path');
|
|
||||||
const finclip = require('./build/Release/finclip.node');
|
|
||||||
const finclipPath = path.resolve(__dirname, '../../vendor/win/x64/finclip.exe');
|
|
||||||
|
|
||||||
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);
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"name": "finclip",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "./finclip.node",
|
|
||||||
"scripts": {
|
|
||||||
"configure": "node-gyp configure",
|
|
||||||
"build": "node-gyp build",
|
|
||||||
"rebuild": "node-gyp rebuild",
|
|
||||||
"erebuild": "electron-rebuild -v 13.6.6"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"electron-rebuild": "^3.2.7",
|
|
||||||
"node-addon-api": "^1.7.2"
|
|
||||||
},
|
|
||||||
"gypfile": true
|
|
||||||
}
|
|
Loading…
Reference in New Issue