Skip to content

Desktop integration

Integration sample code

The integration sample code is available here https://github.com/finogeeks/PhizClip-desktop-demo

If you do not have access to Github in your environment, you can also visit the gitee mirror repository by clicking here.

1. Get applet credentials

To use the SDK you need to apply for the SDK KEY and the SDK SECRET. Only if the correct SDK KEY and SDK SECRET are configured during the initialisation of the SDK will it work.

1.1 Creating applications

Registered users need to log in to "App Management - New Partner App" to complete app creation;

Image.png

1.2 Obtaining SDK KEY and SDK SECRET

After creating the application and adding the Bundle ID, if you need to export the corresponding SDK KEY and SDK SECRET, please select "Copy" after the corresponding Bundle ID, you can paste it by Ctrl+V or Command+V;

Image.png Of which.

  • SDK KEY: This is the credential that enables the partner app to use the applet SDK. If the SDK KEY fails to validate, all APIs of the SDK will not be available.
  • SDK SECERT: is the security certificate for accessing the service, do not give it to third parties.

Tips

For details on creating applications and obtaining the SDK KEY and SDK SECRET, see the 「Introduction-Operation Guidelines-Enterprise Operation Guidelines-7.」 section.

2. Getting and importing the SDK

The directory structure of the desktop version of the SDK is as follows:

PhizClip.zip
│ PhizClipWrapper.(dll | so | dylib)   # Dynamic Link Library
│ PhizClip_api.h                       # Public interface header file
│ PhizClip_const.h 
└───PhizClip/                          # Main program

2.1 Importing the SDK

Depending on the combination of language and builder, the import method varies slightly

:::: tabs :options="{useUrlFragment:false}" ::: tab "cmake"

cmake
 target_include_directories(TARGET PRIVATE ${PhizClip_DIR})
 target_link_libraries(TARGET PRIVATE PhizClipSDKWrapper)

::: ::: tab "qmake"

qmake
 LIBS += "path/to/PhizClipSDKWrapper.lib"
 INCLUDEPATH += "path/to/include"

::: ::: tab "js"

javascript
const PhizClip = require('./build/Release/_PhizClip.node');

::: ::: tab "rust"

rust
// build.rs
fn main() {
 println!("cargo:rustc-link-lib=dylib=PhizClipSDKWrapper");
 println!("cargo:rustc-link-search=native=/path/to/libPhizClipSDKWrapper.so");
}

::: ::::

3. SDK initialisation

3.1 Configuring the SDK

:::: tabs :options="{useUrlFragment:false}" ::: tab "C++"

cpp
 auto *factory = PhizClip_get_packer_factory();
 auto *packer = PhizClip_packer_factory_get_config_packer(factory);
 PhizClip_initialize(packer);
 PhizClipParams *config = PhizClip_create_params();
 PhizClip_params_set(config, PhizClip_CONFIG_APPSTORE, app_store);
 PhizClip_params_set(config, PhizClip_CONFIG_APPKEY, appkey.c_str());
 PhizClip_params_set(config, PhizClip_CONFIG_SECRET, secret.c_str());
 PhizClip_params_set(config, PhizClip_CONFIG_DOMAIN, domain.c_str());
 PhizClip_params_set(config, PhizClip_CONFIG_EXE_PATH, exe_path.c_str());

::: ::: tab "js"

javascript
PhizClip.setDomain('PhizClip_CONFIG_DOMAIN');
PhizClip.setAppkey('PhizClip_CONFIG_APPKEY');
PhizClip.setAppid('PhizClip_CONFIG_APPID');
PhizClip.setSecret('PhizClip_CONFIG_SECRET');

::: ::: tab "rust"

rust
let factory = PhizClip_get_packer_factory();
let packer = PhizClip_packer_factory_get_config_packer(factory);
PhizClip_initialize(packer);
let config = PhizClip_create_params();
PhizClip_params_set(config, cstr("appstore").as_ptr(), cstr(&cfg.appstore).as_ptr());
PhizClip_params_set(config, cstr("appkey").as_ptr(), cstr(&cfg.appkey).as_ptr());
PhizClip_params_set(config, cstr("secret").as_ptr(), cstr(&cfg.secret).as_ptr());
PhizClip_params_set(config, cstr("domain").as_ptr(), cstr(&cfg.domain).as_ptr());
PhizClip_params_set(config, cstr("app_id").as_ptr(), cstr(&cfg.appid).as_ptr());
PhizClip_params_set(config, cstr("exe_path").as_ptr(), cstr(&cfg.exe_path).as_ptr());
PhizClip_config_packer_add_config(packer, config);
PhizClip_start_applet(cstr(&cfg.appstore).as_ptr(), cstr(& cfg.appid).as_ptr());

::: ::::

4. Examples of SDK use

4.1 Launching the applet

:::: tabs :options="{useUrlFragment:false}" ::: tab "C++"

cpp
 PhizClip_start_applet(app_store, appid.c_str());

::: ::: tab "js"

javascript
const result = PhizClip.start({
 handle: 0,
 PhizClipPath: 'PhizClip_PATH',
});

::: ::: tab "rust"

rust
PhizClip_start_applet(cstr(& cfg.appstore).as_ptr(), cstr(&cfg.appid).as_ptr())

::: ::::

4.2 Embedding applets

:::: tabs :options="{useUrlFragment:false}" ::: tab "C++"

cpp
 PhizClip_start_applet_embed(app_store, appid.c_str(), hwnd);

::: ::: tab "rust"

rust
PhizClip_start_applet_embed(cstr(& cfg.appstore).as_ptr(), cstr(&cfg.appid).as_ptr(), hwnd)

::: ::::

4.3 Registering custom api

:::: tabs :options="{useUrlFragment:false}" ::: tab "C++"

cpp
// Define custom APIs
void WebApiExample(const char *event, const char *param, void *input,
 void *res) {
 auto *self = static_cast< MainWindow *>(input);
 PhizClip_params_set(res, "hello", "web api");
}
void AppApiExample(const char *event, const char *param, void *input,
 void *res) {
 auto *self = static_cast< MainWindow *>(input);
 PhizClip_params_set(res, "hello", "app api");
}
// Register custom APIs
 fin_register_api(packer, kWebView, "test", WebApiExample, this);
 fin_register_api(packer, kApplet, "test", AppApiExample, this);

::: ::: tab "rust"

rust
// Define custom APIs
extern "C" fn web_api_callback(res: *const c_char, input: *mut c_void) 
{
 unsafe {
 let data = &*(input as *mut Arc< Mutex< OtherStruct>>);
 let mut d = data.lock().unwrap();
 d. set_value("callback ok!");
 }
}
extern "C" fn web_api_example(event: *const c_char,
 param: *const c_char, input: *mut c_void, _res: *mut c_void) {
 unsafe {
 let data = &*(input as *mut Arc< Mutex< OtherStruct>>);
 let mut d = data. lock().unwrap();
 d. set_value("web api ok!");
 }
}
// Register custom APIs
let other_struct_obj: Arc< Mutex< OtherStruct>>;
let input = & other_struct_obj as *const _ as *mut c_void;
PhizClip_register_api(packer, typ as c_int, str_to_cstr(apis)?as_ptr(),
web_api_example, input);
// call api, only the host can call the api in the webview
let other_struct_obj: Arc< Mutex< OtherStruct>>;
let input = & other_struct_obj as *const _ as *mut c_void;
let res = PhizClip_invoke_api(PhizClipApiType::WebView, appid.as_str(), 
"test", r###"{"hello": "world"}"####, web_api_callback, input);

::: ::::