Skip to content

Commit

Permalink
feat: 采用koffi库的electron demo (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyteng authored Jul 31, 2023
1 parent 95e9a9b commit 3fcd47b
Show file tree
Hide file tree
Showing 16 changed files with 1,541 additions and 3,953 deletions.
1,459 changes: 1,459 additions & 0 deletions examples/electron/package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^18.0.0"
},
"dependencies": {
"finclip": "file:../../src/npm/build/Release"
"electron": "^25.0.0",
"koffi": "^2.5.0"
}
}
38 changes: 38 additions & 0 deletions examples/electron/src/finclip.js
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 15 additions & 15 deletions examples/electron/src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const os = require('os');
const path = require('path');
const finclip = require('finclip');
const finclip = require('./finclip');

let hwnd = 0;
let appid_ = "";
Expand All @@ -12,6 +12,11 @@ let embed = { x: 300, y: 0 };
let isOpen = 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 = () => {
mainWindow = new BrowserWindow({
width: 800,
Expand All @@ -25,7 +30,7 @@ const createMainWindow = () => {
};

const createChildWindow = () => {
childWindow = new BrowserWindow({
childWindow = new BrowserWindow({
parent: mainWindow,
transparent: true,
frame: false,
Expand All @@ -43,19 +48,14 @@ const openFinClipWindow = (arg) => {
if (isOpen) return;
const { domain, appkey, appid, secret } = arg;
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');
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;
const params = finclip.finclip_create_params();
finclip.finclip_params_set(params, "appstore", "1");
finclip.finclip_params_set(params, "appkey", appkey);
finclip.finclip_params_set(params, "secret", secret);
finclip.finclip_params_set(params, "domain", domain);
finclip.finclip_params_set(params, "exe_path", finclipPath);
finclip.finclip_init_with_config("1", params);
config_ = params;
finclip.finclip_start_applet("1", appid);
isOpen = true;
};
Expand Down
51 changes: 27 additions & 24 deletions examples/electron/view/index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<html>
<head></head>
<body>

<head></head>

<body>
<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>
domain<input type="string" id="domain" name="domain" value="">
</div>
<div>
appkey<input type="string" id="appkey" name="appkey" value="">
</div>
<div>
<button onclick="openFinClipWindow()">open</button>
<button onclick="embedFinClipWindow()">embed</button>
<button onclick="closeFinClipWindow()">close</button>
appid<input type="string" id="appid" name="appid" value="">
</div>
<div>
<br />
secret<input type="string" id="secret" name="secret" value="">
</div>
<!-- <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>
Expand All @@ -36,6 +38,7 @@
<div>height<input type="number" id="height" name="height" value="1000"></div>
<div><button onclick="setFinClipPosition()">set position</button></div>
</div> -->
</body>
<script src="../src/mainScript.js"></script>
</body>
<script src="../src/mainScript.js"></script>

</html>
1 change: 0 additions & 1 deletion src/npm/.gitignore

This file was deleted.

Binary file removed src/npm/FinClipSDKWrapper.dll
Binary file not shown.
Binary file removed src/npm/FinClipSDKWrapper.lib
Binary file not shown.
8 changes: 0 additions & 8 deletions src/npm/README.md

This file was deleted.

55 changes: 0 additions & 55 deletions src/npm/binding.gyp

This file was deleted.

Loading

0 comments on commit 3fcd47b

Please sign in to comment.