1
0
Fork 0

electron demo增加设置启动参数的api (#3)

master
g-y-t 2022-04-15 10:56:50 +08:00 committed by GitHub
parent 782141916a
commit 1b6bba38e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 97 additions and 20 deletions

View File

@ -21,7 +21,16 @@ npm run start
const finclip = require('finclip');
```
2. 打开finclip窗口
2. 设置启动参数
```
finclip.setDomain('xxx');
finclip.setAppkey('xxx');
finclip.setAppid('xxx');
finclip.setSecret('xxx');
```
3. 打开finclip窗口
finclipPath为finclip.exe所在位置需转换成绝对路径
```
@ -31,13 +40,13 @@ npm run start
});
```
3. 关闭finclip窗口
4. 关闭finclip窗口
```
finclip.close();
```
4. 设置finclip窗口的位置和大小
5. 设置finclip窗口的位置和大小
```
finclip.setPosition({ width: 800, height: 800, left: 0, top: 0 });

View File

@ -14,7 +14,12 @@ const createMainWindow = () => {
win.loadFile('../view/index.html');
};
const openFinClipWindow = () => {
const openFinClipWindow = (arg) => {
const { domain, appkey, appid, secret } = arg;
finclip.setDomain(domain);
finclip.setAppkey(appkey);
finclip.setAppid(appid);
finclip.setSecret(secret);
const finclipPath = path.resolve(__dirname, '../../../vendor/win/x64/finclip.exe');
const result = finclip.start({
handle: 0,
@ -29,7 +34,7 @@ const closeFinClipWindow = () => {
};
ipcMain.on('OPEN_FINCLIP_WINDOW', (event, arg) => {
openFinClipWindow();
openFinClipWindow(arg);
});
ipcMain.on('CLOSE_FINCLIP_WINDOW', (event, arg) => {

View File

@ -3,7 +3,7 @@ const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld(
'finclip',
{
open: () => ipcRenderer.send('OPEN_FINCLIP_WINDOW'),
open: (payload) => ipcRenderer.send('OPEN_FINCLIP_WINDOW', payload),
close: () => ipcRenderer.send('CLOSE_FINCLIP_WINDOW'),
setPosition: (payload) => ipcRenderer.send('SET_FINCLIP_POSITION', payload),
}

View File

@ -1,5 +1,11 @@
window.openFinClipWindow = () => {
finclip.open();
const domain = document.getElementById('domain').value;
const appkey = document.getElementById('appkey').value;
const appid = document.getElementById('appid').value;
const secret = document.getElementById('secret').value;
finclip.open({
domain, appkey, appid, secret,
});
};
window.closeFinClipWindow = () => {

View File

@ -1,16 +1,39 @@
<html>
<head></head>
<body>
<div>
<div>
启动参数
</div>
<div>
domain<input type="string" id="domain" name="domain" value="https://finchat-mop-b.finogeeks.club">
</div>
<div>
appkey<input type="string" id="appkey" name="appkey" value="22LyZEib0gLTQdU3MUauAQVLIkNNhTSGIN42gXzlAsk=">
</div>
<div>
appid<input type="string" id="appid" name="appid" value="60e3c059949a5300014d0c07">
</div>
<div>
secret<input type="string" id="secret" name="secret" value="ae55433be2f62915">
</div>
</div>
<div>
<button onclick="openFinClipWindow()">open</button>
<button onclick="closeFinClipWindow()">close</button>
</div>
<div>
left<input type="number" id="left" name="left" value="10">
top<input type="number" id="top" name="top" value="10">
width<input type="number" id="width" name="width" value="1000">
height<input type="number" id="height" name="height" value="1000">
<button onclick="setFinClipPosition()">set position</button>
<br />
</div>
<div>
<div>
设置位置
</div>
<div>left<input type="number" id="left" name="left" value="10"></div>
<div>top<input type="number" id="top" name="top" value="10"></div>
<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>
</body>
<script src="../src/mainScript.js"></script>

View File

@ -61,17 +61,21 @@ void CustomApi(const char* event, const char* param,
namespace NodeFinClip {
using namespace Napi;
std::string current_appid;
// std::string current_appid;
std::string domain;
std::string appkey;
std::string appid;
std::string secret;
Napi::String start(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Object args = info[0].ToObject();
int handle = args.Get("handle").ToNumber().Int32Value();
int appstore = 1;
string domain("https://finchat-mop-b.finogeeks.club");
string appkey("22LyZEib0gLTQdU3MUauAQVLIkNNhTSGIN42gXzlAsk=");
string appid("60e3c059949a5300014d0c07");
string secret("ae55433be2f62915");
// string domain("https://finchat-mop-b.finogeeks.club");
// string appkey("22LyZEib0gLTQdU3MUauAQVLIkNNhTSGIN42gXzlAsk=");
// string appid("60e3c059949a5300014d0c07");
// string secret("ae55433be2f62915");
string type("1");
std::string path = args.Get("finclipPath").ToString();
auto* factory = finclip_get_packer_factory();
@ -99,8 +103,8 @@ Napi::String start(const Napi::CallbackInfo& info) {
// hWnd_container, appstore, Utf8Encode(wappid).c_str(), "", packer,
// args.Get("finclipPath").ToString().Utf8Value().c_str(),
// FinclipAppletCallback);
current_appid = appid;
finclip_set_position(current_appid.c_str(), 1000, 300, 540, 960);
// current_appid = appid;
finclip_set_position(appid.c_str(), 1000, 300, 540, 960);
// SetAppletPos(Utf8Encode(wappid).c_str(), 0, 30, 540, 960, true);
// packer->Release();
return Napi::String::New(env, path);
@ -119,7 +123,7 @@ Napi::String setAppletPos(const Napi::CallbackInfo& info) {
int top = args.Get("top").ToNumber().Int32Value();
int width = args.Get("width").ToNumber().Int32Value();
int height = args.Get("height").ToNumber().Int32Value();
finclip_set_position(current_appid.c_str(), left, top, width, height);
finclip_set_position(appid.c_str(), left, top, width, height);
return Napi::String::New(env, "success");
}
@ -131,9 +135,39 @@ Napi::String createWindow(const Napi::CallbackInfo& info) {
return Napi::String::New(env, "success");
}
Napi::String setDomain(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
domain = info[0].ToString();
return Napi::String::New(env, "success");
}
Napi::String setAppid(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
appid = info[0].ToString();
return Napi::String::New(env, "success");
}
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");
}
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"),