我创建了这样的PDK插件:
#include <iostream>
#include <fstream>
#include "PDL.h"
#include "SDL.h"
#define forever for(;;)
using namespace std;
PDL_bool changeUserAgent(PDL_JSParameters * params)
{
ofstream s("/media/internal/myfile.txt");
s << "Some content";
s.close();
return PDL_TRUE;
}
int main(int argc, char** argv)
{
int err = SDL_Init(SDL_INIT_VIDEO);
if ( err )
{
cerr << "Could not init SDL: " << SDL_GetError();
return 1;
}
PDL_Init(0);
PDL_RegisterJSHandler("changeUserAgent", changeUserAgent);
PDL_JSRegistrationComplete();
PDL_CallJS("ready", NULL, 0); //for enyo
atexit(SDL_Quit);
atexit(PDL_Quit);
SDL_Event Event;
bool paused = false, gotEvent;
forever
{
if (paused)
{
SDL_WaitEvent(&Event);
gotEvent = true;
}
else
{
gotEvent = SDL_PollEvent(&Event);
}
while (gotEvent)
{
switch (Event.type)
{
case SDL_ACTIVEEVENT:
if (Event.active.state == SDL_APPACTIVE) {
paused = !Event.active.gain;
}
break;
case SDL_QUIT:
// We exit anytime we get a request to quit the app
// all shutdown code is registered via atexit() so this is clean.
exit(0);
break;
default:
break;
}
}
gotEvent = SDL_PollEvent(&Event);
}
return 0;
}
在Enyo我打电话
enyo.kind(
{
name: "UserAgentTool",
kind: enyo.VFlexBox,
components:
[
// UI components
{
kind: enyo.Hybrid,
name: "plugin",
executable: "UserAgentTool-plugin"
}
],
uaclick: function(inSender)
{
this.$.plugin.callPluginMethodDeferred(null, "changeUserAgent")
enyo.windows.addBannerMessage("User agent changed to " + inSender.getUserAgent(), '{}')
}
});
UI按钮是一种新的
enyo.kind(
{
name: "DeviceButton",
kind: "Button",
// some other properties
onclick: "uaclick",
})
单击DeviceButton时,成功引发横幅。这表明执行了uaclick“slot”。但是没有创建文件“/media/internal/myfile.txt”。 我做错了什么?
谢谢, 马尔钦
编辑:我应该如何使用回调?我真的是一个Enyo新手:(这和“onclick”一样吗?Enyo app的appinfo.json是:
{
"id": "com.palm.marmistrz.useragenttool",
"version": "1.0.0",
"vendor": "Marcin Mielniczuk",
"type": "web",
"main": "index.html",
"title": "User Agent Tool",
"icon": "icon.png",
"uiRevision":2
}
我的插件没有appinfo.json。它只是一个可执行文件。目录上的ls -l是:
rw-r--r-- 1 marcin marcin 215 Nov 2 13:09 appinfo.json
drwx------ 3 marcin marcin 4096 Nov 7 15:10 build
-rw-r--r-- 1 marcin marcin 100 Oct 31 18:57 depends.js
-rw-r--r-- 1 marcin marcin 21 Oct 13 14:45 framework_config.json
drwxr-xr-x 2 marcin marcin 4096 Oct 13 14:44 images
-rw-r--r-- 1 marcin marcin 295 Oct 13 14:44 index.html
drwx------ 2 marcin marcin 4096 Nov 7 15:08 plugin
drwxr-xr-x 2 marcin marcin 4096 Nov 7 15:06 source
-rw-r--r-- 1 marcin marcin 8884 Nov 6 17:41 UserAgentTool-plugin
build是构建插件的目录 图像是空的 插件是插件源 来源是Enyo来源
我做错了吗?
谢谢!